Interactive interface for browsing global, full-resolution satellite imagery
Init animation based on current date #1755
Benjamin King9e9bcdf96e04
diff --git a/web/js/containers/animation-widget.js b/web/js/containers/animation-widget.jsindex c11712d00..dd7afd10d 100644--- a/web/js/containers/animation-widget.js+++ b/web/js/containers/animation-widget.js@@ -25,7 +25,6 @@ import {import { getQueueLength, getMaxQueueLength } from '../modules/animation/util';import {hasSubDaily as hasSubDailySelector,- lastDate as layersLastDateTime,getLayers} from '../modules/layers/selectors';import {@@ -38,7 +37,6 @@ import {changeEndDate,toggleComponentGifActive} from '../modules/animation/actions';-import util from '../util/util';const RangeHandle = props => {const { value, offset, dragging, ...restProps } = props;diff --git a/web/js/containers/timeline/timeline.js b/web/js/containers/timeline/timeline.jsindex 7a4087d55..1940e0318 100644--- a/web/js/containers/timeline/timeline.js+++ b/web/js/containers/timeline/timeline.js@@ -527,7 +527,28 @@ class Timeline extends React.Component {draggerVisibleB});}+ static getDerivedStateFromProps(props, currentState) {+ // Update animation Date states when animation is initiated+ if (!currentState.animationEndLocationDate && !currentState.animationStartLocationDate && props.animStartLocationDate && props.animEndLocationDate) {+ let { position, transformX } = currentState;+ let { timeScale } = props;+ let startDate = props.animStartLocationDate;+ let endDate = props.animEndLocationDate;+ let options = timeScaleOptions[timeScale].timeAxis;+ let gridWidth = options.gridWidth;+ let frontDate = moment.utc(currentState.frontDate);+ let startLocation = frontDate.diff(startDate, timeScale, true) * gridWidth;+ let endLocation = frontDate.diff(endDate, timeScale, true) * gridWidth;+ return {+ animationStartLocationDate: props.animStartLocationDate,+ animationEndLocationDate: props.animEndLocationDate,+ animationStartLocation: position - startLocation + transformX,+ animationEndLocation: position - endLocation + transformX+ };+ }+ return null;+ }componentDidUpdate(prevProps, prevState) {// console.log(prevProps, prevState)// console.log(this.props, this.state)@@ -570,7 +591,6 @@ class Timeline extends React.Component {}}}-// handle draggerTimeState updates if date changesif (dateA !== prevProps.dateA && dateA !== this.state.draggerTimeState) {this.setState({@@ -750,7 +770,7 @@ class Timeline extends React.Component {hoverLinePosition={this.state.hoverLinePosition}/>- {isAnimationWidgetOpen+ {isAnimationWidgetOpen && this.state.animationStartLocation && this.state.animationStartLocationDate && this.state.animationEndLocation && this.state.animationEndLocationDate? <TimelineRangeSelectorposition={this.state.position}frontDate={this.state.frontDate}diff --git a/web/js/modules/animation/actions.js b/web/js/modules/animation/actions.jsindex f06c84ac4..6dc3e7d3a 100644--- a/web/js/modules/animation/actions.js+++ b/web/js/modules/animation/actions.js@@ -12,8 +12,10 @@ import {} from './constants';export function onActivate() {- return {- type: OPEN_ANIMATION+ return (dispatch, getState) => {+ const { compare, date } = getState();+ const dateStr = compare.isCompareA ? 'selected' : 'selectedB';+ dispatch({ type: OPEN_ANIMATION, date: date[dateStr] });};}export function onClose() {diff --git a/web/js/modules/animation/reducers.js b/web/js/modules/animation/reducers.jsindex 94486bcc7..f2057ab61 100644--- a/web/js/modules/animation/reducers.js+++ b/web/js/modules/animation/reducers.js@@ -18,7 +18,9 @@ const defaultState = {isPlaying: false,loop: false,speed: 3,- gifActive: false+ gifActive: false,+ startDate: undefined,+ endDate: undefined};export function getInitialState(config) {return lodashAssign({}, defaultState, {@@ -32,7 +34,11 @@ export function animationReducer(state = defaultState, action) {case OPEN_ANIMATION:return lodashAssign({}, state, {isActive: true,- gifActive: false+ gifActive: false,+ startDate: state.startDate+ ? state.startDate+ : util.dateAdd(action.date, 'day', -7),+ endDate: state.endDate ? state.endDate : action.date});case EXIT_ANIMATION:return lodashAssign({}, state, {diff --git a/web/js/modules/combine-reducers.js b/web/js/modules/combine-reducers.jsindex 6e09dba05..c17cb07c6 100644--- a/web/js/modules/combine-reducers.js+++ b/web/js/modules/combine-reducers.js@@ -77,7 +77,6 @@ export function getInitialState(models, config, parameters) {config,models,date: getDateInitialState(config),- animation: getAnimationInitialState(config),proj: getProjInitialState(config),layers: getLayersInitialState(config),requestedEvents: eventRequestResponse(eventsIgnoreArray),