-
-
Notifications
You must be signed in to change notification settings - Fork 128
Expand file tree
/
Copy pathMapIndexLayer.tsx
More file actions
71 lines (67 loc) · 2.02 KB
/
Copy pathMapIndexLayer.tsx
File metadata and controls
71 lines (67 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { NorthEast } from '@mui/icons-material'
import { Link as MuiLink } from '@mui/material'
import type { TFunction } from 'i18next'
import type { ReactNode } from 'react'
import { useTranslation } from 'react-i18next'
import { Link } from 'react-router'
import type { PositionGroup } from '../map-types'
import {
actualRouteStopMarkerPath,
plannedRouteLineColor,
plannedRouteStopMarkerPath,
} from '../MapContent'
import { MapIndex } from '../MapIndex'
interface MapIndexLayerProps {
showPlannedRoute?: boolean
positionGroups?: PositionGroup[]
}
function vehicleSubtitle(group: PositionGroup, t: TFunction): ReactNode {
if (!group.label) return undefined
const number = group.vehicleRef ? (
<MuiLink
component={Link}
to={`/vehicle?vehicle.vehicleNumber=${group.vehicleRef}`}
reloadDocument
underline="hover"
title={t('go_to_vehicle_page')}
sx={{ display: 'inline-flex', alignItems: 'center', gap: 0.25 }}>
{group.label}
{/* arrow hints the number is a link to the vehicle page; decorative for a11y */}
<NorthEast aria-hidden sx={{ fontSize: '1em' }} />
</MuiLink>
) : (
group.label
)
return (
<bdi>
{'('}
{number}
{')'}
</bdi>
)
}
export function MapIndexLayer({ showPlannedRoute, positionGroups = [] }: MapIndexLayerProps) {
const { t } = useTranslation()
return (
<div className="map-index">
{showPlannedRoute && (
<MapIndex
lineColor={plannedRouteLineColor}
imgSrc={plannedRouteStopMarkerPath}
title={t('plannedRoute')}
/>
)}
{/* The actual-route entry appears only once a ride is selected (positionGroups
populated); before that the legend shows just the planned route. */}
{positionGroups.map((group, idx) => (
<MapIndex
key={idx}
lineColor={group.color}
imgSrc={actualRouteStopMarkerPath}
title={t('actualRoute')}
subtitle={vehicleSubtitle(group, t)}
/>
))}
</div>
)
}