Strange error returned while trying to access raster pixel value

331 views Asked by At

I am trying to access the value of a pixel served through MapServer from webapp via OpenLayers getFeatureInfoUrl(). The server responds with msWMSFeatureInfo(): WMS server error. Invalid I/J values I have tried googling it but could not find any clues on what might be wring with my request only that I/J values refer to the coorndinates of the mouse click so the problem might originate in evt.coordinate from:

var vs = this.wmsLayer
mapol.on('singleclick', function(evt) {
  document.getElementById('info').innerHTML = '';
  var viewResolution = /** @type {number} */ (view.getResolution());
  var url = vs.getSource().getGetFeatureInfoUrl(
     evt.coordinate, viewResolution, 'EPSG:4326',
      {'INFO_FORMAT': 'text/html'});
  if (url) {
    document.getElementById('info').innerHTML =
        '<iframe seamless src="' + url + '"></iframe>';
  }
});

The wmsLayer uses the same 'EPSG:4326' coordinate system as request. Can anyone help me get the pixel value at the clicked location:)

1

There are 1 answers

3
ahocevar On BEST ANSWER

The SRS of the coordinate you pass to the #getGetFeatureInfoUrl() method needs to match the projection you provide as argument. So you'd have to change your code to

var url = vs.getSource().getGetFeatureInfoUrl(
   ol.proj.toLonLat(evt.coordinate, view.getProjection()),
   viewResolution, 'EPSG:4326', {'INFO_FORMAT': 'text/html'});