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. Any help would be greatly appreciated.
e
in yourselectid(e)
function? Can to use browser debuggers to intercept thegetfeatureinfo
request to your geoserver and the response? Geoservers logs could provide some insight as well if these aren't conclusive. – Jason Koopmans