3
votes

In a mapbox-gl map, given the source:

map.addSource('myTileSource', {
    type: "vector",
    tiles: "url to source tiles.pbf",
});

is it possible to get all the layers and/or metadata for the tiles inside that source? This is possible in node with node-mbtiles, but wondering if it is possible directly in mapbox-gl via javascript? Something like map.getLayersFromSource would be awesome.

1
Also posted on GIS stack exchange.malcolm

1 Answers

0
votes

I'm unaware of an official API method to get the information you're looking for. However, exploring Mapbox Studio reveals that there is an HTTP endpoint that returns the desired information:

https://api.mapbox.com/v4/mapbox.mapbox-streets-v7.json?access_token=[Mapbox Token here]

This returns a description of the source, including a list of layers.

{
    "attribution": "...",
    "vector_layers": [
        {
            "id": "layer id",
            "fields": {
                "field_1": "description for field 1"
            }
        }
    ]
}

This is obviously specific to Mapbox sources and won't work for vector tiles from different sources.