From bc2399da90c086a2f0b906eeac49e463024790d6 Mon Sep 17 00:00:00 2001 From: Nishit Suwal <81785002+NSUWAL123@users.noreply.github.com> Date: Fri, 13 Dec 2024 23:50:01 +0545 Subject: [PATCH] fix(mapper): offline mode button visibility & basemap component TS type error (#1990) * fix(basemaps): fix ts type errors * fix(basemaps): use target instead of originalTarget --- .../lib/components/offline/basemaps.svelte | 185 +++++++++--------- src/mapper/src/lib/utils/basemaps.ts | 6 +- 2 files changed, 94 insertions(+), 97 deletions(-) diff --git a/src/mapper/src/lib/components/offline/basemaps.svelte b/src/mapper/src/lib/components/offline/basemaps.svelte index 8ff8fa9917..f8af87e6aa 100644 --- a/src/mapper/src/lib/components/offline/basemaps.svelte +++ b/src/mapper/src/lib/components/offline/basemaps.svelte @@ -1,20 +1,20 @@
- -
-
- Manage Basemaps -
-
+ +
+
+ Manage Basemaps +
+
- -
- {#if basemapsAvailable} - +
+ {#if basemapsAvailable} + - { - const selectedId = event.originalTarget.value - selectedBasemap = basemapStore.projectBasemaps?.find((basemap: Basemap) => basemap.id === selectedId) || null - }} - > - {#each basemapStore.projectBasemaps as basemap} - {#if basemap.status === "SUCCESS"} - - {basemap.tile_source} {basemap.format} - - {/if} - {/each} - - {:else} -
-
- There are no basemaps available for this project. -
-
- Please ask the project manager to create basemaps. -
-
- {/if} -
+ { + const selectedId = event.target.value; + selectedBasemap = basemapStore.projectBasemaps?.find((basemap: Basemap) => basemap.id === selectedId) || null; + }} + > + {#each basemapStore.projectBasemaps as basemap} + {#if basemap.status === 'SUCCESS'} + + {basemap.tile_source} + {basemap.format} + + {/if} + {/each} + + {:else} +
+
There are no basemaps available for this project.
+
Please ask the project manager to create basemaps.
+
+ {/if} +
- - {#if selectedBasemap && selectedBasemap.format === 'pmtiles' } - loadOnlinePmtiles(selectedBasemap.url)} - onkeydown={(e: KeyboardEvent) => { - e.key === 'Enter' && loadOnlinePmtiles(selectedBasemap.url); - }} - role="button" - tabindex="0" - size="small" - class="secondary w-full max-w-[200px]" - > - - Show On Map - + + {#if selectedBasemap && selectedBasemap.format === 'pmtiles'} + loadOnlinePmtiles(selectedBasemap?.url)} + onkeydown={(e: KeyboardEvent) => { + e.key === 'Enter' && loadOnlinePmtiles(selectedBasemap?.url); + }} + role="button" + tabindex="0" + size="small" + class="secondary w-full max-w-[200px]" + > + + Show On Map + - writeOfflinePmtiles(projectId, selectedBasemap.url)} - onkeydown={(e: KeyboardEvent) => { - e.key === 'Enter' && writeOfflinePmtiles(projectId, selectedBasemap.url); - }} - role="button" - tabindex="0" - size="small" - class="secondary w-full max-w-[200px]" - > - - Store Offline - + writeOfflinePmtiles(projectId, selectedBasemap?.url)} + onkeydown={(e: KeyboardEvent) => { + e.key === 'Enter' && writeOfflinePmtiles(projectId, selectedBasemap?.url); + }} + role="button" + tabindex="0" + size="small" + class="secondary w-full max-w-[200px]" + > + + Store Offline + - - {:else if selectedBasemap && selectedBasemap.format === 'mbtiles' } - window.open(selectedBasemap.url)} - onkeydown={(e: KeyboardEvent) => { - e.key === 'Enter' && window.open(selectedBasemap.url); - }} - role="button" - tabindex="0" - size="small" - class="secondary w-full max-w-[200px]" - > - - Download MBTiles - - {/if} + + {:else if selectedBasemap && selectedBasemap.format === 'mbtiles'} + window.open(selectedBasemap?.url)} + onkeydown={(e: KeyboardEvent) => { + e.key === 'Enter' && window.open(selectedBasemap?.url); + }} + role="button" + tabindex="0" + size="small" + class="secondary w-full max-w-[200px]" + > + + Download MBTiles + + {/if} - {@render children?.()} + {@render children?.()}
diff --git a/src/mapper/src/lib/utils/basemaps.ts b/src/mapper/src/lib/utils/basemaps.ts index 485ec106da..f300ae40b8 100644 --- a/src/mapper/src/lib/utils/basemaps.ts +++ b/src/mapper/src/lib/utils/basemaps.ts @@ -38,7 +38,7 @@ export async function getBasemapList(projectId: number): Promise { } } -export async function loadOnlinePmtiles(url: string | null) { +export async function loadOnlinePmtiles(url: string | undefined) { if (!url) return; const pmtilesUrl = `pmtiles://${url}`; @@ -60,7 +60,7 @@ export async function loadOfflinePmtiles(projectId: number) { basemapStore.setProjectPmtilesUrl(pmtilesUrl); } -async function downloadBasemap(url: string | null): Promise { +async function downloadBasemap(url: string | undefined): Promise { let basemapData: ArrayBuffer = new ArrayBuffer(0); if (!url) return basemapData; @@ -87,7 +87,7 @@ async function downloadBasemap(url: string | null): Promise { } } -export async function writeOfflinePmtiles(projectId: number, url: string | null) { +export async function writeOfflinePmtiles(projectId: number, url: string | undefined) { const data = await downloadBasemap(url); // Copy to OPFS filesystem for offline use