Skip to content

Instantly share code, notes, and snippets.

@ArnaudRinquin
Created July 26, 2017 08:43
Show Gist options
  • Save ArnaudRinquin/1cffab6f5c9e1e69c602756d1f9d0263 to your computer and use it in GitHub Desktop.
Save ArnaudRinquin/1cffab6f5c9e1e69c602756d1f9d0263 to your computer and use it in GitHub Desktop.
react-leaflet + flyTo
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