@@ -21,6 +21,22 @@ class BaseMap extends Component {
21
21
if ( ! this . props . isFromSet ) this . props . setLocation ( 'from' , location )
22
22
else if ( ! this . props . isToSet ) this . props . setLocation ( 'to' , location )
23
23
}
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
+ }
24
40
componentWillReceiveProps ( nextProps ) {
25
41
// TODO: maybe setting bounds ought to be handled in map props...
26
42
// Pan to to entire itinerary if made active (clicked)
@@ -56,7 +72,29 @@ class BaseMap extends Component {
56
72
children
57
73
} = this . props
58
74
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
+ }
60
98
return (
61
99
< Map
62
100
ref = 'map'
@@ -79,8 +117,9 @@ const mapStateToProps = (state, ownProps) => {
79
117
activeLeg : activeSearch && activeSearch . activeLeg ,
80
118
activeStep : activeSearch && activeSearch . activeStep ,
81
119
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 ,
84
123
itinerary : getActiveItinerary ( state . otp )
85
124
}
86
125
}
0 commit comments