Skip to content

Commit 798c61c

Browse files
committed
get highlights from SH configuration service
1 parent 4f885c7 commit 798c61c

12 files changed

+86
-19
lines changed

src/layer/AbstractDEMLayer.ts

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export interface ConstructorParameters {
2121
demInstance?: DEMInstanceType | null;
2222
egm?: boolean | null;
2323
clampNegative?: boolean | null;
24+
highlights?: AbstractSentinelHubV3Layer['highlights'];
2425
}
2526

2627
export class AbstractDEMLayer extends AbstractSentinelHubV3Layer {

src/layer/AbstractSentinelHubV3Layer.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
PaginatedTiles,
2323
Stats,
2424
SUPPORTED_DATA_PRODUCTS_PROCESSING,
25+
Highlight,
2526
} from './const';
2627
import { createProcessingPayload, processingGetMap, ProcessingPayload } from './processing';
2728
import { wmsGetMapUrl } from './wms';
@@ -46,6 +47,7 @@ interface ConstructorParameters {
4647
upsampling?: Interpolator | null;
4748
downsampling?: Interpolator | null;
4849
legendUrl?: string | null;
50+
highlights?: Highlight[] | null;
4951
}
5052

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

6366
public constructor({
6467
instanceId = null,
@@ -72,6 +75,7 @@ export class AbstractSentinelHubV3Layer extends AbstractLayer {
7275
upsampling = null,
7376
downsampling = null,
7477
legendUrl = null,
78+
highlights = null,
7579
}: ConstructorParameters) {
7680
super({ title, description, legendUrl });
7781
if (
@@ -92,6 +96,7 @@ export class AbstractSentinelHubV3Layer extends AbstractLayer {
9296
this.mosaickingOrder = mosaickingOrder;
9397
this.upsampling = upsampling;
9498
this.downsampling = downsampling;
99+
this.highlights = highlights;
95100
}
96101

97102
public getLayerId(): string {
@@ -117,11 +122,11 @@ export class AbstractSentinelHubV3Layer extends AbstractLayer {
117122
if (!this.dataset) {
118123
throw new Error('This layer does not support Processing API (unknown dataset)');
119124
}
120-
const layersParams = await fetchLayerParamsFromConfigurationService(
121-
this.getSHServiceRootUrl(),
122-
this.instanceId,
125+
const layersParams = await fetchLayerParamsFromConfigurationService({
126+
shServiceHostName: this.getSHServiceRootUrl(),
127+
instanceId: this.instanceId,
123128
reqConfig,
124-
);
129+
});
125130

126131
const layerParams = layersParams.find((l: any) => l.layerId === this.layerId);
127132
if (!layerParams) {

src/layer/BYOCLayer.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ interface ConstructorParameters {
4040
locationId?: LocationIdSHv3 | null;
4141
subType?: BYOCSubTypes | null;
4242
shServiceRootUrl?: string;
43+
highlights?: AbstractSentinelHubV3Layer['highlights'];
4344
}
4445

4546
type BYOCFindTilesDatasetParameters = {
@@ -68,8 +69,9 @@ export class BYOCLayer extends AbstractSentinelHubV3Layer {
6869
locationId = null,
6970
subType = null,
7071
shServiceRootUrl = SH_SERVICE_ROOT_URL.default,
72+
highlights = null,
7173
}: ConstructorParameters) {
72-
super({ instanceId, layerId, evalscript, evalscriptUrl, dataProduct, title, description });
74+
super({ instanceId, layerId, evalscript, evalscriptUrl, dataProduct, title, description, highlights });
7375
this.collectionId = collectionId;
7476
this.locationId = locationId;
7577
this.subType = subType;

src/layer/HLSAWSLayer.ts

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ interface ConstructorParameters {
1616
legendUrl?: string | null;
1717
maxCloudCoverPercent?: number | null;
1818
constellation?: HLSConstellation | null;
19+
highlights?: AbstractSentinelHubV3WithCCLayer['highlights'];
1920
}
2021

2122
type HLSFindTilesDatasetParameters = {

src/layer/LayersFactory.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ export class LayersFactory {
191191
overrideConstructorParams?: Record<string, any> | null,
192192
reqConfig?: RequestConfiguration,
193193
preferGetCapabilities: boolean = true,
194+
includeHighlights: boolean = false,
194195
): Promise<AbstractLayer[]> {
195196
const returnValue = await ensureTimeout(async (innerReqConfig) => {
196197
for (let hostname of SH_SERVICE_HOSTNAMES_V3) {
@@ -201,6 +202,7 @@ export class LayersFactory {
201202
overrideConstructorParams,
202203
innerReqConfig,
203204
preferGetCapabilities,
205+
includeHighlights,
204206
);
205207
}
206208
}
@@ -228,12 +230,14 @@ export class LayersFactory {
228230
overrideConstructorParams: Record<string, any> | null,
229231
reqConfig: RequestConfiguration,
230232
preferGetCapabilities: boolean = true,
233+
includeHighlights: boolean = false,
231234
): Promise<AbstractLayer[]> {
232235
const filteredLayersInfos = await this.getSHv3LayersInfo(
233236
baseUrl,
234237
reqConfig,
235238
filterLayers,
236239
preferGetCapabilities,
240+
includeHighlights,
237241
);
238242

239243
return filteredLayersInfos.map(
@@ -271,6 +275,7 @@ export class LayersFactory {
271275
reqConfig: RequestConfiguration,
272276
filterLayers: Function,
273277
preferGetCapabilities: boolean = true,
278+
includeHighlights: boolean = false,
274279
): Promise<any[]> {
275280
let layersInfos;
276281
//also check if auth token is present
@@ -279,11 +284,12 @@ export class LayersFactory {
279284
// use configuration if possible
280285
if (authToken && preferGetCapabilities === false) {
281286
try {
282-
const layers = await fetchLayerParamsFromConfigurationService(
283-
getSHServiceRootUrlFromBaseUrl(baseUrl),
284-
parseSHInstanceId(baseUrl),
287+
const layers = await fetchLayerParamsFromConfigurationService({
288+
shServiceHostName: getSHServiceRootUrlFromBaseUrl(baseUrl),
289+
instanceId: parseSHInstanceId(baseUrl),
290+
includeHighlights,
285291
reqConfig,
286-
);
292+
});
287293
layersInfos = layers.map((l: any) => ({
288294
...l,
289295
dataset: LayersFactory.matchDatasetFromGetCapabilities(l.type, baseUrl),

src/layer/ProcessingDataFusionLayer.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ interface ConstructorParameters {
3232
layers: DataFusionLayerInfo[];
3333
title?: string | null;
3434
description?: string | null;
35+
highlights?: AbstractSentinelHubV3Layer['highlights'];
3536
}
3637

3738
export type DataFusionLayerInfo = {
@@ -54,8 +55,9 @@ export class ProcessingDataFusionLayer extends AbstractSentinelHubV3Layer {
5455
evalscript = null,
5556
evalscriptUrl = null,
5657
layers,
58+
highlights = null,
5759
}: ConstructorParameters) {
58-
super({ title, description, evalscript, evalscriptUrl });
60+
super({ title, description, evalscript, evalscriptUrl, highlights });
5961
this.layers = layers;
6062
}
6163

src/layer/S1GRDAWSEULayer.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ interface ConstructorParameters {
7171
backscatterCoeff?: BackscatterCoeff | null;
7272
orbitDirection?: OrbitDirection | null;
7373
speckleFilter?: SpeckleFilter | null;
74+
highlights?: AbstractSentinelHubV3Layer['highlights'];
7475
}
7576

7677
type S1GRDFindTilesDatasetParameters = {
@@ -112,8 +113,19 @@ export class S1GRDAWSEULayer extends AbstractSentinelHubV3Layer {
112113
orbitDirection = null,
113114
speckleFilter = null,
114115
mosaickingOrder = null,
116+
highlights = null,
115117
}: ConstructorParameters) {
116-
super({ instanceId, layerId, evalscript, evalscriptUrl, dataProduct, title, description, legendUrl });
118+
super({
119+
instanceId,
120+
layerId,
121+
evalscript,
122+
evalscriptUrl,
123+
dataProduct,
124+
title,
125+
description,
126+
legendUrl,
127+
highlights,
128+
});
117129
this.acquisitionMode = acquisitionMode;
118130
this.polarization = polarization;
119131
this.resolution = resolution;

src/layer/S3SLSTRLayer.ts

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ interface ConstructorParameters {
2424
legendUrl?: string | null;
2525
maxCloudCoverPercent?: number | null;
2626
view?: S3SLSTRView | null;
27+
highlights?: AbstractSentinelHubV3WithCCLayer['highlights'];
2728
}
2829

2930
export enum S3SLSTRView {

src/layer/S5PL2Layer.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ interface ConstructorParameters {
3737
productType?: ProductType | null;
3838
maxCloudCoverPercent?: number | null;
3939
minQa?: number | null;
40+
highlights?: AbstractSentinelHubV3Layer['highlights'];
4041
}
4142

4243
type S5PL2FindTilesDatasetParameters = {
@@ -63,8 +64,19 @@ export class S5PL2Layer extends AbstractSentinelHubV3Layer {
6364
productType = null,
6465
maxCloudCoverPercent = 100,
6566
minQa = null,
67+
highlights = null,
6668
}: ConstructorParameters) {
67-
super({ instanceId, layerId, evalscript, evalscriptUrl, dataProduct, title, description, legendUrl });
69+
super({
70+
instanceId,
71+
layerId,
72+
evalscript,
73+
evalscriptUrl,
74+
dataProduct,
75+
title,
76+
description,
77+
legendUrl,
78+
highlights,
79+
});
6880
this.productType = productType;
6981
this.maxCloudCoverPercent = maxCloudCoverPercent;
7082
this.minQa = minQa;

src/layer/__tests__/fixtures.BYOCLayer.ts

+1
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ export function constructFixtureUpdateLayerFromServiceIfNeeded({
395395
legend: undefined as any,
396396
title: 'byoc3',
397397
description: '',
398+
highlights: undefined as any,
398399
};
399400

400401
return {

src/layer/const.ts

+12
Original file line numberDiff line numberDiff line change
@@ -297,3 +297,15 @@ export const XmlParserOptions = Object.freeze({
297297
return isA;
298298
},
299299
});
300+
301+
export interface Highlight {
302+
id: string;
303+
layerId: string;
304+
instanceId: string;
305+
title: string;
306+
description: string;
307+
areaOfInterest: object;
308+
fromTime: string;
309+
toTime: string;
310+
orderHint: string;
311+
}

src/layer/utils.ts

+19-7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
SH_SERVICE_HOSTNAMES_V3,
1515
SH_SERVICE_ROOT_URL,
1616
XmlParserOptions,
17+
Highlight,
1718
} from './const';
1819
import { GetCapabilitiesWmtsXml } from './wmts.utils';
1920

@@ -188,17 +189,27 @@ export function getSHServiceRootUrlFromBaseUrl(baseUrl: string): string {
188189
return getSHServiceRootUrl(host);
189190
}
190191

191-
export async function fetchLayerParamsFromConfigurationService(
192-
shServiceHostName: string,
193-
instanceId: string,
194-
reqConfig: RequestConfiguration,
195-
): Promise<any[]> {
192+
export async function fetchLayerParamsFromConfigurationService({
193+
shServiceHostName,
194+
instanceId,
195+
includeHighlights,
196+
reqConfig,
197+
}: {
198+
shServiceHostName: string;
199+
instanceId: string;
200+
includeHighlights?: boolean;
201+
reqConfig: RequestConfiguration;
202+
}): Promise<any[]> {
196203
const authToken = reqConfig && reqConfig.authToken ? reqConfig.authToken : getAuthToken();
197204
if (!authToken) {
198205
throw new Error('Must be authenticated to fetch layer params');
199206
}
200207
const configurationServiceHostName = shServiceHostName ?? SH_SERVICE_ROOT_URL.default;
201-
const url = `${configurationServiceHostName}api/v2/configuration/instances/${instanceId}/layers`;
208+
const url = new URL(`${configurationServiceHostName}api/v2/configuration/instances/${instanceId}/layers`);
209+
if (includeHighlights) {
210+
url.searchParams.set('listHighlights', 'true');
211+
}
212+
202213
const headers = {
203214
Authorization: `Bearer ${authToken}`,
204215
};
@@ -218,7 +229,7 @@ export async function fetchLayerParamsFromConfigurationService(
218229
headers: headers,
219230
...getAxiosReqParams(reqConfigWithMemoryCache, null),
220231
};
221-
const res = await axios.get(url, requestConfig);
232+
const res = await axios.get(url.toString(), requestConfig);
222233
const layersParams = res.data.map((l: any) => {
223234
const defaultStyle = l.styles.find((s: any) => s.name === l.defaultStyleName) ?? l.styles[0];
224235

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

0 commit comments

Comments
 (0)