0

EDIT: URL works fine, I mistakenly thought i,j, width, and height were sending info specific to the WMS image being checked for features.

I could be misunderstanding how the URL works so correct me if I'm wrong. The I, J, height and width attributes are all used to locate the feature on the image correct? When I provide getGetFeatureInfoUrl with different coordinates and viewResolutions, I always get the same location attributes in my URL.

When I create url using getGetFeatureInfoUrl, no matter what the coordinate or viewresolution, the i and j values are always 50. The height and width are also always 101.

Here are some examples:

"URL: http://localhost/geoserver/workspace/wfs?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetFeatureInfo&FORMAT=image%2Fpng&TRANSPARENT=true&QUERY_LAYERS=workspace%3Atable_points&LAYERS=workspace%3Atable_points&time=1500402731190&INFO_FORMAT=application%2Fjson&I=50&J=50&CRS=EPSG%3A4326&STYLES=&WIDTH=101&HEIGHT=101&BBOX=620954.1142031327%2C-34459035.34341003%2C8526377.327569202%2C-26553612.130043965"
Coordinate: -30506323.736727,4573665.720886167
ViewResolution: 78271.51696402048

"URL: http://localhost/geoserver/workspace/wfs?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetFeatureInfo&FORMAT=image%2Fpng&TRANSPARENT=true&QUERY_LAYERS=workspace%3Atable_points&LAYERS=workspace%3Atable_points&time=1500402501193&INFO_FORMAT=application%2Fjson&I=50&J=50&CRS=EPSG%3A4326&STYLES=&WIDTH=101&HEIGHT=101&BBOX=7044436.526761843%2C9118631.726308389%2C10997148.133444877%2C13071343.332991423"  
Coordinate: 11094987.529649906,9020792.33010336  
ViewResolution: 39135.75848201024  

"URL: http://localhost/geoserver/workspace/wfs?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetFeatureInfo&FORMAT=image%2Fpng&TRANSPARENT=true&QUERY_LAYERS=workspace%3Atable_points&LAYERS=workspace%3Atable_points&time=1500402511193&INFO_FORMAT=application%2Fjson&I=50&J=50&CRS=EPSG%3A4326&STYLES=&WIDTH=101&HEIGHT=101&BBOX=-2822992.6322137713%2C-1506726.7015574016%2C5082430.581152298%2C6398696.511808667"  
Coordinate: 2445984.905125633,1129718.974469263  
ViewResolution: 78271.51696402048

"URL: http://localhost/geoserver/workspace/wfs?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetFeatureInfo&FORMAT=image%2Fpng&TRANSPARENT=true&QUERY_LAYERS=workspace%3Atable_points&LAYERS=workspace%3Atable_points&time=1500402511193&INFO_FORMAT=application%2Fjson&I=50&J=50&CRS=EPSG%3A4326&STYLES=&WIDTH=101&HEIGHT=101&BBOX=-5405952.6920264475%2C-10429679.635455731%2C2499470.5213396214%2C-2524256.4220896624"  
Coordinate: -6476968.028772697,-1453241.085343413
ViewResolution: 78271.51696402048

Here's this HTML if it helps:

var displayFeatureInfo = function(coord, pixel)
{
    var features;
    document.getElementById('info').innerHTML = '';
    var viewResolution = /** @type {number} */ (view.getResolution());
    var url = pointLayer.getSource().getGetFeatureInfoUrl(
        coord, viewResolution, 'EPSG:4326',
        {'INFO_FORMAT': 'application/json'});
    if (url) {
      features = url;
      document.getElementById('info').innerHTML = '<iframe seamless src="' + url + '"></iframe>';
    }
};

map.on('singleclick', function(evt) {
    displayFeatureInfo(evt.coordinate, evt.pixel);
});

Edit: I believe I found the issue. Here is the relevant openlayers code, line 141(https://github.com/openlayers/openlayers/blob/9fc0fb5e74146cd9a0c99926bed1a0f51fc745ad/src/ol/source/imagewms.js).

When creating the 'extent' openlayers always uses a default image size, which is [101,101].

  • You must show your code and where it takes the pixel coordinates of the point that user clicks on the map. – user30184 Jul 18 '17 at 19:53
  • The example in openlayers.org/en/latest/examples/getfeatureinfo-image.html seems to work as supposed. – user30184 Jul 18 '17 at 20:25
  • It also produces URLs with i,j=50 and width,height=101. The only thing that changes is the BBOX. I guess that is where the click location is being sent. I misunderstood how the URL works. – Evan Jul 18 '17 at 20:42
  • Ok, feels like a trick but it gives a right result, doesn't it? Info is taken from the center of that sliding window. – user30184 Jul 18 '17 at 21:08
  • Yea, it works correctly. I just didn't realize geoserver used the center of the bounding box to locate the features. – Evan Jul 18 '17 at 21:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.