|
1 |
| -import objectPath from 'object-path' |
2 | 1 | import React, { Component, PropTypes } from 'react'
|
3 | 2 | import { connect } from 'react-redux'
|
4 | 3 |
|
5 | 4 | import { Map, TileLayer, LayersControl, Popup, Marker } from 'react-leaflet'
|
| 5 | +import ContainerDimensions from 'react-container-dimensions' |
6 | 6 |
|
7 | 7 | import { setLocation } from '../../actions/map'
|
8 | 8 | import Icon from '../narrative/icon'
|
@@ -156,18 +156,8 @@ class BaseMap extends Component {
|
156 | 156 | })
|
157 | 157 | }
|
158 | 158 |
|
159 |
| - resized () { |
160 |
| - this.refs.map.leafletElement.invalidateSize() |
161 |
| - if (this.props.itinerary) { |
162 |
| - this.refs.map && |
163 |
| - this.refs.map.leafletElement.fitBounds(getItineraryBounds(this.props.itinerary), { |
164 |
| - padding: [3, 3] |
165 |
| - }) |
166 |
| - } |
167 |
| - } |
168 |
| - |
169 | 159 | render () {
|
170 |
| - const { config, children, diagramLeg, elevationPoint } = this.props |
| 160 | + const { config, children, diagramLeg, elevationPoint, width, height } = this.props |
171 | 161 | const { baseLayers } = this.props.config.map
|
172 | 162 |
|
173 | 163 | const userControlledOverlays = []
|
@@ -230,6 +220,7 @@ class BaseMap extends Component {
|
230 | 220 | ref='map'
|
231 | 221 | className='map'
|
232 | 222 | center={center}
|
| 223 | + style={{ width, height }} |
233 | 224 | zoom={config.map.initZoom || 13}
|
234 | 225 | onClick={this._onLeftClick}
|
235 | 226 | onContextMenu={this._onRightClick}
|
@@ -301,6 +292,22 @@ class BaseMap extends Component {
|
301 | 292 | }
|
302 | 293 | }
|
303 | 294 |
|
| 295 | +// ContainerDimensions-wrapped BaseMap |
| 296 | + |
| 297 | +class MapContainer extends Component { |
| 298 | + render () { |
| 299 | + return ( |
| 300 | + <ContainerDimensions> |
| 301 | + {({ width, height }) => { |
| 302 | + // Do not render map if width or height is undefined or 0 |
| 303 | + if (!width || !height) return null |
| 304 | + return <BaseMap width={width} height={height} {...this.props} /> |
| 305 | + }} |
| 306 | + </ContainerDimensions> |
| 307 | + ) |
| 308 | + } |
| 309 | +} |
| 310 | + |
304 | 311 | // connect to the redux store
|
305 | 312 |
|
306 | 313 | const mapStateToProps = (state, ownProps) => {
|
@@ -329,7 +336,4 @@ const mapDispatchToProps = {
|
329 | 336 | setLocation
|
330 | 337 | }
|
331 | 338 |
|
332 |
| -// allow access to the wrapped BaseMap (for access to resized()) |
333 |
| -export default connect(mapStateToProps, mapDispatchToProps, null, { |
334 |
| - withRef: true |
335 |
| -})(BaseMap) |
| 339 | +export default connect(mapStateToProps, mapDispatchToProps)(MapContainer) |
0 commit comments