Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

fix(video-export): points in video export don't react to zoom changes (#3637)

Igor Dykhtaedd4e20c8646
diff --git a/src/components/src/modals/globe-export-video-container.tsx b/src/components/src/modals/globe-export-video-container.tsx
index 5158d9419..32665d669 100644
--- a/src/components/src/modals/globe-export-video-container.tsx
+++ b/src/components/src/modals/globe-export-video-container.tsx
@@ -546,6 +546,7 @@ export class GlobeExportVideoPanelContainer extends Component<
saving={saving}
durationMs={durationMs}
deckProps={deckProps}
+ mapProps={this.props.mapProps}
backgroundColor={this.getBackgroundColor()}
starsImage={this.areStarsEnabled() ? getStarsBackgroundImage() : null}
/>
diff --git a/src/components/src/modals/globe-export-video-preview.tsx b/src/components/src/modals/globe-export-video-preview.tsx
index fddbb189a..5d8b9313d 100644
--- a/src/components/src/modals/globe-export-video-preview.tsx
+++ b/src/components/src/modals/globe-export-video-preview.tsx
@@ -7,7 +7,7 @@ import type {Deck, DeckProps, MapViewState} from '@deck.gl/core';
import styled from 'styled-components';
import {DeckAdapter} from '@hubble.gl/core';
-import {EXPORT_DECK_DEVICE_PROPS} from './hubble-utils';
+import {EXPORT_DECK_DEVICE_PROPS, getGlobeExportLayers} from './hubble-utils';
const PreviewContainer = styled.div<{
$width: number;
@@ -38,6 +38,7 @@ export type GlobeExportVideoPreviewProps = {
durationMs: number;
/** CSS color string for the area the globe does not cover. */
backgroundColor: string;
+ mapProps?: Record<string, any>;
/** Tileable star-field data URL, matching the live globe map CSS background. */
starsImage?: string | null;
};
@@ -86,19 +87,29 @@ export class GlobeExportVideoPreview extends Component<GlobeExportVideoPreviewPr
resolution,
exportVideoWidth,
backgroundColor,
+ mapData,
+ mapProps,
starsImage
} = this.props;
const {width, height} = this._getContainer();
const deck = this.deckRef.current;
+ // Rebuild layers from the animated camera (hubble 2D: createKeplerLayers(mapData, viewState)).
+ const layers = getGlobeExportLayers(mapData, {
+ mapIndex: 0,
+ mapboxApiAccessToken: mapProps?.mapboxApiAccessToken,
+ mapboxApiUrl: mapProps?.mapboxApiUrl,
+ viewState
+ });
+
// adapter.getProps injects `_animate` (and toggles `controller` off while
- // recording) so hubble's KeplerAnimation can drive the camera. Layers,
- // views, controller bounds and initialViewState come from `deckProps`
+ // recording) so hubble's KeplerAnimation can drive the camera. Views,
+ // controller bounds and initialViewState come from `deckProps`
// (see getHubbleDeckGlProps). A controlled `viewState` keeps the preview in
// sync with the animated camera and prevents the GlobeState assert.
const adapterProps = adapter.getProps({
deck: deck as any,
- extraProps: deckProps as any
+ extraProps: {...deckProps, layers} as any
}) as any;
// Render the drawing buffer at the true export resolution regardless of the
diff --git a/src/components/src/modals/hubble-utils.ts b/src/components/src/modals/hubble-utils.ts
index 92e56b279..fd3df5fd7 100644
--- a/src/components/src/modals/hubble-utils.ts
+++ b/src/components/src/modals/hubble-utils.ts
@@ -313,8 +313,14 @@ export function getGlobeExportLayers(
{
mapIndex,
mapboxApiAccessToken,
- mapboxApiUrl
- }: {mapIndex: number; mapboxApiAccessToken?: string; mapboxApiUrl?: string}
+ mapboxApiUrl,
+ viewState
+ }: {
+ mapIndex: number;
+ mapboxApiAccessToken?: string;
+ mapboxApiUrl?: string;
+ viewState?: MapViewState;
+ }
) {
const globe = keplerState.mapState?.globe;
const globeBaseLayers = getGlobeBaseLayers({
@@ -323,12 +329,19 @@ export function getGlobeExportLayers(
mapStyleType: keplerState.mapStyle?.styleType
});
const globeTopLayers = getGlobeTopLayers({globe});
- const dataLayers = computeDeckLayers(keplerState, {
- mapIndex,
- primaryMap: mapIndex === 0,
- mapboxApiAccessToken,
- mapboxApiUrl
- });
+ // Same as hubble createKeplerLayers: fold the animated camera into mapState so
+ // zoom-dependent props (scatterplot radiusScale) update each frame.
+ const dataLayers = computeDeckLayers(
+ viewState
+ ? {...keplerState, mapState: {...keplerState.mapState, ...viewState}}
+ : keplerState,
+ {
+ mapIndex,
+ primaryMap: mapIndex === 0,
+ mapboxApiAccessToken,
+ mapboxApiUrl
+ }
+ );
return [...globeBaseLayers, ...dataLayers, ...globeTopLayers];
}
diff --git a/src/components/src/modals/swipe-export-video-preview.tsx b/src/components/src/modals/swipe-export-video-preview.tsx
index 3657f6595..a2f0beb0f 100644
--- a/src/components/src/modals/swipe-export-video-preview.tsx
+++ b/src/components/src/modals/swipe-export-video-preview.tsx
@@ -236,7 +236,8 @@ export class SwipeExportVideoPreview extends Component<
return getGlobeExportLayers(mapData, {
mapIndex,
mapboxApiAccessToken: mapProps?.mapboxApiAccessToken,
- mapboxApiUrl: mapProps?.mapboxApiUrl
+ mapboxApiUrl: mapProps?.mapboxApiUrl,
+ viewState
});
}