Interactive interface for browsing global, full-resolution satellite imagery
save closest date to layer options, modify date offsetting to a specific date only, clean up datesinDateRanges condition creation and allow date interval based max date range
Edward Plato061673f0183a
diff --git a/web/js/map/layerbuilder.js b/web/js/map/layerbuilder.jsindex 89861ef1b..5d940c0f1 100644--- a/web/js/map/layerbuilder.js+++ b/web/js/map/layerbuilder.js@@ -89,6 +89,9 @@ export function mapLayerBuilder(models, config, cache, ui, store) {options = options || {};const group = options.group || null;let date = self.closestDate(def, options);+ if (date) {+ options.date = date;+ }const key = self.layerKey(def, options, state);const proj = state.proj.selected;let layer = cache.getItem(key);@@ -140,7 +143,8 @@ export function mapLayerBuilder(models, config, cache, ui, store) {self.closestDate = function(def, options) {const state = store.getState();const activeDateStr = state.compare.isCompareA ? 'selected' : 'selectedB';- let date = options.date || new Date(state.date[activeDateStr]);+ const stateCurrentDate = new Date(state.date[activeDateStr]);+ let date = options.date || stateCurrentDate;// need to get previous available date to prevent unecessary requestslet dateRange;diff --git a/web/js/modules/layers/util.js b/web/js/modules/layers/util.jsindex 757cf6989..66beb9f84 100644--- a/web/js/modules/layers/util.js+++ b/web/js/modules/layers/util.js@@ -54,8 +54,7 @@ export function nearestInterval(def, date) {*/export function prevDateInDateRange(def, date, dateArray) {const closestAvailableDates = [];- // const currentDate = new Date(date.getTime());- const currentDate = new Date(date.getTime() + (date.getTimezoneOffset() * 60000));+ const currentDate = new Date(date.getTime());if (!dateArray ||(def.period === 'monthly' && (isFirstDayOfMonth(currentDate) || isLastDayOfMonth(currentDate))) ||@@ -78,8 +77,6 @@ export function prevDateInDateRange(def, date, dateArray) {const nextClosestDate = dateArray[closestDateIndex + 1];def.nextDate = nextClosestDate || null;- console.log(currentDate, closestDate, nextClosestDate)-return closestDate ? new Date(closestDate.getTime()) : date;};@@ -102,59 +99,59 @@ export function datesinDateRanges(def, date) {let monthDifference;let dayDifference;let minuteDifference;- // default to startDate/endDate if defined in the layer def- let minDate = new Date(def.startDate || dateRange.startDate);- let maxDate = new Date(def.endDate || dateRange.endDate);- // Offset timezone- if (def.period !== 'yearly') {- minDate = new Date(minDate.getTime() - (minDate.getTimezoneOffset() * 60000));- maxDate = new Date(maxDate.getTime() - (maxDate.getTimezoneOffset() * 60000));- }+ let minDate = new Date(dateRange.startDate);+ const maxDate = new Date(dateRange.endDate);+const maxYear = maxDate.getUTCFullYear();const maxMonth = maxDate.getUTCMonth();const maxDay = maxDate.getUTCDate();- const maxHours = maxDate.getUTCHours();- const maxMinutes = maxDate.getUTCMinutes();const minYear = minDate.getUTCFullYear();const minMonth = minDate.getUTCMonth();const minDay = minDate.getUTCDate();- const minMinutes = minDate.getUTCMinutes();-- const maxYearDate = new Date(maxYear + 1, maxMonth, maxDay);- const maxMonthDate = new Date(maxYear, maxMonth + 1, maxDay);- const maxDayDate = new Date(maxYear, maxMonth, maxDay + 1);- let maxMinuteDate = new Date(maxYear, maxMonth, maxDay, maxHours, maxMinutes + dateInterval);let i;// Yearly layersif (def.period === 'yearly') {+ const maxYearDate = new Date(maxYear + dateInterval, maxMonth, maxDay);if (currentDate >= minDate && currentDate <= maxYearDate) {yearDifference = util.yearDiff(minDate, maxYearDate);}for (i = 0; i <= (yearDifference + 1); i++) {- dateArray.push(new Date(minYear + i * dateInterval, minMonth, minDay));+ let year = new Date(minYear + i * dateInterval, minMonth, minDay);+ year = new Date(year.getTime() - (year.getTimezoneOffset() * 60000));+ dateArray.push(year);}// Monthly layers} else if (def.period === 'monthly') {+ const maxMonthDate = new Date(maxYear, maxMonth + dateInterval, maxDay);if (currentDate >= minDate && currentDate <= maxMonthDate) {monthDifference = util.monthDiff(minDate, maxMonthDate);}for (i = 0; i <= (monthDifference + 1); i++) {- dateArray.push(new Date(minYear, minMonth + i * dateInterval, minDay));+ let month = new Date(minYear, minMonth + i * dateInterval, minDay);+ month = new Date(month.getTime() - (month.getTimezoneOffset() * 60000));+ dateArray.push(month);}// Daily layers} else if (def.period === 'daily') {+ const maxDayDate = new Date(maxYear, maxMonth, maxDay + dateInterval);if (currentDate >= minDate && currentDate <= maxDayDate) {dayDifference = util.dayDiff(minDate, maxDayDate);// handle non-1 day intervals to prevent over pushing unused dates to dateArraydayDifference = Math.ceil(dayDifference / dateInterval);}- console.log(dateInterval, dayDifference)for (i = 0; i <= (dayDifference + 1); i++) {- dateArray.push(new Date(minYear, minMonth, minDay + i * dateInterval));+ let day = new Date(minYear, minMonth, minDay + i * dateInterval);+ day = new Date(day.getTime() - (day.getTimezoneOffset() * 60000));+ dateArray.push(day);}// Subdaily layers} else if (def.period === 'subdaily') {+ const maxHours = maxDate.getUTCHours();+ const maxMinutes = maxDate.getUTCMinutes();+ const minMinutes = minDate.getUTCMinutes();+ let maxMinuteDate = new Date(maxYear, maxMonth, maxDay, maxHours, maxMinutes + dateInterval);+const currentDateOffset = currentDate.getTimezoneOffset() * 60000;const hourBeforeCurrentDate = new Date(currentDate.setMinutes(minMinutes) - currentDateOffset - (60 * 60000));const hourAfterCurrentDate = new Date(currentDate.setMinutes(minMinutes) - currentDateOffset + (60 * 60000));@@ -180,7 +177,6 @@ export function datesinDateRanges(def, date) {}}});- console.log(def, dateArray)return dateArray;};