Skip to content

Commit 88f19d8

Browse files
authored
WV-3237 Alert users if snapshot exceeds GRANULE_LIMIT (#5394)
* feat: Add warning for truncated granule dates in ImageDownloadPanel * fix: Fix missing semicolon in ImageDownloadPanel
1 parent 7bc0790 commit 88f19d8

File tree

2 files changed

+58
-14
lines changed

2 files changed

+58
-14
lines changed

web/js/components/image-download/image-download-panel.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import React, { useState } from 'react';
1+
import React, { useState, useEffect } from 'react';
22
import PropTypes from 'prop-types';
33
import googleTagManager from 'googleTagManager';
44
import {
55
imageSizeValid,
66
getDimensions,
77
getDownloadUrl,
8+
getTruncatedGranuleDates,
9+
GRANULE_LIMIT,
810
} from '../../modules/image-download/util';
911
import SelectionList from '../util/selector';
1012
import ResTable from './grid';
@@ -54,6 +56,16 @@ function ImageDownloadPanel(props) {
5456
const [currIsWorldfile, setIsWorldfile] = useState(isWorldfile);
5557
const [currResolution, setResolution] = useState(resolution);
5658
const [debugUrl, setDebugUrl] = useState('');
59+
const [showGranuleWarning, setShowGranuleWarning] = useState(false);
60+
61+
useEffect(() => {
62+
const layerList = getLayers();
63+
const granuleDatesMap = new Map(map.getLayers().getArray().map((layer) => [layer.wv.id, layer.wv.granuleDates]));
64+
const layerDefs = layerList.map((def) => ({ ...def, granuleDates: granuleDatesMap.get(def.id) }));
65+
const isTruncated = getTruncatedGranuleDates(layerDefs, date).truncated;
66+
67+
setShowGranuleWarning(isTruncated);
68+
}, []);
5769

5870
const onDownload = (width, height) => {
5971
const time = new Date(date.getTime());
@@ -195,6 +207,9 @@ function ImageDownloadPanel(props) {
195207
proj={projection.id}
196208
map={map}
197209
/>
210+
{showGranuleWarning && (
211+
<p>Warning: A snapshot will capture a max. of {GRANULE_LIMIT} granules, additional granules are omitted.</p> // eslint-disable-line react/jsx-one-expression-per-line
212+
)}
198213
<ResTable
199214
width={width}
200215
height={height}

web/js/modules/image-download/util.js

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { CRS } from '../map/constants';
1010

1111
const GEO_ESTIMATION_CONSTANT = 256.0;
1212
const POLAR_ESTIMATION_CONSTANT = 0.002197265625;
13-
const GRANULE_LIMIT = 15;
13+
export const GRANULE_LIMIT = 30;
1414

1515
/**
1616
* Get a date time snapped to the interval of the layer with the shortest interval.
@@ -254,6 +254,46 @@ export function bboxWMS13(lonlats, crs) {
254254
}`;
255255
}
256256

257+
/**
258+
* Get the granule date string for each layer and whether or not the granule dates were truncated
259+
* @param {Array} layerDefs
260+
* @returns {Object} { truncated: Boolean, value: String }
261+
*/
262+
export function getTruncatedGranuleDates(layerDefs) {
263+
let numGranules = 0;
264+
let truncated = false;
265+
266+
return layerDefs.reduce((acc, def, i) => {
267+
let granuleDatesString = acc.value;
268+
if (!def.granuleDates) {
269+
return {
270+
truncated,
271+
value: granuleDatesString,
272+
};
273+
}
274+
granuleDatesString = `${acc.value}${i};`; // ensure that each granule layer gets an index
275+
if (numGranules >= GRANULE_LIMIT) { // limit number of granules to GRANULE_LIMIT
276+
truncated = true;
277+
278+
return {
279+
truncated,
280+
value: granuleDatesString,
281+
};
282+
}
283+
const numToAdd = GRANULE_LIMIT - numGranules;
284+
const truncatedDates = def.granuleDates.slice(0, numToAdd);
285+
numGranules += truncatedDates.length;
286+
const processedDates = truncatedDates.map((date) => date.split(':').filter((d) => d !== '00Z').join(':'));
287+
return {
288+
truncated,
289+
value: `${granuleDatesString}${processedDates.join(',')},`,
290+
};
291+
}, {
292+
truncated: false,
293+
value: '',
294+
});
295+
}
296+
257297
/**
258298
* Get the snapshots URL to download an image
259299
* @param {String} url
@@ -282,18 +322,7 @@ export function getDownloadUrl(url, proj, layerDefs, bbox, dimensions, dateTime,
282322
const imgFormat = fileType || 'image/jpeg';
283323
const { height, width } = dimensions;
284324
const snappedDateTime = getLatestIntervalTime(layerDefs, dateTime);
285-
let numGranules = 0;
286-
const granuleDates = layerDefs.reduce((acc, def, i) => {
287-
let granuleDatesString = acc;
288-
if (!def.granuleDates) return granuleDatesString;
289-
granuleDatesString = `${acc}${i};`; // ensure that each granule layer gets an index
290-
if (numGranules >= GRANULE_LIMIT) return granuleDatesString; // limit number of granules
291-
const numToAdd = GRANULE_LIMIT - numGranules;
292-
const truncatedDates = def.granuleDates.slice(0, numToAdd);
293-
numGranules += truncatedDates.length;
294-
const processedDates = truncatedDates.map((date) => date.split(':').filter((d) => d !== '00Z').join(':'));
295-
return `${granuleDatesString}${processedDates.join(',')},`;
296-
}, '');
325+
const granuleDates = getTruncatedGranuleDates(layerDefs).value;
297326
const params = [
298327
'REQUEST=GetSnapshot',
299328
`TIME=${util.toISOStringSeconds(snappedDateTime)}`,

0 commit comments

Comments
 (0)