<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="#ffffff" text="#000000">
Hi list,<br>
<br>
instances of OpenLayers.Vector have a method getFeatureBy(property,
value) that was introduced in revision 10691 [1] and lives in 2.10.
This method returns the <b>first</b> feature that has the property
set to the given value.<br>
<br>
Wouldn't it make more sense to have a function getFeature<b>s</b>By(property,
value) that returns an <b>array</b> of matching features?<br>
<br>
AFAICT vector layers also do not provide a method to get features
that have a certain attribute set to a given value. I propose a new
method getFeaturesByAttribute(attrName, attrValue, strict) that
would scan the attributes of features for matching candidates and
eventually return those as an array (see [2] for a hardly tested
implementation). <br>
<br>
What do you think? <br>
<br>
I have working code for both methods and would gladly share it
(Although I would need to develop tests).<br>
<br>
Regards and thanks for comments,<br>
<br>
Marc<br>
<br>
<br>
[1]
<a class="moz-txt-link-freetext" href="http://trac.osgeo.org/openlayers/changeset/10691/trunk/openlayers/lib/OpenLayers/Layer/Vector.js">http://trac.osgeo.org/openlayers/changeset/10691/trunk/openlayers/lib/OpenLayers/Layer/Vector.js</a><br>
<br>
[2]<br>
OpenLayers.Layer.Vector.prototype.getFeaturesByAttribute = function
getFeaturesByAttribute(attrName, attrValue, strict) {<br>
var i,<br>
feature,<br>
doStrictComparison = !!(typeof strict !== 'undefined'),<br>
useAttrValue = !!(typeof attrValue !== 'undefined'),<br>
len = this.features.length, <br>
foundFeatures = [];<br>
for( i = 0; i < len; i++ ) {<br>
feature = this.features[i];<br>
if(feature && feature.attributes && typeof
feature.attributes[attrName] !== 'undefined'){<br>
if (useAttrValue) {<br>
if (doStrictComparison) {<br>
if ( feature.attributes[attrName] === attrValue)
{<br>
foundFeatures.push(feature);<br>
}<br>
} else {<br>
if ( feature.attributes[attrName] == attrValue)
{<br>
foundFeatures.push(feature);<br>
}<br>
}<br>
} else {<br>
foundFeatures.push(feature);<br>
}<br>
}<br>
}<br>
return foundFeatures;<br>
};<br>
</body>
</html>