feat(maps): draw every travel day's route at once, with the trip total

Extract the day route builder out of useRouteCalculation into a pure module and
aggregate it over the whole trip: one map with every day's route, each day in its
own colour, the mode per stage and the trip's total distance. Straight lines first,
roads as they answer; a refused leg keeps its line and adds no distance.

Give the floating map controls one shared drop shadow while adding the toggle, so
the new pill and the base-layer switcher stand off the tiles the way the locate
button always has. Document the control in wiki/Map-Features.md.

Addresses #1736
This commit is contained in:
Konstantinos Thermos
2026-09-10 15:57:48 +03:00
parent 8acfaea3c4
commit bf1900c3a0
43 changed files with 1095 additions and 192 deletions
+29 -3
View File
@@ -6,6 +6,7 @@ import { useCanDo } from '../store/permissionsStore'
import { useSettingsStore } from '../store/settingsStore'
import { MapViewAuto as MapView } from '../components/Map/MapViewAuto'
import { MapCompassPill, type CompassMap } from '../components/Map/MapCompassPill'
import { TripRouteOverviewPill, TripRouteOverviewPanel } from '../components/Map/TripRouteOverview'
import { getCached, fetchPhoto } from '../services/photoService'
import DayPlanSidebar from '../components/Planner/DayPlanSidebar'
import RoadtripModeSwitch from '../components/Roadtrip/RoadtripModeSwitch'
@@ -252,6 +253,7 @@ function TripPlannerPageDesktop(): React.ReactElement | null {
pushUndo, undo, canUndo, lastActionLabel, handleUndo,
enabledAddons, collabFeatures, tripAccommodations, setTripAccommodations,
roadtripMode, toggleRoadtripMode, roadtripActive, roadtripRoutes, roadtripCorridor,
overviewActive, tripOverview, toggleOverview, overviewShown,
followTrack, roadtripViaCounts,
allowedFileTypes, tripMembers, setTripMembers, refreshMembers, loadAccommodations,
TRANSPORT_TYPES, TRIP_TABS, activeTab, setActiveTab, handleTabChange,
@@ -326,6 +328,7 @@ function TripPlannerPageDesktop(): React.ReactElement | null {
// page level so it has tripMembers / base currency / current user available.
const meId = useAuthStore(s => s.user?.id ?? -1)
const displayCurrency = useSettingsStore(s => s.settings.default_currency)
const distanceUnit = useSettingsStore(s => s.settings.distance_unit)
const costsBase = (displayCurrency || trip?.currency || 'EUR').toUpperCase()
// Transit search departs against a real date, so the whole Automated mode —
// the day-header tram button and the modal's mode switch — is off without one.
@@ -396,7 +399,8 @@ function TripPlannerPageDesktop(): React.ReactElement | null {
tripId={tripId}
places={mapPlaces}
dayPlaces={dayPlaces}
route={roadtripActive ? roadtripRoutes.lines : route}
route={roadtripActive ? roadtripRoutes.lines : overviewActive ? tripOverview.lines : route}
routeColors={overviewActive ? tripOverview.lineColors : undefined}
routeVias={roadtripActive ? roadtripRoutes.vias : routeVias}
accessLines={roadtripActive ? roadtripRoutes.accessLines : undefined}
showTransitRoutes={transitRoutesShown}
@@ -404,7 +408,7 @@ function TripPlannerPageDesktop(): React.ReactElement | null {
// know which automated transports may ride it (#2019).
days={days}
selectedDayId={selectedDayId}
routeSegments={roadtripActive ? roadtripRoutes.segments : routeSegments}
routeSegments={roadtripActive ? roadtripRoutes.segments : overviewActive ? tripOverview.segments : routeSegments}
selectedPlaceId={selectedPlaceId}
onMarkerClick={handleMarkerClick}
onMapClick={handleMapClick}
@@ -439,7 +443,7 @@ function TripPlannerPageDesktop(): React.ReactElement | null {
onRouteClick={roadtripActive && can('day_edit', trip) ? addRoadtripVia : undefined}
roadtripVias={roadtripActive ? roadtripVias.byDay : undefined}
alternativeRoutes={alternativeOverlays}
focusPoints={alternativeFocusPoints}
focusPoints={overviewActive ? tripOverview.focusPoints : alternativeFocusPoints}
clusterLoosely={roadtripActive}
activeAlternative={highlightedAlternative}
onChooseAlternative={chooseRouteAlternative}
@@ -466,6 +470,28 @@ function TripPlannerPageDesktop(): React.ReactElement | null {
</div>
)}
{/* Bottom-RIGHT. Not the top corridor between the panels, which is already
contested by the POI bar and the collapse tabs (#2247); and not the
bottom-left corner, where Leaflet's base-layer switcher sits at
z-index 1000 and would cover this. The right corner is free on both
renderers — the locate button that lives there is phone-only. */}
{!roadtripActive && (
<div className="hidden md:flex" style={{
position: 'absolute', bottom: 18, right: mapInsetRight + 14, zIndex: 26,
pointerEvents: 'none', flexDirection: 'column', alignItems: 'flex-end', gap: 8,
}}>
{overviewActive && (
<TripRouteOverviewPanel
overview={tripOverview}
unit={distanceUnit}
selectedDayId={selectedDayId}
onSelectDay={handleSelectDay}
/>
)}
<TripRouteOverviewPill active={overviewShown} onToggle={toggleOverview} />
</div>
)}
{(poiPillEnabled || glMap) && (
<div className="hidden md:flex" style={{
position: 'absolute', top: 14,
@@ -449,7 +449,9 @@ describe('TripPlannerPage — plan tab', () => {
it('FE-PAGE-TPW-013: the collapse buttons toggle each side panel', () => {
renderPage()
const [leftBtn, rightBtn] = screen.getAllByRole('button')
// By name, not by position: the map layer carries controls of its own, so the
// tabs are not simply the first two buttons on the page.
const [leftBtn, rightBtn] = screen.getAllByLabelText('common.collapse')
fireEvent.click(leftBtn)
expect(hookState.toggleLeft).toHaveBeenCalled()
@@ -466,9 +468,8 @@ describe('TripPlannerPage — plan tab', () => {
// announce themselves with nothing but a hover colour (#2247).
it('FE-PAGE-TPW-013b: each collapse tab is named for what it does', () => {
renderPage({ leftHidden: true, rightHidden: false })
const [leftBtn, rightBtn] = screen.getAllByRole('button')
expect(leftBtn).toHaveAttribute('aria-label', 'trip.mobilePlan')
expect(rightBtn).toHaveAttribute('aria-label', 'common.collapse')
expect(screen.getByLabelText('trip.mobilePlan')).toBeInTheDocument()
expect(screen.getByLabelText('common.collapse')).toBeInTheDocument()
})
// At a foldable's ~860px the viewport centre sits under the Places panel, so the
@@ -485,6 +486,17 @@ describe('TripPlannerPage — plan tab', () => {
expect(cluster.style.left).toBe('calc(350px + 0.5 * (100% - 350px - 0px))')
})
// Leaflet's base-layer switcher owns the bottom-LEFT corner at z-index 1000, so an
// overview control placed there is simply covered by it (#1736).
it('FE-PAGE-TPW-013d: the trip-overview control hugs the right edge, clear of the layer switcher', () => {
renderPage()
const stack = screen.getByTestId('trip-overview-pill').closest('[style*="position: absolute"]') as HTMLElement
expect(stack).not.toBeNull()
expect(stack.style.right).not.toBe('')
expect(stack.style.left).toBe('')
})
it('FE-PAGE-TPW-014: a collapsed panel keeps its toggle but drops the hover highlight', () => {
renderPage({ leftHidden: true, rightHidden: true })
@@ -21,6 +21,7 @@ import { useAuthStore } from '../../store/authStore'
import { useResizablePanels } from '../../hooks/useResizablePanels'
import { useTripWebSocket } from '../../hooks/useTripWebSocket'
import { useRouteCalculation } from '../../hooks/useRouteCalculation'
import { useTripRouteOverview } from '../../components/Map/useTripRouteOverview'
import { useRoadtripRoutes } from '../../components/Roadtrip/useRoadtripRoutes'
import { useRoadtripCorridor } from '../../components/Roadtrip/useRoadtripCorridor'
import { useRoadtripVias } from '../../components/Roadtrip/useRoadtripVias'
@@ -364,6 +365,17 @@ export function useTripPlanner() {
// transport in the trip (#2019).
const transitRoutesShown = routeShown && selectedDayId != null
const [routeProfile, setRouteProfile] = useState<string>('driving')
// Whole-trip route overview (#1736): every day's route at once, each in its own
// colour. Per trip and per session like road trip mode — it answers "what does the
// whole thing look like", which is a question you ask of one trip, not a preference.
const [overviewShown, setOverviewShown] = useState<boolean>(() => sessionStorage.getItem(`trip-overview-${tripId}`) === '1')
const toggleOverview = useCallback(() => {
setOverviewShown(prev => {
const next = !prev
sessionStorage.setItem(`trip-overview-${tripId}`, next ? '1' : '0')
return next
})
}, [tripId])
const [fitKey, setFitKey] = useState<number>(0)
const initialFitTripId = useRef<number | null>(null)
const [mobileSidebarOpen, setMobileSidebarOpen] = useState<'left' | 'right' | null>(null)
@@ -534,6 +546,10 @@ export function useTripPlanner() {
}, [places, placesCategoryFilter, placesFilter, assignments, expandedDayIds, selectedDayId, days, tripAccommodations, reservations])
const { route, routeSegments, routeVias, routeInfo, setRoute, setRouteInfo, updateRouteForDay } = useRouteCalculation({ assignments } as any, selectedDayId, routeShown, routeProfile, tripAccommodations)
// Road trip mode already draws the whole trip its own way, so the overview stands
// down there rather than drawing a second set of lines over it.
const overviewActive = overviewShown && !roadtripMode
const tripOverview = useTripRouteOverview(tripId, days, assignments, reservations, tripAccommodations, routeProfile, overviewActive)
// Road trip mode reads the whole trip, not the selected day, so it owns its own legs.
// Passing no days while the mode is off keeps it inert — no routing requests, no state.
@@ -1785,6 +1801,7 @@ export function useTripPlanner() {
pushUndo, undo, canUndo, lastActionLabel, handleUndo,
enabledAddons, collabFeatures, tripAccommodations, setTripAccommodations,
roadtripMode, toggleRoadtripMode, roadtripActive, roadtripRoutes, roadtripCorridor,
overviewShown, toggleOverview, overviewActive, tripOverview,
followTrack, roadtripViaCounts,
allowedFileTypes, tripMembers, setTripMembers, refreshMembers, loadAccommodations,
TRANSPORT_TYPES, TRIP_TABS, activeTab, setActiveTab, handleTabChange,