Skip to content

Commit 5d74a41

Browse files
Merge pull request #673 from opentripplanner/fix-mobile-map
Fix mobile map
2 parents 2132f1e + ad3c82c commit 5d74a41

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

Diff for: lib/actions/map.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ export function setMapCenter(map /* MapRef */, location, zoom) {
5353
return function () {
5454
const { lat, lon } = location
5555
if (map && !isNaN(lat) && !isNaN(lon)) {
56-
map.jumpTo({ center: [lon, lat], zoom })
56+
const center = [lon, lat]
57+
// Note: passing an undefined zoom to map.jumpTo will trigger a "can't invert matrix" error.
58+
const jumpParams = zoom !== undefined ? { center, zoom } : { center }
59+
map.jumpTo(jumpParams)
5760
}
5861
}
5962
}

Diff for: lib/components/mobile/batch-results-screen.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import { Button } from 'react-bootstrap'
44
import { connect } from 'react-redux'
55
import { FormattedMessage } from 'react-intl'
66
import { ListUl } from '@styled-icons/fa-solid/ListUl'
7+
import { useMap } from 'react-map-gl'
78
import coreUtils from '@opentripplanner/core-utils'
8-
import React from 'react'
9+
import React, { useEffect } from 'react'
910
import styled, { css } from 'styled-components'
1011

1112
import * as uiActions from '../../actions/ui'
@@ -94,6 +95,12 @@ const BatchMobileResultsScreen = ({
9495
itineraryView === ItineraryView.LIST_HIDDEN
9596
const itineraryExpanded = itineraryView === ItineraryView.FULL
9697

98+
const { default: map } = useMap()
99+
// Trigger map resize when the map expanded variable changes.
100+
useEffect(() => {
101+
if (map) map.resize()
102+
}, [mapExpanded, map])
103+
97104
return (
98105
<StyledMobileContainer>
99106
<ResultsHeader />
@@ -130,7 +137,7 @@ const BatchMobileResultsScreen = ({
130137

131138
// connect to the redux store
132139

133-
const mapStateToProps = (state, ownProps) => {
140+
const mapStateToProps = (state) => {
134141
const activeSearch = getActiveSearch(state)
135142
const urlParams = coreUtils.query.getUrlParams()
136143
return {

0 commit comments

Comments
 (0)