-
-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathContainer.jsx
More file actions
82 lines (75 loc) · 2.26 KB
/
Container.jsx
File metadata and controls
82 lines (75 loc) · 2.26 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
// @ts-check
import * as React from 'react'
import { MapContainer } from 'react-leaflet'
import { useMemory } from '@store/useMemory'
import { useStorage } from '@store/useStorage'
import { useMapStore } from '@store/useMapStore'
import { ScanOnDemand } from '@features/scanner'
import { WebhookMarker, WebhookAreaSelection } from '@features/webhooks'
import { ActiveWeather } from '@features/weather'
import { timeCheck } from '@utils/timeCheck'
import { cleanupHiddenEntities } from '@utils/hiddenEntities'
import { Effects } from './Effects'
import { DataView } from './Data'
import { Nav } from './Nav'
import {
ControlledLocate,
ControlledTileLayer,
ControlledZoomLayer,
} from './Layers'
/** @param {{ target: import('leaflet').Map, type: string }} args */
function setLocationZoom({ target: map }) {
const { lat, lng } = map.getCenter()
const zoom = map.getZoom()
useStorage.setState({ location: [lat, lng], zoom })
useMemory.setState({
timeOfDay: timeCheck(lat, lng),
})
if (map.hasEventListeners('fetchdata')) map.fire('fetchdata')
}
const MAX_BOUNDS = /** @type {[[number, number], [number, number]]} */ ([
[-90, -210],
[90, 210],
])
export function Container() {
const { location, zoom } = useStorage.getState()
// Cleanup hidden entities every 15 seconds
React.useEffect(() => {
const interval = setInterval(
() => cleanupHiddenEntities(useMemory.setState),
15000,
)
return () => clearInterval(interval)
}, [])
return (
<MapContainer
tap={false}
center={location}
ref={(ref) => {
if (ref) {
const { attributionPrefix } = useMemory.getState().config.general
ref.attributionControl.setPrefix(attributionPrefix || '')
ref.on('moveend', setLocationZoom)
ref.on('zoomend', setLocationZoom)
}
useMapStore.setState({ map: ref })
}}
zoom={zoom}
zoomControl={false}
maxBounds={MAX_BOUNDS}
preferCanvas
>
<Effects />
<ControlledTileLayer />
<ControlledZoomLayer />
<ControlledLocate />
<DataView />
<ScanOnDemand mode="scanNext" />
<ScanOnDemand mode="scanZone" />
<WebhookMarker />
<WebhookAreaSelection />
<Nav />
<ActiveWeather />
</MapContainer>
)
}