Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get a list of sources? #7529

Closed
bennybobw opened this issue Nov 1, 2018 · 6 comments
Closed

How to get a list of sources? #7529

bennybobw opened this issue Nov 1, 2018 · 6 comments

Comments

@bennybobw
Copy link

bennybobw commented Nov 1, 2018

mapbox-gl-js version: 0.48

How do I get a list of sources for my map?

Noob question here. How do I get a list of sources for my map? It looks like there is a github issue for mapbox native, but I don't see a corresponding one for mapbox gl js mapbox/mapbox-gl-native#7285

map.getSource('state_label');
gives me undefined.

@bennybobw
Copy link
Author

bennybobw commented Nov 1, 2018

Ah I see this now from #2625

map.querySourceFeatures('composite', {sourceLayer: 'source-name', filter: [filters]})

However, in this case I actually want to modify the state_label data source so I can use 2 letter abbreviations rather than the shortened name. Will I need to get the style update the data there and add it using setStyle or is there an easier way to achieve this?

@bennybobw
Copy link
Author

I can see the layers by logging the composite source, but have no idea how to add the metadata I want to the state_label. And I'm not understanding the difference between 'source' and 'sourceLayer' on the state label layer.

      console.log(this.map.getSource('composite'));
      console.log(this.map.getLayer('state label'));

@korywka
Copy link
Contributor

korywka commented Nov 1, 2018

console.log(map.style.sourceCaches); gives you list of sources

@korywka
Copy link
Contributor

korywka commented Nov 1, 2018

Difference btw source and source-layer you can read here: #5820 (comment)

@ryanhamley
Copy link
Contributor

You can call map.getStyle().sources to see a list of all sources in your map's style. The same works with layers. Note that you'll have to wait for the style to fully load to do this (e.g. inside a map.on('load', ...) event listener).

Please note that this issue tracker is for reporting bugs and requesting features. For general how-to questions, you can contact our support team or check out sites like Stack Overflow.

@Kambyses
Copy link

You can call map.getStyle().sources to see a list of all sources in your map's style. The same works with layers. Note that you'll have to wait for the style to fully load to do this (e.g. inside a map.on('load', ...) event listener).

This is not complete true, as this will return only sources defined in style and leaves out sources added later via map.addSource()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants