-
Notifications
You must be signed in to change notification settings - Fork 44
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
Persist sources and layers when basemap style changes #60
Persist sources and layers when basemap style changes #60
Conversation
Someone is attempting to deploy a commit to a Personal Account owned by @dimfeld on Vercel. @dimfeld first needs to authorize it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this approach is quite clever and simple, and nicely localized to one place. I have some smaller svelte-maplibre projects I can change to take advantage of this for some more testing if it's useful
); | ||
sourcesToReAddAfterStyleChange = {}; | ||
for (const id of nonStyleSourceIds) { | ||
sourcesToReAddAfterStyleChange[id] = oldMapStyle.sources[id]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about cases where the paint
or layout
prop of a Layer
component gets modified. Doing the work here based on map.getStyle()
is nice, because it'll pick up the current state before changing style.
One sanity check though -- we don't need to make defensive copies with structuredClone
or similar here? I don't think so, because map.getStyle()
will return new things after the setStyle
below, and the user-managed sources/layers won't be there. The maplibre API isn't terribly clear about ownership/lifetime of source/layer specifications...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont think so either. Especially as the only thing we are storing from this entire function call are the layersToReAddAfterStyleChange and sourcesToReAddAfterStyleChange, objects which are newly constructed each time. We can throw in a structuredClone just in case if we want to be 100% sure. The style shouldn't change often enough that we need to worry about keeping this code too performant. Miight be better to be defensive?
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
I should be able to take a real look at this and your other PR later today. Thanks! Edit: actually will more likely be over the weekend. Thanks for your patience :) |
Ok, released all the recent PRs as v0.4.0. Thanks @stuartlynn and @dabreegster for the PRs and reviews! |
Just spotted maplibre/maplibre-gl-js#2587 (comment), possibly a simpler implementation |
Thanks, yeah that does look like a nice solution. |
This PR fixes a bug where user defined layers and sources got overwritten when the basemap styleURL changed.
To fix this I added some extra logic to the MapLibre component that
I also added an example page which shows this in effect, mostly for testing.
Would be great to get a few eyes on this PR as the logic is a bit complex and I want to make sure this doesn't have any unintended consequences or side effects