Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Increase queue, layer cache & check if animation is playing

ZachTRiced234d87fdaf6
diff --git a/web/js/animation/ui.js b/web/js/animation/ui.js
index ef867ce7c..40ec6f0d1 100644
--- a/web/js/animation/ui.js
+++ b/web/js/animation/ui.js
@@ -82,7 +82,7 @@ export function animationUi(models, ui) {
preload = {};
pastDates = {};
inQueue = {};
- queueLength = 500;
+ queueLength = 5000; // Set to large number to requests all layers up front
self.state = {
playing: false,
playIndex: self.getStartDate(),
diff --git a/web/js/map/layerbuilder.js b/web/js/map/layerbuilder.js
index ab7670f0b..6f662ddcf 100644
--- a/web/js/map/layerbuilder.js
+++ b/web/js/map/layerbuilder.js
@@ -97,23 +97,26 @@ export function mapLayerBuilder(models, config, cache, Parent) {
*/
self.closestDate = function (def, options) {
var date;
+ var animRange;
+ if (models.anim) { animRange = models.anim.rangeState; }
var dateArray = def.availableDates || [];
if (options.date) {
date = options.date;
} else {
date = models.date.selected;
}
- if (!options.precache &&
+ // Perform extensive checks before finding closest date
+ if (!options.precache && (animRange && animRange.playing === false) &&
((def.period === 'daily' && (models.date.selectedZoom > 3)) ||
(def.period === 'monthly' && (models.date.selectedZoom >= 2)) ||
(def.period === 'yearly' && (models.date.selectedZoom >= 1)))) {
- date = util.prevDateInDateRange(date, dateArray);
+ date = util.prevDateInDateRange(def, date, dateArray);
// Is current "rounded" previous date not in array of availableDates
if (date && !dateArray.includes(date)) {
// Then, update layer object with new array of dates
def.availableDates = util.datesinDateRanges(def, date, true);
- date = util.prevDateInDateRange(date, dateArray);
+ date = util.prevDateInDateRange(def, date, dateArray);
}
}
return date;
@@ -142,7 +145,7 @@ export function mapLayerBuilder(models, config, cache, Parent) {
} else {
date = models.date.selected;
}
- self.closestDate(def, options);
+ date = self.closestDate(def, options);
if (models.palettes.isActive(def.id)) {
palette = models.palettes.key(def.id);
diff --git a/web/js/util/util.js b/web/js/util/util.js
index bb94013f6..bd9347375 100644
--- a/web/js/util/util.js
+++ b/web/js/util/util.js
@@ -16,6 +16,9 @@ import Cache from 'cachai';
import closestTo from 'date-fns/closest_to';
import isBefore from 'date-fns/is_before';
import isEqual from 'date-fns/is_equal';
+import isFirstDayOfMonth from 'date-fns/is_first_day_of_month';
+import isLastDayOfMonth from 'date-fns/is_last_day_of_month';
+import lastDayOfYear from 'date-fns/last_day_of_year';
export default (function (self) {
var canvas = null;
@@ -925,14 +928,17 @@ export default (function (self) {
/**
* Find the closest previous date from an array of dates
*
+ * @param {object} def A layer definition
* @param {object} date A date to compare against the array of dates
* @param {array} dateArray An array of dates
* @return {object} The date object with normalized timeszone.
*/
- self.prevDateInDateRange = function (date, dateArray) {
+ self.prevDateInDateRange = function (def, date, dateArray) {
var currentDate = new Date(date.getTime() + (date.getTimezoneOffset() * 60000));
if (!dateArray) return date;
-
+ if ((def.period === 'monthly' && (isFirstDayOfMonth(currentDate) || isLastDayOfMonth(currentDate))) ||
+ (def.period === 'yearly' && ((currentDate.getDate() === 1 &&
+ currentDate.getMonth() === 0) || (currentDate === lastDayOfYear(currentDate))))) return date;
// Return an array of the closest available dates within the range
var closestAvailableDates = [];
lodashEach(dateArray, function(rangeDate) {