mapcomplete/UI/BigComponents/LevelSelector.svelte

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

33 lines
1 KiB
Svelte
Raw Normal View History

2023-04-26 18:04:42 +02:00
<script lang="ts">
/**
* Shows a 'floorSelector' and maps the selected floor onto a global filter
*/
import LayerState from "../../Logic/State/LayerState"
import FloorSelector from "../InputElement/Helpers/FloorSelector.svelte"
import { Store, UIEventSource } from "../../Logic/UIEventSource"
2023-04-26 18:04:42 +02:00
export let layerState: LayerState
export let floors: Store<string[]>
export let zoom: Store<number>
2023-04-26 18:04:42 +02:00
const maxZoom = 16
let selectedFloor: UIEventSource<string> = new UIEventSource<string>(undefined)
selectedFloor.stabilized(5).map(
(floor) => {
if (floors.data === undefined || floors.data.length <= 1 || zoom.data < maxZoom) {
// Only a single floor is visible -> disable the 'level' global filter
// OR we might have zoomed out to much ant want to show all
layerState.setLevelFilter(undefined)
} else {
layerState.setLevelFilter(floor)
}
},
[floors, zoom]
)
2023-04-26 18:04:42 +02:00
</script>
2023-04-26 18:04:42 +02:00
{#if $zoom >= maxZoom}
<FloorSelector {floors} value={selectedFloor} />
{/if}