Interactive interface for browsing global, full-resolution satellite imagery
check for availableWindow
Jason Kentd2e7ccf0f299
diff --git a/web/js/modules/layers/selectors.js b/web/js/modules/layers/selectors.jsindex d952dcfdc..2d1af6800 100644--- a/web/js/modules/layers/selectors.js+++ b/web/js/modules/layers/selectors.js@@ -200,9 +200,7 @@ export function getLayers(layers, spec = {}, state) {function forGroup(group, spec = {}, activeLayers, state) {const projId = spec.proj || state.proj.id;let results = [];- const defs = lodashFilter(activeLayers, {- group,- });+ const defs = lodashFilter(activeLayers, { group });lodashEach(defs, (def) => {// Skip if this layer isn't available for the selected projectionif (!def.projections[projId] && projId !== 'all') {@@ -237,11 +235,9 @@ function forGroup(group, spec = {}, activeLayers, state) {* @param {*} activeLayers* @param {*} config*/-function dateRange(id, activeLayers, config) {- const ignoreRange = config.parameters- && (config.parameters.debugGIBS- || config.parameters.ignoreDateRange);- if (ignoreRange) {+function dateRange(id, layers, { parameters }) {+ const { debugGIBS, ignoreDateRange } = parameters;+ if (debugGIBS || ignoreDateRange) {return {start: new Date(Date.UTC(1970, 0, 1)),end: util.now(),@@ -255,60 +251,57 @@ function dateRange(id, activeLayers, config) {// Use the minute ceiling of the current time so that we don't run into an issue where// seconds value of current appNow time is greater than a layer's available time rangeconst minuteCeilingCurrentTime = util.now().setSeconds(59);- const layers = id ? [lodashFind(activeLayers, { id })] : activeLayers;+ const def = lodashFind(layers, { id });+ if (!def) {+ return;+ }+ if (def.startDate) {+ range = true;+ const start = util.parseDateUTC(def.startDate).getTime();+ min = Math.min(min, start);+ }- layers.forEach((def) => {- if (!def) {- return;- }- if (def.startDate) {- range = true;- const start = util.parseDateUTC(def.startDate).getTime();- min = Math.min(min, start);- }+ // For now, we assume that any layer with an end date is+ // an ongoing product unless it is marked as inactive.+ if (def.futureLayer && def.endDate) {+ range = true;+ max = util.parseDateUTC(def.endDate).getTime();+ maxDates.push(new Date(max));+ } else if (def.inactive && def.endDate) {+ range = true;+ const end = util.parseDateUTC(def.endDate).getTime();+ max = Math.max(max, end);+ maxDates.push(new Date(max));+ } else if (def.endDate) {+ range = true;+ max = minuteCeilingCurrentTime;+ maxDates.push(new Date(max));+ }- // For now, we assume that any layer with an end date is- // an ongoing product unless it is marked as inactive.- if (def.futureLayer && def.endDate) {- range = true;- max = util.parseDateUTC(def.endDate).getTime();- maxDates.push(new Date(max));- } else if (def.inactive && def.endDate) {- range = true;- const end = util.parseDateUTC(def.endDate).getTime();- max = Math.max(max, end);+ // If there is a start date but no end date, this is a+ // product that is currently being created each day, set+ // the max day to today.+ if (def.futureLayer && def.futureTime && !def.endDate) {+ // Calculate endDate + parsed futureTime from layer JSON+ max = new Date();+ const { futureTime } = def;+ const dateType = futureTime.slice(-1);+ const dateInterval = futureTime.slice(0, -1);++ if (dateType === 'D') {+ max.setDate(max.getDate() + parseInt(dateInterval, 10));maxDates.push(new Date(max));- } else if (def.endDate) {- range = true;- max = minuteCeilingCurrentTime;+ } else if (dateType === 'M') {+ max.setMonth(max.getMonth() + parseInt(dateInterval, 10));maxDates.push(new Date(max));- }-- // If there is a start date but no end date, this is a- // product that is currently being created each day, set- // the max day to today.- if (def.futureLayer && def.futureTime && !def.endDate) {- // Calculate endDate + parsed futureTime from layer JSON- max = new Date();- const { futureTime } = def;- const dateType = futureTime.slice(-1);- const dateInterval = futureTime.slice(0, -1);-- if (dateType === 'D') {- max.setDate(max.getDate() + parseInt(dateInterval, 10));- maxDates.push(new Date(max));- } else if (dateType === 'M') {- max.setMonth(max.getMonth() + parseInt(dateInterval, 10));- maxDates.push(new Date(max));- } else if (dateType === 'Y') {- max.setYear(max.getYear() + parseInt(dateInterval, 10));- maxDates.push(new Date(max));- }- } else if (def.startDate && !def.endDate) {- max = minuteCeilingCurrentTime;+ } else if (dateType === 'Y') {+ max.setYear(max.getYear() + parseInt(dateInterval, 10));maxDates.push(new Date(max));}- });+ } else if (def.startDate && !def.endDate) {+ max = minuteCeilingCurrentTime;+ maxDates.push(new Date(max));+ }if (range) {if (max === 0) {@@ -316,9 +309,13 @@ function dateRange(id, activeLayers, config) {maxDates.push(max);}const maxDate = Math.max.apply(max, maxDates);+ const endDate = new Date(maxDate);+ const startDate = def.availableWindow+ ? new Date(new Date().setDate(new Date().getDate() - def.availableWindow))+ : new Date(min);return {- start: new Date(min),- end: new Date(maxDate),+ start: startDate,+ end: endDate,};}}