3

In Mapbox GL JS I am adding a vector tile source from a locally hosted mbtiles file. Adding this source to my map instance is easy like below.

map.addSource("polylinesSource",{
      "type":"vector",      
      "tiles": [
       "http://localhost:8000/polylinesJoined/{z}/{x}/{y}.pbf"
      ]
    })

The source-layers from this service will be dynamic and I am hoping for a way to reference all those layers once the source is loaded. Is it possible to list all the layers in a source once loaded?

1 Answer 1

3

This is surprisingly fiddly to do. Mapbox-GL-JS doesn't expose any methods to list the vector tile source layers available within a tileset.

I built vector inspector to solve this exact problem. The code here shows you the process for extracting that information from a .pbf: https://github.com/stevage/vector-inspector-api/blob/master/server.js

Alternatively, since you have the local mbtiles file, another option is to extract it locally. Using another tool I built, tileinfo.

Also, if you serve the tiles using something like tessera you can access the layers info directly at the TileJSON endpoint.

Sign up to request clarification or add additional context in comments.

1 Comment

where in your tileinfo tool can i see the source layer info? I'm trying to render the map but I don't know where I can find the source-layer of my tileset. Not sure if the wrong source-layer is the reason why my tiles aren't rendering.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.