Projekt

Obecné

Profil

Stáhnout (4.52 KB) Statistiky
| Větev: | Tag: | Revize:
1 41a11178 Vaclav Honzik
import { Button, Divider, Grid, Stack, Typography } from '@mui/material'
2 788ce11e Vaclav Honzik
import { Fragment } from 'react'
3
import AddIcon from '@mui/icons-material/Add'
4 76e15218 Vaclav Honzik
import { MapContainer, Marker, Polyline, Popup, TileLayer } from 'react-leaflet'
5 788ce11e Vaclav Honzik
import mapConfig from '../../config/mapConfig'
6 76e15218 Vaclav Honzik
import TextPath from 'react-leaflet-textpath'
7 0d90d67b Vaclav Honzik
import PlaintextUpload from './PlaintextUpload'
8
import FileUpload from './FileUpload'
9 4f42fa52 Václav Honzík
import L from 'leaflet'
10
import DeleteIcon from '@mui/icons-material/Delete'
11 788ce11e Vaclav Honzik
12
// Page with tracking tool
13
const TrackingTool = () => {
14 0d90d67b Vaclav Honzik
    const createDummyPathCoords = () => {
15 76e15218 Vaclav Honzik
        // Sample dummy path to display
16
        const dummyPath = []
17
        for (let i = 0; i < 10; i += 1) {
18
            dummyPath.push({
19
                latitude:
20
                    mapConfig.defaultCoordinates[0] +
21
                    i * 0.1 +
22
                    Math.random() * 0.1,
23
                longitude:
24
                    mapConfig.defaultCoordinates[1] +
25
                    i * 0.1 +
26
                    Math.random() * 0.1,
27
            })
28
        }
29
        return dummyPath
30
    }
31
32 0d90d67b Vaclav Honzik
    const createDummyPath = () => {
33
        const coords = createDummyPathCoords()
34 76e15218 Vaclav Honzik
        const polylines: any[] = []
35
36 0d90d67b Vaclav Honzik
        if (coords.length < 2) {
37 76e15218 Vaclav Honzik
            return []
38
        }
39
40 0d90d67b Vaclav Honzik
        for (let i = 0; i < coords.length - 1; i += 1) {
41 76e15218 Vaclav Honzik
            polylines.push(
42
                // <Polyline
43
                //     key={i}
44
                //     positions={[
45
                //         [dummyPath[i].latitude, dummyPath[i].longitude],
46
                //         [dummyPath[i + 1].latitude, dummyPath[i + 1].longitude],
47
                //     ]}
48
                //     color="red"
49
                //     weight={5}
50
                //     opacity={1}
51
52
                //     smoothFactor={1}
53
                // >
54
                //     <Popup>Caesar 🥗 War Path (Allegedly)</Popup>
55
                //     </Polyline>
56
                <TextPath
57
                    positions={[
58 0d90d67b Vaclav Honzik
                        [coords[i].latitude, coords[i].longitude],
59
                        [coords[i + 1].latitude, coords[i + 1].longitude],
60 76e15218 Vaclav Honzik
                    ]}
61
                    text="►"
62
                    attributes={{
63
                        'font-size': 25,
64 0d90d67b Vaclav Honzik
                        fill: 'blue',
65 76e15218 Vaclav Honzik
                    }}
66
                    repeat
67
                    center
68
                    weight={10}
69 4f42fa52 Václav Honzík
                ></TextPath>
70 76e15218 Vaclav Honzik
            )
71
        }
72
73 0d90d67b Vaclav Honzik
        return [polylines, coords]
74 76e15218 Vaclav Honzik
    }
75
76 0d90d67b Vaclav Honzik
    const [polylines, coords] = createDummyPath()
77 788ce11e Vaclav Honzik
78
    return (
79
        <Fragment>
80
            <Typography variant="h3" sx={{ mb: 2 }} fontWeight="bold">
81
                Tracking Tool
82
            </Typography>
83
84
            <Grid container>
85
                <Grid item xs={12} md={4}>
86
                    <Stack
87
                        direction="row"
88
                        alignItems="flex-start"
89
                        spacing={2}
90
                        sx={{ m: 0, p: 0 }}
91
                    >
92
                        <Typography
93
                            variant="h5"
94
                            sx={{ mb: 2 }}
95
                            fontWeight="500"
96
                        >
97
                            Upload:
98
                        </Typography>
99 0d90d67b Vaclav Honzik
                        <PlaintextUpload />
100
                        <FileUpload />
101 788ce11e Vaclav Honzik
                    </Stack>
102
                </Grid>
103 76e15218 Vaclav Honzik
                <Grid
104
                    item
105
                    xs={12}
106 41a11178 Vaclav Honzik
                    md={12}
107 76e15218 Vaclav Honzik
                    style={{
108
                        minHeight: '60vh',
109
                        maxHeight: '100vh',
110
                        width: '100%',
111
                    }}
112
                >
113 788ce11e Vaclav Honzik
                    <MapContainer
114 76e15218 Vaclav Honzik
                        center={[
115
                            mapConfig.defaultCoordinates[0],
116
                            mapConfig.defaultCoordinates[1],
117
                        ]}
118 788ce11e Vaclav Honzik
                        zoom={mapConfig.defaultZoom}
119
                        style={{ height: '100%', minHeight: '100%' }}
120
                    >
121 76e15218 Vaclav Honzik
                        <TileLayer
122
                            attribution={mapConfig.attribution}
123
                            url={mapConfig.url}
124
                        />
125 0d90d67b Vaclav Honzik
                        {coords.map(({ latitude, longitude }, idx) => (
126 4f42fa52 Václav Honzík
                            <Marker
127
                                position={[latitude, longitude]}
128
                            />
129 0d90d67b Vaclav Honzik
                        ))}
130 76e15218 Vaclav Honzik
                        {polylines}
131 788ce11e Vaclav Honzik
                    </MapContainer>
132
                </Grid>
133
            </Grid>
134
        </Fragment>
135
    )
136
}
137
138
export default TrackingTool