2023-03-11 02:37:07 +01:00
|
|
|
<script lang="ts">
|
2023-06-14 20:39:36 +02:00
|
|
|
import type { RasterLayerPolygon } from "../../Models/RasterLayers"
|
|
|
|
|
import OverlayMap from "./OverlayMap.svelte"
|
|
|
|
|
import type { MapProperties } from "../../Models/MapProperties"
|
|
|
|
|
import { Store, UIEventSource } from "../../Logic/UIEventSource"
|
|
|
|
|
import { Map as MlMap } from "maplibre-gl"
|
|
|
|
|
import { createEventDispatcher, onDestroy } from "svelte"
|
2023-03-11 02:37:07 +01:00
|
|
|
|
2023-06-14 20:39:36 +02:00
|
|
|
/***
|
|
|
|
|
* Chooses a background-layer out of available options
|
|
|
|
|
*/
|
2024-08-11 16:27:00 +02:00
|
|
|
export let availableLayers: RasterLayerPolygon[]
|
2023-06-14 20:39:36 +02:00
|
|
|
export let mapproperties: MapProperties
|
|
|
|
|
export let map: Store<MlMap>
|
2023-05-18 15:44:54 +02:00
|
|
|
|
2023-06-14 20:39:36 +02:00
|
|
|
export let visible: Store<boolean> = undefined
|
2023-05-18 15:44:54 +02:00
|
|
|
|
2023-06-14 20:39:36 +02:00
|
|
|
let dispatch = createEventDispatcher<{ appliedLayer }>()
|
|
|
|
|
|
|
|
|
|
export let favourite: UIEventSource<string> | undefined = undefined
|
|
|
|
|
|
2024-08-11 16:27:00 +02:00
|
|
|
let rasterLayer = new UIEventSource<RasterLayerPolygon>(availableLayers[0])
|
2024-08-14 13:53:56 +02:00
|
|
|
let rasterLayerId = rasterLayer.sync(
|
|
|
|
|
(l) => l?.properties?.id,
|
|
|
|
|
[],
|
2024-08-23 03:47:04 +02:00
|
|
|
(id) => availableLayers.find((l) => l.properties.id === id),
|
2024-08-14 13:53:56 +02:00
|
|
|
)
|
2024-08-11 16:27:00 +02:00
|
|
|
rasterLayer.setData(availableLayers[0])
|
|
|
|
|
$: rasterLayer.setData(availableLayers[0])
|
2023-06-14 20:39:36 +02:00
|
|
|
|
|
|
|
|
if (favourite) {
|
|
|
|
|
onDestroy(
|
|
|
|
|
favourite.addCallbackAndRunD((favourite) => {
|
2024-08-11 16:27:00 +02:00
|
|
|
const fav = availableLayers?.find((l) => l.properties.id === favourite)
|
2023-06-14 20:39:36 +02:00
|
|
|
if (!fav) {
|
|
|
|
|
return
|
2023-05-18 15:44:54 +02:00
|
|
|
}
|
2023-06-14 20:39:36 +02:00
|
|
|
rasterLayer.setData(fav)
|
2024-08-23 03:47:04 +02:00
|
|
|
}),
|
2023-06-14 20:39:36 +02:00
|
|
|
)
|
2023-05-18 15:44:54 +02:00
|
|
|
|
2023-06-14 20:39:36 +02:00
|
|
|
onDestroy(
|
|
|
|
|
rasterLayer.addCallbackAndRunD((selected) => {
|
|
|
|
|
favourite?.setData(selected.properties.id)
|
2024-08-23 03:47:04 +02:00
|
|
|
}),
|
2023-06-14 20:39:36 +02:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let rasterLayerOnMap = UIEventSource.feedFrom(rasterLayer)
|
|
|
|
|
|
|
|
|
|
if (visible) {
|
|
|
|
|
onDestroy(
|
|
|
|
|
visible?.addCallbackAndRunD((visible) => {
|
|
|
|
|
if (visible) {
|
2024-08-11 16:27:00 +02:00
|
|
|
rasterLayerOnMap.setData(rasterLayer.data ?? availableLayers[0])
|
2023-06-14 20:39:36 +02:00
|
|
|
} else {
|
|
|
|
|
rasterLayerOnMap.setData(undefined)
|
|
|
|
|
}
|
2024-08-23 03:47:04 +02:00
|
|
|
}),
|
2023-06-14 20:39:36 +02:00
|
|
|
)
|
|
|
|
|
}
|
2024-08-11 16:27:00 +02:00
|
|
|
|
2024-01-10 02:25:24 +01:00
|
|
|
function apply() {
|
|
|
|
|
mapproperties.rasterLayer.setData(rasterLayer.data)
|
|
|
|
|
dispatch("appliedLayer")
|
|
|
|
|
}
|
2024-02-20 13:33:38 +01:00
|
|
|
|
|
|
|
|
function handleKeyPress(e: KeyboardEvent) {
|
|
|
|
|
if (e.key === "Enter") {
|
2024-01-10 02:25:24 +01:00
|
|
|
apply()
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-11 02:37:07 +01:00
|
|
|
</script>
|
|
|
|
|
|
2024-08-11 16:27:00 +02:00
|
|
|
{#if availableLayers?.length > 0}
|
2024-01-11 04:00:56 +01:00
|
|
|
<form class="flex h-full w-full flex-col" on:submit|preventDefault={() => {}}>
|
2024-07-21 10:52:51 +02:00
|
|
|
<button
|
|
|
|
|
tabindex="-1"
|
|
|
|
|
on:click={() => apply()}
|
|
|
|
|
class="m-0 h-full w-full cursor-pointer rounded-none border-none p-0"
|
|
|
|
|
>
|
2024-04-13 02:40:21 +02:00
|
|
|
<span class="pointer-events-none relative h-full w-full">
|
2024-02-20 13:33:38 +01:00
|
|
|
<OverlayMap
|
|
|
|
|
interactive={false}
|
|
|
|
|
rasterLayer={rasterLayerOnMap}
|
|
|
|
|
placedOverMap={map}
|
|
|
|
|
placedOverMapProperties={mapproperties}
|
|
|
|
|
{visible}
|
|
|
|
|
/>
|
2024-02-21 17:33:29 +01:00
|
|
|
</span>
|
2023-06-14 20:39:36 +02:00
|
|
|
</button>
|
2024-08-11 16:27:00 +02:00
|
|
|
<select bind:value={$rasterLayerId} class="w-full" on:keydown={handleKeyPress}>
|
|
|
|
|
{#each availableLayers as availableLayer}
|
|
|
|
|
<option value={availableLayer.properties.id}>
|
2023-06-14 20:39:36 +02:00
|
|
|
{availableLayer.properties.name}
|
2024-08-23 03:47:04 +02:00
|
|
|
{#if availableLayer.properties.category.startsWith("historic")}
|
|
|
|
|
⏱️
|
|
|
|
|
{/if}
|
|
|
|
|
{#if availableLayer.properties.category.endsWith("elevation")}
|
|
|
|
|
⛰
|
|
|
|
|
{/if}
|
|
|
|
|
{#if availableLayer.properties.best}
|
|
|
|
|
⭐
|
|
|
|
|
{/if}
|
2023-06-14 20:39:36 +02:00
|
|
|
</option>
|
|
|
|
|
{/each}
|
|
|
|
|
</select>
|
2024-01-10 02:25:24 +01:00
|
|
|
</form>
|
2023-05-18 15:44:54 +02:00
|
|
|
{/if}
|