Skip to content

Commit

Permalink
Change layers with dataProduct to fetch tiles from processing api
Browse files Browse the repository at this point in the history
with exception of datasets/S2L1C/dataproducts/643
  • Loading branch information
Jan Kumer committed Sep 9, 2024
1 parent 37eb8e9 commit 2ece839
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/layer/AbstractSentinelHubV3Layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ import { wmsGetMapUrl } from './wms';

import { Effects } from '../mapDataManipulation/const';
import { runEffectFunctions } from '../mapDataManipulation/runEffectFunctions';
import { StatisticsProviderType } from '../statistics/const';
import { Fis } from '../statistics/Fis';
import { StatisticalApi } from '../statistics/StatisticalApi';
import { CACHE_CONFIG_30MIN, CACHE_CONFIG_NOCACHE } from '../utils/cacheHandlers';
import { fetchLayerParamsFromConfigurationService, getSHServiceRootUrl } from './utils';
import { StatisticsProviderType } from '../statistics/const';
import { fetchDataProduct, fetchLayerParamsFromConfigurationService, getSHServiceRootUrl } from './utils';

interface ConstructorParameters {
instanceId?: string | null;
Expand Down Expand Up @@ -127,6 +127,19 @@ export class AbstractSentinelHubV3Layer extends AbstractLayer {
if (!layerParams) {
throw new Error('Layer params could not be found');
}

if (
!layerParams['evalscript'] &&
layerParams['dataProduct'] &&
!SUPPORTED_DATA_PRODUCTS_PROCESSING.includes(layerParams['dataProduct'])
) {
const response = await fetchDataProduct(layerParams['dataProduct'], reqConfig);
const evalScript = response?.data?.evalScript;
if (evalScript) {
layerParams['evalscript'] = evalScript;
}
}

return layerParams;
}

Expand Down Expand Up @@ -236,10 +249,10 @@ export class AbstractSentinelHubV3Layer extends AbstractLayer {
}

public supportsApiType(api: ApiType): boolean {
if (this.dataProduct && !SUPPORTED_DATA_PRODUCTS_PROCESSING.includes(this.dataProduct)) {
return api === ApiType.WMS;
if (this.dataProduct && SUPPORTED_DATA_PRODUCTS_PROCESSING.includes(this.dataProduct)) {
return api === ApiType.PROCESSING;
}
return api === ApiType.WMS || (api === ApiType.PROCESSING && !!this.dataset);
return api === ApiType.WMS || (api === ApiType.PROCESSING && !!this.dataset && !!this.evalscript);
}

protected getWmsGetMapUrlAdditionalParameters(): Record<string, any> {
Expand Down Expand Up @@ -679,7 +692,7 @@ export class AbstractSentinelHubV3Layer extends AbstractLayer {
if (!this.downsampling && layerParams.downsampling) {
this.downsampling = layerParams.downsampling;
}
// this is a hotfix for `supportsApiType()` not having enough information - should be fixed properly later:

this.dataProduct = layerParams['dataProduct'] ? layerParams['dataProduct'] : null;
}, reqConfig);
}
Expand Down
28 changes: 28 additions & 0 deletions src/layer/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,34 @@ export async function fetchLayerParamsFromConfigurationService(
return layersParams;
}

export async function fetchDataProduct(url: string, reqConfig: RequestConfiguration): Promise<any> {
const authToken = reqConfig && reqConfig.authToken ? reqConfig.authToken : getAuthToken();
if (!authToken) {
throw new Error('Must be authenticated to fetch layer params');
}
const headers = {
Authorization: `Bearer ${authToken}`,
};

const requestConfig: AxiosRequestConfig = {
responseType: 'json',
headers: headers,
...getAxiosReqParams(
{
...reqConfig,
// Do not override cache if cache is disabled with `expiresIn: 0`
cache:
reqConfig && reqConfig.cache && reqConfig.cache.expiresIn === 0
? reqConfig.cache
: CACHE_CONFIG_30MIN_MEMORY,
},
null,
),
};
const res = await axios.get(url, requestConfig);
return res;
}

export function ensureMercatorBBox(bbox: BBox): BBox {
if (bbox.crs.authId === CRS_EPSG3857.authId) {
return bbox;
Expand Down

0 comments on commit 2ece839

Please sign in to comment.