Skip to content

Build your personal knowledge base with Trilium Notes

fix(geomap): bring back the crosshair while a place is being pointed out

Elian Doran985384243966
diff --git a/apps/client/src/widgets/collections/geomap/Markers.spec.tsx b/apps/client/src/widgets/collections/geomap/Markers.spec.tsx
index 6389dc46b5..9372bffcae 100644
--- a/apps/client/src/widgets/collections/geomap/Markers.spec.tsx
+++ b/apps/client/src/widgets/collections/geomap/Markers.spec.tsx
@@ -107,6 +107,10 @@ function fakeMap() {
leaveMarker() {
for (const fn of listeners.get(`mouseleave:${MARKER_LAYER}`) ?? []) fn({});
},
+ /** The same, for a bubble standing in for the notes it gathered. */
+ enterCluster() {
+ for (const fn of listeners.get(`mouseenter:${CLUSTER_LAYER}`) ?? []) fn({});
+ },
/** What the map is currently showing the pointer as. */
get cursor() { return canvas.style.cursor ?? ""; },
isStyleLoaded: () => false,
@@ -335,6 +339,38 @@ describe("Markers", () => {
expect(map.layer(CLUSTER_COUNT_LAYER)?.layout?.["text-allow-overlap"]).toBe(true);
});
+ /**
+ * A bubble offers to be stepped into, which is not what a click means while the map is waiting to
+ * be told a place — and the offer is made by writing the cursor onto the canvas, which is an
+ * inline style and so outranks the crosshair the map wears meanwhile (a rule in index.css).
+ */
+ it("leaves the bubbles alone while the map is armed to place something", async () => {
+ const notes = [
+ buildNote({ title: "One", "#geolocation": "1,2" }),
+ buildNote({ title: "Two", "#geolocation": "1.001,2.001" })
+ ];
+ const map = fakeMap();
+ const parent = new Component();
+
+ await mount(notes, map, parent, { clustered: true });
+ await act(async () => {
+ map.fireStyleLoad();
+ await settle();
+ });
+
+ map.enterCluster();
+ expect(map.cursor).toBe("pointer");
+
+ // Armed with the pointer still on the bubble, which is where it has to be put back by hand:
+ // the `mouseleave` that would have cleared it is no longer being listened for.
+ await mount(notes, map, parent, { clustered: true, placing: true });
+ expect(map.cursor).toBe("");
+
+ // And the bubble makes no offer at all from here on.
+ map.enterCluster();
+ expect(map.cursor).toBe("");
+ });
+
it("leaves every note its own pin when the map is not set to gather them", async () => {
const notes = [
buildNote({ title: "One", "#geolocation": "1,2" }),
diff --git a/apps/client/src/widgets/collections/geomap/Markers.tsx b/apps/client/src/widgets/collections/geomap/Markers.tsx
index 729c92aa75..0ad9688904 100644
--- a/apps/client/src/widgets/collections/geomap/Markers.tsx
+++ b/apps/client/src/widgets/collections/geomap/Markers.tsx
@@ -295,7 +295,7 @@ export default function Markers({ notes, hideLabels, isDarkTheme, clustered, pla
}
}, [ map, hideLabels, isDarkTheme ]);
- useClusterExpansion(map, MARKER_SOURCE, clustered);
+ useClusterExpansion(map, MARKER_SOURCE, clustered && !placing);
useMarkerOpening(map, opensNotes && !placing);
return null;
diff --git a/apps/client/src/widgets/collections/geomap/clusters.ts b/apps/client/src/widgets/collections/geomap/clusters.ts
index 8ace9c34f0..43848714e1 100644
--- a/apps/client/src/widgets/collections/geomap/clusters.ts
+++ b/apps/client/src/widgets/collections/geomap/clusters.ts
@@ -120,8 +120,11 @@ export function installClusterLayers(map: MapLibreGLMap, source: string) {
* in. Safe to call before the layers are up — MapLibre keeps a listener for a layer that does not
* exist yet and starts delivering to it once one does.
*
- * @param enabled whether this map gathers its notes at all. A map that does not has no bubbles to
- * click, and the cursor is left to whatever else on the map wants to set it.
+ * @param enabled whether this map gathers its notes at all, and whether a bubble is this map's to act
+ * on for the moment. A map that gathers nothing has no bubbles to click, and one armed
+ * for placement has a click that belongs to the placement — zooming into the group as
+ * well would both put the marker down and step in on top of it. Either way the cursor
+ * is left to whatever else on the map wants to set it.
*/
export function useClusterExpansion(map: MapLibreGLMap | null, source: string, enabled: boolean) {
useEffect(() => {
@@ -155,6 +158,11 @@ export function useClusterExpansion(map: MapLibreGLMap | null, source: string, e
map.off("click", CLUSTER_LAYER, onClick);
map.off("mouseenter", CLUSTER_LAYER, onEnter);
map.off("mouseleave", CLUSTER_LAYER, onLeave);
+ // The pointer is put back by hand, as it is for the markers (see `useMarkerOpening`): a
+ // cursor set on the canvas is an inline style and outranks any rule, so a pointer left
+ // behind here would sit over the crosshair the map wears while it waits to be told a
+ // place — and the `mouseleave` that would have cleared it is no longer listened for.
+ onLeave();
};
}, [ map, source, enabled ]);
}
diff --git a/apps/client/src/widgets/collections/geomap/index.css b/apps/client/src/widgets/collections/geomap/index.css
index 80794f4b42..7c31973c9d 100644
--- a/apps/client/src/widgets/collections/geomap/index.css
+++ b/apps/client/src/widgets/collections/geomap/index.css
@@ -165,7 +165,18 @@
mask-repeat: no-repeat;
}
-.geo-view.placing-note .geo-map-container {
+/*
+ * The map is waiting to be told a place, and says so under the pointer.
+ *
+ * Set on MapLibre's own canvas container rather than on the map around it: MapLibre dresses that
+ * container itself (`.maplibregl-canvas-container.maplibregl-interactive { cursor: grab }`), so a
+ * cursor stated anywhere above it is never inherited through — which is why the rule stopped showing
+ * when the map moved off Leaflet. Named by four classes, which is what it takes to outweigh that.
+ *
+ * Left off while the pointer is down, so that panning the map to reach the place still says grabbing
+ * as it does at every other time — MapLibre's `:active` rule is a class fewer, and would lose.
+ */
+.geo-view.placing-note .geo-map-container .maplibregl-canvas-container:not(:active) {
cursor: crosshair;
}