2023-12-21 01:46:18 +01:00
|
|
|
<script lang="ts">
|
|
|
|
/**
|
|
|
|
* Shows the current address when shaken
|
|
|
|
**/
|
|
|
|
import Motion from "../../Sensors/Motion"
|
|
|
|
import { Geocoding } from "../../Logic/Osm/Geocoding"
|
|
|
|
import type { MapProperties } from "../../Models/MapProperties"
|
|
|
|
import Hotkeys from "../Base/Hotkeys"
|
|
|
|
import Translations from "../i18n/Translations"
|
|
|
|
import Locale from "../i18n/Locale"
|
2023-12-19 22:21:34 +01:00
|
|
|
|
2023-12-21 01:46:18 +01:00
|
|
|
export let mapProperties: MapProperties
|
|
|
|
let lastDisplayed: Date = undefined
|
|
|
|
let currentLocation: string = undefined
|
2023-12-19 22:21:34 +01:00
|
|
|
|
2023-12-21 01:46:18 +01:00
|
|
|
async function displayLocation() {
|
|
|
|
lastDisplayed = new Date()
|
|
|
|
let result = await Geocoding.reverse(
|
|
|
|
mapProperties.location.data,
|
|
|
|
mapProperties.zoom.data,
|
|
|
|
Locale.language.data
|
|
|
|
)
|
|
|
|
let properties = result.features[0].properties
|
|
|
|
currentLocation = properties.display_name
|
|
|
|
window.setTimeout(() => {
|
|
|
|
if (properties.display_name !== currentLocation) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
currentLocation = undefined
|
|
|
|
}, 5000)
|
|
|
|
}
|
|
|
|
|
|
|
|
Motion.singleton.lastShakeEvent.addCallbackD((shaken) => {
|
|
|
|
if (lastDisplayed !== undefined && shaken.getTime() - lastDisplayed.getTime() < 2000) {
|
2023-12-20 02:50:08 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
displayLocation()
|
|
|
|
})
|
2023-12-21 01:46:18 +01:00
|
|
|
Hotkeys.RegisterHotkey(
|
|
|
|
{ nomod: "q" },
|
|
|
|
Translations.t.hotkeyDocumentation.queryCurrentLocation,
|
|
|
|
() => {
|
|
|
|
displayLocation()
|
|
|
|
}
|
|
|
|
)
|
2023-12-20 02:50:08 +01:00
|
|
|
|
2023-12-21 01:46:18 +01:00
|
|
|
Motion.singleton.startListening()
|
2023-12-19 22:21:34 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
{#if currentLocation}
|
2023-12-21 01:46:18 +01:00
|
|
|
<div
|
|
|
|
role="alert"
|
|
|
|
aria-live="assertive"
|
|
|
|
class="normal-background border-interactive rounded-full px-2"
|
|
|
|
>
|
2023-12-19 22:21:34 +01:00
|
|
|
{currentLocation}
|
|
|
|
</div>
|
|
|
|
{/if}
|