From a1341e6036f1b68a57c0b6e66b204b3b43e4ebac Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 6 Jul 2025 23:41:55 +0300 Subject: [PATCH] feat(views/geomap): display geolocation in empty menu --- apps/client/src/translations/en/translation.json | 3 ++- .../src/widgets/view_widgets/geo_view/context_menu.ts | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json index 4470852a9..00cb9f227 100644 --- a/apps/client/src/translations/en/translation.json +++ b/apps/client/src/translations/en/translation.json @@ -1860,7 +1860,8 @@ }, "geo-map-context": { "open-location": "Open location", - "remove-from-map": "Remove from map" + "remove-from-map": "Remove from map", + "add-note": "Add a marker at this location" }, "help-button": { "title": "Open the relevant help page" diff --git a/apps/client/src/widgets/view_widgets/geo_view/context_menu.ts b/apps/client/src/widgets/view_widgets/geo_view/context_menu.ts index 410064f0f..331beac05 100644 --- a/apps/client/src/widgets/view_widgets/geo_view/context_menu.ts +++ b/apps/client/src/widgets/view_widgets/geo_view/context_menu.ts @@ -1,10 +1,11 @@ -import { LeafletMouseEvent } from "leaflet"; +import type { LatLng, LeafletMouseEvent } from "leaflet"; import appContext from "../../../components/app_context.js"; import type { ContextMenuEvent } from "../../../menus/context_menu.js"; import contextMenu from "../../../menus/context_menu.js"; import linkContextMenu from "../../../menus/link_context_menu.js"; import { t } from "../../../services/i18n.js"; import { createNewNote } from "./editing.js"; +import { copyTextWithToast } from "../../../services/clipboard_ext.js"; export default function openContextMenu(noteId: string, e: ContextMenuEvent) { contextMenu.show({ @@ -38,6 +39,10 @@ export function openMapContextMenu(noteId: string, e: LeafletMouseEvent) { x: e.originalEvent.pageX, y: e.originalEvent.pageY, items: [ + { + title: formatGeoLocation(e.latlng), + handler: () => copyTextWithToast(formatGeoLocation(e.latlng, 15)) + }, { title: t("geo-map-context.add-note"), command: "addNoteToMap", uiIcon: "bx bx-plus" } ], selectMenuItemHandler: ({ command }) => { @@ -51,3 +56,7 @@ export function openMapContextMenu(noteId: string, e: LeafletMouseEvent) { } }); } + +function formatGeoLocation(latlng: LatLng, precision: number = 6) { + return `${latlng.lat.toFixed(precision)}, ${latlng.lng.toFixed(precision)}`; +}