Skip to content

Commit

Permalink
Change AbstractSentinelHubV3Layer to receive evalscript value from da…
Browse files Browse the repository at this point in the history
…taProduct endpoint
  • Loading branch information
Jan Kumer committed Sep 4, 2024
1 parent 37eb8e9 commit 1046ccd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
16 changes: 11 additions & 5 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 @@ -668,8 +668,16 @@ export class AbstractSentinelHubV3Layer extends AbstractLayer {
this.legend = layerParams['legend'] ? layerParams['legend'] : null;

if (!this.evalscript) {
this.evalscript = layerParams['evalscript'] ? layerParams['evalscript'] : null;
const dataProductUrl = layerParams['dataProduct'];
this.evalscript = layerParams['evalscript'];
if (!this.evalscript && dataProductUrl) {
const response = await fetchDataProduct(dataProductUrl, innerReqConfig);
this.evalscript = response.data?.evalScript;
// now that evalscript here, dataProduct=null will make rest of logic use ApiType.PROCESSING
this.dataProduct = null;
}
}

if (!this.mosaickingOrder && layerParams.mosaickingOrder) {
this.mosaickingOrder = layerParams.mosaickingOrder;
}
Expand All @@ -679,8 +687,6 @@ 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 1046ccd

Please sign in to comment.