1

I am serving up a WMS layer from GeoServer in OpenLayers and am trying to extract a specific attribute from an object in this layer when I click on the map.

I am defining my WMS layer like this:


       oas = new OpenLayers.Layer.WMS(
       "oas",
       "http://www.bwgeoserver.com/geoserver/UK_Admin/wms",
        {
          "LAYERS": 'wealthmap_bdy',
          transparent: 'true',
          extractAttributes: 'true'
        },
        {
          buffer: 0,
          opacity: 1,
          displayOutsideMaxExtent: true,
          isBaseLayer: false
        }
        );

map.addLayer(oas);

The layer is displaying OK on the map. I am using a proxy server and there isn't a cross-domain problem as I can select and display all of the attributes in a popup. "OA11Code" is definitely a field on the WMS layer, and it displays OK with the other attributes in the popup.

But when I try to extract this attribute from the selected object using this code:


oaPicker = new OpenLayers.Control.WMSGetFeatureInfo({
             url: 'http://www.bwgeoserver.com/geoserver/UK_Admin/wms',
             title: 'identify features on click',
             layers: [oas],
             queryVisible: true
         });

   oaPicker.events.register('getfeatureinfo', this, selectid);
   map.addControl(oaPicker);
   oaPicker.activate();

   function selectid(e) {
     var val = e.features[0].attributes.OA11Code;
   }

I get an error in the Firefox debugger saying: "TypeError: e.features[0] is undefined".

All I want is to be able to click on the map, extract the value of an attribute from the WMS layer, assign it to a JavaScript variable and do something with it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.