Skip to content

Commit 2122f16

Browse files
committed
fix(BaseMap): fix issue where map recentered twice on endpoint marker drag
recentering happens in componentWillReceiveProps. on marker drag, the isFromSet and isToSet props where being updated unnecessarily. this fix changes them to strict booleans Conflicts: lib/components/map/base-map.js
1 parent 0e3a865 commit 2122f16

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

lib/components/map/base-map.js

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@ class BaseMap extends Component {
2121
if (!this.props.isFromSet) this.props.setLocation('from', location)
2222
else if (!this.props.isToSet) this.props.setLocation('to', location)
2323
}
24+
// TODO: make map controlled component
25+
_mapBoundsChanged = (e) => {
26+
// if (this.state.zoomToTarget) {
27+
// setTimeout(() => { this.setState({zoomToTarget: false}) }, 200)
28+
// return false
29+
// } else {
30+
// const zoom = e.target.getZoom()
31+
const bounds = e.target.getBounds()
32+
// if (this.props.mapState.zoom !== zoom) {
33+
// this.props.updateMapState({zoom})
34+
// }
35+
if (!bounds.equals(this.props.mapState.bounds)) {
36+
this.props.updateMapState({bounds: e.target.getBounds()})
37+
}
38+
// }
39+
}
2440
componentWillReceiveProps (nextProps) {
2541
// TODO: maybe setting bounds ought to be handled in map props...
2642
// Pan to to entire itinerary if made active (clicked)
@@ -56,7 +72,29 @@ class BaseMap extends Component {
5672
children
5773
} = this.props
5874
const position = [config.map.initLat, config.map.initLon]
59-
75+
// const position = [+mapState.lat, +mapState.lon]
76+
// const zoom = +mapState.zoom
77+
const zoom = config.map.initZoom || 13
78+
const bounds = mapState.bounds
79+
const mapProps = {
80+
ref: 'map',
81+
className: 'map',
82+
// center: position,
83+
// bounds: mapState.bounds || null,
84+
// zoom: config.initZoom,
85+
// zoom: +mapState.zoom,
86+
onClick: this._onClick
87+
// onMoveEnd: this._mapBoundsChanged,
88+
// onZoomEnd: this._mapBoundsChanged,
89+
}
90+
if (bounds) {
91+
mapProps.bounds = bounds
92+
} else if (position && zoom) {
93+
mapProps.center = position
94+
mapProps.zoom = zoom
95+
} else {
96+
console.error('no map position/bounds provided!', {position, zoom, bounds})
97+
}
6098
return (
6199
<Map
62100
ref='map'
@@ -79,8 +117,9 @@ const mapStateToProps = (state, ownProps) => {
79117
activeLeg: activeSearch && activeSearch.activeLeg,
80118
activeStep: activeSearch && activeSearch.activeStep,
81119
config: state.otp.config,
82-
isFromSet: state.otp.currentQuery.from && state.otp.currentQuery.from.lat && state.otp.currentQuery.from.lon,
83-
isToSet: state.otp.currentQuery.to && state.otp.currentQuery.to.lat && state.otp.currentQuery.to.lon,
120+
mapState: state.otp.mapState,
121+
isFromSet: state.otp.currentQuery.from && state.otp.currentQuery.from.lat !== null && state.otp.currentQuery.from.lon !== null,
122+
isToSet: state.otp.currentQuery.to && state.otp.currentQuery.to.lat !== null && state.otp.currentQuery.to.lon !== null,
84123
itinerary: getActiveItinerary(state.otp)
85124
}
86125
}

0 commit comments

Comments
 (0)