feat(tours): plan ski and winter tours, snowshoeing and winter hiking among them

Ski becomes "Ski & winter", a type the planner plans with six disciplines
(alpine, snowboard, cross-country, ski touring, snowshoeing, winter hiking),
nothing preselected; saving needs a discipline, and a technique for
cross-country. Every leg is drawn straight between the points through
planner/skiRouting.ts, the one place the piste router will plug in, with its
heights from the elevation source and no ski time worked out.

The hike's winter label goes entirely: its migration, column, field, marks,
GPX rule, MCP field and strings. A hike is summer only; a ski tour with the
snowshoe discipline exports as snowshoeing. The unreleased ski migration takes
the six disciplines and the collection migration loses the winter column.

The pistes are offered for a ski tour, shown until switched off, and with no
tour open, never for a hike. Export, copy, collections, stages (untimed),
actual tracks, the atlas, list and day marks (one glyph per discipline), 3D,
planning over a ski import and list_tours/get_tour_plan know the planned ski
tour.
This commit is contained in:
Maurice
2026-10-20 18:27:53 +02:00
parent 204ee2ef86
commit 164a3633ac
116 changed files with 1675 additions and 1576 deletions
@@ -134,6 +134,7 @@ function planner(
mapBaseLayer: 'default',
setMapBaseLayer: vi.fn(),
mapOverlays: new Set(),
mapOverlaysOff: new Set(),
toggleMapOverlay: vi.fn(),
routeProfileFocus: null,
setRouteProfileFocus: vi.fn(),
@@ -575,6 +576,28 @@ describe('TourPlannerMapStage', () => {
expect(tourPlanner.undo).not.toHaveBeenCalled();
});
it('FE-PAGE-TOURSTAGE-033: a planned ski tour flies in 3D with its grade colours, the pistes laid over it (SKI-02)', async () => {
const samples = [0, 1, 2].map((i) => ({
distanceMeters: i * 100,
elevationMeters: 1800 - i * 60,
lat: 47 + i / 1000,
lng: 11,
}));
const tourPlanner = planner('edit-saved', {
tourType: 'ski',
routeAnalysis: { distanceIndexedProfileSamples: samples },
});
renderStage(tourPlanner);
expect(stage.flatMap.props?.tourLayers?.bases).toEqual(['default', 'topo', 'satellite']);
expect(stage.flatMap.props?.tourLayers?.overlays?.map((overlay) => [overlay.id, overlay.status])).toEqual([
['pistes', 'on'],
]);
expect(stage.flatMap.props?.ferrataLayer).toBeUndefined();
await openTerrain();
expect(screen.getByRole('button', { name: 'Grade mix' })).toBeInTheDocument();
expect(tourPlanner.addWaypoint).not.toHaveBeenCalled();
});
it('FE-PAGE-TOURSTAGE-019: while a section is compared its card is up, and a click on the route sets no shaping point (RTE-02)', () => {
const route = [
[46, 7],
@@ -821,10 +844,10 @@ describe('TourPlannerMapStage', () => {
expect(overlay()).toMatchObject({ status: 'off', active: false });
});
it('FE-PAGE-TOURSTAGE-028: the pistes switch on over the map with no tour open and stay on when a hike opens (SKI-01)', () => {
it('FE-PAGE-TOURSTAGE-028: the pistes switch on over the map with no tour open and stay on when a ski tour opens (SKI-01)', () => {
function NeutralStage({ mode }: { mode: 'neutral' | 'new-draft' }) {
const view = useTourMapView();
return <TourPlannerMapStage {...stageProps(planner(mode, view))} />;
return <TourPlannerMapStage {...stageProps(planner(mode, { ...view, tourType: 'ski' }))} />;
}
const { rerender } = render(<NeutralStage mode="neutral" />);
const pistes = () => flat().tourLayers?.overlays?.find((overlay) => overlay.id === 'pistes');
@@ -838,18 +861,18 @@ describe('TourPlannerMapStage', () => {
});
expect(pistes()?.attribution).toContain('OpenSnowMap');
expect(pistes()?.attribution).toContain('OpenStreetMap');
// The choice is the map view's, so it outlasts the switch from no tour to a hike.
// The choice is the map view's, so it outlasts the switch from no tour to a ski tour.
rerender(<NeutralStage mode="new-draft" />);
expect(pistes()?.status).toBe('on');
});
it('FE-PAGE-TOURSTAGE-029: switching the pistes changes no point and no step, and a source that stopped answering keeps the map (SKI-01)', () => {
const tourPlanner = planner('edit-saved', { mapOverlays: new Set(['pistes']) });
const tourPlanner = planner('edit-saved', { tourType: 'ski', mapOverlays: new Set(['pistes']) });
renderStage(tourPlanner);
const pistes = () => flat().tourLayers?.overlays?.find((overlay) => overlay.id === 'pistes');
expect(pistes()?.status).toBe('on');
act(() => pistes()?.onToggle());
expect(tourPlanner.toggleMapOverlay).toHaveBeenCalledWith('pistes');
expect(tourPlanner.toggleMapOverlay).toHaveBeenCalledWith('pistes', true);
act(() => {
for (let i = 0; i < 4; i += 1) pistes()?.onTileError();
});
@@ -862,13 +885,13 @@ describe('TourPlannerMapStage', () => {
expect(tourPlanner.undo).not.toHaveBeenCalled();
});
it('FE-PAGE-TOURSTAGE-030: an imported ski track offers the pistes; a bike tour, a run and a paddle tour do not (SKI-01)', () => {
it('FE-PAGE-TOURSTAGE-030: an imported ski track shows the pistes at once; a hike, a bike tour, a run and a paddle tour do not offer them (SKI-01)', () => {
const viewed = (tour: Record<string, unknown>) =>
planner('view-gpx', { mode: { type: 'view-gpx', placeId: 9, tour: { place_id: 9, ...tour } } });
const ski = renderStage(viewed({ tour_type: 'ski', ski_discipline: 'alpine' }));
expect(overlayStates()).toEqual([['pistes', 'off']]);
expect(overlayStates()).toEqual([['pistes', 'on']]);
ski.unmount();
for (const tourType of ['bike', 'run', 'kayak']) {
for (const tourType of ['hike', 'bike', 'run', 'kayak']) {
const other = renderStage(planner('new-draft', { tourType }));
expect(flat().tourLayers?.overlays?.some((overlay) => overlay.id === 'pistes')).toBe(false);
other.unmount();
@@ -886,5 +909,22 @@ describe('TourPlannerMapStage', () => {
act(() => flat().onViewportChange?.(area, 12));
expect(pistes()?.belowMinZoom).toBe(false);
});
it('FE-PAGE-TOURSTAGE-032: a planned ski tour shows the pistes until switched off, and off they stay for the next one (SKI-01)', () => {
function SkiStage({ placeId }: { placeId: number }) {
const view = useTourMapView();
const mode = { type: 'edit-saved', placeId };
return <TourPlannerMapStage {...stageProps(planner('edit-saved', { ...view, tourType: 'ski', mode }))} />;
}
const { rerender } = render(<SkiStage placeId={4} />);
const pistes = () => flat().tourLayers?.overlays?.find((overlay) => overlay.id === 'pistes');
expect(pistes()).toMatchObject({ status: 'on', active: true });
act(() => pistes()?.onToggle());
expect(pistes()).toMatchObject({ status: 'off', active: false });
rerender(<SkiStage placeId={5} />);
expect(pistes()?.status).toBe('off');
act(() => pistes()?.onToggle());
expect(pistes()?.status).toBe('on');
});
});
});
@@ -15,7 +15,14 @@ function planner(
tourType: Planner['tourType'] = 'hike',
mapBaseLayer: Planner['mapBaseLayer'] = 'hiking'
): Planner {
return { mode, tourType, mapBaseLayer, mapOverlays: new Set(), toggleMapOverlay: () => {} };
return {
mode,
tourType,
mapBaseLayer,
mapOverlays: new Set(),
mapOverlaysOff: new Set(),
toggleMapOverlay: () => {},
};
}
const basesOf = (p: Planner, zoom: number | null = null) =>
@@ -68,17 +75,33 @@ describe('useTourStageLayers: OpenHikingMap (MAP-01)', () => {
describe('useTourStageLayers: the pistes (SKI-01)', () => {
const pistesOf = (p: Planner) => basesOf(p).tourLayers.overlays.find((overlay) => overlay.id === 'pistes');
it('offers them with no tour open, for a hike and for an imported ski track, off until switched on', () => {
const ski = { type: 'view-gpx', placeId: 9, tour: { place_id: 9, tour_type: 'ski' } as TourListItem } as const;
for (const mode of [{ type: 'neutral' }, { type: 'new-draft' }, ski] as const) {
expect(pistesOf(planner(mode, 'hike', 'default'))).toMatchObject({ status: 'off', active: false });
}
it('offers them with no tour open, off until switched on, and shows them for a ski tour until switched off', () => {
expect(pistesOf(planner({ type: 'neutral' }, 'hike', 'default'))).toMatchObject({ status: 'off', active: false });
// With no tour open they come even while the last type chosen was a paddle tour.
expect(pistesOf(planner({ type: 'neutral' }, 'kayak', 'default'))).toBeDefined();
const imported = { type: 'view-gpx', placeId: 9, tour: { place_id: 9, tour_type: 'ski' } as TourListItem } as const;
for (const p of [planner(imported, 'hike', 'default'), planner({ type: 'new-draft' }, 'ski', 'default')]) {
expect(pistesOf(p)).toMatchObject({ status: 'on', active: true });
expect(pistesOf({ ...p, mapOverlaysOff: new Set(['pistes']) })).toMatchObject({ status: 'off', active: false });
}
});
it('not for a bike tour, a run or a paddle tour that is open', () => {
for (const tourType of ['bike', 'run', 'kayak'] as const)
it('switches the pistes of a ski tour off by saying they show, and on again by saying they do not', () => {
const toggles: Array<[string, boolean | undefined]> = [];
const toggleMapOverlay = (id: string, shown?: boolean) => {
toggles.push([id, shown]);
};
const shown = { ...planner({ type: 'new-draft' }, 'ski', 'default'), toggleMapOverlay };
pistesOf(shown)?.onToggle();
pistesOf({ ...shown, mapOverlaysOff: new Set(['pistes']) })?.onToggle();
expect(toggles).toEqual([
['pistes', true],
['pistes', false],
]);
});
it('not for a hike, a bike tour, a run or a paddle tour that is open: a hike is summer only', () => {
for (const tourType of ['hike', 'bike', 'run', 'kayak'] as const)
expect(pistesOf(planner({ type: 'new-draft' }, tourType, 'default'))).toBeUndefined();
});
@@ -20,12 +20,16 @@ type FerrataLayerState = ReturnType<typeof useFerrataMapLayer>;
* neither draws nor warns about ferratas, even if the layer was switched on before; a base layer it
* does not offer falls back to its default without changing the choice kept,
* which is also what an install whose admin withdrew OpenHikingMap sees.
* The pistes (SKI-01) are offered with no tour open too, whatever type was chosen last.
* The pistes (SKI-01) are offered for a ski tour, where they show until switched off, and with
* no tour open, whatever type was chosen last; a hike no longer has them.
* `mapZoom` is the map's zoom on the raster tile scale, null until it reported one, so an
* overlay switched on further out than its tiles reach can say so instead of looking broken.
*/
export function useTourStageLayers(
tourPlanner: Pick<TourPlannerController, 'mode' | 'tourType' | 'mapBaseLayer' | 'mapOverlays' | 'toggleMapOverlay'>,
tourPlanner: Pick<
TourPlannerController,
'mode' | 'tourType' | 'mapBaseLayer' | 'mapOverlays' | 'mapOverlaysOff' | 'toggleMapOverlay'
>,
ferrata: FerrataLayerState,
mapZoom: number | null = null
) {
@@ -36,7 +40,8 @@ export function useTourStageLayers(
const hikingMapAllowed = useAddonStore((state) => state.toursHikingMap);
const cycleMapAllowed = useAddonStore((state) => state.toursCycleMap);
const tourOpen = mode.type !== 'neutral';
const layerSet = tourMapLayersFor(mode.type === 'view-gpx' ? mode.tour.tour_type : tourPlanner.tourType, {
const openType = mode.type === 'view-gpx' ? mode.tour.tour_type : tourPlanner.tourType;
const layerSet = tourMapLayersFor(openType, {
hikingMap: hikingMapAllowed && tourOpen,
cycleMap: cycleMapAllowed && tourOpen,
});
@@ -54,14 +59,20 @@ export function useTourStageLayers(
toggleSeamarks,
mapZoom
);
// SKI-01: the pistes for the types they serve, and with no tour open, so a ski area can be
// looked at without any route. Switching them never touches the tour: the switch is the map view's.
// SKI-01: the pistes for a ski tour, and with no tour open, so a ski area can be looked at
// without any route. A ski tour shows them until they are switched off; switching them never
// touches the tour: the switch is the map view's.
const offersPistes = !tourOpen || layerSet.overlays.includes('pistes');
const togglePistes = useCallback(() => toggleMapOverlay(PISTE_OVERLAY.id), [toggleMapOverlay]);
const pistesByDefault = tourOpen && openType === 'ski' && !tourPlanner.mapOverlaysOff.has(PISTE_OVERLAY.id);
const pistesShown = tourPlanner.mapOverlays.has(PISTE_OVERLAY.id) || pistesByDefault;
const togglePistes = useCallback(
() => toggleMapOverlay(PISTE_OVERLAY.id, pistesShown),
[toggleMapOverlay, pistesShown]
);
const pistes = useTourRasterOverlay(
PISTE_OVERLAY,
offersPistes,
tourPlanner.mapOverlays.has(PISTE_OVERLAY.id),
pistesShown,
togglePistes,
mapZoom
);