feat(tours): lay pistes, cross-country trails and lifts over the planner map

SKI-01. The Tours planner's layer switch gains a winter layer: OpenSnowMap's
transparent piste overlay over whichever base map is shown, so a ski area
can be looked at while preparing a winter trip. It is offered with no tour
open (a resort without any route), beside a hike for winter hiking and on an
imported ski track; it needs neither a GPX import nor the ski type, and a
bike tour, a run and a paddle tour do not offer it. It is off until switched
on, and the choice belongs to the map view: switching it changes no point,
no step and no route, and it stays on from no tour to a hike and into 3D,
where the terrain draws it too.

The switch goes by its icon alone, named by its tooltip, so a hike's row
stays short. While the layer shows, a small key button rides beside it in
the same pill, its badge the four grade colours. The key opens above the
map as a popover: the downhill grades in OpenSnowMap's own colours (novice,
easy, intermediate, advanced, expert, freeride), cross-country trails,
winter and snowshoe trails, toboggan runs and lifts, a note that this is
mapped data that says nothing about what is open or groomed, the snow or
avalanches, and a link to the full key at OpenSnowMap. If the tiles stop
coming, the switch turns to the warning tone with its badge and says that
the map and the route still work, and the key stays away.

Only the overlay is used, never OpenSnowMap's relief or base maps. Like
every overlay it loads only the tiles in view: nothing is prefetched or
cached by the Service Worker, as their terms forbid bulk downloads. The
tiles go out with the page's origin as the referer, the attribution credits
OpenSnowMap (CC BY-SA) and the OpenStreetMap contributors, and the layer
stops at zoom 18, beyond which the server answers a picture instead of a
transparent tile. The CSP admits tiles.opensnowmap.org for the GL map,
which reads tiles through fetch.
This commit is contained in:
Maurice
2026-10-20 14:02:54 +02:00
parent 0169be3d79
commit 5ff7e54e09
40 changed files with 960 additions and 36 deletions
@@ -1,9 +1,10 @@
// FE-COMP-MAPLAYER-001 to FE-COMP-MAPLAYER-020
// FE-COMP-MAPLAYER-001 to FE-COMP-MAPLAYER-023
import React from 'react'
import { describe, it, expect, vi } from 'vitest'
import { render, screen, fireEvent } from '../../../tests/helpers/render'
import { MapLayerSwitcher, TourMapLayerSwitcher, MAP_ROUND_CONTROL_SIZE } from './MapLayerSwitcher'
import type { FerrataMapLayer } from '../Ferratas/useFerrataMapLayer'
import type { ToggleableRasterOverlay } from './mapRasterOverlay'
describe('MapLayerSwitcher', () => {
it('FE-COMP-MAPLAYER-001: on the default layer, offers the switch to satellite', () => {
@@ -235,3 +236,53 @@ describe('TourMapLayerSwitcher via ferrata switch', () => {
expect(screen.getByRole('button', { name: 'Set points' })).toHaveClass('text-content-muted')
})
})
const pisteOverlay = (overrides: Partial<ToggleableRasterOverlay> = {}): ToggleableRasterOverlay => ({
id: 'pistes',
url: 'https://tiles.opensnowmap.org/pistes/{z}/{x}/{y}.png',
attribution: 'OpenSnowMap',
minZoom: 9,
maxZoom: 18,
active: false,
status: 'off',
onToggle: vi.fn(),
onTileError: vi.fn(),
onTileLoad: vi.fn(),
...overrides,
})
describe('TourMapLayerSwitcher piste switch (SKI-01)', () => {
it('FE-COMP-MAPLAYER-021: the pistes switch sits on its icon alone, named by its tooltip, and offers no key while off', async () => {
const overlay = pisteOverlay()
render(<TourMapLayerSwitcher active="default" onChange={() => {}} ferrataLayer={ferrataLayer()} layers={{ overlays: [overlay] }} />)
const toggle = screen.getByRole('button', { name: 'Pistes, cross-country trails and lifts' })
expect(toggle).toHaveAttribute('aria-pressed', 'false')
expect(toggle.textContent).toBe('')
expect(screen.queryByTestId('piste-key-button')).toBeNull()
fireEvent.click(toggle)
expect(overlay.onToggle).toHaveBeenCalledTimes(1)
fireEvent.mouseEnter(toggle)
expect(await screen.findByRole('tooltip')).toHaveTextContent('Pistes, cross-country trails and lifts')
})
it('FE-COMP-MAPLAYER-022: on, the switch is pressed in the accent and the key rides beside it in the same pill', () => {
render(<TourMapLayerSwitcher active="default" onChange={() => {}} layers={{ overlays: [pisteOverlay({ active: true, status: 'on' })] }} />)
const toggle = screen.getByRole('button', { name: 'Pistes, cross-country trails and lifts' })
expect(toggle).toHaveAttribute('aria-pressed', 'true')
expect(toggle).toHaveClass('bg-accent', 'text-accent-text')
const key = screen.getByTestId('piste-key-button')
expect(screen.getByRole('group')).toContainElement(key)
expect(key).toHaveAccessibleName('Piste key')
})
it('FE-COMP-MAPLAYER-023: a piste source that stopped answering shows the warning badge, says so, and hides the key', async () => {
render(<TourMapLayerSwitcher active="default" onChange={() => {}} layers={{ overlays: [pisteOverlay({ active: true, status: 'down' })] }} />)
const toggle = screen.getByRole('button', { name: 'Pistes, cross-country trails and lifts' })
expect(toggle).toHaveAttribute('data-status', 'down')
expect(toggle).toHaveTextContent('!')
expect(screen.queryByTestId('piste-key-button')).toBeNull()
expect(screen.getByRole('status')).toHaveTextContent('Pistes are not loading. The map and your route still work.')
fireEvent.mouseEnter(toggle)
expect(await screen.findByRole('tooltip')).toHaveTextContent('Pistes are not loading.')
})
})
+27 -12
View File
@@ -1,6 +1,7 @@
import { Anchor, Bike, Footprints, Loader2, Map as MapIcon, MapPinPlus, Mountain, Rotate3d, Satellite } from 'lucide-react'
import { Anchor, Bike, Footprints, Loader2, Map as MapIcon, MapPinPlus, Mountain, MountainSnow, Rotate3d, Satellite } from 'lucide-react'
import type { PaddleMapLayer } from '../Tours/paddle/paddleMapLayer'
import type { CSSProperties } from 'react'
import { PisteKeyButton } from '../Tours/winter/PisteKey'
import type { ComponentType, CSSProperties } from 'react'
import { useTranslation } from '../../i18n'
import { FerrataLineIcon } from '../Ferratas/FerrataGlyph'
import type { FerrataMapLayer } from '../Ferratas/useFerrataMapLayer'
@@ -193,17 +194,23 @@ function PlaceToolToggle({ tool }: { tool: MapPlaceTool }) {
)
}
/** How each overlay the planner can offer is named and drawn on its switch. */
const OVERLAY_LOOK: Record<string, { Icon: typeof Anchor; labelKey: string; downKey: string }> = {
seamarks: { Icon: Anchor, labelKey: 'tours.map.seamarks', downKey: 'tours.map.seamarksDown' },
/** How an overlay the planner can offer is named and drawn on its switch. */
interface OverlayLook {
Icon: typeof Anchor
labelKey: string
downKey: string
/** On its icon alone, named by its tooltip, so the row stays short beside a type's other switches. */
iconOnly?: boolean
/** The overlay's key, beside its switch while the layer shows. */
Key?: ComponentType
}
const OVERLAY_LOOK: Record<string, OverlayLook> = {
seamarks: { Icon: Anchor, labelKey: 'tours.map.seamarks', downKey: 'tours.map.seamarksDown' },
// SKI-01: a hike's row already holds four maps, the ferratas and 3D, so the pistes go by their icon.
pistes: { Icon: MountainSnow, labelKey: 'tours.map.pistes', downKey: 'tours.map.pistesDown', iconOnly: true, Key: PisteKeyButton },
}
/**
* The switch for a transparent overlay (the seamarks), the way the via
* ferrata switch looks: on in the accent, and in the warning tone with a badge
* once its source stopped answering, which the tooltip names. The map and the
* planning go on without it.
*/
/** The warning mark on a switch whose source stopped answering; the tooltip says what it means. */
function DownBadge() {
return (
@@ -213,6 +220,13 @@ function DownBadge() {
)
}
/**
* The switch for a transparent overlay (the seamarks, the pistes), the way the via
* ferrata switch looks: on in the accent, and in the warning tone with a badge
* once its source stopped answering, which the tooltip names. The map and the
* planning go on without it. An overlay with a key shows the key's button
* beside the switch while its tiles arrive.
*/
function OverlayToggle({ overlay, compact }: { overlay: ToggleableRasterOverlay; compact: boolean }) {
const { t } = useTranslation()
const look = OVERLAY_LOOK[overlay.id]
@@ -234,10 +248,11 @@ function OverlayToggle({ overlay, compact }: { overlay: ToggleableRasterOverlay;
style={segmentStyle(on)}
>
<look.Icon size={15} strokeWidth={2} />
{!compact && <span>{label}</span>}
{!compact && !look.iconOnly && <span>{label}</span>}
{down && <DownBadge />}
</button>
</Tooltip>
{look.Key && overlay.status === 'on' && <look.Key />}
<span role="status" aria-live="polite" className="sr-only">{down ? t(look.downKey) : ''}</span>
</>
)
@@ -23,6 +23,8 @@ function RasterOverlaysLeaflet({ overlays }: { overlays?: readonly MapRasterOver
maxNativeZoom={overlay.maxZoom}
maxZoom={22}
zIndex={OVERLAY_Z_INDEX}
// The page's origin as the referer, which the overlays' operators ask for (OpenSnowMap names it).
referrerPolicy="strict-origin-when-cross-origin"
eventHandlers={{ tileerror: overlay.onTileError, tileload: overlay.onTileLoad }}
/>
))}
@@ -1,11 +1,11 @@
import { describe, expect, it } from 'vitest';
import { baseLayerFor, tourMapLayersFor } from './tourMapLayers';
import { baseLayerFor, PISTE_OVERLAY, tourMapLayersFor } from './tourMapLayers';
describe('tourMapLayersFor (MAP-01)', () => {
it('offers OpenHikingMap to a hike only while the admin allows it', () => {
expect(tourMapLayersFor('hike').bases).not.toContain('hiking');
expect(tourMapLayersFor('hike', { hikingMap: true }).bases).toEqual(['default', 'topo', 'hiking', 'satellite']);
expect(tourMapLayersFor('hike', { hikingMap: true }).overlays).toEqual(['ferratas']);
expect(tourMapLayersFor('hike', { hikingMap: true }).overlays).toEqual(['ferratas', 'pistes']);
expect(tourMapLayersFor('kayak', { hikingMap: true }).bases).not.toContain('hiking');
expect(tourMapLayersFor(null, { hikingMap: true }).bases).not.toContain('hiking');
});
@@ -15,12 +15,27 @@ describe('tourMapLayersFor (MAP-01)', () => {
expect(baseLayerFor(tourMapLayersFor('hike'), 'hiking')).toBe('default');
});
it('SKI-02: a ski track gets the standard map, topo and satellite, and no via ferratas', () => {
it('SKI-02: a ski track gets the standard map, topo and satellite, the pistes and no via ferratas', () => {
expect(tourMapLayersFor('ski')).toEqual({
bases: ['default', 'topo', 'satellite'],
defaultBase: 'default',
overlays: [],
overlays: ['pistes'],
});
expect(baseLayerFor(tourMapLayersFor('ski'), 'hiking')).toBe('default');
});
it('SKI-01: the pistes are offered to a hike and a ski track, never to a bike tour, a run, a paddle tour or another type', () => {
expect(tourMapLayersFor('hike').overlays).toContain('pistes');
expect(tourMapLayersFor('ski').overlays).toContain('pistes');
for (const type of ['bike', 'run', 'kayak', 'walk', null] as const)
expect(tourMapLayersFor(type).overlays).not.toContain('pistes');
});
it("SKI-01: the piste layer is OpenSnowMap's overlay alone, from zoom 9 to 18, credited to OpenSnowMap and OpenStreetMap", () => {
expect(PISTE_OVERLAY.url).toBe('https://tiles.opensnowmap.org/pistes/{z}/{x}/{y}.png');
expect([PISTE_OVERLAY.minZoom, PISTE_OVERLAY.maxZoom]).toEqual([9, 18]);
expect(PISTE_OVERLAY.attribution).toContain('OpenSnowMap.org');
expect(PISTE_OVERLAY.attribution).toContain('CC BY-SA');
expect(PISTE_OVERLAY.attribution).toContain('OpenStreetMap');
});
});
+37 -6
View File
@@ -10,23 +10,27 @@ import type { TourBaseLayer } from '../Map/MapLayerSwitcher';
* laid over it and switched on its own; it is off until the user turns it on.
* Only sources TREK already ships or that a card cleared are listed: OpenTopoMap
* and the Esri imagery the planner had, OpenHikingMap (MAP-01), the via ferrata
* layer (RC-10) and OpenSeaMap's seamarks (PAD-10).
* layer (RC-10), OpenSeaMap's seamarks (PAD-10) and OpenSnowMap's pistes (SKI-01).
*
* - Hike: the standard map first, as before; topo, OpenHikingMap (MAP-01, while the admin
* allows it) and satellite beside it; via ferratas.
* allows it) and satellite beside it; via ferratas, and the pistes for winter hiking (SKI-01).
* - Bike (BIK-01): the standard map, topo for the climbs, CyclOSM (BIK-06, while the admin
* allows it) and satellite. No ferratas, a bike tour climbs none.
* - Run (RUN-01): the standard map, topo for the climbs and satellite. No ferratas, a run
* takes none.
* - Ski (SKI-02): the standard map, topo for the slopes and satellite. No ferratas.
* - Ski (SKI-02): the standard map, topo for the slopes and satellite. No ferratas. The
* pistes as an overlay (SKI-01).
* - Paddle: the standard map, whose water reads clearly, and satellite. No topo and
* no ferratas, those are hiking maps. Seamarks as an overlay.
* - Any other type (switched off, or one this build does not plan): the standard map
* and satellite, no overlays.
*
* The planner offers the pistes with no tour open too, so a ski area can be looked at
* without any route (useTourStageLayers decides that, as it does for the ferratas).
*
* If an overlay fails, the base map and the planning go on; the switch says so.
*/
type TourOverlayId = 'ferratas' | 'seamarks';
type TourOverlayId = 'ferratas' | 'seamarks' | 'pistes';
export interface TourMapLayerSet {
bases: readonly TourBaseLayer[];
@@ -37,13 +41,17 @@ export interface TourMapLayerSet {
const HIKE: TourMapLayerSet = {
bases: ['default', 'topo', 'satellite'],
defaultBase: 'default',
overlays: ['ferratas'],
overlays: ['ferratas', 'pistes'],
};
const HIKE_WITH_HIKING_MAP: TourMapLayerSet = { ...HIKE, bases: ['default', 'topo', 'hiking', 'satellite'] };
const BIKE: TourMapLayerSet = { bases: ['default', 'topo', 'satellite'], defaultBase: 'default', overlays: [] };
const BIKE_WITH_CYCLE_MAP: TourMapLayerSet = { ...BIKE, bases: ['default', 'topo', 'cycle', 'satellite'] };
const RUN: TourMapLayerSet = { bases: ['default', 'topo', 'satellite'], defaultBase: 'default', overlays: [] };
const SKI: TourMapLayerSet = { bases: ['default', 'topo', 'satellite'], defaultBase: 'default', overlays: [] };
const SKI: TourMapLayerSet = {
bases: ['default', 'topo', 'satellite'],
defaultBase: 'default',
overlays: ['pistes'],
};
const PADDLE: TourMapLayerSet = { bases: ['default', 'satellite'], defaultBase: 'default', overlays: ['seamarks'] };
const OTHER: TourMapLayerSet = { bases: ['default', 'satellite'], defaultBase: 'default', overlays: [] };
@@ -80,3 +88,26 @@ export const SEAMARK_OVERLAY = {
minZoom: 6,
maxZoom: 18,
} as const;
/**
* SKI-01: OpenSnowMap's transparent piste layer (pistes, cross-country trails,
* winter walking trails, toboggan runs and lifts as mapped in OpenStreetMap),
* only the overlay and never their relief or base maps, which are not cleared
* for use elsewhere. Tiles CC-BY-SA, data ODbL, both credited in the map's
* attribution. Their terms forbid bulk downloads: like every overlay it loads
* only the tiles in view, the tile prefetch and the Service Worker never store
* it, and the browser sends the page's origin as the referer, which the app's
* referrer policy (strict-origin-when-cross-origin) keeps. Checked on
* 20.10.2026: every tile answers 200 with a PNG, an empty one transparent, CORS
* open; nothing is drawn below zoom 9, and from zoom 19 the server answers a
* "No tile here" picture instead of a transparent tile, so the layer stops at
* 18 and the maps enlarge that zoom's tiles further in.
*/
export const PISTE_OVERLAY = {
id: 'pistes',
url: 'https://tiles.opensnowmap.org/pistes/{z}/{x}/{y}.png',
attribution:
'Pistes &copy; <a href="https://www.opensnowmap.org">OpenSnowMap.org</a> (<a href="https://creativecommons.org/licenses/by-sa/2.0/">CC BY-SA</a>), data &copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
minZoom: 9,
maxZoom: 18,
} as const;
@@ -0,0 +1,80 @@
// FE-TOUR-PISTE-KEY-001 to FE-TOUR-PISTE-KEY-005
import userEvent from '@testing-library/user-event';
import { describe, expect, it } from 'vitest';
import { fireEvent, render, screen, within } from '../../../../tests/helpers/render';
import { PisteKeyButton } from './PisteKey';
const trigger = () => screen.getByRole('button', { name: 'Piste key' });
const key = () => screen.queryByRole('group', { name: 'Piste key' });
describe('PisteKeyButton (SKI-01)', () => {
it('FE-TOUR-PISTE-KEY-001: the button carries the grade colours as its badge and opens nothing on its own', () => {
render(<PisteKeyButton />);
expect(trigger()).toHaveAttribute('aria-expanded', 'false');
expect(trigger().querySelectorAll('span[style]')).toHaveLength(4);
expect(key()).toBeNull();
});
it('FE-TOUR-PISTE-KEY-002: opened, the key names every downhill grade and the other winter ways the layer draws', async () => {
render(<PisteKeyButton />);
await userEvent.click(trigger());
const panel = key();
expect(panel).toBeInTheDocument();
expect(trigger()).toHaveAttribute('aria-expanded', 'true');
expect(trigger()).toHaveAttribute('aria-controls', panel?.id);
expect(within(panel as HTMLElement).getByText('Downhill runs by difficulty')).toBeInTheDocument();
const grades = within(screen.getByTestId('piste-key-grades')).getAllByRole('listitem');
expect(grades.map((grade) => grade.textContent)).toEqual([
'Novice',
'Easy',
'Intermediate',
'Advanced',
'Expert',
'Freeride',
]);
const ways = within(screen.getByTestId('piste-key-ways')).getAllByRole('listitem');
expect(ways.map((way) => way.textContent)).toEqual([
'Cross-country trails',
'Winter and snowshoe trails',
'Toboggan runs',
'Lifts and cable cars',
]);
// Winter walking trails are dotted, as on the map; the other trails are lines.
expect(ways[1]?.querySelectorAll('span[style]')).toHaveLength(3);
expect(ways[0]?.querySelectorAll('span[style]')).toHaveLength(1);
expect(within(panel as HTMLElement).getByText('OpenSnowMap')).toBeInTheDocument();
});
it('FE-TOUR-PISTE-KEY-003: the key says the colours are mapped data and no report on opening, grooming, snow or avalanches', async () => {
render(<PisteKeyButton />);
await userEvent.click(trigger());
expect(
screen.getByText(
'Mapped data, not a live report: it says nothing about what is open or groomed, the snow or avalanches.'
)
).toBeInTheDocument();
});
it('FE-TOUR-PISTE-KEY-004: the full key opens at OpenSnowMap in a new tab and takes the focus when the key opens', async () => {
render(<PisteKeyButton />);
await userEvent.click(trigger());
const link = screen.getByRole('link', { name: 'Full key at OpenSnowMap' });
expect(link).toHaveAttribute('href', 'https://www.opensnowmap.org/');
expect(link).toHaveAttribute('target', '_blank');
expect(link).toHaveAttribute('rel', 'noopener noreferrer');
expect(link).toHaveFocus();
});
it('FE-TOUR-PISTE-KEY-005: Escape and a click beside it close the key and leave the button', async () => {
render(<PisteKeyButton />);
await userEvent.click(trigger());
await userEvent.keyboard('{Escape}');
expect(key()).toBeNull();
expect(trigger()).toHaveFocus();
await userEvent.click(trigger());
expect(key()).toBeInTheDocument();
fireEvent.mouseDown(document.body);
expect(key()).toBeNull();
});
});
@@ -0,0 +1,173 @@
import { CableCar, ExternalLink, Info } from 'lucide-react';
import { useEffect } from 'react';
import { useTranslation } from '../../../i18n';
import { SoftPill } from '../../Planner/planParts';
import { fs } from '../../shared/DialogShell';
import { LABEL, PopoverListPanel } from '../../shared/dialogParts';
import { Tooltip } from '../../shared/Tooltip';
import { usePopoverList } from '../../shared/usePopoverList';
import { TourNotice } from '../tourParts';
/**
* SKI-01: OpenSnowMap's own paint, read off its map key (opensnowmap.org,
* pics/mapkey_wide.png) on 20.10.2026. The key repeats what the tiles draw, so
* these keep their colours in every theme, as the map under them does.
*/
const PAINT = {
novice: '#41d83e',
easy: '#2949ca',
intermediate: '#d51e1e',
advanced: '#313131',
expert: '#f37300',
freeride: '#f3ce00',
nordic: '#3960ff',
winterHike: '#f07bbd',
sled: '#8bff44',
} as const;
type Paint = keyof typeof PAINT;
/** The grades a downhill run is coloured by, as OpenStreetMap's piste:difficulty names them. */
const DOWNHILL: readonly { paint: Paint; labelKey: string }[] = [
{ paint: 'novice', labelKey: 'tours.map.pisteGrade.novice' },
{ paint: 'easy', labelKey: 'tours.map.pisteGrade.easy' },
{ paint: 'intermediate', labelKey: 'tours.map.pisteGrade.intermediate' },
{ paint: 'advanced', labelKey: 'tours.map.pisteGrade.advanced' },
{ paint: 'expert', labelKey: 'tours.map.pisteGrade.expert' },
{ paint: 'freeride', labelKey: 'tours.map.pisteGrade.freeride' },
];
/** The other winter ways the layer draws, each in its one colour; winter walking trails dotted, as on the map. */
const WAYS: readonly { paint: Paint; labelKey: string; dotted?: boolean }[] = [
{ paint: 'nordic', labelKey: 'tours.map.pisteNordic' },
{ paint: 'winterHike', labelKey: 'tours.map.pisteWinterHike', dotted: true },
{ paint: 'sled', labelKey: 'tours.map.pisteSled' },
];
/** The four grades the key's button shows as its badge, the colours a skier knows first. */
const BADGE_GRADES: readonly Paint[] = ['novice', 'easy', 'intermediate', 'advanced'];
/** Where the full key lives: OpenSnowMap's own map, whose menu holds it with the rarer ways and marks. */
const FULL_KEY_URL = 'https://www.opensnowmap.org/';
/** A downhill run as the tiles draw it: a pale band edged in its grade's colour, readable on light and dark alike. */
function RunBand({ colour }: { colour: string }) {
return (
<span
aria-hidden
className="h-2.5 w-6 flex-none rounded-[3px] border-[1.5px]"
style={{ borderColor: colour, background: `color-mix(in srgb, ${colour} 22%, white)` }}
/>
);
}
/** A trail as a line in its colour, or as a row of dots where the map dots it. */
function WayLine({ colour, dotted = false }: { colour: string; dotted?: boolean }) {
if (!dotted) return <span aria-hidden className="h-[3px] w-6 flex-none rounded-full" style={{ background: colour }} />;
return (
<span aria-hidden className="flex w-6 flex-none items-center justify-between px-px">
{[0, 1, 2].map((dot) => (
<span key={dot} className="h-[5px] w-[5px] rounded-full" style={{ background: colour }} />
))}
</span>
);
}
const ROW = 'flex min-w-0 items-center gap-2 text-content-secondary';
/** The key's content: the downhill grades, the other ways, what the colours do not say, and where the full key is. */
function PisteKeyBody() {
const { t } = useTranslation();
return (
<div className="flex flex-col gap-3 p-1.5">
<div className="flex items-center justify-between gap-2">
<span className="font-semibold text-content" style={fs(12.5, 'body')}>
{t('tours.map.pisteKey')}
</span>
<SoftPill>OpenSnowMap</SoftPill>
</div>
<div>
<span className={LABEL}>{t('tours.map.pisteDownhill')}</span>
<ul className="grid grid-cols-2 gap-x-3 gap-y-1.5" data-testid="piste-key-grades">
{DOWNHILL.map(({ paint, labelKey }) => (
<li key={paint} className={ROW} style={fs(11.5, 'body')}>
<RunBand colour={PAINT[paint]} />
<span className="truncate">{t(labelKey)}</span>
</li>
))}
</ul>
</div>
<ul className="flex flex-col gap-1.5 border-t border-edge-faint pt-3" data-testid="piste-key-ways">
{WAYS.map(({ paint, labelKey, dotted }) => (
<li key={paint} className={ROW} style={fs(11.5, 'body')}>
<WayLine colour={PAINT[paint]} dotted={dotted} />
<span className="truncate">{t(labelKey)}</span>
</li>
))}
<li className={ROW} style={fs(11.5, 'body')}>
<span aria-hidden className="flex w-6 flex-none justify-center text-content">
<CableCar size={14} strokeWidth={2} />
</span>
<span className="truncate">{t('tours.map.pisteLift')}</span>
</li>
</ul>
<TourNotice icon={<Info size={12} strokeWidth={2} />}>{t('tours.map.pisteStatic')}</TourNotice>
<a
href={FULL_KEY_URL}
target="_blank"
rel="noopener noreferrer"
className="inline-flex items-center gap-1 self-start font-semibold text-accent-on hover:underline"
style={fs(11.5, 'body')}
>
{t('tours.map.pisteFullKey')}
<ExternalLink size={11} strokeWidth={2.2} aria-hidden />
</a>
</div>
);
}
/**
* SKI-01: the piste layer's key, opened from a button beside its switch while
* the layer shows. The button carries the grade colours as a small badge, so
* it reads as the key at a glance; the key itself opens above the map in the
* popover look and closes on Escape or a click beside it, the map untouched.
*/
export function PisteKeyButton() {
const { t } = useTranslation();
const list = usePopoverList(-1, { estimatedHeight: 380 });
const { open, box, toggle, triggerRef, menuRef, listId } = list;
const label = t('tours.map.pisteKey');
const shown = open && !!box;
// No list to walk here, only the link: opening moves the focus onto it, so Tab and Escape act as in any popover.
useEffect(() => {
if (shown) menuRef.current?.querySelector('a')?.focus({ preventScroll: true });
}, [shown, menuRef]);
return (
<>
<Tooltip label={label} placement="top" disabled={open}>
<button
ref={triggerRef}
type="button"
onClick={toggle}
aria-label={label}
aria-expanded={open}
aria-controls={open ? listId : undefined}
data-testid="piste-key-button"
className={`grid h-[34px] w-[34px] flex-none place-items-center rounded-full transition-colors hover:bg-surface-hover ${open ? 'bg-surface-hover' : ''}`}
>
<span
aria-hidden
className="grid grid-cols-2 gap-[2px] rounded-[5px] bg-surface-card p-[3px] shadow-sm ring-1 ring-edge"
>
{BADGE_GRADES.map((paint) => (
<span key={paint} className="h-[5px] w-[5px] rounded-full" style={{ background: PAINT[paint] }} />
))}
</span>
</button>
</Tooltip>
<PopoverListPanel list={list} label={label} className="w-[272px]">
<PisteKeyBody />
</PopoverListPanel>
</>
);
}