diff --git a/src/layer/S3SYNL2CDASLayer.ts b/src/layer/S3SYNL2CDASLayer.ts index ed010e42..7dd1c579 100644 --- a/src/layer/S3SYNL2CDASLayer.ts +++ b/src/layer/S3SYNL2CDASLayer.ts @@ -4,14 +4,45 @@ import { DATASET_CDAS_S3SYNERGYL2 } from './dataset'; import { AbstractSentinelHubV3WithCCLayer } from './AbstractSentinelHubV3WithCCLayer'; import { RequestConfiguration } from '../utils/cancelRequests'; -import { PaginatedTiles, Link, LinkType, FindTilesAdditionalParameters } from './const'; +import { PaginatedTiles, Link, LinkType, FindTilesAdditionalParameters, DataProductId } from './const'; +import { ProcessingPayload } from './processing'; + +interface ConstructorParameters { + instanceId?: string | null; + layerId?: string | null; + evalscript?: string | null; + evalscriptUrl?: string | null; + dataProduct?: DataProductId | null; + title?: string | null; + description?: string | null; + legendUrl?: string | null; + maxCloudCoverPercent?: number | null; + highlights?: AbstractSentinelHubV3WithCCLayer['highlights']; + s3Type?: string | null; +} type S3SYNL2FindTilesDatasetParameters = { type?: string; + s3Type?: string | null; }; export class S3SYNL2CDASLayer extends AbstractSentinelHubV3WithCCLayer { public readonly dataset = DATASET_CDAS_S3SYNERGYL2; + public s3Type: string | null; + + public constructor(props: ConstructorParameters) { + super(props); + this.s3Type = props.s3Type; + } + + public async _updateProcessingGetMapPayload( + payload: ProcessingPayload, + datasetSeqNo: number = 0, + ): Promise { + payload = await super._updateProcessingGetMapPayload(payload); + payload.input.data[datasetSeqNo].dataFilter.s3Type = this.s3Type; + return payload; + } protected convertResponseFromSearchIndex(response: { data: { tiles: any[]; hasMore: boolean }; @@ -27,9 +58,32 @@ export class S3SYNL2CDASLayer extends AbstractSentinelHubV3WithCCLayer { }; } + protected extractFindTilesMeta(tile: any): Record { + return { + ...super.extractFindTilesMeta(tile), + s3Type: tile.s3Type, + }; + } + + protected extractFindTilesMetaFromCatalog(feature: Record): Record { + let result: Record = {}; + + if (!feature) { + return result; + } + + result = { + ...super.extractFindTilesMetaFromCatalog(feature), + s3Type: feature.properties['s3:type'], + }; + + return result; + } + protected getFindTilesAdditionalParameters(): FindTilesAdditionalParameters { const findTilesDatasetParameters: S3SYNL2FindTilesDatasetParameters = { type: this.dataset.shProcessingApiDatasourceAbbreviation, + s3Type: this.s3Type, }; return { @@ -47,6 +101,10 @@ export class S3SYNL2CDASLayer extends AbstractSentinelHubV3WithCCLayer { }, }; + if (this.s3Type) { + result.datasetParameters.s3Type = this.s3Type; + } + if (this.maxCloudCoverPercent !== null) { result.maxCloudCoverage = this.maxCloudCoverPercent / 100; } @@ -79,4 +137,40 @@ export class S3SYNL2CDASLayer extends AbstractSentinelHubV3WithCCLayer { } return result; } + + protected createCatalogFilterQuery( + maxCloudCoverPercent?: number | null, + datasetParameters?: Record | null, + ): Record { + let result = { ...super.createCatalogFilterQuery(maxCloudCoverPercent, datasetParameters) }; + + let conditions = []; + if (result) { + conditions.push(result); + } + + if (this.s3Type) { + conditions.push({ + op: '=', + args: [ + { + property: 's3:type', + }, + this.s3Type, + ], + }); + } + + // combine multiple conditions with AND + if (conditions.length > 1) { + result = { + op: 'and', + args: conditions, + }; + } else if (conditions.length === 1) { + result = conditions[0]; + } + + return result && Object.keys(result).length > 0 ? result : null; + } }