@@ -10,7 +10,7 @@ import { CRS } from '../map/constants';
1010
1111const GEO_ESTIMATION_CONSTANT = 256.0 ;
1212const 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