mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-06-19 13:21:46 +00:00
f8eb1915fe
ReservationOverlay was Leaflet-only: react-leaflet components, L.divIcon, panes, useMap/useMapEvents. When the user switched the planner map to Mapbox GL, the entire feature disappeared — no polylines, no endpoint badges, no clickable IATA labels. Add a matching overlay for the Mapbox renderer: - New reservationsMapbox.ts with an imperative `ReservationMapboxOverlay` class — mapbox-gl is imperative, so a React component wrapper would fight its own lifecycle every render. The manager owns one GeoJSON source + line layer for the arcs, one HTML `mapboxgl.Marker` per endpoint badge, and one per flight stats label. It cleans itself up when the map is rebuilt (style/token/3d toggle) or unmounted. - Geometry helpers (great-circle arc, antimeridian split, haversine, tz-aware duration math, label formatting) are copied from the Leaflet overlay so both renderers produce the same lines. Great-circle is useful even on the Mapbox globe because the mercator projection mode still draws the short-way line, and the antimeridian split prevents a NYC↔Tokyo flight from wrapping halfway around the planet. - Flights / cruises get geodesic arcs; trains / cars get straight lines. All four types get clickable endpoint badges with the matching lucide icon; only flights render the rotating mid-arc stats label (IATA → IATA · distance · duration) — same rule as the Leaflet overlay. - The stats label's rotation is recomputed on every `render` event by projecting two points straddling the arc midpoint, which keeps it parallel to the arc as the camera rotates/zooms on the globe. - Visibility thresholds mirror the Leaflet overlay (per-type min pixel distance before a line / endpoint label is worth drawing). - MapViewGL now accepts the `reservations`, `visibleConnectionIds`, `showReservationStats`, `onReservationClick` props that the Leaflet MapView already took. `visibleConnectionIds` is honoured the same way — the per-booking toggle in DayPlanSidebar controls which routes appear, so switching the renderer doesn't lose that UX. - Added a `mapReady` gate so the overlay can only add its source/layer once the map's `load` handler has attached the other trip sources; the gate resets on every style rebuild.