Skip to content

Build your personal knowledge base with Trilium Notes

feat(geomap): find a GPX track by its title

Elian Dorane30c624650fc
diff --git a/apps/client/src/widgets/collections/geomap/SearchBox.spec.tsx b/apps/client/src/widgets/collections/geomap/SearchBox.spec.tsx
index 568fcde1a0..f416b44717 100644
--- a/apps/client/src/widgets/collections/geomap/SearchBox.spec.tsx
+++ b/apps/client/src/widgets/collections/geomap/SearchBox.spec.tsx
@@ -11,6 +11,7 @@ import type FNote from "../../../entities/fnote";
import { buildNote } from "../../../test/easy-froca";
import { renderInto } from "../../../test/render";
import { DEFAULT_GEOCODING_PROVIDER_NAME, GEOCODING_PROVIDERS, type GeoSearchResult } from "./geocoding";
+import { GPX_MIME } from "./GpxTrack";
import { ParentMap } from "./map";
import type { SearchResult } from "./results";
import SearchBox from "./SearchBox";
@@ -228,6 +229,24 @@ describe("geo map SearchBox", () => {
expect(labels().at(-1)).toBe("geo-map.search-online(cafe)");
});
+ it("offers a GPX track by its title, which stands on no location of its own", async () => {
+ mockGeocoder([]);
+ const map = fakeMap();
+ const track = buildNote({ title: "Ridge walk", mime: GPX_MIME });
+ const container = renderSearchBox(map, [ ...mapNotes(), track ]);
+
+ await type(container, "ridge");
+ expect(labels()[0]).toBe("Ridge walk");
+
+ await pick(0);
+
+ // Reported with no point to stand on, so the pane fits the whole route (see DetailPane)
+ // rather than the map flying to one end of it.
+ expect(picked.at(-1)?.results[0]).toEqual({ kind: "note", noteId: track.noteId, center: undefined });
+ expect(map.flyTo).not.toHaveBeenCalled();
+ expect(map.fitBounds).not.toHaveBeenCalled();
+ });
+
it("offers nothing for a query below the minimum length", async () => {
const container = renderSearchBox(fakeMap(), mapNotes());
diff --git a/apps/client/src/widgets/collections/geomap/SearchBox.tsx b/apps/client/src/widgets/collections/geomap/SearchBox.tsx
index cefaee77a0..b197ae9649 100644
--- a/apps/client/src/widgets/collections/geomap/SearchBox.tsx
+++ b/apps/client/src/widgets/collections/geomap/SearchBox.tsx
@@ -15,6 +15,7 @@ import FormAutocomplete from "../../react/FormAutocomplete";
import Icon from "../../react/Icon";
import OverlayToolbar, { OverlayToolbarButton } from "../../react/OverlayToolbar";
import { DEFAULT_GEOCODING_PROVIDER_NAME, DEFAULT_PLACE_ICON, type GeoBounds, GEOCODING_PROVIDERS, type GeoSearchResult, SEARCH_RADIUS_M } from "./geocoding";
+import { GPX_MIME } from "./GpxTrack";
import { ParentMap } from "./map";
import { describePlace } from "./place_address";
import { LOCATION_ATTRIBUTE, parseLocation } from "./Markers";
@@ -79,7 +80,8 @@ type SearchEntry = {
/** A second line under the first: the address that places a place, or whose answer a row is. */
detail?: string;
} & (
- | { kind: "marker"; center: [number, number]; noteId: string }
+ /** A note of the map's own. `center` is absent for a GPX track, which stands on no one point. */
+ | { kind: "marker"; center?: [number, number]; noteId: string }
/** A place from the geocoder, carried whole for whoever the pick is reported to. */
| { kind: "place"; center: [number, number]; result: GeoSearchResult }
/** Names the run of rows below it; not a choice (see `isHeading` on FormAutocomplete). */
@@ -317,11 +319,12 @@ function keyOf(result: SearchResult) {
* geocoder's row and its reports name no place, and a map that could not be drawn is looking nowhere.
*/
function withDistance(entry: SearchEntry, origin: [number, number] | null): SearchEntry {
- if (!origin || !("center" in entry)) {
+ const center = "center" in entry ? entry.center : undefined;
+ if (!origin || !center) {
return entry;
}
- return { ...entry, distance: metresBetween(origin, entry.center) };
+ return { ...entry, distance: metresBetween(origin, center) };
}
/** The great-circle metres between two `[lng, lat]` points. */
@@ -358,10 +361,11 @@ function matchMarkers(notes: FNote[], query: string): SearchEntry[] {
for (const note of notes) {
if (!matchesFilter(tokens, note.title)) continue;
- // A note without a readable location has no marker to fly to. GPX tracks are skipped for the
- // same reason: their route is in the file rather than on a label.
+ // A note without a readable location has no marker to fly to. A GPX track has no location
+ // either — its route is in the file — but it is drawn on the map all the same, and the pane
+ // fits the whole of it (see DetailPane).
const center = parseLocation(note.getLabelValue(LOCATION_ATTRIBUTE));
- if (!center) continue;
+ if (!center && note.mime !== GPX_MIME) continue;
matches.push({
kind: "marker",
@@ -369,7 +373,7 @@ function matchMarkers(notes: FNote[], query: string): SearchEntry[] {
noteId: note.noteId,
label: note.title,
icon: note.getIcon(),
- center
+ center: center ?? undefined
});
}
diff --git a/apps/client/src/widgets/collections/geomap/results.ts b/apps/client/src/widgets/collections/geomap/results.ts
index c5d58330e8..9c5579b95e 100644
--- a/apps/client/src/widgets/collections/geomap/results.ts
+++ b/apps/client/src/widgets/collections/geomap/results.ts
@@ -4,7 +4,8 @@ import type { GeoSearchResult } from "./geocoding";
/** One of the things a search turned up: a note of the map's own, or a place from the geocoder. */
export type SearchResult =
- | { kind: "note"; noteId: string; center: [number, number] }
+ /** `center` is absent for a GPX track, whose route is in the file rather than on a label. */
+ | { kind: "note"; noteId: string; center?: [number, number] }
| { kind: "place"; place: GeoSearchResult };
/** The zoom level a place is shown at where the geocoder does not say how much ground it covers. */
@@ -28,6 +29,9 @@ const PLACE_PADDING = 60;
* A place is framed on the ground it covers, where the geocoder says how much that is: one zoom
* level suited to a city shows a street as the city around it. A note marks a spot and has no extent
* to frame, and neither has a place the geocoder gave no bounding box for.
+ *
+ * A GPX track is left to the pane, which fits its whole route once the line is on the map (see
+ * DetailPane) — a route is a shape, and there is no one point to fly to.
*/
export function frameResult(map: MapLibreGLMap, result: SearchResult) {
if (result.kind === "place" && result.place.bounds) {
@@ -35,9 +39,12 @@ export function frameResult(map: MapLibreGLMap, result: SearchResult) {
return;
}
- const center: [number, number] = result.kind === "place"
- ? [ result.place.lng, result.place.lat ]
- : result.center;
+ if (result.kind === "note") {
+ if (result.center) {
+ map.flyTo({ center: result.center, zoom: NOTE_ZOOM });
+ }
+ return;
+ }
- map.flyTo({ center, zoom: result.kind === "place" ? PLACE_ZOOM : NOTE_ZOOM });
+ map.flyTo({ center: [ result.place.lng, result.place.lat ], zoom: PLACE_ZOOM });
}
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Geo Map.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Geo Map.html
index 4dbb586303..add3dfb7a5 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Geo Map.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Geo Map.html
@@ -63,7 +63,8 @@
<em>Zürich Hauptbahnhof</em>, and each word is looked for on its own, so
<code spellcheck="false">hotel paris</code> finds <em>Paris Hotel</em>. Notes without a
<code spellcheck="false">#geolocation</code> attribute are not offered, since there would be nowhere
- to go; GPS tracks are left out for the same reason.</p>
+ to go. GPS tracks are offered, even though they carry no such attribute: selecting one brings
+ its whole route into view.</p>
<p>Where more notes match than the list has room for, the ones nearest to what
the map is showing are offered.</p>
<h3>Searching for places online</h3>
diff --git a/docs/User Guide/User Guide/Collections/Geo Map.md b/docs/User Guide/User Guide/Collections/Geo Map.md
index 36e00fd580..3bd258db13 100644
--- a/docs/User Guide/User Guide/Collections/Geo Map.md
+++ b/docs/User Guide/User Guide/Collections/Geo Map.md
@@ -46,7 +46,7 @@ The search bar at the top-left of the map looks in two places: the notes already
### Searching the notes already on the map
-Type in the search bar and the map's own notes are matched by their title as you type. Accents are ignored on both sides, so typing `zurich` finds _Zürich Hauptbahnhof_, and each word is looked for on its own, so `hotel paris` finds _Paris Hotel_. Notes without a `#geolocation` attribute are not offered, since there would be nowhere to go; GPS tracks are left out for the same reason.
+Type in the search bar and the map's own notes are matched by their title as you type. Accents are ignored on both sides, so typing `zurich` finds _Zürich Hauptbahnhof_, and each word is looked for on its own, so `hotel paris` finds _Paris Hotel_. Notes without a `#geolocation` attribute are not offered, since there would be nowhere to go. GPS tracks are offered, even though they carry no such attribute: selecting one brings its whole route into view.
Where more notes match than the list has room for, the ones nearest to what the map is showing are offered.