feat(tours): plan a trail run on forest tracks and natural paths

RUN-02. Trail running joins Running as a run profile, chosen on purpose in
the planner and in the GPX import. It asks Valhalla's pedestrian costing for
tracks wherever they serve (use_tracks 1) and admits mountain paths up to T2
(max_hiking_difficulty 2), never T3 and above, with ferries only where no
way on land exists. Checked with trace_attributes against the public
instance: above Freiburg Guenterstal up to the Schauinsland the route went
from 82 % roads and 83 % paved (running) to 78 % forest tracks and 81 %
compacted, gravel and dirt; Rathen to the Bastei took 28 % of T2 path that
running leaves out; Heidelberg's old town stayed as it was. Leaning on
footways (walkway_factor) was tried and left out, it moved runs onto paved
footways.

While a run is planned, a card says what it runs on: its surfaces, the
hiking grades of its paths (sac_scale, T1 to T6, as mappers gave them) and
its kinds of way, each as shares with lengths that point at their stretches
on the map. A way without a grade or a surface is its own row, unknown and
never easy, and an info dot says the grades say nothing about whether a way
can be run. The head carries the unpaved share and the hardest graded path
as badges. The line is matched on foot for this, so steps and mountain
paths stay on it; a bike tour's is matched as before. Reading fails, goes
offline or is retried as for a bike tour, and nothing of it changes the run.

Pace and time are RUN-01's: the running time stays the distance at the
runner's pace, with climbs, descents and difficulty left out, whatever the
profile. A profile change plans the route again and keeps the pace; a
failed trail route keeps the last route and holds Save back. The card's
building blocks moved out of the bike card into RouteWaySections, so both
cards share one set of rows, bars and status lines.

The run_profile column already allowed trail (RUN-01), so no migration.
GPX export names a trail run trail_running, list_tours describes the
profile as a routing preference, never a statement that a way can be run.
This commit is contained in:
Maurice
2026-10-20 13:15:31 +02:00
parent 1d9b9bf838
commit 51bfb5abd1
58 changed files with 1161 additions and 306 deletions
@@ -48,6 +48,7 @@ import { TourScopeSummary } from '../TourScopeSummary'
import { useTourListFilters } from '../useTourListFilters'
import { TourPoiSearchCard } from '../poi/TourPoiSearchCard'
import { BikeWaysCard } from '../bike/BikeWaysCard'
import { RunWaysCard } from '../run/RunWaysCard'
import { walkTimeFields } from '../walk/walkTimeFields'
const STATUS_KEY: Partial<Record<TourPlannerStatus, string>> = {
@@ -454,6 +455,8 @@ export function TourPlannerRail({ planner,
<BikeWaysCard planner={planner} />
<RunWaysCard planner={planner} />
<TourPoiSearchCard planner={planner} />
<PaddleEditorCards planner={planner} locked={locked} checklist={paddleChecklist} />
@@ -245,4 +245,14 @@ describe('routing on land, bike profiles and unreachable points (BIK-01)', () =>
valhallaRun.mockResolvedValueOnce(run([3, 900]))
expect(await routeRun(waypoints, 'running')).toEqual({ unreachable: 1, snappedMeters: 900 })
})
it('TOUR-ROUTING-035: a trail run asks for tracks and natural paths, up to mountain paths, and still no ferry (RUN-02)', async () => {
valhallaRun.mockResolvedValueOnce(run([3, 4]))
expect(await routeRun(waypoints, 'trail')).toMatchObject({ distanceMeters: 1500 })
expect(valhallaRun).toHaveBeenCalledWith(waypoints, 'walking', [], undefined, {
use_tracks: 1,
use_ferry: 0,
max_hiking_difficulty: 2,
})
})
})
@@ -120,24 +120,36 @@ export async function routeCityWalk(
const CITY_WALK_COSTING: Readonly<CostingOptions> = { use_ferry: 0 }
/**
* RUN-01: what each run profile asks Valhalla's pedestrian costing for.
* Running keeps to runnable, mostly paved ways: farm and forest tracks are
* taken only where there is no other way (`use_tracks` 0), and a run is run,
* so a ferry only where no way on land exists (`use_ferry` 0). Checked with
* trace_attributes against the public instance on 20.10.2026 (shares of the
* length): Berlin S Grunewald into the forest went from 95 % tracks with 3 %
* paved to 67 % smooth paved paths over 3.58 km instead of 3.50 km; Munich
* Großhesseloher Brücke to Pullach from 79 % to 88 % smooth asphalt and no
* track left; Marienplatz to the Englischer Garten stayed as it was. No hiking
* limit is sent, so the router keeps to the ways it takes for walking anyway
* (T1). The router's own time is a walker's and is never used: a run's time is
* its distance at the runner's pace. Nothing here says a way can be run.
* RUN-01, RUN-02: what each run profile asks Valhalla's pedestrian costing
* for. A run is run, so a ferry only where no way on land exists
* (`use_ferry` 0). Checked with trace_attributes against the public instance
* on 20.10.2026 (shares of the length):
* - running keeps to runnable, mostly paved ways: farm and forest tracks only
* where there is no other way (`use_tracks` 0), and no hiking limit, so the
* router keeps to the ways it takes for walking anyway (T1). Berlin S
* Grunewald into the forest went from 95 % tracks with 3 % paved to 67 %
* smooth paved paths over 3.58 km instead of 3.50 km; Munich Großhesseloher
* Brücke to Pullach from 79 % to 88 % smooth asphalt and no track left;
* Marienplatz to the Englischer Garten stayed as it was.
* - trail takes tracks wherever they serve (`use_tracks` 1) and admits
* mountain paths up to T2 (`max_hiking_difficulty` 2), never T3 and above.
* Above Freiburg Günterstal up to the Schauinsland it went from 82 % roads
* and 83 % paved (running) to 78 % forest tracks and 81 % compacted, gravel
* and dirt over 9.57 km instead of 10.15 km; Rathen to the Bastei took 28 % of T2
* path that running leaves out; Heidelberg's old town, all streets, stayed
* as it was. Leaning on footways (`walkway_factor`) was tried and left out:
* along the Isar it moved the run onto paved footways, from 33 % to 18 %
* unpaved.
* The router's own time is a walker's and is never used: a run's time is its
* distance at the runner's pace, whatever the profile. Nothing here says a
* way can be run.
*/
const RUN_COSTING: Record<RunProfile, Readonly<CostingOptions>> = {
running: { use_tracks: 0, use_ferry: 0 },
trail: { use_tracks: 1, use_ferry: 0, max_hiking_difficulty: 2 },
}
/** RUN-01: a run, on foot for its profile; a leg drawn by hand is kept as drawn. */
/** RUN-01, RUN-02: a run, on foot for its profile; a leg drawn by hand is kept as drawn. */
export async function routeRun(
waypoints: LandWaypoint[],
profile: RunProfile,
@@ -16,7 +16,7 @@ vi.mock('../useTourPermissions', () => ({ useTourPermissions: () => ({ canEdit:
import { useTourPlanner, type DerivedTourDraft } from './useTourPlanner';
// FE-TOUR-RUN-001 to FE-TOUR-RUN-008
// FE-TOUR-RUN-001 to FE-TOUR-RUN-010
const routed = {
coordinates: [
@@ -242,4 +242,38 @@ describe("useTourPlanner, a run at the runner's own pace (RUN-01)", () => {
expect(result.current.runPace.paceSecondsPerKm).toBeNull();
expect(result.current.runPaceMissing).toBe(true);
});
it('FE-TOUR-RUN-009: trail running plans the route again for trails, keeps the pace and its sum, and saves as trail (RUN-02)', async () => {
createTour.mockResolvedValue({ tour: { ...savedRun, run_profile: 'trail' }, waypoints: savedPoints });
const { result } = await plannedRun(79);
act(() => result.current.runPace.setPace(450));
routeRun.mockClear();
act(() => result.current.setRunProfile('trail'));
await settle();
expect(routeRun).toHaveBeenCalledWith(expect.any(Array), 'trail', expect.any(AbortSignal));
expect(result.current.runProfile).toBe('trail');
const distanceKm = result.current.routeAnalysis?.distanceKm ?? 0;
// The profile changes the ways, never the time: still the distance at the pace, nothing for the terrain.
expect(result.current.walkingDurationMinutes).toBe(Math.round(distanceKm * 7.5));
await act(async () => {
await result.current.save();
});
expect(createTour).toHaveBeenCalledWith(
79,
expect.objectContaining({ tour_type: 'run', run_profile: 'trail', run_pace_seconds_per_km: 450 })
);
});
it('FE-TOUR-RUN-010: a trail route the router cannot plan keeps the last route, and the run waits rather than saving it (RUN-02)', async () => {
const { result } = await plannedRun(80);
act(() => result.current.runPace.setPace(450));
routeRun.mockResolvedValueOnce(null);
act(() => result.current.setRunProfile('trail'));
await settle();
expect(result.current.status).toBe('routing-failed');
expect(result.current.route).toEqual(routed.coordinates);
expect(result.current.tourType).toBe('run');
expect(result.current.runPace.paceSecondsPerKm).toBe(450);
expect(result.current.canSave).toBe(false);
});
});