-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Explorable map of landscapes (complete feature) (#448)
* chore: Explore Landscapes base branch * feat: Added map to landscapes directory (#449) * feat: Explorable map of landscapes: Display points and clusters (#455) * feat: Explorable map of landscapes - Pin popup (#458)
- Loading branch information
Showing
15 changed files
with
302 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
.landscape-list-map-cluster-icon div { | ||
background-clip: padding-box; | ||
background-color: #985329; | ||
width: 30px; | ||
height: 25px; | ||
margin-left: 5px; | ||
margin-top: 5px; | ||
text-align: center; | ||
border-radius: 15px; | ||
padding-top: 5px; | ||
color: #fff; | ||
} | ||
|
||
.landscape-list-map-cluster-icon { | ||
background-clip: padding-box; | ||
background-color: #98532999; | ||
border-radius: 20px; | ||
} | ||
|
||
.landscape-list-map-marker-icon { | ||
background-clip: padding-box; | ||
background-color: #985329; | ||
border-radius: 30px; | ||
} | ||
|
||
.landscape-marker-popup .leaflet-popup-content-wrapper { | ||
background: #fff; | ||
font-size: 16px; | ||
line-height: 24px; | ||
border-radius: 3px; | ||
border: 1px solid #985329; | ||
box-shadow: none; | ||
} | ||
.landscape-marker-popup .leaflet-popup-tip { | ||
border: 1px solid transparent; | ||
border-right: 1px solid #985329; | ||
background-color: transparent; | ||
box-shadow: none; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import React, { useEffect, useMemo, useRef } from 'react'; | ||
|
||
import L from 'leaflet'; | ||
import _ from 'lodash/fp'; | ||
|
||
import Map from 'gis/components/Map'; | ||
|
||
import 'leaflet.markercluster'; | ||
import 'leaflet.markercluster/dist/MarkerCluster.Default.css'; | ||
|
||
import { Marker, Popup, useMap } from 'react-leaflet'; | ||
import MarkerClusterGroup from 'react-leaflet-markercluster'; | ||
import { useSelector } from 'react-redux'; | ||
|
||
import { getLandscapePin } from 'landscape/landscapeUtils'; | ||
|
||
import './LandscapeListMap.css'; | ||
|
||
import { useTranslation } from 'react-i18next'; | ||
import { Link as RouterLink } from 'react-router-dom'; | ||
|
||
import { Link, Typography } from '@mui/material'; | ||
|
||
import { countryNameForCode } from 'common/utils'; | ||
|
||
const LandscapesClusters = () => { | ||
const map = useMap(); | ||
const { t } = useTranslation(); | ||
const { landscapes } = useSelector(state => state.landscape.list); | ||
|
||
const clusterRef = useRef(); | ||
|
||
const landscapesWithPosition = useMemo(() => { | ||
return landscapes | ||
.map(landscape => ({ | ||
position: getLandscapePin(landscape), | ||
data: landscape, | ||
})) | ||
.filter(landscape => !!landscape.position); | ||
}, [landscapes]); | ||
|
||
useEffect(() => { | ||
if (!_.isEmpty(landscapesWithPosition)) { | ||
const bounds = clusterRef.current?.getBounds?.(); | ||
if (bounds) { | ||
map.fitBounds(bounds); | ||
} | ||
} | ||
}, [map, landscapesWithPosition]); | ||
|
||
return ( | ||
<MarkerClusterGroup | ||
ref={clusterRef} | ||
maxClusterRadius={40} | ||
showCoverageOnHover={false} | ||
iconCreateFunction={cluster => { | ||
return L.divIcon({ | ||
className: 'landscape-list-map-cluster-icon', | ||
iconSize: new L.Point(40, 40), | ||
html: `<div>${cluster.getChildCount()}</div>`, | ||
}); | ||
}} | ||
> | ||
{landscapesWithPosition.map((landscape, index) => ( | ||
<Marker | ||
icon={L.divIcon({ | ||
className: 'landscape-list-map-marker-icon', | ||
iconSize: new L.Point(15, 15), | ||
html: `<span class="visually-hidden">${landscape.data.name}</span>`, | ||
})} | ||
key={index} | ||
position={landscape.position} | ||
> | ||
<Popup className="landscape-marker-popup" closeButton={false}> | ||
<Link | ||
variant="h6" | ||
component={RouterLink} | ||
to={`/landscapes/${landscape.data.slug}`} | ||
> | ||
{landscape.data.name} | ||
</Link> | ||
<Typography variant="caption" display="block" sx={{ mb: 1 }}> | ||
{countryNameForCode(landscape.data.location)?.name || | ||
landscape.data.location} | ||
</Typography> | ||
<Link | ||
variant="body2" | ||
component={RouterLink} | ||
to={`/landscapes/${landscape.data.slug}`} | ||
> | ||
{t('landscape.list_map_popup_link', { | ||
name: landscape.data.name, | ||
})} | ||
</Link> | ||
</Popup> | ||
</Marker> | ||
))} | ||
</MarkerClusterGroup> | ||
); | ||
}; | ||
|
||
const LandscapeListMap = () => { | ||
return ( | ||
<Map | ||
style={{ | ||
width: '100%', | ||
height: '400px', | ||
}} | ||
> | ||
<LandscapesClusters /> | ||
</Map> | ||
); | ||
}; | ||
|
||
export default LandscapeListMap; |
Oops, something went wrong.