openlayers:为特征添加唯一数据并引用它

use*_*246 4 controls openlayers

如何将某些唯一数据附加到openlayers中的某个功能部分然后引用它?我已经看到很多例子可以在加载地图之前设置数据,但是在通过点击控件设置要素时没有.

我有我的控制权,但是我想向它添加一些数据然后在onclick弹出窗口中引用它.feature.somedata只是为了显示我希望它被引用的位置.

supp: new OpenLayers.Control.DrawFeature(featuresLayer,OpenLayers.Handler.Point) 

"<div style='font-size:.8em'>Feature: " + feature.id + "<br/> Some data:"+feature.somedata+"."+"<br/></div>",
Run Code Online (Sandbox Code Playgroud)

小智 8

这个名为feature.attributes的属性.加载的数据存储在那里.所以你只需要像:

feature.attributes = { "somedata" : "value", "unique_id": "x"};
Run Code Online (Sandbox Code Playgroud)

它回答了你的问题吗?

  • (+1)可以存储在“ feature.attributes”或“ feature.data”中 (2认同)