2

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
  • Mapbox has simple tools that take a tile source and convert it to GeoJSON, such as github.com/mapbox/vt2geojson which may be useful here.
    – kuanb
    Commented Feb 6, 2019 at 22:58

2 Answers 2

1

Since you have a .MBTiles file you can use TileServer GL to serve up your data. This tiny web server has a mode called Inspect or X-Ray which will sniff the vector layers in the .MBTiles and display a basic style so you can see the data.

TileServer GL uses Javascript to show the vector data available at each zoom level. It also has a mouse event handler to show you the metadata of each feature.

After installing tileserver-gl or tileserver-gl-light you can then navigate to the Inspect mode by navigating to

See this link for more information on how to install

tileserver-gl-xray-inspect Example of Inspect mode from TileServer GL

2
  • What is the recommended server requirements for Tileserver-gl-light? Should I expect performance similar to mbtiles-server which uses node-mbtiles? I have tileserver PHP installed and the performance for serving of vector tiles from mbtiles is not good, though the server CPU and memory are very limited. Finally, can Tileserver-gl-light watch a directory or do I have to specify each mbtiles individually?
    – Malcolm
    Commented Jan 20, 2017 at 9:54
  • I would refer you to the docs github.com/klokantech/tileserver-gl This is a newer project than the PHP version, so it may address some of your questions.
    – RobLabs
    Commented Jan 20, 2017 at 16:04
0

There is a bit of ambiguity in your question, but if your question is "list all Mapbox GL JS layers for a given source ID", you can iterate through all the layers in a Mapbox GL map and filter out anything that doesn't match the source name:

map.getStyle().layers.filter(i => i.source === 'myTileSource')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.