-
-
Notifications
You must be signed in to change notification settings - Fork 128
Expand file tree
/
Copy pathindex.tsx
More file actions
133 lines (121 loc) · 4.75 KB
/
Copy pathindex.tsx
File metadata and controls
133 lines (121 loc) · 4.75 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
import { OpenInFullRounded } from '@mui/icons-material'
import { Alert, CircularProgress, IconButton, Stack } from '@mui/material'
import React, { useCallback, useContext, useRef, useState } from 'react'
import { MapContainer, TileLayer } from 'react-leaflet'
import dayjs from 'src/dayjs'
import { useConstrainedFloatingButton } from 'src/hooks/useConstrainedFloatingButton'
import { SearchContext } from '../../model/pageState'
import { DateNavigator } from '../components/dateNavigator/DateNavigator'
import { DateSelector } from '../components/DateSelector'
import { VelocityHeatmapLegend } from './components/VelocityHeatmapLegend'
import { VelocityHeatmapRectangles } from './components/VelocityHeatmapRectangles'
const VIS_MODES = [
{ key: 'avg', label: 'Visualize Avg Speed' },
{ key: 'std', label: 'Visualize Std' },
{ key: 'cv', label: 'Visualize Std / Avg Speed (Coeff of Var)' },
]
const DEFAULT_ZOOM_LEVEL = 10
const VelocityHeatmapPage: React.FC = () => {
const [isExpanded, setIsExpanded] = useState<boolean>(false)
const toggleExpanded = useCallback(() => setIsExpanded((expanded) => !expanded), [])
const { search, setSearch } = useContext(SearchContext)
const [visMode, setVisMode] = useState<'avg' | 'std' | 'cv'>('avg')
const [min, setMin] = useState(0)
const [max, setMax] = useState(1)
const [isLoading, setIsLoading] = useState(false)
const [errorMessage, setErrorMessage] = useState<string | null>(null)
const mapContainerRef = useRef<HTMLDivElement>(null)
const buttonRef = useRef<HTMLButtonElement>(null)
const handleTimestampChange = (time: dayjs.Dayjs | null) => {
setSearch((current) => ({ ...current, timestamp: time?.valueOf() ?? +new Date('2026-01-01') }))
}
useConstrainedFloatingButton(mapContainerRef, buttonRef, isExpanded)
return (
<div>
<h1>Velocity Aggregation Heatmap</h1>
<p>This page will display a heatmap of velocity aggregation data.</p>
{/* choose date*/}
<Stack direction="column" spacing={2} sx={{ mb: 2, width: { xs: '100%', md: '70%' } }}>
<DateSelector time={dayjs(search.timestamp)} onChange={handleTimestampChange} />
<DateNavigator currentTime={dayjs(search.timestamp)} onChange={handleTimestampChange} />
</Stack>
<div style={{ margin: '12px 0' }}>
<b>Visualization:</b>{' '}
{VIS_MODES.map((mode) => (
<label key={mode.key} style={{ marginRight: 12 }}>
<input
type="radio"
name="visMode"
value={mode.key}
checked={visMode === mode.key}
onChange={() => setVisMode(mode.key as 'avg' | 'std' | 'cv')}
/>{' '}
{mode.label}
</label>
))}
</div>
<div ref={mapContainerRef} className={`map-info ${isExpanded ? 'expanded' : 'collapsed'}`}>
<IconButton
ref={buttonRef}
color="primary"
className="expand-button"
onClick={toggleExpanded}>
<OpenInFullRounded fontSize="large" />
</IconButton>
{isLoading && (
<div
style={{
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'rgba(255, 255, 255, 0.7)',
zIndex: 1000,
gap: 12,
}}>
<CircularProgress size={48} />
<span style={{ fontSize: '1.1em', color: '#333' }}>Loading heatmap data...</span>
</div>
)}
{errorMessage && !isLoading && (
<div
style={{
position: 'absolute',
top: 12,
left: '50%',
transform: 'translateX(-50%)',
zIndex: 1000,
}}>
<Alert severity="error">{errorMessage}</Alert>
</div>
)}
<MapContainer
center={[29.65, 34.6]}
zoom={DEFAULT_ZOOM_LEVEL}
scrollWheelZoom={true}
style={{ height: '100%', width: '100%' }}>
<TileLayer
attribution='© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
url="https://tile-a.openstreetmap.fr/hot/{z}/{x}/{y}.png"
/>
<VelocityHeatmapRectangles
visMode={visMode}
setMinMax={(min, max) => {
setMin(min)
setMax(max)
}}
onLoadingChange={setIsLoading}
onErrorChange={setErrorMessage}
/>
<VelocityHeatmapLegend visMode={visMode} min={min} max={max} />
</MapContainer>
</div>
</div>
)
}
export default VelocityHeatmapPage