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

fix: Vertically center the map on mobile when opening it #149

Merged
merged 3 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## 🐛 Bug Fixes

* Vertically center the trip map on mobile when opening it

## 🔧 Tech

# 0.7.0
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ $ yarn fixtures
You can run a migration service to add aggregation data on your timeseries.

```sh
$ yarn build
$ yarn service:timeseriesWithoutAggregateMigration
```

Expand Down
15 changes: 12 additions & 3 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 @@ -51,7 +52,7 @@ const TripMap = () => {
[theme]
)
const mapPanRatio = useMemo(
() => (isMobile ? bottomSheetSettings.mediumHeightRatio / 2 : 0),
() => (isMobile ? bottomSheetSettings.mediumHeightRatio : 0),
[isMobile]
)

Expand All @@ -63,8 +64,16 @@ const TripMap = () => {
useEffect(() => {
if (geojsonRef.current) {
const geojsonL = geojsonRef.current.leafletElement
mapL.fitBounds(geojsonL.getBounds())
mapL.panBy([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