[MapServer-users] How to get a WMS GetFeatureInfo response with MapServer in JSON format ?

Julien Hubert JHubert at forum-marais-atl.com
Thu Sep 14 01:25:36 PDT 2023


Hi,
I use Mapserver with the Leaflet JS library and I want to display some attributes informations by clicking on the map.
Therefore I use the GetFeatureInfo WMS request in order to return these informations.
I managed to get the infos with the text/html format but I'd like to get a JSON response back in my browser, e.g :
{
    "value": [value_0], // I must precise I use GetFeatureInfo on a raster
}

So I changed the wms_get_feature_info_formalist in the METADATA bloc of my mapfile :
"wms_getfeatureinfo_formatlist" "application/json"

Then, I edited my template as following to return the value of the pixel :
<!-- MapServer Template -->
[value_0]

My GetFeatureInfo request is the one (see "application/json" specified in the INFO_FORMAT parameter)

http://IP/cgi-bin/mapserv?map=/var/www/html/mapfiles/test1.map&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetFeatureInfo&BBOX=465348.6282001531,5431156.607774916,697564.3201305186,5503160.28841955&SRS=EPSG:3857&WIDTH=1519&HEIGHT=471&LAYERS=layer1&STYLES=&FORMAT=image/png&TRANSPARENT=true&QUERY_LAYERS=layer1&INFO_FORMAT=application/json&X=766&Y=261

But when I try the GetFeatureInfo request, my browser returns nothing (whereas it works with the text/html) and it downloads a file called "mapserv" with nothing inside :
[enter image description here]<https://i.stack.imgur.com/GuVAe.png>

I must explain I don't want to download a GeoJSON file but to return the content of a JSON response in my browser.
Do you know how I could get my JSON response ? Is it possible to make it work ?

Any help would be greatly appreciated, thanks !

--
Julien H
Back-end developper
Forum des Marais Atlantiques
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20230914/b6aa593e/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 3277 bytes
Desc: image001.png
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20230914/b6aa593e/attachment.png>


More information about the MapServer-users mailing list