Created
July 26, 2017 08:43
-
-
Save ArnaudRinquin/1cffab6f5c9e1e69c602756d1f9d0263 to your computer and use it in GitHub Desktop.
react-leaflet + flyTo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component } from 'react' | |
import { connect } from 'react-redux' | |
class MapWrapper extends Component { | |
render() { | |
const mapProps = 123 // todo | |
return <LeafletMap ref={(mapEl) => this.mapEl = mapEl} {...mapProps} /> | |
} | |
componentDidMount() { | |
const { markerData } = this.props | |
if (markerData) { | |
this.flyTo(markerData) | |
} | |
} | |
componentDidUpdate(prevProps) { | |
const { markerData } = this.props | |
if (markderData !== preProps.markerData) { | |
this.flyTo(markerData) | |
} | |
} | |
flyTo(markerData) { | |
this.mapEl.flyTo(markerData) | |
} | |
} | |
export default connect(state => ({ | |
markerData: state.ui.hoveredMarkerData, | |
}))(MapWrapper) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment