4

I am trying to write a filter that will match on values from several properties of a layer.

For example, in my hypothetical layer of breweries, I'd like to match those breweries that have a state name of Utah, Texas or Florida and a brewery type of Irish or American.

I can filter on state like this

var stateFilter = ['match', ['get', 'stateNam'], ['Utah','Texas','Florida'], true, false]
map.setFilter('breweriesLayer',stateFilter)

Or on brewery type like this

var typeFilter = ['match', ['get', 'breweryType'], ['Irish','American'], true, false]
map.setFilter('breweriesLayer',typeFilter)

How can I combine the two examples above into one filter? I looked at using expressions and concatenation of fields but in my actual use case, I have several fields with 100s of possible values, making the expressions cumbersome.

1 Answer 1

7

Looks like I had some of my expressions logic mixed up with my filter logic. Anyhow, this works

var breweryFilter=[
    "all",
    ["in", "stateNam", 'Utah','Texas','Florida'],
    ["in", "breweryType", 'Irish','American']
]
map.setFilter('breweriesLayer',breweryFilter)

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.