Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
[Feat] add onViewStateChange callback to KeplerGl (#506)
Shan Hed9546db91619
diff --git a/README.md b/README.mdindex f8f3dea43..c001cac5a 100644--- a/README.md+++ b/README.md@@ -185,10 +185,17 @@ version displayed in side panel header##### `onSaveMap` (Function, optional)-- Default: `() => {}`+- Default: `undefined`Action called when click Save Map Url in side panel header.+##### `onViewStateChange` (Function, optional)++- Default: `undefined`+- Parameter: `viewState` - An updated view state object containing parameters such as longitude, latitude, zoom etc++Action triggered when map viewport is updated.+##### `getMapboxRef(mapbox, index)` (Function, optional)- Default: `undefined`diff --git a/src/components/kepler-gl.js b/src/components/kepler-gl.jsindex 4a282e4c8..6008b46e0 100644--- a/src/components/kepler-gl.js+++ b/src/components/kepler-gl.js@@ -169,6 +169,7 @@ function KeplerGlFactory(appName,version,onSaveMap,+ onViewStateChange,width,height,mapboxApiAccessToken,@@ -239,6 +240,7 @@ function KeplerGlFactory(hoverInfo,clicked,toggleMapControl: uiStateActions.toggleMapControl,+ onViewStateChange,uiStateActions,visStateActions,mapStateActionsdiff --git a/src/components/map-container.js b/src/components/map-container.jsindex 575f9923c..dd3871406 100644--- a/src/components/map-container.js+++ b/src/components/map-container.js@@ -388,12 +388,19 @@ export default function MapContainerFactory(MapPopover, MapControl) {}}+ _onViewportChange = (viewState) => {+ if (typeof this.props.onViewStateChange === 'function') {+ this.props.onViewStateChange(viewState);+ }+ this.props.mapStateActions.updateMap(viewState);+ }+render() {const {mapState, mapStyle, mapStateActions, mapLayers, layers, MapComponent,datasets, mapboxApiAccessToken, mapControls, toggleMapControl} = this.props;- const {updateMap, onMapClick} = mapStateActions;+ const {onMapClick} = mapStateActions;if (!mapStyle.bottomMapStyle) {// style not yet loaded@@ -404,7 +411,7 @@ export default function MapContainerFactory(MapPopover, MapControl) {...mapState,preserveDrawingBuffer: true,mapboxApiAccessToken,- onViewportChange: updateMap,+ onViewportChange: this._onViewportChange,transformRequest};