Interactive interface for browsing global, full-resolution satellite imagery
Make animation permalink work #1623 #1622
Benjamin King0edf26e3f399
diff --git a/web/js/components/animation-widget/play-queue.js b/web/js/components/animation-widget/play-queue.jsindex bac3e7b00..85ffae7f2 100644--- a/web/js/components/animation-widget/play-queue.js+++ b/web/js/components/animation-widget/play-queue.js@@ -508,7 +508,6 @@ class PlayAnimation extends React.Component {this.shiftCache();return this.checkQueue(queueLength, this.currentPlayingDate);}-this.checkQueue(queueLength, this.currentPlayingDate);this.interval = setTimeout(player, 1000 / this.props.speed);};diff --git a/web/js/containers/tour.js b/web/js/containers/tour.jsindex c0e14c9d1..84d3524e6 100644--- a/web/js/containers/tour.js+++ b/web/js/containers/tour.js@@ -75,8 +75,13 @@ class Tour extends React.Component {});this.props.selectTour(currentStoryId);this.fetchMetadata(currentStory, 0);+ const storyStep = currentStory.steps[0];+ const transition = getTransitionAttr(+ storyStep.transition.element,+ storyStep.transition.action+ );this.props.processStepLink(- currentStory.steps[0]['stepLink'] + '&tr=' + currentStoryId+ storyStep['stepLink'] + '&tr=' + currentStoryId + transition);}fetchMetadata(currentStory, stepIndex) {@@ -156,8 +161,16 @@ class Tour extends React.Component {let newStep = currentStep + 1;this.fetchMetadata(currentStory, currentStep);this.setState({ currentStep: newStep });+ let storyStep = currentStory.steps[newStep - 1];+ const transition = getTransitionAttr(+ storyStep.transition.element,+ storyStep.transition.action+ );this.props.processStepLink(- currentStory.steps[newStep - 1]['stepLink'] + '&tr=' + currentStoryId+ currentStory.steps[newStep - 1]['stepLink'] ++ '&tr=' ++ currentStoryId ++ transition);}if (currentStep + 1 === totalSteps + 1) {@@ -172,8 +185,16 @@ class Tour extends React.Component {let newStep = currentStep - 1;this.fetchMetadata(currentStory, newStep - 1);this.setState({ currentStep: newStep });+ const storyStep = currentStory.steps[newStep - 1];+ const transition = getTransitionAttr(+ storyStep.transition.element,+ storyStep.transition.action+ );this.props.processStepLink(- currentStory.steps[newStep - 1]['stepLink'] + '&tr=' + currentStoryId+ currentStory.steps[newStep - 1]['stepLink'] ++ '&tr=' ++ currentStoryId ++ transition);} else {this.setState({@@ -336,6 +357,12 @@ function mapStateToProps(state) {showTour};}+const getTransitionAttr = function(el, action) {+ if (el === 'animation' && action === 'play') {+ return '&playanim=true';+ }+ return '';+};const hideTour = function(e) {var hideTour = localStorage.getItem('hideTour');// Checkbox to "hide tour modal until a new story has been added" has been checkeddiff --git a/web/js/location.js b/web/js/location.jsindex adad0db20..0d85a7ca4 100644--- a/web/js/location.js+++ b/web/js/location.js@@ -16,6 +16,7 @@ import {import { resetLayers } from './modules/layers/selectors';import { eventsReducerState } from './modules/natural-events/reducers';import { mapLocationToPaletteState } from './modules/palettes/util';+import { mapLocationToAnimationState } from './modules/animation/util';import util from './util/util';import update from 'immutability-helper';@@ -53,6 +54,12 @@ export function mapLocationToState(state, location) {state,config);+ stateFromLocation = mapLocationToAnimationState(+ parameters,+ stateFromLocation,+ state,+ config+ );// one level deep merge of newState with defaultStatefor (var key in stateFromLocation) {const obj = lodashAssign({}, state[key], stateFromLocation[key]);@@ -254,6 +261,46 @@ const getParameters = function(config, parameters) {stateKey: 'tour.selected',initialState: ''},+ al: {+ stateKey: 'animation.loop',+ initialState: false,+ type: 'bool'+ },+ as: {+ stateKey: 'animation.startDate',+ initialState: util.dateAdd(now, 'day', -7),+ type: 'date',+ options: {+ serialize: serializeDate,+ parse: tryCatchDate+ }+ },+ ae: {+ stateKey: 'animation.endDate',+ initialState: now,+ type: 'date',+ options: {+ serialize: serializeDate,+ parse: tryCatchDate+ }+ },+ av: {+ stateKey: 'animation.speed',+ initialState: 3,+ type: 'number'+ },+ ab: {+ stateKey: 'animation.isActive',+ initialState: false,+ options: {+ serialize: boo => {+ return boo ? 'on' : undefined;+ },+ parse: str => {+ return str === 'on';+ }+ }+ },download: {stateKey: 'data.selectedProduct',initialState: '',diff --git a/web/js/modules/animation/util.js b/web/js/modules/animation/util.jsindex 6290109ee..80acb2d8a 100644--- a/web/js/modules/animation/util.js+++ b/web/js/modules/animation/util.js@@ -5,6 +5,7 @@ import {} from 'lodash';import canvg from 'canvg-browser';import util from '../../util/util';+import update from 'immutability-helper';export function getAnimationParameterSetup(parameters,@@ -210,3 +211,16 @@ export function getQueueLength(startDate, endDate, speed, interval, delta) {}return i;}+export function mapLocationToAnimationState(+ parameters,+ stateFromLocation,+ state,+ config+) {+ if (parameters.playanim && parameters.ab) {+ stateFromLocation = update(stateFromLocation, {+ animation: { isPlaying: { $set: true } }+ });+ }+ return stateFromLocation;+}