My data is in SRS EPSG:4326. My map (view/layers) are in the default EPSG:3857.
I want to just work in the data projection and would like to query a feature on map click with my data projection coordinates, but I only seem to get a value back if I use the view coordinates and projection. I don't want to force the map to be reprojected to EPSG:4326 by OpenLayers because it gets stretched. I am using getGetFeatureInfoUrl to build the URL to call.
An AJAX call to this URL returns/finds a feature:
var viewResolution = map.getView().getResolution();
var coords = [-11131949.079327358,4865942.279503176];
var url = wmsSource.getGetFeatureInfoUrl(coords, viewResolution, 'EPSG:3857', {'INFO_FORMAT': 'application/json'});
/*
URL is now:
http://mymapserver/geoserver/myworkspace/wms?
SERVICE=WMS&
VERSION=1.1.1&
REQUEST=GetFeatureInfo&
FORMAT=image%2Fpng&
TRANSPARENT=true&
QUERY_LAYERS=myworkspace%3Amyfeature&
TILED=true&
STYLES=&
LAYERS=myworkspace%3Amyfeature&
INFO_FORMAT=application%2Fjson&
X=28&
Y=29&
WIDTH=256&
HEIGHT=256&
SRS=EPSG%3A3857&
BBOX=-11271098.442818949%2C3757032.814272983%2C-10018754.171394622%2C5009377.085697311&
*/
The code below does not find a feature, why?
var viewResolution = map.getView().getResolution();
// transform coordinates to EPSG:4326
var coords = ol.proj.transform([-11131949.079327358,4865942.279503176], 'EPSG:3857', 'EPSG:4326');
// coords now equals [-100,40]
var url = wmsSource.getGetFeatureInfoUrl(coords, viewResolution, 'EPSG:4326', {'INFO_FORMAT': 'application/json'});
/*
URL is now:
http://mympaserver/geoserver/myworkspace/wms?
SERVICE=WMS&
VERSION=1.1.1&
REQUEST=GetFeatureInfo&
FORMAT=image%2Fpng&
TRANSPARENT=true&
QUERY_LAYERS=myworkspace%3Amyfeature&
TILED=true&
STYLES=&
LAYERS=myworkspace%3Amyfeature&
INFO_FORMAT=application%2Fjson&
X=56&
Y=291&
WIDTH=256&
HEIGHT=256&
SRS=EPSG%3A4326&
BBOX=-180%2C90%2C180%2C450&
*/
Shouldn't the feature be found?
Do I need to somehow transform the resolution as well?
I am specifying the coordinate system as EPSG:4326. If the URL built by OpenLayers is incorrect, why?