2024-04-28 18:59:31 +02:00
|
|
|
<script lang="ts">
|
2025-02-02 11:17:22 +01:00
|
|
|
import { Input } from '$lib/components/ui/input';
|
|
|
|
|
import { Textarea } from '$lib/components/ui/textarea';
|
|
|
|
|
import { Label } from '$lib/components/ui/label/index.js';
|
|
|
|
|
import { Button } from '$lib/components/ui/button';
|
|
|
|
|
import * as Select from '$lib/components/ui/select';
|
2025-06-21 21:07:36 +02:00
|
|
|
import { i18n } from '$lib/i18n.svelte';
|
2025-10-05 19:34:05 +02:00
|
|
|
import { ListWaypointItem } from '$lib/components/file-list/file-list';
|
2025-02-02 11:17:22 +01:00
|
|
|
import { dbUtils, fileObservers, getFile, settings, type GPXFileWithStatistics } from '$lib/db';
|
|
|
|
|
import { get } from 'svelte/store';
|
|
|
|
|
import Help from '$lib/components/Help.svelte';
|
|
|
|
|
import { onDestroy, onMount } from 'svelte';
|
|
|
|
|
import { map } from '$lib/stores';
|
|
|
|
|
import { getURLForLanguage, resetCursor, setCrosshairCursor } from '$lib/utils';
|
2025-06-21 21:07:36 +02:00
|
|
|
import { MapPin, CircleX, Save } from '@lucide/svelte';
|
2025-02-02 11:17:22 +01:00
|
|
|
import { getSymbolKey, symbols } from '$lib/assets/symbols';
|
2025-10-17 23:54:45 +02:00
|
|
|
import { selection } from '$lib/logic/selection';
|
|
|
|
|
import { selectedWaypoint } from './waypoint';
|
2024-05-24 20:23:49 +02:00
|
|
|
|
2025-10-05 19:34:05 +02:00
|
|
|
let props: {
|
|
|
|
|
class?: string;
|
|
|
|
|
} = $props();
|
2024-06-12 18:48:03 +02:00
|
|
|
|
2025-10-05 19:34:05 +02:00
|
|
|
let name = $state('');
|
|
|
|
|
let description = $state('');
|
|
|
|
|
let link = $state('');
|
|
|
|
|
let symbolKey = $state('');
|
|
|
|
|
let longitude = $state(0);
|
|
|
|
|
let latitude = $state(0);
|
2024-06-12 18:48:03 +02:00
|
|
|
|
2025-10-05 19:34:05 +02:00
|
|
|
let canCreate = $derived(selection.value.size > 0);
|
2024-06-12 18:48:03 +02:00
|
|
|
|
2025-02-02 11:17:22 +01:00
|
|
|
function resetWaypointData() {
|
|
|
|
|
name = '';
|
|
|
|
|
description = '';
|
|
|
|
|
link = '';
|
2025-06-21 21:07:36 +02:00
|
|
|
symbolKey = '';
|
2025-02-02 11:17:22 +01:00
|
|
|
longitude = 0;
|
|
|
|
|
latitude = 0;
|
|
|
|
|
}
|
2024-06-12 18:48:03 +02:00
|
|
|
|
2025-02-02 11:17:22 +01:00
|
|
|
function createOrUpdateWaypoint() {
|
|
|
|
|
if (typeof latitude === 'string') {
|
|
|
|
|
latitude = parseFloat(latitude);
|
|
|
|
|
}
|
|
|
|
|
if (typeof longitude === 'string') {
|
|
|
|
|
longitude = parseFloat(longitude);
|
|
|
|
|
}
|
|
|
|
|
latitude = parseFloat(latitude.toFixed(6));
|
|
|
|
|
longitude = parseFloat(longitude.toFixed(6));
|
2024-07-17 23:05:17 +02:00
|
|
|
|
2025-02-02 11:17:22 +01:00
|
|
|
dbUtils.addOrUpdateWaypoint(
|
|
|
|
|
{
|
|
|
|
|
attributes: {
|
|
|
|
|
lat: latitude,
|
|
|
|
|
lon: longitude,
|
|
|
|
|
},
|
|
|
|
|
name: name.length > 0 ? name : undefined,
|
|
|
|
|
desc: description.length > 0 ? description : undefined,
|
|
|
|
|
cmt: description.length > 0 ? description : undefined,
|
|
|
|
|
link: link.length > 0 ? { attributes: { href: link } } : undefined,
|
2025-06-21 21:07:36 +02:00
|
|
|
sym: symbols[symbolKey]?.value ?? '',
|
2025-02-02 11:17:22 +01:00
|
|
|
},
|
2025-10-05 19:34:05 +02:00
|
|
|
selectedWaypoint.wpt && selectedWaypoint.fileId
|
|
|
|
|
? new ListWaypointItem(selectedWaypoint.fileId, selectedWaypoint.wpt._data.index)
|
2025-02-02 11:17:22 +01:00
|
|
|
: undefined
|
|
|
|
|
);
|
2024-07-17 23:05:17 +02:00
|
|
|
|
2025-10-05 19:34:05 +02:00
|
|
|
selectedWaypoint.reset();
|
2025-02-02 11:17:22 +01:00
|
|
|
resetWaypointData();
|
|
|
|
|
}
|
2024-06-12 18:48:03 +02:00
|
|
|
|
2025-02-02 11:17:22 +01:00
|
|
|
function setCoordinates(e: any) {
|
|
|
|
|
latitude = e.lngLat.lat.toFixed(6);
|
|
|
|
|
longitude = e.lngLat.lng.toFixed(6);
|
|
|
|
|
}
|
2024-06-12 18:48:03 +02:00
|
|
|
|
2025-10-05 19:34:05 +02:00
|
|
|
let sortedSymbols = $derived(
|
|
|
|
|
Object.entries(symbols).sort((a, b) => {
|
|
|
|
|
return i18n
|
|
|
|
|
._(`gpx.symbol.${a[0]}`)
|
|
|
|
|
.localeCompare(i18n._(`gpx.symbol.${b[0]}`), i18n.lang);
|
|
|
|
|
})
|
|
|
|
|
);
|
2024-08-11 19:43:28 +02:00
|
|
|
|
2025-02-02 11:17:22 +01:00
|
|
|
onMount(() => {
|
2025-10-05 19:34:05 +02:00
|
|
|
map.value?.on('click', setCoordinates);
|
|
|
|
|
// setCrosshairCursor();
|
2025-02-02 11:17:22 +01:00
|
|
|
});
|
2024-06-12 18:48:03 +02:00
|
|
|
|
2025-02-02 11:17:22 +01:00
|
|
|
onDestroy(() => {
|
2025-10-05 19:34:05 +02:00
|
|
|
map.value?.off('click', setCoordinates);
|
|
|
|
|
// resetCursor();
|
2025-02-02 11:17:22 +01:00
|
|
|
});
|
2024-04-28 18:59:31 +02:00
|
|
|
</script>
|
|
|
|
|
|
2025-10-05 19:34:05 +02:00
|
|
|
<div class="flex flex-col gap-3 w-full max-w-96 {props.class ?? ''}">
|
2025-02-02 11:17:22 +01:00
|
|
|
<fieldset class="flex flex-col gap-2">
|
2025-06-21 21:07:36 +02:00
|
|
|
<Label for="name">{i18n._('menu.metadata.name')}</Label>
|
2025-02-02 11:17:22 +01:00
|
|
|
<Input
|
|
|
|
|
bind:value={name}
|
|
|
|
|
id="name"
|
|
|
|
|
class="font-semibold h-8"
|
2025-10-05 19:34:05 +02:00
|
|
|
disabled={!canCreate && !selectedWaypoint.wpt}
|
2025-02-02 11:17:22 +01:00
|
|
|
/>
|
2025-06-21 21:07:36 +02:00
|
|
|
<Label for="description">{i18n._('menu.metadata.description')}</Label>
|
2025-02-02 11:17:22 +01:00
|
|
|
<Textarea
|
|
|
|
|
bind:value={description}
|
|
|
|
|
id="description"
|
2025-10-05 19:34:05 +02:00
|
|
|
disabled={!canCreate && !selectedWaypoint.wpt}
|
2025-02-02 11:17:22 +01:00
|
|
|
/>
|
2025-06-21 21:07:36 +02:00
|
|
|
<Label for="symbol">{i18n._('toolbar.waypoint.icon')}</Label>
|
|
|
|
|
<Select.Root bind:value={symbolKey} type="single">
|
2025-02-02 11:17:22 +01:00
|
|
|
<Select.Trigger
|
|
|
|
|
id="symbol"
|
|
|
|
|
class="w-full h-8"
|
2025-10-05 19:34:05 +02:00
|
|
|
disabled={!canCreate && !selectedWaypoint.wpt}
|
2025-02-02 11:17:22 +01:00
|
|
|
>
|
2025-06-21 21:07:36 +02:00
|
|
|
{#if symbolKey in symbols}
|
|
|
|
|
{i18n._(`gpx.symbol.${symbolKey}`)}
|
|
|
|
|
{:else}
|
|
|
|
|
{symbolKey}
|
|
|
|
|
{/if}
|
2025-02-02 11:17:22 +01:00
|
|
|
</Select.Trigger>
|
|
|
|
|
<Select.Content class="max-h-60 overflow-y-scroll">
|
|
|
|
|
{#each sortedSymbols as [key, symbol]}
|
|
|
|
|
<Select.Item value={symbol.value}>
|
|
|
|
|
<span>
|
|
|
|
|
{#if symbol.icon}
|
|
|
|
|
<svelte:component
|
|
|
|
|
this={symbol.icon}
|
|
|
|
|
size="14"
|
|
|
|
|
class="inline-block align-sub mr-0.5"
|
|
|
|
|
/>
|
|
|
|
|
{:else}
|
2025-06-08 16:32:41 +02:00
|
|
|
<span class="w-4 inline-block"></span>
|
2025-02-02 11:17:22 +01:00
|
|
|
{/if}
|
2025-06-21 21:07:36 +02:00
|
|
|
{i18n._(`gpx.symbol.${key}`)}
|
2025-02-02 11:17:22 +01:00
|
|
|
</span>
|
|
|
|
|
</Select.Item>
|
|
|
|
|
{/each}
|
|
|
|
|
</Select.Content>
|
|
|
|
|
</Select.Root>
|
2025-06-21 21:07:36 +02:00
|
|
|
<Label for="link">{i18n._('toolbar.waypoint.link')}</Label>
|
2025-02-02 11:17:22 +01:00
|
|
|
<Input
|
|
|
|
|
bind:value={link}
|
|
|
|
|
id="link"
|
|
|
|
|
class="h-8"
|
2025-10-05 19:34:05 +02:00
|
|
|
disabled={!canCreate && !selectedWaypoint.wpt}
|
2025-02-02 11:17:22 +01:00
|
|
|
/>
|
|
|
|
|
<div class="flex flex-row gap-2">
|
|
|
|
|
<div class="grow">
|
2025-06-21 21:07:36 +02:00
|
|
|
<Label for="latitude">{i18n._('toolbar.waypoint.latitude')}</Label>
|
2025-02-02 11:17:22 +01:00
|
|
|
<Input
|
|
|
|
|
bind:value={latitude}
|
|
|
|
|
type="number"
|
|
|
|
|
id="latitude"
|
|
|
|
|
step={1e-6}
|
|
|
|
|
min={-90}
|
|
|
|
|
max={90}
|
|
|
|
|
class="text-xs h-8"
|
2025-10-05 19:34:05 +02:00
|
|
|
disabled={!canCreate && !selectedWaypoint.wpt}
|
2025-02-02 11:17:22 +01:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="grow">
|
2025-06-21 21:07:36 +02:00
|
|
|
<Label for="longitude">{i18n._('toolbar.waypoint.longitude')}</Label>
|
2025-02-02 11:17:22 +01:00
|
|
|
<Input
|
|
|
|
|
bind:value={longitude}
|
|
|
|
|
type="number"
|
|
|
|
|
id="longitude"
|
|
|
|
|
step={1e-6}
|
|
|
|
|
min={-180}
|
|
|
|
|
max={180}
|
|
|
|
|
class="text-xs h-8"
|
2025-10-05 19:34:05 +02:00
|
|
|
disabled={!canCreate && !selectedWaypoint.wpt}
|
2025-02-02 11:17:22 +01:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</fieldset>
|
|
|
|
|
<div class="flex flex-row gap-2 items-center">
|
|
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
2025-10-05 19:34:05 +02:00
|
|
|
disabled={!canCreate && !selectedWaypoint.wpt}
|
2025-02-02 11:17:22 +01:00
|
|
|
class="grow whitespace-normal h-fit"
|
2025-06-21 21:07:36 +02:00
|
|
|
onclick={createOrUpdateWaypoint}
|
2025-02-02 11:17:22 +01:00
|
|
|
>
|
2025-10-05 19:34:05 +02:00
|
|
|
{#if selectedWaypoint.wpt}
|
2025-02-02 11:17:22 +01:00
|
|
|
<Save size="16" class="mr-1 shrink-0" />
|
2025-06-21 21:07:36 +02:00
|
|
|
{i18n._('menu.metadata.save')}
|
2025-02-02 11:17:22 +01:00
|
|
|
{:else}
|
|
|
|
|
<MapPin size="16" class="mr-1 shrink-0" />
|
2025-06-21 21:07:36 +02:00
|
|
|
{i18n._('toolbar.waypoint.create')}
|
2025-02-02 11:17:22 +01:00
|
|
|
{/if}
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
2025-06-21 21:07:36 +02:00
|
|
|
onclick={() => {
|
2025-10-05 19:34:05 +02:00
|
|
|
selectedWaypoint.reset();
|
2025-02-02 11:17:22 +01:00
|
|
|
resetWaypointData();
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<CircleX size="16" />
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
2025-06-21 21:07:36 +02:00
|
|
|
<Help link={getURLForLanguage(i18n.lang, '/help/toolbar/poi')}>
|
2025-10-05 19:34:05 +02:00
|
|
|
{#if selectedWaypoint.wpt || canCreate}
|
2025-06-21 21:07:36 +02:00
|
|
|
{i18n._('toolbar.waypoint.help')}
|
2025-02-02 11:17:22 +01:00
|
|
|
{:else}
|
2025-06-21 21:07:36 +02:00
|
|
|
{i18n._('toolbar.waypoint.help_no_selection')}
|
2025-02-02 11:17:22 +01:00
|
|
|
{/if}
|
|
|
|
|
</Help>
|
2024-05-24 20:23:49 +02:00
|
|
|
</div>
|