我有一个包含多个多边形的 geojson。每个多边形都有一个名称。我想显示除“boundingBox”之外的所有多边形。我在 addLayer() 中使用过滤器:
"filter": ["all",["==", "$type", "Polygon"],["!=",["string", ['get', 'name'],""], "boundingBox"]]
但没有出现多边形。
如果我这样做:
"filter": ["==", "$type", "Polygon"]
显示所有多边形。
这里出了什么问题?
最佳答案
看起来您混合使用了已弃用的过滤器语法 ($type
) 和表达式语法,这是不允许的。
Expression syntax and the deprecated syntax below cannot be mixed in a single filter definition. https://docs.mapbox.com/mapbox-gl-js/style-spec/#other-filter
尝试
"filter": ["all",["==", ["geometry-type"], "Polygon"],["!=",["string", ['get', 'name'],""], "boundingBox"]]
关于javascript - 我的带有 "all"运算符的 Mapbox 表达式有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56833912/