Using Openlayers.....Is it possible to select a feature on a map by an attribute? eg: Select a feature from a dropdown menu populated with the feature "id" or a table field attribute values.
Answer
You can either use the getFeaturesByAttribute method, or loop through the layer's features array:
for(var f=0;f if(layer.features[f].attributes.someAttribute == 'desiredValue') {
selectFeatureControl.select(layer.features[f]);
break;
}
}
This assumes you have an active instance of OpenLayers.Control.SelectFeature named "selectFeatureControl", a vector layer named "layer" and you are looking for feature having someAttribute loosely equal to 'desiredValue'. If you have to consider not only the value but also data type (as getFeaturesById does), replace == with ===.
No comments:
Post a Comment