1
|
import { LeafletMouseEvent } from 'leaflet'
|
2
|
import { Fragment, useCallback, useState } from 'react'
|
3
|
import { Popup, useMapEvents } from 'react-leaflet'
|
4
|
import Typography from '@mui/material/Typography'
|
5
|
import { Stack } from '@mui/material'
|
6
|
import AddFromCoordinatesDialog from './AddFromCoordinatesDialog'
|
7
|
import { useSelector } from 'react-redux'
|
8
|
import { RootState } from '../../redux/store'
|
9
|
import ImportLocationDialog from './ImportLocationDialog'
|
10
|
|
11
|
const RightClickPopupMenu = () => {
|
12
|
const [open, setOpen] = useState(false)
|
13
|
const [latLng, setLatLng] = useState<[number, number]>([0, 0])
|
14
|
const path = useSelector(
|
15
|
(state: RootState) => state.trackingTool.displayedPath
|
16
|
)
|
17
|
|
18
|
useMapEvents({
|
19
|
contextmenu: (e: LeafletMouseEvent) => {
|
20
|
if (!path) {
|
21
|
return
|
22
|
}
|
23
|
setLatLng([e.latlng.lat, e.latlng.lng])
|
24
|
setOpen(true)
|
25
|
},
|
26
|
})
|
27
|
|
28
|
const closeContextMenu = useCallback(() => {
|
29
|
setOpen(false)
|
30
|
}, [setOpen])
|
31
|
|
32
|
return (
|
33
|
<Fragment>
|
34
|
{open && (
|
35
|
<Popup onClose={() => setOpen(false)} position={latLng}>
|
36
|
<Stack
|
37
|
sx={{ p: 0, mt: 0 }}
|
38
|
direction="column"
|
39
|
justifyItems="center"
|
40
|
justifyContent="center"
|
41
|
>
|
42
|
<Typography
|
43
|
style={{ margin: 0 }}
|
44
|
sx={{ mb: 0.5 }}
|
45
|
align="center"
|
46
|
>
|
47
|
{latLng[0].toFixed(5)}°{latLng[1].toFixed(5)}°
|
48
|
</Typography>
|
49
|
<AddFromCoordinatesDialog
|
50
|
latLng={latLng}
|
51
|
closeContextMenu={closeContextMenu}
|
52
|
/>
|
53
|
<ImportLocationDialog
|
54
|
latLng={latLng}
|
55
|
closeContextMenu={closeContextMenu}
|
56
|
/>
|
57
|
</Stack>
|
58
|
</Popup>
|
59
|
)}
|
60
|
</Fragment>
|
61
|
)
|
62
|
}
|
63
|
|
64
|
export default RightClickPopupMenu
|