Skip to content

Instantly share code, notes, and snippets.

@stepankuzmin
Created November 20, 2019 08:29
Show Gist options
  • Save stepankuzmin/dcd239a0d109c5599d85e8d649922b16 to your computer and use it in GitHub Desktop.
Save stepankuzmin/dcd239a0d109c5599d85e8d649922b16 to your computer and use it in GitHub Desktop.
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