Say I have a vector layer with a couple hundred features, and I just want to operate on a filtered subset of those features, such as those that have a State attribute of "OR".

Am I reading the OL docs correctly that the Filter classes are only for filtering WFS requests? Is there some other way of filtering ordinary features by a specific attribute (e.g. for zooming to the extent of just those features)?

Or do I have to just manually iterate over the features and populate an array of the desired ones? (Not a huge deal, by the way; just wondering if there's a more OpenLayers-y way of doing this).

1 Answer 1


I iterate all the time and it seems fine as far as speed is concerned. It might be easiest too.

You can also use the filter for other OGC standards such as WMS, GML, and KML.

You can also use it with a filter strategy:

setFilter: function({OpenLayers.Filter})

This will re-evaluate any features on the layer and in the cache. Only features for which filter.evalute(feature) returns true will be added to the layer. Others will be cached by the strategy.

Please look at http://openlayers.org/dev/examples/filter-strategy.js


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.