Skip to content

Commit

Permalink
get highlights from SH configuration service
Browse files Browse the repository at this point in the history
  • Loading branch information
zcernigoj committed Dec 10, 2024
1 parent 4f885c7 commit 798c61c
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 19 deletions.
1 change: 1 addition & 0 deletions src/layer/AbstractDEMLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface ConstructorParameters {
demInstance?: DEMInstanceType | null;
egm?: boolean | null;
clampNegative?: boolean | null;
highlights?: AbstractSentinelHubV3Layer['highlights'];
}

export class AbstractDEMLayer extends AbstractSentinelHubV3Layer {
Expand Down
13 changes: 9 additions & 4 deletions src/layer/AbstractSentinelHubV3Layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
PaginatedTiles,
Stats,
SUPPORTED_DATA_PRODUCTS_PROCESSING,
Highlight,
} from './const';
import { createProcessingPayload, processingGetMap, ProcessingPayload } from './processing';
import { wmsGetMapUrl } from './wms';
Expand All @@ -46,6 +47,7 @@ interface ConstructorParameters {
upsampling?: Interpolator | null;
downsampling?: Interpolator | null;
legendUrl?: string | null;
highlights?: Highlight[] | null;
}

// this class provides any SHv3-specific functionality to the subclasses:
Expand All @@ -59,6 +61,7 @@ export class AbstractSentinelHubV3Layer extends AbstractLayer {
public mosaickingOrder: MosaickingOrder | null; // public because ProcessingDataFusionLayer needs to read it directly
public upsampling: Interpolator | null;
public downsampling: Interpolator | null;
public highlights?: Highlight[] | null;

public constructor({
instanceId = null,
Expand All @@ -72,6 +75,7 @@ export class AbstractSentinelHubV3Layer extends AbstractLayer {
upsampling = null,
downsampling = null,
legendUrl = null,
highlights = null,
}: ConstructorParameters) {
super({ title, description, legendUrl });
if (
Expand All @@ -92,6 +96,7 @@ export class AbstractSentinelHubV3Layer extends AbstractLayer {
this.mosaickingOrder = mosaickingOrder;
this.upsampling = upsampling;
this.downsampling = downsampling;
this.highlights = highlights;
}

public getLayerId(): string {
Expand All @@ -117,11 +122,11 @@ export class AbstractSentinelHubV3Layer extends AbstractLayer {
if (!this.dataset) {
throw new Error('This layer does not support Processing API (unknown dataset)');
}
const layersParams = await fetchLayerParamsFromConfigurationService(
this.getSHServiceRootUrl(),
this.instanceId,
const layersParams = await fetchLayerParamsFromConfigurationService({
shServiceHostName: this.getSHServiceRootUrl(),
instanceId: this.instanceId,
reqConfig,
);
});

const layerParams = layersParams.find((l: any) => l.layerId === this.layerId);
if (!layerParams) {
Expand Down
4 changes: 3 additions & 1 deletion src/layer/BYOCLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ interface ConstructorParameters {
locationId?: LocationIdSHv3 | null;
subType?: BYOCSubTypes | null;
shServiceRootUrl?: string;
highlights?: AbstractSentinelHubV3Layer['highlights'];
}

type BYOCFindTilesDatasetParameters = {
Expand Down Expand Up @@ -68,8 +69,9 @@ export class BYOCLayer extends AbstractSentinelHubV3Layer {
locationId = null,
subType = null,
shServiceRootUrl = SH_SERVICE_ROOT_URL.default,
highlights = null,
}: ConstructorParameters) {
super({ instanceId, layerId, evalscript, evalscriptUrl, dataProduct, title, description });
super({ instanceId, layerId, evalscript, evalscriptUrl, dataProduct, title, description, highlights });
this.collectionId = collectionId;
this.locationId = locationId;
this.subType = subType;
Expand Down
1 change: 1 addition & 0 deletions src/layer/HLSAWSLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface ConstructorParameters {
legendUrl?: string | null;
maxCloudCoverPercent?: number | null;
constellation?: HLSConstellation | null;
highlights?: AbstractSentinelHubV3WithCCLayer['highlights'];
}

type HLSFindTilesDatasetParameters = {
Expand Down
14 changes: 10 additions & 4 deletions src/layer/LayersFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ export class LayersFactory {
overrideConstructorParams?: Record<string, any> | null,
reqConfig?: RequestConfiguration,
preferGetCapabilities: boolean = true,
includeHighlights: boolean = false,
): Promise<AbstractLayer[]> {
const returnValue = await ensureTimeout(async (innerReqConfig) => {
for (let hostname of SH_SERVICE_HOSTNAMES_V3) {
Expand All @@ -201,6 +202,7 @@ export class LayersFactory {
overrideConstructorParams,
innerReqConfig,
preferGetCapabilities,
includeHighlights,
);
}
}
Expand Down Expand Up @@ -228,12 +230,14 @@ export class LayersFactory {
overrideConstructorParams: Record<string, any> | null,
reqConfig: RequestConfiguration,
preferGetCapabilities: boolean = true,
includeHighlights: boolean = false,
): Promise<AbstractLayer[]> {
const filteredLayersInfos = await this.getSHv3LayersInfo(
baseUrl,
reqConfig,
filterLayers,
preferGetCapabilities,
includeHighlights,
);

return filteredLayersInfos.map(
Expand Down Expand Up @@ -271,6 +275,7 @@ export class LayersFactory {
reqConfig: RequestConfiguration,
filterLayers: Function,
preferGetCapabilities: boolean = true,
includeHighlights: boolean = false,
): Promise<any[]> {
let layersInfos;
//also check if auth token is present
Expand All @@ -279,11 +284,12 @@ export class LayersFactory {
// use configuration if possible
if (authToken && preferGetCapabilities === false) {
try {
const layers = await fetchLayerParamsFromConfigurationService(
getSHServiceRootUrlFromBaseUrl(baseUrl),
parseSHInstanceId(baseUrl),
const layers = await fetchLayerParamsFromConfigurationService({
shServiceHostName: getSHServiceRootUrlFromBaseUrl(baseUrl),
instanceId: parseSHInstanceId(baseUrl),
includeHighlights,
reqConfig,
);
});
layersInfos = layers.map((l: any) => ({
...l,
dataset: LayersFactory.matchDatasetFromGetCapabilities(l.type, baseUrl),
Expand Down
4 changes: 3 additions & 1 deletion src/layer/ProcessingDataFusionLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ interface ConstructorParameters {
layers: DataFusionLayerInfo[];
title?: string | null;
description?: string | null;
highlights?: AbstractSentinelHubV3Layer['highlights'];
}

export type DataFusionLayerInfo = {
Expand All @@ -54,8 +55,9 @@ export class ProcessingDataFusionLayer extends AbstractSentinelHubV3Layer {
evalscript = null,
evalscriptUrl = null,
layers,
highlights = null,
}: ConstructorParameters) {
super({ title, description, evalscript, evalscriptUrl });
super({ title, description, evalscript, evalscriptUrl, highlights });
this.layers = layers;
}

Expand Down
14 changes: 13 additions & 1 deletion src/layer/S1GRDAWSEULayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ interface ConstructorParameters {
backscatterCoeff?: BackscatterCoeff | null;
orbitDirection?: OrbitDirection | null;
speckleFilter?: SpeckleFilter | null;
highlights?: AbstractSentinelHubV3Layer['highlights'];
}

type S1GRDFindTilesDatasetParameters = {
Expand Down Expand Up @@ -112,8 +113,19 @@ export class S1GRDAWSEULayer extends AbstractSentinelHubV3Layer {
orbitDirection = null,
speckleFilter = null,
mosaickingOrder = null,
highlights = null,
}: ConstructorParameters) {
super({ instanceId, layerId, evalscript, evalscriptUrl, dataProduct, title, description, legendUrl });
super({
instanceId,
layerId,
evalscript,
evalscriptUrl,
dataProduct,
title,
description,
legendUrl,
highlights,
});
this.acquisitionMode = acquisitionMode;
this.polarization = polarization;
this.resolution = resolution;
Expand Down
1 change: 1 addition & 0 deletions src/layer/S3SLSTRLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ interface ConstructorParameters {
legendUrl?: string | null;
maxCloudCoverPercent?: number | null;
view?: S3SLSTRView | null;
highlights?: AbstractSentinelHubV3WithCCLayer['highlights'];
}

export enum S3SLSTRView {
Expand Down
14 changes: 13 additions & 1 deletion src/layer/S5PL2Layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ interface ConstructorParameters {
productType?: ProductType | null;
maxCloudCoverPercent?: number | null;
minQa?: number | null;
highlights?: AbstractSentinelHubV3Layer['highlights'];
}

type S5PL2FindTilesDatasetParameters = {
Expand All @@ -63,8 +64,19 @@ export class S5PL2Layer extends AbstractSentinelHubV3Layer {
productType = null,
maxCloudCoverPercent = 100,
minQa = null,
highlights = null,
}: ConstructorParameters) {
super({ instanceId, layerId, evalscript, evalscriptUrl, dataProduct, title, description, legendUrl });
super({
instanceId,
layerId,
evalscript,
evalscriptUrl,
dataProduct,
title,
description,
legendUrl,
highlights,
});
this.productType = productType;
this.maxCloudCoverPercent = maxCloudCoverPercent;
this.minQa = minQa;
Expand Down
1 change: 1 addition & 0 deletions src/layer/__tests__/fixtures.BYOCLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ export function constructFixtureUpdateLayerFromServiceIfNeeded({
legend: undefined as any,
title: 'byoc3',
description: '',
highlights: undefined as any,
};

return {
Expand Down
12 changes: 12 additions & 0 deletions src/layer/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,15 @@ export const XmlParserOptions = Object.freeze({
return isA;
},
});

export interface Highlight {
id: string;
layerId: string;
instanceId: string;
title: string;
description: string;
areaOfInterest: object;
fromTime: string;
toTime: string;
orderHint: string;
}
26 changes: 19 additions & 7 deletions src/layer/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
SH_SERVICE_HOSTNAMES_V3,
SH_SERVICE_ROOT_URL,
XmlParserOptions,
Highlight,
} from './const';
import { GetCapabilitiesWmtsXml } from './wmts.utils';

Expand Down Expand Up @@ -188,17 +189,27 @@ export function getSHServiceRootUrlFromBaseUrl(baseUrl: string): string {
return getSHServiceRootUrl(host);
}

export async function fetchLayerParamsFromConfigurationService(
shServiceHostName: string,
instanceId: string,
reqConfig: RequestConfiguration,
): Promise<any[]> {
export async function fetchLayerParamsFromConfigurationService({
shServiceHostName,
instanceId,
includeHighlights,
reqConfig,
}: {
shServiceHostName: string;
instanceId: string;
includeHighlights?: boolean;
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 configurationServiceHostName = shServiceHostName ?? SH_SERVICE_ROOT_URL.default;
const url = `${configurationServiceHostName}api/v2/configuration/instances/${instanceId}/layers`;
const url = new URL(`${configurationServiceHostName}api/v2/configuration/instances/${instanceId}/layers`);
if (includeHighlights) {
url.searchParams.set('listHighlights', 'true');
}

const headers = {
Authorization: `Bearer ${authToken}`,
};
Expand All @@ -218,7 +229,7 @@ export async function fetchLayerParamsFromConfigurationService(
headers: headers,
...getAxiosReqParams(reqConfigWithMemoryCache, null),
};
const res = await axios.get(url, requestConfig);
const res = await axios.get(url.toString(), requestConfig);
const layersParams = res.data.map((l: any) => {
const defaultStyle = l.styles.find((s: any) => s.name === l.defaultStyleName) ?? l.styles[0];

Expand All @@ -236,6 +247,7 @@ export async function fetchLayerParamsFromConfigurationService(
? `${configurationServiceHostName}api/v2/configuration/datasets/${l.collectionType}/dataproducts/${defaultStyle.dataProductId}`
: undefined,
legend: defaultStyle ? defaultStyle.legend : null,
highlights: l.highlights?.member.map((h: Highlight) => ({ ...h, datasetId: l.collectionType })),
};
});
return layersParams;
Expand Down

0 comments on commit 798c61c

Please sign in to comment.