Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Changed auto delta searching calculation (#6454)

christof-wittreichc69bc16872f5
diff --git a/web/js/modules/date/util.js b/web/js/modules/date/util.js
index 545ebfeb1..2f233066f 100644
--- a/web/js/modules/date/util.js
+++ b/web/js/modules/date/util.js
@@ -586,7 +586,10 @@ export function getNextImageryDelta(layers, date, signConstant) {
const obj = dateRanges[j];
const startDateObj = new Date(obj.startDate);
const endDateObj = new Date(obj.endDate);
- const minDelta = Number(obj.dateInterval) === 1 ? 60 : Number(obj.dateInterval);
+ const exactDateInterval = ((endDateObj - startDateObj) / 1000) / 60;
+ const correctedDateInterval = Math.floor(exactDateInterval) === Number(obj.dateInterval)
+ ? Math.ceil(exactDateInterval) : Number(obj.dateInterval);
+ const minDelta = Number(obj.dateInterval) === 1 ? 60 : correctedDateInterval;
if (dateAObj < startDateObj) {
const possibleDelta = Math.ceil(((startDateObj - dateAObj) / 1000) / 60);
if (possibleDelta >= 1) {
@@ -597,10 +600,8 @@ export function getNextImageryDelta(layers, date, signConstant) {
}
if (dateAObj < endDateObj) {
const possibleDate = new Date(dateAObj.getTime() + (minDelta * 60000));
- const possibleDelta = possibleDate > endDateObj
- ? Math.floor(((endDateObj - dateAObj) / 1000) / 60) : minDelta;
- if (possibleDelta >= minDelta && possibleDate.getTime() !== endDateObj.getTime()) {
- delta = possibleDelta;
+ if (possibleDate <= endDateObj && possibleDate.getTime() !== endDateObj.getTime()) {
+ delta = minDelta;
hasDeltaChanged = true;
break;
}
@@ -622,7 +623,10 @@ export function getNextImageryDelta(layers, date, signConstant) {
const obj = [...dateRanges].reverse()[j];
const startDateObj = new Date(obj.startDate);
const endDateObj = new Date(obj.endDate);
- const minDelta = Number(obj.dateInterval) === 1 ? 60 : Number(obj.dateInterval);
+ const exactDateInterval = ((endDateObj - startDateObj) / 1000) / 60;
+ const correctedDateInterval = Math.floor(exactDateInterval) === Number(obj.dateInterval)
+ ? Math.ceil(exactDateInterval) : Number(obj.dateInterval);
+ const minDelta = Number(obj.dateInterval) === 1 ? 60 : correctedDateInterval;
if (dateAObj > endDateObj) {
const possibleDelta = Math.ceil(((dateAObj - endDateObj) / 1000) / 60);
if (possibleDelta >= minDelta) {
@@ -633,10 +637,8 @@ export function getNextImageryDelta(layers, date, signConstant) {
}
if (dateAObj > startDateObj) {
const possibleDate = new Date(dateAObj.getTime() - (minDelta * 60000));
- const possibleDelta = possibleDate < startDateObj
- ? Math.floor(((dateAObj - startDateObj) / 1000) / 60) : minDelta;
- if (possibleDelta >= minDelta && possibleDate.getTime() !== startDateObj.getTime()) {
- delta = possibleDelta;
+ if (possibleDate >= startDateObj && possibleDate.getTime() !== startDateObj.getTime()) {
+ delta = minDelta;
hasDeltaChanged = true;
break;
}