Performance: lazily download ELI when needed instead of bundling this in the download

This commit is contained in:
Pieter Vander Vennet 2024-08-11 16:27:00 +02:00
parent 8c779fe09b
commit 68f8432db7
14 changed files with 257 additions and 183 deletions

View file

@ -9,7 +9,7 @@
/***
* Chooses a background-layer out of available options
*/
export let availableLayers: Store<RasterLayerPolygon[]>
export let availableLayers: RasterLayerPolygon[]
export let mapproperties: MapProperties
export let map: Store<MlMap>
@ -19,34 +19,26 @@
export let favourite: UIEventSource<string> | undefined = undefined
let rasterLayer = new UIEventSource<RasterLayerPolygon>(availableLayers.data?.[0])
let hasLayers = true
onDestroy(
availableLayers.addCallbackAndRun((layers) => {
if (layers === undefined || layers.length === 0) {
hasLayers = false
return
}
hasLayers = true
rasterLayer.setData(layers[0])
})
)
let rasterLayer = new UIEventSource<RasterLayerPolygon>(availableLayers[0])
let rasterLayerId = rasterLayer.sync(l => l?.properties?.id, [], id => availableLayers.find(l => l.properties.id === id))
rasterLayer.setData(availableLayers[0])
$: rasterLayer.setData(availableLayers[0])
if (favourite) {
onDestroy(
favourite.addCallbackAndRunD((favourite) => {
const fav = availableLayers.data?.find((l) => l.properties.id === favourite)
const fav = availableLayers?.find((l) => l.properties.id === favourite)
if (!fav) {
return
}
rasterLayer.setData(fav)
})
}),
)
onDestroy(
rasterLayer.addCallbackAndRunD((selected) => {
favourite?.setData(selected.properties.id)
})
}),
)
}
@ -56,13 +48,14 @@
onDestroy(
visible?.addCallbackAndRunD((visible) => {
if (visible) {
rasterLayerOnMap.setData(rasterLayer.data ?? availableLayers.data[0])
rasterLayerOnMap.setData(rasterLayer.data ?? availableLayers[0])
} else {
rasterLayerOnMap.setData(undefined)
}
})
}),
)
}
function apply() {
mapproperties.rasterLayer.setData(rasterLayer.data)
dispatch("appliedLayer")
@ -75,7 +68,7 @@
}
</script>
{#if hasLayers}
{#if availableLayers?.length > 0}
<form class="flex h-full w-full flex-col" on:submit|preventDefault={() => {}}>
<button
tabindex="-1"
@ -92,9 +85,9 @@
/>
</span>
</button>
<select bind:value={$rasterLayer} class="w-full" on:keydown={handleKeyPress}>
{#each $availableLayers as availableLayer}
<option value={availableLayer}>
<select bind:value={$rasterLayerId} class="w-full" on:keydown={handleKeyPress}>
{#each availableLayers as availableLayer}
<option value={availableLayer.properties.id}>
{availableLayer.properties.name}
</option>
{/each}