Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

WV-3906: Recent dateRanges post-build not showing fix (#6405)

christof-wittreicha0c36ab290a4
diff --git a/schemas/layer-config.json b/schemas/layer-config.json
index d8bcb0dbd..278e8773c 100644
--- a/schemas/layer-config.json
+++ b/schemas/layer-config.json
@@ -291,6 +291,16 @@
}
}
},
+ "tempoDateRanges": {
+ "type": "array",
+ "items": {
+ "type": "array",
+ "items": {
+ "type": "string",
+ "$ref": "#/definitions/date"
+ }
+ }
+ },
"shiftadjacentdays": {
"type": "boolean"
},
diff --git a/web/js/containers/timeline/timeline.js b/web/js/containers/timeline/timeline.js
index 5f7baf1ec..cd572abbc 100644
--- a/web/js/containers/timeline/timeline.js
+++ b/web/js/containers/timeline/timeline.js
@@ -111,7 +111,10 @@ const checkRightArrowDisabled = (
delta,
timeScaleChangeUnit,
timelineEndDateLimit,
+ autoSelected,
) => {
+ if (autoSelected) return false;
+
const nextIncMoment = moment.utc(date).add(delta, timeScaleChangeUnit);
const startOfDayNextIncrement = nextIncMoment.startOf('day').valueOf();
@@ -615,13 +618,19 @@ class Timeline extends React.Component {
timelineEndDateLimit,
timelineStartDateLimit,
subDailyLayersList,
+ activeString,
dateA,
+ dateB,
} = this.props;
let delta = customSelected && deltaChangeAmt ? deltaChangeAmt : 1;
let timescale = timeScaleChangeUnit;
if (autoSelected && subDailyLayersList && subDailyLayersList.length) {
- delta = getNextImageryDelta(subDailyLayersList, dateA, signConstant);
+ delta = getNextImageryDelta(
+ subDailyLayersList,
+ activeString === 'active' ? dateA : dateB,
+ signConstant,
+ );
timescale = 'minute';
}
if (!timeScaleChangeUnit) { // undefined custom will not allow arrow change
@@ -1559,7 +1568,7 @@ function mapStateToProps(state) {
selectedZoom,
timelineCustomModalOpen,
} = date;
- const { isCompareA } = compare;
+ const { isCompareA, activeString } = compare;
const isCompareModeActive = compare.active;
const isChartingActive = charting.active;
const { isDistractionFreeModeActive, isKioskModeActive, displayStaticMap } = ui;
@@ -1585,7 +1594,7 @@ function mapStateToProps(state) {
? [...getSubDaily(layers.active.layers), ...getSubDaily(layers.activeB.layers)]
: subdailyLayers(state);
const newCustomDelta = getSmallestIntervalValue(state);
- const hasTempoProduct = layers.active.layers.filter((layer) => layer.visible && layer.id.includes('TEMPO')).length > 0;
+ const hasTempoProduct = layers[activeString].layers.filter((layer) => layer.visible && layer.id.includes('TEMPO')).length > 0;
// if future layers are included, timeline axis end date will extend past appNow
const hasFutureLayers = checkHasFutureLayers(state);
@@ -1630,6 +1639,7 @@ function mapStateToProps(state) {
delta,
unit,
timelineEndDateLimit,
+ autoSelected,
);
const nowButtonDisabled = checkNowButtonDisabled(
selectedDate,
@@ -1664,6 +1674,7 @@ function mapStateToProps(state) {
hasTempoProduct,
dateA: getISODateFormatted(selected),
dateB: getISODateFormatted(selectedB),
+ activeString,
timelineStartDateLimit: config.startDate, // same as startDate
isAnimationWidgetOpen: animation.isActive,
animStartLocationDate: animation.startDate,
@@ -1793,6 +1804,7 @@ Timeline.propTypes = {
autoSelected: PropTypes.bool,
dateA: PropTypes.string,
dateB: PropTypes.string,
+ activeString: PropTypes.string,
deltaChangeAmt: PropTypes.number,
displayStaticMap: PropTypes.bool,
draggerSelected: PropTypes.string,
diff --git a/web/js/map/layerbuilder.js b/web/js/map/layerbuilder.js
index 833432aeb..1b76bdc00 100644
--- a/web/js/map/layerbuilder.js
+++ b/web/js/map/layerbuilder.js
@@ -98,6 +98,67 @@ export default function mapLayerBuilder(config, cache, store) {
};
};
+ /**
+ * For TEMPO layers, get and set the product's dateRanges
+ * so that they are up-to-date and not stale from build-time
+ */
+ const getUpdatedDateRanges = (def, callback, group) => {
+ const state = store.getState();
+ const { config, proj } = state;
+ const describeDomainsUrl = config?.features?.describeDomains?.url
+ || 'https://gibs.earthdata.nasa.gov';
+ const {
+ id,
+ } = def;
+ let oldRanges = [];
+ const worker = new Worker('js/workers/describe-domains.worker.js');
+ worker.onmessage = (event) => {
+ if (Array.isArray(event.data)) { // our final format is an array
+ worker.terminate(); // terminate the worker
+ const newRanges = event.data.map(([startDate, endDate, dateInterval]) => ({
+ startDate, endDate, dateInterval,
+ }));
+ return callback(def, [...oldRanges, ...newRanges], group);
+ }
+ // DOMParser is not available in workers so we parse the xml
+ // on the main thread before sending it back to the worker
+ const parser = new DOMParser();
+ const xmlDoc = parser.parseFromString(event.data, 'text/xml');
+ const domains = xmlDoc.querySelector('Domain')?.textContent;
+ if (!domains) {
+ worker.terminate();
+ return callback(def, oldRanges, group);
+ }
+ return worker.postMessage({ operation: 'mergeDomains', args: [domains, 60_000, true] });
+ };
+ worker.onerror = () => worker.terminate();
+ let startDate = new Date(def.startDate);
+ const endDate = def.endDate ? new Date(def.endDate).toISOString() : new Date().toISOString();
+ // If there are any existing dateRanges, find any after the latest one
+ if (def.dateRanges && def.dateRanges.length > 0) {
+ startDate = new Date(def.dateRanges[def.dateRanges.length - 1].endDate);
+ startDate.setSeconds(startDate.getSeconds() + 1);
+ }
+ const params = {
+ startDate,
+ endDate,
+ id,
+ proj: proj.selected.crs,
+ baseUrl: describeDomainsUrl,
+ };
+ worker.postMessage({ operation: 'requestDescribeDomains', args: [params] });
+ // While worker is running, format any problematic existing dateRanges
+ if (def.dateRanges && def.dateRanges.length > 0) {
+ oldRanges = def.dateRanges.map(({ startDate, endDate, dateInterval }) => ({
+ startDate,
+ endDate: startDate === endDate
+ ? new Date(new Date(endDate).getTime() + (Number(dateInterval) * 60000)).toISOString()
+ : endDate,
+ dateInterval,
+ }));
+ }
+ };
+
/**
*
* @function layerKey
@@ -240,9 +301,16 @@ export default function mapLayerBuilder(config, cache, store) {
const state = store.getState();
const { compare: { activeString } } = state;
const { ui: { isKioskModeActive, displayStaticMap } } = state;
+ const { tempoCallback } = options;
options.group = options.group || activeString;
+ // If layer is a TEMPO layer, fetch updated date ranges
+ if (def.id.includes('TEMPO') && !def.tempoDateRanges && tempoCallback) {
+ tempoCallback(def, [], options.group);
+ getUpdatedDateRanges(def, tempoCallback, options.group);
+ }
+
// if gibs/dns failure, display static image layer
if (displayStaticMap && isKioskModeActive) {
const layer = await createStaticImageLayer();
diff --git a/web/js/mapUI/components/update-projection/updateProjection.js b/web/js/mapUI/components/update-projection/updateProjection.js
index a9e77163e..9e1572aae 100644
--- a/web/js/mapUI/components/update-projection/updateProjection.js
+++ b/web/js/mapUI/components/update-projection/updateProjection.js
@@ -26,6 +26,7 @@ import { EXIT_ANIMATION, STOP_ANIMATION } from '../../../modules/animation/const
import { SET_SCREEN_INFO } from '../../../modules/screen-size/constants';
import { requestPalette } from '../../../modules/palettes/actions';
import usePrevious from '../../../util/customHooks';
+import { addTEMPODateRanges } from '../../../modules/layers/actions';
function UpdateProjection(props) {
const {
@@ -52,6 +53,7 @@ function UpdateProjection(props) {
ui,
renderedPalettes,
requestPalette,
+ addTEMPODateRanges,
} = props;
const layerStateRef = useRef(layerState);
@@ -106,6 +108,9 @@ function UpdateProjection(props) {
if (def.palette) {
requestPalette(def.id);
}
+ if (def.id.includes('TEMPO')) {
+ options.tempoCallback = addTEMPODateRanges;
+ }
return createLayer(def, options);
});
const compareLayerGroup = await Promise.all(layers);
@@ -143,6 +148,9 @@ function UpdateProjection(props) {
compare.activeString,
granuleOptions,
);
+ if (def.id.includes('TEMPO')) {
+ options.tempoCallback = addTEMPODateRanges;
+ }
return createLayer(def, options);
});
const layerResults = await Promise.allSettled(layerPromises);
@@ -454,6 +462,9 @@ const mapDispatchToProps = (dispatch) => ({
requestPalette: (id) => {
dispatch(requestPalette(id));
},
+ addTEMPODateRanges: (layer, dateRanges, activeString) => {
+ dispatch(addTEMPODateRanges(layer, dateRanges, activeString));
+ },
});
export default connect(
@@ -485,4 +496,5 @@ UpdateProjection.propTypes = {
updateMapUI: PropTypes.func,
renderedPalettes: PropTypes.oneOfType([PropTypes.object, PropTypes.oneOf(['null'])]),
requestPalette: PropTypes.func,
+ addTEMPODateRanges: PropTypes.func,
};
diff --git a/web/js/modules/date/util.js b/web/js/modules/date/util.js
index 6135c04fc..a2d9d9f28 100644
--- a/web/js/modules/date/util.js
+++ b/web/js/modules/date/util.js
@@ -549,25 +549,31 @@ export const rollDate = function(date, interval, amount, minDate, maxDate) {
* @param {Number} signConstant Direction of increment
* @returns {array} Array of visible layers within the date.
*/
-export function getNextImageryDelta(layers, dateA, signConstant) {
+export function getNextImageryDelta(layers, date, signConstant) {
let delta = 0;
let invalidLayerCount = 0;
- const dateAObj = new Date(dateA);
+ const dateAObj = new Date(date);
let hasDeltaChanged = false;
+ let dateRanges;
for (let i = 0; i < layers.length; i += 1) {
- if (!Object.prototype.hasOwnProperty.call(layers[i], 'dateRanges') || !layers[i].visible) {
+ if (Object.prototype.hasOwnProperty.call(layers[i], 'tempoDateRanges')) {
+ dateRanges = layers[i].tempoDateRanges;
+ } else if (Object.prototype.hasOwnProperty.call(layers[i], 'dateRanges')) {
+ dateRanges = layers[i].dateRanges;
+ }
+ if (!dateRanges || !layers[i].visible) {
invalidLayerCount += 1;
} else if (signConstant > 0) {
// Forward in time
- const foundIndex = layers[i].dateRanges.findIndex(
- (element) => element.startDate > dateA,
+ const foundIndex = dateRanges.findIndex(
+ (element) => element.startDate > date,
);
const startingIndex = foundIndex - 5 < 0 ? 0 : foundIndex - 5;
// endingIndex gives 10 tries to find a valid next interval
- const endingIndex = foundIndex + 5 > layers[i].dateRanges.length
- ? layers[i].dateRanges.length : foundIndex + 5;
+ const endingIndex = foundIndex + 5 > dateRanges.length
+ ? dateRanges.length : foundIndex + 5;
for (let j = startingIndex; j < endingIndex; j += 1) {
- const obj = layers[i].dateRanges[j];
+ 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);
@@ -583,7 +589,7 @@ export function getNextImageryDelta(layers, dateA, signConstant) {
const possibleDate = new Date(dateAObj.getTime() + (minDelta * 60000));
const possibleDelta = possibleDate > endDateObj
? Math.floor(((endDateObj - dateAObj) / 1000) / 60) : minDelta;
- if (possibleDelta >= minDelta) {
+ if (possibleDelta >= minDelta && possibleDate.getTime() !== endDateObj.getTime()) {
delta = possibleDelta;
hasDeltaChanged = true;
break;
@@ -595,20 +601,20 @@ export function getNextImageryDelta(layers, dateA, signConstant) {
}
} else {
// Backward in time
- const foundIndex = [...layers[i].dateRanges].reverse().findIndex(
- (element) => element.startDate < dateA,
+ const foundIndex = [...dateRanges].reverse().findIndex(
+ (element) => element.endDate < date,
);
const startingIndex = foundIndex - 5 < 0 ? 0 : foundIndex - 5;
// endingIndex gives 10 tries to find a valid next interval
- const endingIndex = foundIndex + 5 > layers[i].dateRanges.length
- ? layers[i].dateRanges.length : foundIndex + 5;
+ const endingIndex = foundIndex + 5 > dateRanges.length
+ ? dateRanges.length : foundIndex + 5;
for (let j = startingIndex; j < endingIndex; j += 1) {
- const obj = [...layers[i].dateRanges].reverse()[j];
- const endDateObj = new Date(obj.endDate);
+ 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);
if (dateAObj > endDateObj) {
- const possibleDelta = Math.floor(((dateAObj - endDateObj) / 1000) / 60);
+ const possibleDelta = Math.ceil(((dateAObj - endDateObj) / 1000) / 60);
if (possibleDelta >= minDelta) {
delta = possibleDelta;
hasDeltaChanged = true;
@@ -619,7 +625,7 @@ export function getNextImageryDelta(layers, dateA, signConstant) {
const possibleDate = new Date(dateAObj.getTime() - (minDelta * 60000));
const possibleDelta = possibleDate < startDateObj
? Math.floor(((dateAObj - startDateObj) / 1000) / 60) : minDelta;
- if (possibleDelta >= minDelta) {
+ if (possibleDelta >= minDelta && possibleDate.getTime() !== startDateObj.getTime()) {
delta = possibleDelta;
hasDeltaChanged = true;
break;
diff --git a/web/js/modules/layers/actions.js b/web/js/modules/layers/actions.js
index bca0d54ec..4a9188584 100644
--- a/web/js/modules/layers/actions.js
+++ b/web/js/modules/layers/actions.js
@@ -34,6 +34,7 @@ import {
UPDATE_COLLECTION,
UPDATE_DDV_LAYER,
ADD_GRANULE_DATE_RANGES,
+ ADD_TEMPO_DATE_RANGES,
} from './constants';
import { updateRecentLayers } from '../product-picker/util';
import { getOverlayGroups, getLayersFromGroups } from './util';
@@ -450,3 +451,16 @@ export function updateBandCombination(id, bandCombo, layerIndex, selectedPreset)
});
};
}
+
+export function addTEMPODateRanges(layer, tempoDateRanges, activeString) {
+ return (dispatch) => {
+ const { id } = layer;
+
+ dispatch({
+ type: ADD_TEMPO_DATE_RANGES,
+ activeString,
+ id,
+ tempoDateRanges,
+ });
+ };
+}
diff --git a/web/js/modules/layers/constants.js b/web/js/modules/layers/constants.js
index 86f6e504e..1ee4afc5d 100644
--- a/web/js/modules/layers/constants.js
+++ b/web/js/modules/layers/constants.js
@@ -22,3 +22,4 @@ export const MIN_GRANULES = 1;
export const MAX_GRANULES = 30;
export const UPDATE_DDV_LAYER = 'LAYERS/UPDATE_DDV_LAYER';
export const ADD_GRANULE_DATE_RANGES = 'LAYERS/ADD_GRANULE_DATE_RANGES';
+export const ADD_TEMPO_DATE_RANGES = 'LAYERS/ADD_TEMPO_DATE_RANGES';
diff --git a/web/js/modules/layers/reducers.js b/web/js/modules/layers/reducers.js
index 08cc9194d..e2bdeb9bc 100644
--- a/web/js/modules/layers/reducers.js
+++ b/web/js/modules/layers/reducers.js
@@ -23,6 +23,7 @@ import {
UPDATE_DDV_LAYER,
UPDATE_COLLECTION,
ADD_GRANULE_DATE_RANGES,
+ ADD_TEMPO_DATE_RANGES,
} from './constants';
import {
SET_CUSTOM as SET_CUSTOM_PALETTE,
@@ -426,6 +427,23 @@ export function layerReducer(state = initialState, action) {
});
}
+ case ADD_TEMPO_DATE_RANGES: {
+ const {
+ tempoDateRanges,
+ } = action;
+ const layerIndex = getLayerIndex();
+
+ return update(state, {
+ [compareState]: {
+ layers: {
+ [layerIndex]: {
+ tempoDateRanges: { $set: tempoDateRanges },
+ },
+ },
+ },
+ });
+ }
+
default:
return state;
}
diff --git a/web/js/workers/describe-domains.worker.js b/web/js/workers/describe-domains.worker.js
index 3d1dd982c..d0dc9bb7f 100644
--- a/web/js/workers/describe-domains.worker.js
+++ b/web/js/workers/describe-domains.worker.js
@@ -89,17 +89,19 @@ function periodToTime(period) {
* @method mergeDomains
* @param {array} domains
* @param {number} timeBuffer
+ * @param {boolean} keepDateIntervals
* @returns {array} mergedDateRanges
* @description
* Merge overlapping date ranges
*/
-function mergeDomains(domains, timeBuffer) {
+function mergeDomains(domains, timeBuffer, keepDateIntervals = false) {
const dateRanges = domains.split(',').map((range) => range.split('/'));
const mergedDateRanges = dateRanges.reduce((acc, [start, end, period]) => {
// convert start and end to time values
const startTime = makeTime(start);
let endTime = makeTime(end);
+ const formattedPeriod = keepDateIntervals ? [period.match(/\d+/)[0]] : [];
// if start and end are the same, add period
if (startTime === endTime) {
@@ -108,7 +110,8 @@ function mergeDomains(domains, timeBuffer) {
if (!acc.length) {
return [[makeDateString(startTime),
- makeDateString(endTime)]];
+ makeDateString(endTime),
+ ...formattedPeriod]];
} // add the first range to the accumulator
// round start time down and end time up by a set time to account for small range gaps
@@ -125,12 +128,15 @@ function mergeDomains(domains, timeBuffer) {
return acc;
}
- if (bufferedStartTime > lastRangeEndTime) { // discontinuous, add new range
- return [...acc, [makeDateString(startTime), makeDateString(endTime)]];
+ // discontinuous, add new range
+ if (bufferedStartTime > lastRangeEndTime || keepDateIntervals) {
+ return [...acc, [makeDateString(startTime), makeDateString(endTime),
+ ...formattedPeriod]];
}
+ // intersects current range, merge
if (bufferedStartTime <= lastRangeEndTime
- && bufferedEndTime > lastRangeEndTime) { // intersects current range, merge
+ && bufferedEndTime > lastRangeEndTime && !keepDateIntervals) {
return acc.with(-1, [acc.at(-1)[0], makeDateString(endTime)]);
}