Preserving a map and its state across pages #184
Unanswered
dabreegster
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a sveltekit app with many pages, some of which embed a map. Currently each page recreates the map component from scratch, meaning that there's noticeable lag when changing pages to load tiles and that the viewport state is lost. I want to share one map instance across all pages, preventing both problems, but any components nested underneath the map (aka sources and layers), I want to unmount when a page is unmounted, as usual.
Has anybody done something like this and have some example code or any pitfalls? I've tried searching around for similar sveltekit questions about sharing one component instance across pages. https://kit.svelte.dev/docs/state-management#component-and-page-state-is-preserved suggests that putting the map in the overall layout could be one approach, but the pages involving a map all have different layouts. Instead, I'm going to try binding the
<MapLibre>
component to a shared store and when a map page gets destroyed, preserving the DOM node but making it invisible. Later on, inserting that node in a new page and making it visible again. I'll report back with any progress.Beta Was this translation helpful? Give feedback.
All reactions