-
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
Change map style with sources #6039
Comments
Hey @miguelleitevieira, you'll want to check if the style is done loading before manipulating the map by listening for the
You can see this pattern on many of the examples in the documentation, e.g. https://www.mapbox.com/mapbox-gl-js/example/add-image/. If you have any more "how do I" questions like this, please refer to the documentation or ask on StackOverflow. |
You didn't understood the case. The map are already loaded, but when I try to change the style I get a error. So I need to load the markers and circles when I change the style? Isn't a good approach. |
@miguelleitevieira are you programmatically adding/changing markers and circles while switching the style, or have they already been loaded by the time you change the style? If the former, you'll need to hold off on manipulating markers and circles while the style is being loaded. Runtime styling functions manipulate the underlying style and therefore require a style to be finished loading in order to operate on it. This is the case in which I'd expect to see the error you're seeing. If the latter — you're not manipulating the style in any other way while switching the basemap — then the presence of that error is a bug; can you please provide a minimal self-contained JSFiddle that demonstrates the issue? Additionally, you won't be able to preserve any added markers with a pure Upon closer inspection it looks like in the middle of your stack trace there's something from mapbox-gl-circle (which I assume is https://github.com/smithmicro/mapbox-gl-circle) — it's worth looking into whether the error you're seeing is related to behaviors of that module (i.e. that mapbox-gl-circle attempts to manipulate layers in the middle of loading a new style), but it's impossible to diagnose without a self-contained example. |
@lbud The "removing and adding stuff back" is already supported by mapbox-gl-circle; https://github.com/smithmicro/mapbox-gl-circle/blob/master/lib/main.js#L794-L807 It seems that the issue that @miguelleitevieira identified was caused by circle being built with |
I need a workaround for this scenario.
I create a map with 'mapbox://styles/mapbox/streets-v9' style, and I have a option to switch to change style to 'mapbox://styles/mapbox/satellite-v9' or for the initial style.
So, when I don't have anything on map (markers and circles) works well, but then I drawn something on the map, I get a error:
Uncaught Error: Style is not done loading
at t._checkLoaded (style.js:292)
at t.removeLayer (style.js:610)
at e.removeLayer (map.js:1153)
at e.value (mapbox-gl-circle-1.6.4.min.js:1)
at e.value (mapbox-gl-circle-1.6.4.min.js:1)
at e.Evented.fire (evented.js:93)
at e._onDataLoading (map.js:1666)
at e.Evented.fire (evented.js:93)
at t.Evented.fire (evented.js:103)
at t.loadURL (style.js:149)
Someone know a workaround for this?
Thanks.
The text was updated successfully, but these errors were encountered: