2024-02-21 17:33:29 +01:00
|
|
|
<script lang="ts">
|
|
|
|
import Loading from "../Base/Loading.svelte"
|
|
|
|
import { Stores, UIEventSource } from "../../Logic/UIEventSource"
|
|
|
|
import { Map as MlMap } from "maplibre-gl"
|
|
|
|
import { onDestroy } from "svelte"
|
|
|
|
|
|
|
|
let isLoading = false
|
|
|
|
export let map: UIEventSource<MlMap>
|
2024-03-22 09:58:06 +01:00
|
|
|
/**
|
|
|
|
* Optional. Only used for the 'global' change indicator so that it won't spin on pan/zoom but only when a change _actually_ occured
|
|
|
|
*/
|
2024-03-12 03:40:55 +01:00
|
|
|
export let rasterLayer: UIEventSource<any> = undefined
|
2024-04-13 02:40:21 +02:00
|
|
|
|
2024-03-12 03:40:55 +01:00
|
|
|
let didChange = undefined
|
2024-04-13 02:40:21 +02:00
|
|
|
onDestroy(
|
|
|
|
rasterLayer?.addCallback(() => {
|
|
|
|
didChange = true
|
|
|
|
}) ?? (() => {})
|
|
|
|
)
|
|
|
|
|
|
|
|
onDestroy(
|
|
|
|
Stores.Chronic(250).addCallback(() => {
|
2024-03-13 01:58:52 +01:00
|
|
|
const mapIsLoading = !map.data?.isStyleLoaded()
|
2024-03-22 09:58:06 +01:00
|
|
|
isLoading = mapIsLoading && (didChange || rasterLayer === undefined)
|
2024-04-13 02:40:21 +02:00
|
|
|
if (didChange && !mapIsLoading) {
|
2024-03-12 03:40:55 +01:00
|
|
|
didChange = false
|
|
|
|
}
|
2024-04-13 02:40:21 +02:00
|
|
|
})
|
|
|
|
)
|
2024-02-21 17:33:29 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
{#if isLoading}
|
2024-03-12 03:40:55 +01:00
|
|
|
<Loading cls="h-6 w-6" />
|
|
|
|
{:else}
|
|
|
|
<slot />
|
2024-02-21 17:33:29 +01:00
|
|
|
{/if}
|