@elastic/ems-client 7.15.1 → 7.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.backportrc.json +13 -2
- package/.buildkite/build.sh +16 -0
- package/.buildkite/pipeline.yml +8 -0
- package/.buildkite/pull-requests.json +30 -0
- package/.nvmrc +1 -0
- package/CHANGELOG.md +16 -0
- package/catalog-info.yaml +68 -0
- package/package.json +8 -5
- package/src/ems_client.ts +14 -12
- package/src/file_layer.ts +0 -1
- package/target/node/ems_client.js +33 -100
- package/target/node/ems_service.js +11 -23
- package/target/node/file_layer.js +18 -64
- package/target/node/index.js +6 -10
- package/target/node/origin.js +3 -4
- package/target/node/tms_service.js +16 -64
- package/target/node/utils.js +0 -3
- package/target/web/ems_client.js +300 -432
- package/target/web/ems_service.js +10 -26
- package/target/web/file_layer.js +62 -118
- package/target/web/index.js +1 -0
- package/target/web/origin.js +1 -0
- package/target/web/tms_service.js +367 -540
- package/target/web/utils.js +0 -2
- package/.ci/jobs/defaults.yml +0 -67
- package/.ci/jobs/elastic+ems-client+master.yml +0 -18
- package/.ci/jobs/elastic+ems-client+pull-request.yml +0 -18
- package/target/ems_client.js +0 -443
- package/target/ems_service.js +0 -76
- package/target/file_layer.js +0 -123
- package/target/index.js +0 -28
- package/target/origin.js +0 -24
- package/target/tms_service.js +0 -429
- package/target/tsdoc-metadata.json +0 -11
- package/target/utils.js +0 -42
package/.backportrc.json
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"upstream": "elastic/ems-client",
|
|
3
|
-
"branches": [
|
|
4
|
-
|
|
3
|
+
"branches": [
|
|
4
|
+
{
|
|
5
|
+
"name": "8.4",
|
|
6
|
+
"checked": true
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"name": "7.17",
|
|
10
|
+
"checked": true
|
|
11
|
+
}
|
|
12
|
+
],
|
|
13
|
+
"labels": [
|
|
14
|
+
"backport"
|
|
15
|
+
]
|
|
5
16
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
3
|
+
# or more contributor license agreements. Licensed under the Elastic License;
|
|
4
|
+
# you may not use this file except in compliance with the Elastic License.
|
|
5
|
+
#
|
|
6
|
+
|
|
7
|
+
set -eu
|
|
8
|
+
|
|
9
|
+
echo "--- :yarn: Installing dependencies"
|
|
10
|
+
yarn install
|
|
11
|
+
|
|
12
|
+
echo "--- :alembic: Running tests"
|
|
13
|
+
yarn test
|
|
14
|
+
|
|
15
|
+
echo "--- :gear: Building"
|
|
16
|
+
yarn build
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"jobs": [
|
|
3
|
+
{
|
|
4
|
+
"repoOwner": "elastic",
|
|
5
|
+
"repoName": "ems-client",
|
|
6
|
+
"enabled": true,
|
|
7
|
+
"pipeline_slug": "ems-client",
|
|
8
|
+
"allow_org_users": true,
|
|
9
|
+
"allowed_repo_permissions": [
|
|
10
|
+
"admin",
|
|
11
|
+
"write"
|
|
12
|
+
],
|
|
13
|
+
"allowed_list": [
|
|
14
|
+
"dependabot"
|
|
15
|
+
],
|
|
16
|
+
"build_on_commit": true,
|
|
17
|
+
"build_on_comment": true,
|
|
18
|
+
"trigger_comment_regex": "^(?:(?:buildkite\\W+)?(?:build|test)\\W+(?:this|it))",
|
|
19
|
+
"always_trigger_comment_regex": "^(?:(?:buildkite\\W+)?(?:build|test)\\W+(?:this|it))",
|
|
20
|
+
"skip_ci_labels": [
|
|
21
|
+
"skip-ci"
|
|
22
|
+
],
|
|
23
|
+
"skip_ci_on_only_changed": [
|
|
24
|
+
"\\.md$",
|
|
25
|
+
"^.ci/.+\\.yml$",
|
|
26
|
+
"^\\.buildkite/pull_requests\\.json$"
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
}
|
package/.nvmrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
lts/iron
|
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,22 @@ All notable changes to this project will be documented in this file.
|
|
|
3
3
|
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
5
5
|
|
|
6
|
+
## [7.17.1] - 2023-11-09
|
|
7
|
+
|
|
8
|
+
### Changed
|
|
9
|
+
|
|
10
|
+
- Default EMS version is 7.17
|
|
11
|
+
- Upgrade dependencies #138 #162 #165 #169 #172 #173 !76 #184 #191 #198 #205
|
|
12
|
+
- Migration from Jenkins to Buildkite for automatic testing #163 #199
|
|
13
|
+
- Upgrade to Node 20 #208
|
|
14
|
+
|
|
15
|
+
## [7.16.0] - 2021-10-13
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
- Default EMS version is 7.16
|
|
19
|
+
- Update dependencies using `yarn upgrade`
|
|
20
|
+
- Better error handling for HTTP responses
|
|
21
|
+
|
|
6
22
|
## [7.15.1] - 2021-09-01
|
|
7
23
|
|
|
8
24
|
### Changed
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
---
|
|
2
|
+
# yaml-language-server: $schema=https://json.schemastore.org/catalog-info.json
|
|
3
|
+
apiVersion: backstage.io/v1alpha1
|
|
4
|
+
kind: Component
|
|
5
|
+
metadata:
|
|
6
|
+
name: ems-client
|
|
7
|
+
description: JavaScript library to interact with the Elastic Maps Service
|
|
8
|
+
|
|
9
|
+
annotations:
|
|
10
|
+
backstage.io/source-location: url:https://github.com/elastic/ems-client/
|
|
11
|
+
github.com/project-slug: elastic/ems-client
|
|
12
|
+
github.com/team-slug: elastic/ems
|
|
13
|
+
buildkite.com/project-slug: elastic/ems-client
|
|
14
|
+
|
|
15
|
+
tags:
|
|
16
|
+
- nodejs
|
|
17
|
+
- ems
|
|
18
|
+
- kibana
|
|
19
|
+
|
|
20
|
+
links:
|
|
21
|
+
- title: Releases (npm)
|
|
22
|
+
url: https://www.npmjs.com/@elastic/ems-client
|
|
23
|
+
- title: Documentation
|
|
24
|
+
url: https://github.com/elastic/ems-client/blob/master/README.md
|
|
25
|
+
- title: EMS License
|
|
26
|
+
url: https://www.elastic.co/elastic-maps-service-terms
|
|
27
|
+
|
|
28
|
+
spec:
|
|
29
|
+
type: library
|
|
30
|
+
owner: group:ems
|
|
31
|
+
lifecycle: production
|
|
32
|
+
---
|
|
33
|
+
# yaml-language-server: $schema=https://gist.githubusercontent.com/elasticmachine/988b80dae436cafea07d9a4a460a011d/raw/e57ee3bed7a6f73077a3f55a38e76e40ec87a7cf/rre.schema.json
|
|
34
|
+
apiVersion: backstage.io/v1alpha1
|
|
35
|
+
kind: Resource
|
|
36
|
+
metadata:
|
|
37
|
+
name: buildkite-pipeline-ems-client
|
|
38
|
+
description: Buildkite Pipeline for ems-client
|
|
39
|
+
links:
|
|
40
|
+
- title: Pipeline
|
|
41
|
+
url: https://buildkite.com/elastic/ems-client
|
|
42
|
+
|
|
43
|
+
spec:
|
|
44
|
+
type: buildkite-pipeline
|
|
45
|
+
owner: group:ems
|
|
46
|
+
system: buildkite
|
|
47
|
+
implementation:
|
|
48
|
+
apiVersion: buildkite.elastic.dev/v1
|
|
49
|
+
kind: Pipeline
|
|
50
|
+
metadata:
|
|
51
|
+
name: EMS Client
|
|
52
|
+
description: Pipeline to run the EMS Client tests suite on
|
|
53
|
+
spec:
|
|
54
|
+
repository: elastic/ems-client
|
|
55
|
+
pipeline_file: ".buildkite/pipeline.yml"
|
|
56
|
+
default_branch: master
|
|
57
|
+
env:
|
|
58
|
+
ELASTIC_PR_COMMENTS_ENABLED: 'true'
|
|
59
|
+
teams: # Who has access to the pipeline.
|
|
60
|
+
ems: {}
|
|
61
|
+
everyone:
|
|
62
|
+
access_level: READ_ONLY
|
|
63
|
+
provider_settings:
|
|
64
|
+
publish_commit_status: true
|
|
65
|
+
schedules:
|
|
66
|
+
Weekly build on master branch:
|
|
67
|
+
cronline: "@weekly"
|
|
68
|
+
message: "Weekly tests and build"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elastic/ems-client",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.17.1",
|
|
4
4
|
"description": "JavaScript client library for the Elastic Maps Service",
|
|
5
5
|
"main": "target/node/index.js",
|
|
6
6
|
"browser": "target/web/index.js",
|
|
@@ -35,13 +35,13 @@
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@types/geojson": "^7946.0.
|
|
38
|
+
"@types/geojson": "^7946.0.10",
|
|
39
39
|
"@types/lru-cache": "^5.1.0",
|
|
40
|
-
"@types/topojson-client": "^3.
|
|
40
|
+
"@types/topojson-client": "^3.1.1",
|
|
41
41
|
"@types/topojson-specification": "^1.0.1",
|
|
42
42
|
"lodash": "^4.17.15",
|
|
43
43
|
"lru-cache": "^6.0.0",
|
|
44
|
-
"semver": "
|
|
44
|
+
"semver": "7.5.4",
|
|
45
45
|
"topojson-client": "^3.1.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
@@ -66,6 +66,9 @@
|
|
|
66
66
|
"node-fetch": "^2.6.1",
|
|
67
67
|
"prettier": "^2.0.5",
|
|
68
68
|
"ts-jest": "^26.2.0",
|
|
69
|
-
"typescript": "
|
|
69
|
+
"typescript": "4.6.3"
|
|
70
|
+
},
|
|
71
|
+
"engines": {
|
|
72
|
+
"node": ">=18 <=20"
|
|
70
73
|
}
|
|
71
74
|
}
|
package/src/ems_client.ts
CHANGED
|
@@ -9,13 +9,14 @@ import _ from 'lodash';
|
|
|
9
9
|
import { TMSService } from './tms_service';
|
|
10
10
|
import { EMSFormatType, FileLayer } from './file_layer';
|
|
11
11
|
import { FeatureCollection } from 'geojson';
|
|
12
|
+
import { Response } from 'node-fetch';
|
|
12
13
|
import semver from 'semver';
|
|
13
14
|
import { format as formatUrl, parse as parseUrl, UrlObject } from 'url';
|
|
14
15
|
import { toAbsoluteUrl } from './utils';
|
|
15
16
|
import { ParsedUrlQueryInput } from 'querystring';
|
|
16
17
|
import LRUCache from 'lru-cache';
|
|
17
18
|
|
|
18
|
-
const DEFAULT_EMS_VERSION = '7.
|
|
19
|
+
const DEFAULT_EMS_VERSION = '7.17';
|
|
19
20
|
|
|
20
21
|
type URLMeaningfulParts = {
|
|
21
22
|
auth?: string | null;
|
|
@@ -278,16 +279,17 @@ export class EMSClient {
|
|
|
278
279
|
async getManifest<T>(endpointUrl: string): Promise<T> {
|
|
279
280
|
try {
|
|
280
281
|
const url = extendUrl(endpointUrl, { query: this._queryParams });
|
|
281
|
-
const
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
if (!e) {
|
|
285
|
-
e = new Error('Unknown error');
|
|
282
|
+
const response = await this._fetchWithTimeout(url);
|
|
283
|
+
if (!response.ok) {
|
|
284
|
+
throw new Error(response.statusText);
|
|
286
285
|
}
|
|
287
|
-
|
|
288
|
-
|
|
286
|
+
return response ? await response.json() : null;
|
|
287
|
+
} catch (e) {
|
|
288
|
+
if (e instanceof Error) {
|
|
289
|
+
throw e;
|
|
290
|
+
} else {
|
|
291
|
+
throw new Error('Unknown error');
|
|
289
292
|
}
|
|
290
|
-
throw new Error(`Unable to retrieve data from ${endpointUrl}: ${e.message}`);
|
|
291
293
|
}
|
|
292
294
|
}
|
|
293
295
|
|
|
@@ -390,14 +392,14 @@ export class EMSClient {
|
|
|
390
392
|
}
|
|
391
393
|
}
|
|
392
394
|
|
|
393
|
-
private _fetchWithTimeout(url: string): Promise<
|
|
394
|
-
return new Promise<
|
|
395
|
+
private _fetchWithTimeout(url: string): Promise<Response> {
|
|
396
|
+
return new Promise<Response>((resolve, reject) => {
|
|
395
397
|
const timer = setTimeout(
|
|
396
398
|
() => reject(new Error(`Request to ${url} timed out`)),
|
|
397
399
|
this.EMS_LOAD_TIMEOUT
|
|
398
400
|
);
|
|
399
401
|
this._fetchFunction(url).then(
|
|
400
|
-
(response:
|
|
402
|
+
(response: Response) => {
|
|
401
403
|
clearTimeout(timer);
|
|
402
404
|
resolve(response);
|
|
403
405
|
},
|
package/src/file_layer.ts
CHANGED
|
@@ -41,7 +41,6 @@ export class FileLayer extends AbstractEmsService {
|
|
|
41
41
|
|
|
42
42
|
const format = this.getDefaultFormatType();
|
|
43
43
|
const fetchUrl = this.getDefaultFormatUrl();
|
|
44
|
-
// let fetchedJson;
|
|
45
44
|
let geojson;
|
|
46
45
|
const fetchedJson = await this._emsClient.getManifest(fetchUrl);
|
|
47
46
|
if (fetchedJson) {
|
|
@@ -4,27 +4,23 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.EMSClient = void 0;
|
|
7
|
-
|
|
8
7
|
var _lodash = _interopRequireDefault(require("lodash"));
|
|
9
|
-
|
|
10
8
|
var _tms_service = require("./tms_service");
|
|
11
|
-
|
|
12
9
|
var _file_layer = require("./file_layer");
|
|
13
|
-
|
|
14
10
|
var _semver = _interopRequireDefault(require("semver"));
|
|
15
|
-
|
|
16
11
|
var _url = require("url");
|
|
17
|
-
|
|
18
12
|
var _utils = require("./utils");
|
|
19
|
-
|
|
20
13
|
var _lruCache = _interopRequireDefault(require("lru-cache"));
|
|
21
|
-
|
|
22
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
-
|
|
24
|
-
function
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
15
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
16
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
17
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /*
|
|
18
|
+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
19
|
+
* or more contributor license agreements. Licensed under the Elastic License
|
|
20
|
+
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
21
|
+
* 2.0.
|
|
22
|
+
*/
|
|
23
|
+
const DEFAULT_EMS_VERSION = '7.17';
|
|
28
24
|
/**
|
|
29
25
|
* plugins cannot have upstream dependencies on core/*-kibana.
|
|
30
26
|
* Work-around by copy-pasting modifyUrl routine here.
|
|
@@ -32,13 +28,14 @@ const DEFAULT_EMS_VERSION = '7.15';
|
|
|
32
28
|
* @param block
|
|
33
29
|
*/
|
|
34
30
|
function modifyUrlLocal(url, block) {
|
|
35
|
-
const parsed = (0, _url.parse)(url, true);
|
|
31
|
+
const parsed = (0, _url.parse)(url, true);
|
|
32
|
+
|
|
33
|
+
// copy over the most specific version of each
|
|
36
34
|
// property. By default, the parsed url includes
|
|
37
35
|
// several conflicting properties (like path and
|
|
38
36
|
// pathname + search, or search and query) and keeping
|
|
39
37
|
// track of which property is actually used when they
|
|
40
38
|
// are formatted is harder than necessary
|
|
41
|
-
|
|
42
39
|
const meaningfulParts = {
|
|
43
40
|
protocol: parsed.protocol,
|
|
44
41
|
slashes: parsed.slashes,
|
|
@@ -48,10 +45,12 @@ function modifyUrlLocal(url, block) {
|
|
|
48
45
|
pathname: parsed.pathname,
|
|
49
46
|
query: parsed.query || {},
|
|
50
47
|
hash: parsed.hash
|
|
51
|
-
};
|
|
48
|
+
};
|
|
52
49
|
|
|
53
|
-
|
|
50
|
+
// the block modifies the meaningfulParts object, or returns a new one
|
|
51
|
+
const modifiedParts = block(meaningfulParts) || meaningfulParts;
|
|
54
52
|
|
|
53
|
+
// format the modified/replaced meaningfulParts back into a url
|
|
55
54
|
return (0, _url.format)({
|
|
56
55
|
protocol: modifiedParts.protocol,
|
|
57
56
|
slashes: modifiedParts.slashes,
|
|
@@ -63,65 +62,43 @@ function modifyUrlLocal(url, block) {
|
|
|
63
62
|
hash: modifiedParts.hash
|
|
64
63
|
});
|
|
65
64
|
}
|
|
66
|
-
|
|
67
65
|
const extendUrl = (url, props) => modifyUrlLocal(url, parsed => _lodash.default.merge(parsed, props));
|
|
66
|
+
|
|
68
67
|
/**
|
|
69
68
|
* Unescape a url template that was escaped by encodeURI() so leaflet
|
|
70
69
|
* will be able to correctly locate the variables in the template
|
|
71
70
|
* @param {String} url
|
|
72
71
|
* @return {String}
|
|
73
72
|
*/
|
|
74
|
-
|
|
75
|
-
|
|
76
73
|
const unescapeTemplateVars = url => {
|
|
77
74
|
const ENCODED_TEMPLATE_VARS_RE = /%7B(\w+?)%7D/g;
|
|
78
75
|
return url.replace(ENCODED_TEMPLATE_VARS_RE, (total, varName) => `{${varName}}`);
|
|
79
76
|
};
|
|
80
|
-
|
|
81
77
|
//this is not the default locale from Kibana, but the default locale supported by the Elastic Maps Service
|
|
82
78
|
const DEFAULT_LANGUAGE = 'en';
|
|
83
|
-
|
|
84
79
|
class EMSClient {
|
|
85
|
-
/**
|
|
86
|
-
* these methods are assigned outside the constructor
|
|
87
|
-
*/
|
|
88
80
|
constructor(config) {
|
|
89
81
|
_defineProperty(this, "EMS_LOAD_TIMEOUT", 32000);
|
|
90
|
-
|
|
91
82
|
_defineProperty(this, "_queryParams", void 0);
|
|
92
|
-
|
|
93
83
|
_defineProperty(this, "_appVersion", void 0);
|
|
94
|
-
|
|
95
84
|
_defineProperty(this, "_fetchFunction", void 0);
|
|
96
|
-
|
|
97
85
|
_defineProperty(this, "_sanitizer", void 0);
|
|
98
|
-
|
|
99
86
|
_defineProperty(this, "_manifestServiceUrl", void 0);
|
|
100
|
-
|
|
101
87
|
_defineProperty(this, "_fileApiUrl", void 0);
|
|
102
|
-
|
|
103
88
|
_defineProperty(this, "_tileApiUrl", void 0);
|
|
104
|
-
|
|
105
89
|
_defineProperty(this, "_emsVersion", void 0);
|
|
106
|
-
|
|
107
90
|
_defineProperty(this, "_emsLandingPageUrl", void 0);
|
|
108
|
-
|
|
109
91
|
_defineProperty(this, "_language", void 0);
|
|
110
|
-
|
|
111
92
|
_defineProperty(this, "_proxyPath", void 0);
|
|
112
|
-
|
|
113
93
|
_defineProperty(this, "_cache", void 0);
|
|
114
|
-
|
|
94
|
+
/**
|
|
95
|
+
* these methods are assigned outside the constructor
|
|
96
|
+
*/
|
|
115
97
|
_defineProperty(this, "_getMainCatalog", void 0);
|
|
116
|
-
|
|
117
98
|
_defineProperty(this, "_getDefaultTMSCatalog", void 0);
|
|
118
|
-
|
|
119
99
|
_defineProperty(this, "_getDefaultFileCatalog", void 0);
|
|
120
|
-
|
|
121
100
|
_defineProperty(this, "_loadTMSServices", void 0);
|
|
122
|
-
|
|
123
101
|
_defineProperty(this, "_loadFileLayers", void 0);
|
|
124
|
-
|
|
125
102
|
// Remove kbnVersion in 8.0
|
|
126
103
|
if ('kbnVersion' in config) {
|
|
127
104
|
console.warn('The "kbnVersion" parameter for ems-client is deprecated. Please use "appVersion" instead.');
|
|
@@ -129,7 +106,6 @@ class EMSClient {
|
|
|
129
106
|
} else {
|
|
130
107
|
this._appVersion = config.appVersion;
|
|
131
108
|
}
|
|
132
|
-
|
|
133
109
|
this._queryParams = {
|
|
134
110
|
elastic_tile_service_tos: 'agree',
|
|
135
111
|
my_app_name: config.appName || 'kibana',
|
|
@@ -147,159 +123,127 @@ class EMSClient {
|
|
|
147
123
|
this._cache = new _lruCache.default({
|
|
148
124
|
max: config.cacheSize || 10
|
|
149
125
|
});
|
|
150
|
-
|
|
151
126
|
this._invalidateSettings();
|
|
152
127
|
}
|
|
153
|
-
|
|
154
128
|
getDefaultLocale() {
|
|
155
129
|
return DEFAULT_LANGUAGE;
|
|
156
130
|
}
|
|
157
|
-
|
|
158
131
|
getLocale() {
|
|
159
132
|
return this._language;
|
|
160
133
|
}
|
|
161
|
-
|
|
162
134
|
getValueInLanguage(i18nObject) {
|
|
163
135
|
if (!i18nObject) {
|
|
164
136
|
return '';
|
|
165
137
|
}
|
|
166
|
-
|
|
167
138
|
return i18nObject[this._language] ? i18nObject[this._language] : i18nObject[DEFAULT_LANGUAGE];
|
|
168
139
|
}
|
|
140
|
+
|
|
169
141
|
/**
|
|
170
142
|
* this internal method is overridden by the tests to simulate custom manifest.
|
|
171
143
|
*/
|
|
172
|
-
|
|
173
|
-
|
|
174
144
|
async getManifest(endpointUrl) {
|
|
175
145
|
try {
|
|
176
146
|
const url = extendUrl(endpointUrl, {
|
|
177
147
|
query: this._queryParams
|
|
178
148
|
});
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
if (!e) {
|
|
183
|
-
e = new Error('Unknown error');
|
|
149
|
+
const response = await this._fetchWithTimeout(url);
|
|
150
|
+
if (!response.ok) {
|
|
151
|
+
throw new Error(response.statusText);
|
|
184
152
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
153
|
+
return response ? await response.json() : null;
|
|
154
|
+
} catch (e) {
|
|
155
|
+
if (e instanceof Error) {
|
|
156
|
+
throw e;
|
|
157
|
+
} else {
|
|
158
|
+
throw new Error('Unknown error');
|
|
188
159
|
}
|
|
189
|
-
|
|
190
|
-
throw new Error(`Unable to retrieve data from ${endpointUrl}: ${e.message}`);
|
|
191
160
|
}
|
|
192
161
|
}
|
|
162
|
+
|
|
193
163
|
/**
|
|
194
164
|
* Add optional query-parameters to all requests
|
|
195
165
|
*
|
|
196
166
|
* @param additionalQueryParams
|
|
197
167
|
*/
|
|
198
|
-
|
|
199
|
-
|
|
200
168
|
addQueryParams(additionalQueryParams) {
|
|
201
169
|
for (const key in additionalQueryParams) {
|
|
202
170
|
if (additionalQueryParams.hasOwnProperty(key)) {
|
|
203
171
|
if (additionalQueryParams[key] !== this._queryParams[key]) {
|
|
204
172
|
//changes detected.
|
|
205
173
|
this._queryParams = _lodash.default.assign({}, this._queryParams, additionalQueryParams);
|
|
206
|
-
|
|
207
174
|
this._invalidateSettings();
|
|
208
|
-
|
|
209
175
|
break;
|
|
210
176
|
}
|
|
211
177
|
}
|
|
212
178
|
}
|
|
213
179
|
}
|
|
214
|
-
|
|
215
180
|
async getMainManifest() {
|
|
216
181
|
return await this._getMainCatalog();
|
|
217
182
|
}
|
|
218
|
-
|
|
219
183
|
async getDefaultFileManifest() {
|
|
220
184
|
return await this._getDefaultFileCatalog();
|
|
221
185
|
}
|
|
222
|
-
|
|
223
186
|
async getDefaultTMSManifest() {
|
|
224
187
|
return await this._getDefaultTMSCatalog();
|
|
225
188
|
}
|
|
226
|
-
|
|
227
189
|
async getFileLayers() {
|
|
228
190
|
return await this._loadFileLayers();
|
|
229
191
|
}
|
|
230
|
-
|
|
231
192
|
async getTMSServices() {
|
|
232
193
|
return await this._loadTMSServices();
|
|
233
194
|
}
|
|
234
|
-
|
|
235
195
|
cacheGeoJson(layerId, geoJson) {
|
|
236
196
|
this._cache.set(layerId, geoJson);
|
|
237
|
-
|
|
238
197
|
return;
|
|
239
198
|
}
|
|
240
|
-
|
|
241
199
|
getCachedGeoJson(layerId) {
|
|
242
200
|
return this._cache.get(layerId);
|
|
243
201
|
}
|
|
244
|
-
|
|
245
202
|
getTileApiUrl() {
|
|
246
203
|
return this._tileApiUrl;
|
|
247
204
|
}
|
|
248
|
-
|
|
249
205
|
getFileApiUrl() {
|
|
250
206
|
return this._fileApiUrl;
|
|
251
207
|
}
|
|
252
|
-
|
|
253
208
|
getLandingPageUrl() {
|
|
254
209
|
return this._emsLandingPageUrl;
|
|
255
210
|
}
|
|
256
|
-
|
|
257
211
|
sanitizeHtml(html) {
|
|
258
212
|
return this._sanitizer(html);
|
|
259
213
|
}
|
|
260
|
-
|
|
261
214
|
extendUrlWithParams(url) {
|
|
262
215
|
return unescapeTemplateVars(extendUrl(url, {
|
|
263
216
|
query: this._queryParams
|
|
264
217
|
}));
|
|
265
218
|
}
|
|
266
|
-
|
|
267
219
|
async findFileLayerById(id) {
|
|
268
220
|
const fileLayers = await this.getFileLayers();
|
|
269
|
-
|
|
270
221
|
for (let i = 0; i < fileLayers.length; i++) {
|
|
271
222
|
if (fileLayers[i].hasId(id)) {
|
|
272
223
|
return fileLayers[i];
|
|
273
224
|
}
|
|
274
225
|
}
|
|
275
226
|
}
|
|
276
|
-
|
|
277
227
|
async findTMSServiceById(id) {
|
|
278
228
|
const tmsServices = await this.getTMSServices();
|
|
279
|
-
|
|
280
229
|
for (let i = 0; i < tmsServices.length; i++) {
|
|
281
230
|
if (tmsServices[i].hasId(id)) {
|
|
282
231
|
return tmsServices[i];
|
|
283
232
|
}
|
|
284
233
|
}
|
|
285
234
|
}
|
|
286
|
-
|
|
287
235
|
_getEmsVersion(version) {
|
|
288
236
|
const userVersion = _semver.default.valid(_semver.default.coerce(version));
|
|
289
|
-
|
|
290
237
|
const semverVersion = userVersion ? userVersion : _semver.default.coerce(DEFAULT_EMS_VERSION);
|
|
291
|
-
|
|
292
238
|
if (semverVersion) {
|
|
293
239
|
return `v${_semver.default.major(semverVersion)}.${_semver.default.minor(semverVersion)}`;
|
|
294
240
|
} else {
|
|
295
241
|
throw new Error(`Invalid version: ${version}`);
|
|
296
242
|
}
|
|
297
243
|
}
|
|
298
|
-
|
|
299
244
|
_fetchWithTimeout(url) {
|
|
300
245
|
return new Promise((resolve, reject) => {
|
|
301
246
|
const timer = setTimeout(() => reject(new Error(`Request to ${url} timed out`)), this.EMS_LOAD_TIMEOUT);
|
|
302
|
-
|
|
303
247
|
this._fetchFunction(url).then(response => {
|
|
304
248
|
clearTimeout(timer);
|
|
305
249
|
resolve(response);
|
|
@@ -309,15 +253,12 @@ class EMSClient {
|
|
|
309
253
|
});
|
|
310
254
|
});
|
|
311
255
|
}
|
|
312
|
-
|
|
313
256
|
async _getManifestWithParams(url) {
|
|
314
257
|
const extendedUrl = this.extendUrlWithParams(url);
|
|
315
258
|
return await this.getManifest(extendedUrl);
|
|
316
259
|
}
|
|
317
|
-
|
|
318
260
|
_invalidateSettings() {
|
|
319
261
|
this._cache.reset();
|
|
320
|
-
|
|
321
262
|
this._getMainCatalog = _lodash.default.once(async () => {
|
|
322
263
|
// Preserve manifestServiceUrl parameter for backwards compatibility with EMS v7.2
|
|
323
264
|
if (this._manifestServiceUrl) {
|
|
@@ -326,21 +267,18 @@ class EMSClient {
|
|
|
326
267
|
return await this._getManifestWithParams(this._manifestServiceUrl);
|
|
327
268
|
} else {
|
|
328
269
|
const services = [];
|
|
329
|
-
|
|
330
270
|
if (this._tileApiUrl) {
|
|
331
271
|
services.push({
|
|
332
272
|
type: 'tms',
|
|
333
273
|
manifest: (0, _utils.toAbsoluteUrl)(this._tileApiUrl, `${this._emsVersion}/manifest`)
|
|
334
274
|
});
|
|
335
275
|
}
|
|
336
|
-
|
|
337
276
|
if (this._fileApiUrl) {
|
|
338
277
|
services.push({
|
|
339
278
|
type: 'file',
|
|
340
279
|
manifest: (0, _utils.toAbsoluteUrl)(this._fileApiUrl, `${this._emsVersion}/manifest`)
|
|
341
280
|
});
|
|
342
281
|
}
|
|
343
|
-
|
|
344
282
|
return {
|
|
345
283
|
services: services
|
|
346
284
|
};
|
|
@@ -349,30 +287,27 @@ class EMSClient {
|
|
|
349
287
|
this._getDefaultTMSCatalog = _lodash.default.once(async () => {
|
|
350
288
|
const catalogue = await this._getMainCatalog();
|
|
351
289
|
const firstService = catalogue.services.find(service => service.type === 'tms');
|
|
352
|
-
|
|
353
290
|
if (!firstService) {
|
|
354
291
|
return {
|
|
355
292
|
services: []
|
|
356
293
|
};
|
|
357
294
|
}
|
|
358
|
-
|
|
359
295
|
const url = this._proxyPath + firstService.manifest;
|
|
360
296
|
return await this.getManifest(url);
|
|
361
297
|
});
|
|
362
298
|
this._getDefaultFileCatalog = _lodash.default.once(async () => {
|
|
363
299
|
const catalogue = await this._getMainCatalog();
|
|
364
300
|
const firstService = catalogue.services.find(service => service.type === 'file');
|
|
365
|
-
|
|
366
301
|
if (!firstService) {
|
|
367
302
|
return {
|
|
368
303
|
layers: []
|
|
369
304
|
};
|
|
370
305
|
}
|
|
371
|
-
|
|
372
306
|
const url = this._proxyPath + firstService.manifest;
|
|
373
307
|
return await this.getManifest(url);
|
|
374
|
-
});
|
|
308
|
+
});
|
|
375
309
|
|
|
310
|
+
//Cache the actual instances of TMSService as these in turn cache sub-manifests for the style-files
|
|
376
311
|
this._loadTMSServices = _lodash.default.once(async () => {
|
|
377
312
|
const tmsManifest = await this._getDefaultTMSCatalog();
|
|
378
313
|
return tmsManifest.services.map(serviceConfig => new _tms_service.TMSService(serviceConfig, this, this._proxyPath));
|
|
@@ -382,7 +317,5 @@ class EMSClient {
|
|
|
382
317
|
return fileManifest.layers.map(layerConfig => new _file_layer.FileLayer(layerConfig, this, this._proxyPath));
|
|
383
318
|
});
|
|
384
319
|
}
|
|
385
|
-
|
|
386
320
|
}
|
|
387
|
-
|
|
388
321
|
exports.EMSClient = EMSClient;
|