mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-09-01 08:12:32 +00:00
map context menu with coordinates, closes #149
This commit is contained in:
18
website/src/lib/components/CoordinatesPopup.svelte
Normal file
18
website/src/lib/components/CoordinatesPopup.svelte
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { map } from '$lib/stores';
|
||||||
|
import { trackpointPopup } from '$lib/components/gpx-layer/GPXLayerPopup';
|
||||||
|
import { TrackPoint } from 'gpx';
|
||||||
|
|
||||||
|
$: if ($map) {
|
||||||
|
$map.on('contextmenu', (e) => {
|
||||||
|
trackpointPopup?.setItem({
|
||||||
|
item: new TrackPoint({
|
||||||
|
attributes: {
|
||||||
|
lat: e.lngLat.lat,
|
||||||
|
lon: e.lngLat.lng
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
@@ -7,6 +7,7 @@ import MapPopupComponent from "./MapPopup.svelte";
|
|||||||
export type PopupItem<T = Waypoint | TrackPoint | any> = {
|
export type PopupItem<T = Waypoint | TrackPoint | any> = {
|
||||||
item: T;
|
item: T;
|
||||||
fileId?: string;
|
fileId?: string;
|
||||||
|
hide?: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export class MapPopup {
|
export class MapPopup {
|
||||||
@@ -30,6 +31,8 @@ export class MapPopup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setItem(item: PopupItem | null) {
|
setItem(item: PopupItem | null) {
|
||||||
|
if (item)
|
||||||
|
item.hide = () => this.hide();
|
||||||
this.item.set(item);
|
this.item.set(item);
|
||||||
if (item === null) {
|
if (item === null) {
|
||||||
this.hide();
|
this.hide();
|
||||||
|
@@ -2,9 +2,11 @@
|
|||||||
import type { TrackPoint } from 'gpx';
|
import type { TrackPoint } from 'gpx';
|
||||||
import type { PopupItem } from '$lib/components/MapPopup';
|
import type { PopupItem } from '$lib/components/MapPopup';
|
||||||
import * as Card from '$lib/components/ui/card';
|
import * as Card from '$lib/components/ui/card';
|
||||||
|
import { Button } from '$lib/components/ui/button';
|
||||||
import WithUnits from '$lib/components/WithUnits.svelte';
|
import WithUnits from '$lib/components/WithUnits.svelte';
|
||||||
import { Compass, Mountain, Timer } from 'lucide-svelte';
|
import { Compass, Mountain, Timer, ClipboardCopy } from 'lucide-svelte';
|
||||||
import { df } from '$lib/utils';
|
import { df } from '$lib/utils';
|
||||||
|
import { _ } from 'svelte-i18n';
|
||||||
|
|
||||||
export let trackpoint: PopupItem<TrackPoint>;
|
export let trackpoint: PopupItem<TrackPoint>;
|
||||||
</script>
|
</script>
|
||||||
@@ -32,5 +34,18 @@
|
|||||||
{df.format(trackpoint.item.time)}
|
{df.format(trackpoint.item.time)}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
<Button
|
||||||
|
class="w-full px-2 py-1 h-6 justify-start mt-0.5"
|
||||||
|
variant="secondary"
|
||||||
|
on:click={() => {
|
||||||
|
navigator.clipboard.writeText(
|
||||||
|
`${trackpoint.item.getLatitude().toFixed(6)}, ${trackpoint.item.getLongitude().toFixed(6)}`
|
||||||
|
);
|
||||||
|
trackpoint.hide?.();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<ClipboardCopy size="16" class="mr-1" />
|
||||||
|
{$_('menu.copy_coordinates')}
|
||||||
|
</Button>
|
||||||
</Card.Content>
|
</Card.Content>
|
||||||
</Card.Root>
|
</Card.Root>
|
||||||
|
@@ -79,7 +79,8 @@
|
|||||||
"hide": "Hide",
|
"hide": "Hide",
|
||||||
"unhide": "Unhide",
|
"unhide": "Unhide",
|
||||||
"center": "Center",
|
"center": "Center",
|
||||||
"open_in": "Open in"
|
"open_in": "Open in",
|
||||||
|
"copy_coordinates": "Copy coordinates"
|
||||||
},
|
},
|
||||||
"toolbar": {
|
"toolbar": {
|
||||||
"routing": {
|
"routing": {
|
||||||
|
@@ -8,6 +8,7 @@
|
|||||||
import Toolbar from '$lib/components/toolbar/Toolbar.svelte';
|
import Toolbar from '$lib/components/toolbar/Toolbar.svelte';
|
||||||
import StreetViewControl from '$lib/components/street-view-control/StreetViewControl.svelte';
|
import StreetViewControl from '$lib/components/street-view-control/StreetViewControl.svelte';
|
||||||
import LayerControl from '$lib/components/layer-control/LayerControl.svelte';
|
import LayerControl from '$lib/components/layer-control/LayerControl.svelte';
|
||||||
|
import CoordinatesPopup from '$lib/components/CoordinatesPopup.svelte';
|
||||||
import Resizer from '$lib/components/Resizer.svelte';
|
import Resizer from '$lib/components/Resizer.svelte';
|
||||||
import { Toaster } from '$lib/components/ui/sonner';
|
import { Toaster } from '$lib/components/ui/sonner';
|
||||||
import { observeFilesFromDatabase, settings } from '$lib/db';
|
import { observeFilesFromDatabase, settings } from '$lib/db';
|
||||||
@@ -99,6 +100,7 @@
|
|||||||
<StreetViewControl />
|
<StreetViewControl />
|
||||||
<LayerControl />
|
<LayerControl />
|
||||||
<GPXLayers />
|
<GPXLayers />
|
||||||
|
<CoordinatesPopup />
|
||||||
<Toaster richColors />
|
<Toaster richColors />
|
||||||
{#if !$treeFileView}
|
{#if !$treeFileView}
|
||||||
<div class="h-10 -translate-y-10 w-full pointer-events-none absolute z-30">
|
<div class="h-10 -translate-y-10 w-full pointer-events-none absolute z-30">
|
||||||
|
Reference in New Issue
Block a user