1
|
import { Checkbox, FormControlLabel, Stack, Typography } from '@mui/material'
|
2
|
import { useState } from 'react'
|
3
|
import { useDispatch, useSelector } from 'react-redux'
|
4
|
import { RootState } from '../../redux/store'
|
5
|
import { updateDisplayedPath } from '../trackingToolSlice'
|
6
|
import { MapPointType } from '../trackingToolUtils'
|
7
|
|
8
|
// Component which controls what type of map points are enabled and disabled
|
9
|
const MapPointToggleables = () => {
|
10
|
const dispatch = useDispatch()
|
11
|
const path = useSelector((state: RootState) => state.trackingTool.displayedPath)
|
12
|
|
13
|
// keep track of the state of the checkboxes
|
14
|
const [enableMap, setEnableMap] = useState({
|
15
|
[MapPointType.LocalCatalog]: true,
|
16
|
[MapPointType.FromCoordinates]: true,
|
17
|
[MapPointType.GeoJson]: true,
|
18
|
[MapPointType.ExternalCatalog]: true,
|
19
|
})
|
20
|
|
21
|
// Disables specific feature
|
22
|
const toggleFeature = (feature: MapPointType) => {
|
23
|
if (!path) {
|
24
|
return
|
25
|
}
|
26
|
setEnableMap({ ...enableMap, [feature]: !enableMap[feature] })
|
27
|
const newPath = path.map((point) => {
|
28
|
// if the point is the feature we are disabling, set it to as so, skip otherwise
|
29
|
if (point.type === feature) {
|
30
|
return {
|
31
|
...point,
|
32
|
hidden: enableMap[point.type],
|
33
|
addToPath: !enableMap[point.type] ? true : point.addToPath,
|
34
|
}
|
35
|
}
|
36
|
|
37
|
return point
|
38
|
})
|
39
|
dispatch(updateDisplayedPath(newPath))
|
40
|
}
|
41
|
|
42
|
return (
|
43
|
<Stack direction="column">
|
44
|
<Stack direction="row" justifyItems="space-between">
|
45
|
<Typography align="left" variant="h6" sx={{ mr: 1 }}>
|
46
|
From file
|
47
|
</Typography>
|
48
|
<FormControlLabel
|
49
|
control={
|
50
|
<Checkbox
|
51
|
checked={enableMap[MapPointType.GeoJson]}
|
52
|
onChange={() => toggleFeature(MapPointType.GeoJson)}
|
53
|
/>
|
54
|
}
|
55
|
label="Show All"
|
56
|
/>
|
57
|
</Stack>
|
58
|
<Stack direction="row" justifyItems="space-between">
|
59
|
<Typography align="left" variant="h6" sx={{ mr: 1 }}>
|
60
|
From local catalog
|
61
|
</Typography>
|
62
|
<FormControlLabel
|
63
|
control={
|
64
|
<Checkbox
|
65
|
checked={enableMap[MapPointType.LocalCatalog]}
|
66
|
onChange={() =>
|
67
|
toggleFeature(MapPointType.LocalCatalog)
|
68
|
}
|
69
|
/>
|
70
|
}
|
71
|
label="Show All"
|
72
|
/>
|
73
|
</Stack>
|
74
|
<Stack direction="row" justifyItems="space-between">
|
75
|
<Typography align="left" variant="h6" sx={{ mr: 1 }}>
|
76
|
From coordinates
|
77
|
</Typography>
|
78
|
<FormControlLabel
|
79
|
control={
|
80
|
<Checkbox
|
81
|
checked={enableMap[MapPointType.FromCoordinates]}
|
82
|
onChange={() =>
|
83
|
toggleFeature(MapPointType.FromCoordinates)
|
84
|
}
|
85
|
/>
|
86
|
}
|
87
|
label="Show All"
|
88
|
/>
|
89
|
</Stack>
|
90
|
<Stack direction="row" justifyItems="space-between">
|
91
|
<Typography align="left" variant="h6" sx={{ mr: 1 }}>
|
92
|
From external catalog
|
93
|
</Typography>
|
94
|
<FormControlLabel
|
95
|
control={
|
96
|
<Checkbox
|
97
|
checked={enableMap[MapPointType.ExternalCatalog]}
|
98
|
onChange={() =>
|
99
|
toggleFeature(MapPointType.ExternalCatalog)
|
100
|
}
|
101
|
/>
|
102
|
}
|
103
|
label="Show All"
|
104
|
/>
|
105
|
</Stack>
|
106
|
</Stack>
|
107
|
)
|
108
|
}
|
109
|
|
110
|
export default MapPointToggleables
|