[OpenLayers-Users] WMSGetFeatureInfo returns zero features but correct response.

Paul Meems bontepaarden at gmail.com
Tue Aug 13 13:34:34 PDT 2013


I'm trying to format the attributes of a WMS layer myself.
The WMS layer is made from a shapefile using Geoserver.
Using Google I found this piece of code:

            var infoControl = new OpenLayers.Control.WMSGetFeatureInfo({
              url: serverLocation,
              title: 'Get data',
              queryVisible: true,
              infoFormat: 'application/vnd.ogc.gml',
              output: 'features',
              eventListeners: {
                getfeatureinfo: function(event) {
                  console.log(event.features.length);
                  for (var i = 0; i < event.features.length; i++) {
                    var feature = event.features[i];
                    var attributes = feature.attributes;
                    console.log(attributes);
                    document.getElementById('info').innerHTML =
attributes[0];
                  }
                }
             }
          });
          map.addControl(infoControl);
          infoControl.activate();

This doesn't do anything because event.features.length is zero.
When I change the infoFormat to text and put event.text in my div I get the
default formatted table.
So the response is correct.
When I use Firebug and look at the response of the GET that is send, I see
my data in xml format.

So what am I missing that I cannot parse that xml into the event.features
class.

Thanks,

Paul
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20130813/3ff831ec/attachment.html>


More information about the Users mailing list