mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 10:44:23 +00:00
feat(journey): draw the trips' GPX tracks on the journey map (#1911)
* feat(journey): serve the GPX tracks behind a journey A journey has no trip of its own, but every entry records the trip it came from, and a trip's routed geometries live on its places. So the tracks are derivable without any new storage: GET /journeys/:id/tracks walks that link and returns the geometries, dropping elevation nothing on the map reads and skipping anything that is not a usable line. * feat(journey): draw those tracks on the journey map Both renderers, Leaflet and GL, plus the mobile map-timeline that shares them. Solid and in the track's own colour with a white casing, so it reads as a recorded route rather than as the dashed line that merely connects entries in time order, and stays legible on satellite tiles. * feat(journey): load the tracks alongside the journey Fetched separately from the journey itself: most journeys have no tracks, and a failed lookup should cost the map its lines rather than the whole page. * docs(journey): document the GPX tracks on the map * fix(journey): label tracks with the house map tooltip bindTooltip's default box ignores the appearance tokens, so it sat there in Leaflet grey next to markers already using .map-tooltip. Same class now, and an unnamed track gets no tooltip at all instead of an empty one.
This commit is contained in:
@@ -35,14 +35,14 @@ vi.mock('leaflet', () => {
|
||||
map: vi.fn(() => mockMap),
|
||||
tileLayer: vi.fn(() => ({ addTo: vi.fn() })),
|
||||
marker: vi.fn(() => mockMarker),
|
||||
polyline: vi.fn(() => ({ addTo: vi.fn() })),
|
||||
polyline: vi.fn(() => { const line: any = { addTo: vi.fn(() => line), bindTooltip: vi.fn(() => line) }; return line }),
|
||||
divIcon: vi.fn(() => ({})),
|
||||
latLngBounds: vi.fn(() => ({})),
|
||||
},
|
||||
map: vi.fn(() => mockMap),
|
||||
tileLayer: vi.fn(() => ({ addTo: vi.fn() })),
|
||||
marker: vi.fn(() => mockMarker),
|
||||
polyline: vi.fn(() => ({ addTo: vi.fn() })),
|
||||
polyline: vi.fn(() => { const line: any = { addTo: vi.fn(() => line), bindTooltip: vi.fn(() => line) }; return line }),
|
||||
divIcon: vi.fn(() => ({})),
|
||||
latLngBounds: vi.fn(() => ({})),
|
||||
};
|
||||
@@ -489,4 +489,65 @@ describe('JourneyMap', () => {
|
||||
unmount();
|
||||
expect(vi.mocked(map.remove).mock.calls.length).toBe(before + 1);
|
||||
});
|
||||
// ── GPX tracks (#1260) ──────────────────────────────────────────────────────
|
||||
const track = (over: Partial<{ place_id: number; trip_id: number; name: string; color: string | null; points: [number, number][] }> = {}) => ({
|
||||
place_id: 1, trip_id: 1, name: 'Morning hike', color: '#ff0000',
|
||||
points: [[47.1, 11.2], [47.2, 11.3]] as [number, number][], ...over,
|
||||
});
|
||||
|
||||
it('FE-COMP-JOURNEYMAP-040: draws a track as a casing plus a coloured line', () => {
|
||||
vi.mocked(L.polyline).mockClear();
|
||||
render(<JourneyMap checkins={[]} entries={entriesWithCoords} tracks={[track()]} />);
|
||||
|
||||
const calls = vi.mocked(L.polyline).mock.calls;
|
||||
const casing = calls.find(c => (c[1] as any)?.color === '#ffffff');
|
||||
const line = calls.find(c => (c[1] as any)?.color === '#ff0000');
|
||||
expect(casing).toBeDefined();
|
||||
expect(line).toBeDefined();
|
||||
// Leaflet wants [lat, lng], which is the order the geometry is stored in.
|
||||
expect(line![0]).toEqual([[47.1, 11.2], [47.2, 11.3]]);
|
||||
// Solid, unlike the dashed line that merely connects entries in time order.
|
||||
expect((line![1] as any).dashArray).toBeUndefined();
|
||||
});
|
||||
|
||||
it('FE-COMP-JOURNEYMAP-043: labels a track with the map tooltip the markers use', () => {
|
||||
vi.mocked(L.polyline).mockClear();
|
||||
render(<JourneyMap checkins={[]} entries={entriesWithCoords} tracks={[track({ name: 'Morning hike' })]} />);
|
||||
|
||||
const line = vi.mocked(L.polyline).mock.results
|
||||
.map(r => r.value as any)
|
||||
.find(v => v.bindTooltip.mock.calls.length > 0);
|
||||
expect(line).toBeDefined();
|
||||
const [label, opts] = line.bindTooltip.mock.calls[0];
|
||||
expect(label).toBe('Morning hike');
|
||||
// The house tooltip, not Leaflet's default box: it reads the appearance tokens.
|
||||
expect(opts.className).toBe('map-tooltip');
|
||||
});
|
||||
|
||||
it('FE-COMP-JOURNEYMAP-044: an unnamed track gets no empty tooltip', () => {
|
||||
vi.mocked(L.polyline).mockClear();
|
||||
render(<JourneyMap checkins={[]} entries={entriesWithCoords} tracks={[track({ name: '' })]} />);
|
||||
|
||||
const tooltipped = vi.mocked(L.polyline).mock.results
|
||||
.map(r => r.value as any)
|
||||
.filter(v => v.bindTooltip.mock.calls.length > 0);
|
||||
expect(tooltipped).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('FE-COMP-JOURNEYMAP-041: a track without its own colour falls back rather than vanishing', () => {
|
||||
vi.mocked(L.polyline).mockClear();
|
||||
render(<JourneyMap checkins={[]} entries={entriesWithCoords} tracks={[track({ color: null })]} />);
|
||||
|
||||
const colors = vi.mocked(L.polyline).mock.calls.map(c => (c[1] as any)?.color);
|
||||
expect(colors).toContain('#4f46e5');
|
||||
});
|
||||
|
||||
it('FE-COMP-JOURNEYMAP-042: a track with fewer than two points draws nothing', () => {
|
||||
vi.mocked(L.polyline).mockClear();
|
||||
render(<JourneyMap checkins={[]} entries={entriesWithCoords} tracks={[track({ points: [[47.1, 11.2]] })]} />);
|
||||
|
||||
const colors = vi.mocked(L.polyline).mock.calls.map(c => (c[1] as any)?.color);
|
||||
expect(colors).not.toContain('#ff0000');
|
||||
expect(colors).not.toContain('#ffffff');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user