Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

only update every 15 minutes since updates can make timeline look jumpy. make sure it's safe to update before doing so by checking for user interaction and waiting

Jason Kentc19a9d096570
diff --git a/web/js/components/timeline/timeline-axis/timeline-axis.js b/web/js/components/timeline/timeline-axis/timeline-axis.js
index b3ef31768..02d313297 100644
--- a/web/js/components/timeline/timeline-axis/timeline-axis.js
+++ b/web/js/components/timeline/timeline-axis/timeline-axis.js
@@ -500,7 +500,7 @@ class TimelineAxis extends Component {
// update scale if end time limit has changed (e.g. time has elapsed since the app was started)
if (timelineEndDateLimit !== prevProps.timelineEndDateLimit) {
- this.updateScale(draggerDate, timeScale, null, 0.8, true);
+ this.updateScale(draggerDate, timeScale, null, null, true);
}
// handle switching A/B dragger axis focus if switched from A/B sidebar tabs
diff --git a/web/js/containers/timeline/timeline.js b/web/js/containers/timeline/timeline.js
index 63041ad35..e8eae43b7 100644
--- a/web/js/containers/timeline/timeline.js
+++ b/web/js/containers/timeline/timeline.js
@@ -693,18 +693,6 @@ class Timeline extends React.Component {
}
}
- /**
- * Compare minute values of appNow and current time.
- * Update appNow when there is a change.
- */
- checkAndUpdateAppNow() {
- const { appNow, updateAppNow } = this.props;
- const currentTime = new Date();
- if (currentTime.getMinutes() !== appNow.getMinutes()) {
- updateAppNow(currentTime);
- }
- }
-
/**
* @desc update dragger time state
* @param {String} date
@@ -723,6 +711,36 @@ class Timeline extends React.Component {
}
}
+ /**
+ *
+ */
+ checkAndUpdateAppNow() {
+ const { updateAppNow } = this.props;
+ const self = this;
+ const ensureCanUpdate = function () {
+ return new Promise(function(resolve, reject) {
+ (function waitForSafeUpdate() {
+ const {
+ isTimelineDragging,
+ isDraggerDragging,
+ isAnimationDraggerDragging,
+ isAnimationPlaying
+ } = self.state;
+ const userIsInteracting = isTimelineDragging || isDraggerDragging || isAnimationDraggerDragging;
+ const canUpdate = !userIsInteracting && !isAnimationPlaying;
+ if (canUpdate) {
+ return resolve();
+ }
+ setTimeout(waitForSafeUpdate, 1000);
+ })();
+ });
+ };
+
+ ensureCanUpdate().then(() => {
+ updateAppNow(new Date());
+ });
+ }
+
componentDidMount() {
document.addEventListener('keydown', this.handleKeyDown);
document.addEventListener('keyup', this.handleKeyUp);
@@ -731,8 +749,7 @@ class Timeline extends React.Component {
document.querySelector('.timeline-container').addEventListener('wheel', preventDefaultFunc, { passive: false });
this.checkAndUpdateAppNow = this.checkAndUpdateAppNow.bind(this);
- // Check every 5 seconds to see if we need to update appNow
- this.appNowUpdateInterval = setInterval(this.checkAndUpdateAppNow, 5000);
+ this.appNowUpdateInterval = setInterval(this.checkAndUpdateAppNow, 60000 * 15);
this.setInitialState();
}