在Mapbox GL JS中以多种类型呈现GeoJSON文件中的FeatureCollection
我们目前正在从geojson数据将图层加载到mapbox GL中。如果我们的geojson有一个包含点和多边形的要素集合,那么似乎没有办法让mapbox gl同时显示这两个要素,因为您需要设置图层的类型 有没有一种方法可以让一个图层有多种类型?似乎它无法处理多个在Mapbox GL JS中以多种类型呈现GeoJSON文件中的FeatureCollection,mapbox,mapbox-gl,mapbox-gl-js,Mapbox,Mapbox Gl,Mapbox Gl Js,我们目前正在从geojson数据将图层加载到mapbox GL中。如果我们的geojson有一个包含点和多边形的要素集合,那么似乎没有办法让mapbox gl同时显示这两个要素,因为您需要设置图层的类型 有没有一种方法可以让一个图层有多种类型?似乎它无法处理多个 map.addLayer({ "id": "route", "type": "line", //THIS SEEMS TO BE THE LIMITATION "source": "route", }
map.addLayer({
"id": "route",
"type": "line", //THIS SEEMS TO BE THE LIMITATION
"source": "route",
});
您是正确的,GL JS无法处理每个层的多种类型 但是,通过创建多个图层,可以从单个源显示多个几何图形类型:
map.addLayer({
"id": "route-line",
"type": "line",
"source": "route",
"filter": ["==", "$type", "LineString"]
});
map.addLayer({
"id": "route-point",
"type": "circle",
"source": "route",
"filter": ["==", "$type", "Point"]
});
map.addLayer({
"id": "route-fill",
"type": "fill",
"source": "route",
"filter": ["==", "$type", "Polygon"]
});
您是正确的,GL JS无法处理每个层的多种类型 但是,通过创建多个图层,可以从单个源显示多个几何图形类型:
map.addLayer({
"id": "route-line",
"type": "line",
"source": "route",
"filter": ["==", "$type", "LineString"]
});
map.addLayer({
"id": "route-point",
"type": "circle",
"source": "route",
"filter": ["==", "$type", "Point"]
});
map.addLayer({
"id": "route-fill",
"type": "fill",
"source": "route",
"filter": ["==", "$type", "Polygon"]
});
谢谢卢卡斯,我会试试的!使用矢量平铺源如何实现这一点?可能吗?不用上面列出的geojson示例,谢谢Lucas-我将尝试一下!使用矢量平铺源如何实现这一点?可能吗?而不是上面列出的geojson示例