2024-04-22 19:36:31 +02:00
|
|
|
<script lang="ts">
|
2024-04-28 17:50:39 +02:00
|
|
|
import ToolbarItemMenu from '$lib/components/toolbar/ToolbarItemMenu.svelte';
|
2024-04-22 19:36:31 +02: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';
|
2024-05-07 17:19:53 +02:00
|
|
|
import { Button } from '$lib/components/ui/button';
|
|
|
|
import Help from '$lib/components/Help.svelte';
|
|
|
|
import Tooltip from '$lib/components/Tooltip.svelte';
|
|
|
|
import {
|
|
|
|
Bike,
|
|
|
|
Footprints,
|
|
|
|
Waves,
|
|
|
|
TrainFront,
|
|
|
|
Route,
|
|
|
|
TriangleAlert,
|
|
|
|
ArrowRightLeft,
|
2024-05-08 12:20:01 +02:00
|
|
|
Home,
|
|
|
|
RouteOff
|
2024-05-07 17:19:53 +02:00
|
|
|
} from 'lucide-svelte';
|
2024-04-22 19:36:31 +02:00
|
|
|
|
2024-05-22 16:05:31 +02:00
|
|
|
import { map, Tool } from '$lib/stores';
|
2024-05-07 17:19:53 +02:00
|
|
|
import { dbUtils, settings } from '$lib/db';
|
2024-05-04 15:10:30 +02:00
|
|
|
import { brouterProfiles, routingProfileSelectItem } from './Routing';
|
2024-04-23 14:11:05 +02:00
|
|
|
|
2024-04-24 18:13:01 +02:00
|
|
|
import { _ } from 'svelte-i18n';
|
2024-04-30 20:55:47 +02:00
|
|
|
import { get } from 'svelte/store';
|
2024-04-25 16:41:06 +02:00
|
|
|
import { RoutingControls } from './RoutingControls';
|
2024-04-26 13:33:17 +02:00
|
|
|
import RoutingControlPopup from './RoutingControlPopup.svelte';
|
|
|
|
import { onMount } from 'svelte';
|
|
|
|
import mapboxgl from 'mapbox-gl';
|
2024-05-02 19:51:08 +02:00
|
|
|
import { fileObservers } from '$lib/db';
|
2024-05-07 17:19:53 +02:00
|
|
|
import { slide } from 'svelte/transition';
|
2024-05-22 16:05:31 +02:00
|
|
|
import { selection } from '$lib/components/file-list/Selection';
|
|
|
|
import type { ListItem } from '$lib/components/file-list/FileList';
|
2024-04-25 16:41:06 +02:00
|
|
|
|
2024-04-30 20:55:47 +02:00
|
|
|
let routingControls: Map<string, RoutingControls> = new Map();
|
2024-04-26 13:33:17 +02:00
|
|
|
let popupElement: HTMLElement;
|
|
|
|
let popup: mapboxgl.Popup | null = null;
|
2024-05-22 16:05:31 +02:00
|
|
|
let selectedItem: ListItem | null = null;
|
2024-04-25 16:41:06 +02:00
|
|
|
let active = false;
|
|
|
|
|
2024-05-04 15:10:30 +02:00
|
|
|
const { privateRoads, routing } = settings;
|
|
|
|
|
2024-05-02 19:51:08 +02:00
|
|
|
$: if ($map) {
|
2024-04-25 16:41:06 +02:00
|
|
|
// remove controls for deleted files
|
2024-04-30 20:55:47 +02:00
|
|
|
routingControls.forEach((controls, fileId) => {
|
2024-05-02 19:51:08 +02:00
|
|
|
if (!$fileObservers.has(fileId)) {
|
2024-04-25 16:41:06 +02:00
|
|
|
controls.remove();
|
2024-04-30 20:55:47 +02:00
|
|
|
routingControls.delete(fileId);
|
2024-04-30 22:35:54 +02:00
|
|
|
|
2024-05-22 16:05:31 +02:00
|
|
|
if (selectedItem && selectedItem.getFileId() === fileId) {
|
|
|
|
selectedItem = null;
|
2024-04-30 22:35:54 +02:00
|
|
|
}
|
2024-04-25 16:41:06 +02:00
|
|
|
}
|
2024-04-23 16:20:47 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-05-22 16:05:31 +02:00
|
|
|
$: if ($map && $selection) {
|
2024-04-25 16:41:06 +02:00
|
|
|
// update selected file
|
2024-05-22 16:05:31 +02:00
|
|
|
if ($selection.size == 0 || $selection.size > 1 || !active) {
|
|
|
|
if (selectedItem) {
|
|
|
|
routingControls.get(selectedItem.getFileId())?.remove();
|
2024-04-25 16:41:06 +02:00
|
|
|
}
|
2024-05-22 16:05:31 +02:00
|
|
|
selectedItem = null;
|
2024-04-25 11:13:15 +02:00
|
|
|
} else {
|
2024-05-22 16:05:31 +02:00
|
|
|
let newSelectedItem = get(selection).getSelected()[0];
|
|
|
|
if (selectedItem !== newSelectedItem) {
|
|
|
|
if (selectedItem) {
|
|
|
|
routingControls.get(selectedItem.getFileId())?.remove();
|
2024-04-25 16:41:06 +02:00
|
|
|
}
|
2024-05-22 16:05:31 +02:00
|
|
|
selectedItem = newSelectedItem;
|
2024-04-25 16:41:06 +02:00
|
|
|
}
|
2024-04-25 11:13:15 +02:00
|
|
|
}
|
|
|
|
}
|
2024-04-24 20:13:42 +02:00
|
|
|
|
2024-05-22 16:05:31 +02:00
|
|
|
$: if ($map && selectedItem) {
|
|
|
|
let fileId = selectedItem.getFileId();
|
|
|
|
if (!routingControls.has(fileId)) {
|
|
|
|
let selectedFileObserver = get(fileObservers).get(fileId);
|
2024-05-02 19:51:08 +02:00
|
|
|
if (selectedFileObserver) {
|
2024-04-30 20:55:47 +02:00
|
|
|
routingControls.set(
|
2024-05-22 16:05:31 +02:00
|
|
|
fileId,
|
|
|
|
new RoutingControls(get(map), fileId, selectedFileObserver, popup, popupElement)
|
2024-04-30 20:55:47 +02:00
|
|
|
);
|
|
|
|
}
|
2024-04-25 16:41:06 +02:00
|
|
|
} else {
|
2024-05-22 16:05:31 +02:00
|
|
|
routingControls.get(fileId)?.add();
|
2024-04-25 16:41:06 +02:00
|
|
|
}
|
2024-04-22 19:36:31 +02:00
|
|
|
}
|
2024-04-26 13:33:17 +02:00
|
|
|
|
|
|
|
onMount(() => {
|
|
|
|
popup = new mapboxgl.Popup({
|
|
|
|
closeButton: false,
|
|
|
|
maxWidth: undefined
|
|
|
|
});
|
|
|
|
popup.setDOMContent(popupElement);
|
|
|
|
popupElement.classList.remove('hidden');
|
|
|
|
});
|
2024-04-22 19:36:31 +02:00
|
|
|
</script>
|
|
|
|
|
2024-04-28 18:59:31 +02:00
|
|
|
<ToolbarItemMenu tool={Tool.ROUTING} bind:active>
|
2024-05-07 17:19:53 +02:00
|
|
|
<Tooltip>
|
|
|
|
<div slot="data" class="w-full flex flex-row justify-between items-center gap-2">
|
2024-05-08 12:20:01 +02:00
|
|
|
<Label for="routing" class="flex flex-row gap-1">
|
|
|
|
{#if $routing}
|
|
|
|
<Route size="16" />
|
|
|
|
{:else}
|
|
|
|
<RouteOff size="16" />
|
|
|
|
{/if}
|
|
|
|
{$_('toolbar.routing.use_routing')}</Label
|
2024-05-07 17:19:53 +02:00
|
|
|
>
|
|
|
|
<Switch id="routing" class="scale-90" bind:checked={$routing} />
|
|
|
|
</div>
|
|
|
|
<span slot="tooltip">{$_('toolbar.routing.use_routing_tooltip')}</span>
|
|
|
|
</Tooltip>
|
|
|
|
{#if $routing}
|
|
|
|
<div class="flex flex-col gap-3" in:slide>
|
|
|
|
<div class="w-full flex flex-row justify-between items-center gap-2">
|
|
|
|
<Label class="flex flex-row gap-1">
|
|
|
|
{#if $routingProfileSelectItem.value.includes('bike') || $routingProfileSelectItem.value.includes('motorcycle')}
|
|
|
|
<Bike size="16" />
|
|
|
|
{:else if $routingProfileSelectItem.value.includes('foot')}
|
|
|
|
<Footprints size="16" />
|
|
|
|
{:else if $routingProfileSelectItem.value.includes('water')}
|
|
|
|
<Waves size="16" />
|
|
|
|
{:else if $routingProfileSelectItem.value.includes('railway')}
|
|
|
|
<TrainFront size="16" />
|
|
|
|
{/if}
|
|
|
|
{$_('toolbar.routing.activity')}
|
|
|
|
</Label>
|
|
|
|
<Select.Root bind:selected={$routingProfileSelectItem}>
|
|
|
|
<Select.Trigger class="h-8 w-full">
|
|
|
|
<Select.Value />
|
|
|
|
</Select.Trigger>
|
|
|
|
<Select.Content>
|
|
|
|
{#each Object.keys(brouterProfiles) as profile}
|
|
|
|
<Select.Item value={profile}
|
|
|
|
>{$_(`toolbar.routing.activities.${profile}`)}</Select.Item
|
|
|
|
>
|
|
|
|
{/each}
|
|
|
|
</Select.Content>
|
|
|
|
</Select.Root>
|
|
|
|
</div>
|
|
|
|
<div class="w-full flex flex-row justify-between items-center gap-2">
|
|
|
|
<Label for="private" class="flex flex-row gap-1"
|
|
|
|
><TriangleAlert size="16" />{$_('toolbar.routing.allow_private')}</Label
|
|
|
|
>
|
|
|
|
<Switch id="private" class="scale-90" bind:checked={$privateRoads} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
<div class="flex flex-row justify-center gap-2">
|
|
|
|
<Tooltip>
|
|
|
|
<Button
|
|
|
|
slot="data"
|
|
|
|
variant="outline"
|
2024-05-22 16:05:31 +02:00
|
|
|
on:click={() => dbUtils.applyToSelection((file) => file.reverse())}
|
2024-05-07 17:19:53 +02:00
|
|
|
>
|
|
|
|
<ArrowRightLeft size="16" />
|
|
|
|
</Button>
|
|
|
|
<span slot="tooltip">{$_('toolbar.routing.reverse_tooltip')}</span>
|
|
|
|
</Tooltip>
|
|
|
|
<Tooltip>
|
|
|
|
<Button
|
|
|
|
slot="data"
|
|
|
|
variant="outline"
|
2024-05-22 16:05:31 +02:00
|
|
|
disabled={$selection.size != 1}
|
2024-05-07 17:19:53 +02:00
|
|
|
on:click={() => {
|
2024-05-22 16:05:31 +02:00
|
|
|
const fileId = get(selection).getSelected()[0].getFileId();
|
2024-05-07 17:19:53 +02:00
|
|
|
routingControls.get(fileId)?.routeToStart();
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Home size="16" />
|
|
|
|
</Button>
|
|
|
|
<span slot="tooltip">{$_('toolbar.routing.route_back_to_start_tooltip')}</span>
|
|
|
|
</Tooltip>
|
|
|
|
<Tooltip>
|
|
|
|
<Button
|
|
|
|
slot="data"
|
|
|
|
variant="outline"
|
2024-05-22 16:05:31 +02:00
|
|
|
disabled={$selection.size != 1}
|
2024-05-07 17:19:53 +02:00
|
|
|
on:click={() => {
|
2024-05-22 16:05:31 +02:00
|
|
|
const fileId = get(selection).getSelected()[0].getFileId();
|
2024-05-07 17:19:53 +02:00
|
|
|
routingControls.get(fileId)?.createRoundTrip();
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Home size="16" />
|
|
|
|
</Button>
|
|
|
|
<span slot="tooltip">{$_('toolbar.routing.round_trip_tooltip')}</span>
|
|
|
|
</Tooltip>
|
2024-04-28 18:59:31 +02:00
|
|
|
</div>
|
2024-05-07 17:19:53 +02:00
|
|
|
<Help class="max-w-60">
|
2024-05-22 16:05:31 +02:00
|
|
|
{#if $selection.size > 1}
|
2024-05-07 17:19:53 +02:00
|
|
|
<div>{$_('toolbar.routing.help_multiple_files')}</div>
|
2024-05-22 16:05:31 +02:00
|
|
|
{:else if $selection.size == 0}
|
2024-05-07 17:19:53 +02:00
|
|
|
<div>{$_('toolbar.routing.help_no_file')}</div>
|
|
|
|
{:else}
|
|
|
|
<div>{$_('toolbar.routing.help')}</div>
|
|
|
|
{/if}
|
|
|
|
</Help>
|
2024-04-28 18:59:31 +02:00
|
|
|
</ToolbarItemMenu>
|
2024-04-26 13:33:17 +02:00
|
|
|
|
|
|
|
<RoutingControlPopup bind:element={popupElement} />
|