maplibre-gl-js
maplibre-gl-js copied to clipboard
map.isStyleLoaded contradicts map.style._loaded
Expected Behavior
map.style._loaded to be equal map.isStyleLoaded like here: https://github.com/mapbox/mapbox-gl-js/blob/c072bf74d3c8c21cbdc73dcae83e04035e07c8c4/3d-style/source/model_source.js#L76
Actual Behavior
map.style.loaded
method doesn't rely on map.style._loaded
and seems like recursive:
https://github.com/maplibre/maplibre-gl-js/blob/33fb1ed4d10404a917bd4ab959016eccc2676b9d/src/ui/map.ts#L3071
Now there is no way to addSource
or addLayer
because map.style.loaded() returns false
Likely related to #2587. I would like to find a better approach for marking a style load as "done," but I haven't had time to look at it yet.
It's not a recursive call. You linked the map loaded method, which in turn uses the style loaded method. The _loaded property is an internal one that shouldn't be used and is partial to the entire loaded state of the style. In general, the link to the mapbox code is not something we can use as mapbox code is licensed as close, and also it can cause copyright infringement. Please avoid linking to their code on the future. The expectance of this issue is incorrect in general and the linked issue is tracking the problem with the event. There's also an open PR to address the linked issue. I'm leaning towards closing this issue unless there's anything else you would like to cover here.
I need to draw paths between points reactively when places changes and avoid error Style is not done
. I need also redraw paths when style changes (light/dark modes). Now I have following code:
useEffect(() => {
if (map.style._loaded) {
map.addSource('placesRoutes', ...sourceParams);
map.addLayer('placesRoutesLine', ...layerParams);
map.addLayer('placesRoutesArrow', ...layerParams);
}
return () => {
map.removeSource('placesRoutes');
map.removeLayer('placesRoutesLine');
map.removeLayer('placesRoutesArrow');
}, [map.style._loaded, places])
I would appreciate if you advice more correct way to do that