1

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;
console.log(fn);
var filtered = features.filter(function(feature) {
    console.log(feature);
    console.log(feature.values_.fn.value);
    return feature.values_.featureName1 == 2;
});

will littarly give this as console log:

categorie_melding

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

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) {
    //console.log(feature.values_);
    return feature.values_[featureName1] == checkWaarde1;
});
vectorSource.clear();
var length = filtered.length;
for (var i = 0; i < length; i++) {
    vectorSource.addFeature(filtered[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.