Files
TREK/client/src/components/Map/DawarichTrailLayer.tsx
T
Maurice 51af575c9a fix(map): keep places and routes on one world, and start new installs with Journey and Collections
A right-click, click or drag on a repeated world copy reported the longitude it
has on that copy (274.9 for -85.1). The place was saved there, the geocoder
found nothing, and a route to a place on the real world ran across the whole
map (#2976). Longitudes are now brought back onto [-180, 180] where the map
hands them out (Leaflet and GL), where they are stored (places, booking
endpoints, collection places, so REST, MCP, plugin RPC and importers alike)
and before reverse geocoding. A migration moves the ones already stored.

Leaflet draws a layer at its literal longitude only, so a trip from Los
Angeles to Auckland had its pins at opposite ends of the world while the
flight ran off the edge to the next copy (#2975). A trip that crosses the
antimeridian is now drawn in one longitude frame, seamed in the widest
stretch it leaves empty, so pins, routes, flights and every overlay lie on
one copy and the map opens across the Pacific. Every other trip has no frame
and draws exactly as before. The GL day fit also takes the short way.

A new install now starts with Journey and Collections switched on, next to
the trip addons (all but Road trip), Atlas, Vacay and the Naver import that
already were. Existing installs keep their addons as they are.

Closes #2975
Closes #2976
2026-11-04 10:56:36 +01:00

87 lines
3.0 KiB
TypeScript

import { useMemo } from 'react'
import { Polyline } from 'react-leaflet'
import { useLngFrame } from './lngFrameContext'
import { frameLine } from '../../utils/lngFrame'
import type { DawarichTrack } from '@trek/shared'
import {
DAWARICH_TRAIL_CASING,
trailSegments,
type DawarichTrailSegment,
} from './dawarichTrail'
/**
* The recorded route on the Leaflet renderer.
*
* Three lines per segment, the same construction the GPX tracks next door use:
* a white casing so the line survives a satellite tile, the coloured line
* itself, and nothing on top — this overlay is not clickable. That last part is
* deliberate: a fat invisible hit-line would sit over the places and the
* planned route, and swallow the clicks that select them, in exchange for a
* popup nobody asked for.
*
* Dashed rather than solid. The planned route is already a solid line in the
* user's accent, and the whole point of this layer is to be visibly the other
* thing — what actually happened, next to what was planned. Telling them apart
* has to survive being printed, screenshotted and looked at by someone who
* cannot distinguish the two hues.
*/
export default function DawarichTrailLayer({
track,
selectedDate,
hiddenDates,
casingPane,
}: {
track: DawarichTrack | null
/** When set, only that local day is drawn. */
selectedDate?: string | null
/** Local dates whose day is folded away in the day plan. */
hiddenDates?: ReadonlySet<string> | null
/** The `trek-track-casing` pane, when the renderer supports panes. */
casingPane?: string
}) {
const frame = useLngFrame()
// Drawn in the map's longitude frame, with the trip it was recorded on (#2975).
const segments = useMemo(() => trailSegments(track, selectedDate, hiddenDates)
.map(segment => (frame ? { ...segment, points: frameLine(frame, segment.points) } : segment)), [track, selectedDate, hiddenDates, frame])
if (segments.length === 0) return null
return (
<>
{segments.map((segment: DawarichTrailSegment) => (
<Polyline
key={`dawarich-casing-${segment.id}`}
positions={segment.points}
pane={casingPane}
// theme-lint-disable — map paint
pathOptions={{
color: DAWARICH_TRAIL_CASING,
weight: 6,
opacity: 0.55,
lineCap: 'round',
lineJoin: 'round',
}}
interactive={false}
/>
))}
{/* pathOptions rather than bare props: react-leaflet only calls setStyle
when the pathOptions reference changes, so a bare `color` would stick
at its mount-time value and a day recolour would never arrive. */}
{segments.map((segment: DawarichTrailSegment) => (
<Polyline
key={`dawarich-line-${segment.id}`}
positions={segment.points}
pathOptions={{
color: segment.color,
weight: 3,
opacity: 0.85,
dashArray: '6 5',
lineCap: 'round',
lineJoin: 'round',
}}
interactive={false}
/>
))}
</>
)
}