Skip to content

Commit 1332d18

Browse files
author
Jan Kumer
committed
Fix circular dependencies
1 parent d5cccee commit 1332d18

9 files changed

+22
-18
lines changed

src/layer/AbstractLayer.ts

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ interface ConstructorParameters {
3131
}
3232

3333
export class AbstractLayer {
34+
public type = 'AbstractLayer';
3435
public title: string | null = null;
3536
public description: string | null = null;
3637
public readonly dataset: Dataset | null = null;

src/layer/AbstractSentinelHubV1OrV2Layer.ts

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ interface ConstructorParameters {
3838

3939
// this class provides any SHv1- or SHv2-specific (EO Cloud) functionality to the subclasses:
4040
export class AbstractSentinelHubV1OrV2Layer extends AbstractLayer {
41+
public readonly type = 'AbstractSentinelHubV1OrV2Layer';
4142
protected instanceId: string;
4243
protected layerId: string;
4344
protected evalscript: string | null;

src/layer/AbstractSentinelHubV3Layer.ts

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export class AbstractSentinelHubV3Layer extends AbstractLayer {
5252
protected evalscript: string | null;
5353
protected evalscriptUrl: string | null;
5454
protected dataProduct: DataProductId | null;
55+
public readonly type: 'AbstractSentinelHubV3Layer';
5556
public legend?: any[] | null;
5657
public mosaickingOrder: MosaickingOrder | null; // public because ProcessingDataFusionLayer needs to read it directly
5758
public upsampling: Interpolator | null;

src/layer/WmsLayer.ts

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ interface ConstructorParameters {
1717
}
1818

1919
export class WmsLayer extends AbstractLayer {
20+
public readonly type = 'WmsLayer';
2021
// The URL of the WMS service, for example: "https://services.sentinel-hub.com/ogc/wms/<instance-id>/"
2122
protected baseUrl: string;
2223
protected layerId: string;

src/layer/WmtsLayer.ts

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ interface ConstructorParameters {
2727
}
2828

2929
export class WmtsLayer extends AbstractLayer {
30+
public readonly type = 'WmtsLayer';
3031
protected baseUrl: string;
3132
protected layerId: string;
3233
protected resourceUrl: string;

src/layer/const.ts

+4
Original file line numberDiff line numberDiff line change
@@ -282,3 +282,7 @@ export const PLANET_FALSE_COLOR_TEMPLATES = [
282282
{ description: '', titleSuffix: 'TGI', resourceUrlParams: { proc: 'tgi' } },
283283
{ description: '', titleSuffix: 'CIR', resourceUrlParams: { proc: 'cir' } },
284284
];
285+
286+
export const EQUATOR_RADIUS = 6378137.0;
287+
export const DEGREE_TO_RADIAN = Math.PI / 180;
288+
export const RADIAN_TO_DEGREE = 180 / Math.PI;

src/layer/utils.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import axios, { AxiosRequestConfig } from 'axios';
22
import { stringify, parseUrl, stringifyUrl } from 'query-string';
33
import { parseStringPromise } from 'xml2js';
4-
5-
import { OgcServiceTypes, SH_SERVICE_HOSTNAMES_V3, SH_SERVICE_ROOT_URL } from './const';
4+
import { EQUATOR_RADIUS, OgcServiceTypes, SH_SERVICE_HOSTNAMES_V3, SH_SERVICE_ROOT_URL } from './const';
65
import { getAxiosReqParams, RequestConfiguration } from '../utils/cancelRequests';
76
import { CACHE_CONFIG_30MIN, CACHE_CONFIG_30MIN_MEMORY } from '../utils/cacheHandlers';
8-
import { EQUATOR_RADIUS, GetCapabilitiesWmtsXml } from './wmts.utils';
7+
import type { GetCapabilitiesWmtsXml } from './wmts.utils';
98
import { getAuthToken } from '../auth';
109
import { BBox } from '../bbox';
1110
import { CRS_EPSG3857 } from '../crs';

src/layer/wmts.utils.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
import { RequestConfiguration } from '..';
22
import { BBox } from '../bbox';
33
import { CRS_EPSG3857, CRS_EPSG4326 } from '../crs';
4-
import { OgcServiceTypes } from './const';
4+
import { DEGREE_TO_RADIAN, EQUATOR_RADIUS, OgcServiceTypes, RADIAN_TO_DEGREE } from './const';
55
import { fetchGetCapabilitiesXml, GetCapabilitiesXmlLayer } from './utils';
66

7-
const DEGREE_TO_RADIAN = Math.PI / 180;
8-
const RADIAN_TO_DEGREE = 180 / Math.PI;
9-
export const EQUATOR_RADIUS = 6378137.0;
10-
117
export type GetCapabilitiesWmtsXml = {
128
Capabilities: {
139
'ows:ServiceIdentification': any[][];

src/statistics/Fis.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import moment from 'moment';
33
import WKT from 'terraformer-wkt-parser';
44
import { RequestConfiguration } from '../utils/cancelRequests';
55
import { CRS_EPSG4326, CRS_WGS84, findCrsFromUrn } from '../crs';
6-
import { AbstractLayer } from '../layer/AbstractLayer';
7-
import { AbstractSentinelHubV1OrV2Layer } from '../layer/AbstractSentinelHubV1OrV2Layer';
8-
import { AbstractSentinelHubV3Layer } from '../layer/AbstractSentinelHubV3Layer';
6+
import type { AbstractLayer } from '../layer/AbstractLayer';
7+
import type { AbstractSentinelHubV1OrV2Layer } from '../layer/AbstractSentinelHubV1OrV2Layer';
8+
import type { AbstractSentinelHubV3Layer } from '../layer/AbstractSentinelHubV3Layer';
99
import { FisPayload, FisResponse, GetStatsParams, HistogramType } from '../layer/const';
1010
import { CACHE_CONFIG_NOCACHE } from '../utils/cacheHandlers';
1111
import { getAxiosReqParams } from '../utils/cancelRequests';
12-
import { StatisticsProvider } from './StatisticsProvider';
12+
import type { StatisticsProvider } from './StatisticsProvider';
1313
import { StatisticalApiResponse } from './const';
1414

1515
export class Fis implements StatisticsProvider {
@@ -63,8 +63,8 @@ export class Fis implements StatisticsProvider {
6363
} else {
6464
payload.evalscript = Buffer.from(layer.getEvalscript(), 'utf8').toString('base64');
6565
}
66-
if (layer instanceof AbstractSentinelHubV1OrV2Layer) {
67-
payload.evalsource = layer.getEvalsource();
66+
if (layer.type === 'AbstractSentinelHubV1OrV2Layer') {
67+
payload.evalsource = (layer as AbstractSentinelHubV1OrV2Layer).getEvalsource();
6868
}
6969
}
7070
return payload;
@@ -86,10 +86,10 @@ export class Fis implements StatisticsProvider {
8686
params: GetStatsParams,
8787
reqConfig?: RequestConfiguration,
8888
): Promise<FisResponse> {
89-
if (layer instanceof AbstractSentinelHubV3Layer) {
90-
return this.handleV3(layer, params, reqConfig);
91-
} else if (layer instanceof AbstractSentinelHubV1OrV2Layer) {
92-
return this.handleV1orV2(layer, params, reqConfig);
89+
if (layer.type === 'AbstractSentinelHubV3Layer') {
90+
return this.handleV3(layer as AbstractSentinelHubV3Layer, params, reqConfig);
91+
} else if (layer.type === 'AbstractSentinelHubV1OrV2Layer') {
92+
return this.handleV1orV2(layer as AbstractSentinelHubV1OrV2Layer, params, reqConfig);
9393
} else {
9494
throw new Error('Not supported');
9595
}

0 commit comments

Comments
 (0)