import { BBox } from '../bbox' ; import { GetMapParams , Interpolator , PreviewMode , ApiType , PaginatedTiles , MosaickingOrder } from './const' ; import { createProcessingPayload , convertPreviewToString , processingGetMap , ProcessingPayloadDatasource , } from './processing' ; import { AbstractSentinelHubV3Layer } from './AbstractSentinelHubV3Layer' ; import { RequestConfiguration } from '../utils/cancelRequests' ; import { ensureTimeout } from '../utils/ensureTimeout' ; import { Effects } from '../mapDataManipulation/const' ; import { runEffectFunctions } from '../mapDataManipulation/runEffectFunctions' ; interface ConstructorParameters { evalscript : string | null ; evalscriptUrl ? : string | null ; layers : DataFusionLayerInfo [ ] ; title ? : string | null ; description ? : string | null ; } export type DataFusionLayerInfo = { layer : AbstractSentinelHubV3Layer ; id ? : string ; fromTime ? : Date ; toTime ? : Date ; preview ? : PreviewMode ; mosaickingOrder ? : MosaickingOrder ; upsampling ? : Interpolator ; downsampling ? : Interpolator ; } ; export const DEFAULT_SH_SERVICE_HOSTNAME = 'https://services.sentinel-hub.com/' ; export class ProcessingDataFusionLayer extends AbstractSentinelHubV3Layer { protected layers : DataFusionLayerInfo [ ] ; public constructor ( { title = null , description = null , evalscript = null , evalscriptUrl = null , layers , } ) { super ( { title , description , evalscript , evalscriptUrl } ) ; this . layers = layers ; } public async getMap ( params , api , reqConfig ? ) { return await ensureTimeout ( async ( innerReqConfig ) => { params = await this . decideJpegOrPng ( params , innerReqConfig ) ; if ( api !== ApiType . PROCESSING ) { throw new Error ( `Only API type "PROCESSING" is supported` ) ; } await this . fetchEvalscriptUrlIfNeeded ( innerReqConfig ) ; const bogusFirstLayer = this . layers [ 0 ] . layer ; let payload = createProcessingPayload ( bogusFirstLayer . dataset , params , this . evalscript ) ; payload . input . data = [ ] ; for ( let i = 0 ; i < this . layers . length ; i ++ ) { const layerInfo = this . layers [ i ] ; let datasource = { dataFilter : { timeRange : { from : layerInfo . fromTime ? layerInfo . fromTime . toISOString ( ) : params . fromTime . toISOString ( ) , to : layerInfo . toTime ? layerInfo . toTime . toISOString ( ) : params . toTime . toISOString ( ) , } , mosaickingOrder : MosaickingOrder . MOST_RECENT , } , processing : { } , type : layerInfo . layer . dataset . shProcessingApiDatasourceAbbreviation , } ; if ( layerInfo . id !== undefined ) { datasource . id = layerInfo . id ; } if ( layerInfo . preview !== undefined ) { datasource . dataFilter . previewMode = convertPreviewToString ( layerInfo . preview ) ; } else if ( params . preview !== undefined ) { datasource . dataFilter . previewMode = convertPreviewToString ( params . preview ) ; } if ( layerInfo . layer . mosaickingOrder ) { datasource . dataFilter . mosaickingOrder = layerInfo . layer . mosaickingOrder ; } if ( layerInfo . layer . upsampling ) { datasource . processing . upsampling = layerInfo . layer . upsampling ; } if ( layerInfo . layer . downsampling ) { datasource . processing . downsampling = layerInfo . layer . downsampling ; } payload . input . data . push ( datasource ) ; await layerInfo . layer . _updateProcessingGetMapPayload ( payload , payload . input . data . length - 1 , reqConfig ) ; } let shServiceHostname ; if ( this . layers . every ( layer => layer . layer . dataset . shServiceHostname === bogusFirstLayer . dataset . shServiceHostname ) ) { shServiceHostname = bogusFirstLayer . dataset . shServiceHostname ; } else { shServiceHostname = DEFAULT_SH_SERVICE_HOSTNAME ; } let blob = await processingGetMap ( shServiceHostname , payload , innerReqConfig ) ; const effects = { gain : params . gain , gamma : params . gamma , ... params . effects } ; blob = await runEffectFunctions ( blob , effects ) ; return blob ; } , reqConfig ) ; } public supportsApiType ( api ) { return api === ApiType . PROCESSING ; } public async findTiles ( bbox , fromTime , toTime , maxCount = null , offset = null , reqConfig ? ) { throw new Error ( 'Not supported - use individual layers when searching for tiles or flyovers' ) ; } public async findDatesUTC ( bbox , fromTime , toTime ) { throw new Error ( 'Not supported - use individual layers when searching for available dates' ) ; } }