1
|
import { Button } from '@mui/material'
|
2
|
import { useSelector } from 'react-redux'
|
3
|
import { RootState } from '../../redux/store'
|
4
|
import { isMapPointDisplayable } from '../trackingToolUtils'
|
5
|
import { exportAsGeoJsonString } from '../Map/geoJsonMapping'
|
6
|
|
7
|
const GeoJsonExportButton = () => {
|
8
|
const path = useSelector((state: RootState) => state.trackingTool.displayedPath)
|
9
|
const exportPath = () => {
|
10
|
if (!path) {
|
11
|
return
|
12
|
}
|
13
|
|
14
|
const exportPath = path.filter(
|
15
|
(vertex) => isMapPointDisplayable(vertex) && vertex.addToPath
|
16
|
)
|
17
|
const exportPathString = exportAsGeoJsonString(exportPath)
|
18
|
const blob = new Blob([exportPathString], { type: 'application/json' })
|
19
|
const url = window.URL.createObjectURL(blob)
|
20
|
const link = document.createElement('a')
|
21
|
link.href = url
|
22
|
link.setAttribute('download', 'path.json')
|
23
|
document.body.appendChild(link)
|
24
|
link.click()
|
25
|
document.body.removeChild(link)
|
26
|
}
|
27
|
|
28
|
return (
|
29
|
<Button variant="contained" onClick={exportPath}>
|
30
|
Export
|
31
|
</Button>
|
32
|
)
|
33
|
}
|
34
|
|
35
|
export default GeoJsonExportButton
|