How can I attach some unique data to a feature in openlayers and then reference it? I have seen lots of examples where data can be set before the map is loaded but none when the features are being set through a click control.
I have my control which draws the point but I want to add some data to it and then reference it later within the onclick popup. feature.somedata is just to show where I would want it to be referenced.
supp: new OpenLayers.Control.DrawFeature(featuresLayer,OpenLayers.Handler.Point)
"<div style='font-size:.8em'>Feature: " + feature.id + "<br/> Some data:"+feature.somedata+"."+"<br/></div>",
There is a attribute for this called feature.attributes. The data that is loaded is stored there. So you just have to put like:
feature.attributes = { "somedata" : "value", "unique_id": "x"};
Did it answered your question?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With