为特定 属性 mapbox gl js 的多个值过滤特征层

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]]

试试这个:

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

您可以在此页面上阅读有关 Mapbox GJ JS 表达式的更多信息: https://docs.mapbox.com/mapbox-gl-js/style-spec/expressions/#match

有时您可以在 Mapbox Studio 中进行编辑,以检查后面的代码以便稍后在 JS 中重用。 截图:https://ibb.co/z5D8rh3

可以通过三种方式做到这一点:

match

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

in:

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

any:

"filter" : [
  "any", 
  ["==", ["get", "COUNTY"], "County1"],
  ["==", ["get", "COUNTY"], "County2"],
  ...
]