forked from OurHike/OurHike
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapScreen.tsx
More file actions
167 lines (150 loc) · 4.62 KB
/
Copy pathMapScreen.tsx
File metadata and controls
167 lines (150 loc) · 4.62 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// The map screen shell (WIREFRAMES.md §1), stacking the pieces top to bottom.
//
// Still to slot in: the elevation ribbon and the three waypoint lanes (D8), and
// the legend bottom sheet (D7). They are left out rather than stubbed, so the
// gap stays visible instead of hiding behind an empty placeholder.
//
// Attribution is rendered here rather than by MapLibre's own control, because
// WIREFRAMES.md positions it bottom-left beneath the scale bar. USGS topo is
// public domain; OpenStreetMap is ODbL and its credit is a licence condition,
// so this element is not optional and is not behind a prop.
import { StatusStrip } from './StatusStrip'
import { Header, type HikeDirection } from './Header'
import { TabBar } from './TabBar'
import type { TabId } from './tabs'
import { Legend, type BlazeCount } from './Legend'
import { Search } from './Search'
import { ElevationRibbon, type ElevationRibbonProps } from './ElevationRibbon'
import { WaypointLanes, type WaypointLanesProps } from './WaypointLanes'
import type { Map as MapLibreMap } from 'maplibre-gl'
import { MapView } from '../map/MapView'
import { ATTRIBUTION } from '../map/style'
import type { ScaleUnits } from '../map/mapChrome'
import type { BoundingBox, MapPoint } from '../lib/legendContents'
import type { SearchablePoi } from '../lib/searchPoi'
import './chrome.css'
export interface MapScreenProps {
topoArchiveUrl: string
trailsUrl: string
trailName: string
// All three are omitted until they are actually known - see HeaderProps.
state?: string
mile?: number
direction?: HikeDirection
time: Date
online: boolean
hasGpsFix: boolean
lastSyncedAt: Date | null
activeTab: TabId
onSelectTab: (id: TabId) => void
onOpenLegend: () => void
onOpenSearch: () => void
legendOpen: boolean
onCloseLegend: () => void
// Search takes over the header rather than sitting beside it
// (WIREFRAMES.md Interactions), so the shell owns whether it is showing.
searchOpen: boolean
onCloseSearch: () => void
searchablePois: SearchablePoi[]
onSelectSearchResult: (poi: SearchablePoi) => void
bbox: BoundingBox
viewportPoints: MapPoint[]
blazeCounts: BlazeCount[]
hiddenTypes: Set<string>
onToggleType: (type: string) => void
// Both are optional and both are omitted rather than stubbed when their data
// isn't there. An empty ribbon or a bare set of lanes would read as "nothing
// ahead of you," which is a different and much worse claim than "we don't
// have the profile for this stretch."
elevation?: ElevationRibbonProps
waypoints?: WaypointLanesProps
showZoomButtons?: boolean
units?: ScaleUnits
/** Opening camera only; later moves are the hiker's. */
center?: [number, number]
onViewportChange?: (bbox: BoundingBox) => void
onMapReady?: (map: MapLibreMap | null) => void
}
export function MapScreen({
topoArchiveUrl,
trailsUrl,
trailName,
state,
mile,
direction,
time,
online,
hasGpsFix,
lastSyncedAt,
activeTab,
onSelectTab,
onOpenLegend,
onOpenSearch,
legendOpen,
onCloseLegend,
searchOpen,
onCloseSearch,
searchablePois,
onSelectSearchResult,
bbox,
viewportPoints,
blazeCounts,
hiddenTypes,
onToggleType,
elevation,
waypoints,
showZoomButtons = false,
units = 'imperial',
center,
onViewportChange,
onMapReady,
}: MapScreenProps) {
return (
<div className="map-screen">
<StatusStrip
time={time}
online={online}
hasGpsFix={hasGpsFix}
lastSyncedAt={lastSyncedAt}
/>
<Header
trailName={trailName}
state={state}
mile={mile}
direction={direction}
onOpenLegend={onOpenLegend}
onOpenSearch={onOpenSearch}
/>
{elevation && <ElevationRibbon {...elevation} />}
{waypoints && <WaypointLanes {...waypoints} />}
<div className="map-screen__canvas">
<MapView
topoArchiveUrl={topoArchiveUrl}
trailsUrl={trailsUrl}
showZoomButtons={showZoomButtons}
units={units}
center={center}
onViewportChange={onViewportChange}
onMapReady={onMapReady}
/>
<p className="map-screen__attribution">{ATTRIBUTION}</p>
<Search
open={searchOpen}
pois={searchablePois}
onSelect={onSelectSearchResult}
onClose={onCloseSearch}
/>
</div>
<Legend
open={legendOpen}
bbox={bbox}
points={viewportPoints}
blazeCounts={blazeCounts}
hiddenTypes={hiddenTypes}
onToggleType={onToggleType}
onClose={onCloseLegend}
/>
<TabBar active={activeTab} onSelect={onSelectTab} />
</div>
)
}