Skip to content

Commit 7007ca2

Browse files
authored
Merge pull request #290 from sentinel-hub/feature/layers-highlights
get highlights from SH configuration service
2 parents d24188c + 817765a commit 7007ca2

12 files changed

+85
-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
@@ -215,6 +215,7 @@ export class LayersFactory {
215215
overrideConstructorParams?: Record<string, any> | null,
216216
reqConfig?: RequestConfiguration,
217217
preferGetCapabilities: boolean = true,
218+
includeHighlights: boolean = false,
218219
): Promise<AbstractLayer[]> {
219220
const returnValue = await ensureTimeout(async (innerReqConfig) => {
220221
for (let hostname of SH_SERVICE_HOSTNAMES_V3) {
@@ -225,6 +226,7 @@ export class LayersFactory {
225226
overrideConstructorParams,
226227
innerReqConfig,
227228
preferGetCapabilities,
229+
includeHighlights,
228230
);
229231
}
230232
}
@@ -252,12 +254,14 @@ export class LayersFactory {
252254
overrideConstructorParams: Record<string, any> | null,
253255
reqConfig: RequestConfiguration,
254256
preferGetCapabilities: boolean = true,
257+
includeHighlights: boolean = false,
255258
): Promise<AbstractLayer[]> {
256259
const filteredLayersInfos = await this.getSHv3LayersInfo(
257260
baseUrl,
258261
reqConfig,
259262
filterLayers,
260263
preferGetCapabilities,
264+
includeHighlights,
261265
);
262266

263267
return filteredLayersInfos.map(
@@ -295,6 +299,7 @@ export class LayersFactory {
295299
reqConfig: RequestConfiguration,
296300
filterLayers: Function,
297301
preferGetCapabilities: boolean = true,
302+
includeHighlights: boolean = false,
298303
): Promise<any[]> {
299304
let layersInfos;
300305
//also check if auth token is present
@@ -303,11 +308,12 @@ export class LayersFactory {
303308
// use configuration if possible
304309
if (authToken && preferGetCapabilities === false) {
305310
try {
306-
const layers = await fetchLayerParamsFromConfigurationService(
307-
getSHServiceRootUrlFromBaseUrl(baseUrl),
308-
parseSHInstanceId(baseUrl),
311+
const layers = await fetchLayerParamsFromConfigurationService({
312+
shServiceHostName: getSHServiceRootUrlFromBaseUrl(baseUrl),
313+
instanceId: parseSHInstanceId(baseUrl),
314+
includeHighlights,
309315
reqConfig,
310-
);
316+
});
311317
layersInfos = layers.map((l: any) => ({
312318
...l,
313319
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
@@ -301,3 +301,15 @@ export const XmlParserOptions = Object.freeze({
301301
return isA;
302302
},
303303
});
304+
305+
export interface Highlight {
306+
id: string;
307+
layerId: string;
308+
instanceId: string;
309+
title: string;
310+
description: string;
311+
areaOfInterest: object;
312+
fromTime: string;
313+
toTime: string;
314+
orderHint: string;
315+
}

src/layer/utils.ts

+18-7
Original file line numberDiff line numberDiff line change
@@ -188,17 +188,27 @@ export function getSHServiceRootUrlFromBaseUrl(baseUrl: string): string {
188188
return getSHServiceRootUrl(host);
189189
}
190190

191-
export async function fetchLayerParamsFromConfigurationService(
192-
shServiceHostName: string,
193-
instanceId: string,
194-
reqConfig: RequestConfiguration,
195-
): Promise<any[]> {
191+
export async function fetchLayerParamsFromConfigurationService({
192+
shServiceHostName,
193+
instanceId,
194+
includeHighlights,
195+
reqConfig,
196+
}: {
197+
shServiceHostName: string;
198+
instanceId: string;
199+
includeHighlights?: boolean;
200+
reqConfig: RequestConfiguration;
201+
}): Promise<any[]> {
196202
const authToken = reqConfig && reqConfig.authToken ? reqConfig.authToken : getAuthToken();
197203
if (!authToken) {
198204
throw new Error('Must be authenticated to fetch layer params');
199205
}
200206
const configurationServiceHostName = shServiceHostName ?? SH_SERVICE_ROOT_URL.default;
201-
const url = `${configurationServiceHostName}api/v2/configuration/instances/${instanceId}/layers`;
207+
const url = new URL(`${configurationServiceHostName}api/v2/configuration/instances/${instanceId}/layers`);
208+
if (includeHighlights) {
209+
url.searchParams.set('listHighlights', 'true');
210+
}
211+
202212
const headers = {
203213
Authorization: `Bearer ${authToken}`,
204214
};
@@ -218,7 +228,7 @@ export async function fetchLayerParamsFromConfigurationService(
218228
headers: headers,
219229
...getAxiosReqParams(reqConfigWithMemoryCache, null),
220230
};
221-
const res = await axios.get(url, requestConfig);
231+
const res = await axios.get(url.toString(), requestConfig);
222232
const layersParams = res.data.map((l: any) => {
223233
const defaultStyle = l.styles.find((s: any) => s.name === l.defaultStyleName) ?? l.styles[0];
224234

@@ -236,6 +246,7 @@ export async function fetchLayerParamsFromConfigurationService(
236246
? `${configurationServiceHostName}api/v2/configuration/datasets/${l.collectionType}/dataproducts/${defaultStyle.dataProductId}`
237247
: undefined,
238248
legend: defaultStyle ? defaultStyle.legend : null,
249+
highlights: l.highlights?.member,
239250
};
240251
});
241252
return layersParams;

0 commit comments

Comments
 (0)