Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

openlayers: adding unique data to a feature and referencing it

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>",
like image 585
user1142246 Avatar asked Jan 11 '12 04:01

user1142246


1 Answers

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?

like image 187
Arthur Avatar answered Sep 26 '22 23:09

Arthur