Skip to content

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

[Enhancement] add toggleLayerAnimationControl action (#1537)

Shan He29cf0829e741
diff --git a/src/actions/vis-state-actions.d.ts b/src/actions/vis-state-actions.d.ts
index cc5593eeb..fa8f00362 100644
--- a/src/actions/vis-state-actions.d.ts
+++ b/src/actions/vis-state-actions.d.ts
@@ -292,12 +292,13 @@ export function updateLayerAnimationSpeed(
speed: number
): Merge<UpdateLayerAnimationSpeedUpdaterAction, {type: ActionTypes.UPDATE_LAYER_ANIMATION_SPEED}>;
-export type ToggleLayerAnimationUpdaterAction = {
- idx;
-};
-export function toggleLayerAnimation(
- idx: number
-): Merge<ToggleLayerAnimationUpdaterAction, {type: ActionTypes.TOGGLE_LAYER_ANIMATION}>;
+export type ToggleLayerAnimationUpdaterAction = {};
+export function toggleLayerAnimation():
+ Merge<ToggleLayerAnimationUpdaterAction, {type: ActionTypes.TOGGLE_LAYER_ANIMATION}>;
+
+export type ToggleLayerAnimationControlUpdaterAction = {};
+export function toggleLayerAnimationControl():
+ Merge<ToggleLayerAnimationControlUpdaterAction, {type: ActionTypes.TOGGLE_LAYER_ANIMATION_CONTROL}>;
export type EnlargeFilterUpdaterAction = {
idx: number;
diff --git a/src/actions/vis-state-actions.js b/src/actions/vis-state-actions.js
index 01cef993d..a0ff67681 100644
--- a/src/actions/vis-state-actions.js
+++ b/src/actions/vis-state-actions.js
@@ -499,12 +499,32 @@ export function updateLayerAnimationSpeed(speed) {
};
}
+/**
+ * start end end layer animation
+ * @memberof visStateActions
+ * @type {typeof import('./vis-state-actions').toggleLayerAnimation}
+ * @returns action
+ * @public
+ */
export function toggleLayerAnimation() {
return {
type: ActionTypes.TOGGLE_LAYER_ANIMATION
};
}
+/**
+ * hide and show layer animation control
+ * @memberof visStateActions
+ * @type {typeof import('./vis-state-actions').toggleLayerAnimationControl}
+ * @returns action
+ * @public
+ */
+export function toggleLayerAnimationControl() {
+ return {
+ type: ActionTypes.TOGGLE_LAYER_ANIMATION_CONTROL
+ };
+}
+
/**
* Show larger time filter at bottom for time playback (apply to time filter only)
* @memberof visStateActions
diff --git a/src/components/bottom-widget.js b/src/components/bottom-widget.js
index a0f3c9920..6e176c2b6 100644
--- a/src/components/bottom-widget.js
+++ b/src/components/bottom-widget.js
@@ -124,6 +124,8 @@ BottomWidgetFactory.deps = [
FilterAnimationControllerFactory,
LayerAnimationControllerFactory
];
+
+/* eslint-disable complexity */
export default function BottomWidgetFactory(
TimeWidget,
AnimationControl,
@@ -165,7 +167,8 @@ export default function BottomWidgetFactory(
Array.isArray(animationConfig.domain) && Number.isFinite(animationConfig.currentTime);
// if animation control is showing, hide time display in time slider
const showFloatingTimeDisplay = !animatableLayer.length;
- const showAnimationControl = animatableLayer.length && readyToAnimation;
+ const showAnimationControl =
+ animatableLayer.length && readyToAnimation && !animationConfig.hideControl;
const showTimeWidget = enlargedFilterIdx > -1 && Object.keys(datasets).length > 0;
// if filter is not animating, pass in enlarged filter here because
@@ -236,3 +239,4 @@ export default function BottomWidgetFactory(
return BottomWidget;
}
+/* eslint-enable complexity */
diff --git a/src/components/common/time-slider-marker.js b/src/components/common/time-slider-marker.js
index 26d9b8ee6..536ffb5ef 100644
--- a/src/components/common/time-slider-marker.js
+++ b/src/components/common/time-slider-marker.js
@@ -19,7 +19,7 @@
// THE SOFTWARE.
import React, {useRef, useEffect, useMemo} from 'react';
-import moment from 'moment';
+import moment from 'moment-timezone';
import PropTypes from 'prop-types';
import {scaleUtc} from 'd3-scale';
import {select} from 'd3-selection';
diff --git a/src/constants/action-types.d.ts b/src/constants/action-types.d.ts
index 80a97488f..6052500fa 100644
--- a/src/constants/action-types.d.ts
+++ b/src/constants/action-types.d.ts
@@ -40,6 +40,7 @@ export type ActionType = {
UPDATE_LAYER_ANIMATION_SPEED: string;
TOGGLE_LAYER_CONFIG_ACTIVE: string;
TOGGLE_LAYER_ANIMATION: string;
+ TOGGLE_LAYER_ANIMATION_CONTROL: string;
ENLARGE_FILTER: string;
TOGGLE_FILTER_FEATURE: string;
SET_VISIBLE_LAYERS_FOR_MAP: string;
diff --git a/src/constants/action-types.js b/src/constants/action-types.js
index d7afbb330..3f0f5aabc 100644
--- a/src/constants/action-types.js
+++ b/src/constants/action-types.js
@@ -91,6 +91,7 @@ const ActionTypes = {
UPDATE_ANIMATION_SPEED: `${ACTION_PREFIX}UPDATE_ANIMATION_SPEED`,
UPDATE_LAYER_ANIMATION_SPEED: `${ACTION_PREFIX}UPDATE_LAYER_ANIMATION_SPEED`,
TOGGLE_LAYER_ANIMATION: `${ACTION_PREFIX}TOGGLE_LAYER_ANIMATION`,
+ TOGGLE_LAYER_ANIMATION_CONTROL: `${ACTION_PREFIX}TOGGLE_LAYER_ANIMATION_CONTROL`,
TOGGLE_LAYER_CONFIG_ACTIVE: `${ACTION_PREFIX}TOGGLE_LAYER_CONFIG_ACTIVE`,
ENLARGE_FILTER: `${ACTION_PREFIX}ENLARGE_FILTER`,
TOGGLE_FILTER_FEATURE: `${ACTION_PREFIX}TOGGLE_FILTER_FEATURE`,
diff --git a/src/reducers/vis-state-updaters.d.ts b/src/reducers/vis-state-updaters.d.ts
index 1b61316d0..8c87cc36d 100644
--- a/src/reducers/vis-state-updaters.d.ts
+++ b/src/reducers/vis-state-updaters.d.ts
@@ -177,6 +177,8 @@ export type AnimationConfig = {
timeFormat?: string | null;
// custom ui input
timezone?: string | null;
+ // hide or show control
+ hideControl?: boolean;
};
export type BaseInteraction = {
@@ -321,6 +323,10 @@ export function toggleLayerAnimationUpdater(
state: VisState,
action: VisStateActions.ToggleLayerAnimationUpdaterAction
): VisState;
+export function toggleLayerAnimationControlUpdater(
+ state: VisState,
+ action: VisStateActions.ToggleLayerAnimationControlUpdaterAction
+): VisState;
export function interactionConfigChangeUpdater(
state: VisState,
action: VisStateActions.InteractionConfigChangeUpdaterAction
diff --git a/src/reducers/vis-state-updaters.js b/src/reducers/vis-state-updaters.js
index 670ea0118..9082efbf3 100644
--- a/src/reducers/vis-state-updaters.js
+++ b/src/reducers/vis-state-updaters.js
@@ -780,6 +780,21 @@ export const toggleLayerAnimationUpdater = state => ({
isAnimating: !state.animationConfig.isAnimating
}
});
+
+/**
+ * Hide and show layer animation control
+ * @memberof visStateUpdaters
+ * @type {typeof import('./vis-state-updaters').toggleLayerAnimationControlUpdater}
+ * @public
+ */
+export const toggleLayerAnimationControlUpdater = state => ({
+ ...state,
+ animationConfig: {
+ ...state.animationConfig,
+ hideControl: !state.animationConfig.hideControl
+ }
+});
+
/**
* Change filter animation speed
* @memberof visStateUpdaters
diff --git a/src/reducers/vis-state.js b/src/reducers/vis-state.js
index c9c675c46..5e842f088 100644
--- a/src/reducers/vis-state.js
+++ b/src/reducers/vis-state.js
@@ -55,6 +55,8 @@ const actionHandler = {
[ActionTypes.TOGGLE_LAYER_ANIMATION]: visStateUpdaters.toggleLayerAnimationUpdater,
+ [ActionTypes.TOGGLE_LAYER_ANIMATION_CONTROL]: visStateUpdaters.toggleLayerAnimationControlUpdater,
+
[ActionTypes.LOAD_FILES]: visStateUpdaters.loadFilesUpdater,
[ActionTypes.LOAD_FILES_ERR]: visStateUpdaters.loadFilesErrUpdater,