The documentation for Map.querySourceFeatures says it takes a parameter for sourceID - the ID of the vector tile or GeoJSON source. In their example, they add a source manually:

map.addSource('counties', {
    "type": "vector",
    "url": "mapbox://mapbox.82pkq93d"

And so the sourceID is counties.

If I create a Mapbox style in Mapbox Studio and publish it with a url, say:


and pass that directly to the Map constructor like this:

this.map = new mapboxgl.Map({
    container: 'map',
    style: 'mapbox://styles/mycoolcompany/mycoolmap123',
    center: [-123.12, 49.28],
    zoom: 5,

How can I get (or set?) the styleID programatically? I'm trying different combinations of things from Mapbox Studio but querySourceFeatures returns an empty array every time with no exceptions or indication of what it's missing.

More succinctly: how do I use querySourceFeatures on a home-made Mapbox Studio Style?

(mapbox-gl 0.36.0)


There isn't a public API to get all source IDs from a map, but


will return an object wherein each key is a source ID and its value is a source cache (the class responsible for managing an individual source).

Note that Mapbox Studio automatically composites sources — so, if you've added a custom vector source, rather than having multiple vector sources you'll likely see just one (composite), and if you were to download the JSON stylesheet its URL would be something like

"url": "mapbox://mapbox.mapbox-streets-v7,mycoolcompany.randomsha"

so you'll probably be looking for a source called composite.

  • Thank you, that answers my question and I was able to get querySourceFeatures returning values. For anyone else puzzling over querySourceFeatures returning empty arrays, you will probably need to dive into map.style.sourceCaches described above and make a note of the source and sourceLayer names. – DMack Apr 25 '17 at 18:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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