Jesus Loves GRASS

Technical blog about GRASS/GIS,open source geoinformatics and MAPSERVER.

Tuesday, September 29, 2009

WMS/WFS getfeature on hover, problem to display the GML (mapserver)

I had a hard time programming something similar to the "WFS GetFeature Example" shown in the OpenLayers examples, the example uses calls to a WFS/WMS services that have the same name and data origin.

The WFS/WMS service call is done with the OpenLayers.Protocol.WFS.fromWMSLayer as follows (the layerWMS is a OpenLayrs.Layer.WMS object)

control = new OpenLayers.Control.GetFeature({
protocol: OpenLayers.Protocol.WFS.fromWMSLayer(layerWMS),
hover: true
});

Using firebug it is possible to see the requests going back-and-forward when hovering the polygons, but in the end the polygons aren't select, because trigger-events aren't called.

The problem is cause by the namespace used in the WFS of mapserver (since the example given in the web site uses geoserver, everything is ok), the solution is to indicate the namespace and featureTypeName.

In my mapserver response I have something like this:
<gml:featureMember>
<ms:wdpa gml:id="wdpa.67886">

Therefore control has to be changed as follows:

control = new OpenLayers.Control.GetFeature({
protocol: OpenLayers.Protocol.WFS.fromWMSLayer(layerWMS,{featureType:"wdpa",featurePrefix:"ms"}),
hover: true
});


It seems that the same has to be done for the standard WFS layer when using mapserver.

Labels: , , ,