From 05638a753175398ed4daef2be01614b2e0c93e1a Mon Sep 17 00:00:00 2001 From: NSUWAL123 Date: Fri, 13 Dec 2024 09:35:51 +0545 Subject: [PATCH 1/2] fix(basemaps): fix ts type errors --- .../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..ed827b84ef 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.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} +
- - {#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 From 9fc8565cfe08d759b611d9f4368485f801d6f867 Mon Sep 17 00:00:00 2001 From: NSUWAL123 Date: Fri, 13 Dec 2024 09:42:49 +0545 Subject: [PATCH 2/2] fix(basemaps): use target instead of originalTarget --- src/mapper/src/lib/components/offline/basemaps.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mapper/src/lib/components/offline/basemaps.svelte b/src/mapper/src/lib/components/offline/basemaps.svelte index ed827b84ef..f8af87e6aa 100644 --- a/src/mapper/src/lib/components/offline/basemaps.svelte +++ b/src/mapper/src/lib/components/offline/basemaps.svelte @@ -46,7 +46,7 @@ { - const selectedId = event.originalTarget.value; + const selectedId = event.target.value; selectedBasemap = basemapStore.projectBasemaps?.find((basemap: Basemap) => basemap.id === selectedId) || null; }} >