Give Layer.Vector a method getFeaturesByAttribute, p=marcjansen, r=me (closes #2979)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@10960 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Éric Lemoine
2010-12-14 08:07:29 +00:00
parent b351734cf6
commit 1ff89a9c40
2 changed files with 107 additions and 0 deletions

View File

@@ -876,6 +876,36 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
getFeatureByFid: function(featureFid) {
return this.getFeatureBy('fid', featureFid);
},
/**
* APIMethod: getFeaturesByAttribute
* Returns an array of features that have the given attribute key set to the
* given value. Comparison of attribute values takes care of datatypes, e.g.
* the string '1234' is not equal to the number 1234.
*
* Parameters:
* attrName - {String}
* attrValue - {Mixed}
*
* Returns:
* Array(<OpenLayers.Feature.Vector>) An array of features that have the
* passed named attribute set to the given value.
*/
getFeaturesByAttribute: function(attrName, attrValue) {
var i,
feature,
len = this.features.length,
foundFeatures = [];
for(i = 0; i < len; i++) {
feature = this.features[i];
if(feature && feature.attributes) {
if (feature.attributes[attrName] === attrValue) {
foundFeatures.push(feature);
}
}
}
return foundFeatures;
},
/**
* Unselect the selected features