Openlayers:select 来自 GeoJson 的编程功能
Openlayers: select a feature programmatically from GeoJson
我正在做一个使用openlayers(2.14版)显示Bing图层(GeoJSON格式)的项目,我读取GeoJSON和显示功能没有问题,但我想select 以编程方式显示特征,例如,有一个 table 显示所有特征属性(GeoJSON format.sample:
{"type": "FeatureCollection",
"features": [ {"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[-7923751.4232522,5233536.7371399]},"crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:OGC:1.3:CRS84"}}}
], }
),当我单击 table 中的一行时,我想 select 或使用该行中的 GEOJSON 数据突出显示地图上的特定要素。
我该怎么做?
谢谢
您可以使用方法"getFeaturesByAttribute"
或遍历所有特征:
for(var i = 0; i < yourgeojsonlayer.features.length; i++) {
if(yourgeojsonlayer.features[i].attributes.searchedAttribute == 'searchedValue')
{ selectFeatureControl.select(yourgeojsonlayer.features[i]); break; }
}
Ps:需要先创建一个select控件并分配你在for循环中使用的变量名(这里是selectFeatureControl)
在此处查看我的示例:http://jsfiddle.net/expedio/sh9wv4m7/ and http://jsfiddle.net/3p5q0ybh/
我正在做一个使用openlayers(2.14版)显示Bing图层(GeoJSON格式)的项目,我读取GeoJSON和显示功能没有问题,但我想select 以编程方式显示特征,例如,有一个 table 显示所有特征属性(GeoJSON format.sample:
{"type": "FeatureCollection", "features": [ {"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[-7923751.4232522,5233536.7371399]},"crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:OGC:1.3:CRS84"}}} ], }
),当我单击 table 中的一行时,我想 select 或使用该行中的 GEOJSON 数据突出显示地图上的特定要素。
我该怎么做?
谢谢
您可以使用方法"getFeaturesByAttribute"
或遍历所有特征:
for(var i = 0; i < yourgeojsonlayer.features.length; i++) {
if(yourgeojsonlayer.features[i].attributes.searchedAttribute == 'searchedValue')
{ selectFeatureControl.select(yourgeojsonlayer.features[i]); break; }
}
Ps:需要先创建一个select控件并分配你在for循环中使用的变量名(这里是selectFeatureControl)
在此处查看我的示例:http://jsfiddle.net/expedio/sh9wv4m7/ and http://jsfiddle.net/3p5q0ybh/