9

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?

7

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.

  • 2
    displaying or not displaying is one thing but radek want to return only some fields values. It makes a big difference regarding transfered data and security aspects. – simo Feb 10 '11 at 14:09
  • 2
    That's why my first suggestion was to create a view. – underdark Feb 10 '11 at 14:33
  • More on using VIEWs here. – radek Oct 10 '11 at 15:36
7

Just don't include the fields you don't want in your freemarker template. See http://docs.geoserver.org/trunk/en/user/tutorials/GetFeatureInfo/index.html#custom-templates

5

You can do this using the GeoServer propertyName WMS request parameter:

http://docs.geoserver.org/stable/en/user/services/wms/vendor.html#propertyname

  • For me this is the best solution! 1. Very simple! 2. I even have the possibility from other applications to make a full featureInfo. With the templates it isn´t possible any more! 3. And last but not least the network traffic is much smaller then requesting complete feature! Tank-you! – marcel Nov 11 '16 at 15:11
0

You can add conditional statements to freemarker templates.

For example in your content.ftl file you can add something like this to only list "YOUR_FIELDNAME".

<#if attribute.name == "YOUR_FIELDNAME">
     <li>${attribute.name}: ${attribute.value}</li>
</#if>

Alternatively you can exclude a field by doing this:

<#if !attribute.name == "YOUR_FIELDNAME">
     <li>${attribute.name}: ${attribute.value}</li>
</#if>
-2

What about this?

Also, for this to return attributes (and not just the layer name and feature id) you have to add "ows_include_items" "attribute1, attribute2, ..., attributeN" or "ows_include_items" "all" to the metadata section of your WMS layer's map file entry.

From : http://trac.osgeo.org/openlayers/wiki/GetFeatureInfo

  • But Radek uses Geoserver, not UMN Mapserver, so there is no map file. – underdark Feb 10 '11 at 13:17
  • 1
    I've seen that. I've never used geoserver but I guess there is one way to set metadata as well, no? – simo Feb 10 '11 at 13:27

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.