2024-04-22 19:36:31 +02:00
|
|
|
<script lang="ts">
|
2025-02-02 11:17:22 +01:00
|
|
|
import * as Select from '$lib/components/ui/select';
|
|
|
|
|
import { Switch } from '$lib/components/ui/switch';
|
|
|
|
|
import { Label } from '$lib/components/ui/label/index.js';
|
|
|
|
|
import { Button } from '$lib/components/ui/button';
|
|
|
|
|
import Help from '$lib/components/Help.svelte';
|
|
|
|
|
import ButtonWithTooltip from '$lib/components/ButtonWithTooltip.svelte';
|
|
|
|
|
import Tooltip from '$lib/components/Tooltip.svelte';
|
|
|
|
|
import Shortcut from '$lib/components/Shortcut.svelte';
|
|
|
|
|
import {
|
|
|
|
|
Bike,
|
|
|
|
|
Footprints,
|
|
|
|
|
Waves,
|
|
|
|
|
TrainFront,
|
|
|
|
|
Route,
|
|
|
|
|
TriangleAlert,
|
|
|
|
|
ArrowRightLeft,
|
|
|
|
|
Home,
|
|
|
|
|
RouteOff,
|
|
|
|
|
Repeat,
|
|
|
|
|
SquareArrowUpLeft,
|
|
|
|
|
SquareArrowOutDownRight,
|
2025-06-21 21:07:36 +02:00
|
|
|
} from '@lucide/svelte';
|
2025-10-18 16:10:08 +02:00
|
|
|
import { brouterProfiles } from '$lib/components/toolbar/tools/routing/routing';
|
2025-06-21 21:07:36 +02:00
|
|
|
import { i18n } from '$lib/i18n.svelte';
|
2025-02-02 11:17:22 +01:00
|
|
|
import { slide } from 'svelte/transition';
|
|
|
|
|
import {
|
|
|
|
|
ListFileItem,
|
|
|
|
|
ListRootItem,
|
|
|
|
|
ListTrackItem,
|
|
|
|
|
ListTrackSegmentItem,
|
|
|
|
|
type ListItem,
|
2025-10-05 19:34:05 +02:00
|
|
|
} from '$lib/components/file-list/file-list';
|
2025-10-18 16:10:08 +02:00
|
|
|
import { getURLForLanguage } from '$lib/utils';
|
2025-02-02 11:17:22 +01:00
|
|
|
import { onDestroy, onMount } from 'svelte';
|
|
|
|
|
import { TrackPoint } from 'gpx';
|
2025-10-17 23:54:45 +02:00
|
|
|
import { settings } from '$lib/logic/settings';
|
|
|
|
|
import { map } from '$lib/components/map/map';
|
2025-10-18 16:10:08 +02:00
|
|
|
import { fileStateCollection, GPXFileStateCollectionObserver } from '$lib/logic/file-state';
|
2025-10-17 23:54:45 +02:00
|
|
|
import { selection } from '$lib/logic/selection';
|
|
|
|
|
import { fileActions, getFileIds, newGPXFile } from '$lib/logic/file-actions';
|
2025-10-18 16:10:08 +02:00
|
|
|
import { mapCursor, MapCursorState } from '$lib/logic/map-cursor';
|
|
|
|
|
import { RoutingControls, routingControls } from './RoutingControls';
|
2025-10-05 19:34:05 +02:00
|
|
|
|
|
|
|
|
let {
|
|
|
|
|
minimized = $bindable(false),
|
|
|
|
|
minimizable = true,
|
|
|
|
|
popup = undefined,
|
|
|
|
|
popupElement = undefined,
|
|
|
|
|
class: className = '',
|
|
|
|
|
}: {
|
|
|
|
|
minimized?: boolean;
|
|
|
|
|
minimizable?: boolean;
|
|
|
|
|
popup?: mapboxgl.Popup;
|
|
|
|
|
popupElement?: HTMLDivElement;
|
|
|
|
|
class?: string;
|
|
|
|
|
} = $props();
|
2024-04-25 16:41:06 +02:00
|
|
|
|
2025-06-21 21:07:36 +02:00
|
|
|
const { privateRoads, routing, routingProfile } = settings;
|
2024-05-04 15:10:30 +02:00
|
|
|
|
2025-10-18 16:10:08 +02:00
|
|
|
let fileStateCollectionObserver: GPXFileStateCollectionObserver;
|
2024-04-26 13:33:17 +02:00
|
|
|
|
2025-10-05 19:34:05 +02:00
|
|
|
let validSelection = $derived(
|
2025-10-17 23:54:45 +02:00
|
|
|
$selection.hasAnyChildren(new ListRootItem(), true, ['waypoints'])
|
2025-10-05 19:34:05 +02:00
|
|
|
);
|
2024-06-15 19:17:27 +02:00
|
|
|
|
2025-02-02 11:17:22 +01:00
|
|
|
function createFileWithPoint(e: any) {
|
2025-10-17 23:54:45 +02:00
|
|
|
if ($selection.size === 0) {
|
2025-02-02 11:17:22 +01:00
|
|
|
let file = newGPXFile();
|
|
|
|
|
file.replaceTrackPoints(0, 0, 0, 0, [
|
|
|
|
|
new TrackPoint({
|
|
|
|
|
attributes: {
|
|
|
|
|
lat: e.lngLat.lat,
|
|
|
|
|
lon: e.lngLat.lng,
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
]);
|
|
|
|
|
file._data.id = getFileIds(1)[0];
|
2025-10-05 19:34:05 +02:00
|
|
|
fileActions.add(file);
|
2025-10-18 16:10:08 +02:00
|
|
|
selection.selectFileWhenLoaded(file._data.id);
|
2025-02-02 11:17:22 +01:00
|
|
|
}
|
|
|
|
|
}
|
2024-06-15 19:17:27 +02:00
|
|
|
|
2025-02-02 11:17:22 +01:00
|
|
|
onMount(() => {
|
2025-10-18 16:10:08 +02:00
|
|
|
if ($map && popup && popupElement) {
|
|
|
|
|
fileStateCollectionObserver = new GPXFileStateCollectionObserver(
|
2025-10-19 16:14:05 +02:00
|
|
|
(newFiles) => {
|
|
|
|
|
newFiles.forEach((fileState, fileId) => {
|
|
|
|
|
routingControls.set(
|
|
|
|
|
fileId,
|
|
|
|
|
new RoutingControls(fileId, fileState, popup, popupElement)
|
|
|
|
|
);
|
|
|
|
|
});
|
2025-10-18 16:10:08 +02:00
|
|
|
},
|
|
|
|
|
(fileId) => {
|
|
|
|
|
const controls = routingControls.get(fileId);
|
|
|
|
|
if (controls) {
|
|
|
|
|
controls.destroy();
|
|
|
|
|
routingControls.delete(fileId);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
() => {
|
|
|
|
|
routingControls.forEach((controls) => controls.destroy());
|
|
|
|
|
routingControls.clear();
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
mapCursor.notify(MapCursorState.TOOL_WITH_CROSSHAIR, true);
|
|
|
|
|
$map.on('click', createFileWithPoint);
|
|
|
|
|
}
|
2025-02-02 11:17:22 +01:00
|
|
|
});
|
2024-06-15 19:17:27 +02:00
|
|
|
|
2025-02-02 11:17:22 +01:00
|
|
|
onDestroy(() => {
|
2025-10-18 16:10:08 +02:00
|
|
|
if ($map) {
|
2025-10-18 18:51:11 +02:00
|
|
|
if (fileStateCollectionObserver) {
|
|
|
|
|
fileStateCollectionObserver.destroy();
|
|
|
|
|
}
|
2024-07-13 11:42:21 +02:00
|
|
|
|
2025-10-18 16:10:08 +02:00
|
|
|
mapCursor.notify(MapCursorState.TOOL_WITH_CROSSHAIR, false);
|
|
|
|
|
$map.off('click', createFileWithPoint);
|
|
|
|
|
}
|
2025-02-02 11:17:22 +01:00
|
|
|
});
|
2024-04-22 19:36:31 +02:00
|
|
|
</script>
|
|
|
|
|
|
2024-09-30 12:56:58 +02:00
|
|
|
{#if minimizable && minimized}
|
2025-02-02 11:17:22 +01:00
|
|
|
<div class="-m-1.5 -mb-2">
|
2025-10-18 18:51:11 +02:00
|
|
|
<Button variant="ghost" size="icon-sm" class="size-6" onclick={() => (minimized = false)}>
|
|
|
|
|
<SquareArrowOutDownRight size="18" class="size-4.5" />
|
2025-02-02 11:17:22 +01:00
|
|
|
</Button>
|
|
|
|
|
</div>
|
2024-06-10 12:06:32 +02:00
|
|
|
{:else}
|
2025-10-05 19:34:05 +02:00
|
|
|
<div class="flex flex-col gap-3 w-full max-w-80 animate-in animate-out {className ?? ''}">
|
2025-02-02 11:17:22 +01:00
|
|
|
<div class="flex flex-col gap-3">
|
2025-10-18 18:51:11 +02:00
|
|
|
<Label class="justify-between">
|
2025-02-02 11:17:22 +01:00
|
|
|
<span class="flex flex-row items-center gap-1">
|
2025-10-18 16:10:08 +02:00
|
|
|
{#if $routing}
|
2025-02-02 11:17:22 +01:00
|
|
|
<Route size="16" />
|
|
|
|
|
{:else}
|
|
|
|
|
<RouteOff size="16" />
|
|
|
|
|
{/if}
|
2025-06-21 21:07:36 +02:00
|
|
|
{i18n._('toolbar.routing.use_routing')}
|
2025-02-02 11:17:22 +01:00
|
|
|
</span>
|
2025-06-21 21:07:36 +02:00
|
|
|
<Tooltip label={i18n._('toolbar.routing.use_routing_tooltip')}>
|
2025-10-18 18:51:11 +02:00
|
|
|
<Switch bind:checked={$routing} />
|
|
|
|
|
{#snippet extra()}
|
|
|
|
|
<Shortcut key="F5" />
|
|
|
|
|
{/snippet}
|
2025-02-02 11:17:22 +01:00
|
|
|
</Tooltip>
|
|
|
|
|
</Label>
|
2025-10-18 16:10:08 +02:00
|
|
|
{#if $routing}
|
2025-02-02 11:17:22 +01:00
|
|
|
<div class="flex flex-col gap-3" in:slide>
|
2025-10-18 18:51:11 +02:00
|
|
|
<Label class="justify-between">
|
2025-02-02 11:17:22 +01:00
|
|
|
<span class="shrink-0 flex flex-row items-center gap-1">
|
2025-10-18 16:10:08 +02:00
|
|
|
{#if $routingProfile.includes('bike') || $routingProfile.includes('motorcycle')}
|
2025-02-02 11:17:22 +01:00
|
|
|
<Bike size="16" />
|
2025-10-18 16:10:08 +02:00
|
|
|
{:else if $routingProfile.includes('foot')}
|
2025-02-02 11:17:22 +01:00
|
|
|
<Footprints size="16" />
|
2025-10-18 16:10:08 +02:00
|
|
|
{:else if $routingProfile.includes('water')}
|
2025-02-02 11:17:22 +01:00
|
|
|
<Waves size="16" />
|
2025-10-18 16:10:08 +02:00
|
|
|
{:else if $routingProfile.includes('railway')}
|
2025-02-02 11:17:22 +01:00
|
|
|
<TrainFront size="16" />
|
|
|
|
|
{/if}
|
2025-06-21 21:07:36 +02:00
|
|
|
{i18n._('toolbar.routing.activity')}
|
2025-02-02 11:17:22 +01:00
|
|
|
</span>
|
2025-10-18 16:10:08 +02:00
|
|
|
<Select.Root type="single" bind:value={$routingProfile}>
|
2025-02-02 11:17:22 +01:00
|
|
|
<Select.Trigger class="h-8 grow">
|
2025-10-18 16:10:08 +02:00
|
|
|
{i18n._(`toolbar.routing.activities.${$routingProfile}`)}
|
2025-02-02 11:17:22 +01:00
|
|
|
</Select.Trigger>
|
|
|
|
|
<Select.Content>
|
|
|
|
|
{#each Object.keys(brouterProfiles) as profile}
|
|
|
|
|
<Select.Item value={profile}
|
2025-06-21 21:07:36 +02:00
|
|
|
>{i18n._(
|
|
|
|
|
`toolbar.routing.activities.${profile}`
|
|
|
|
|
)}</Select.Item
|
2025-02-02 11:17:22 +01:00
|
|
|
>
|
|
|
|
|
{/each}
|
|
|
|
|
</Select.Content>
|
|
|
|
|
</Select.Root>
|
|
|
|
|
</Label>
|
2025-10-18 18:51:11 +02:00
|
|
|
<Label class="justify-between">
|
2025-02-02 11:17:22 +01:00
|
|
|
<span class="flex flex-row gap-1">
|
|
|
|
|
<TriangleAlert size="16" />
|
2025-06-21 21:07:36 +02:00
|
|
|
{i18n._('toolbar.routing.allow_private')}
|
2025-02-02 11:17:22 +01:00
|
|
|
</span>
|
2025-10-18 18:51:11 +02:00
|
|
|
<Switch bind:checked={$privateRoads} />
|
2025-02-02 11:17:22 +01:00
|
|
|
</Label>
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
<div class="flex flex-row flex-wrap justify-center gap-1">
|
|
|
|
|
<ButtonWithTooltip
|
2025-06-21 21:07:36 +02:00
|
|
|
label={i18n._('toolbar.routing.reverse.tooltip')}
|
2025-02-02 11:17:22 +01:00
|
|
|
variant="outline"
|
2025-10-18 18:51:11 +02:00
|
|
|
class="gap-1 text-xs"
|
2025-02-02 11:17:22 +01:00
|
|
|
disabled={!validSelection}
|
2025-10-05 19:34:05 +02:00
|
|
|
onclick={fileActions.reverseSelection}
|
2025-02-02 11:17:22 +01:00
|
|
|
>
|
2025-06-21 21:07:36 +02:00
|
|
|
<ArrowRightLeft size="12" />{i18n._('toolbar.routing.reverse.button')}
|
2025-02-02 11:17:22 +01:00
|
|
|
</ButtonWithTooltip>
|
|
|
|
|
<ButtonWithTooltip
|
2025-06-21 21:07:36 +02:00
|
|
|
label={i18n._('toolbar.routing.route_back_to_start.tooltip')}
|
2025-02-02 11:17:22 +01:00
|
|
|
variant="outline"
|
2025-10-18 18:51:11 +02:00
|
|
|
class="gap-1 text-xs"
|
2025-02-02 11:17:22 +01:00
|
|
|
disabled={!validSelection}
|
2025-06-21 21:07:36 +02:00
|
|
|
onclick={() => {
|
2025-10-05 19:34:05 +02:00
|
|
|
const selected = selection.getOrderedSelection();
|
2025-02-02 11:17:22 +01:00
|
|
|
if (selected.length > 0) {
|
|
|
|
|
const firstFileId = selected[0].getFileId();
|
2025-10-05 19:34:05 +02:00
|
|
|
const firstFile = fileStateCollection.getFile(firstFileId);
|
2025-02-02 11:17:22 +01:00
|
|
|
if (firstFile) {
|
|
|
|
|
let start = (() => {
|
|
|
|
|
if (selected[0] instanceof ListFileItem) {
|
|
|
|
|
return firstFile.trk[0]?.trkseg[0]?.trkpt[0];
|
|
|
|
|
} else if (selected[0] instanceof ListTrackItem) {
|
|
|
|
|
return firstFile.trk[selected[0].getTrackIndex()]?.trkseg[0]
|
|
|
|
|
?.trkpt[0];
|
|
|
|
|
} else if (selected[0] instanceof ListTrackSegmentItem) {
|
|
|
|
|
return firstFile.trk[selected[0].getTrackIndex()]?.trkseg[
|
|
|
|
|
selected[0].getSegmentIndex()
|
|
|
|
|
]?.trkpt[0];
|
|
|
|
|
}
|
|
|
|
|
})();
|
2024-09-30 12:56:58 +02:00
|
|
|
|
2025-02-02 11:17:22 +01:00
|
|
|
if (start !== undefined) {
|
|
|
|
|
const lastFileId = selected[selected.length - 1].getFileId();
|
2025-10-18 16:10:08 +02:00
|
|
|
routingControls
|
|
|
|
|
.get(lastFileId)
|
|
|
|
|
?.appendAnchorWithCoordinates(start.getCoordinates());
|
2025-02-02 11:17:22 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
>
|
2025-06-21 21:07:36 +02:00
|
|
|
<Home size="12" />{i18n._('toolbar.routing.route_back_to_start.button')}
|
2025-02-02 11:17:22 +01:00
|
|
|
</ButtonWithTooltip>
|
|
|
|
|
<ButtonWithTooltip
|
2025-06-21 21:07:36 +02:00
|
|
|
label={i18n._('toolbar.routing.round_trip.tooltip')}
|
2025-02-02 11:17:22 +01:00
|
|
|
variant="outline"
|
2025-10-18 18:51:11 +02:00
|
|
|
class="gap-1 text-xs"
|
2025-02-02 11:17:22 +01:00
|
|
|
disabled={!validSelection}
|
2025-10-17 23:54:45 +02:00
|
|
|
onclick={fileActions.createRoundTripForSelection}
|
2025-02-02 11:17:22 +01:00
|
|
|
>
|
2025-06-21 21:07:36 +02:00
|
|
|
<Repeat size="12" />{i18n._('toolbar.routing.round_trip.button')}
|
2025-02-02 11:17:22 +01:00
|
|
|
</ButtonWithTooltip>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="w-full flex flex-row gap-2 items-end justify-between">
|
2025-06-21 21:07:36 +02:00
|
|
|
<Help link={getURLForLanguage(i18n.lang, '/help/toolbar/routing')}>
|
2025-02-02 11:17:22 +01:00
|
|
|
{#if !validSelection}
|
2025-06-21 21:07:36 +02:00
|
|
|
{i18n._('toolbar.routing.help_no_file')}
|
2025-02-02 11:17:22 +01:00
|
|
|
{:else}
|
2025-06-21 21:07:36 +02:00
|
|
|
{i18n._('toolbar.routing.help')}
|
2025-02-02 11:17:22 +01:00
|
|
|
{/if}
|
|
|
|
|
</Help>
|
|
|
|
|
<Button
|
|
|
|
|
variant="ghost"
|
2025-10-18 18:51:11 +02:00
|
|
|
size="icon-sm"
|
|
|
|
|
class="size-6"
|
2025-06-21 21:07:36 +02:00
|
|
|
onclick={() => {
|
2025-02-02 11:17:22 +01:00
|
|
|
if (minimizable) {
|
|
|
|
|
minimized = true;
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<SquareArrowUpLeft size="18" />
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2024-06-10 12:06:32 +02:00
|
|
|
{/if}
|