MapComplete/src/UI/BigComponents/VisualFeedbackPanel.svelte

57 lines
1.9 KiB
Svelte
Raw Normal View History

<script lang="ts">
/**
* The visual feedback panel gives visual (and auditive) feedback on the main map view
*/
import Translations from "../i18n/Translations"
import ThemeViewState from "../../Models/ThemeViewState"
import Summary from "./Summary.svelte"
import Tr from "../Base/Tr.svelte"
2023-12-21 17:36:43 +01:00
import { UIEventSource } from "../../Logic/UIEventSource"
import type { KeyNavigationEvent } from "../../Models/MapProperties"
2023-12-21 17:36:43 +01:00
import MapCenterDetails from "./MapCenterDetails.svelte"
export let state: ThemeViewState
const t = Translations.t.general.visualFeedback
2023-12-21 17:36:43 +01:00
let map = state.mapProperties
let centerFeatures = state.closestFeatures.features
2023-12-21 17:36:43 +01:00
let translationWithLength = centerFeatures.mapD(cf => cf.length).mapD(n => {
if (n === 1) {
return t.oneFeatureInView
}
return t.closestFeaturesAre.Subs({ n })
})
2023-12-21 01:46:18 +01:00
let lastAction: UIEventSource<KeyNavigationEvent> = new UIEventSource<KeyNavigationEvent>(
2023-12-21 17:36:43 +01:00
undefined,
2023-12-21 01:46:18 +01:00
)
state.mapProperties.onKeyNavigationEvent((event) => {
lastAction.setData(event)
})
2023-12-21 01:46:18 +01:00
lastAction.stabilized(750).addCallbackAndRunD((_) => lastAction.setData(undefined))
</script>
<div aria-live="assertive" class="p-1 bg-white m-1 rounded">
2023-12-21 17:36:43 +01:00
{#if $lastAction?.key === "out"}
<Tr t={t.out.Subs({z: map.zoom.data - 1})} />
{:else if $lastAction?.key === "in"}
<Tr t={t.out.Subs({z: map.zoom.data + 1})} />
{:else if $lastAction !== undefined}
<Tr t={t[$lastAction.key]} />
2023-12-21 17:36:43 +01:00
{:else if $centerFeatures?.length === 0}
<Tr t={t.noCloseFeatures} />
2023-12-21 17:36:43 +01:00
<MapCenterDetails {state} />
{:else if $centerFeatures !== undefined}
<div class="pointer-events-auto">
2023-12-21 17:36:43 +01:00
<Tr t={$translationWithLength} />
<MapCenterDetails {state} />
<div class="grid grid-cols-3 space-x-1 space-y-0.5">
2023-12-21 17:36:43 +01:00
{#each $centerFeatures.slice(0, 9) as feat, i (feat.properties.id)}
<Summary {state} feature={feat} {i} />
{/each}
</div>
</div>
{/if}
</div>