Skip to content

Build your personal knowledge base with Trilium Notes

fix(geomap): leave the camera alone while the pane covers the map

Elian Doran7dc0d5083dc4
diff --git a/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx b/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx
index b6c1f4699f..978f13d380 100644
--- a/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx
+++ b/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx
@@ -708,11 +708,12 @@ describe("DetailPane", () => {
});
/**
- * The map holds a selected marker clear of the pane, which a pane covering the whole map
- * leaves nowhere to hold it in — so the offset is given up while it is grown, and taken up
- * again as it comes back down (see paneOffset).
+ * The camera waits out a pane that covers the map rather than aiming into it: there is
+ * nowhere left to hold the marker clear of, and a move made behind the pane would be a move
+ * to somewhere nobody can see — seen all the same, the map sliding while the pane is still
+ * growing over it. It is the coming back down that is worth framing for.
*/
- it("stops holding the marker clear of itself while it covers the map", async () => {
+ it("leaves the camera alone while it covers the map, and frames again as it comes down", async () => {
const note = buildNote({ title: "Somewhere", "#geolocation": "1,2" });
const map = fakeMap();
await openPaneFor(note, map);
@@ -722,14 +723,14 @@ describe("DetailPane", () => {
});
await maximize();
- await maximize();
+ // Nothing moved for the growing.
+ expect(map.eased).toEqual([ { center: [ 2, 1 ], offset: [ -200, 0 ] } ]);
- // Held clear of the pane as it opens; brought back to the middle as the pane grows over
- // the map, there being no uncovered half left to hold it in; and held clear once more as
- // the pane comes down, rather than left under it until something else moves the camera.
+ await maximize();
+ // And the marker is framed clear of the pane again as it comes back down, rather than
+ // left wherever it was until something else happens to move the camera.
expect(map.eased).toEqual([
{ center: [ 2, 1 ], offset: [ -200, 0 ] },
- { center: [ 2, 1 ], offset: [ 0, 0 ] },
{ center: [ 2, 1 ], offset: [ -200, 0 ] }
]);
});
diff --git a/apps/client/src/widgets/collections/geomap/DetailPane.tsx b/apps/client/src/widgets/collections/geomap/DetailPane.tsx
index bf35192cf8..25d6a3f9a5 100644
--- a/apps/client/src/widgets/collections/geomap/DetailPane.tsx
+++ b/apps/client/src/widgets/collections/geomap/DetailPane.tsx
@@ -72,8 +72,8 @@ export default function DetailPane({ notes, parentNote, placing, isReadOnly, sel
* The pane has been grown to cover the map (see {@link MaximizeAction} in the header below).
* Owned by the map view rather than by the pane for the reason the selection is: the map places
* what it draws around the pane, and a pane covering the whole of it leaves nothing to place
- * around — the marker previews have nowhere to stand clear to (see Tooltips), and the camera has
- * no uncovered half to hold the marker in (see {@link paneOffset}).
+ * around — the marker previews have nowhere to stand clear to (see Tooltips), and the camera
+ * has no uncovered half to aim into (see the easing effect below).
*/
maximized: boolean;
onMaximizedChange: (maximized: boolean) => void;
@@ -170,6 +170,11 @@ export default function DetailPane({ notes, parentNote, placing, isReadOnly, sel
// or only what the click named where it named more (see PaneFocus).
useEffect(() => {
if (!map || !note) return;
+ // Nothing is aimed at behind a pane that covers the map: the camera would be moving to a
+ // place nobody can see, and the move is seen — the map slides while the pane is still
+ // growing over it. Waiting instead is what makes the dependency below worth having, the
+ // pane coming back down being the moment the marker is worth framing again.
+ if (maximized) return;
if (note.mime === GPX_MIME) {
const focus = selection?.focus;
@@ -178,7 +183,7 @@ export default function DetailPane({ notes, parentNote, placing, isReadOnly, sel
// were reading at, exactly as a note marker is — flying out to frame the whole file
// would lose the very flag they clicked.
if (focus && "at" in focus) {
- map.easeTo({ center: focus.at, offset: paneOffset(map, maximized) });
+ map.easeTo({ center: focus.at, offset: paneOffset(map) });
return;
}
@@ -193,7 +198,7 @@ export default function DetailPane({ notes, parentNote, placing, isReadOnly, sel
if (done || !bounds) return;
done = true;
map.off("sourcedata", onSourceData);
- map.fitBounds(bounds, { padding: trackFitPadding(map, maximized), maxZoom: TRACK_FIT_MAX_ZOOM });
+ map.fitBounds(bounds, { padding: trackFitPadding(map), maxZoom: TRACK_FIT_MAX_ZOOM });
};
// A track selected the moment it was brought onto the map has no line yet: its content
@@ -216,7 +221,7 @@ export default function DetailPane({ notes, parentNote, placing, isReadOnly, sel
const coordinates = parseLocation(location);
if (!coordinates) return;
- map.easeTo({ center: coordinates, offset: paneOffset(map, maximized) });
+ map.easeTo({ center: coordinates, offset: paneOffset(map) });
// 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.
//
@@ -280,11 +285,9 @@ export const PANE_REACH = PANE_WIDTH + PANE_INSET;
* transform, so `getCenter()` — which the view is saved from (see map.tsx) — would report the middle
* of the uncovered half from then on, walking the saved viewport sideways on every open.
*/
-function paneOffset(map: MapLibreGLMap, maximized: boolean): [number, number] {
- // A pane grown over the whole map leaves nowhere to hold the marker clear of, as an embedded map
- // narrower than the pane does. Reading the note is what a grown pane is for; the marker is
- // brought clear again as it is put back down (see the camera effect above).
- if (maximized || map.getContainer().clientWidth <= PANE_REACH) {
+function paneOffset(map: MapLibreGLMap): [number, number] {
+ // An embedded map narrower than the pane leaves nowhere to hold the marker clear of.
+ if (map.getContainer().clientWidth <= PANE_REACH) {
return [ 0, 0 ];
}
@@ -381,14 +384,12 @@ async function trackBounds(map: MapLibreGLMap, noteId: string, track?: number):
* the map does not clip the fit but forfeits it: MapLibre cannot solve the camera and leaves it
* where it stands.
*/
-function trackFitPadding(map: MapLibreGLMap, maximized: boolean) {
+function trackFitPadding(map: MapLibreGLMap) {
const { clientWidth, clientHeight } = map.getContainer();
const air = Math.max(0, Math.min(TRACK_FIT_AIR, Math.floor(Math.min(clientWidth, clientHeight) / 4)));
const padding = { top: air, bottom: air, left: air, right: air };
- // Nothing is reserved for a pane that covers the map: there is no uncovered side to fit the
- // track into, and reserving one would forfeit the fit outright (see above).
- if (!maximized && clientWidth > PANE_REACH + 2 * air) {
+ if (clientWidth > PANE_REACH + 2 * air) {
padding[glob.isRtl ? "left" : "right"] += PANE_REACH;
}