mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-09-02 16:52:31 +00:00
improve routing menu
This commit is contained in:
@@ -367,7 +367,7 @@ export class TrackSegment extends GPXTreeLeaf {
|
|||||||
this.trkpt.splice(start, end - start + 1, ...points);
|
this.trkpt.splice(start, end - start + 1, ...points);
|
||||||
}
|
}
|
||||||
|
|
||||||
reverse(originalNextTimestamp: Date | undefined, newPreviousTimestamp: Date | undefined): void {
|
reverse(originalNextTimestamp?: Date, newPreviousTimestamp?: Date): void {
|
||||||
if (originalNextTimestamp !== undefined && newPreviousTimestamp !== undefined) {
|
if (originalNextTimestamp !== undefined && newPreviousTimestamp !== undefined) {
|
||||||
let originalEndTimestamp = this.getEndTimestamp();
|
let originalEndTimestamp = this.getEndTimestamp();
|
||||||
let newStartTimestamp = new Date(
|
let newStartTimestamp = new Date(
|
||||||
|
8
website/src/lib/components/Help.svelte
Normal file
8
website/src/lib/components/Help.svelte
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<script>
|
||||||
|
import { CircleHelp } from 'lucide-svelte';
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="{$$props.class || ''} text-sm rounded border flex flex-row items-center p-2">
|
||||||
|
<CircleHelp size="16" class="w-10 mr-2" />
|
||||||
|
<slot />
|
||||||
|
</div>
|
@@ -1,11 +1,9 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Tool } from '$lib/stores';
|
import { Tool } from '$lib/stores';
|
||||||
import { dbUtils } from '$lib/db';
|
|
||||||
import Routing from '$lib/components/toolbar/tools/routing/Routing.svelte';
|
import Routing from '$lib/components/toolbar/tools/routing/Routing.svelte';
|
||||||
import Waypoint from '$lib/components/toolbar/tools/waypoint/Waypoint.svelte';
|
import Waypoint from '$lib/components/toolbar/tools/waypoint/Waypoint.svelte';
|
||||||
import ToolbarItem from './ToolbarItem.svelte';
|
import ToolbarItem from './ToolbarItem.svelte';
|
||||||
import {
|
import {
|
||||||
ArrowRightLeft,
|
|
||||||
Group,
|
Group,
|
||||||
CalendarClock,
|
CalendarClock,
|
||||||
Pencil,
|
Pencil,
|
||||||
@@ -33,13 +31,6 @@
|
|||||||
<CalendarClock slot="icon" size="18" />
|
<CalendarClock slot="icon" size="18" />
|
||||||
<span slot="tooltip">{$_('toolbar.time_tooltip')}</span>
|
<span slot="tooltip">{$_('toolbar.time_tooltip')}</span>
|
||||||
</ToolbarItem>
|
</ToolbarItem>
|
||||||
<ToolbarItem
|
|
||||||
tool={Tool.REVERSE}
|
|
||||||
on:click={() => dbUtils.applyToSelectedFiles((file) => file.reverse())}
|
|
||||||
>
|
|
||||||
<ArrowRightLeft slot="icon" size="18" />
|
|
||||||
<span slot="tooltip">{$_('toolbar.reverse_tooltip')}</span>
|
|
||||||
</ToolbarItem>
|
|
||||||
<ToolbarItem tool={Tool.MERGE}>
|
<ToolbarItem tool={Tool.MERGE}>
|
||||||
<Group slot="icon" size="18" />
|
<Group slot="icon" size="18" />
|
||||||
<span slot="tooltip">{$_('toolbar.merge_tooltip')}</span>
|
<span slot="tooltip">{$_('toolbar.merge_tooltip')}</span>
|
||||||
|
@@ -13,10 +13,18 @@
|
|||||||
<div in:flyAndScale={{ x: -2, y: 0, duration: 100 }} class="translate-x-1 h-full">
|
<div in:flyAndScale={{ x: -2, y: 0, duration: 100 }} class="translate-x-1 h-full">
|
||||||
<div class="rounded-md shadow-md pointer-events-auto">
|
<div class="rounded-md shadow-md pointer-events-auto">
|
||||||
<Card.Root class="border-none">
|
<Card.Root class="border-none">
|
||||||
<Card.Content class="p-4 flex flex-col gap-4">
|
<Card.Content class="p-3 flex flex-col gap-3">
|
||||||
<slot />
|
<slot />
|
||||||
</Card.Content>
|
</Card.Content>
|
||||||
</Card.Root>
|
</Card.Root>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
<svelte:window
|
||||||
|
on:keydown={(e) => {
|
||||||
|
if (active && e.key === 'Escape') {
|
||||||
|
currentTool.set(null);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
@@ -3,11 +3,22 @@
|
|||||||
import * as Select from '$lib/components/ui/select';
|
import * as Select from '$lib/components/ui/select';
|
||||||
import { Switch } from '$lib/components/ui/switch';
|
import { Switch } from '$lib/components/ui/switch';
|
||||||
import { Label } from '$lib/components/ui/label/index.js';
|
import { Label } from '$lib/components/ui/label/index.js';
|
||||||
import * as Alert from '$lib/components/ui/alert';
|
import { Button } from '$lib/components/ui/button';
|
||||||
import { CircleHelp } from 'lucide-svelte';
|
import Help from '$lib/components/Help.svelte';
|
||||||
|
import Tooltip from '$lib/components/Tooltip.svelte';
|
||||||
|
import {
|
||||||
|
Bike,
|
||||||
|
Footprints,
|
||||||
|
Waves,
|
||||||
|
TrainFront,
|
||||||
|
Route,
|
||||||
|
TriangleAlert,
|
||||||
|
ArrowRightLeft,
|
||||||
|
Home
|
||||||
|
} from 'lucide-svelte';
|
||||||
|
|
||||||
import { map, selectedFiles, Tool } from '$lib/stores';
|
import { map, selectedFiles, Tool } from '$lib/stores';
|
||||||
import { settings } from '$lib/db';
|
import { dbUtils, settings } from '$lib/db';
|
||||||
import { brouterProfiles, routingProfileSelectItem } from './Routing';
|
import { brouterProfiles, routingProfileSelectItem } from './Routing';
|
||||||
|
|
||||||
import { _ } from 'svelte-i18n';
|
import { _ } from 'svelte-i18n';
|
||||||
@@ -17,6 +28,7 @@
|
|||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import mapboxgl from 'mapbox-gl';
|
import mapboxgl from 'mapbox-gl';
|
||||||
import { fileObservers } from '$lib/db';
|
import { fileObservers } from '$lib/db';
|
||||||
|
import { slide } from 'svelte/transition';
|
||||||
|
|
||||||
let routingControls: Map<string, RoutingControls> = new Map();
|
let routingControls: Map<string, RoutingControls> = new Map();
|
||||||
let popupElement: HTMLElement;
|
let popupElement: HTMLElement;
|
||||||
@@ -83,30 +95,92 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ToolbarItemMenu tool={Tool.ROUTING} bind:active>
|
<ToolbarItemMenu tool={Tool.ROUTING} bind:active>
|
||||||
|
<Tooltip>
|
||||||
|
<div slot="data" class="w-full flex flex-row justify-between items-center gap-2">
|
||||||
|
<Label for="routing" class="flex flex-row gap-1"
|
||||||
|
><Route size="16" />{$_('toolbar.routing.use_routing')}</Label
|
||||||
|
>
|
||||||
|
<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">
|
<div class="w-full flex flex-row justify-between items-center gap-2">
|
||||||
<Label>{$_('toolbar.routing.activity')}</Label>
|
<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.Root bind:selected={$routingProfileSelectItem}>
|
||||||
<Select.Trigger class="h-8 w-40">
|
<Select.Trigger class="h-8 w-full">
|
||||||
<Select.Value />
|
<Select.Value />
|
||||||
</Select.Trigger>
|
</Select.Trigger>
|
||||||
<Select.Content>
|
<Select.Content>
|
||||||
{#each Object.keys(brouterProfiles) as profile}
|
{#each Object.keys(brouterProfiles) as profile}
|
||||||
<Select.Item value={profile}>{$_(`toolbar.routing.activities.${profile}`)}</Select.Item>
|
<Select.Item value={profile}
|
||||||
|
>{$_(`toolbar.routing.activities.${profile}`)}</Select.Item
|
||||||
|
>
|
||||||
{/each}
|
{/each}
|
||||||
</Select.Content>
|
</Select.Content>
|
||||||
</Select.Root>
|
</Select.Root>
|
||||||
</div>
|
</div>
|
||||||
<div class="w-full flex flex-row justify-between items-center gap-2">
|
<div class="w-full flex flex-row justify-between items-center gap-2">
|
||||||
<Label for="routing">{$_('toolbar.routing.use_routing')}</Label>
|
<Label for="private" class="flex flex-row gap-1"
|
||||||
<Switch id="routing" class="scale-90" bind:checked={$routing} />
|
><TriangleAlert size="16" />{$_('toolbar.routing.allow_private')}</Label
|
||||||
</div>
|
>
|
||||||
<div class="w-full flex flex-row justify-between items-center gap-2">
|
|
||||||
<Label for="private">{$_('toolbar.routing.allow_private')}</Label>
|
|
||||||
<Switch id="private" class="scale-90" bind:checked={$privateRoads} />
|
<Switch id="private" class="scale-90" bind:checked={$privateRoads} />
|
||||||
</div>
|
</div>
|
||||||
<Alert.Root class="max-w-64">
|
</div>
|
||||||
<CircleHelp size="16" />
|
{/if}
|
||||||
<Alert.Description>
|
<div class="flex flex-row justify-center gap-2">
|
||||||
|
<Tooltip>
|
||||||
|
<Button
|
||||||
|
slot="data"
|
||||||
|
variant="outline"
|
||||||
|
on:click={() => dbUtils.applyToSelectedFiles((file) => file.reverse())}
|
||||||
|
>
|
||||||
|
<ArrowRightLeft size="16" />
|
||||||
|
</Button>
|
||||||
|
<span slot="tooltip">{$_('toolbar.routing.reverse_tooltip')}</span>
|
||||||
|
</Tooltip>
|
||||||
|
<Tooltip>
|
||||||
|
<Button
|
||||||
|
slot="data"
|
||||||
|
variant="outline"
|
||||||
|
disabled={$selectedFiles.size != 1}
|
||||||
|
on:click={() => {
|
||||||
|
const fileId = get(selectedFiles).values().next().value;
|
||||||
|
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"
|
||||||
|
disabled={$selectedFiles.size != 1}
|
||||||
|
on:click={() => {
|
||||||
|
const fileId = get(selectedFiles).values().next().value;
|
||||||
|
routingControls.get(fileId)?.createRoundTrip();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Home size="16" />
|
||||||
|
</Button>
|
||||||
|
<span slot="tooltip">{$_('toolbar.routing.round_trip_tooltip')}</span>
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
<Help class="max-w-60">
|
||||||
{#if $selectedFiles.size > 1}
|
{#if $selectedFiles.size > 1}
|
||||||
<div>{$_('toolbar.routing.help_multiple_files')}</div>
|
<div>{$_('toolbar.routing.help_multiple_files')}</div>
|
||||||
{:else if $selectedFiles.size == 0}
|
{:else if $selectedFiles.size == 0}
|
||||||
@@ -114,8 +188,7 @@
|
|||||||
{:else}
|
{:else}
|
||||||
<div>{$_('toolbar.routing.help')}</div>
|
<div>{$_('toolbar.routing.help')}</div>
|
||||||
{/if}
|
{/if}
|
||||||
</Alert.Description>
|
</Help>
|
||||||
</Alert.Root>
|
|
||||||
</ToolbarItemMenu>
|
</ToolbarItemMenu>
|
||||||
|
|
||||||
<RoutingControlPopup bind:element={popupElement} />
|
<RoutingControlPopup bind:element={popupElement} />
|
||||||
|
@@ -315,13 +315,17 @@ export class RoutingControls {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async appendAnchor(e: mapboxgl.MapMouseEvent) { // Add a new anchor to the end of the last segment
|
async appendAnchor(e: mapboxgl.MapMouseEvent) { // Add a new anchor to the end of the last segment
|
||||||
|
this.appendAnchorWithCoordinates({
|
||||||
|
lat: e.lngLat.lat,
|
||||||
|
lon: e.lngLat.lng
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async appendAnchorWithCoordinates(coordinates: Coordinates) { // Add a new anchor to the end of the last segment
|
||||||
let lastAnchor = this.anchors[this.anchors.length - 1];
|
let lastAnchor = this.anchors[this.anchors.length - 1];
|
||||||
|
|
||||||
let newPoint = new TrackPoint({
|
let newPoint = new TrackPoint({
|
||||||
attributes: {
|
attributes: coordinates
|
||||||
lat: e.lngLat.lat,
|
|
||||||
lon: e.lngLat.lng
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
newPoint._data.anchor = true;
|
newPoint._data.anchor = true;
|
||||||
newPoint._data.zoom = 0;
|
newPoint._data.zoom = 0;
|
||||||
@@ -345,6 +349,36 @@ export class RoutingControls {
|
|||||||
await this.routeBetweenAnchors([lastAnchor, newAnchor], [lastAnchor.point.getCoordinates(), newAnchor.point.getCoordinates()]);
|
await this.routeBetweenAnchors([lastAnchor, newAnchor], [lastAnchor.point.getCoordinates(), newAnchor.point.getCoordinates()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
routeToStart() {
|
||||||
|
let segments = get(this.file).getSegments();
|
||||||
|
if (segments.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let segment = segments[segments.length - 1];
|
||||||
|
let firstAnchor = this.anchors.find((anchor) => anchor.segment === segment);
|
||||||
|
|
||||||
|
if (!firstAnchor) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.appendAnchorWithCoordinates(firstAnchor.point.getCoordinates());
|
||||||
|
}
|
||||||
|
|
||||||
|
createRoundTrip() {
|
||||||
|
let segments = get(this.file).getSegments();
|
||||||
|
if (segments.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
dbUtils.applyToFile(this.fileId, (file) => {
|
||||||
|
let segment = file.getSegments()[segments.length - 1];
|
||||||
|
let newSegment = segment.clone();
|
||||||
|
newSegment.reverse(undefined, undefined);
|
||||||
|
segment.replace(segment.trkpt.length, segment.trkpt.length, newSegment.trkpt);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
getNeighbouringAnchors(anchor: Anchor): [Anchor | null, Anchor | null] {
|
getNeighbouringAnchors(anchor: Anchor): [Anchor | null, Anchor | null] {
|
||||||
let previousAnchor: Anchor | null = null;
|
let previousAnchor: Anchor | null = null;
|
||||||
let nextAnchor: Anchor | null = null;
|
let nextAnchor: Anchor | null = null;
|
||||||
|
@@ -40,8 +40,12 @@
|
|||||||
"routing": {
|
"routing": {
|
||||||
"tooltip": "Edit the route",
|
"tooltip": "Edit the route",
|
||||||
"activity": "Activity",
|
"activity": "Activity",
|
||||||
"use_routing": "Routing (follow roads)",
|
"use_routing": "Routing",
|
||||||
|
"use_routing_tooltip": "Connect anchor points through the road network. Disable to draw straight lines.",
|
||||||
"allow_private": "Allow private roads",
|
"allow_private": "Allow private roads",
|
||||||
|
"reverse_tooltip": "Reverse the direction",
|
||||||
|
"route_back_to_start_tooltip": "Route back to start",
|
||||||
|
"round_trip_tooltip": "Create round trip",
|
||||||
"help_no_file": "Select a file to use the routing tool, or create a new file from the menu",
|
"help_no_file": "Select a file to use the routing tool, or create a new file from the menu",
|
||||||
"help_multiple_files": "Select a single file to use the routing tool",
|
"help_multiple_files": "Select a single file to use the routing tool",
|
||||||
"help": "Click on the map to add a new point, or drag existing points to change the route",
|
"help": "Click on the map to add a new point, or drag existing points to change the route",
|
||||||
@@ -93,7 +97,6 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"time_tooltip": "Change the time and speed data",
|
"time_tooltip": "Change the time and speed data",
|
||||||
"reverse_tooltip": "Reverse the direction",
|
|
||||||
"merge_tooltip": "Merge files together",
|
"merge_tooltip": "Merge files together",
|
||||||
"extract_tooltip": "Extract inner tracks or segments",
|
"extract_tooltip": "Extract inner tracks or segments",
|
||||||
"waypoint_tooltip": "Create a new point of interest",
|
"waypoint_tooltip": "Create a new point of interest",
|
||||||
|
Reference in New Issue
Block a user