From 9b1279ce142ad4c0d2af3952c4c31cfe6a58b270 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Wed, 22 Jan 2025 21:07:40 +0200 Subject: [PATCH] feat(geo_map): add option to open location --- src/public/app/components/app_context.ts | 6 +++--- src/public/app/menus/link_context_menu.ts | 2 +- src/public/app/services/link.ts | 2 +- src/public/app/widgets/type_widgets/geo_map.ts | 12 ++++++++++++ .../app/widgets/type_widgets/geo_map_context_menu.ts | 8 +++++++- 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/public/app/components/app_context.ts b/src/public/app/components/app_context.ts index b15e075b6..731f187fb 100644 --- a/src/public/app/components/app_context.ts +++ b/src/public/app/components/app_context.ts @@ -23,6 +23,7 @@ import type LoadResults from "../services/load_results.js"; import type { Attribute } from "../services/attribute_parser.js"; import type NoteTreeWidget from "../widgets/note_tree.js"; import type { default as NoteContext, GetTextEditorCallback } from "./note_context.js"; +import type { ContextMenuEvent } from "../menus/context_menu.js"; interface Layout { getRootWidget: (appContext: AppContext) => RootWidget; @@ -195,9 +196,8 @@ export type CommandMappings = { } // Geomap - deleteFromMap: { - noteId: string; - } + deleteFromMap: { noteId: string }, + openGeoLocation: { noteId: string, event: JQuery.MouseDownEvent } }; type EventMappings = { diff --git a/src/public/app/menus/link_context_menu.ts b/src/public/app/menus/link_context_menu.ts index 634f69db9..6456c6519 100644 --- a/src/public/app/menus/link_context_menu.ts +++ b/src/public/app/menus/link_context_menu.ts @@ -12,7 +12,7 @@ function openContextMenu(notePath: string, e: ContextMenuEvent, viewScope: ViewS }); } -function getItems(): MenuItem[] { +function getItems(): MenuItem[] { return [ { title: t("link_context_menu.open_note_in_new_tab"), command: "openNoteInNewTab", uiIcon: "bx bx-link-external" }, { title: t("link_context_menu.open_note_in_new_split"), command: "openNoteInNewSplit", uiIcon: "bx bx-dock-right" }, diff --git a/src/public/app/services/link.ts b/src/public/app/services/link.ts index 3e9d4f310..f80a3c10a 100644 --- a/src/public/app/services/link.ts +++ b/src/public/app/services/link.ts @@ -234,7 +234,7 @@ function goToLink(evt: MouseEvent | JQuery.ClickEvent) { return goToLinkExt(evt, hrefLink, $link); } -function goToLinkExt(evt: MouseEvent | JQuery.ClickEvent | React.PointerEvent, hrefLink: string | undefined, $link: JQuery | null) { +function goToLinkExt(evt: MouseEvent | JQuery.ClickEvent | JQuery.MouseDownEvent | React.PointerEvent, hrefLink: string | undefined, $link?: JQuery | null) { if (hrefLink?.startsWith("data:")) { return true; } diff --git a/src/public/app/widgets/type_widgets/geo_map.ts b/src/public/app/widgets/type_widgets/geo_map.ts index 5dd9af475..160e37e47 100644 --- a/src/public/app/widgets/type_widgets/geo_map.ts +++ b/src/public/app/widgets/type_widgets/geo_map.ts @@ -10,6 +10,7 @@ import { t } from "../../services/i18n.js"; import attributes from "../../services/attributes.js"; import asset_path from "../../../../services/asset_path.js"; import openContextMenu from "./geo_map_context_menu.js"; +import link from "../../services/link.js"; const TPL = `\
@@ -294,6 +295,17 @@ export default class GeoMapTypeWidget extends TypeWidget { } } + openGeoLocationEvent({ noteId, event }: EventData<"openGeoLocation">) { + const marker = this.currentMarkerData[noteId]; + if (!marker) { + return; + } + + const latLng = this.currentMarkerData[noteId].getLatLng(); + const url = `geo:${latLng.lat},${latLng.lng}`; + link.goToLinkExt(event, url); + } + deleteFromMapEvent({ noteId }: EventData<"deleteFromMap">) { this.moveMarker(noteId, null); } diff --git a/src/public/app/widgets/type_widgets/geo_map_context_menu.ts b/src/public/app/widgets/type_widgets/geo_map_context_menu.ts index aae7746f7..12bbfaa91 100644 --- a/src/public/app/widgets/type_widgets/geo_map_context_menu.ts +++ b/src/public/app/widgets/type_widgets/geo_map_context_menu.ts @@ -9,15 +9,21 @@ export default function openContextMenu(noteId: string, e: ContextMenuEvent) { y: e.pageY, items: [ ...linkContextMenu.getItems(), + { title: "Open location", command: "openGeoLocation", uiIcon: "bx bx-map-alt" }, { title: "----" }, { title: "Remove from map", command: "deleteFromMap", uiIcon: "bx bx-trash" } ], - selectMenuItemHandler: ({ command }) => { + selectMenuItemHandler: ({ command }, e) => { if (command === "deleteFromMap") { appContext.triggerCommand(command, { noteId }); return; } + if (command === "openGeoLocation") { + appContext.triggerCommand(command, { noteId, event: e }); + return; + } + // Pass the events to the link context menu linkContextMenu.handleLinkContextMenuItem(command, noteId); }