Skip to content

Build your personal knowledge base with Trilium Notes

feat(geomap): let a GPX track say which note it belongs to

Elian Dorand6ece372f460
diff --git a/apps/client/src/widgets/collections/geomap/ContextMenus.spec.tsx b/apps/client/src/widgets/collections/geomap/ContextMenus.spec.tsx
index eb2b868c05..b428071c3a 100644
--- a/apps/client/src/widgets/collections/geomap/ContextMenus.spec.tsx
+++ b/apps/client/src/widgets/collections/geomap/ContextMenus.spec.tsx
@@ -33,16 +33,23 @@ vi.mock("../../../menus/link_context_menu", () => ({
vi.mock("../../../menus/custom-items/NoteColorPicker", () => ({ default: () => null }));
/** A map that reports what is under a click and delegates its own, which is all this component asks. */
-function fakeMap(markerUnderPointer?: FNote) {
+function fakeMap(markerUnderPointer?: FNote, trackUnderPointer?: FNote) {
const listeners = new Set<(e: unknown) => void>();
+ // The layer a GPX track offers to be pointed at by, named after its note (see `trackHitLayers`).
+ const trackLayer = trackUnderPointer && `gpx-hit-${trackUnderPointer.noteId}`;
return {
on(event: string, fn: (e: unknown) => void) { if (event === "contextmenu") listeners.add(fn); },
off(event: string, fn: (e: unknown) => void) { if (event === "contextmenu") listeners.delete(fn); },
- queryRenderedFeatures: (_point: unknown, options: { layers: string[] }) =>
- markerUnderPointer && options.layers.includes(MARKER_LAYER)
+ getLayersOrder: () => (trackLayer ? [ trackLayer ] : []),
+ queryRenderedFeatures: (_point: unknown, options: { layers: string[] }) => [
+ ...(markerUnderPointer && options.layers.includes(MARKER_LAYER)
? [ { properties: { id: markerUnderPointer.noteId } } ]
- : [],
+ : []),
+ ...(trackUnderPointer && trackLayer && options.layers.includes(trackLayer)
+ ? [ { properties: { id: trackUnderPointer.noteId } } ]
+ : [])
+ ],
/** The map being right-clicked, as MapLibre reports it. */
rightClick() {
for (const fn of listeners) {
@@ -109,4 +116,26 @@ describe("ContextMenus", () => {
expect(moveItem(items)).toBeUndefined();
expect(items).toContainEqual(expect.objectContaining({ title: "geo-map-context.add-note" }));
});
+
+ it("opens the note of a GPX track that was clicked, not the map's own menu", async () => {
+ const track = buildNote({ title: "A Sunday ride" });
+ const { items } = await openMenu(fakeMap(undefined, track));
+
+ // The note's menu rather than the map's: a track is a note, so what it offers is what a
+ // marker offers, and never the offer to add a note where the click landed.
+ expect(items).not.toContainEqual(expect.objectContaining({ title: "geo-map-context.add-note" }));
+ expect(items).toContainEqual(expect.objectContaining({ title: "geo-map-context.remove-from-map" }));
+ });
+
+ it("prefers the marker to the track it stands on, both being under the pointer", async () => {
+ const marker = buildNote({ title: "Where I stopped", "#geolocation": "1,2" });
+ const track = buildNote({ title: "A Sunday ride" });
+ const { items, onRelocate } = await openMenu(fakeMap(marker, track));
+
+ // Aiming at a pin standing on its own track has to mean the pin: it is the smaller target,
+ // and moving it is something only the marker's menu offers.
+ const move = moveItem(items);
+ move?.handler?.(move, undefined as never);
+ expect(onRelocate).toHaveBeenCalledWith(marker.noteId);
+ });
});
diff --git a/apps/client/src/widgets/collections/geomap/ContextMenus.ts b/apps/client/src/widgets/collections/geomap/ContextMenus.ts
index 5b43ec2f07..407328a6c8 100644
--- a/apps/client/src/widgets/collections/geomap/ContextMenus.ts
+++ b/apps/client/src/widgets/collections/geomap/ContextMenus.ts
@@ -10,6 +10,7 @@ import { copyTextWithToast } from "../../../services/clipboard_ext.js";
import { t } from "../../../services/i18n.js";
import link from "../../../services/link.js";
import { createNewNote } from "./api.js";
+import { trackHitLayers } from "./GpxTrack.js";
import { type GeoMouseEvent, ParentMap, toGeoMouseEvent } from "./map.js";
import { MARKER_LAYER } from "./Markers.js";
@@ -30,12 +31,15 @@ export default function ContextMenus({ note, isReadOnly, onRelocate }: ContextMe
const onContextMenu = useCallback((e: GeoMouseEvent) => {
if (!map) return;
+ // The markers first and the tracks after, so that a pin standing on its own track opens the
+ // pin's menu rather than the line's — they are the same note either way, but a marker is the
+ // smaller target and is what the user was aiming at when they hit both.
const features = map.queryRenderedFeatures(e.point, {
- layers: [ MARKER_LAYER ]
+ layers: [ MARKER_LAYER, ...trackHitLayers(map) ]
});
if (features.length > 0) {
- // Marker context menu.
+ // Marker or track context menu.
openContextMenu(features[0].properties.id, e, !isReadOnly, onRelocate);
} else {
// Empty area context menu.
diff --git a/apps/client/src/widgets/collections/geomap/GpxTrack.spec.tsx b/apps/client/src/widgets/collections/geomap/GpxTrack.spec.tsx
index 062a6170b1..62f421557a 100644
--- a/apps/client/src/widgets/collections/geomap/GpxTrack.spec.tsx
+++ b/apps/client/src/widgets/collections/geomap/GpxTrack.spec.tsx
@@ -78,6 +78,9 @@ function fakeMap() {
if (!loaded) throw new Error("Style is not done loading");
layers.set(layer.id, layer);
},
+ getLayersOrder() {
+ return [ ...layers.keys() ];
+ },
removeSource(id: string) {
sources.delete(id);
},
@@ -111,6 +114,9 @@ const TWO_SEGMENT_GPX = `<?xml version="1.0" encoding="UTF-8"?>
</trk>
</gpx>`;
+/** The note the track belongs to, which every one of its layers is named after. */
+const NOTE_ID = "gpxNoteId1";
+
describe("GpxTrack", () => {
let container: HTMLElement;
let map: ReturnType<typeof fakeMap>;
@@ -133,17 +139,23 @@ describe("GpxTrack", () => {
});
/** Mounts the track under a map whose style has loaded (or not), as the context reports it. */
- function renderTrack({ styleLoaded, gpx = TWO_SEGMENT_GPX }: { styleLoaded: boolean; gpx?: string }) {
+ function renderTrack({ styleLoaded, gpx = TWO_SEGMENT_GPX, hideLabels = false, isDarkTheme = false }: {
+ styleLoaded: boolean; gpx?: string; hideLabels?: boolean; isDarkTheme?: boolean;
+ }) {
act(() => {
render(
<ParentMap.Provider value={map as never}>
<MapStyleLoaded.Provider value={styleLoaded}>
<GpxTrack
+ noteId={NOTE_ID}
+ title="A Sunday ride"
gpxXmlString={gpx}
trackColor="red"
startIconHtml="<i>start</i>"
endIconHtml="<i>end</i>"
waypointIconHtml="<i>waypoint</i>"
+ hideLabels={hideLabels}
+ isDarkTheme={isDarkTheme}
/>
</MapStyleLoaded.Provider>
</ParentMap.Provider>,
@@ -152,18 +164,26 @@ describe("GpxTrack", () => {
});
}
- /** The one line layer the track added, whatever its generated id. */
- function trackLayer() {
- return [ ...map.layers.values() ][0] as { paint: Record<string, unknown> } | undefined;
+ /** A layer the track added, by the id it is named after the note with. */
+ function layer(kind: "layer" | "hit" | "label") {
+ return map.layers.get(`gpx-${kind}-${NOTE_ID}`) as
+ { layout?: Record<string, unknown>; paint: Record<string, unknown> } | undefined;
}
/** The coordinates of the one source the track added. */
function trackCoordinates() {
- const source = [ ...map.sources.values() ][0] as
+ const source = map.sources.get(`gpx-source-${NOTE_ID}`) as
{ data: { geometry: { type: string; coordinates: [number, number][][] } } } | undefined;
return source?.data.geometry;
}
+ /** What the source says the line stands for. */
+ function trackProperties() {
+ const source = map.sources.get(`gpx-source-${NOTE_ID}`) as
+ { data: { properties: Record<string, unknown> } } | undefined;
+ return source?.data.properties;
+ }
+
it("draws the line when it mounts after the style loaded, with the tiles still coming in", () => {
// The style is long since loaded and `style.load` is spent — the case that used to lose.
map.loadStyle();
@@ -171,7 +191,7 @@ describe("GpxTrack", () => {
renderTrack({ styleLoaded: true });
- expect(trackLayer()?.paint["line-color"]).toBe("red");
+ expect(layer("layer")?.paint["line-color"]).toBe("red");
expect(trackCoordinates()?.type).toBe("MultiLineString");
});
@@ -183,7 +203,7 @@ describe("GpxTrack", () => {
act(() => map.loadStyle());
- expect(map.layers.size).toBe(1);
+ expect(layer("layer")).toBeDefined();
expect(trackCoordinates()?.coordinates).toHaveLength(2);
});
@@ -252,17 +272,85 @@ describe("GpxTrack", () => {
it("puts the line back when the style is switched under it", () => {
map.loadStyle();
renderTrack({ styleLoaded: true });
- expect(map.layers.size).toBe(1);
+ expect(map.layers.size).toBe(3);
// A style is a world of its own: switching one takes everything on it away.
map.layers.clear();
map.sources.clear();
act(() => map.loadStyle());
- expect(map.layers.size).toBe(1);
+ expect(map.layers.size).toBe(3);
expect(trackCoordinates()?.type).toBe("MultiLineString");
});
+ it("writes the note's name along the line, in the fontstack the styles carry", () => {
+ map.loadStyle();
+ renderTrack({ styleLoaded: true });
+
+ const label = layer("label");
+ expect(label?.layout?.["symbol-placement"]).toBe("line");
+ expect(label?.layout?.["text-field"]).toEqual([ "get", "name" ]);
+ expect(label?.layout?.["text-font"]).toEqual([ "Open Sans Regular" ]);
+ expect(trackProperties()).toEqual({ id: NOTE_ID, name: "A Sunday ride" });
+ });
+
+ it("draws the name the way the marker titles are drawn, light map or dark", async () => {
+ const { LABEL_PAINT } = await import("./Markers");
+
+ map.loadStyle();
+ renderTrack({ styleLoaded: true, isDarkTheme: true });
+
+ expect(layer("label")?.paint).toMatchObject(LABEL_PAINT.dark);
+ });
+
+ it("leaves the name off when the map's titles are hidden", () => {
+ map.loadStyle();
+ renderTrack({ styleLoaded: true, hideLabels: true });
+
+ expect(layer("label")).toBeUndefined();
+ // The line and the target for pointing at it are still there.
+ expect(layer("layer")).toBeDefined();
+ expect(layer("hit")).toBeDefined();
+ });
+
+ it("gives the line a target wide enough to be pointed at, without drawing it", () => {
+ map.loadStyle();
+ renderTrack({ styleLoaded: true });
+
+ const hit = layer("hit");
+ expect(hit?.paint["line-opacity"]).toBe(0);
+ // Wider than the three pixels the line is drawn with, or nobody could hit it.
+ expect(hit?.paint["line-width"]).toBeGreaterThan(layer("layer")?.paint["line-width"] as number);
+ });
+
+ it("offers its target to whatever hit-tests the tracks", async () => {
+ const { trackHitLayers } = await import("./GpxTrack");
+
+ map.loadStyle();
+ renderTrack({ styleLoaded: true });
+
+ // The line and the label are not offered: only the target is meant to be pointed at.
+ expect(trackHitLayers(map as never)).toEqual([ `gpx-hit-${NOTE_ID}` ]);
+
+ act(() => render(null, container));
+
+ // And a track that has gone is no longer named, so a query cannot ask for a layer that the
+ // style has since lost.
+ expect(trackHitLayers(map as never)).toEqual([]);
+ });
+
+ it("names its layers after the note, so a rerun does not churn through fresh ones", () => {
+ map.loadStyle();
+ renderTrack({ styleLoaded: true });
+ const first = [ ...map.layers.keys() ];
+
+ // The same track drawn again — as it is each time one of its icons resolves.
+ renderTrack({ styleLoaded: true });
+
+ expect([ ...map.layers.keys() ]).toEqual(first);
+ expect(first).toEqual([ `gpx-layer-${NOTE_ID}`, `gpx-hit-${NOTE_ID}`, `gpx-label-${NOTE_ID}` ]);
+ });
+
it("draws nothing for a file with no points, and does not throw over it", () => {
map.loadStyle();
renderTrack({
@@ -278,7 +366,7 @@ describe("GpxTrack", () => {
it("takes the line off the map when it goes", () => {
map.loadStyle();
renderTrack({ styleLoaded: true });
- expect(map.layers.size).toBe(1);
+ expect(map.layers.size).toBe(3);
act(() => render(null, container));
diff --git a/apps/client/src/widgets/collections/geomap/GpxTrack.tsx b/apps/client/src/widgets/collections/geomap/GpxTrack.tsx
index 5ff204ebee..4cbd0e05dc 100644
--- a/apps/client/src/widgets/collections/geomap/GpxTrack.tsx
+++ b/apps/client/src/widgets/collections/geomap/GpxTrack.tsx
@@ -1,24 +1,56 @@
-import { Marker as MapLibreMarker } from "maplibre-gl";
+import { type Map as MapLibreGLMap, Marker as MapLibreMarker } from "maplibre-gl";
import { useContext, useEffect } from "preact/hooks";
import { MapStyleLoaded, ParentMap } from "./map";
+import { LABEL_PAINT } from "./Markers";
export interface GpxTrackProps {
+ /** The note the track belongs to, which is what its layers are named after and what a click on
+ * one of them resolves to. */
+ noteId: string;
+ /** What the line is named along its length. */
+ title: string;
gpxXmlString: string;
trackColor?: string;
startIconHtml?: string;
endIconHtml?: string;
waypointIconHtml?: string;
+ /** Whether the map is a dark one, which decides how the name is drawn over it (see Markers). */
+ isDarkTheme?: boolean;
+ /** Whether the map's titles are hidden (`#map:hideLabels`), the track's name among them. */
+ hideLabels?: boolean;
}
+/**
+ * What a track's layers are named with.
+ *
+ * A prefix rather than a fixed name, because every track has layers of its own — see the note on ids
+ * below. Anything hit-testing tracks finds the current set by asking the style for its layers and
+ * keeping the ones that start with this (see {@link trackHitLayers}).
+ */
+const HIT_LAYER_PREFIX = "gpx-hit-";
+
+/** How wide a track is to the pointer, as against the three pixels it is drawn with. */
+const HIT_WIDTH = 20;
+
+/** How far apart the name is repeated along the line, in pixels. */
+const LABEL_SPACING = 250;
+
/**
* A GPX file, drawn as a line with a marker at either end and one at every waypoint.
*
* The line is a layer of the map's style and the markers are elements of their own: there are a
* handful of them per file at most, and each carries the note's own icon as HTML — unlike the note
* markers, which are drawn in their thousands and so are rasterized into one layer (see Markers).
+ *
+ * The line says which note it belongs to in two ways. It is named along its length, the way a map
+ * names a road or a river, so the answer is wherever the reader happens to be looking rather than
+ * back at the start pin they may have panned away from. And it carries the note in the feature
+ * itself, over a transparent line wide enough to be pointed at, so that right-clicking a track opens
+ * the note's own menu (see ContextMenus) — a line three pixels wide being nearly impossible to hit
+ * otherwise.
*/
-export function GpxTrack({ gpxXmlString, trackColor, startIconHtml, endIconHtml, waypointIconHtml }: GpxTrackProps) {
+export function GpxTrack({ noteId, title, gpxXmlString, trackColor, startIconHtml, endIconHtml, waypointIconHtml, isDarkTheme, hideLabels }: GpxTrackProps) {
const parentMap = useContext(ParentMap);
const styleLoaded = useContext(MapStyleLoaded);
@@ -28,8 +60,14 @@ export function GpxTrack({ gpxXmlString, trackColor, startIconHtml, endIconHtml,
const map = parentMap;
const markers: MapLibreMarker[] = [];
- const sourceId = `gpx-source-${Math.random().toString(36).slice(2)}`;
- const layerId = `gpx-layer-${sourceId}`;
+ // Named after the note rather than at random. A random name is a different name on every run
+ // of this effect — and it runs again for each of the three icons resolving — so every track
+ // used to churn through a handful of sources and layers on its way onto the map, leaving
+ // nothing an outside observer could have recognised it by.
+ const sourceId = `gpx-source-${noteId}`;
+ const layerId = `gpx-layer-${noteId}`;
+ const labelLayerId = `gpx-label-${noteId}`;
+ const hitLayerId = `${HIT_LAYER_PREFIX}${noteId}`;
const gpxDoc = new DOMParser().parseFromString(gpxXmlString, "application/xml");
const lines = readLines(gpxDoc);
@@ -83,7 +121,10 @@ export function GpxTrack({ gpxXmlString, trackColor, startIconHtml, endIconHtml,
type: "geojson",
data: {
type: "Feature",
- properties: {},
+ // The note the line stands for, carried by the feature so that whatever
+ // the pointer lands on can be traced back to it — `id` is what the
+ // context menu opens, and `name` is what the line is labelled with.
+ properties: { id: noteId, name: title },
// One line per segment rather than every point strung together: a track
// is broken into segments exactly where it stopped being recorded, so
// joining them drew a straight line across each gap — through whatever
@@ -102,12 +143,69 @@ export function GpxTrack({ gpxXmlString, trackColor, startIconHtml, endIconHtml,
id: layerId,
type: "line",
source: sourceId,
+ layout: {
+ // Otherwise a track doubling back on itself meets its own corners as
+ // spikes, and every segment ends in a flat stub.
+ "line-join": "round",
+ "line-cap": "round"
+ },
paint: {
"line-color": trackColor ?? "blue",
"line-width": 3
}
});
}
+
+ // What the pointer is actually aiming at. Transparent and far wider than the line is
+ // drawn, because three pixels is not something anyone can reliably hit — and left
+ // queryable by being transparent rather than hidden, since MapLibre drops a layer
+ // from a query for `visibility: none` but not for being invisible.
+ if (!map.getLayer(hitLayerId)) {
+ map.addLayer({
+ id: hitLayerId,
+ type: "line",
+ source: sourceId,
+ paint: {
+ "line-color": trackColor ?? "blue",
+ "line-opacity": 0,
+ "line-width": HIT_WIDTH
+ }
+ });
+ }
+
+ // The name, written along the line the way a map writes the name of a road or a
+ // river: repeated as the line runs, so which track this is can be read wherever the
+ // reader is looking rather than only back at the pin it started from.
+ if (!hideLabels && title && !map.getLayer(labelLayerId)) {
+ map.addLayer({
+ id: labelLayerId,
+ type: "symbol",
+ source: sourceId,
+ layout: {
+ "symbol-placement": "line",
+ "text-field": [ "get", "name" ],
+ // The fontstack the styles carry glyphs for — the same one the marker
+ // titles are set in, so a map reads as one map (see Markers, and the
+ // note on `glyphs` in map.tsx).
+ "text-font": [ "Open Sans Regular" ],
+ "text-size": 12,
+ "symbol-spacing": LABEL_SPACING,
+ // Lifted just clear of the line, so the line does not strike through
+ // its own name.
+ "text-offset": [ 0, -0.8 ],
+ // A name is dropped rather than bent around a hairpin, and rather than
+ // laid over a marker's title: every symbol layer shares one collision
+ // index, so the two are placed against each other.
+ "text-max-angle": 30,
+ "text-padding": 4
+ },
+ paint: {
+ ...LABEL_PAINT[isDarkTheme ? "dark" : "light"],
+ "text-halo-width": 2,
+ "text-halo-blur": 1
+ }
+ });
+ }
} catch (e) {
// Only worth a word if the style was ready and it still would not take the line.
if (styleLoaded) {
@@ -127,8 +225,12 @@ export function GpxTrack({ gpxXmlString, trackColor, startIconHtml, endIconHtml,
marker.remove();
}
try {
- if (map.getLayer(layerId)) {
- map.removeLayer(layerId);
+ // Every layer drawing from the source before the source itself: one still in use
+ // cannot be removed.
+ for (const layer of [ layerId, hitLayerId, labelLayerId ]) {
+ if (map.getLayer(layer)) {
+ map.removeLayer(layer);
+ }
}
if (map.getSource(sourceId)) {
map.removeSource(sourceId);
@@ -137,11 +239,23 @@ export function GpxTrack({ gpxXmlString, trackColor, startIconHtml, endIconHtml,
// The map may already have been removed.
}
};
- }, [ parentMap, styleLoaded, gpxXmlString, trackColor, startIconHtml, endIconHtml, waypointIconHtml ]);
+ }, [ parentMap, styleLoaded, noteId, title, gpxXmlString, trackColor, startIconHtml, endIconHtml, waypointIconHtml, isDarkTheme, hideLabels ]);
return <div />;
}
+/**
+ * The layers standing in for the tracks currently on the map, for whatever wants to hit-test them.
+ *
+ * Asked of the style each time rather than remembered, because a track is a component of its own and
+ * comes and goes with the note it belongs to: a list built once would name layers that have since
+ * been taken off, and `queryRenderedFeatures` refuses the whole query — returning nothing at all,
+ * rather than skipping the one it cannot find — if a single named layer is missing.
+ */
+export function trackHitLayers(map: MapLibreGLMap) {
+ return map.getLayersOrder().filter((id) => id.startsWith(HIT_LAYER_PREFIX));
+}
+
/**
* The lines a GPX file draws, one per track segment and one per route.
*
diff --git a/apps/client/src/widgets/collections/geomap/Markers.tsx b/apps/client/src/widgets/collections/geomap/Markers.tsx
index 1d6bdd3ead..b70bdc2454 100644
--- a/apps/client/src/widgets/collections/geomap/Markers.tsx
+++ b/apps/client/src/widgets/collections/geomap/Markers.tsx
@@ -61,7 +61,7 @@ const LABEL_LAYOUT: Extract<AddLayerObject, { type: "symbol" }>["layout"] = {
* by a soft, blurred glow rather than a hard keyline. A crisp white outline stood out as a cut-out
* sticker on any map, and on a dark one it was a white edge around dark text.
*/
-const LABEL_PAINT = {
+export const LABEL_PAINT = {
light: {
"text-color": "#333",
"text-halo-color": "rgba(255, 255, 255, 0.8)"
diff --git a/apps/client/src/widgets/collections/geomap/index.tsx b/apps/client/src/widgets/collections/geomap/index.tsx
index 95a62f95ae..f646d29e4a 100644
--- a/apps/client/src/widgets/collections/geomap/index.tsx
+++ b/apps/client/src/widgets/collections/geomap/index.tsx
@@ -209,7 +209,7 @@ export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewM
<Tooltips />
<ContextMenus note={note} isReadOnly={isReadOnly} onRelocate={startMarkerRelocation} />
<Markers notes={notes} hideLabels={hideLabels} isDarkTheme={layerData.isDarkTheme ?? false} clustered={clustered} placing={!!placement} />
- {notes.map(note => <NoteGpxTrackWrapper note={note} hideLabels={hideLabels} />)}
+ {notes.map(note => <NoteGpxTrackWrapper note={note} hideLabels={hideLabels} isDarkTheme={layerData.isDarkTheme ?? false} />)}
</Map>}
</div>
);
@@ -260,17 +260,17 @@ function ToggleReadOnlyButton({ note }: { note: FNote }) {
* Only tracks are rendered a component apiece: a note that merely carries a location is drawn into
* the shared symbol layer instead (see {@link Markers}).
*/
-function NoteGpxTrackWrapper({ note, hideLabels }: { note: FNote, hideLabels: boolean }) {
+function NoteGpxTrackWrapper({ note, hideLabels, isDarkTheme }: { note: FNote, hideLabels: boolean, isDarkTheme: boolean }) {
const mime = useNoteProperty(note, "mime");
if (mime !== "application/gpx+xml") {
return null;
}
- return <NoteGpxTrack note={note} hideLabels={hideLabels} />;
+ return <NoteGpxTrack note={note} hideLabels={hideLabels} isDarkTheme={isDarkTheme} />;
}
-function NoteGpxTrack({ note, hideLabels }: { note: FNote, hideLabels?: boolean }) {
+function NoteGpxTrack({ note, hideLabels, isDarkTheme }: { note: FNote, hideLabels?: boolean, isDarkTheme?: boolean }) {
const [ xmlString, setXmlString ] = useState<string>();
const blob = useNoteBlob(note);
@@ -288,18 +288,25 @@ function NoteGpxTrack({ note, hideLabels }: { note: FNote, hideLabels?: boolean
// React to changes
const color = useNoteLabel(note, "color");
useNoteLabel(note, "iconClass");
+ // The line is named after the note along its whole length, so a note being renamed has to reach
+ // the map rather than leaving the old name written across the track.
+ const title = useNoteProperty(note, "title") ?? "";
const trackColor = useMemo(() => note.getLabelValue("color") ?? "blue", [ color ]);
- const startIconHtml = useIconHtml(note.getIcon(), note.getColorClass() ?? undefined, hideLabels ? undefined : note.title);
+ const startIconHtml = useIconHtml(note.getIcon(), note.getColorClass() ?? undefined, hideLabels ? undefined : title);
const endIconHtml = useIconHtml("bx bxs-flag-checkered");
const waypointIconHtml = useIconHtml("bx bx-pin");
return xmlString && <GpxTrack
+ noteId={note.noteId}
+ title={title}
gpxXmlString={xmlString}
trackColor={trackColor}
startIconHtml={startIconHtml}
endIconHtml={endIconHtml}
waypointIconHtml={waypointIconHtml}
+ isDarkTheme={isDarkTheme}
+ hideLabels={hideLabels}
/>;
}