0

I am trying to get a WMSGetFeatureInfo request to work on my MapServer WMS layer but I am not sure how to correctly configure my map file and the request in OpenLayers.

I have setup a jsFiddle with my WMS overlay and the WMSGetFeatureInfo request.

http://jsfiddle.net/goldrydigital/YBWRz/

The request is as follows:

var getFeatureInfo = new OpenLayers.Control.WMSGetFeatureInfo({
    url: 'http://137.117.37.130:8081/cgi-bin/mapserv.exe?map=c:/ms4w/wms_sample.map&', 
    title: 'Identify features by clicking',
    layers: 'estados'
})
getFeatureInfo.events.register('getfeatureinfo', map, function (e) {
    alert(e.text);
});
map.addControl(getFeatureInfo);
getFeatureInfo.activate();

The layer takes the data from a Mapinfo tab file. The Layer definition in the Map file is as follows:

    LAYER

    NAME "estados"
    TYPE POLYGON
    STATUS ON
    CONNECTIONTYPE OGR
    CONNECTION "estados.tab"
    TEMPLATE "blank.html"
    DUMP TRUE

    CLASS

        OUTLINECOLOR 10 10 10

    END
    METADATA

        "wms_title"          "estados"
        "gml_geometries"     "geom"
        "gml_geom_type"      "polygon"
        "gml_include_items"  "all"
        "wms_include_items"  "all"
        "wms_feature_info_mime_type" "text/plain"

    END

    END

Can you put me in the right direction with this?

2 Answers 2

1

In your WMSGetFeatureInfo constructor, the value of the layers property should be an array of layer objects, not the name of the layer.

1
  • Thanks a lot. I can't vote up due to lack of rep but give you the correct answer since you posted first. Commented May 15, 2014 at 15:07
1

@drunkenwagoner is correct.

Your call to WMSGetFeatureInfo should look like this

var getFeatureInfo = new OpenLayers.Control.WMSGetFeatureInfo({
    url: 'http://137.117.37.130:8081/cgi-bin/mapserv.exe?map=c:/ms4w/wms_sample.map&', 
    title: 'Identify features by clicking',
    layers: [estadosMexico]
})

The important change being that layers is now associated with [estadosMexico] (rather than "estados" as it was before).

Here's an update of your jsFiddle that does what you were trying to do (shows the alert window when you click on a feature).

1
  • Spot on. Thanks a lot. I got really stuck with this one. Commented May 15, 2014 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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