OpenLayers – Implementing GetFeatureInfo for GeoServer Layer Groups

geoservergetfeatureinfoopenlayers-2

I've created a GeoServer layer group. I'm using OpenLayers.Layer.WMS to retrieve the layer group, and this works fine. In addition, I'd like to pull feature info for the layer. For this, I'm using OpenLayer's GetFeatureInfo. But the GetFeatureInfo only returns feature info for only one of the layers in the layer group. Is there a way I can retrieve feature info for both layers in the group? And, is this an optimal way of dealing with layer groups?

A section of my code is shown below:

    var layer_group = new OpenLayers.Layer.WMS(
        "Sample Layer Group",
        "http://localhost:8081/geoserver/wms",
        {layers: "layer_group_name", transparent: true},
        {isBaseLayer: false, visibility: false}
    );
    map.addLayers([layer_group]);

to retrieve the layer group.

And:

    map.events.register('click', map, function (e) {
        var url =  layer_group.getFullRequestString({
            REQUEST: "GetFeatureInfo",
            EXCEPTIONS: "application/vnd.ogc.se_xml",
            BBOX: layer_group.map.getExtent().toBBOX(),
            X: e.xy.x,
            Y: e.xy.y,
            INFO_FORMAT: 'text/html',
            QUERY_LAYERS: layer_group.params.LAYERS,
            WIDTH: layer_group.map.size.w,
            HEIGHT: layer_group.map.size.h});

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

To retrieve the feature info.

My environment setup: GeoServer 2.1.3, PostGIS 1.5, OpenLayers 2.11.

EDIT: The features shown are only for one layer
enter image description here

Increasing FEATURE_COUNT only increases the number of instances(rows) returned. The instances are over 1M. What I'd like to achieve is have one row having feature info for all the layers in the layer group.

Best Answer

GetFeatureInfo by default (per WMS standard) just returns one result, if you want more add FEATURE_COUNT to your request, e.g.:

FEATURE_COUNT: 50

Related Question