[OpenLayers-Dev] Layer.Vector: getFeatureBy and getFeaturesByAttribute

Eric Lemoine eric.lemoine at camptocamp.com
Sat Dec 11 16:29:11 EST 2010


On Thu, Dec 9, 2010 at 6:16 PM, Marc Jansen <jansen at terrestris.de> wrote:
> Hi list,

Hi Marc

> 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 first feature that has the property set to the given value.
>
> Wouldn't it make more sense to have a function getFeaturesBy(property,
> value) that returns an array of matching features?

I think getFeatureBy was just introduced for the purpose of
getFeatureById and getFeatureByFid, and id and fid are primary keys
here. I'm even wondering if it should be part of the API.

> 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).
>
> What do you think?

I would personally not add such a function to the library. My reason:
coding this function is easy enough, so I'd leave its implementation
to the application developer, thereby avoiding bloating OpenLayers
with code that most application developers won't need. Also, by having
this function in the application code, you will probably not need the
"strict" argument and the logic that goes with it in the core of the
function, so this will result in fewer bytes of JavaScript, overall.

Just my personal view of things.

-- 
Eric Lemoine

Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex

Tel : 00 33 4 79 44 44 96
Mail : eric.lemoine at camptocamp.com
http://www.camptocamp.com


More information about the Dev mailing list