diff --git a/src/layer/AbstractLayer.ts b/src/layer/AbstractLayer.ts index f31fc48c..b2f9a2f5 100644 --- a/src/layer/AbstractLayer.ts +++ b/src/layer/AbstractLayer.ts @@ -91,14 +91,19 @@ export class AbstractLayer { let flyoverIndex = 0; let currentFlyoverGeometry = null; + let nTilesInFlyover = 0; + let sumCloudCoverPercent = undefined; for (let tileIndex = 0; tileIndex < tiles.length; tileIndex++) { if (tileIndex === 0) { flyoverIntervals[flyoverIndex] = { fromTime: tiles[tileIndex].sensingTime, toTime: tiles[tileIndex].sensingTime, coveragePercent: 0, + meta: {}, }; currentFlyoverGeometry = tiles[tileIndex].geometry; + sumCloudCoverPercent = tiles[tileIndex].meta.cloudCoverPercent; + nTilesInFlyover = 1; continue; } @@ -109,18 +114,31 @@ export class AbstractLayer { if (diffMS < orbitTimeMS) { flyoverIntervals[flyoverIndex].toTime = tiles[tileIndex].sensingTime; currentFlyoverGeometry = union(currentFlyoverGeometry, tiles[tileIndex].geometry); + sumCloudCoverPercent = + sumCloudCoverPercent !== undefined + ? sumCloudCoverPercent + tiles[tileIndex].meta.cloudCoverPercent + : undefined; + nTilesInFlyover++; } else { flyoverIntervals[flyoverIndex].coveragePercent = this.calculateCoveragePercent( bbox, currentFlyoverGeometry, ); + if (sumCloudCoverPercent !== undefined) { + flyoverIntervals[flyoverIndex].meta.averageCloudCoverPercent = + sumCloudCoverPercent / nTilesInFlyover; + } + flyoverIndex++; flyoverIntervals[flyoverIndex] = { fromTime: tiles[tileIndex].sensingTime, toTime: tiles[tileIndex].sensingTime, coveragePercent: 0, + meta: {}, }; currentFlyoverGeometry = tiles[tileIndex].geometry; + sumCloudCoverPercent = tiles[tileIndex].meta.cloudCoverPercent; + nTilesInFlyover = 1; } } if (flyoverIntervals.length > 0) { @@ -128,6 +146,9 @@ export class AbstractLayer { bbox, currentFlyoverGeometry, ); + if (sumCloudCoverPercent !== undefined) { + flyoverIntervals[flyoverIndex].meta.averageCloudCoverPercent = sumCloudCoverPercent / nTilesInFlyover; + } } return flyoverIntervals; } diff --git a/src/layer/const.ts b/src/layer/const.ts index ae507de3..2de937f9 100644 --- a/src/layer/const.ts +++ b/src/layer/const.ts @@ -63,6 +63,7 @@ export type FlyoverInterval = { fromTime: Date; toTime: Date; coveragePercent: number; + meta: Record; }; export type MimeType = diff --git a/stories/index.stories.js b/stories/index.stories.js index 03f9d665..f07e35ba 100644 --- a/stories/index.stories.js +++ b/stories/index.stories.js @@ -259,6 +259,52 @@ export const S1GRDFindTiles = () => { return wrapperEl; }; +export const findFlyovers = () => { + const layer = new S2L2ALayer(instanceId, s2l2aLayerId); + const bbox = new BBox(CRS_EPSG4326, 11.9, 42.05, 12.95, 43.09); + + const wrapperEl = document.createElement('div'); + wrapperEl.innerHTML = "

findFlyovers

"; + + const img = document.createElement('img'); + img.width = '512'; + img.height = '512'; + wrapperEl.insertAdjacentElement("beforeend", img); + + const flyoversContainerEl = document.createElement('pre'); + wrapperEl.insertAdjacentElement("beforeend", flyoversContainerEl); + + const perform = async () => { + await setAuthTokenWithOAuthCredentials(); + const fromTime = new Date(Date.UTC(2020, 1 - 1, 1, 0, 0, 0)); + const toTime = new Date(Date.UTC(2020, 1 - 1, 15, 6, 59, 59)); + const flyovers = await layer.findFlyovers( + bbox, + fromTime, + toTime, + 20, + 50, + ); + flyoversContainerEl.innerHTML = JSON.stringify(flyovers, null, true) + + // prepare an image to show that the number makes sense: + const getMapParams = { + bbox: bbox, + fromTime: fromTime, + toTime: toTime, + width: 512, + height: 512, + format: MimeTypes.JPEG, + }; + const imageBlob = await layer.getMap(getMapParams, ApiType.WMS); + img.src = URL.createObjectURL(imageBlob); + }; + perform().then(() => {}); + + return wrapperEl; +}; + + function renderTilesList(containerEl, list) { list.forEach(tile => { const ul = document.createElement('ul');