Closed Timo972 closed 6 months ago
In theory this line should be reloading the layers on style change, although perhaps the source isn't reloaded or this doesn't get fired in some cases.
In fact in the playground the original layer persists when I change style. The only bug I notice is that if I change layers it gets reset to the original.
Doing as you are saying and copying the implementation from the source into the layer might work. You will probably need to change the addLayer
function to not add a layer if it already exists like it does for the source.
I might take a look into this later when I have time (CI/CD is currently broken which is blocking the latest Mapbox update so I need to fix that first.) Feel free to give this a try if you would like, a PR is always welcome!
Now that I think about it, if the layer is loaded after the source this does not get called. Perhaps the proper fix is to just make sure this always gets called so the layer always gets reloaded with the source.
Seems like this issue got more depth than expected. I will have a deeper look at it later on, so you can focus fixing the CI.
Now that I think about it, if the layer is loaded after the source this does not get called. Perhaps the proper fix is to just make sure this always gets called so the layer always gets reloaded with the source.
Guess you're right, I will give it a try
Now that I think about it, if the layer is loaded after the source this does not get called. Perhaps the proper fix is to just make sure this always gets called so the layer always gets reloaded with the source.
implemented in pr #96
Hi, I use the MapSource and MapLayer components to register mapbox sources and layers. Facing the issue that they are being unloaded on a style change, i did some research on why's that. Interestingly this is intended behaviour by mapbox, as they even provide an example for persistent sources/layers. See https://docs.mapbox.com/mapbox-gl-js/example/style-switch/
As far as i can tell, this logic is already implemented for sources but is missing for layers. Is there a specific reason this is the case?
Implementing this enhancement should be as easy as calling
addLayer
in the style load event callback over here, similar to the implementation in the MapSource component.I can do a pr for this 3-liner if you like 😉