Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Round Time for TEMPO granule requests (#5405)

Patrick Moulden09c2f217fcf1
diff --git a/web/js/map/granule/granule-layer-builder.js b/web/js/map/granule/granule-layer-builder.js
index 6ce11dc24..6a27dfbe8 100644
--- a/web/js/map/granule/granule-layer-builder.js
+++ b/web/js/map/granule/granule-layer-builder.js
@@ -64,6 +64,7 @@ export default function granuleLayerBuilder(cache, store, createLayerWMTS) {
* Query CMR to get dates
* @param {object} def - Layer specs
* @param {object} selectedDate - current selected date (Note: may not return this date, but this date will be the max returned)
+ * @returns {array} granule dates
*/
const getQueriedGranuleDates = async (def, selectedDate) => {
const {
@@ -72,23 +73,23 @@ export default function granuleLayerBuilder(cache, store, createLayerWMTS) {
const state = store.getState();
const { proj: { selected: { crs } } } = state;
const getGranulesUrl = getGranulesUrlSelector(state);
- const params = getParamsForGranuleRequest(def, selectedDate, crs);
- const nrtParams = getParamsForGranuleRequest(def, selectedDate, crs, true);
+ const paramsArray = getParamsForGranuleRequest(def, selectedDate, crs);
let data = [];
let nrtData = [];
try {
showLoading();
- const requestUrl = getGranulesUrl(params);
- const nrtRequestUrl = getGranulesUrl(nrtParams);
- const requests = [fetch(requestUrl, CMR_AJAX_OPTIONS), fetch(nrtRequestUrl, CMR_AJAX_OPTIONS)];
- const responses = await Promise.allSettled(requests);
+ const promises = paramsArray.map((params) => {
+ const requestUrl = getGranulesUrl(params);
+ return fetch(requestUrl, CMR_AJAX_OPTIONS);
+ });
+ const responses = await Promise.allSettled(promises);
const fulfilledResponses = responses.filter(({ status }) => status === 'fulfilled').map(({ value }) => value);
const [response, nrtResponse] = fulfilledResponses;
- const jsonRequests = [response.json(), nrtResponse.json()];
+ const jsonRequests = [response?.json(), nrtResponse?.json()];
const jsonResponses = await Promise.allSettled(jsonRequests);
const [responseJson, nrtResponseJson] = jsonResponses.filter(({ status }) => status === 'fulfilled').map(({ value }) => value);
- data = responseJson.feed.entry;
- nrtData = nrtResponseJson.feed.entry;
+ data = responseJson?.feed?.entry || [];
+ nrtData = nrtResponseJson?.feed?.entry || [];
} catch (e) {
console.error(e);
throttleDispathCMRErrorDialog(title);
@@ -176,6 +177,7 @@ export default function granuleLayerBuilder(cache, store, createLayerWMTS) {
const { date } = item;
const dateDate = new Date(date);
const leadingEdgeDateUTC = new Date(leadingEdgeDate.toUTCString());
+ leadingEdgeDateUTC.setSeconds(59);
const isWithinRange = isWithinRanges(leadingEdgeDateUTC, granuleDateRanges);
if (dateDate <= leadingEdgeDateUTC && isWithinRange && isWithinBounds(crs, item)) {
granules.unshift(item);
diff --git a/web/js/map/granule/util.js b/web/js/map/granule/util.js
index 1fb65a30d..aa2ea59c1 100644
--- a/web/js/map/granule/util.js
+++ b/web/js/map/granule/util.js
@@ -161,9 +161,9 @@ export const getCMRQueryDates = (crs, selectedDate) => {
* @param {*} def - layer definition
* @param {*} date - "current" date from which to base the query
* @param {*} crs
- * @returns
+ * @returns {Array} - array of objects with parameters for CMR request
*/
-export const getParamsForGranuleRequest = (def, date, crs, nrt) => {
+export const getParamsForGranuleRequest = (def, date, crs) => {
const dayNightFilter = def.daynight[0];
const bboxForProj = {
[CRS.WEB_MERCATOR]: [-180, -65, 180, 65],
@@ -173,7 +173,7 @@ export const getParamsForGranuleRequest = (def, date, crs, nrt) => {
};
const { startQueryDate, endQueryDate } = getCMRQueryDates(crs, date);
- const getShortName = () => {
+ const getShortName = (nrt) => {
try {
const { shortName } = def.conceptIds[0];
if (nrt) return shortName;
@@ -184,14 +184,35 @@ export const getParamsForGranuleRequest = (def, date, crs, nrt) => {
}
};
- return {
+ if (def.conceptIds[0].type === 'NRT') {
+ return [
+ {
+ shortName: getShortName(false),
+ startDate: startQueryDate.toISOString(),
+ endDate: endQueryDate.toISOString(),
+ dayNight: dayNightFilter,
+ bbox: bboxForProj[crs],
+ pageSize: 500,
+ },
+ {
+ shortName: getShortName(true),
+ startDate: startQueryDate.toISOString(),
+ endDate: endQueryDate.toISOString(),
+ dayNight: dayNightFilter,
+ bbox: bboxForProj[crs],
+ pageSize: 500,
+ },
+ ];
+ }
+
+ return [{
shortName: getShortName(),
startDate: startQueryDate.toISOString(),
endDate: endQueryDate.toISOString(),
dayNight: dayNightFilter,
bbox: bboxForProj[crs],
pageSize: 500,
- };
+ }];
};
/**