I try to use Openlayers 3 DragBox for BoxSelection ang get selected feature info from wms source. Layer projection EPSG:4326
var host = 'http://x.x.x.x/geoserver/wms'
var view = new ol.View({
center: [12018110.072132599, 6954779.226347315],
projection: 'EPSG:3857',
zoom: 6
});
var wmsStation = new ol.source.TileWMS({
url: host,
params: {
'LAYERS': 'baikalgeol:station_psg',
'TILED': true,
'VERSION': '1.1.1'
},
serverType: 'geoserver',
crossOrigin: 'anonymous'
});
var layerStation = new ol.layer.Tile({
title: 'Station',
source: wmsStation,
});
var map = new ol.Map({
pixelRatio: 1,
controls: ol.control.defaults().extend([
new ol.control.ScaleLine({
units: 'metric'
})
]),
renderer: 'canvas',
target: 'map',
layers: [
new ol.layer.Group({
layerStation,
...
})
],
view: view
});
var dragBox = new ol.interaction.DragBox({
condition: ol.events.condition.platformModifierKeyOnly
});
map.addInteraction(dragBox);
dragBox.on('boxend', function(evt) {
var info = []
var extent = dragBox.getGeometry().getExtent();
console.log(extent)
// extent = ol.proj.transformExtent(extent, 'EPSG:3857', 'EPSG:4326')
// extent = [extent[1], extent[0], extent[3], extent[2]]
console.log(extent)
var source = wmsStation;
var viewResolution = map.getView().getResolution();
var queryLayers = source.getParams().LAYERS;
var url = source.getGetFeatureInfoUrl(extent, viewResolution, 'EPSG:3857', {
'INFO_FORMAT': 'text/html',
'QUERY_LAYERS': queryLayers,
'VERSION': '1.1.1'
});
if (url) {
// url = url.replace('&CRS=', '&SRS=')
console.log(url)
document.getElementById('info').innerHTML =
'<iframe id="frame" seamless src="' + url + '"></iframe>';
}
});
But geoserver not return feature, only empty html.
I think the problem in the extent. I tried transform extent coordinates for layer projection and changed getGetFeatureInfoUrl projection:
extent = ol.proj.transformExtent(extent, 'EPSG:3857', 'EPSG:4326')
...
var url = source.getGetFeatureInfoUrl(extent, viewResolution, 'EPSG:4326'...
But geoserver return:
<ServiceExceptionReport version="1.1.1" >
<ServiceException code="InvalidPoint">
655, -176 not in dimensions of image: 256, 256
</ServiceException>
</ServiceExceptionReport>