Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
fix(video-export): pixel ratio in preview mode regression (#3634)
Igor Dykhta6296973d7a11
diff --git a/src/components/src/modals/export-video-modal.spec.tsx b/src/components/src/modals/export-video-modal.spec.tsxindex 66c3b4b53..0afb1f6c2 100644--- a/src/components/src/modals/export-video-modal.spec.tsx+++ b/src/components/src/modals/export-video-modal.spec.tsx@@ -54,7 +54,11 @@ jest.mock('./hubble-utils', () => ({views: {}})),getTimeRangeFilterKeyframes: jest.fn(),- getAnimatableFilters: jest.fn(() => [])+ getAnimatableFilters: jest.fn(() => []),+ getResolutionSetting: jest.fn(value => {+ const [width, height] = String(value || '1280x720').split('x').map(Number);+ return {value, width, height, label: value};+ })}));import ExportVideoModalFactory from './export-video-modal';@@ -442,4 +446,30 @@ describe('ExportVideoModal', () => {expect(effects[0]).toBe(nonShadowEffect);});});++ describe('devicePixelRatio freeze', () => {+ const originalDpr = window.devicePixelRatio;++ afterEach(() => {+ Object.defineProperty(window, 'devicePixelRatio', {+ configurable: true,+ enumerable: true,+ writable: true,+ value: originalDpr+ });+ });++ test('pins devicePixelRatio to export scale and restores it on unmount', async () => {+ const {unmount} = await renderAndWaitForPanel();+ const {exportVideoWidth} = mockExportVideoPanelContainer.mock.calls[0][0];++ expect(window.devicePixelRatio).toBe(1280 / exportVideoWidth);++ window.devicePixelRatio = 1;+ expect(window.devicePixelRatio).toBe(1280 / exportVideoWidth);++ unmount();+ expect(window.devicePixelRatio).toBe(originalDpr);+ });+ });});diff --git a/src/components/src/modals/export-video-modal.tsx b/src/components/src/modals/export-video-modal.tsxindex 0ca110a6b..b184d5d92 100644--- a/src/components/src/modals/export-video-modal.tsx+++ b/src/components/src/modals/export-video-modal.tsx@@ -32,7 +32,8 @@ import {getBeforeLayerId,getHubbleDeckGlProps,getTimeRangeFilterKeyframes,- getAnimatableFilters+ getAnimatableFilters,+ getResolutionSetting} from './hubble-utils';import {useFogHeightAnimation} from './fog-height-animation';@@ -399,6 +400,34 @@ const ExportVideoModalFactory = () => {// 2D Mercator map behind/around the globe.const isGlobeEnabled = Boolean(mapState?.globe?.enabled);+ useEffect(() => {+ // Same freeze as before: hubble.gl writes window.devicePixelRatio to scale+ // the preview, then sets it to 1 during animated preview, which desyncs+ // MapLibre from the Deck overlay. Pin to the *export* scale (not native DPR)+ // so preview stays aligned and recording still uses the selected quality.+ if (isSwipeMode || isGlobeEnabled) return undefined;++ const {width} = getResolutionSetting(videoConfiguration.resolution || '');+ const scaledDpr = exportVideoWidth ? Math.max(1, width / exportVideoWidth) : 1;+ const descriptor = Object.getOwnPropertyDescriptor(window, 'devicePixelRatio');++ Object.defineProperty(window, 'devicePixelRatio', {+ configurable: true,+ get: () => scaledDpr,+ set: () => {+ // no-op: ignore hubble.gl dropping DPR to 1 during preview+ }+ });++ return () => {+ if (descriptor) {+ Object.defineProperty(window, 'devicePixelRatio', descriptor);+ } else {+ delete (window as {devicePixelRatio?: number}).devicePixelRatio;+ }+ };+ }, [isSwipeMode, isGlobeEnabled, videoConfiguration.resolution, exportVideoWidth]);+const onFilterFrameUpdate = useCallback((filterIdx: number, name: string, value: any) => {visStateActions.setFilterAnimationTime(filterIdx, name, value);