1
|
import { Button, Divider, Grid, Stack, Typography } from '@mui/material'
|
2
|
import { Fragment } from 'react'
|
3
|
import AddIcon from '@mui/icons-material/Add'
|
4
|
import { MapContainer, Marker, Polyline, Popup, TileLayer } from 'react-leaflet'
|
5
|
import mapConfig from '../../config/mapConfig'
|
6
|
import TextPath from 'react-leaflet-textpath'
|
7
|
import PlaintextUpload from './PlaintextUpload'
|
8
|
import FileUpload from './FileUpload'
|
9
|
import L from 'leaflet'
|
10
|
import DeleteIcon from '@mui/icons-material/Delete'
|
11
|
|
12
|
// Page with tracking tool
|
13
|
const TrackingTool = () => {
|
14
|
const createDummyPathCoords = () => {
|
15
|
// 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
|
const createDummyPath = () => {
|
33
|
const coords = createDummyPathCoords()
|
34
|
const polylines: any[] = []
|
35
|
|
36
|
if (coords.length < 2) {
|
37
|
return []
|
38
|
}
|
39
|
|
40
|
for (let i = 0; i < coords.length - 1; i += 1) {
|
41
|
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
|
[coords[i].latitude, coords[i].longitude],
|
59
|
[coords[i + 1].latitude, coords[i + 1].longitude],
|
60
|
]}
|
61
|
text="►"
|
62
|
attributes={{
|
63
|
'font-size': 25,
|
64
|
fill: 'blue',
|
65
|
}}
|
66
|
repeat
|
67
|
center
|
68
|
weight={10}
|
69
|
></TextPath>
|
70
|
)
|
71
|
}
|
72
|
|
73
|
return [polylines, coords]
|
74
|
}
|
75
|
|
76
|
const [polylines, coords] = createDummyPath()
|
77
|
|
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
|
<PlaintextUpload />
|
100
|
<FileUpload />
|
101
|
</Stack>
|
102
|
</Grid>
|
103
|
<Grid
|
104
|
item
|
105
|
xs={12}
|
106
|
md={12}
|
107
|
style={{
|
108
|
minHeight: '60vh',
|
109
|
maxHeight: '100vh',
|
110
|
width: '100%',
|
111
|
}}
|
112
|
>
|
113
|
<MapContainer
|
114
|
center={[
|
115
|
mapConfig.defaultCoordinates[0],
|
116
|
mapConfig.defaultCoordinates[1],
|
117
|
]}
|
118
|
zoom={mapConfig.defaultZoom}
|
119
|
style={{ height: '100%', minHeight: '100%' }}
|
120
|
>
|
121
|
<TileLayer
|
122
|
attribution={mapConfig.attribution}
|
123
|
url={mapConfig.url}
|
124
|
/>
|
125
|
{coords.map(({ latitude, longitude }, idx) => (
|
126
|
<Marker
|
127
|
position={[latitude, longitude]}
|
128
|
/>
|
129
|
))}
|
130
|
{polylines}
|
131
|
</MapContainer>
|
132
|
</Grid>
|
133
|
</Grid>
|
134
|
</Fragment>
|
135
|
)
|
136
|
}
|
137
|
|
138
|
export default TrackingTool
|