1
|
import { Box, Typography } from '@mui/material'
|
2
|
import { Fragment, FunctionComponent } from 'react'
|
3
|
import { MapContainer, Marker, Popup, TileLayer } from 'react-leaflet'
|
4
|
import mapConfig from '../../config/mapConfig'
|
5
|
import { CatalogItemDto } from '../../swagger/data-contracts'
|
6
|
|
7
|
const CatalogItemMap: FunctionComponent<{ item: CatalogItemDto }> = ({
|
8
|
item,
|
9
|
}) => {
|
10
|
const [lat, long] = [
|
11
|
item.longitude ?? mapConfig.defaultCoordinates[0],
|
12
|
item.latitude ?? mapConfig.defaultCoordinates[1],
|
13
|
]
|
14
|
|
15
|
return (
|
16
|
<Fragment>
|
17
|
<Box sx={{ px: 2, py: 4 }} style={{ height: '100%', minHeight: '450px', maxHeight: '70vh'}}>
|
18
|
<MapContainer center={[long, lat]} zoom={7} style={{ height: '100%', minHeight: '100%'}}>
|
19
|
<TileLayer attribution={mapConfig.attribution} url={mapConfig.url} />
|
20
|
{!item.longitude || !item.latitude ? null : (
|
21
|
<Marker position={[long, lat]}>
|
22
|
<Popup>{item.name}</Popup>
|
23
|
</Marker>
|
24
|
)}
|
25
|
</MapContainer>
|
26
|
{!item.longitude || !item.latitude ? (
|
27
|
<Typography color="error" align="center" fontWeight="bold">Location Unavailable</Typography>
|
28
|
) : null}
|
29
|
</Box>
|
30
|
</Fragment>
|
31
|
)
|
32
|
}
|
33
|
|
34
|
export default CatalogItemMap
|