0
votes

When using the layer.setOptions function, I need to figure out how to combine two data driven style expressions so that both expressions are respected when using the filter property.

Why? In my project I am filtering the visbility of map objects (features likes shapes, points etc) using layer groups whereby each feature when created or updated, I set a property value with the layer group that it belongs to. So later the user can choose whether turn the visibility on or off for groups of map objects, example below:

enter image description here

In addition to filtering the visbility of my map objects by layer group, I also need to apply a filter so each layer type will only render certain geomtry types. The MS docs explanation on this is shown here:

enter image description here

Now when I set the options for any of the layers used, I need to be able to combine the two filters into one argument-->

The first filter argument would filter the layers by layer groups:

var filter = ['in', ['get', 'layerGroup'], ['literal', layerGroupsArray]]

The second filter would ensure that only certain geomtry types are rendered for that layer:

var filter = ['==', ['geometry-type'], 'LineString']; // other shapes could be 'Polygon' / 'Circle' etc

Note: Using either of the above filters in isolation both work in their own right, but I dont know how to combine both arguments together, its almost like we need a logical AND function, which i tried but the browser debug throws an error:

var combinedFilterExample = ['in', ['get', 'layerGroup'], ['literal', layerGroupsArray]] & ['==', ['geometry-type'], 'LineString'];

enter image description here

enter image description here

1

1 Answers

0
votes

Eventually I found a snippet from the MS Docs that explains how to set the expression so it requires all arguments to be respected, they use the 'all' attribute to do this which i beleive achieves a simialr objective to using an AND logic operator.

So from my original question, we can combine two filter expressions into one argument as follows:

var lineLayerFilter = ['all', ['==', ['geometry-type'], 'LineString'], ['in', ['get', 'layerGroup'], ['literal', layerGroupsArray]]]

If you want to combine more expressions in the argument then we simply add more to the argument, and it looks to be we dont need to add any closing sqaure brackets at the end. Further example:

var polygonOuterLayerFilter = ['all', ['==', ['geometry-type'], 'Polygon'], ['==', ['geometry-type'], 'LineString'], ['in', ['get', 'layerGroup'], ['literal', layerGroupsArray]]]

enter image description here

MS Docs reference here: https://docs.microsoft.com/en-us/azure/azure-maps/data-driven-style-expressions-web-sdk#aggregate-expression