Skip to content

Build your personal knowledge base with Trilium Notes

feat(geo_map): add option to open location

Elian Doran9b1279ce142a
diff --git a/src/public/app/components/app_context.ts b/src/public/app/components/app_context.ts
index b15e075b64..731f187fb2 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 634f69db9a..6456c6519c 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<any>[] {
+function getItems(): MenuItem<CommandNames>[] {
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 3e9d4f310d..f80a3c10ad 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<HTMLCanvasElement>, hrefLink: string | undefined, $link: JQuery<HTMLElement> | null) {
+function goToLinkExt(evt: MouseEvent | JQuery.ClickEvent | JQuery.MouseDownEvent | React.PointerEvent<HTMLCanvasElement>, hrefLink: string | undefined, $link?: JQuery<HTMLElement> | 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 5dd9af475a..160e37e474 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 = `\
<div class="note-detail-geo-map note-detail-printable">
@@ -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 aae7746f7f..12bbfaa915 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);
}