feat(views/geomap): display geolocation in empty menu

This commit is contained in:
Elian Doran 2025-07-06 23:41:55 +03:00
parent d31af2ddc2
commit a1341e6036
No known key found for this signature in database
2 changed files with 12 additions and 2 deletions

View file

@ -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"

View file

@ -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)}`;
}