class cgxp.plugins.GetFeature(config)

With this plugin we can query the map with a simple click (WMS GetFeatureInfo) or with a CTRL-Drag for a box query (WFS GetFeature). We can optionally (with actionTarget) add a toggle button to a toolbar to do a box query without pressing the CTRL key.

Only the currently visible layers are queried.

For a WMS layer the feature types sent in the WFS GetFeature query are obtained from its layers parameter.

For a layer of another type (layer that does not have a layers parameter), the feature types are obtained from the layer’s queryLayers option if it is defined, and from its mapserverLayers option if queryLayers is not defined.

Here’s an example on how to use the queryLayers option in a layer config:

queryLayers: [{
    name: "buildings",
    identifierAttribute: "name",
    maxResolutionHint: 6.6145797614602611
}, {
    name: "parcels",
    identifierAttribute: "number",
    maxScaleDenominator: 10000

If there are OpenLayers WMS layers including feature filters (featureFilter property on the layer), then these filters are evaluated for each feature received in the WMS GetFeatureInfo and WFS GetFeature responses. Features that do not pass the filter are excluded from the features array passed in the queryresults event.

var layer = ...; // an OpenLayers layer
var filter = ...; // an OpenLayers filter
layer.featureFilter = filter

// This can be used in conjonction with the GetMap request SLD parameter
layer.mergeNewParams({ SLD: url }); // where the SLD file corresponds to the OpenLayers filter

Example Use

Sample code showing how to add a GetFeature plugin to a gxp.Viewer:

// WFS namespace, depends of the backend used, default is for Mapserver
cgxp.WFS_FEATURE_NS = "";

new gxp.Viewer({
    tools: [{
        ptype: "cgxp_getfeature",
        actionTarget: "center.tbar",
        toggleGroup: "maptools",
        events: EVENTS,
        themes: THEMES,
        mapserverURL: "${request.route_url('mapserverproxy')}",
        WFSTypes: ${WFSTypes | n},
        externalWFSTypes: ${externalWFSTypes | n},
        enableWMTSLayers: true

The min/maxResolutionHint can be computed with the following rule:

1 / (1 / 25000 * 39.3701 * 96)

Or you can use min/maxScaleDenominator as set in MapServer.

Config Options

Configuration properties.


Object Action options


String or null Where to place the optional tool button. If set to null, no button is displayed (default is null).


String The name of the activate toggle group this tool is in. Default is “clickgroup”.


Boolean Deactivate the tool after query. Default is true.


Boolean Set to true to make point requests handled by WFS GetFeature instead of WMS GetFeatureInfo. Default is false.


Boolean Set to true to run an additional WFS request to get the total number of hits when the maxFeatures limit as been reached by a WFS GetFeature request. Default is true.


Boolean If true, WMTS layers will be queried as well.


Object An Observer used to send events.


Array The queryable type on the parent server.


String The geometry name.


String The mapserver proxy URL


Integer Limit of features returned by mapserver. Default is 200.


Object List of internal and external themes and layers. (The same object as that passed to the cgxp.plugins.LayerTree).


String If this tool should be radio-button style toggled with other tools, this string is to identify the toggle group.


Array The queryable type on the internal server.

Table Of Contents

Previous topic


Next topic


This Page

Fork me on GitHub