I'm using a select interaction. I can filter the layers which are selectable using a filter function as the layers option key. I want to also filter which features are selectable.

The documentation says "Which features are selected is determined by the condition option". I am therefore trying to write a function for the condition option which can filter out particular features. But I'm not sure it's possible. I think the quoted documentation may be misleading.

The condition function takes an event argument. I first filter out any events which aren't of the click type, but then I want to filter on features. The event has a target property, but it's not clear to me what this is pointing to. It doesn't appear to be a layer or a feature.

I do have the pixel coordinates and the map coordinates at the clicked point. I could use either of these to loop over features at that point in the layer and, if I deem one of them selectable, return true. But what if there are two overlapping features, one of which I want to be selectable and one not?

I'm guessing this condition option is not what I'm looking for, since it is run once per event, not once per possible feature. Is there a way to achieve what I'm looking for?

2 Answers 2


The feature made it into Openlayers 3 master branch recently from https://github.com/openlayers/ol3/pull/3402 -- it'll be in 3.5.0. The following is working for me:

var selectInteraction = new ol.interaction.Select({
    layers: function(layer) {
        return /* some logic on layer to decide if its features should be considered; return true if yes */;
    filter: function(feature, layer) {
        return /* some logic on a feature and layer to decide if it should be selectable; return true if yes */;

There seems to be a lot of discussion regarding this here: https://github.com/openlayers/ol3/issues/3257

  • Thanks for that. From github.com/openlayers/ol3/pull/3277 (linked from the above) it seems that the feature should be available as a filter option to the select interaction with release 3.4.0.
    – tremby
    Mar 25, 2015 at 20:23

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.