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
@@ -360,6 +360,20 @@ describe('TourTerrainMap', () => {
expect(screen.queryByText('18 to 27 %')).toBeNull();
});
it('FE-COMP-TERRAIN-012b: a paddle tour keeps its tour colour, without the grade switch or the grade mix', async () => {
await renderTerrain({ samples: TOUR, water: true });
loadStyle();
await act(async () => openTiles());
expect(screen.queryByRole('button', { name: 'Grade' })).toBeNull();
expect(screen.queryByRole('button', { name: 'Grade mix' })).toBeNull();
const setData = gl.sources.get('tour-terrain-track')?.setData as ReturnType<typeof vi.fn> | undefined;
const drawCalls = setData?.mock.calls ?? [];
const drawn = drawCalls[drawCalls.length - 1]?.[0] as { features: { properties: { color: string } }[] } | undefined;
expect(drawn?.features.length).toBeGreaterThan(0);
expect(drawn?.features.every((feature) => feature.properties.color === '#0a84ff')).toBe(true);
});
it('FE-COMP-TERRAIN-013: swaps the style in place for another base layer and draws on it again', async () => {
const { rerender } = await renderTerrain({ samples: TOUR });
loadStyle();
@@ -37,6 +37,8 @@ export interface TourTerrainMapProps {
rightWidth: number;
waypoints: TerrainWaypoints;
framePoints: [number, number][];
/** A paddle tour: no grade colours, no grade legend and no switch for them, the water is flat. */
water?: boolean;
/** The planner map's via ferrata layer: its switch joins the layer pill, its lines the terrain. */
ferrataLayer?: FerrataMapLayer;
/** What the tour's type offers: its base layers, and the overlays drawn on the terrain too. */
@@ -78,7 +80,10 @@ export default function TourTerrainMap(props: TourTerrainMapProps) {
const { setContainer, ...terrain } = useTourTerrain({ ...props, panels: { leftWidth, rightWidth } });
const stats = useMemo(() => terrainStats(samples), [samples]);
const { fit, height: controlsHeight, attachRow, attachStack } = useControlRowFit();
const legend = terrain.canReplay ? <GradeLegend stats={stats} unit={unit} onLayout={props.onLegendLayout} /> : null;
const legend =
terrain.canReplay && !props.water ? (
<GradeLegend stats={stats} unit={unit} onLayout={props.onLegendLayout} />
) : null;
const legendAbove = fit === 'stacked';
useEffect(() => {
@@ -120,7 +125,7 @@ export default function TourTerrainMap(props: TourTerrainMapProps) {
<div className="grid min-w-0 flex-1 grid-cols-[1fr_auto_1fr] items-end gap-3">
<span />
{terrain.canReplay ? (
<TerrainDock terrain={terrain} />
<TerrainDock terrain={terrain} water={props.water} />
) : (
<div
className="pointer-events-auto rounded-full px-4 py-2.5 text-content-muted"
@@ -173,8 +178,14 @@ function Divider() {
return <span aria-hidden className="mx-0.5 h-5 w-px flex-none bg-edge" />;
}
/** One pill like the layer switcher: play, restart, overview · speed · relief · colour. */
function TerrainDock({ terrain }: { terrain: Omit<ReturnType<typeof useTourTerrain>, 'setContainer'> }) {
/** One pill like the layer switcher: play, restart, overview · speed · relief · colour (not on water). */
function TerrainDock({
terrain,
water,
}: {
terrain: Omit<ReturnType<typeof useTourTerrain>, 'setContainer'>;
water?: boolean;
}) {
const { t } = useTranslation();
return (
<div className="pointer-events-auto flex items-center gap-0.5 rounded-full p-1" style={GLASS}>
@@ -231,6 +242,16 @@ function TerrainDock({ terrain }: { terrain: Omit<ReturnType<typeof useTourTerra
<span className="w-7 font-semibold tabular-nums">{terrain.exaggeration.toFixed(1)}×</span>
</label>
</Tooltip>
{!water && <GradeSwitch terrain={terrain} />}
</div>
);
}
/** Colour the route by grade or in the tour colour. */
function GradeSwitch({ terrain }: { terrain: Omit<ReturnType<typeof useTourTerrain>, 'setContainer'> }) {
const { t } = useTranslation();
return (
<>
<Divider />
<button
type="button"
@@ -242,7 +263,7 @@ function TerrainDock({ terrain }: { terrain: Omit<ReturnType<typeof useTourTerra
<Palette size={15} strokeWidth={2} />
{t('tours.terrain.colorByGrade')}
</button>
</div>
</>
);
}
@@ -147,12 +147,12 @@ describe('camera and markers', () => {
});
it('numbers a control point and shows whether it can be dragged', () => {
const pin = waypointPinElement(2, true, true);
const pin = waypointPinElement({}, 2, true, true);
expect(pin.textContent).toBe('3');
expect(pin.getAttribute('aria-label')).toBe('Waypoint 3');
expect(pin.style.width).toBe('30px');
expect(pin.style.cursor).toBe('grab');
const fixed = waypointPinElement(0, false, false);
const fixed = waypointPinElement({}, 0, false, false);
expect(fixed.style.width).toBe('26px');
expect(fixed.style.cursor).toBe('pointer');
});
@@ -3,6 +3,7 @@ import { OPENTOPOMAP_TILE_URL, SATELLITE_TILE_URL } from '../../../constants/map
import type { DistanceIndexedProfileSample } from '../../../utils/routeGeometry';
import { OPENFREEMAP_DEFAULT_STYLE } from '../../Map/glProviders';
import type { TourBaseLayer } from '../../Map/MapLayerSwitcher';
import { plannerPinShape, type PlannerPinPoint } from '../../Map/plannerPinShape';
import type { TileTemplate } from './terrainPrefetch';
import { gradeBand, gradeSegments } from './tourTerrainModel';
@@ -198,11 +199,16 @@ export function riderElement(trackColor: string): HTMLElement {
}
/** A numbered control point, the same pin the flat planner map draws. */
export function waypointPinElement(index: number, selected: boolean, editable: boolean): HTMLButtonElement {
const size = selected ? 30 : 26;
export function waypointPinElement(
point: PlannerPinPoint,
index: number,
selected: boolean,
editable: boolean
): HTMLButtonElement {
const { size, text } = plannerPinShape(point, index, selected);
const el = document.createElement('button');
el.type = 'button';
el.textContent = String(index + 1);
el.textContent = text;
el.setAttribute('aria-label', `Waypoint ${index + 1}`);
el.style.cssText = `display:flex;width:${size}px;height:${size}px;align-items:center;justify-content:center;border-radius:9999px;background:${PIN_BLUE};color:white;border:${selected ? 3 : 2}px solid white;box-shadow:0 2px 7px rgba(0,0,0,.4);font:700 11px system-ui;cursor:${editable ? 'grab' : 'pointer'};padding:0`;
return el;
@@ -6,7 +6,15 @@ import type { TerrainGl } from './useTerrainMap';
export interface TerrainWaypoints {
/** `name` and `detail` (its role) show on hover. */
points: Array<{ id: string; lat: number; lng: number; name?: string; detail?: string }>;
points: Array<{
id: string;
lat: number;
lng: number;
name?: string;
detail?: string;
label?: string;
shaping?: boolean;
}>;
selectedId: string | null;
onSelect: (id: string) => void;
/** Absent while the tour cannot be edited; the pins then stay put. */
@@ -38,7 +46,7 @@ export function useTerrainPins(
gl.map.on('movestart', hideOnMove);
const unbind: (() => void)[] = [() => gl.map.off('movestart', hideOnMove)];
pinsRef.current = points.map((point, index) => {
const el = waypointPinElement(index, point.id === selectedId, editable);
const el = waypointPinElement(point, index, point.id === selectedId, editable);
const name = point.name ?? String(index + 1);
el.setAttribute('aria-label', name);
unbind.push(bindPinHoverLabel(el, hoverLabel, gl.map.getContainer(), { name, detail: point.detail ?? null }));
@@ -30,13 +30,17 @@ interface Options {
tourLayers?: TourLayerOffer;
/** The visible area, for the via ferrata layer to ask for. */
onViewportChange?: (bbox: FerrataBbox) => void;
/** A paddle tour: the route is never coloured by grade. */
water?: boolean;
}
/** The planner map's 3D mode: map, pins, corridor preload and the flyover sharing the rail's focus. */
export function useTourTerrain(options: Options) {
const { samples, routes, trackColor, baseLayer, focus, onFocusChange, panels, waypoints, framePoints } = options;
const [exaggeration, setExaggeration] = useState(1.5);
const [colorMode, setColorMode] = useState<TrackColorMode>('grade');
const [chosenColorMode, setColorMode] = useState<TrackColorMode>('grade');
// Water is flat: a paddle tour keeps its tour colour, whatever was picked for a hike.
const colorMode: TrackColorMode = options.water ? 'tour' : chosenColorMode;
const data = useMemo(
() => trackData(samples, routes, colorMode, trackColor),
[samples, routes, colorMode, trackColor]