[OpenLayers-Users] feature attribute onload of GeoJSON layer

Robert Sanson Robert.Sanson at asurequality.com
Wed Aug 14 14:05:07 PDT 2013


Hi Aditya

There are a couple of ways. You could either use the OpenLayers GeoJSON format reader to read the response into features that are added to your layer:

var geojson_format = new OpenLayers.Format.GeoJSON();
var olgeo = geojson_format.read(response.responseText);
var geol = new OpenLayers.Layer.Vector("MyLayer",
				{isBaseLayer: false,
				styleMap: geoStyles,
				rendererOptions: {zIndexing: true},
				extractAttributes: true,
				eventListeners: layerListeners});
geol.addFeatures(olgeo);

//All the attributes will now be properties of the features which you than select and display
var layerListeners = {
    featureclick: function(e) {
                   e.feature.renderIntent = "select";
                   e.feature.layer.drawFeature(e.feature);
                   alert(e.feature.attributes.wardid+"|"+e.feature.attributes.ward_no+"|"+e.feature.attributes.ward_name);
    }
};

or you could parse the response within a callback function:

function mycallback(response) {
    var wardid = response.responseText.features[0].properties.wardid;
    var ward_no = response.responseText.features[0].properties.ward_no;
    var ward_name = response.responseText.features[0].properties.ward_name;
    alert(wardid+"|"+ward_no+"|"+ward_name);
}

Regards,

Robert

>>> adityakumar529 <adityakumar529 at gmail.com> 15/08/2013 12:54 a.m. >>>
Hi Users,
    I am loading a layer which is coming as  a result of  query passed to
server. As the layer loads I want the attributes of the layer in alert.
Following is the GeoJSON layer
http://api.ichangemycity.com/readwardboundary?longitude=77.66083409999999&latitude=13.0265715.


Thanks in advance.
Aditya Kumar



-----
GIS Developer
India Urban Space Foundation
--
View this message in context: http://osgeo-org.1560.x6.nabble.com/feature-attribute-onload-of-GeoJSON-layer-tp5072501.html 
Sent from the OpenLayers Users mailing list archive at Nabble.com.
_______________________________________________
Users mailing list
Users at lists.osgeo.org 
http://lists.osgeo.org/mailman/listinfo/openlayers-users



This email and any attachments are confidential and intended solely for the addressee(s). If you are not the intended recipient, please notify us immediately and then delete this email from your system.

This message has been scanned for Malware and Viruses by Websense Hosted Security.
www.websense.com


More information about the Users mailing list