从Mapbox-GL-JS中具有多种类型的GeoJSON文件中渲染FeatureCollection [英] Render a FeatureCollection from a GeoJSON file with multiple types in Mapbox-GL-JS
问题描述
我们当前正在将图层从geojson数据加载到mapbox GL中.如果我们的geojson具有包含点和多边形的要素集合,则由于需要设置图层类型,因此似乎没有办法同时显示mapbox gl.
We are currently loading layers into mapbox GL from geojson data. If our geojson has a feature collection that contains points and polygons, there does not seem to be a way to have mapbox gl show both because of how you need to set the type of layer.
是否可以为一个图层设置多种类型?似乎无法处理多个.
Is there a way to have multiple types for a layer? It seems as if it can't handle multiple.
map.addLayer({
"id": "route",
"type": "line", //THIS SEEMS TO BE THE LIMITATION
"source": "route",
});
推荐答案
您是正确的,GL JS无法处理每层多种类型.
You are correct, GL JS cannot handle multiple types per layer.
但是,您可以通过创建多个图层来显示来自单一来源的多种几何类型:
You can, however, display multiple geometry types from a single source by creating multiple layers:
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"]
});
这篇关于从Mapbox-GL-JS中具有多种类型的GeoJSON文件中渲染FeatureCollection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!