Skip to content

Commit

Permalink
fix: Add a small safety padding to the map on all the screens
Browse files Browse the repository at this point in the history
This prevents the route to reach the edges of the map
when it is opened
  • Loading branch information
PolariTOON committed Jul 5, 2022
1 parent 2b6dc86 commit 7c3e703
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/components/Trip/TripMap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { getGeoJSONData } from 'src/lib/timeseries'
import './tripmap.styl'

const mapCenter = [51.505, -0.09]
const mapPadding = 16

const makeGeoJsonOptions = theme => ({
style: feature => {
Expand Down Expand Up @@ -63,8 +64,15 @@ const TripMap = () => {
useEffect(() => {
if (geojsonRef.current) {
const geojsonL = geojsonRef.current.leafletElement
mapL.fitBounds(geojsonL.getBounds(), {
paddingBottomRight: [0, mapL.getSize().y * mapPanRatio]
const bounds = geojsonL.getBounds()
const paddingTopLeft = [mapPadding, mapPadding]
const paddingBottomRight = [
mapPadding,
mapPadding + mapL.getSize().y * mapPanRatio
]
mapL.fitBounds(bounds, {
paddingTopLeft,
paddingBottomRight
})
}
}, [mapL, mapPanRatio])
Expand Down

0 comments on commit 7c3e703

Please sign in to comment.