Revize 48690561
Přidáno uživatelem Václav Honzík před asi 2 roky(ů)
frontend/src/features/TrackingTool/TrackingTool.tsx | ||
---|---|---|
1 |
import { |
|
2 |
Button, |
|
3 |
Card, |
|
4 |
CardContent, |
|
5 |
Grid, |
|
6 |
Stack, |
|
7 |
ThemeProvider, |
|
8 |
Typography, |
|
9 |
} from '@mui/material' |
|
10 |
import { Fragment, useEffect, useRef } from 'react' |
|
11 |
import { MapContainer, TileLayer } from 'react-leaflet' |
|
12 |
import mapConfig from '../../config/mapConfig' |
|
1 |
import { Button, Grid, Stack, Typography } from '@mui/material' |
|
2 |
import { Fragment, useEffect } from 'react' |
|
13 | 3 |
import PlaintextUpload from './Upload/PlaintextUpload' |
14 | 4 |
import FileUpload from './Upload/FileUpload' |
15 |
import { Map } from 'leaflet' |
|
16 |
import { formatHtmlStringToReactDom } from '../../utils/formatting/HtmlUtils' |
|
17 |
import MapPath from './Map/MapPath' |
|
18 | 5 |
import { useDispatch, useSelector } from 'react-redux' |
19 | 6 |
import { RootState } from '../redux/store' |
20 | 7 |
import { clear, consumeErr as consumeError } from './trackingToolSlice' |
21 | 8 |
import { showNotification } from '../Notification/notificationSlice' |
22 | 9 |
import ClearIcon from '@mui/icons-material/Clear' |
23 |
import GeoJsonExportButton from './Upload/GeoJsonExportButton' |
|
24 |
import GeoJsonImportDialog from './Upload/GeoJsonImportDialog' |
|
25 |
import ProcessedTextDisplay from './ProcessedText/ProcessedTextDisplay' |
|
26 |
import MapPointDraggableList from './MapPointDraggableList/MapPointDraggableList' |
|
27 |
import RightClickPopupMenu from './Import/ImportContextMenu' |
|
28 |
import { buildTheme, getPalette } from '../Theme/ThemeWrapper' |
|
29 |
import AttachFileIcon from '@mui/icons-material/AttachFile' |
|
30 |
import MapPointToggleables from './Import/MapPointToggleables' |
|
31 |
|
|
32 |
const mapTheme = buildTheme('light') |
|
10 |
import GeoJsonExportButton from './Import/GeoJsonExportButton' |
|
11 |
import ProcessedTextDisplay from './Controls/ProcessedTextDisplay' |
|
12 |
import MapPointToggleables from './Controls/MapPointToggleables' |
|
13 |
import GeoJsonImportDialog from './Import/GeoJsonImportDialog' |
|
14 |
import Map from './Map/Map' |
|
33 | 15 |
|
34 | 16 |
// Page with tracking tool |
35 | 17 |
const TrackingTool = () => { |
36 |
const dispatch = useDispatch() |
|
37 |
|
|
38 |
// Path response from the API |
|
39 | 18 |
const pathDto = useSelector( |
19 |
// Path response from the API |
|
40 | 20 |
(state: RootState) => state.trackingTool.pathDto |
41 | 21 |
) |
42 |
const pathVariants = useSelector( |
|
43 |
(state: RootState) => state.trackingTool.pathVariants |
|
44 |
) |
|
45 |
const mapCenter = useSelector( |
|
46 |
(state: RootState) => state.trackingTool.mapCenter |
|
22 |
|
|
23 |
// Use path as flag for undefined or present |
|
24 |
const path = useSelector( |
|
25 |
(state: RootState) => state.trackingTool.displayedPath |
|
47 | 26 |
) |
48 | 27 |
|
49 | 28 |
// Consume any error |
29 |
const dispatch = useDispatch() |
|
50 | 30 |
const err = useSelector((state: RootState) => state.trackingTool.lastError) |
51 | 31 |
useEffect(() => { |
52 | 32 |
if (!err) { |
... | ... | |
62 | 42 |
) |
63 | 43 |
}, [err, dispatch]) |
64 | 44 |
|
65 |
const mapRef = useRef<Map | undefined>(undefined) |
|
66 |
useEffect(() => { |
|
67 |
if (!mapRef || !mapRef.current) { |
|
68 |
console.log('No map ref') |
|
69 |
return |
|
70 |
} |
|
71 |
|
|
72 |
const map = mapRef.current |
|
73 |
map.setView(mapCenter, mapConfig.defaultZoom, { |
|
74 |
animate: true, |
|
75 |
}) |
|
76 |
}, [mapCenter, mapRef]) |
|
77 |
|
|
78 | 45 |
return ( |
79 | 46 |
<Fragment> |
80 | 47 |
<Typography variant="h3" sx={{ mb: 2 }} fontWeight="bold"> |
... | ... | |
113 | 80 |
<FileUpload /> |
114 | 81 |
</Fragment> |
115 | 82 |
)} |
116 |
{pathVariants && pathVariants.length > 0 && (
|
|
83 |
{path && ( |
|
117 | 84 |
<Fragment> |
118 | 85 |
<GeoJsonImportDialog /> |
119 | 86 |
<GeoJsonExportButton /> |
... | ... | |
124 | 91 |
{pathDto && ( |
125 | 92 |
<Fragment> |
126 | 93 |
<MapPointToggleables /> |
127 |
<Stack alignItems="flex-end"> |
|
128 |
<Button |
|
129 |
startIcon={<ClearIcon />} |
|
130 |
sx={{ mb: 1 }} |
|
131 |
variant="contained" |
|
132 |
onClick={() => dispatch(clear())} |
|
133 |
> |
|
134 |
Clear Map |
|
135 |
</Button> |
|
136 |
</Stack> |
|
94 |
<Stack alignItems="flex-end">
|
|
95 |
<Button
|
|
96 |
startIcon={<ClearIcon />}
|
|
97 |
sx={{ mb: 1 }}
|
|
98 |
variant="contained"
|
|
99 |
onClick={() => dispatch(clear())}
|
|
100 |
>
|
|
101 |
Clear Map
|
|
102 |
</Button>
|
|
103 |
</Stack>
|
|
137 | 104 |
</Fragment> |
138 | 105 |
)} |
139 | 106 |
</Grid> |
... | ... | |
148 | 115 |
width: '100%', |
149 | 116 |
}} |
150 | 117 |
> |
151 |
<ThemeProvider theme={mapTheme}> |
|
152 |
<MapContainer |
|
153 |
center={[mapCenter[0], mapCenter[1]]} |
|
154 |
zoom={mapConfig.defaultZoom} |
|
155 |
style={{ height: '100%', minHeight: '100%' }} |
|
156 |
whenCreated={(map) => { |
|
157 |
mapRef.current = map |
|
158 |
}} |
|
159 |
> |
|
160 |
<TileLayer |
|
161 |
attribution={mapConfig.attribution} |
|
162 |
url={mapConfig.url} |
|
163 |
/> |
|
164 |
{pathVariants?.map((pathVariant, idx) => ( |
|
165 |
<MapPath idx={idx} /> |
|
166 |
))} |
|
167 |
<RightClickPopupMenu /> |
|
168 |
</MapContainer> |
|
169 |
</ThemeProvider> |
|
118 |
<Map /> |
|
170 | 119 |
</Grid> |
171 | 120 |
<Grid container sx={{ mt: 1, mb: 20 }} spacing={1}> |
172 | 121 |
<Grid item xs={12} md={6}> |
173 |
<MapPointDraggableList />
|
|
122 |
{/* <MapPointDraggableList /> */}
|
|
174 | 123 |
</Grid> |
175 | 124 |
<Grid item xs={12} md={6}> |
176 | 125 |
<ProcessedTextDisplay /> |
Také k dispozici: Unified diff
smol refactor
re #9741