Saturday, 3 December 2016

javascript - Filter on features in a vector layer


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.




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...