Interactive interface for browsing global, full-resolution satellite imagery
#2399 when starting animation playback, always snap the first playback step to a proper one based on start date, interval, and delta so that subsequent playthrougs have matching steps. fixes a bug where animation hangs when it should loop and where first playback steps don't match subsequent playback fsteps
Jason Kent8aabe3d4fdcf
diff --git a/web/js/containers/animation-widget.js b/web/js/containers/animation-widget.jsindex 9a8ef9a68..5540c677f 100644--- a/web/js/containers/animation-widget.js+++ b/web/js/containers/animation-widget.js@@ -29,7 +29,11 @@ import {timeScaleToNumberKey,customModalType} from '../modules/date/constants';-import { getQueueLength, getMaxQueueLength } from '../modules/animation/util';+import {+ getQueueLength,+ getMaxQueueLength,+ snapToIntervalDelta+} from '../modules/animation/util';import {hasSubDaily as hasSubDailySelector,getLayers@@ -272,7 +276,6 @@ class AnimationWidget extends React.Component {** @return {void}*/-onIntervalSelect(timeScale, openModal) {let delta;const { customInterval, customDelta } = this.props;@@ -346,48 +349,6 @@ class AnimationWidget extends React.Component {};}- /**- * Clear out, or "snap", the value for the time unit one step below playback interval.- * For example, clear hours if interval is set to day.- * This essentially snaps the current date time to: (startDate + (n * interval))- * so that the current datetime is properly snapped to the start datetime upon looping.- * This avoids issues where the first playback is not in sync with subsequent playbacks- * due to an offset initial current datetime.- *- * @param {*} currentDate - current app date/time- * @param {*} startDate - animation start date- * @param {*} interval - animation interval- * @returns {date}- */- zeroForInterval(currentDate, startDate, interval) {- let adjustedDate;- let monthOfYear;- let dayOfMonth;- let minutes;-- switch (interval) {- case 'year':- monthOfYear = startDate.getUTCMonth();- dayOfMonth = startDate.getUTCDate();- adjustedDate = new Date(currentDate.setUTCMonth(monthOfYear));- adjustedDate = new Date(adjustedDate.setUTCDate(dayOfMonth));- return new Date(adjustedDate.setUTCHours(0, 0, 0, 0));- case 'month':- dayOfMonth = startDate.getUTCDate();- adjustedDate = new Date(currentDate.setUTCDate(dayOfMonth));- return new Date(adjustedDate.setUTCHours(0, 0, 0, 0));- case 'day':- return new Date(currentDate.setUTCHours(0, 0, 0, 0));- case 'hour':- minutes = startDate.getUTCMinutes();- return new Date(currentDate.setUTCMinutes(minutes, 0, 0));- case 'minute':- return new Date(currentDate.setUTCSeconds(0, 0));- default:- return currentDate;- }- }-/*** @desc show/hide custom interval modal* @param {Boolean} isOpen@@ -618,10 +579,16 @@ class AnimationWidget extends React.Component {interval,delta);- const snappedCurrentDate = this.zeroForInterval(++ console.log('start:', startDate);+ console.log(' end:', endDate);++ const snappedCurrentDate = snapToIntervalDelta(currentDate,startDate,- interval+ endDate,+ interval,+ delta);if (!isActive) {diff --git a/web/js/modules/animation/util.js b/web/js/modules/animation/util.jsindex c9e578620..6e2855ab8 100644--- a/web/js/modules/animation/util.js+++ b/web/js/modules/animation/util.js@@ -2,6 +2,42 @@ import { round as lodashRound, get as lodashGet } from 'lodash';import canvg from 'canvg-browser';import util from '../../util/util';import update from 'immutability-helper';+import moment from 'moment';++/**+ * Snap the value for the date/time to the closest previous playback step so that+ * th date/time properly syncs when looping. This avoids issues where the+ * first playback is not in sync with subsequent playbacks due to the current+ * time not being snapped to a proper step (when calculated from startDate).+ *+ * @param {*} currDate+ * @param {*} startDate+ * @param {*} endDate+ * @param {*} interval+ * @param {*} delta+ */+export function snapToIntervalDelta(currDate, startDate, endDate, interval, delta) {+ // moment pluralizes: 'days', 'hours', etc+ const units = interval + 's';+ const dateArray = [];+ let tempDate = startDate;+ let currentDate, prevMoment, nextMoment;++ while (tempDate <= endDate) {+ prevMoment = moment.utc(tempDate);+ nextMoment = moment.utc(tempDate).add(delta, units);+ if (currDate >= prevMoment && currDate <= nextMoment) {+ currentDate = new Date(prevMoment);+ }+ dateArray.push(tempDate);+ tempDate = new Date(nextMoment);+ }++ console.log(dateArray);+ console.log('NEW CURRENT:', currentDate || startDate);+ console.log('*******************************************************');+ return currentDate || startDate;+}export function getStampProps(stampWidthRatio,@@ -42,6 +78,7 @@ export function getStampProps(}return { stampHeight: stampHeight, dateStamp: dateStamp };}+export function svgToPng(svgURL, stampHeight) {var newImage;var canvasEl = document.createElement('canvas');@@ -58,6 +95,7 @@ export function svgToPng(svgURL, stampHeight) {return newImage;}+/*** Returns the queueLength based on the play speed selected* @method getMaxQueueLength@@ -86,6 +124,7 @@ export function getMaxQueueLength(speed) {}return queueLength;}+/** default queueLength*@@ -111,6 +150,7 @@ export function getQueueLength(startDate, endDate, speed, interval, delta) {}return i;}+export function mapLocationToAnimationState(parameters,stateFromLocation,