mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	feat(views/geomap): display geolocation in both context menus
This commit is contained in:
		| @@ -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 formatGeoLocation(latlng: LatLng, precision: number = 6) { | ||||
| 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: "----" | ||||
|         } | ||||
|     ]; | ||||
| } | ||||
|   | ||||
| @@ -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(); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user