Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

add future date range for layers

Ed Platobda252f1ebb9
diff --git a/web/js/components/location-search/location-search-input.js b/web/js/components/location-search/location-search-input.js
index 60c1537bd..9590cbf46 100644
--- a/web/js/components/location-search/location-search-input.js
+++ b/web/js/components/location-search/location-search-input.js
@@ -43,7 +43,7 @@ class SearchBox extends Component {
if (coordinatesPending.length > 0) {
onCoordinateInputSelect();
} else if (suggestions.length > 0) {
- // submit hightlighted item in search result menu
+ // submit highlighted item in search result menu
if (this.highlightedItem) {
onSelect(this.highlightedItem.text, this.highlightedItem);
} else {
@@ -192,7 +192,7 @@ class SearchBox extends Component {
);
}
- // condtional autocomplete wrapper styling
+ // conditional autocomplete wrapper styling
getWrapperStyle = () => {
const {
inputValue,
diff --git a/web/js/components/timeline/timeline-coverage/coverage-item-container.js b/web/js/components/timeline/timeline-coverage/coverage-item-container.js
index fff9d4adf..2964f96d8 100644
--- a/web/js/components/timeline/timeline-coverage/coverage-item-container.js
+++ b/web/js/components/timeline/timeline-coverage/coverage-item-container.js
@@ -116,7 +116,7 @@ class CoverageItemContainer extends Component {
visible,
} = layer;
- // condtional styling for line/background colors
+ // conditional styling for line/background colors
const {
lineBackgroundColor,
} = getLayerItemStyles(visible, id);
diff --git a/web/js/components/timeline/timeline-coverage/coverage-item-list.js b/web/js/components/timeline/timeline-coverage/coverage-item-list.js
index e21a9a9e2..cda42c81b 100644
--- a/web/js/components/timeline/timeline-coverage/coverage-item-list.js
+++ b/web/js/components/timeline/timeline-coverage/coverage-item-list.js
@@ -2,7 +2,7 @@ import React, { Component } from 'react';
import PropTypes from 'prop-types';
import moment from 'moment';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
-import { datesinDateRanges } from '../../../modules/layers/util';
+import { datesInDateRanges } from '../../../modules/layers/util';
import util from '../../../util/util';
import {
timeScaleToNumberKey,
@@ -295,7 +295,7 @@ class CoverageItemList extends Component {
const layerIdDates = `${appNow.toISOString()}-${frontDate}-${backDate}`;
if (this.layerDateArrayCache[id][layerIdDates] === undefined) {
- dateIntervalStartDates = datesinDateRanges(def, startDateLimit, startDateLimit, endDateLimit, appNow);
+ dateIntervalStartDates = datesInDateRanges(def, startDateLimit, startDateLimit, endDateLimit, appNow);
this.layerDateArrayCache[id][layerIdDates] = dateIntervalStartDates;
} else {
dateIntervalStartDates = this.layerDateArrayCache[id][layerIdDates];
@@ -315,7 +315,7 @@ class CoverageItemList extends Component {
*/
getLayerItemStyles = (visible, id) => {
const { hoveredLayer } = this.state;
- // condtional styling for line/background colors
+ // conditional styling for line/background colors
const containerBackgroundColor = visible
? 'rgb(204, 204, 204)'
: 'rgb(79, 79, 79)';
@@ -402,7 +402,7 @@ class CoverageItemList extends Component {
// concat (ex: day to days) for moment manipulation below
layerPeriod += 's';
- // condtional styling for line/background colors
+ // conditional styling for line/background colors
const {
layerItemBackground,
layerItemOutline,
diff --git a/web/js/fixtures.js b/web/js/fixtures.js
index a2a37a634..9940f73e3 100644
--- a/web/js/fixtures.js
+++ b/web/js/fixtures.js
@@ -274,6 +274,37 @@ fixtures.config = function() {
},
inactive: true,
},
+ MODIS_Combined_L4_LAI_4Day: {
+ id: 'MODIS_Combined_L4_LAI_4Day',
+ title: 'Leaf Area Index (L4, 4-Day)',
+ subtitle: 'Terra and Aqua / MODIS',
+ description: 'modis/combined/MODIS_Combined_L4_LAI_4Day',
+ group: 'overlays',
+ product: 'MCD15A3H',
+ layergroup: 'Leaf Area Index',
+ dateRanges: [
+ {
+ startDate: '2018-01-01T00:00:00Z',
+ endDate: '2018-12-27T00:00:00Z',
+ dateInterval: '4',
+ },
+ {
+ startDate: '2019-01-01T00:00:00Z',
+ endDate: '2019-12-27T00:00:00Z',
+ dateInterval: '4',
+ },
+ {
+ startDate: '2020-01-01T00:00:00Z',
+ endDate: '2020-09-26T00:00:00Z',
+ dateInterval: '4',
+ },
+ ],
+ projections: {
+ geographic: {},
+ arctic: {},
+ antarctic: {},
+ },
+ },
'terra-aod': {
id: 'terra-aod',
group: 'overlays',
diff --git a/web/js/main.js b/web/js/main.js
index 2cbb3421d..ad4cf050a 100644
--- a/web/js/main.js
+++ b/web/js/main.js
@@ -33,9 +33,9 @@ import parse from './parse';
import combineUi from './combine-ui';
import { preloadPalettes, hasCustomTypePalette } from './modules/palettes/util';
import {
- validate as layerValidate,
layersParse12,
adjustEndDates,
+ adjustActiveDateRanges,
adjustStartDates,
mockFutureTimeLayerOptions,
} from './modules/layers/util';
@@ -44,7 +44,6 @@ import { CUSTOM_PALETTE_TYPE_ARRAY } from './modules/palettes/constants';
const history = createBrowserHistory();
const configURI = Brand.url('config/wv.json');
-const startTime = Date.now();
const compose = DEBUG === false || DEBUG === 'logger'
? defaultCompose
: DEBUG === 'devtools' && composeWithDevTools({
@@ -63,7 +62,6 @@ const compose = DEBUG === false || DEBUG === 'logger'
},
});
let parameters = util.fromQueryString(window.location.search);
-let { elapsed } = util;
const errors = [];
/**
@@ -107,7 +105,6 @@ function render (config, legacyState) {
),
);
listenForHistoryChange(store, history);
- elapsed('Render', startTime, parameters);
ReactDOM.render(
<Provider store={store}>
@@ -121,10 +118,6 @@ function render (config, legacyState) {
// Document ready function
window.onload = () => {
- if (!parameters.elapsed) {
- elapsed = function() {};
- }
- elapsed('loading config', startTime, parameters);
const promise = fetch(configURI);
promise
@@ -162,7 +155,6 @@ window.onload = () => {
custom: {},
};
- elapsed('Config loaded', config.now, parameters);
// Determine which layers need to be preloaded
let layers = [];
if (
@@ -185,8 +177,11 @@ window.onload = () => {
});
}
const legacyState = parse(parameters, config, errors);
- layerValidate(errors, config);
adjustStartDates(config.layers);
+
+ // handle extending active layer date ranges
+ adjustActiveDateRanges(config.layers, pageLoadTime);
+
// handle add mock future time to provided layer id
if (parameters.mockFutureLayer) {
mockFutureTimeLayerOptions(config.layers, parameters.mockFutureLayer);
diff --git a/web/js/map/layerbuilder.js b/web/js/map/layerbuilder.js
index 9e7ab543f..b82c95821 100644
--- a/web/js/map/layerbuilder.js
+++ b/web/js/map/layerbuilder.js
@@ -19,7 +19,7 @@ import lodashGet from 'lodash/get';
import util from '../util/util';
import lookupFactory from '../ol/lookupimagetile';
import { createVectorUrl, getGeographicResolutionWMS, mergeBreakpointLayerAttributes } from './util';
-import { datesinDateRanges, prevDateInDateRange } from '../modules/layers/util';
+import { datesInDateRanges, prevDateInDateRange } from '../modules/layers/util';
import getSelectedDate from '../modules/date/selectors';
import {
isActive as isPaletteActive,
@@ -35,13 +35,9 @@ import {
nearestInterval,
} from '../modules/layers/util';
-export default function mapLayerBuilder(models, config, cache, ui, store) {
+export default function mapLayerBuilder(config, cache, store) {
const self = {};
- self.init = function() {
- self.extentLayers = [];
- };
-
/**
* Return a layer, or layergroup, created with the supplied function
* @param {*} createLayerFunc
@@ -70,7 +66,7 @@ export default function mapLayerBuilder(models, config, cache, ui, store) {
* For subdaily layers, if the layer date is within 30 minutes of current
* time, set expiration to ten minutes from now
*/
- const getCacheOptions = (period, date, state) => {
+ const getCacheOptions = (period, date) => {
const tenMin = 10 * 60000;
const thirtyMin = 30 * 60000;
const now = Date.now();
@@ -108,7 +104,7 @@ export default function mapLayerBuilder(models, config, cache, ui, store) {
if (!layer) {
// layer is not in the cache
if (!date) date = options.date || getSelectedDate(state);
- const cacheOptions = getCacheOptions(def.period, date, state);
+ const cacheOptions = getCacheOptions(def.period, date);
const attributes = {
id: def.id,
key,
@@ -178,6 +174,8 @@ export default function mapLayerBuilder(models, config, cache, ui, store) {
*/
self.getRequestDates = function(def, options) {
const state = store.getState();
+ const { date } = state;
+ const { appNow } = date;
const stateCurrentDate = new Date(getSelectedDate(state));
const previousLayer = options.previousLayer || {};
let closestDate = options.date || stateCurrentDate;
@@ -194,7 +192,40 @@ export default function mapLayerBuilder(models, config, cache, ui, store) {
) {
previousDateFromRange = previousLayerDate;
} else {
- const dateRange = datesinDateRanges(def, closestDate);
+ const { dateRanges, inactive, period } = def;
+ let dateRange;
+ if (inactive) {
+ dateRange = datesInDateRanges(def, closestDate);
+ } else {
+ let endDateLimit;
+ let startDateLimit;
+
+ let interval = 1;
+ if (dateRanges && dateRanges.length > 0) {
+ for (let i = 0; i < dateRanges.length; i += 1) {
+ const d = dateRanges[i];
+ const int = Number(d.dateInterval);
+ if (int > interval) {
+ interval = int;
+ }
+ }
+ }
+
+ if (period === 'daily') {
+ endDateLimit = util.dateAdd(closestDate, 'day', interval);
+ startDateLimit = util.dateAdd(closestDate, 'day', -interval);
+ } else if (period === 'monthly') {
+ endDateLimit = util.dateAdd(closestDate, 'month', interval);
+ startDateLimit = util.dateAdd(closestDate, 'month', -interval);
+ } else if (period === 'yearly') {
+ endDateLimit = util.dateAdd(closestDate, 'year', interval);
+ startDateLimit = util.dateAdd(closestDate, 'year', -interval);
+ } else {
+ endDateLimit = new Date(closestDate);
+ startDateLimit = new Date(closestDate);
+ }
+ dateRange = datesInDateRanges(def, closestDate, startDateLimit, endDateLimit, appNow);
+ }
const { next, previous } = prevDateInDateRange(def, closestDate, dateRange);
previousDateFromRange = previous;
previousLayerDate = previous;
@@ -274,7 +305,7 @@ export default function mapLayerBuilder(models, config, cache, ui, store) {
const setlimitsLen = matrixSetLimits && matrixSetLimits.length;
// If number of set limits doesn't match sets, we are assuming this product
- // crosses the antimeridian and don't have a reliable way to calculate a single
+ // crosses the anti-meridian and don't have a reliable way to calculate a single
// extent based on multiple set limits.
if (!matrixSetLimits || setlimitsLen !== resolutionLen || day) {
return { origin, extent };
@@ -562,6 +593,5 @@ export default function mapLayerBuilder(models, config, cache, ui, store) {
return layer;
};
- self.init();
return self;
}
diff --git a/web/js/map/ui.js b/web/js/map/ui.js
index 436bc3c9c..cb4a1f944 100644
--- a/web/js/map/ui.js
+++ b/web/js/map/ui.js
@@ -90,10 +90,8 @@ export default function mapui(models, config, store, ui) {
self.proj = {}; // One map for each projection
self.selected = null; // The map for the selected projection
const layerBuilder = self.layerBuilder = mapLayerBuilder(
- models,
config,
cache,
- ui,
store,
);
self.layerKey = layerBuilder.layerKey;
diff --git a/web/js/modules/layers/util.js b/web/js/modules/layers/util.js
index 592244627..252ad70b3 100644
--- a/web/js/modules/layers/util.js
+++ b/web/js/modules/layers/util.js
@@ -1,10 +1,7 @@
import {
get as lodashGet,
- cloneDeep as lodashCloneDeep,
eachRight as lodashEachRight,
isUndefined as lodashIsUndefined,
- remove as lodashRemove,
- findIndex as lodashFindIndex,
each as lodashEach,
isNaN as lodashIsNaN,
startCase as lodashStartCase,
@@ -65,7 +62,7 @@ export function nearestInterval(def, date) {
* @param {object} def A layer definition
* @param {object} date A date to compare against the array of dates
* @param {array} dateArray An array of dates
- * @return {object} The date object with normalized timeszone.
+ * @return {object} The date object with normalized timezone.
*/
export function prevDateInDateRange(def, date, dateArray) {
const closestAvailableDates = [];
@@ -635,7 +632,7 @@ const getSubdailyDateRange = ({
/**
* Return an array of dates based on the dateRange the current date falls in.
*
- * @method datesinDateRanges
+ * @method datesInDateRanges
* @param {Object} def A layer object
* @param {Object} date A date object for currently selected date
* @param {Object} startDateLimit A date object used as start date of timeline range for available data
@@ -643,15 +640,16 @@ 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 function datesInDateRanges(def, date, startDateLimit, endDateLimit, appNow) {
const {
dateRanges,
futureTime,
period,
inactive,
} = def;
- const rangeLimitsProvided = !!(startDateLimit && endDateLimit);
let dateArray = [];
+ if (!dateRanges) { return dateArray; }
+ const rangeLimitsProvided = !!(startDateLimit && endDateLimit);
let currentDate = new Date(date);
let inputStartDate;
@@ -665,8 +663,7 @@ export function datesinDateRanges(def, date, startDateLimit, endDateLimit, appNo
inputStartDateTime = inputStartDate.getTime();
inputEndDateTime = inputEndDate.getTime();
} else {
- singleDateRangeAndInterval = dateRanges
- && dateRanges.length === 1
+ singleDateRangeAndInterval = dateRanges.length === 1
&& dateRanges[0].dateInterval === '1';
}
@@ -858,28 +855,6 @@ export function serializeGroupOverlays (groupOverlays, state, activeString) {
return groupOverlays;
}
-export function toggleVisibility(id, layers) {
- const index = lodashFindIndex(layers, {
- id,
- });
- if (index === -1) {
- throw new Error(`Invalid layer ID: ${id}`);
- }
- const visibility = !layers[index].visible;
-
- return update(layers, { [index]: { visible: { $set: visibility } } });
-}
-
-export function removeLayer(id, layers) {
- const index = lodashFindIndex(layers, {
- id,
- });
- if (index === -1) {
- throw new Error(`Invalid layer ID: ${id}`);
- }
- return update(layers, { $splice: [[index, 1]] });
-}
-
// this function takes an array of date ranges in this format:
// [{ layer.period, dateRanges.startDate: Date, dateRanges.endDate: Date, dateRanges.dateInterval: Number}]
// the array is first sorted, and then checked for any overlap
@@ -1171,37 +1146,6 @@ const createLayerArrayFromState = function(state, config) {
return layerArray;
};
-export function validate(errors, config) {
- const error = function(layerId, cause) {
- errors.push({
- message: `Invalid layer: ${layerId}`,
- cause,
- layerRemoved: true,
- });
- delete config.layers[layerId];
- lodashRemove(config.layerOrder.baselayers, (e) => e === layerId);
- lodashRemove(config.layerOrder.overlays, (e) => e === layerId);
- };
-
- const layers = lodashCloneDeep(config.layers);
- lodashEach(layers, (layer) => {
- if (!layer.group) {
- error(layer.id, 'No group defined');
- return;
- }
- if (!layer.projections) {
- error(layer.id, 'No projections defined');
- }
- });
-
- const orders = lodashCloneDeep(config.layerOrder);
- lodashEach(orders, (layerId) => {
- if (!config.layers[layerId]) {
- error(layerId, 'No configuration');
- }
- });
-}
-
export function mapLocationToLayerState(
parameters,
stateFromLocation,
@@ -1405,6 +1349,92 @@ export function adjustStartDates(layers) {
return Object.values(layers).forEach(applyDateAdjustment);
}
+/**
+ * For active, multi-interval layers with on going coverage,
+ * date ranges are modified and added for layer config
+ *
+ * @method adjustActiveDateRanges
+ * @param {Array} layers array
+ * @param {Object} appNow - pageLoadTime date
+ * @returns {Array} array of layers
+ */
+export function adjustActiveDateRanges(layers, appNow) {
+ // active layers that can't be future predicted reliably due to sparse coverage
+ const ignoredLayers = {
+ AMSRU2_Snow_Water_Equivalent_5Day: true,
+ };
+ const appNowYear = appNow.getUTCFullYear();
+ const applyDateRangeAdjustment = (layer) => {
+ const { dateRanges } = layer;
+ const { inactive, id, period } = layer;
+ const failConditions = inactive
+ || ignoredLayers[id]
+ || !dateRanges
+ || period === 'subdaily';
+ if (failConditions) {
+ return;
+ }
+
+ const dateRangesModified = [...dateRanges];
+ for (let i = 0; i < dateRangesModified.length; i += 1) {
+ const dateRange = dateRangesModified[i];
+ const {
+ endDate,
+ startDate,
+ dateInterval,
+ } = dateRange;
+
+ const dateIntervalNum = Number(dateInterval);
+ if (i === dateRangesModified.length - 1 && dateIntervalNum > 1) {
+ // create/add dynamic dates to iterated dateRange
+ const start = new Date(startDate);
+ const startDateYear = start.getUTCFullYear();
+
+ if (startDateYear < appNowYear) {
+ const dynamicStartYear = start.getUTCFullYear() + 1;
+ const dynamicStartDate = new Date(start.setUTCFullYear(dynamicStartYear));
+
+ const end = new Date(endDate);
+ const endDateYear = end.getUTCFullYear();
+ const dynamicEndYear = end.getUTCFullYear() + 1;
+ let dynamicEndDate = new Date(end.setUTCFullYear(dynamicEndYear));
+
+ // don't extend endDate past appNow
+ dynamicEndDate = dynamicEndDate < appNow
+ ? dynamicEndDate
+ : appNow;
+
+ // extend endDate till end of year if before appNow year
+ // ex: app build date 11/2020 and it's 04/2021 now, this will extend to end of 12/2020
+ if (endDateYear < appNowYear) {
+ let endOfYearDate = new Date('2021-12-31T00:00:00.000Z');
+ endOfYearDate = new Date(endOfYearDate.setUTCFullYear(endDateYear));
+ const modifiedDateRange = {
+ startDate,
+ endDate: util.toISOStringSeconds(endOfYearDate),
+ dateInterval,
+ };
+ dateRangesModified.splice(i, 1, modifiedDateRange);
+ }
+
+ // add date range to modified layer dateRanges
+ if (dynamicStartDate < appNow) {
+ const dynamicDateRange = {
+ startDate: util.toISOStringSeconds(dynamicStartDate),
+ endDate: util.toISOStringSeconds(dynamicEndDate),
+ dateInterval,
+ };
+ dateRangesModified.push(dynamicDateRange);
+ }
+ }
+ }
+ }
+ layer.dateRanges = dateRangesModified;
+ };
+
+ return Object.values(layers).forEach(applyDateRangeAdjustment);
+}
+
/**
* Change end dates for future layers to add 'futureTime' (ex: '3D')
* Adjust def.endDate and, if applicable, the last endDate in dateRange object
diff --git a/web/js/modules/layers/util.test.js b/web/js/modules/layers/util.test.js
index 754312a08..9d99fa665 100644
--- a/web/js/modules/layers/util.test.js
+++ b/web/js/modules/layers/util.test.js
@@ -1,10 +1,9 @@
import { assign } from 'lodash';
import {
- datesinDateRanges,
+ adjustActiveDateRanges,
+ datesInDateRanges,
serializeLayers,
layersParse12,
- removeLayer,
- toggleVisibility,
mapLocationToLayerState,
isVectorLayerClickable,
hasNonClickableVectorLayer,
@@ -100,22 +99,7 @@ test('serialize layers and palettes', () => {
expect(layerStr).toBe('terra-aod(hidden,opacity=0.54)');
});
-test('removeLayer util function', () => {
- const layers = [config.layers['terra-cr'], config.layers['terra-aod']];
- const newLayers = removeLayer('terra-cr', layers);
- expect(newLayers.length).toBe(1);
- expect(newLayers[0].id).toBe('terra-aod');
-});
-
-test('toggleVisibility util function', () => {
- const terraCrLayer = config.layers['terra-cr'];
- terraCrLayer.visible = false;
- const layers = [config.layers['terra-aod'], terraCrLayer];
- const newLayers = toggleVisibility('terra-cr', layers);
- expect(newLayers[1].visible).toBe(true);
-});
-
-// Permalionk 1.0
+// Permalink 1.0
describe('permalink 1.0', () => {
beforeEach(() => {
defaultStateFromLocation = {
@@ -144,7 +128,7 @@ describe('permalink 1.0', () => {
});
});
-// Permalionk 1.1
+// Permalink 1.1
describe('permalink 1.1', () => {
beforeEach(() => {
defaultStateFromLocation = {
@@ -251,6 +235,37 @@ describe('permalink 1.1', () => {
expect(activeLayers[0].id).toBe('terra-cr');
expect(activeLayers[0].visible).toBeFalsy();
});
+});
+
+// Date range building
+describe('Date range building', () => {
+ beforeEach(() => {
+ defaultStateFromLocation = {
+ layers: {
+ active: {
+ layers: [],
+ },
+ },
+ };
+ });
+
+ test('test active multi-day layers are extending beyond known GC end date using adjustActiveDateRanges', () => {
+ const parameters = {
+ products: 'MODIS_Combined_L4_LAI_4Day',
+ };
+
+ const stateFromLocation = mapLocationToLayerState(
+ parameters,
+ defaultStateFromLocation,
+ globalState,
+ config,
+ );
+ const activeLayers = stateFromLocation.layers.active.layers;
+ adjustActiveDateRanges(activeLayers, new Date('2021-04-30T16:00:00Z'));
+ const { dateRanges } = activeLayers[0];
+ 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', () => {
const parameters = {
products: 'terra-cr',
@@ -263,7 +278,7 @@ describe('permalink 1.1', () => {
config,
);
const activeLayers = stateFromLocation.layers.active.layers;
- const dates = datesinDateRanges(activeLayers[0], new Date('2020-01-01'));
+ const dates = datesInDateRanges(activeLayers[0], new Date('2020-01-01'));
expect(dates.length).toBe(3);
});
test('test only next date returned (out of range past)', () => {
@@ -278,7 +293,7 @@ describe('permalink 1.1', () => {
config,
);
const activeLayers = stateFromLocation.layers.active.layers;
- const dates = datesinDateRanges(activeLayers[0], new Date('1990-01-01'));
+ const dates = datesInDateRanges(activeLayers[0], new Date('1990-01-01'));
expect(dates.length).toBe(1);
});
test('test no dates returned (out of range future)', () => {
@@ -293,7 +308,7 @@ describe('permalink 1.1', () => {
config,
);
const activeLayers = stateFromLocation.layers.active.layers;
- const dates = datesinDateRanges(activeLayers[0], new Date('2030-01-01'));
+ const dates = 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', () => {
@@ -308,7 +323,7 @@ describe('permalink 1.1', () => {
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 = 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);
@@ -316,6 +331,7 @@ describe('permalink 1.1', () => {
expect(isLastDateEqual).toBeTruthy();
});
});
+
describe('Vector layers', () => {
const breakPointLayer = {
projections: {
@@ -372,7 +388,7 @@ describe('Vector layers', () => {
expect(false1).toBe(false);
expect(true1).toBe(true);
});
- test(' hasVectorLayers func', () => {
+ test('hasVectorLayers func', () => {
const false1 = hasVectorLayers([{ type: 'wms', visible: true }], 0.1);
const false2 = hasVectorLayers([{ type: 'vector', visible: false }], 0.1);
const true1 = hasVectorLayers(layers);
diff --git a/web/js/util/util.js b/web/js/util/util.js
index 6890ed8e9..af891fae6 100644
--- a/web/js/util/util.js
+++ b/web/js/util/util.js
@@ -91,12 +91,6 @@ export default (function(self) {
}
return result;
};
- self.elapsed = function(message, startTime, parameters) {
- if (parameters && !parameters.elapsed) return;
- const t = Date.now() - startTime;
- console.log(t, message);
- return t;
- };
/**
* Converts an object to a query string. For example, the following
@@ -255,25 +249,24 @@ export default (function(self) {
self.coverageDateFormatter = function(dateType, date, period) {
let dateString;
- date = this.parseDate(date);
-
+ const parsedDate = this.parseDate(date);
switch (period) {
case 'subdaily':
- dateString = `${moment(date).format('DD MMMM YYYY HH:mm')}Z`;
+ dateString = `${moment(parsedDate).format('DD MMMM YYYY HH:mm')}Z`;
break;
case 'yearly':
- if (dateType === 'END-DATE') date.setFullYear(date.getFullYear() - 1);
- dateString = moment(date).format('YYYY');
+ if (dateType === 'END-DATE') parsedDate.setFullYear(parsedDate.getFullYear() - 1);
+ dateString = moment(parsedDate).format('YYYY');
break;
case 'monthly':
- if (dateType === 'END-DATE') date.setMonth(date.getMonth() - 1);
- dateString = moment(date).format('MMMM YYYY');
+ if (dateType === 'END-DATE') parsedDate.setMonth(parsedDate.getMonth() - 1);
+ dateString = moment(parsedDate).format('MMMM YYYY');
break;
default:
- dateString = moment(date).format('DD MMMM YYYY');
+ dateString = moment(parsedDate).format('DD MMMM YYYY');
break;
}
@@ -443,8 +436,7 @@ export default (function(self) {
return newDate;
};
- self.getNumberOfDays = function(start, end, interval, increment, maxToCheck) {
- increment = increment || 1;
+ self.getNumberOfDays = function(start, end, interval, increment = 1, maxToCheck) {
let i = 1;
let currentDate = start;
while (currentDate < end) {
@@ -620,9 +612,7 @@ export default (function(self) {
};
};
- self.rollDate = function(date, interval, amount, minDate, maxDate) {
- minDate = minDate || self.minDate();
- maxDate = maxDate || self.maxDate();
+ self.rollDate = function(date, interval, amount, minDate = self.minDate(), maxDate = self.maxDate()) {
const range = self.rollRange(date, interval, minDate, maxDate);
const min = range.first;
const max = range.last;
@@ -756,13 +746,9 @@ export default (function(self) {
self.errorReport = function(errors) {
// eslint-disable-next-line no-unused-vars
- let layersRemoved = 0;
lodashEach(errors, (error) => {
const cause = error.cause ? `: ${error.cause}` : '';
self.warn(error.message + cause);
- if (error.layerRemoved) {
- layersRemoved += 1;
- }
});
};