MapComplete/src/UI/Map/StyleLoadingIndicator.svelte

32 lines
749 B
Svelte
Raw Normal View History

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>
export let rasterLayer: UIEventSource<any> = undefined
let didChange = undefined
onDestroy(rasterLayer?.addCallback(() => {
didChange = true
}) ??( () => {}))
2024-02-21 17:33:29 +01:00
onDestroy(Stores.Chronic(250).addCallback(
() => {
isLoading = !map.data?.isStyleLoaded() && (didChange === undefined || didChange)
if(didChange){
didChange = false
}
2024-02-21 17:33:29 +01:00
},
))
</script>
{#if isLoading}
<Loading cls="h-6 w-6" />
{:else}
<slot />
2024-02-21 17:33:29 +01:00
{/if}