Created
November 20, 2019 08:29
-
-
Save stepankuzmin/dcd239a0d109c5599d85e8d649922b16 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| onMoveEnd = (event) => { | |
| const map = this._mapRef.current.getMap(); | |
| map.off('moveend', this.onMoveEnd); | |
| const zoom = map.getZoom(); | |
| const { lat, lng } = map.getCenter(); | |
| const viewport = { longitude: lng, latitude: lat, zoom }; | |
| this.props.onViewportChange(viewport); | |
| }; | |
| componentDidUpdate(prevProps) { | |
| const { bounds } = this.props; | |
| if (bounds !== prevProps.bounds && bounds !== null) { | |
| const map = this._mapRef.current.getMap(); | |
| map.fitBounds(bounds, { | |
| padding: { top: 100, bottom: 380, left: 50, right: 50 } | |
| }); | |
| map.on('moveend', this.onMoveEnd); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment