Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
chore(collections/map): reintroduce marker context menu
Elian Doranb812d7f9187c
diff --git a/apps/client/src/widgets/collections/geomap/index.tsx b/apps/client/src/widgets/collections/geomap/index.tsxindex 443dd917e0..a3a3a257ef 100644--- a/apps/client/src/widgets/collections/geomap/index.tsx+++ b/apps/client/src/widgets/collections/geomap/index.tsx@@ -22,7 +22,7 @@ import openContextMenu, { openMapContextMenu } from "./context_menu";import Map, { GeoMouseEvent } from "./map";import { DEFAULT_MAP_LAYER_NAME, MAP_LAYERS, MapLayer } from "./map_layer";import Marker, { GpxTrack } from "./marker";-import { MARKER_SVG, useMarkerData } from "./marker_data";+import { MARKER_LAYER, MARKER_SVG, useMarkerData } from "./marker_data";const DEFAULT_COORDINATES: [number, number] = [3.878638227135724, 446.6630455551659];const DEFAULT_ZOOM = 2;@@ -98,12 +98,24 @@ export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewM}, [ state ]);const onContextMenu = useCallback((e: GeoMouseEvent) => {- openMapContextMenu(note.noteId, e, !isReadOnly);+ const map = apiRef.current;+ if (!map) return;+ const features = map.queryRenderedFeatures(e.point, {+ layers: [ MARKER_LAYER ]+ });++ if (features.length > 0) {+ // Marker context menu.+ openContextMenu(features[0].properties.id, e, !isReadOnly);+ } else {+ // Empty area context menu.+ openMapContextMenu(note.noteId, e, !isReadOnly);+ }}, [ note.noteId, isReadOnly ]);// Draggingconst containerRef = useRef<HTMLDivElement>(null);- const apiRef = useRef<maplibregl.Map>(null);+ const apiRef = useRef<maplibregl.Map | null>(null);useMarkerData(note, apiRef);useNoteTreeDrag(containerRef, {diff --git a/apps/client/src/widgets/collections/geomap/map.tsx b/apps/client/src/widgets/collections/geomap/map.tsxindex fe61774dd0..a79031e827 100644--- a/apps/client/src/widgets/collections/geomap/map.tsx+++ b/apps/client/src/widgets/collections/geomap/map.tsx@@ -1,6 +1,6 @@import "maplibre-gl/dist/maplibre-gl.css";-import maplibregl, { NavigationControl } from "maplibre-gl";+import maplibregl, { NavigationControl, type Point } from "maplibre-gl";import { ComponentChildren, createContext, RefObject } from "preact";import { useEffect, useImperativeHandle, useRef } from "preact/hooks";@@ -10,6 +10,7 @@ import { MapLayer } from "./map_layer";export interface GeoMouseEvent {latlng: { lat: number; lng: number };originalEvent: MouseEvent;+ point: Point;}export const ParentMap = createContext<maplibregl.Map | null>(null);@@ -31,7 +32,8 @@ interface MapProps {function toMapLibreEvent(e: maplibregl.MapMouseEvent): GeoMouseEvent {return {latlng: { lat: e.lngLat.lat, lng: e.lngLat.lng },- originalEvent: e.originalEvent+ originalEvent: e.originalEvent,+ point: e.point};}diff --git a/apps/client/src/widgets/collections/geomap/marker_data.ts b/apps/client/src/widgets/collections/geomap/marker_data.tsindex 331021712c..6b38ebd17e 100644--- a/apps/client/src/widgets/collections/geomap/marker_data.ts+++ b/apps/client/src/widgets/collections/geomap/marker_data.ts@@ -11,7 +11,9 @@ const DEFAULT_MARKER_COLOR = "#2A81CB";export const MARKER_SVG = "foo"; // TODO: Fixconst iconSvgCache = new Map<string, string>();-export function useMarkerData(note: FNote | null | undefined, apiRef: MutableRef<maplibregl.Map>) {+export const MARKER_LAYER = "points-layer";++export function useMarkerData(note: FNote | null | undefined, apiRef: MutableRef<maplibregl.Map | null>) {const childNotes = useChildNotes(note?.noteId);async function refresh() {@@ -68,7 +70,7 @@ export function useMarkerData(note: FNote | null | undefined, apiRef: MutableRef}});map.addLayer({- id: "points-layer",+ id: MARKER_LAYER,type: "symbol",source: "points",layout: {