Interactive interface for browsing global, full-resolution satellite imagery
handle additional intervals, move code to animatino widget
Jason Kent08d682668a01
diff --git a/web/js/components/animation-widget/play-queue.js b/web/js/components/animation-widget/play-queue.jsindex 616f45aea..c3c6e25c6 100644--- a/web/js/components/animation-widget/play-queue.js+++ b/web/js/components/animation-widget/play-queue.js@@ -42,29 +42,6 @@ class PlayAnimation extends React.Component {}}- /**- * Clear out value for time unit one step below playback interval- * This essentially snaps the playback interval to the correct value so that- * the current datetime is properly snapped to the start datetime. This avoids- * issues where the first playback is not in sync with subsequent loops due to a- * non-snapped initial current time.- *- * @param {*} date- * @param {*} interval- */- zeroForInterval(date, interval) {- switch (interval) {- case 'day':- return new Date(date.setUTCHours(0));- case 'hour':- return new Date(date.setUTCMinutes(0));- case 'minute':- return new Date(date.setUTCSeconds(0));- default:- return date;- }- }-/*** Determines whether to start at* current date or to start at the@@ -73,9 +50,8 @@ class PlayAnimation extends React.Component {* @returns {string} ISO string Date*/getStartDate() {- const { endDate, startDate, currentDate, interval } = this.props;- const zeroedDate = this.zeroForInterval(currentDate, interval);- const nextDate = this.nextDate(zeroedDate);+ const { endDate, startDate, currentDate } = this.props;+ const nextDate = this.nextDate(currentDate);if (currentDate > startDate && nextDate < endDate) {return util.toISOStringSeconds(nextDate);diff --git a/web/js/containers/animation-widget.js b/web/js/containers/animation-widget.jsindex 59400ceed..9a8ef9a68 100644--- a/web/js/containers/animation-widget.js+++ b/web/js/containers/animation-widget.js@@ -231,7 +231,7 @@ class AnimationWidget extends React.Component {);}- /*+ /*** Sets a new state to say whether or not* the animation should loop*@@ -261,7 +261,7 @@ class AnimationWidget extends React.Component {}}- /*+ /*** Changes selected default or custom interval in header and* changes left/right date arrow increments*@@ -293,7 +293,7 @@ class AnimationWidget extends React.Component {this.props.onIntervalSelect(delta, timeScale, customSelected);}- /*+ /*** update global store startDate, endDate, and isPlaying** @method onPushPlay@@ -313,7 +313,7 @@ class AnimationWidget extends React.Component {onPushPlay();}- /*+ /*** Zeroes start and end animation dates to UTC 00:00:00 for predictable animation range* subdaily intervals retain hours and minutes*@@ -346,6 +346,48 @@ 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@@ -576,6 +618,11 @@ class AnimationWidget extends React.Component {interval,delta);+ const snappedCurrentDate = this.zeroForInterval(+ currentDate,+ startDate,+ interval+ );if (!isActive) {return null;@@ -587,12 +634,12 @@ class AnimationWidget extends React.Component {<ErrorBoundary>{isPlaying && (<PlayQueue- endDate={endDate}loop={looping}isPlaying={isPlaying}- currentDate={currentDate}canPreloadAll={queueLength <= maxLength}+ currentDate={snappedCurrentDate}startDate={startDate}+ endDate={endDate}hasCustomPalettes={hasCustomPalettes}map={map}maxQueueLength={maxLength}diff --git a/web/js/util/util.js b/web/js/util/util.jsindex 3b7b18c23..08f63cf73 100644--- a/web/js/util/util.js+++ b/web/js/util/util.js@@ -404,10 +404,7 @@ export default (function(self) {* @return {Date} the date object*/self.clearTimeUTC = function(date) {- date.setUTCHours(0);- date.setUTCMinutes(0);- date.setUTCSeconds(0);- date.setUTCMilliseconds(0);+ date.setUTCHours(0, 0, 0, 0);return date;};