Skip to content

Build your personal knowledge base with Trilium Notes

fix(geomap): zoom in on a marker taken from the search

Elian Doran07cdab1f9c94
diff --git a/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx b/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx
index 4d435b0b96..91adb8fb7e 100644
--- a/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx
+++ b/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx
@@ -500,6 +500,16 @@ describe("DetailPane", () => {
expect(map.eased).toEqual([ { center: [ 2, 1 ], offset: [ -200, 0 ] } ]);
});
+ it("stands the marker at the zoom the selection names", async () => {
+ const note = buildNote({ title: "Somewhere", "#geolocation": "1,2" });
+ const map = fakeMap();
+
+ await mount([ note ], map, false, false, { noteId: note.noteId, zoom: 15 });
+ await settle();
+
+ expect(map.eased).toEqual([ { center: [ 2, 1 ], offset: [ -200, 0 ], zoom: 15 } ]);
+ });
+
/** An embedded map may be narrower than the pane, leaving nowhere to move to. */
it("leaves the marker where it is on a map the pane covers whole", async () => {
const note = buildNote({ title: "Somewhere", "#geolocation": "1,2" });
diff --git a/apps/client/src/widgets/collections/geomap/DetailPane.tsx b/apps/client/src/widgets/collections/geomap/DetailPane.tsx
index 3a325be5d1..3f86f1e7b4 100644
--- a/apps/client/src/widgets/collections/geomap/DetailPane.tsx
+++ b/apps/client/src/widgets/collections/geomap/DetailPane.tsx
@@ -1,7 +1,7 @@
import "./DetailPane.css";
import clsx from "clsx";
-import type { GeoJSONSource, MapGeoJSONFeature, Map as MapLibreGLMap, MapMouseEvent, MapSourceDataEvent } from "maplibre-gl";
+import type { EaseToOptions, GeoJSONSource, MapGeoJSONFeature, Map as MapLibreGLMap, MapMouseEvent, MapSourceDataEvent } from "maplibre-gl";
import { useCallback, useContext, useEffect, useMemo, useRef } from "preact/hooks";
import FNote from "../../../entities/fnote";
@@ -36,6 +36,9 @@ export interface PaneSelection {
isNew?: boolean;
/** What of the note the click named, where it named more than the note. See {@link PaneFocus}. */
focus?: PaneFocus;
+ /** The zoom to stand the marker at. Absent for a marker clicked on the map, which keeps the
+ * current zoom. */
+ zoom?: number;
}
/**
@@ -227,14 +230,18 @@ export default function DetailPane({ notes, parentNote, placing, isReadOnly, sel
const coordinates = parseLocation(location);
if (!coordinates) return;
- map.easeTo({ center: coordinates, offset: paneOffset(map) });
+ const aim: EaseToOptions = { center: coordinates, offset: paneOffset(map) };
+ if (selection?.zoom !== undefined) {
+ aim.zoom = selection.zoom;
+ }
+ map.easeTo(aim);
// The focus is depended on by identity, which a click renews even on the same note: every
// click is a fresh ask, and re-clicking what is already open brings it back into view.
//
// Growing and shrinking the pane are asks of the same kind, the room the camera is aiming
// into being what changed: a pane put back down brings its marker clear of it again, rather
// than leaving it under the pane until something else happens to move the camera.
- }, [ map, note?.noteId, location, selection?.focus, maximized ]);
+ }, [ map, note?.noteId, location, selection?.focus, selection?.zoom, maximized ]);
// Bound only while something is selected, so the map's other Escape — giving up on placing a
// marker (see index.tsx) — stands alone when nothing is. A phone's dialog answers the key
diff --git a/apps/client/src/widgets/collections/geomap/index.tsx b/apps/client/src/widgets/collections/geomap/index.tsx
index 6b8cd91230..33cddc5971 100644
--- a/apps/client/src/widgets/collections/geomap/index.tsx
+++ b/apps/client/src/widgets/collections/geomap/index.tsx
@@ -29,7 +29,7 @@ import PlaceMarker from "./PlaceMarker";
import PlacePanel from "./PlacePanel";
import Pois from "./Pois";
import ResultNavigator from "./ResultNavigator";
-import type { SearchResult } from "./results";
+import { NOTE_ZOOM, type SearchResult } from "./results";
import SearchBox from "./SearchBox";
import Tooltips from "./Tooltips";
@@ -197,7 +197,8 @@ export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewM
if (result.kind === "place") {
pickPlace(result.place);
} else {
- selectNote({ noteId: result.noteId });
+ // The pane aims the camera at the marker, so it is given the zoom to aim at as well.
+ selectNote({ noteId: result.noteId, zoom: NOTE_ZOOM });
}
}, [ pickPlace, selectNote ]);
diff --git a/apps/client/src/widgets/collections/geomap/results.ts b/apps/client/src/widgets/collections/geomap/results.ts
index 1582b99393..c5d58330e8 100644
--- a/apps/client/src/widgets/collections/geomap/results.ts
+++ b/apps/client/src/widgets/collections/geomap/results.ts
@@ -11,7 +11,7 @@ export type SearchResult =
const PLACE_ZOOM = 12;
/** The zoom level a note is shown at, closer in since it marks a spot rather than an area. */
-const NOTE_ZOOM = 15;
+export const NOTE_ZOOM = 15;
/**
* How close a place is framed at most. A house's extent is a few metres across, which on its own