1
|
import { ThemeProvider } from '@mui/material'
|
2
|
import { useRef, useEffect } from 'react'
|
3
|
import { MapContainer, TileLayer } from 'react-leaflet'
|
4
|
import { useSelector } from 'react-redux'
|
5
|
import mapConfig from '../../../config/mapConfig'
|
6
|
import { RootState } from '../../redux/store'
|
7
|
import { buildTheme } from '../../Theme/ThemeWrapper'
|
8
|
import RightClickPopupMenu from '../Import/ImportContextMenu'
|
9
|
import MapPath from './MapPath'
|
10
|
import { Map as LeafletMap } from 'leaflet'
|
11
|
|
12
|
const mapTheme = buildTheme('light')
|
13
|
|
14
|
const Map = () => {
|
15
|
|
16
|
const mapCenter = useSelector((state: RootState) => state.trackingTool.mapCenter)
|
17
|
|
18
|
const mapRef = useRef<LeafletMap | undefined>(undefined)
|
19
|
useEffect(() => {
|
20
|
if (!mapRef || !mapRef.current) {
|
21
|
return
|
22
|
}
|
23
|
|
24
|
const map = mapRef.current
|
25
|
map.setView(mapCenter, mapConfig.defaultZoom, {
|
26
|
animate: true,
|
27
|
})
|
28
|
}, [mapCenter, mapRef])
|
29
|
|
30
|
return (
|
31
|
<ThemeProvider theme={mapTheme}>
|
32
|
<MapContainer
|
33
|
center={[mapCenter[0], mapCenter[1]]}
|
34
|
zoom={mapConfig.defaultZoom}
|
35
|
style={{ height: '100%', minHeight: '100%' }}
|
36
|
whenCreated={(map) => {
|
37
|
mapRef.current = map
|
38
|
}}
|
39
|
>
|
40
|
<TileLayer
|
41
|
attribution={mapConfig.attribution}
|
42
|
url={mapConfig.url}
|
43
|
/>
|
44
|
<MapPath />
|
45
|
<RightClickPopupMenu />
|
46
|
</MapContainer>
|
47
|
</ThemeProvider>
|
48
|
)
|
49
|
}
|
50
|
|
51
|
export default Map
|