Skip to content
Advertisement

filter a featurelayer for several values of a specific property mapbox gl js

I’d like to filter a feature layer for several values of a specific property, something like

"filter":["==","COUNTY",[array of filter values]]

Advertisement

Answer

There are three ways to do this:

With match

"filter" : [
  "match",
  ["get", "COUNTY"],
  ["County1", "County2", ... ],
  true,
  false
]

With in:

"filter" : [
  "in", 
  ["get", "COUNTY"],
  ["literal", ["County1", "County2", ... ]]
]

With any:

"filter" : [
  "any", 
  ["==", ["get", "COUNTY"], "County1"],
  ["==", ["get", "COUNTY"], "County2"],
  ...
]
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement