-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
setStyle(URL) is a race condition - subsequent addLayer() and addSource() possibly lost #10534
Comments
Writing this issue up did help me find a workaround that solves the issue:
This works fine - by fetching the style ourselves, once we call |
I'm actually not really sure what Mapbox GL JS should do here, between calling
|
Hi @stevage, I think you've raised a really important issue here. map.setStyle('mystyle.json')
.then(map => {
map.addLayer({...})
}); or await map.setStyle('mystyle.json')
map.addLayer({...}); This would require a breaking change but I think it would greatly improve the developer experience. The current requirement to add your own logic to avoid non-deterministic layer ordering gives the API a somewhat "low level" feel. There has been some progress introducing promises in other parts of the API (#10203), which is great. I feel like this is probably the best way forward in the long term. Thoughts? |
I think it would be better than the current situation, yes. I'd really love a comprehensive solution that solves all the issues with "style is not finished loading", difficulty determining state, when it's safe to manipulate the map etc.
Mapbox is, from past experience, extremely reluctant to make breaking changes - particularly in a case like this. I think realistically, it's more likely to happen externally, maybe in mapbox-gl-utils.
|
I think a fully promise-based API would go a long way towards solving these issues. Hopefully the switch to ES6 has brought this a little bit closer to reality. As noted in #10565:
I would enthusiastically support switching to a fully promise-based API. But yes, for now it seems like it's up to the developer, or other libraries, to work around these issues. |
mapbox-gl-js version: 1.13.0
Steps to Trigger Behavior
Expected Behavior
false, false, 10
(maybe - unclear what isStyleLoaded should do exactly)Then print out the background layer we added
Actual Behavior
true, true, 5
undefined
Super frustrating, like #8691, #9779, #2268.
After calling
setStyle()
(with a JSON) it's difficult/impossible to know when the new style has actually taken effect. If you immediately add new layers, there is no error, but they apparently happen before the actual style change takes place, so they get removed.The text was updated successfully, but these errors were encountered: