Give Layer.Vector a getFeatureByFid and a getFeatureBy method. Thanks vog for this very clean patch and the verbose unit tests. r=me (closes #2722)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@10691 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -823,30 +823,61 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
|
||||
var featureId = this.renderer.getFeatureIdFromEvent(evt);
|
||||
return this.getFeatureById(featureId);
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* APIMethod: getFeatureById
|
||||
* Given a feature id, return the feature if it exists in the features array
|
||||
* APIMethod: getFeatureBy
|
||||
* Given a property value, return the feature if it exists in the features array
|
||||
*
|
||||
* Parameters:
|
||||
* featureId - {String}
|
||||
* property - {String}
|
||||
* value - {String}
|
||||
*
|
||||
* Returns:
|
||||
* {<OpenLayers.Feature.Vector>} A feature corresponding to the given
|
||||
* featureId
|
||||
* property value or null if there is no such feature.
|
||||
*/
|
||||
getFeatureById: function(featureId) {
|
||||
getFeatureBy: function(property, value) {
|
||||
//TBD - would it be more efficient to use a hash for this.features?
|
||||
var feature = null;
|
||||
for(var i=0, len=this.features.length; i<len; ++i) {
|
||||
if(this.features[i].id == featureId) {
|
||||
if(this.features[i][property] == value) {
|
||||
feature = this.features[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return feature;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* APIMethod: getFeatureById
|
||||
* Given a feature id, return the feature if it exists in the features array
|
||||
*
|
||||
* Parameters:
|
||||
* featureId - {String}
|
||||
*
|
||||
* Returns:
|
||||
* {<OpenLayers.Feature.Vector>} A feature corresponding to the given
|
||||
* featureId or null if there is no such feature.
|
||||
*/
|
||||
getFeatureById: function(featureId) {
|
||||
return this.getFeatureBy('id', featureId);
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: getFeatureByFid
|
||||
* Given a feature fid, return the feature if it exists in the features array
|
||||
*
|
||||
* Parameters:
|
||||
* featureFid - {String}
|
||||
*
|
||||
* Returns:
|
||||
* {<OpenLayers.Feature.Vector>} A feature corresponding to the given
|
||||
* featureFid or null if there is no such feature.
|
||||
*/
|
||||
getFeatureByFid: function(featureFid) {
|
||||
return this.getFeatureBy('fid', featureFid);
|
||||
},
|
||||
|
||||
/**
|
||||
* Unselect the selected features
|
||||
* i.e. clears the featureSelection array
|
||||
|
||||
Reference in New Issue
Block a user