-
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
Calling map.setStyle() removes all layers and sources #8660
Comments
I believe this is #4006. That thread has some discussion on possible solutions, but generally the expectation is with you to either re-add those sources/layers after setStyle or even better integrate them into your Style JSON you pass to setStyle so that the smart diff which powers setStyle can retain them. |
@andrewharvey thanks for chiming in, seconded. Closing as a duplicate of #4006. |
do you solve the question? |
Create one function that adds an existing layer and source again. The function execution must use setTimeout. Otherwise not applicable |
Sometimes |
Here I leave a possible solution, I hope it can help you. codesandbox.io |
mapbox-gl-js version: 1.2.1
browser: Chrome(76.0.3809.100) and Firefox(68.0.2)
Steps to Trigger Behavior
setStyle()
Link to Demonstration
This can be seen in this official example.
I've also added a basic example derived from the setStyle example which only adds another layer to the map. If you change the map style, this layer will be removed.
https://jsbin.com/yekisosehe/1/edit?html,console,output
Expected Behavior
Change the map style and do NOT remove all the existing layers. This is critical, as in my case, I have a great deal of layers, sources and markers on the map and removing them when switching styles is a deal breaker.
Actual Behavior
Changes the map style and generates a warning in the console.
Any known way to work around this and not rerender all the layers? Maybe I'm missing something obvious, but I don't think this should be the behaviour. I know there are some related issues such as 8241, 2058 or 2059 but with no conclusive answers.
The text was updated successfully, but these errors were encountered: