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 tooltip on mouse enter
Elian Doranc7842c7f05e2
diff --git a/apps/client/src/widgets/FloatingButtons.css b/apps/client/src/widgets/FloatingButtons.cssindex cdceee5837..5d3f4bb65b 100644--- a/apps/client/src/widgets/FloatingButtons.css+++ b/apps/client/src/widgets/FloatingButtons.css@@ -88,12 +88,6 @@}/* #endregion */-/* #region Geo map buttons */-.maplibregl-canvas-container {- z-index: 50;-}-/* #endregion */-/* #region Close floating buttons */.close-floating-buttons {margin-inline-start: 5px !important;diff --git a/apps/client/src/widgets/collections/geomap/index.css b/apps/client/src/widgets/collections/geomap/index.cssindex bd6858a161..5e7cc85ca3 100644--- a/apps/client/src/widgets/collections/geomap/index.css+++ b/apps/client/src/widgets/collections/geomap/index.css@@ -7,14 +7,9 @@> .collection-properties {position: relative;- z-index: 998;}}-body.mobile .geo-view > .collection-properties {- z-index: 2500;-}-.geo-map-container {height: 100%;overflow: hidden;@@ -24,13 +19,6 @@ body.mobile .geo-view > .collection-properties {}}-.maplibregl-ctrl-top-left,-.maplibregl-ctrl-top-right,-.maplibregl-ctrl-bottom-left,-.maplibregl-ctrl-bottom-right {- z-index: 997 !important;-}-.geo-view.placing-note .geo-map-container {cursor: crosshair;}diff --git a/apps/client/src/widgets/collections/geomap/index.tsx b/apps/client/src/widgets/collections/geomap/index.tsxindex a3a3a257ef..deb326ce4e 100644--- a/apps/client/src/widgets/collections/geomap/index.tsx+++ b/apps/client/src/widgets/collections/geomap/index.tsx@@ -1,6 +1,8 @@import "./index.css";import type maplibregl from "maplibre-gl";+import { MapMouseEvent, Popup } from "maplibre-gl";+import { RefObject } from "preact";import { useCallback, useContext, useEffect, useMemo, useRef, useState } from "preact/hooks";import appContext from "../../../components/app_context";@@ -13,7 +15,7 @@ import toast from "../../../services/toast";import CollectionProperties from "../../note_bars/CollectionProperties";import ActionButton from "../../react/ActionButton";import { ButtonOrActionButton } from "../../react/Button";-import { useNoteBlob, useNoteLabel, useNoteLabelBoolean, useNoteProperty, useNoteTreeDrag, useSpacedUpdate, useTriliumEvent } from "../../react/hooks";+import { useNoteBlob, useNoteLabel, useNoteLabelBoolean, useNoteProperty, useNoteTreeDrag, useSpacedUpdate, useTooltip, useTriliumEvent } from "../../react/hooks";import { ParentComponent } from "../../react/react_utils";import TouchBar, { TouchBarButton, TouchBarSlider } from "../../react/TouchBar";import { ViewModeProps } from "../interface";@@ -117,7 +119,7 @@ export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewMconst containerRef = useRef<HTMLDivElement>(null);const apiRef = useRef<maplibregl.Map | null>(null);useMarkerData(note, apiRef);-+ useHoverTooltip(containerRef, apiRef);useNoteTreeDrag(containerRef, {dragEnabled: !isReadOnly,dragNotEnabledMessage: {@@ -205,6 +207,40 @@ function useLayerData(note: FNote) {return layerData;}+function useHoverTooltip(containerRef: RefObject<HTMLDivElement>, mapRef: RefObject<maplibregl.Map | null>) {+ useEffect(() => {+ const map = mapRef.current;+ if (!map) return;++ const tooltip = new Popup({+ closeButton: false,+ closeOnClick: false,+ offset: 12,+ className: "marker-tooltip"+ });++ function onMouseEnter(e: MapMouseEvent) {+ const feature = e.features[0];+ tooltip+ .setLngLat(feature.geometry.coordinates)+ .setHTML(`<strong>${feature.properties.name}</strong>`)+ .addTo(map);+ }++ function onMouseLeave() {+ tooltip.remove();+ }++ map.on("mouseenter", MARKER_LAYER, onMouseEnter);+ map.on("mouseleave", MARKER_LAYER, onMouseLeave);++ return () => {+ map.off("mouseenter", MARKER_LAYER, onMouseEnter);+ map.off("mouseleave", MARKER_LAYER, onMouseLeave);+ };+ }, [ mapRef ]);+}+function ToggleReadOnlyButton({ note }: { note: FNote }) {const [ isReadOnly, setReadOnly ] = useNoteLabelBoolean(note, "readOnly");