Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: map updates #31

Merged
merged 1 commit into from
Feb 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 41 additions & 28 deletions frontend/src/components/MapView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { useEffect, useState } from 'react'
import apiService from '@/service/api-service'
import pin from '../assets/marker-icon-2x-red.png'
import shadow from '../assets/marker-shadow.png'
import Table from '@mui/material/Table'
import TableCell from '@mui/material/TableCell'
import TableRow from '@mui/material/TableRow'

/**
* Renders a map with a marker at the supplied location
*
Expand All @@ -24,7 +28,13 @@ const LeafletMapWithPoint = () => {
?.map((item) => {
return {
position: [item?.Latitude, item?.Longitude],
details: item,
details: {
'Authorization Number': item['Authorization Number'],
'Authorization Type': item['Authorization Type'],
'Authorization Status': item['Authorization Status'],
'Regulated Party': item['Regulated Party'],
'Facility Location': item['Facility Location'],
},
}
})
setData(points)
Expand All @@ -38,11 +48,10 @@ const LeafletMapWithPoint = () => {
// Set the position of the marker for center of BC
const position = [53.7267, -127.6476]
// define points
const samplePoints = [
{ position: [60, -140], details: 'BC' },
{ position: [49.019, -122.455], details: 'BC' },
{ position: [51.7267, -128.6476], details: 'BC' },
]
const samplePoints = [{ position: [60, -140], details: 'BC' }, {
position: [49.019, -122.455],
details: 'BC',
}, { position: [51.7267, -128.6476], details: 'BC' }]
//define red icon
const redIcon = new L.Icon({
//read from assets
Expand All @@ -54,28 +63,32 @@ const LeafletMapWithPoint = () => {
shadowSize: [41, 41],
})

return (
<>
<MapContainer
id="map"
center={position}
zoom={6}
style={{ height: '60em', width: '100%', marginLeft: '4em' }}
className="map-container"
>
<TileLayer
attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
{dataFetched &&
data.map((item, index) => (
<Marker key={index} position={item.position} icon={redIcon}>
<Popup>{item.details['Authorization Number']}</Popup>
</Marker>
))}
</MapContainer>
</>
)
return (<>
<MapContainer
id="map"
center={position}
zoom={6}
style={{ height: '60em', width: '100%', marginLeft: '4em' }}
className="map-container"
>
<TileLayer
attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
{dataFetched && data.map((item, index) => (<Marker key={index} position={item.position} icon={redIcon}>
<Popup sx={{ maxWidth: '50em' }}>
<Table size="small">
{Object.keys(item.details).map((itemDetails) => (
<><TableRow><TableCell variant="head" align="right">{itemDetails}</TableCell>
<TableCell align="right">{item.details[itemDetails]}</TableCell></TableRow></>
))
}
</Table>
</Popup>
</Marker>
))}
</MapContainer>
</>)
}

export default LeafletMapWithPoint
Loading