feat(views/geomap): display geolocation in both context menus

This commit is contained in:
Elian Doran 2025-07-06 23:48:51 +03:00
parent a1341e6036
commit 8102172557
No known key found for this signature in database
2 changed files with 20 additions and 11 deletions

View File

@ -1,17 +1,17 @@
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) {
export default function openContextMenu(noteId: string, e: LeafletMouseEvent) {
contextMenu.show({
x: e.pageX,
y: e.pageY,
x: e.originalEvent.pageX,
y: e.originalEvent.pageY,
items: [
...buildGeoLocationItem(e),
...linkContextMenu.getItems(),
{ title: t("geo-map-context.open-location"), command: "openGeoLocation", uiIcon: "bx bx-map-alt" },
{ title: "----" },
@ -39,10 +39,7 @@ 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))
},
...buildGeoLocationItem(e),
{ title: t("geo-map-context.add-note"), command: "addNoteToMap", uiIcon: "bx bx-plus" }
],
selectMenuItemHandler: ({ command }) => {
@ -57,6 +54,18 @@ export function openMapContextMenu(noteId: string, e: LeafletMouseEvent) {
});
}
function buildGeoLocationItem(e: LeafletMouseEvent) {
function formatGeoLocation(latlng: LatLng, precision: number = 6) {
return `${latlng.lat.toFixed(precision)}, ${latlng.lng.toFixed(precision)}`;
}
return [
{
title: formatGeoLocation(e.latlng),
handler: () => copyTextWithToast(formatGeoLocation(e.latlng, 15))
},
{
title: "----"
}
];
}

View File

@ -33,7 +33,7 @@ export default function processNoteWithMarker(map: Map, note: FNote, location: s
}
});
newMarker.on("contextmenu", (e) => {
openContextMenu(note.noteId, e.originalEvent);
openContextMenu(note.noteId, e);
});
const el = newMarker.getElement();