Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] Avoid confusion in viewstate context #2361

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/components/src/map-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,7 @@ export default function MapContainerFactory(
const {
mapStyle,
visState,
mapState,
visStateActions,
mapboxApiAccessToken,
mapboxApiUrl,
Expand All @@ -716,7 +717,8 @@ export default function MapContainerFactory(
const isEditorDrawingMode = EditorLayerUtils.isDrawingActive(editorMenuActive, editor.mode);

const internalViewState = this.context?.getInternalViewState(index);
const viewport = getViewportFromMapState(internalViewState);
const internalMapState = {...mapState, ...internalViewState};
const viewport = getViewportFromMapState(internalMapState);

const editorFeatureSelectedIndex = this.selectedPolygonIndexSelector(this.props);

Expand All @@ -726,7 +728,7 @@ export default function MapContainerFactory(
const deckGlLayers = generateDeckGLLayersMethod(
{
visState,
mapState: internalViewState,
mapState: internalMapState,
mapStyle
},
{
Expand Down
3 changes: 2 additions & 1 deletion src/components/src/map-view-state-context.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, {useState, useEffect, createContext} from 'react';
import isEqual from 'lodash.isequal';
import pick from 'lodash.pick';
import {pickViewportPropsFromMapState} from '@kepler.gl/reducers';

import {MapState} from '@kepler.gl/types';

Expand Down Expand Up @@ -38,7 +39,7 @@ export const MapViewStateContextProvider = ({
}
} else {
if (hasChanged(primaryState, mapState)) {
setViewStates([mapState]);
setViewStates([pickViewportPropsFromMapState(mapState)] as MapState[]);
}
}
// Only update internalViewState when viewState changes
Expand Down
2 changes: 1 addition & 1 deletion src/reducers/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export * from './provider-state';
export * from './ui-state';
export * from './map-state';
export {getInitialInputStyle, loadMapStylesUpdater, INITIAL_MAP_STYLE} from './map-style-updaters';
export {fitBoundsUpdater, INITIAL_MAP_STATE} from './map-state-updaters';
export {fitBoundsUpdater, pickViewportPropsFromMapState, INITIAL_MAP_STATE} from './map-state-updaters';

// Helpers
export * from './composer-helpers';
Expand Down
8 changes: 4 additions & 4 deletions src/reducers/src/map-state-updaters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,9 @@ export const toggleSplitMapViewportUpdater = (
// if current viewport is synced, and we are unsyncing it
// or already in unsynced mode and NOT toggling locked zoom
// make a fresh copy of the current viewport object, assign it to splitMapViewports[]
// getViewportFromMapState is called twice to avoid memory allocation conflicts
const leftViewport = getViewportFromMapState(newMapState);
const rightViewport = getViewportFromMapState(newMapState);
// pickViewportPropsFromMapState is called twice to avoid memory allocation conflicts
const leftViewport = pickViewportPropsFromMapState(newMapState);
const rightViewport = pickViewportPropsFromMapState(newMapState);
newMapState.splitMapViewports = [leftViewport, rightViewport];
}

Expand Down Expand Up @@ -468,7 +468,7 @@ function updateViewportBasedOnBounds(state: MapState, newMapState: MapState) {
return newMapState;
}

function getViewportFromMapState(state) {
export function pickViewportPropsFromMapState(state: MapState): Viewport {
return pick(state, [
'width',
'height',
Expand Down