-1

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:)

Alešinar
  • 123
  • 1
  • 11
  • What projection is your view in? If it is different than EPSG:4326, you'll need to transform the `evt.coordinate` you pass to `getGetFeatureInfoUrl` to EPSG:4326. – ahocevar Sep 08 '17 at 04:57
  • Hi, thanks for the clue. I defined the projection in my view as EPSG:4326 and it works now!!! However, my map looks very streched now. Is it possible to use EPSG:3857 in all parameters and would it work that way. Anoter question: I have defined TEMPLATE in my LAYER class of the .map file and in the first class as the raster is classified for display of more complex color range. Do I have to define TEMPLATE for every CLASS? – Alešinar Sep 08 '17 at 06:52
  • Anyway go ahead and add your comment as an answer so I can comfirm and mark the question as answered. – Alešinar Sep 08 '17 at 06:54

1 Answers1

2

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'});
ahocevar
  • 5,448
  • 15
  • 29
  • As I said this solution Works but only if both map view and layer are in epsg:4326. If I want to display the map and layer in epsg:3857 the getFeatureInfoUrl() returns notihing. – Alešinar Sep 11 '17 at 12:27
  • This might be a MapServer configuration issue. Someone more knowledgeable about that may want to weigh in. To debug this further, it would help if you could post the GetFeatureInfo request url generated by OpenLayers in all these cases. – ahocevar Sep 12 '17 at 09:31
  • Hi, sorry for late response. I somehow managed to get it going. The problem was not really in the coordinate system but viewResolution and my WMS having very large cells/pixels. Clicking on or close to cell center returns the correct result. Thank you very much for your help! – Alešinar Sep 14 '17 at 07:58