-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Possibility to get current map style state #1982
Comments
+1, this would be great. Currently for each new map element that I create or switch styles + layers between, I need to:
If that could be condensed into one function call, that would be much more succinct and simple from a user perspective. Not sure if the WebGL canvas limits this or not (reusing layer objects between canvases). |
👍 Providing free combinations of mapbox "baselayers" (dark, bright, etc) and custom overlays (scene1, scene2, scene3, etc) to the user gives me the same need. Loading a complete fresh style is as ugly as removing and adding only the custom sources and layers to the style in the moment. I think some sort of bundeling/grouping for Layers and Sources would be a nice solution (e.g. |
Could you give a more thorough description of your use case? Why can't you create a full stylesheet including the basemap and your custom layers (i.e. in Mapbox Studio)?
|
I'm using mapbox-gl-js to make a showcase app for a gis service of my company. In the moment there are 3 showcases (think of them as locations or scenes), each with 4-6 timesteps. Every timestep has at least one raster dataset (satellite image) and a bunch of vector data (with symbols, labels, and of course all kind of GeoJSON data). Within a scene the vector data may or may not be similar. So every timestep comes with 10-20 mapbox style layers and 2-5 sources. |
This ticket is getting a little off track. Please try to focus on a single feature request, I think the solution to your use case that best fits with our roadmap is to make all map mutations (adding layers, changing basemap, etc) to an external stylesheet object and use the (planned) " |
Sorry for hijacking this issue...#1341 is what i was searching for. But it is closed? And the "folloups" is discussing dynamic data and not dynamic styles... |
You're right.
This comment suggests we should re-open a "setStyle" diffing issue. |
Opened a new ticket at #1989 |
I'm going to call both |
@lucaswoj The reason why I wanted to get/copy the map state was that I currently use the map as the "master" for my current style state. The reason for this is exactly what you have discussed in this thread, that I want to be able to transition between style states, and even though it would be possible to maintain a separate style object which I then manually diff and restyle my map against it would be quite an effort to implement, which you certainly know as this is pretty much what you will have to do for the transitioned If |
Sounds like we should focus our efforts on #1989 👍 |
@lucaswoj One thing I realised is that GeoJSON sources are part of the style, so replacing the entire style will also remove all sources added programmatically, unless part of the style I provide. Even with a smart, transitioned, In my world a clearer separation between data (sources) and presentation (layers) would be appealing.. whereas today they're part of the same semantic object (style). |
If the source data doesn't change, there will be a negligible cost to calling
|
As you point out, providing a URL instead of an object isn't always possible. I apply tons of filtering etc. client side.
For sure! But there will certainly be times when I want to change the data without changing the style, and , more importantly, times when I want to change the style without changing the data. Use case example:
At this point I will have to fall back to |
|
I support adding a @averas The way I'd recommend implementing your use case is:
|
This is an example of what I do: So far
Yup, and this works fine when only changing a single property, but becomes cumbersome (and slow) when I start applying several properties (especially layout properties) to tens or even hundreds of layers. |
@averas @ryanbaumann @indus This API has been added in |
Great work! |
I'm probably using a non-supported way to pass styles between two map instances using map.style.stylesheet which works quite good. The obvious problem with this approach is that I don't get any sources or layers that were added programmatically to the map. Could the API be extended with a getStyle() method which returns the current effective style including sources and layers added programmatically? Essentially I want to be able to do map2.setStyle(map1.getStyle())...
The text was updated successfully, but these errors were encountered: