Interactive interface for browsing global, full-resolution satellite imagery
WV-3954 - Auto Interval Animations & dateRanges Build Changes (#6736)
christof-wittreichdec2a7004835
diff --git a/tasks/build-options/processTemporalLayer.js b/tasks/build-options/processTemporalLayer.jsindex 38bd49848..38a65a49a 100644--- a/tasks/build-options/processTemporalLayer.js+++ b/tasks/build-options/processTemporalLayer.js@@ -1,3 +1,4 @@+const fs = require('fs')const moment = require('moment')const xml2js = require('xml2js')@@ -15,106 +16,174 @@ function toList (val) {return val instanceof Array ? val : [val]}-async function processTemporalLayer (wvLayer, value, source = 'GIBS:geographic', cacheMode) {+function rangesHelper (wvLayer, ranges) {const dateFormat = 'YYYY-MM-DD'const dateTimeFormat = 'YYYY-MM-DD HH:mm:ss'+ let startDate = moment.min()+ let endDate = moment.max()+ const dateRangeStart = []+ const dateRangeEnd = []+ const rangeInterval = []+ if (ranges && ranges[0] && ranges[0]._text && ranges[0]._text.includes('T')) {+ wvLayer.period = 'subdaily'+ } else {+ if (ranges && ranges[0] && ranges[0]._text && ranges[0]._text.endsWith('Y')) {+ wvLayer.period = 'yearly'+ } else if (ranges && ranges[0] && ranges[0]._text && ranges[0]._text.endsWith('M')) {+ wvLayer.period = 'monthly'+ } else {+ wvLayer.period = 'daily'+ }+ }+ for (const range of ranges) {+ if (!range._text || !range._text.length) continue+ const [start, end, interval] = range._text.split('/')+ if (+ wvLayer.period === 'daily' ||+ wvLayer.period === 'monthly' ||+ wvLayer.period === 'yearly'+ ) {+ startDate = moment.min(startDate, moment(start, dateFormat))+ endDate = moment.max(endDate, moment(end, dateFormat))+ if (start) {+ startDate = moment(start, dateFormat).format('YYYY-MM-DDTHH:mm:ss[Z]')+ dateRangeStart.push(startDate)+ }+ if (end) {+ endDate = moment(end, dateFormat).format('YYYY-MM-DDTHH:mm:ss[Z]')+ }+ if (interval !== 'P1D') {+ endDate = moment.utc(endDate).add(moment.duration(interval)).format('YYYY-MM-DDTHH:mm:ss[Z]')+ // For monthly products subtract 1 day+ if (wvLayer.period === 'monthly') {+ endDate = moment.utc(endDate).subtract(1, 'day').format('YYYY-MM-DDTHH:mm:ss[Z]')+ }+ }+ const regex = /\d+/g+ const match = regex.exec(interval)+ rangeInterval.push(match)+ if (endDate.endsWith('T00:00:00Z')) {+ endDate = endDate.replace('T00:00:00Z', 'T23:59:59Z')+ }+ dateRangeEnd.push(endDate)+ } else {+ // Subdaily Layers+ startDate = moment(start, dateTimeFormat).format('YYYY-MM-DDTHH:mm:ss[Z]')+ endDate = moment(end, dateTimeFormat).format('YYYY-MM-DDTHH:mm:ss[Z]')++ if (start) {+ dateRangeStart.push(startDate)+ }+ if (end) {+ dateRangeEnd.push(endDate)+ }++ rangeInterval.push(interval.match(/\d+/)[0])+ }++ wvLayer.startDate = dateRangeStart[0]+ wvLayer.endDate = dateRangeEnd[dateRangeEnd.length - 1]+ }+ return [dateRangeStart, dateRangeEnd, rangeInterval]+}++async function processTemporalLayer (wvLayer, value, source = 'GIBS:geographic', cacheMode) {const fetchOpts = cacheMode === 'no-store' ? { cache: cacheMode } : undefinedtry {let ranges = toList(value)- const describeDomainsUrl = `https://gibs.earthdata.nasa.gov/wmts/${projDict[source]}/best/1.0.0/${wvLayer.id}/default/250m/all/all.xml`+ let rangesAll, startYear+ let dateRangeStart = []+ let dateRangeEnd = []+ let rangeInterval = []+ const parser = new xml2js.Parser()+ // Fetch from 'all' endpoint to get starting year+ const describeDomainsAllUrl = `https://gibs.earthdata.nasa.gov/wmts/${projDict[source]}/best/1.0.0/${wvLayer.id}/default/250m/all/all.xml`try {- const describeDomainsResponse = await fetch(describeDomainsUrl, fetchOpts)- if (describeDomainsResponse?.ok) {- const describeDomainsText = await describeDomainsResponse?.text?.() || ''- const parser = new xml2js.Parser()- const describeDomainsJson = await parser.parseStringPromise(describeDomainsText)- const domain = describeDomainsJson?.Domains?.DimensionDomain?.[0]?.Domain?.[0] || ''- const domains = domain.split(',')- if (domains?.length) {- const formattedDomains = domains.map((d) => {+ const describeDomainsAllResponse = await fetch(describeDomainsAllUrl, fetchOpts)+ if (describeDomainsAllResponse?.ok) {+ const describeDomainsAllText = await describeDomainsAllResponse?.text?.() || ''+ const describeDomainsAllJson = await parser.parseStringPromise(describeDomainsAllText)+ const domainAll = describeDomainsAllJson?.Domains?.DimensionDomain?.[0]?.Domain?.[0] || ''+ const domainsAll = domainAll.split(',')+ if (domainsAll?.length) {+ const formattedDomainsAll = domainsAll.map((d) => {return {_text: d}})- ranges = toList(formattedDomains)+ rangesAll = toList(formattedDomainsAll)+ if (rangesAll[0]._text && rangesAll[0]._text.length) {+ const startDate = rangesAll[0]._text.split('/')[0]+ startYear = Number(startDate.split('-')[0])+ }}}} catch (error) {- console.error(`Error fetching ${describeDomainsUrl}: ${error}`)- } finally {- if (ranges && ranges[0] && ranges[0]._text && ranges[0]._text.includes('T')) {- wvLayer.period = 'subdaily'- } else {- if (ranges && ranges[0] && ranges[0]._text && ranges[0]._text.endsWith('Y')) {- wvLayer.period = 'yearly'- } else if (ranges && ranges[0] && ranges[0]._text && ranges[0]._text.endsWith('M')) {- wvLayer.period = 'monthly'- } else {- wvLayer.period = 'daily'- }+ console.error(`Error fetching ${describeDomainsAllUrl}: ${error}`)+ }+ // Fetch ranges year-by-year if more than 10,000 ranges, as they may not all be present in all.xml+ if (rangesAll.length > 10000 && startYear) {+ const endYear = new Date().getFullYear()+ const requestDates = [];+ // Create an array of request ranges, split into 6-month chunks+ for (let year = startYear; year <= endYear; year++) {+ requestDates.push({+ start: `${year}-01-01T00:00:00Z`,+ end: `${year}-06-30T23:59:59Z`,+ })+ requestDates.push({+ start: `${year}-07-01T00:00:00Z`,+ end: `${year}-12-31T23:59:59Z`,+ })}- let startDate = moment.min()- let endDate = moment.max()- const dateRangeStart = []- const dateRangeEnd = []- const rangeInterval = []- for (const range of ranges) {- if (!range._text || !range._text.length) continue- const [start, end, interval] = range._text.split('/')- if (- wvLayer.period === 'daily' ||- wvLayer.period === 'monthly' ||- wvLayer.period === 'yearly'- ) {- startDate = moment.min(startDate, moment(start, dateFormat))- endDate = moment.max(endDate, moment(end, dateFormat))- if (start) {- startDate = moment(start, dateFormat).format('YYYY-MM-DDTHH:mm:ss[Z]')- dateRangeStart.push(startDate)- }- if (end) {- endDate = moment(end, dateFormat).format('YYYY-MM-DDTHH:mm:ss[Z]')- }- if (interval !== 'P1D') {- endDate = moment.utc(endDate).add(moment.duration(interval)).format('YYYY-MM-DDTHH:mm:ss[Z]')- // For monthly products subtract 1 day- if (wvLayer.period === 'monthly') {- endDate = moment.utc(endDate).subtract(1, 'day').format('YYYY-MM-DDTHH:mm:ss[Z]')+ for (const index in requestDates) {+ let invalidRanges = false+ const { start, end } = requestDates[index];+ const describeDomainsUrl = `https://gibs.earthdata.nasa.gov/wmts/${projDict[source]}/best/1.0.0/${wvLayer.id}/default/250m/all/${start}--${end}.xml`+ try {+ const describeDomainsResponse = await fetch(describeDomainsUrl, fetchOpts)+ if (describeDomainsResponse?.ok) {+ const describeDomainsText = await describeDomainsResponse?.text?.() || ''+ const describeDomainsJson = await parser.parseStringPromise(describeDomainsText)+ const domain = describeDomainsJson?.Domains?.DimensionDomain?.[0]?.Domain?.[0] || ''+ const domains = domain.split(',')+ if (domain && domains?.length) {+ const formattedDomains = domains.map((d) => {+ return {+ _text: d+ }+ })+ ranges = toList(formattedDomains)+ } else {+ invalidRanges = true}}- const regex = /\d+/g- const match = regex.exec(interval)- rangeInterval.push(match)- if (endDate.endsWith('T00:00:00Z')) {- endDate = endDate.replace('T00:00:00Z', 'T23:59:59Z')- }- dateRangeEnd.push(endDate)- } else {- // Subdaily Layers- startDate = moment(start, dateTimeFormat).format('YYYY-MM-DDTHH:mm:ss[Z]')- endDate = moment(end, dateTimeFormat).format('YYYY-MM-DDTHH:mm:ss[Z]')-- if (start) {- dateRangeStart.push(startDate)+ } catch (error) {+ invalidRanges = true+ console.error(`Error fetching ${describeDomainsUrl}: ${error}`)+ } finally {+ if (!invalidRanges) {+ const [dateRangeStartYear, dateRangeEndYear, rangeIntervalYear] = rangesHelper(wvLayer, ranges)+ dateRangeStart.push(...dateRangeStartYear)+ dateRangeEnd.push(...dateRangeEndYear)+ rangeInterval.push(...rangeIntervalYear)}- if (end) {- dateRangeEnd.push(endDate)- }-- rangeInterval.push(interval.match(/\d+/)[0])- }-- wvLayer.startDate = dateRangeStart[0]- wvLayer.endDate = dateRangeEnd[dateRangeEnd.length - 1]-- if (dateRangeStart.length && dateRangeEnd.length) {- wvLayer.dateRanges = dateRangeStart.map((s, i) => ({- startDate: s,- endDate: dateRangeEnd[i],- dateInterval: rangeInterval[i]- }))}}+ } else {+ [dateRangeStart, dateRangeEnd, rangeInterval] = rangesHelper(wvLayer, rangesAll)+ }+ if (dateRangeStart.length && dateRangeEnd.length) {+ const dateRangesObj = dateRangeStart.map((s, i) => ({+ startDate: s,+ endDate: dateRangeEnd[i],+ dateInterval: rangeInterval[i]+ }))+ if (wvLayer.period === 'subdaily') {+ await fs.writeFileSync(`build/options/config/dateRanges/${wvLayer.id}.json`, JSON.stringify(dateRangesObj, null, 2))+ } else {+ wvLayer.dateRanges = dateRangesObj+ }}} catch (e) {throw new Error(`Error processing temporal layer ${wvLayer.id}: ${e}`)diff --git a/tasks/buildOptions.sh b/tasks/buildOptions.shindex 4760e2f07..ec7b8e949 100755--- a/tasks/buildOptions.sh+++ b/tasks/buildOptions.sh@@ -113,6 +113,7 @@ else# Run extractConfigFromWMTS.js script with config.jsonif [ -e "$BUILD_DIR/config.json" ] ; then+ mkdir -p "$DEST_DIR"/config/dateRangesif [ "$MODE" == "verbose" ] ; thenecho "Run extractConfigFromWMTS.js script with config.json"fidiff --git a/web/js/components/animation-widget/play-queue.js b/web/js/components/animation-widget/play-queue.jsindex ec8f76d17..961d2aacd 100644--- a/web/js/components/animation-widget/play-queue.js+++ b/web/js/components/animation-widget/play-queue.js@@ -6,7 +6,7 @@ import { Progress } from 'reactstrap';import LoadingIndicator from './loading-indicator';import util from '../../util/util';import {- getNextImageryDelta,+ getValidDateRanges,} from '../../modules/date/util';// We assume anything this fast or faster is a frame that was pulled from the cache@@ -85,10 +85,18 @@ function PlayQueue(props) {const [loadedItems, setLoadedItems] = useState(0);const bufferObjectRef = useRef({});const isLoopActiveRef = useRef(isLoopActive);+ const validDateRangesRef = useRef(getValidDateRanges(layers, startDate, endDate));function nextDate(date) {if (autoSelected) {- return util.dateAdd(date, 'minute', getNextImageryDelta(layers, date, 1));+ const foundIndex = validDateRangesRef.current.findIndex(+ (element) => new Date(element.startDate) > new Date(date),+ );+ // If date is not found within dateRanges, force date back to start+ if (foundIndex < 0) {+ return util.dateAdd(date, 'day', 1);+ }+ return new Date(validDateRangesRef.current[foundIndex].startDate);}return util.dateAdd(date, interval, delta);}@@ -122,7 +130,7 @@ function PlayQueue(props) {const currentBufferSize = util.objectLength(bufferObjectRef.current);const queueLength = currentBufferSize || initialBufferSize;- let i = 1;+ let i = 0;while (i < queueLength) {if (nextDate(currentDateObj) > endDate) {if (!isLoopActiveRef.current) {@@ -172,6 +180,17 @@ function PlayQueue(props) {} catch (error) {if (error instanceof TimeoutError) {console.error('Imagery loading timed out after 3 seconds');+ setLoadedItems(util.objectLength(bufferObjectRef.current) + 1);++ if (!mounted) return true;+ bufferObjectRef.current[strDate] = strDate;+ delete inQueueObject[strDate];+ const currentBufferSize = util.objectLength(bufferObjectRef.current);++ if (!initialLoad || canPreloadAll || currentBufferSize >= initialBufferSize) {+ checkQueue();+ checkShouldPlay();+ }}}}diff --git a/web/js/components/animation-widget/play-queue.test.js b/web/js/components/animation-widget/play-queue.test.jsindex 51a1e6d91..3be9b1cb4 100644--- a/web/js/components/animation-widget/play-queue.test.js+++ b/web/js/components/animation-widget/play-queue.test.js@@ -56,11 +56,12 @@ jest.mock('../../util/util', () => {jest.mock('../../modules/date/util', () => ({getNextImageryDelta: jest.fn(() => new Date('2026-05-01T00:00:00Z')),+ getValidDateRanges: jest.fn(() => [new Date('2026-05-01T00:00:00Z')]),}));const PlayQueue = require('./play-queue').default;const { TimeoutError } = require('p-queue');-const { getNextImageryDelta } = jest.requireMock('../../modules/date/util');+const { getValidDateRanges } = jest.requireMock('../../modules/date/util');describe('PlayQueue Component', () => {let defaultProps;@@ -252,7 +253,7 @@ describe('PlayQueue Component', () => {it('uses autoSelected date calculation when enabled', async () => {await renderPlayQueue({ autoSelected: true, layers: [{}] });- expect(getNextImageryDelta).toHaveBeenCalled();+ expect(getValidDateRanges).toHaveBeenCalled();});it('selects the startDate immediately when there is only one frame', async () => {diff --git a/web/js/components/timeline/timeline-coverage/coverage-item-list.js b/web/js/components/timeline/timeline-coverage/coverage-item-list.jsindex 91567b4fb..f078ecb05 100644--- a/web/js/components/timeline/timeline-coverage/coverage-item-list.js+++ b/web/js/components/timeline/timeline-coverage/coverage-item-list.js@@ -241,7 +241,7 @@ class CoverageItemList extends Component {* @param {Boolean} isLastInRange* @returns {Array} dateIntervalStartDates*/- getDatesInDateRange = (def, range, endDateLimit, isLastInRange) => {+ getDatesInDateRange = async (def, range, endDateLimit, isLastInRange) => {const {appNow,backDate,@@ -290,7 +290,7 @@ class CoverageItemList extends Component {const layerIdDates = `${appNow.toISOString()}-${frontDate}-${backDate}`;if (this.layerDateArrayCache[id][layerIdDates] === undefined) {- dateIntervalStartDates = datesInDateRanges(+ dateIntervalStartDates = await datesInDateRanges(def,startDateLimit,startDateLimit,diff --git a/web/js/components/timeline/timeline-coverage/coverage-item-list.test.js b/web/js/components/timeline/timeline-coverage/coverage-item-list.test.jsindex ffa1a15fe..c9b4b2700 100644--- a/web/js/components/timeline/timeline-coverage/coverage-item-list.test.js+++ b/web/js/components/timeline/timeline-coverage/coverage-item-list.test.js@@ -618,38 +618,38 @@ describe('CoverageItemList', () => {expect(datesInDateRanges).toHaveBeenCalledTimes(1);});- it('returns [] when startDate is after endDateLimit', () => {+ it('returns [] when startDate is after endDateLimit', async () => {renderComponent();const futureRange = { ...validRange, startDate: '2022-01-01' };- const result = capturedContainerProps+ const result = await capturedContainerProps.getDatesInDateRange(makeDef(), futureRange, endDateLimit, false);expect(result).toEqual([]);expect(datesInDateRanges).not.toHaveBeenCalled();});- it('returns [] when rangeEnd is before startDateLimit', () => {+ it('returns [] when rangeEnd is before startDateLimit', async () => {renderComponent();// rangeEnd = new Date('2019-01-01'), startDateLimit ≈ 2019-12-31const pastRange = { startDate: '2020-01-01', endDate: '2019-01-01', dateInterval: '1' };- const result = capturedContainerProps+ const result = await capturedContainerProps.getDatesInDateRange(makeDef(), pastRange, endDateLimit, false);expect(result).toEqual([]);expect(datesInDateRanges).not.toHaveBeenCalled();});- it('caches the result and avoids duplicate datesInDateRanges calls', () => {+ it('caches the result and avoids duplicate datesInDateRanges calls', async () => {renderComponent();- capturedContainerProps.getDatesInDateRange(makeDef(), validRange, endDateLimit, false);- capturedContainerProps.getDatesInDateRange(makeDef(), validRange, endDateLimit, false);+ await capturedContainerProps.getDatesInDateRange(makeDef(), validRange, endDateLimit, false);+ await capturedContainerProps.getDatesInDateRange(makeDef(), validRange, endDateLimit, false);expect(datesInDateRanges).toHaveBeenCalledTimes(1);});- it('uses cached result for second call', () => {+ it('uses cached result for second call', async () => {const fakeDate = new Date('2020-06-01');- datesInDateRanges.mockReturnValueOnce([fakeDate]);+ datesInDateRanges.mockImplementation(() => Promise.resolve([fakeDate]));renderComponent();capturedContainerProps.getDatesInDateRange(makeDef(), validRange, endDateLimit, false);- const second = capturedContainerProps+ const second = await capturedContainerProps.getDatesInDateRange(makeDef(), validRange, endDateLimit, false);expect(second).toEqual([fakeDate]);});diff --git a/web/js/containers/animation-widget/animation-widget.js b/web/js/containers/animation-widget/animation-widget.jsindex 6945dfcde..bf1c1649d 100644--- a/web/js/containers/animation-widget/animation-widget.js+++ b/web/js/containers/animation-widget/animation-widget.js@@ -54,6 +54,7 @@ function AnimationWidget (props) {endDate,hasFutureLayers,hasSubdailyLayers,+ hasTempoProduct,interval,isActive,isCollapsed,@@ -274,6 +275,7 @@ function AnimationWidget (props) {endDate={endDate}handleDragStart={handleDragStart}hasSubdailyLayers={hasSubdailyLayers}+ hasTempoProduct={hasTempoProduct}interval={interval}isKioskModeActive={isKioskModeActive}isPlaying={isPlaying}@@ -398,6 +400,7 @@ const mapStateToProps = (state) => {} = date;const hasSubdailyLayers = subdailyLayersActive(state);+ const hasTempoProduct = layers[compare.activeString].layers.filter((layer) => layer.visible && layer.id.includes('TEMPO')).length > 0;const activeLayersForProj = getAllActiveLayers(state);const hasFutureLayers = activeLayersForProj.filter((layer) => layer.futureTime).length > 0;const layerDateRange = getDateRange({}, activeLayersForProj);@@ -427,7 +430,7 @@ const mapStateToProps = (state) => {}const useInterval = customSelected ? customInterval || 3 : interval;const useDelta = customSelected && customDelta ? customDelta : delta;- const subDailyInterval = useInterval > 3;+ const subDailyInterval = useInterval > 3 || autoSelected;const subDailyMode = subDailyInterval && hasSubdailyLayers;const maxFrames = 300;const mobileMaxFrames = 50;@@ -485,6 +488,7 @@ const mapStateToProps = (state) => {screenHeight,hasFutureLayers,hasSubdailyLayers,+ hasTempoProduct,subDailyMode,delta: useDelta,interval: TIME_SCALE_FROM_NUMBER[useInterval] || 'day',@@ -497,7 +501,8 @@ const mapStateToProps = (state) => {looping: loop,map,proj,- promiseImageryForTime: (dateArg) => promiseImageryForTimeUtil(state, dateArg),+ promiseImageryForTime: (dateArg) =>+ promiseImageryForTimeUtil(state, dateArg, undefined, autoSelected),isEmbedModeActive,playDisabled: !screenSize.isMobileDevice? numberOfFrames >= maxFrames || numberOfFrames === 1@@ -558,6 +563,7 @@ AnimationWidget.propTypes = {endDate: PropTypes.oneOfType([PropTypes.object, PropTypes.oneOf(['null'])]),hasFutureLayers: PropTypes.bool,hasSubdailyLayers: PropTypes.bool,+ hasTempoProduct: PropTypes.bool,interval: PropTypes.string,isActive: PropTypes.bool,isCollapsed: PropTypes.bool,diff --git a/web/js/containers/animation-widget/desktop-animation-widget.js b/web/js/containers/animation-widget/desktop-animation-widget.jsindex 0bd9f985b..b3d8dee2e 100644--- a/web/js/containers/animation-widget/desktop-animation-widget.js+++ b/web/js/containers/animation-widget/desktop-animation-widget.js@@ -17,6 +17,7 @@ function DesktopAnimationWidget(props) {endDate,handleDragStart,hasSubdailyLayers,+ hasTempoProduct,interval,isDistractionFreeModeActive,isPlaying,@@ -71,6 +72,7 @@ function DesktopAnimationWidget(props) {<TimeScaleIntervalChangetimeScaleChangeUnit={interval}hasSubdailyLayers={hasSubdailyLayers}+ hasTempoProduct={hasTempoProduct}modalType={customModalType.ANIMATION}isDisabled={isPlaying}/>@@ -140,6 +142,7 @@ DesktopAnimationWidget.propTypes = {endDate: PropTypes.oneOfType([PropTypes.object, PropTypes.oneOf(['null'])]),handleDragStart: PropTypes.func,hasSubdailyLayers: PropTypes.bool,+ hasTempoProduct: PropTypes.bool,interval: PropTypes.string,isDistractionFreeModeActive: PropTypes.bool,isPlaying: PropTypes.bool,diff --git a/web/js/map/layerbuilder.js b/web/js/map/layerbuilder.jsindex c22f2be2d..2c1a2a4ec 100644--- a/web/js/map/layerbuilder.js+++ b/web/js/map/layerbuilder.js@@ -32,7 +32,7 @@ import {getGeographicResolutionWMS,mergeBreakpointLayerAttributes,} from './util';-import { datesInDateRanges, prevDateInDateRange } from '../modules/layers/util';+import { fetchSubdailyDateRanges, datesInDateRanges, prevDateInDateRange } from '../modules/layers/util';import { getSelectedDate } from '../modules/date/selectors';import {isActive as isPaletteActive,@@ -101,7 +101,7 @@ 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 getUpdatedDateRanges = async (def, callback, group) => {const state = store.getState();const { config: stateConfig, proj } = state;const describeDomainsUrl = stateConfig?.features?.describeDomains?.url ||@@ -110,6 +110,10 @@ export default function mapLayerBuilder(config, cache, store) {id,} = def;let oldRanges = [];+ const result = await fetchSubdailyDateRanges(def.id);+ if (result) {+ def.dateRanges = result;+ }const worker = new Worker('js/workers/describe-domains.worker.js');worker.onmessage = (event) => {if (Array.isArray(event.data)) { // our final format is an array@@ -201,7 +205,7 @@ export default function mapLayerBuilder(config, cache, store) {* @param {object} options Layer options* @return {object} Closest date*/- const getRequestDates = (def, options) => {+ const getRequestDates = async (def, options) => {const state = store.getState();const { date } = state;const { appNow } = date;@@ -221,10 +225,16 @@ export default function mapLayerBuilder(config, cache, store) {) {previousDateFromRange = previousLayerDate;} else {+ if (!def.dateRanges && def.period === 'subdaily') {+ const result = await fetchSubdailyDateRanges(def.id);+ if (result) {+ def.dateRanges = result;+ }+ }const { dateRanges, ongoing, period } = def;let dateRange;if (!ongoing) {- dateRange = datesInDateRanges(def, closestDate);+ dateRange = await datesInDateRanges(def, closestDate);} else {let endDateLimit;let startDateLimit;@@ -313,7 +323,7 @@ export default function mapLayerBuilder(config, cache, store) {// If layer is a TEMPO layer, fetch updated date rangesif (def?.id?.includes('TEMPO') && !def?.tempoDateRanges && tempoCallback) {tempoCallback(def, [], options.group);- getUpdatedDateRanges(def, tempoCallback, options.group);+ await getUpdatedDateRanges(def, tempoCallback, options.group);}// if gibs/dns failure, display static image layer@@ -326,7 +336,7 @@ export default function mapLayerBuilder(config, cache, store) {closestDate,nextDate,previousDate,- } = getRequestDates(def, options);+ } = await getRequestDates(def, options);const date = closestDate;if (date && !options.date) {options.date = date;diff --git a/web/js/map/layerbuilder.test.js b/web/js/map/layerbuilder.test.jsindex 399a3908e..66d9ef251 100644--- a/web/js/map/layerbuilder.test.js+++ b/web/js/map/layerbuilder.test.js@@ -148,6 +148,7 @@ jest.mock('../modules/layers/util', () => ({previous: new Date('2020-12-31'),}),nearestInterval: jest.fn().mockReturnValue(new Date('2021-01-01')),+ fetchSubdailyDateRanges: jest.fn(),}));jest.mock('../modules/date/selectors', () => ({@@ -1173,27 +1174,27 @@ describe('mapLayerBuilder', () => {}));});- it('handles worker onmessage with final array data format', () => {+ it('handles worker onmessage with final array data format', async () => {const tempoCallback = jest.fn();const def = buildDef({id: 'TEMPO_NO2_Hourly',projections: { geographic: {} },dateRanges: [{ startDate: '2021-01-01', endDate: '2021-01-02', dateInterval: '60' }],});- builder.createLayer(def, buildOptions({ tempoCallback }));+ await builder.createLayer(def, buildOptions({ tempoCallback }));mockWorker.onmessage({ data: [['2021-01-01T00:00:00Z', '2021-01-02T00:00:00Z', '60']] });expect(mockWorker.terminate).toHaveBeenCalled();expect(tempoCallback).toHaveBeenCalledTimes(2);});- it('handles worker onmessage with xml string and valid Domain element', () => {+ it('handles worker onmessage with xml string and valid Domain element', async () => {global.DOMParser = jest.fn().mockImplementation(() => ({parseFromString: jest.fn().mockReturnValue({querySelector: jest.fn().mockReturnValue({ textContent: 'domain1 domain2' }),}),}));const tempoCallback = jest.fn();- builder.createLayer(+ await builder.createLayer(buildDef({ id: 'TEMPO_NO2_Hourly', projections: { geographic: {} } }),buildOptions({ tempoCallback }),);@@ -1201,14 +1202,14 @@ describe('mapLayerBuilder', () => {expect(mockWorker.postMessage).toHaveBeenCalledTimes(2);});- it('handles worker onmessage with xml string and null Domain element', () => {+ it('handles worker onmessage with xml string and null Domain element', async () => {global.DOMParser = jest.fn().mockImplementation(() => ({parseFromString: jest.fn().mockReturnValue({querySelector: jest.fn().mockReturnValue(null),}),}));const tempoCallback = jest.fn();- builder.createLayer(+ await builder.createLayer(buildDef({ id: 'TEMPO_NO2_Hourly', projections: { geographic: {} } }),buildOptions({ tempoCallback }),);@@ -1217,9 +1218,9 @@ describe('mapLayerBuilder', () => {expect(tempoCallback).toHaveBeenCalledTimes(2);});- it('handles worker onerror by terminating and calling callback', () => {+ it('handles worker onerror by terminating and calling callback', async () => {const tempoCallback = jest.fn();- builder.createLayer(+ await builder.createLayer(buildDef({ id: 'TEMPO_NO2_Hourly', projections: { geographic: {} } }),buildOptions({ tempoCallback }),);@@ -1228,7 +1229,7 @@ describe('mapLayerBuilder', () => {expect(tempoCallback).toHaveBeenCalledTimes(2);});- it('formats existing dateRanges where startDate equals endDate', () => {+ it('formats existing dateRanges where startDate equals endDate', async () => {const tempoCallback = jest.fn();const sameDate = '2021-01-01T00:00:00.000Z';const def = buildDef({@@ -1236,7 +1237,7 @@ describe('mapLayerBuilder', () => {projections: { geographic: {} },dateRanges: [{ startDate: sameDate, endDate: sameDate, dateInterval: '60' }],});- builder.createLayer(def, buildOptions({ tempoCallback }));+ await builder.createLayer(def, buildOptions({ tempoCallback }));mockWorker.onmessage({ data: [['2021-01-01T00:00:00Z', '2021-01-02T00:00:00Z', '60']] });expect(tempoCallback).toHaveBeenCalledTimes(2);});diff --git a/web/js/modules/animation/util.js b/web/js/modules/animation/util.jsindex 6f3084f4b..8f4f73f70 100644--- a/web/js/modules/animation/util.js+++ b/web/js/modules/animation/util.js@@ -5,6 +5,7 @@ import canvg from '../../util/canvg';import util from '../../util/util';import {getNextImageryDelta,+ getValidDateRanges,} from '../date/util';/**@@ -61,10 +62,10 @@ export function getNumberOfSteps(layers,stateDelta = 1,) {- let delta = stateDelta;if (autoSelected) {- delta = getNextImageryDelta(layers, start, 1);+ return getValidDateRanges(layers, start, end).length;}+ let delta = stateDelta;let i = 1;let currentDate = start;let nextDate = util.dateAdd(start, interval, delta);@@ -72,14 +73,12 @@ export function getNumberOfSteps(i = 1;return i;}- while (currentDate < end) {+ while (currentDate < end && delta > 0) {i += 1;- if (autoSelected) {- delta = getNextImageryDelta(layers, currentDate, 1);- }currentDate = util.dateAdd(currentDate, interval, delta);if (autoSelected) {- delta = getNextImageryDelta(layers, currentDate, 1);+ delta = getNextImageryDelta(layers, nextDate, 1);+ currentDate = nextDate;}nextDate = util.dateAdd(currentDate, interval, delta);// checking to see if next date is after end date to prevent creation of extra framediff --git a/web/js/modules/date/util.js b/web/js/modules/date/util.jsindex 823aa036e..d4bb6f847 100644--- a/web/js/modules/date/util.js+++ b/web/js/modules/date/util.js@@ -550,6 +550,56 @@ export const rollDate = function(date, interval, amount, minDate, maxDate) {return newDate;};+/**+ * Retrieves the dateRanges for the given layer+ *+ * @method getDateRanges+ * @param {object} layer Selected layer+ * @returns {array} Array of dateRanges.+ */+function getDateRanges(layer) {+ let dateRanges = [];+ if (Object.prototype.hasOwnProperty.call(layer, 'tempoDateRanges')) {+ dateRanges = layer.tempoDateRanges;+ } else if (Object.prototype.hasOwnProperty.call(layer, 'granuleDateRanges') &&+ layer.granuleDateRanges?.length) {+ // granuleDateRanges are stored as [[start, end], ...] arrays from CMR/DD workers;+ // convert to the {startDate, endDate, dateInterval} format used below.+ // When dateInterval is absent (CMR), derive it from the range span in minutes.+ dateRanges = layer.granuleDateRanges.map(+ ([startDate, endDate, dateInterval]) => {+ const interval = dateInterval ||+ String(Math.max(1, Math.ceil(+ ((new Date(endDate) - new Date(startDate)) / 1000) / 60,+ )));+ return { startDate, endDate, dateInterval: interval };+ },+ );+ } else if (Object.prototype.hasOwnProperty.call(layer, 'dateRanges')) {+ dateRanges = layer.dateRanges;+ }+ return dateRanges;+}++/**+ * Gets the dateRanges between two dates for auto increments+ *+ * @method getValidDateRanges+ * @param {Array} layers+ * @param {object} dateA Start date+ * @param {object} dateB End date+ * @returns {Array} Array of dateRanges.+ */+export function getValidDateRanges(layers, dateA, dateB) {+ for (let i = 0; i < layers.length; i += 1) {+ const dateRanges = getDateRanges(layers[i]);+ if (dateRanges && layers[i].visible) {+ return dateRanges.filter((element) => new Date(element.startDate) <= dateB &&+ new Date(element.endDate) >= dateA);+ }+ }+}+/*** Gets the next imagery delta for auto increments*@@ -565,35 +615,16 @@ export function getNextImageryDelta(layers, date, signConstant) {const dateAObj = new Date(date);let hasDeltaChanged = false;for (let i = 0; i < layers.length; i += 1) {- let dateRanges;- if (Object.prototype.hasOwnProperty.call(layers[i], 'tempoDateRanges')) {- dateRanges = layers[i].tempoDateRanges;- } else if (Object.prototype.hasOwnProperty.call(layers[i], 'granuleDateRanges') &&- layers[i].granuleDateRanges?.length) {- // granuleDateRanges are stored as [[start, end], ...] arrays from CMR/DD workers;- // convert to the {startDate, endDate, dateInterval} format used below.- // When dateInterval is absent (CMR), derive it from the range span in minutes.- dateRanges = layers[i].granuleDateRanges.map(- ([startDate, endDate, dateInterval]) => {- const interval = dateInterval ||- String(Math.max(1, Math.ceil(- ((new Date(endDate) - new Date(startDate)) / 1000) / 60,- )));- return { startDate, endDate, dateInterval: interval };- },- );- } else if (Object.prototype.hasOwnProperty.call(layers[i], 'dateRanges')) {- dateRanges = layers[i].dateRanges;- }- if (!dateRanges || !layers[i].visible) {+ const dateRanges = getDateRanges(layers[i]);+ if (!dateRanges || !dateRanges.length || !layers[i].visible) {invalidLayerCount += 1;} else if (signConstant > 0) {// Forward in timeconst foundIndex = dateRanges.findIndex(- (element) => element.startDate > date,+ (element) => new Date(element.startDate) > dateAObj,);- const startingIndex = foundIndex - 5 < 0 ? 0 : foundIndex - 5;- // endingIndex gives 10 tries to find a valid next interval+ const startingIndex = foundIndex < 0 ? 0 : foundIndex;+ // endingIndex gives 5 tries to find a valid next intervalconst endingIndex = foundIndex + 5 > dateRanges.length? dateRanges.length: foundIndex + 5;@@ -634,10 +665,10 @@ export function getNextImageryDelta(layers, date, signConstant) {} else {// Backward in timeconst foundIndex = [...dateRanges].reverse().findIndex(- (element) => element.endDate < date,+ (element) => new Date(element.endDate) < dateAObj,);- const startingIndex = foundIndex - 5 < 0 ? 0 : foundIndex - 5;- // endingIndex gives 10 tries to find a valid next interval+ const startingIndex = foundIndex < 0 ? 0 : foundIndex;+ // endingIndex gives 5 tries to find a valid next intervalconst endingIndex = foundIndex + 5 > dateRanges.length? dateRanges.length: foundIndex + 5;diff --git a/web/js/modules/layers/util.js b/web/js/modules/layers/util.jsindex ad2d72728..82adb0362 100644--- a/web/js/modules/layers/util.js+++ b/web/js/modules/layers/util.js@@ -684,6 +684,23 @@ const getSubdailyDateRange = ({return newDateArray;};+/**+ * Return an array of dateRanges for subdaily layers+ *+ * @method fetchSubdailyDateRanges+ * @param {String} def The layer id+ * @return {Array} An array of dateRanges+ */+export async function fetchSubdailyDateRanges(id) {+ try {+ const response = await fetch(`config/dateRanges/${id}.json`);+ const result = await response.json();+ return result;+ } catch {+ return [];+ }+}+/*** Return an array of dates based on the dateRange the current date falls in.*@@ -697,14 +714,22 @@ const getSubdailyDateRange = ({* @param {Object} appNow A date object of appNow (current date or set explicitly)* @return {Array} An array of dates with normalized timezones*/-export function datesInDateRanges(def, date, startDateLimit, endDateLimit, appNow) {+export async function datesInDateRanges(def, date, startDateLimit, endDateLimit, appNow) {const {- dateRanges,futureTime,period,ongoing,} = def;let dateArray = [];+ if (!def.dateRanges && def.period === 'subdaily') {+ const result = await fetchSubdailyDateRanges(def.id);+ if (result) {+ def.dateRanges = result;+ }+ }+ const {+ dateRanges,+ } = def;if (!dateRanges) { return dateArray; }const rangeLimitsProvided = !!(startDateLimit && endDateLimit);let currentDate = new Date(date);@@ -1489,7 +1514,8 @@ export function adjustStartDates(layers) {console.warn(`GetCapabilities is missing the time value for ${layer.id}`);}- if (Array.isArray(historicalRanges) && historicalRanges.length) {+ if (Array.isArray(historicalRanges) && historicalRanges.length &&+ Array.isArray(dateRanges) && dateRanges.length) {layer.startDate = historicalRanges[0].startDate;historicalRanges.reverse().forEach((range) => {layer.dateRanges.unshift(range);diff --git a/web/js/modules/layers/util.test.js b/web/js/modules/layers/util.test.jsindex 679b89d85..eb800c5fc 100644--- a/web/js/modules/layers/util.test.js+++ b/web/js/modules/layers/util.test.js@@ -289,7 +289,7 @@ describe('Date range building', () => {expect(dateRanges.length).toBe(4);expect(dateRanges[3].endDate).toBe('2021-04-30T16:00:00Z');});- test('test limited date range returned for layer with single date range and interval [layers-limited-date-range]', () => {+ test('test limited date range returned for layer with single date range and interval [layers-limited-date-range]', async () => {const parameters = {products: 'terra-cr',};@@ -301,10 +301,10 @@ describe('Date range building', () => {config,);const activeLayers = stateFromLocation.layers.active.layers;- const dates = datesInDateRanges(activeLayers[0], new Date('2020-01-01'));+ const dates = await datesInDateRanges(activeLayers[0], new Date('2020-01-01'));expect(dates.length).toBe(3);});- test('test only next date returned (out of range past) [layers-out-of-range-past]', () => {+ test('test only next date returned (out of range past) [layers-out-of-range-past]', async () => {const parameters = {products: 'terra-cr',};@@ -316,10 +316,10 @@ describe('Date range building', () => {config,);const activeLayers = stateFromLocation.layers.active.layers;- const dates = datesInDateRanges(activeLayers[0], new Date('1990-01-01'));+ const dates = await datesInDateRanges(activeLayers[0], new Date('1990-01-01'));expect(dates.length).toBe(1);});- test('test no dates returned (out of range future) [layers-out-of-range-future]', () => {+ test('test no dates returned (out of range future) [layers-out-of-range-future]', async () => {const parameters = {products: 'terra-cr',};@@ -331,10 +331,10 @@ describe('Date range building', () => {config,);const activeLayers = stateFromLocation.layers.active.layers;- const dates = datesInDateRanges(activeLayers[0], new Date('2030-01-01'));+ const dates = await datesInDateRanges(activeLayers[0], new Date('2030-01-01'));expect(dates.length).toBe(0);});- test('test date range returned from given start/end date range for layer coverage panel [layers-coverage-panel]', () => {+ test('test date range returned from given start/end date range for layer coverage panel [layers-coverage-panel]', async () => {const parameters = {products: 'terra-cr',};@@ -346,7 +346,7 @@ describe('Date range building', () => {config,);const activeLayers = stateFromLocation.layers.active.layers;- const dates = datesInDateRanges(activeLayers[0], new Date('2018-01-01'), new Date('2017-12-01'), new Date('2018-02-01'), new Date('2020-01-01'));+ const dates = await datesInDateRanges(activeLayers[0], new Date('2018-01-01'), new Date('2017-12-01'), new Date('2018-02-01'), new Date('2020-01-01'));const isFirstDateEqual = dates[0].toISOString() === '2017-12-01T00:00:00.000Z';const isLastDateEqual = dates[dates.length - 1].toISOString() === '2018-01-31T00:00:00.000Z';expect(dates.length).toBe(62);diff --git a/web/js/modules/map/util.js b/web/js/modules/map/util.jsindex cbb0d0151..a892924ab 100644--- a/web/js/modules/map/util.js+++ b/web/js/modules/map/util.js@@ -240,7 +240,7 @@ function promiseLayerGroup(layerGroup, map) {* @method promiseImageryForTime* @return {object} Promise*/-export async function promiseImageryForTime(state, date, activeString) {+export async function promiseImageryForTime(state, date, activeString, isAutoAnimation = false) {const { map } = state;if (!map.ui.proj) return undefined;const {@@ -248,7 +248,7 @@ export async function promiseImageryForTime(state, date, activeString) {} = map.ui;const layers = getActiveVisibleLayersAtDate(state, date, activeString);await Promise.all(layers.map(async (layer) => {- if (layer.type === 'granule' || layer.type === 'titiler') {+ if ((layer.type === 'granule' && !isAutoAnimation) || layer.type === 'titiler') {return Promise.resolve();}const options = { date, group: activeString };diff --git a/web/scss/features/anim-widget.scss b/web/scss/features/anim-widget.scssindex d83b137d4..a794123f0 100644--- a/web/scss/features/anim-widget.scss+++ b/web/scss/features/anim-widget.scss@@ -122,7 +122,7 @@.wv-animation-widget {width: 334px;border-radius: 5px;- height: 136px;+ height: 142px;background: #212121;color: #fff;padding: 1px 0;