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
fix(geomap): frame a western track where it stands, not round the world
Elian Doran039f0294149d
diff --git a/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx b/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsxindex 91adb8fb7e..e96c5132fe 100644--- a/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx+++ b/apps/client/src/widgets/collections/geomap/DetailPane.spec.tsx@@ -371,6 +371,29 @@ describe("DetailPane", () => {} ]);});+ /** The two frames are the same width for a track that crosses no seam, give or take what+ * floating point does to them, and the raw one is the one that reads west of Greenwich. */+ it("frames a track in the western hemisphere where it stands", async () => {+ buildNote({ id: "root", title: "root", children: [ { id: "hikewest", title: "A ride", mime: GPX_MIME } ] });+ const note = froca.notes["hikewest"];+ const map = fakeMap();+ map.addSource(trackSourceId(note.noteId), {+ type: "FeatureCollection",+ features: [+ { type: "Feature", properties: {}, geometry: { type: "MultiLineString", coordinates: [ [ [ -80.3, 25.7 ], [ -80.1, 25.9 ] ] ] } }+ ]+ });+ await mount([ note ], map);++ map.setUnderPointer([ trackFeature(note) ]);+ await act(async () => map.click());+ await settle();++ expect(map.fitted).toHaveLength(1);+ const { bounds } = map.fitted[0] as { bounds: [ [ number, number ], [ number, number ] ] };+ expect(bounds).toEqual([ [ -80.3, 25.7 ], [ -80.1, 25.9 ] ]);+ });+/*** A track that crosses the antimeridian holds points on either side of the ±180° seam — 179.9°* and -179.9° are a stroll apart on the ground. Read as raw minimum and maximum, they stand adiff --git a/apps/client/src/widgets/collections/geomap/DetailPane.tsx b/apps/client/src/widgets/collections/geomap/DetailPane.tsxindex 3f86f1e7b4..97f3d3a4e6 100644--- a/apps/client/src/widgets/collections/geomap/DetailPane.tsx+++ b/apps/client/src/widgets/collections/geomap/DetailPane.tsx@@ -353,10 +353,13 @@ function featureFocus(feature: MapGeoJSONFeature): PaneFocus | undefined {* Longitude is read in two frames at once, because it is a circle wearing a seam: a track across* the antimeridian holds points either side of ±180° that are a stroll apart on the ground, and* their raw minimum and maximum span nearly the whole world. The same longitudes are therefore- * also read with the seam moved to 0° — each western value pushed a turn east — and whichever- * frame drew the narrower box is the one answered. A crossing of one seam is whole in the other- * frame; only a track truly girdling half the earth stays wide in both, and then wide is the- * truth. The shifted answer may name longitudes past 180°, which `fitBounds` takes in stride.+ * also read with the seam moved to 0° — each western value pushed a turn east — and the shifted+ * frame answers where it draws the narrower box.+ *+ * Only a box wider than half the world is reconsidered, that being the width a crossing of the seam+ * produces. Anything narrower is already whole, and the two widths are then equal to within what+ * floating point does to them, which is enough to send a track in Florida round the far side of the+ * world. The shifted answer may name longitudes past 180°, which `fitBounds` takes in stride.*/async function trackBounds(map: MapLibreGLMap, noteId: string, track?: number): Promise<[[number, number], [number, number]] | null> {const data = await map.getSource<GeoJSONSource>(trackSourceId(noteId))?.getData();@@ -391,7 +394,8 @@ async function trackBounds(map: MapLibreGLMap, noteId: string, track?: number):if (!Number.isFinite(west)) return null;- return eastShifted - westShifted < east - west+ const spansHalfTheWorld = east - west > 180;+ return spansHalfTheWorld && eastShifted - westShifted < east - west? [ [ westShifted, south ], [ eastShifted, north ] ]: [ [ west, south ], [ east, north ] ];}