Monday, 2 December 2019

openlayers 2 - How to select fields returned by GeoServer WMS GetFeatureInfo request?


I'm running simple local mapping service based on PostGIS/GeoServer/OpenLayers stack.


Following opengeo tutorial I've tied click events in OpenLayers to WMS GetFeatureInfo call using:


    map.events.register('click', map, function (e) {
var url = "http://localhost:1979/geoserver/wms"
+ "?REQUEST=GetFeatureInfo"
+ "&EXCEPTIONS=application/vnd.ogc.se_xml"
+ "&BBOX=" + map.getExtent().toBBOX()

+ "&X=" + e.xy.x
+ "&Y=" + e.xy.y
+ "&INFO_FORMAT=text/html"
+ "&QUERY_LAYERS=MYDATA:MYLAYER"
+ "&LAYERS=MYDATA:MYLAYER"
+ "&FEATURE_COUNT=5"
+ "&SRS=EPSG:3857"
+ "&STYLES="
+ "&WIDTH=" + map.size.w
+ "&HEIGHT=" + map.size.h;

window.open(url,
"getfeatureinfo",
"location=0,status=0,scrollbars=1,width=800,height=125"
);
});

I've used GeoServer's FreeMarker templates to format the response correctly. The problem I have is that the response I get returns all of the fields from the layer.


Is there a way to select the ones that are relevant to the user?



Answer



Doesn't look good (source):




... GetFeatureInfo [...] is a WMS request and WFS. [...] One difference in their behaviour is that Geoserver sends always all the attributes with GetFeatureInfo but with WFS the list of attributes can be given in the request.



You could create a view that contains only the attributes your user wants to/should see and serve that through Geoserver.


An alternative would be to adjust die GetFeatureInfo template.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...