feat(tours): route paddle tours on the water, shaping points and auto-loaded regions

Paddle tours are planned on the water by TREK's own router: a water network
per paddle region, built from the same Geofabrik extract as the obstacles and
searched in a worker thread of the server (no sidecar). Rivers, canals and
lakes (direct or along the shore), portages round weirs, locks by policy,
whitewater by boat, gaps marked. Found portages and locks become points of
their own; an unplannable leg says why and offers a way out.

- Shaping points: a click on the line sets a point that steers the route
  without being a stop (hikes and paddle tours); recompute a single leg.
- Lake style direct/shore, suggested from the wind forecast.
- Regions load by themselves where a paddler plans (admin setting: automatic,
  on request, off; size cap and a daily count), with requests for the admins,
  a notification, and the load followed on the leg.
- Portage from the last point, portages follow footways via the walking
  router (or stay straight), "put in here" on slipways and put-ins.
- MCP plan_paddle_route with the REST route's rules.
This commit is contained in:
Maurice
2026-10-18 01:13:24 +02:00
parent b76a298bb3
commit 1bc82f97fd
321 changed files with 14675 additions and 471 deletions
@@ -3,6 +3,7 @@
export const ADMIN_EVENT_LABEL_KEYS: Record<string, string> = {
version_available: 'settings.notifyVersionAvailable',
replica_failure: 'settings.notifyReplicaFailure',
paddle_region_requested: 'settings.notifyPaddleRegionRequested',
}
export const ADMIN_CHANNEL_LABEL_KEYS: Record<string, string> = {
@@ -1,4 +1,4 @@
// FE-PAGE-TOURSTAGE-001 to FE-PAGE-TOURSTAGE-016
// FE-PAGE-TOURSTAGE-001 to FE-PAGE-TOURSTAGE-018
import type { Ferrata, PaddleFeature } from '@trek/shared';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { act, fireEvent, render, screen, waitFor } from '../../../tests/helpers/render';
@@ -486,6 +486,54 @@ describe('TourPlannerMapStage', () => {
expect(screen.getByTestId('tour-map-surface')).not.toHaveAttribute('data-placing');
});
it('FE-PAGE-TOURSTAGE-017: a click on the route being edited sets a shaping point in the leg there and selects it (P2A-03)', () => {
const tourPlanner = planner('new-draft', {
waypoints: [
{ id: 'w1', lat: 46, lng: 7 },
{ id: 'w2', lat: 46.1, lng: 7.1, shaping: true },
{ id: 'w3', lat: 46.2, lng: 7.2 },
],
route: [
[46, 7],
[46.1, 7.1],
[46.2, 7.2],
],
insertShapingPoint: vi.fn(() => 'shape-1'),
});
renderStage(tourPlanner);
const props = stage.flatMap.props;
expect(props?.plannerWaypoints?.map((point) => [point.label ?? null, !!point.shaping])).toEqual([
['1', false],
[null, true],
['2', false],
]);
props?.onRouteClick?.(46.15, 7.15);
expect(tourPlanner.insertShapingPoint).toHaveBeenCalledWith('w2', 46.15, 7.15);
expect(tourPlanner.setSelectedWaypointId).toHaveBeenCalledWith('shape-1');
});
it('FE-PAGE-TOURSTAGE-018: the route takes no shaping clicks outside editing or without edit rights', () => {
renderStage(
planner('view-saved', {
route: [
[46, 7],
[46.1, 7.1],
],
})
);
expect(stage.flatMap.props?.onRouteClick).toBeUndefined();
renderStage(
planner('new-draft', {
route: [
[46, 7],
[46.1, 7.1],
],
}),
false
);
expect(stage.flatMap.props?.onRouteClick).toBeUndefined();
});
describe('map layers per tour type (P2B-06/07, PAD-04, PAD-10)', () => {
const flat = () => stage.flatMap.props as MapViewProps;
@@ -11,9 +11,11 @@ import { MapViewAuto as MapView } from '../../components/Map/MapViewAuto';
import LocationSelect from '../../components/Planner/LocationSelect';
import { ChecklistObstaclePanel } from '../../components/Tours/paddle/ObstacleDecisionPanel';
import PaddleObstacleOverlay from '../../components/Tours/paddle/PaddleObstacleOverlay';
import { PaddleObstaclePlaceButton } from '../../components/Tours/paddle/PaddleObstaclePlaceButton';
import { useShapingClick } from '../../components/Tours/planner/useShapingClick';
import type { TerrainLegendLayout } from '../../components/Tours/terrain/TourTerrainMap';
import { isRtlLanguage, useTranslation } from '../../i18n';
import { usePaddleObstacleStore } from '../../store/paddleObstacleStore';
import { selectPaddleObstacle, usePaddleObstacleStore } from '../../store/paddleObstacleStore';
import { useSettingsStore } from '../../store/settingsStore';
import { publishTourFerrataCrossings } from '../../store/tourFerrataCrossingStore';
import { useFerrataAdopt } from './useFerrataAdopt';
@@ -137,6 +139,14 @@ export function TourPlannerMapStage({
const closingPress = useOutsidePressGuard();
const paddleOpen = usePaddleObstacleStore((state) => state.selectedRef !== null);
const adoptFerrata = useFerrataAdopt(tourPlanner, canPlaceEdit, ferrata.close);
// PAD-05B: a put-in, slipway or egress taken over from its card as the tour's next point.
const placeFromCard =
canPlaceEdit && tourPlanner.isPaddle && !tourPlanner.isSaving && tourPlanner.mode.type !== 'view-gpx'
? (lat: number, lng: number) => {
tourPlanner.addWaypoint(lat, lng);
selectPaddleObstacle(null);
}
: undefined;
const ferrataOnTour = useMemo(() => new Set(ferrataCrossings.map(({ group }) => group.id)), [ferrataCrossings]);
const distanceUnit = useSettingsStore((s) => s.settings.distance_unit);
// The "set points" tool, per mode; only a real click places, never the end of a drag.
@@ -150,6 +160,8 @@ export function TourPlannerMapStage({
});
// PAD-03 on a recorded paddle track: with a marking tool on, a click on the line marks the spot on it.
const { pickOnLine, onAddOrMark } = useTrackLinePick(tourPlanner, canPlaceEdit, closingPress.guard, waypoints.onAdd);
// P2A-03: a click on the route being edited sets a shaping point there.
const shapeAt = useShapingClick(tourPlanner, { editable: !!waypoints.onMove, picking: pickOnLine });
// What each panel covers of the map, a collapsed one its rail.
const leftInset = leftHidden ? 56 : leftPanelPx;
const rightInset = rightHidden ? 56 : rightPanelPx;
@@ -180,6 +192,7 @@ export function TourPlannerMapStage({
rightWidth={rightInset}
waypoints={waypoints}
framePoints={tourMap.focusPoints}
water={tourPlanner.isPaddle}
ferrataLayer={ferrataLayer}
onViewportChange={viewportChanged}
onControlsHeightChange={setTerrainControlsPx}
@@ -209,6 +222,7 @@ export function TourPlannerMapStage({
selectedPlannerWaypointId={waypoints.selectedId}
onPlannerWaypointClick={tourPlanner.setSelectedWaypointId}
onPlannerWaypointMove={waypoints.onMove}
onRouteClick={shapeAt}
routeProfileFocus={tourPlanner.routeProfileFocus}
viewBaseLayer={baseLayer}
onViewBaseLayerChange={tourPlanner.setMapBaseLayer}
@@ -235,11 +249,18 @@ export function TourPlannerMapStage({
onOutsidePress={closingPress.arm}
insetEnd={(isRtlLanguage(language) ? leftInset : rightInset) + MAP_LAYER_SWITCHER_INSET}
{...ferrataCardPlacement(terrain3d, bottomRowTop, terrainLegend)}
extra={(detail) =>
paddleChecklist ? (
<ChecklistObstaclePanel checklist={paddleChecklist} featureRef={detail.feature.ref} />
) : null
}
extra={(detail) => (
<>
{paddleChecklist && <ChecklistObstaclePanel checklist={paddleChecklist} featureRef={detail.feature.ref} />}
{placeFromCard && (
<PaddleObstaclePlaceButton
kind={detail.feature.kind}
geometry={detail.feature.geometry}
onPlace={placeFromCard}
/>
)}
</>
)}
/>
{/* "Point set", with the way back, above the bottom row and between the panels. */}
{placedHint.shown && (
@@ -76,13 +76,24 @@ export function useTourMapPoints({ tourPlanner, canPlaceEdit, mode, cardOpen, gu
const shown = isClosedLoop(waypoints) ? waypoints.slice(0, -1) : waypoints;
// A paddle tour names a pin for the paddler (put-in, take-out, re-entry) and says where a lock is.
const roles = isPaddle ? paddleRolesById(waypoints) : null;
return shown.map((point, index) => {
// Stops are numbered on their own: a shaping point (P2A-03) only steers and takes no number.
let stop = 0;
return shown.map((point) => {
if (point.shaping) {
return {
...point,
name: placeNames[point.id] ?? t('tours.planner.shapingPoint'),
detail: t('tours.planner.shapingPoint'),
};
}
stop += 1;
const role = roles?.get(point.id);
const detail = role ? t(`tours.paddle.role.${role}`) : roles ? '' : t(ROLE_KEY[point.role]);
const lock = point.lock ? t('tours.paddle.lock') : '';
return {
...point,
name: placeNames[point.id] ?? t('tours.planner.waypointLabel', { n: index + 1 }),
label: String(stop),
name: placeNames[point.id] ?? t('tours.planner.waypointLabel', { n: stop }),
detail: [detail, lock].filter(Boolean).join(', ') || t(ROLE_KEY[point.role]),
};
});
@@ -67,12 +67,12 @@ export function useTripPlannerPage() {
tourConversion.line, trackParts,
])
const editingRoute = tourPlanner.mode.type === 'new-draft' || tourPlanner.mode.type === 'edit-saved'
// A hand-drawn stretch of a hike is dotted, a paddle tour's portages dotted and brown.
// What no router planned is dotted; a paddle tour's portages brown, whitewater amber, gaps red.
const paddlePaint = usePaddlePaint()
const partStyle = tourRouteStyle(
!wandererBrowser.open && editingRoute ? tourPlanner.routeParts : !tourConversion.line ? trackParts : null,
tourPlanner.isPaddle || !!trackParts,
{ line: paddlePaint.portage, casing: paddlePaint.disc },
{ portage: paddlePaint.portage, rapids: paddlePaint.rapids, gap: paddlePaint.gap, casing: paddlePaint.disc },
)
const routeWalking = partStyle.walking ?? (route && route.length === 2 && tourConversion.line ? [true, false] : null)