Projekt

Obecné

Profil

Stáhnout (2.08 KB) Statistiky
| Větev: | Tag: | Revize:
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
import { PathDto } from '../../../swagger/data-contracts'
11

    
12
const RightClickPopupMenu = () => {
13
    const [open, setOpen] = useState(false)
14
    const [latLng, setLatLng] = useState<[number, number]>([0, 0])
15
    const pathDto = useSelector((state: RootState) => state.trackingTool.pathDto)
16

    
17
    useMapEvents({
18
        contextmenu: (e: LeafletMouseEvent) => {
19
            if (!pathDto) {
20
                return
21
            }
22
            setLatLng([e.latlng.lat, e.latlng.lng])
23
            setOpen(true)
24
        },
25
    })
26

    
27
    const closeContextMenu = useCallback(() => {
28
        setOpen(false)
29
    }, [setOpen])
30

    
31
    return (
32
        <Fragment>
33
            {open && (
34
                <Popup onClose={() => setOpen(false)} position={latLng}>
35
                    <Stack
36
                        sx={{ p: 0, mt: 0 }}
37
                        direction="column"
38
                        justifyItems="center"
39
                        justifyContent="center"
40
                    >
41
                        <Typography style={{margin: 0}} sx={{ mb: 0.5 }} align="center">
42
                            {latLng[0].toFixed(5)}°{latLng[1].toFixed(5)}°
43
                        </Typography>
44
                        <AddFromCoordinatesDialog
45
                            latLng={latLng}
46
                            closeContextMenu={closeContextMenu}
47
                        />
48
                        <ImportLocationDialog
49
                            latLng={latLng}
50
                            closeContextMenu={closeContextMenu}
51
                        />
52
                    </Stack>
53
                </Popup>
54
            )}
55
        </Fragment>
56
    )
57
}
58

    
59
export default RightClickPopupMenu
(2-2/4)