Skip to content

Commit

Permalink
feat: add legend to map
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-famibelle-pronzola committed Mar 3, 2023
1 parent d3ff727 commit 8022ae5
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 1 deletion.
6 changes: 5 additions & 1 deletion components/map/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import maplibregl from 'maplibre-gl'

import {sources} from '@/components/map/sources.js'
import {layers} from '@/components/map/layers.js'
import Legend from '@/components/map/legend.js'
import colors from '@/styles/colors.js'

const itineraireLayer = {
Expand Down Expand Up @@ -278,7 +279,10 @@ const Map = ({selectedAdresse, collegeFeature, collegeItineraire, isMobileDevice
}, [map, handleCollegeClick, selectedCollegeFeatureRef])

return (
<div ref={mapContainer} style={{width: '100%', height: '100%'}} />
<>
<Legend />
<div ref={mapContainer} style={{width: '100%', height: '100%'}} />
</>
)
}

Expand Down
87 changes: 87 additions & 0 deletions components/map/legend.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import {useState} from 'react'
import {uniqueId} from 'lodash-es'

import colors from '@/styles/colors.js'

const legend = [
{
circle: true,
color: colors.green,
libelle: 'Autre collège'
},
{
circle: true,
color: colors.blue,
libelle: 'Autre collège sélectionné'
},
{
circle: false,
color: 'rgba(0, 83, 179, 0.1)',
libelle: 'Zones de rattachement'
},
{
circle: false,
color: 'rgba(0, 83, 179, 0.5)',
libelle: 'Zones de rattachement du collège sélectionné'
}
]

const Legend = () => {
const [isWrap, setIsWrap] = useState(true)

return (
<div className='legend'
onMouseEnter={() => setIsWrap(false)}
onMouseLeave={() => setIsWrap(true)}
>
<div>Légende</div>

{!isWrap && (
<div className='legend-wrapper'>
{legend.map(({libelle, color, circle}) => (
<div key={uniqueId()}>
<div key={libelle} className='legend-container'>
<div className='legend-color' style={{backgroundColor: `${color}`, borderRadius: `${circle ? '25px' : ''}`}} />
<div>{libelle}</div>
</div>
</div>
))}
</div>
)}

<style jsx>{`
.legend {
position: absolute;
margin-top: 1em;
margin-left: 1em;
box-shadow: none;
border: 2px solid #dcd8d5;
border-radius: 4px;
z-index: 1;
padding: 0.5em;
background-color: rgba(255, 255, 255, 0.8);
max-width: 1000px;
}
.legend-wrapper {
margin-top: 1em;
}
.legend-container {
margin: .5em 0;
display: flex;
align-items: center;
}
.legend-color {
width: 15px;
height: 15px;
margin-right: 0.5em;
}
`}</style>
</div>

)
}

export default Legend

0 comments on commit 8022ae5

Please sign in to comment.