问题
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",
});
回答1:
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"]
});
来源:https://stackoverflow.com/questions/36923916/render-a-featurecollection-from-a-geojson-file-with-multiple-types-in-mapbox-gl