@elastic/ems-client 8.3.3 → 8.4.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 +5 -17
- 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 +12 -0
- package/CONTRIBUTING.md +18 -0
- package/catalog-info.yaml +68 -0
- package/package.json +7 -4
- package/src/ems_client.ts +1 -2
- package/src/tms_service.ts +5 -1
- package/target/node/ems_client.js +24 -92
- package/target/node/ems_service.js +11 -21
- package/target/node/file_layer.js +17 -62
- package/target/node/index.js +0 -4
- package/target/node/tms_service.js +33 -99
- package/target/node/utils.js +8 -10
- package/target/tms_service.d.ts +1 -1
- package/target/web/ems_client.js +297 -438
- package/target/web/ems_service.js +10 -26
- package/target/web/file_layer.js +62 -117
- package/target/web/index.js +1 -0
- package/target/web/tms_service.js +448 -651
- package/target/web/utils.js +10 -8
- 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 -19
package/.backportrc.json
CHANGED
|
@@ -2,25 +2,13 @@
|
|
|
2
2
|
"upstream": "elastic/ems-client",
|
|
3
3
|
"branches": [
|
|
4
4
|
{
|
|
5
|
-
"name": "8.
|
|
5
|
+
"name": "8.4",
|
|
6
6
|
"checked": true
|
|
7
7
|
},
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"7.16",
|
|
13
|
-
"7.16",
|
|
14
|
-
"7.15",
|
|
15
|
-
"7.14",
|
|
16
|
-
"7.12",
|
|
17
|
-
"7.11",
|
|
18
|
-
"7.10",
|
|
19
|
-
"7.9",
|
|
20
|
-
"7.8",
|
|
21
|
-
"7.7",
|
|
22
|
-
"7.6",
|
|
23
|
-
"7.2"
|
|
8
|
+
{
|
|
9
|
+
"name": "7.17",
|
|
10
|
+
"checked": true
|
|
11
|
+
}
|
|
24
12
|
],
|
|
25
13
|
"labels": [
|
|
26
14
|
"backport"
|
|
@@ -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,18 @@ 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
|
+
## [8.4.1] - 2023-11-09
|
|
7
|
+
|
|
8
|
+
- Migration from Jenkins to Buildkite for automatic testing #145 #147 #199
|
|
9
|
+
- Dependencies updates #165 #173 #176 #183 #181 #184 #191 #198 #205
|
|
10
|
+
- Upgrade to Node 20 #208
|
|
11
|
+
|
|
12
|
+
## [8.4.0] - 2023-01-11
|
|
13
|
+
|
|
14
|
+
- Default EMS version is 8.4
|
|
15
|
+
- Add types to colorOperationDefaults #123
|
|
16
|
+
- Update dependencies #131 #133 #134 #138
|
|
17
|
+
|
|
6
18
|
## [8.3.3] - 2022-05-24
|
|
7
19
|
|
|
8
20
|
- Make percentage an optional parameter #117
|
package/CONTRIBUTING.md
CHANGED
|
@@ -19,3 +19,21 @@ If you have access to make releases, the process is as follows:
|
|
|
19
19
|
1. Update the latest major branch on upstream with `git push upstream <major_branch>`
|
|
20
20
|
1. Build the targets with `yarn build`
|
|
21
21
|
1. Publish to npm with `npm publish --access public`
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
## Continuous Integration
|
|
25
|
+
|
|
26
|
+
This repository is tracked by Elastic [Buildkite infrastructure](https://buildkite.com/elastic) to ensure the tests suite passes and a build is successfully generated. The pipeline is located at [`.buildkite/pipeline.yml`](.buildkite/pipeline.yml), and defines the execution of the `test` and `build` scripts from `package.json`.
|
|
27
|
+
|
|
28
|
+
Builds are **triggered** on the following conditions:
|
|
29
|
+
|
|
30
|
+
* Any push to `master`
|
|
31
|
+
* Any Pull Request coming from a branch in the `elastic/ems-client` repository
|
|
32
|
+
* It will run automatically on `master` on a weekly basis
|
|
33
|
+
* Comments from Elastic team members on a Pull Request like: `buildkite test this`
|
|
34
|
+
|
|
35
|
+
Builds will be **skipped** on:
|
|
36
|
+
|
|
37
|
+
* Pull Requests from forks from users that don't have write/admin permissions on the upstream repository (`elastic/ems-client`) or are not part of the Elastic GitHub organization.
|
|
38
|
+
* Pull Requests with the `skip-ci` label
|
|
39
|
+
* Pull Requests with all files modified matching any of the regular expressions in `.buildkite/pull-requests.json => skip_ci_on_only_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": "8.
|
|
3
|
+
"version": "8.4.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,14 +35,14 @@
|
|
|
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
|
"chroma-js": "^2.1.0",
|
|
43
43
|
"lodash": "^4.17.15",
|
|
44
44
|
"lru-cache": "^6.0.0",
|
|
45
|
-
"semver": "
|
|
45
|
+
"semver": "7.5.4",
|
|
46
46
|
"topojson-client": "^3.1.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
@@ -70,5 +70,8 @@
|
|
|
70
70
|
"prettier": "^2.0.5",
|
|
71
71
|
"ts-jest": "^26.2.0",
|
|
72
72
|
"typescript": "4.6.3"
|
|
73
|
+
},
|
|
74
|
+
"engines": {
|
|
75
|
+
"node": ">=18 <=20"
|
|
73
76
|
}
|
|
74
77
|
}
|
package/src/ems_client.ts
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
5
5
|
* 2.0.
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
7
|
import _ from 'lodash';
|
|
9
8
|
import { TMSService } from './tms_service';
|
|
10
9
|
import { EMSFormatType, FileLayer } from './file_layer';
|
|
@@ -16,7 +15,7 @@ import { toAbsoluteUrl } from './utils';
|
|
|
16
15
|
import { ParsedUrlQueryInput } from 'querystring';
|
|
17
16
|
import LRUCache from 'lru-cache';
|
|
18
17
|
|
|
19
|
-
const DEFAULT_EMS_VERSION = '8.
|
|
18
|
+
const DEFAULT_EMS_VERSION = '8.4';
|
|
20
19
|
|
|
21
20
|
type URLMeaningfulParts = {
|
|
22
21
|
auth?: string | null;
|
package/src/tms_service.ts
CHANGED
|
@@ -124,7 +124,11 @@ export class TMSService extends AbstractEmsService {
|
|
|
124
124
|
/*
|
|
125
125
|
Suggested default operations for the different EMS styles
|
|
126
126
|
*/
|
|
127
|
-
public static colorOperationDefaults
|
|
127
|
+
public static colorOperationDefaults: {
|
|
128
|
+
style: string;
|
|
129
|
+
operation: blendMode;
|
|
130
|
+
percentage: number;
|
|
131
|
+
}[] = [
|
|
128
132
|
{ style: 'road_map', operation: 'mix', percentage: 0.25 },
|
|
129
133
|
{ style: 'road_map_desaturated', operation: 'screen', percentage: 0.25 },
|
|
130
134
|
{ style: 'dark_map', operation: 'dodge', percentage: 0.25 },
|
|
@@ -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 = '8.4';
|
|
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 = '8.3';
|
|
|
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,41 +123,33 @@ 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
149
|
const response = await this._fetchWithTimeout(url);
|
|
180
|
-
|
|
181
150
|
if (!response.ok) {
|
|
182
151
|
throw new Error(response.statusText);
|
|
183
152
|
}
|
|
184
|
-
|
|
185
153
|
return response ? await response.json() : null;
|
|
186
154
|
} catch (e) {
|
|
187
155
|
if (e instanceof Error) {
|
|
@@ -191,116 +159,91 @@ class EMSClient {
|
|
|
191
159
|
}
|
|
192
160
|
}
|
|
193
161
|
}
|
|
162
|
+
|
|
194
163
|
/**
|
|
195
164
|
* Add optional query-parameters to all requests
|
|
196
165
|
*
|
|
197
166
|
* @param additionalQueryParams
|
|
198
167
|
*/
|
|
199
|
-
|
|
200
|
-
|
|
201
168
|
addQueryParams(additionalQueryParams) {
|
|
202
169
|
for (const key in additionalQueryParams) {
|
|
203
170
|
if (additionalQueryParams.hasOwnProperty(key)) {
|
|
204
171
|
if (additionalQueryParams[key] !== this._queryParams[key]) {
|
|
205
172
|
//changes detected.
|
|
206
173
|
this._queryParams = _lodash.default.assign({}, this._queryParams, additionalQueryParams);
|
|
207
|
-
|
|
208
174
|
this._invalidateSettings();
|
|
209
|
-
|
|
210
175
|
break;
|
|
211
176
|
}
|
|
212
177
|
}
|
|
213
178
|
}
|
|
214
179
|
}
|
|
215
|
-
|
|
216
180
|
async getMainManifest() {
|
|
217
181
|
return await this._getMainCatalog();
|
|
218
182
|
}
|
|
219
|
-
|
|
220
183
|
async getDefaultFileManifest() {
|
|
221
184
|
return await this._getDefaultFileCatalog();
|
|
222
185
|
}
|
|
223
|
-
|
|
224
186
|
async getDefaultTMSManifest() {
|
|
225
187
|
return await this._getDefaultTMSCatalog();
|
|
226
188
|
}
|
|
227
|
-
|
|
228
189
|
async getFileLayers() {
|
|
229
190
|
return await this._loadFileLayers();
|
|
230
191
|
}
|
|
231
|
-
|
|
232
192
|
async getTMSServices() {
|
|
233
193
|
return await this._loadTMSServices();
|
|
234
194
|
}
|
|
235
|
-
|
|
236
195
|
cacheGeoJson(layerId, geoJson) {
|
|
237
196
|
this._cache.set(layerId, geoJson);
|
|
238
|
-
|
|
239
197
|
return;
|
|
240
198
|
}
|
|
241
|
-
|
|
242
199
|
getCachedGeoJson(layerId) {
|
|
243
200
|
return this._cache.get(layerId);
|
|
244
201
|
}
|
|
245
|
-
|
|
246
202
|
getTileApiUrl() {
|
|
247
203
|
return this._tileApiUrl;
|
|
248
204
|
}
|
|
249
|
-
|
|
250
205
|
getFileApiUrl() {
|
|
251
206
|
return this._fileApiUrl;
|
|
252
207
|
}
|
|
253
|
-
|
|
254
208
|
getLandingPageUrl() {
|
|
255
209
|
return this._emsLandingPageUrl;
|
|
256
210
|
}
|
|
257
|
-
|
|
258
211
|
sanitizeHtml(html) {
|
|
259
212
|
return this._sanitizer(html);
|
|
260
213
|
}
|
|
261
|
-
|
|
262
214
|
extendUrlWithParams(url) {
|
|
263
215
|
return unescapeTemplateVars(extendUrl(url, {
|
|
264
216
|
query: this._queryParams
|
|
265
217
|
}));
|
|
266
218
|
}
|
|
267
|
-
|
|
268
219
|
async findFileLayerById(id) {
|
|
269
220
|
const fileLayers = await this.getFileLayers();
|
|
270
|
-
|
|
271
221
|
for (let i = 0; i < fileLayers.length; i++) {
|
|
272
222
|
if (fileLayers[i].hasId(id)) {
|
|
273
223
|
return fileLayers[i];
|
|
274
224
|
}
|
|
275
225
|
}
|
|
276
226
|
}
|
|
277
|
-
|
|
278
227
|
async findTMSServiceById(id) {
|
|
279
228
|
const tmsServices = await this.getTMSServices();
|
|
280
|
-
|
|
281
229
|
for (let i = 0; i < tmsServices.length; i++) {
|
|
282
230
|
if (tmsServices[i].hasId(id)) {
|
|
283
231
|
return tmsServices[i];
|
|
284
232
|
}
|
|
285
233
|
}
|
|
286
234
|
}
|
|
287
|
-
|
|
288
235
|
_getEmsVersion(version) {
|
|
289
236
|
const userVersion = _semver.default.valid(_semver.default.coerce(version));
|
|
290
|
-
|
|
291
237
|
const semverVersion = userVersion ? userVersion : _semver.default.coerce(DEFAULT_EMS_VERSION);
|
|
292
|
-
|
|
293
238
|
if (semverVersion) {
|
|
294
239
|
return `v${_semver.default.major(semverVersion)}.${_semver.default.minor(semverVersion)}`;
|
|
295
240
|
} else {
|
|
296
241
|
throw new Error(`Invalid version: ${version}`);
|
|
297
242
|
}
|
|
298
243
|
}
|
|
299
|
-
|
|
300
244
|
_fetchWithTimeout(url) {
|
|
301
245
|
return new Promise((resolve, reject) => {
|
|
302
246
|
const timer = setTimeout(() => reject(new Error(`Request to ${url} timed out`)), this.EMS_LOAD_TIMEOUT);
|
|
303
|
-
|
|
304
247
|
this._fetchFunction(url).then(response => {
|
|
305
248
|
clearTimeout(timer);
|
|
306
249
|
resolve(response);
|
|
@@ -310,15 +253,12 @@ class EMSClient {
|
|
|
310
253
|
});
|
|
311
254
|
});
|
|
312
255
|
}
|
|
313
|
-
|
|
314
256
|
async _getManifestWithParams(url) {
|
|
315
257
|
const extendedUrl = this.extendUrlWithParams(url);
|
|
316
258
|
return await this.getManifest(extendedUrl);
|
|
317
259
|
}
|
|
318
|
-
|
|
319
260
|
_invalidateSettings() {
|
|
320
261
|
this._cache.reset();
|
|
321
|
-
|
|
322
262
|
this._getMainCatalog = _lodash.default.once(async () => {
|
|
323
263
|
// Preserve manifestServiceUrl parameter for backwards compatibility with EMS v7.2
|
|
324
264
|
if (this._manifestServiceUrl) {
|
|
@@ -327,21 +267,18 @@ class EMSClient {
|
|
|
327
267
|
return await this._getManifestWithParams(this._manifestServiceUrl);
|
|
328
268
|
} else {
|
|
329
269
|
const services = [];
|
|
330
|
-
|
|
331
270
|
if (this._tileApiUrl) {
|
|
332
271
|
services.push({
|
|
333
272
|
type: 'tms',
|
|
334
273
|
manifest: (0, _utils.toAbsoluteUrl)(this._tileApiUrl, `${this._emsVersion}/manifest`)
|
|
335
274
|
});
|
|
336
275
|
}
|
|
337
|
-
|
|
338
276
|
if (this._fileApiUrl) {
|
|
339
277
|
services.push({
|
|
340
278
|
type: 'file',
|
|
341
279
|
manifest: (0, _utils.toAbsoluteUrl)(this._fileApiUrl, `${this._emsVersion}/manifest`)
|
|
342
280
|
});
|
|
343
281
|
}
|
|
344
|
-
|
|
345
282
|
return {
|
|
346
283
|
services: services
|
|
347
284
|
};
|
|
@@ -350,30 +287,27 @@ class EMSClient {
|
|
|
350
287
|
this._getDefaultTMSCatalog = _lodash.default.once(async () => {
|
|
351
288
|
const catalogue = await this._getMainCatalog();
|
|
352
289
|
const firstService = catalogue.services.find(service => service.type === 'tms');
|
|
353
|
-
|
|
354
290
|
if (!firstService) {
|
|
355
291
|
return {
|
|
356
292
|
services: []
|
|
357
293
|
};
|
|
358
294
|
}
|
|
359
|
-
|
|
360
295
|
const url = this._proxyPath + firstService.manifest;
|
|
361
296
|
return await this.getManifest(url);
|
|
362
297
|
});
|
|
363
298
|
this._getDefaultFileCatalog = _lodash.default.once(async () => {
|
|
364
299
|
const catalogue = await this._getMainCatalog();
|
|
365
300
|
const firstService = catalogue.services.find(service => service.type === 'file');
|
|
366
|
-
|
|
367
301
|
if (!firstService) {
|
|
368
302
|
return {
|
|
369
303
|
layers: []
|
|
370
304
|
};
|
|
371
305
|
}
|
|
372
|
-
|
|
373
306
|
const url = this._proxyPath + firstService.manifest;
|
|
374
307
|
return await this.getManifest(url);
|
|
375
|
-
});
|
|
308
|
+
});
|
|
376
309
|
|
|
310
|
+
//Cache the actual instances of TMSService as these in turn cache sub-manifests for the style-files
|
|
377
311
|
this._loadTMSServices = _lodash.default.once(async () => {
|
|
378
312
|
const tmsManifest = await this._getDefaultTMSCatalog();
|
|
379
313
|
return tmsManifest.services.map(serviceConfig => new _tms_service.TMSService(serviceConfig, this, this._proxyPath));
|
|
@@ -383,7 +317,5 @@ class EMSClient {
|
|
|
383
317
|
return fileManifest.layers.map(layerConfig => new _file_layer.FileLayer(layerConfig, this, this._proxyPath));
|
|
384
318
|
});
|
|
385
319
|
}
|
|
386
|
-
|
|
387
320
|
}
|
|
388
|
-
|
|
389
321
|
exports.EMSClient = EMSClient;
|