MapComplete/src/UI/Map/StyleLoadingIndicator.svelte

36 lines
955 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>
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
*/
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(
() => {
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-03-13 01:58:52 +01:00
if(didChange && !mapIsLoading){
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}