Reputation: 13
I am working on a project that uses openlayers (version2.14)to display a Bing layer(GeoJSON format), I have no problem reading the GeoJSON and display features, but I want to select a feature programmatically, for example, there is a table displaying all the features attributes(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"}}} ], }
), when I click a row from the table, I want to select or highlight a specific feature on the map using the GEOJSON data in that row.
How can I do that?
Thanks
Upvotes: 0
Views: 1433
Reputation: 165
You could use the method "getFeaturesByAttribute"
or iterate through all features:
for(var i = 0; i < yourgeojsonlayer.features.length; i++) {
if(yourgeojsonlayer.features[i].attributes.searchedAttribute == 'searchedValue')
{ selectFeatureControl.select(yourgeojsonlayer.features[i]); break; }
}
Ps: makes necessary to create a select control first and assign the variable name you use in the for loop (here selectFeatureControl)
See my examples here: http://jsfiddle.net/expedio/sh9wv4m7/ and http://jsfiddle.net/3p5q0ybh/
Upvotes: 2