What I try to achieve is quite simple. I want to filter my vector layer by a query in the features. What I found out is that vector layer doesn't have updateParams() where I could do something like:

'layerDefs': featureName1+operatorName1+checkValue1 

So is there an other way to achieve this? Cause now I`m kinda clueless on how to filter a vector layer. Every way is welcome, the vector is already made so it's not a new vector layer.

I`m working with OpenLayers3 and ArcGIS featureservice.

I`m also not sure how to redraw the vector after it's filtered yet. All of my vectors are saved in an array.

I tried everything but sadly i couldn't get it to work. this is what i tried in the end. Last try is underneath with help of the suggestion from @Alexis_A

Okay after some more testing i found the problem, for some reason it gives the name of my variable and not the value that contains my variable. So in other words this bit of code:

var fn = featureName1;
var filtered = features.filter(function(feature) {
    return feature.values_.featureName1 == 2;

will littarly give this as console log:


Object { pendingRemovals_: Object, dispatching_: Object, listeners_: Object, revision_: 2, ol_uid: 90, values_: Object, id_: 158816, geometryName_: "geometry", style_: null, styleFunction_: undefined, 2 meer… }

TypeError: feature.values_.fn is undefined[Meer info]

So at first it knows what the variable should be, but when i`m in the filter function it's just clueless. Anyone any idea on how to fix this?

And why is filtering in OpenLayers3 so hard i just can't understand that they dont have an easier way to do it.

1 Answer 1


Well it took me some time but i managed to make a sort of a working filter on vectorSource but it works for like half a second then it get's back to normal again. The code i used for that is this:

var vectorSource = mapLayersArray[0].getSource();
var features = vectorSource.getFeatures();
var filtered = features.filter(function(feature) {
    return feature.values_[featureName1] == checkWaarde1;
var length = filtered.length;
for (var i = 0; i < length; i++) {

But as said it shows the filter for only like half a second for some(update,refresh,panning,zooming) reason i`m not sure of why.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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