我正在尝试从 geojson 文件过滤添加到地图中的图层。每次我单击按钮来过滤地图时,它都会隐藏整个图层,而不是该图层上的单个元素。有人可以告诉我哪里出了问题/不理解 .setFilter()
我尝试了多种使用过滤器的方法,例如map.setFilter('allBuildings', ['==', 'properties.name', 'buildingone']);
但是,它仍然隐藏了整个图层。如果有人能将我推向正确的方向,我将不胜感激。谢谢
这里我将源和图层添加到地图中,一切正常。
map.addSource('buildings', {type: 'geojson', data: '/buildings.geojson'});
map.addLayer({
"id": "allBuildings",
"type": "symbol",
"source": "buildings",
"layout": {
"icon-image": "marker-building",
"icon-size": 0.25
}
});
然后我尝试使用
过滤图层map.setFilter('allBuildings', ['>', 'properties.height', '30']);
此时,它会隐藏图层,而不仅仅是高度大于 30 的对象。
这是我的 geojson 文件的一部分。
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"name": "buildingone",
"height": "52",
},
"geometry": {
"type": "Point",
"coordinates": [
114.1454573,
22.2760386
]
}
}
]
}