Projekt

Obecné

Profil

Stáhnout (4.48 KB) Statistiky
| Větev: | Tag: | Revize:
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

    
10
// Page with tracking tool
11
const TrackingTool = () => {
12
    const createDummyPathCoords = () => {
13
        // Sample dummy path to display
14
        const dummyPath = []
15
        for (let i = 0; i < 10; i += 1) {
16
            dummyPath.push({
17
                latitude:
18
                    mapConfig.defaultCoordinates[0] +
19
                    i * 0.1 +
20
                    Math.random() * 0.1,
21
                longitude:
22
                    mapConfig.defaultCoordinates[1] +
23
                    i * 0.1 +
24
                    Math.random() * 0.1,
25
            })
26
        }
27
        return dummyPath
28
    }
29

    
30
    const createDummyPath = () => {
31
        const coords = createDummyPathCoords()
32
        const polylines: any[] = []
33

    
34
        if (coords.length < 2) {
35
            return []
36
        }
37

    
38
        for (let i = 0; i < coords.length - 1; i += 1) {
39
            polylines.push(
40
                // <Polyline
41
                //     key={i}
42
                //     positions={[
43
                //         [dummyPath[i].latitude, dummyPath[i].longitude],
44
                //         [dummyPath[i + 1].latitude, dummyPath[i + 1].longitude],
45
                //     ]}
46
                //     color="red"
47
                //     weight={5}
48
                //     opacity={1}
49

    
50
                //     smoothFactor={1}
51
                // >
52
                //     <Popup>Caesar 🥗 War Path (Allegedly)</Popup>
53
                //     </Polyline>
54
                <TextPath
55
                    positions={[
56
                        [coords[i].latitude, coords[i].longitude],
57
                        [coords[i + 1].latitude, coords[i + 1].longitude],
58
                    ]}
59
                    text="►"
60
                    attributes={{
61
                        'font-size': 25,
62
                        fill: 'blue',
63
                    }}
64
                    repeat
65
                    center
66
                    weight={10}
67
                >
68
                    <Popup>Caesar 🥗 War Path (Allegedly)</Popup>
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 position={[latitude, longitude]} />
127
                        ))}
128
                        {polylines}
129
                    </MapContainer>
130
                </Grid>
131
                
132
            </Grid>
133
        </Fragment>
134
    )
135
}
136

    
137
export default TrackingTool
(3-3/3)