Reputation: 424
Can we have a feature that can get source's meta info to list layers's id and layer's type when add a unknown vector tile service? I think these can help us to style vector service in right way,and can made a default style for different layers (point--circle,polygon--fill,line--line).
Upvotes: 2
Views: 544
Reputation: 3802
Unfortunately there is no standard way to list all the layers in a vector tile source. Mapbox sources provide a vector_layers
object in their TileJSON but because this feature is not standard, it is not available within the GL JS API.
Upvotes: 1
Reputation: 3209
You can call map.getStyle().layers
to find the layers defined in the current style.
Here is how you can get the id
and the type
of each layer:
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/light-v9',
zoom: 13,
center: [-122.447303, 37.753574]
});
map.on('load', function () {
var layersMeta = map.getStyle().layers
.map(function(layer) {
return [layer.id, layer.type];
});
console.log(layersMeta);
});
And here's the corresponding jsfiddle. Have a look at the console.
Upvotes: 2