Javascript 如何基于属性值过滤MapBox热图中的点?

Javascript 如何基于属性值过滤MapBox热图中的点?,javascript,mapbox,geojson,Javascript,Mapbox,Geojson,假设我有一个基本的地图盒热图。生成此热图的矢量平铺的geojson如下所示: {"type":"FeatureCollection", "features":[ {"type":"Feature","properties":{"dbh":0, "icon-type": "bike"},"geometry":{"type":"Point","coordinates":[-79.91746,40.44356]}}, {"type":"Feature","p

假设我有一个基本的地图盒热图。生成此热图的矢量平铺的geojson如下所示:

{"type":"FeatureCollection",
    "features":[
         {"type":"Feature","properties":{"dbh":0, "icon-type": "bike"},"geometry":{"type":"Point","coordinates":[-79.91746,40.44356]}},
         {"type":"Feature","properties":{"dbh":12, "icon-type": "bike"},"geometry":{"type":"Point","coordinates":[-79.94606,40.44961]}},
         {"type":"Feature","properties":{"dbh":6, "icon-type": "cat"},"geometry":{"type":"Point","coordinates":[-79.96474,40.46283]}},
         {"type":"Feature","properties":{"dbh":2, "icon-type": "dog"},"geometry":{"type":"Point","coordinates":[-80.00949,40.42532]}}
     ]
}
我了解如何根据此处的教程显示热图:

请注意,geojson中的每个特性都有一个图标类型属性。我想动态地告诉我的热图只显示数据中具有特定图标类型值的点,例如“bike”或“cat”


如何实现这一点?

您可以在层配置中使用,如中所使用的

在您的情况下,它将类似于:

map.addLayer({
  id: 'heatmap-layer',
  type: 'heatmap',
  source: 'your-source',
  paint: { ... },
  filter: ['==', ['get', 'icon-type'], 'cat']
});
“==”
只允许下两个参数相等的功能

'get'
用于访问功能属性,因此
['get','icon type']
解析为功能的
图标类型
属性

“cat”是一个字符串literal