@elastic/ems-client 8.3.2 → 8.4.0
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/.ci/jobs/defaults.yml +2 -2
- package/CHANGELOG.md +10 -0
- package/package.json +4 -4
- package/src/ems_client.ts +1 -2
- package/src/index.ts +1 -0
- package/src/tms_service.ts +12 -5
- package/src/utils.ts +1 -1
- package/target/index.d.ts +1 -0
- package/target/node/ems_client.js +17 -89
- package/target/node/ems_service.js +4 -18
- package/target/node/file_layer.js +7 -56
- package/target/node/index.js +8 -4
- package/target/node/tms_service.js +21 -90
- package/target/node/utils.js +7 -14
- package/target/tms_service.d.ts +2 -2
- package/target/web/ems_client.js +48 -160
- package/target/web/ems_service.js +8 -23
- package/target/web/file_layer.js +15 -68
- package/target/web/index.js +3 -1
- package/target/web/tms_service.js +70 -241
- package/target/web/utils.js +8 -17
- package/test/ems_client_colour.test.ts +62 -1
package/.ci/jobs/defaults.yml
CHANGED
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
set -e
|
|
41
41
|
set +x
|
|
42
42
|
|
|
43
|
-
NODE_IMG="node:
|
|
43
|
+
NODE_IMG="node:16"
|
|
44
44
|
|
|
45
45
|
docker pull $NODE_IMG
|
|
46
46
|
docker run --rm -i \
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
--volume $PWD:/app \
|
|
52
52
|
--workdir /app \
|
|
53
53
|
$NODE_IMG \
|
|
54
|
-
bash -c '
|
|
54
|
+
bash -c '/opt/yarn*/bin/yarn && yarn test && yarn run build'
|
|
55
55
|
|
|
56
56
|
publishers:
|
|
57
57
|
- email:
|
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@ 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.0] - 2023-01-11
|
|
7
|
+
|
|
8
|
+
- Default EMS version is 8.4
|
|
9
|
+
- Add types to colorOperationDefaults #123
|
|
10
|
+
- Update dependencies #131 #133 #134 #138
|
|
11
|
+
|
|
12
|
+
## [8.3.3] - 2022-05-24
|
|
13
|
+
|
|
14
|
+
- Make percentage an optional parameter #117
|
|
15
|
+
- Make color and operation optional parameters #118
|
|
6
16
|
|
|
7
17
|
## [8.3.2] - 2022-05-16
|
|
8
18
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elastic/ems-client",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.4.0",
|
|
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": "^7.3.
|
|
45
|
+
"semver": "^7.3.8",
|
|
46
46
|
"topojson-client": "^3.1.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
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/index.ts
CHANGED
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 },
|
|
@@ -220,9 +224,9 @@ export class TMSService extends AbstractEmsService {
|
|
|
220
224
|
*/
|
|
221
225
|
public static transformColorProperties(
|
|
222
226
|
layer: LayerSpecification,
|
|
223
|
-
color
|
|
224
|
-
operation
|
|
225
|
-
percentage
|
|
227
|
+
color?: string,
|
|
228
|
+
operation?: blendMode,
|
|
229
|
+
percentage?: number
|
|
226
230
|
): { property: keyof layerPaintProperty; color: mbColorDefinition | undefined }[] {
|
|
227
231
|
if (['background', 'fill', 'line', 'symbol'].indexOf(layer.type) !== -1 && layer.paint) {
|
|
228
232
|
const paint = layer.paint as layerPaintProperty;
|
|
@@ -250,7 +254,10 @@ export class TMSService extends AbstractEmsService {
|
|
|
250
254
|
const paintColor = paint[type];
|
|
251
255
|
return {
|
|
252
256
|
property: type,
|
|
253
|
-
color:
|
|
257
|
+
color:
|
|
258
|
+
paintColor && color
|
|
259
|
+
? colorizeColor(paintColor, color, operation, percentage)
|
|
260
|
+
: paintColor,
|
|
254
261
|
};
|
|
255
262
|
});
|
|
256
263
|
} else {
|
package/src/utils.ts
CHANGED
|
@@ -76,7 +76,7 @@ function transformColor(paintColor: mbColorDefinition, func: Function): mbColorD
|
|
|
76
76
|
const newColor = transformColor(stop[1], func);
|
|
77
77
|
return [stop[0], newColor];
|
|
78
78
|
});
|
|
79
|
-
const newPaintColor = {
|
|
79
|
+
const newPaintColor = Object.assign({}, paintColor, { stops });
|
|
80
80
|
return newPaintColor;
|
|
81
81
|
} else return paintColor;
|
|
82
82
|
}
|
package/target/index.d.ts
CHANGED
|
@@ -4,27 +4,18 @@ 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
|
-
const DEFAULT_EMS_VERSION = '8.
|
|
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
|
+
const DEFAULT_EMS_VERSION = '8.4';
|
|
28
19
|
/**
|
|
29
20
|
* plugins cannot have upstream dependencies on core/*-kibana.
|
|
30
21
|
* Work-around by copy-pasting modifyUrl routine here.
|
|
@@ -32,13 +23,14 @@ const DEFAULT_EMS_VERSION = '8.3';
|
|
|
32
23
|
* @param block
|
|
33
24
|
*/
|
|
34
25
|
function modifyUrlLocal(url, block) {
|
|
35
|
-
const parsed = (0, _url.parse)(url, true);
|
|
26
|
+
const parsed = (0, _url.parse)(url, true);
|
|
27
|
+
|
|
28
|
+
// copy over the most specific version of each
|
|
36
29
|
// property. By default, the parsed url includes
|
|
37
30
|
// several conflicting properties (like path and
|
|
38
31
|
// pathname + search, or search and query) and keeping
|
|
39
32
|
// track of which property is actually used when they
|
|
40
33
|
// are formatted is harder than necessary
|
|
41
|
-
|
|
42
34
|
const meaningfulParts = {
|
|
43
35
|
protocol: parsed.protocol,
|
|
44
36
|
slashes: parsed.slashes,
|
|
@@ -48,10 +40,12 @@ function modifyUrlLocal(url, block) {
|
|
|
48
40
|
pathname: parsed.pathname,
|
|
49
41
|
query: parsed.query || {},
|
|
50
42
|
hash: parsed.hash
|
|
51
|
-
};
|
|
43
|
+
};
|
|
52
44
|
|
|
53
|
-
|
|
45
|
+
// the block modifies the meaningfulParts object, or returns a new one
|
|
46
|
+
const modifiedParts = block(meaningfulParts) || meaningfulParts;
|
|
54
47
|
|
|
48
|
+
// format the modified/replaced meaningfulParts back into a url
|
|
55
49
|
return (0, _url.format)({
|
|
56
50
|
protocol: modifiedParts.protocol,
|
|
57
51
|
slashes: modifiedParts.slashes,
|
|
@@ -63,65 +57,44 @@ function modifyUrlLocal(url, block) {
|
|
|
63
57
|
hash: modifiedParts.hash
|
|
64
58
|
});
|
|
65
59
|
}
|
|
66
|
-
|
|
67
60
|
const extendUrl = (url, props) => modifyUrlLocal(url, parsed => _lodash.default.merge(parsed, props));
|
|
61
|
+
|
|
68
62
|
/**
|
|
69
63
|
* Unescape a url template that was escaped by encodeURI() so leaflet
|
|
70
64
|
* will be able to correctly locate the variables in the template
|
|
71
65
|
* @param {String} url
|
|
72
66
|
* @return {String}
|
|
73
67
|
*/
|
|
74
|
-
|
|
75
|
-
|
|
76
68
|
const unescapeTemplateVars = url => {
|
|
77
69
|
const ENCODED_TEMPLATE_VARS_RE = /%7B(\w+?)%7D/g;
|
|
78
70
|
return url.replace(ENCODED_TEMPLATE_VARS_RE, (total, varName) => `{${varName}}`);
|
|
79
71
|
};
|
|
80
|
-
|
|
81
72
|
//this is not the default locale from Kibana, but the default locale supported by the Elastic Maps Service
|
|
82
73
|
const DEFAULT_LANGUAGE = 'en';
|
|
83
|
-
|
|
84
74
|
class EMSClient {
|
|
85
75
|
/**
|
|
86
76
|
* these methods are assigned outside the constructor
|
|
87
77
|
*/
|
|
78
|
+
|
|
88
79
|
constructor(config) {
|
|
89
80
|
_defineProperty(this, "EMS_LOAD_TIMEOUT", 32000);
|
|
90
|
-
|
|
91
81
|
_defineProperty(this, "_queryParams", void 0);
|
|
92
|
-
|
|
93
82
|
_defineProperty(this, "_appVersion", void 0);
|
|
94
|
-
|
|
95
83
|
_defineProperty(this, "_fetchFunction", void 0);
|
|
96
|
-
|
|
97
84
|
_defineProperty(this, "_sanitizer", void 0);
|
|
98
|
-
|
|
99
85
|
_defineProperty(this, "_manifestServiceUrl", void 0);
|
|
100
|
-
|
|
101
86
|
_defineProperty(this, "_fileApiUrl", void 0);
|
|
102
|
-
|
|
103
87
|
_defineProperty(this, "_tileApiUrl", void 0);
|
|
104
|
-
|
|
105
88
|
_defineProperty(this, "_emsVersion", void 0);
|
|
106
|
-
|
|
107
89
|
_defineProperty(this, "_emsLandingPageUrl", void 0);
|
|
108
|
-
|
|
109
90
|
_defineProperty(this, "_language", void 0);
|
|
110
|
-
|
|
111
91
|
_defineProperty(this, "_proxyPath", void 0);
|
|
112
|
-
|
|
113
92
|
_defineProperty(this, "_cache", void 0);
|
|
114
|
-
|
|
115
93
|
_defineProperty(this, "_getMainCatalog", void 0);
|
|
116
|
-
|
|
117
94
|
_defineProperty(this, "_getDefaultTMSCatalog", void 0);
|
|
118
|
-
|
|
119
95
|
_defineProperty(this, "_getDefaultFileCatalog", void 0);
|
|
120
|
-
|
|
121
96
|
_defineProperty(this, "_loadTMSServices", void 0);
|
|
122
|
-
|
|
123
97
|
_defineProperty(this, "_loadFileLayers", void 0);
|
|
124
|
-
|
|
125
98
|
// Remove kbnVersion in 8.0
|
|
126
99
|
if ('kbnVersion' in config) {
|
|
127
100
|
console.warn('The "kbnVersion" parameter for ems-client is deprecated. Please use "appVersion" instead.');
|
|
@@ -129,7 +102,6 @@ class EMSClient {
|
|
|
129
102
|
} else {
|
|
130
103
|
this._appVersion = config.appVersion;
|
|
131
104
|
}
|
|
132
|
-
|
|
133
105
|
this._queryParams = {
|
|
134
106
|
elastic_tile_service_tos: 'agree',
|
|
135
107
|
my_app_name: config.appName || 'kibana',
|
|
@@ -147,41 +119,33 @@ class EMSClient {
|
|
|
147
119
|
this._cache = new _lruCache.default({
|
|
148
120
|
max: config.cacheSize || 10
|
|
149
121
|
});
|
|
150
|
-
|
|
151
122
|
this._invalidateSettings();
|
|
152
123
|
}
|
|
153
|
-
|
|
154
124
|
getDefaultLocale() {
|
|
155
125
|
return DEFAULT_LANGUAGE;
|
|
156
126
|
}
|
|
157
|
-
|
|
158
127
|
getLocale() {
|
|
159
128
|
return this._language;
|
|
160
129
|
}
|
|
161
|
-
|
|
162
130
|
getValueInLanguage(i18nObject) {
|
|
163
131
|
if (!i18nObject) {
|
|
164
132
|
return '';
|
|
165
133
|
}
|
|
166
|
-
|
|
167
134
|
return i18nObject[this._language] ? i18nObject[this._language] : i18nObject[DEFAULT_LANGUAGE];
|
|
168
135
|
}
|
|
136
|
+
|
|
169
137
|
/**
|
|
170
138
|
* this internal method is overridden by the tests to simulate custom manifest.
|
|
171
139
|
*/
|
|
172
|
-
|
|
173
|
-
|
|
174
140
|
async getManifest(endpointUrl) {
|
|
175
141
|
try {
|
|
176
142
|
const url = extendUrl(endpointUrl, {
|
|
177
143
|
query: this._queryParams
|
|
178
144
|
});
|
|
179
145
|
const response = await this._fetchWithTimeout(url);
|
|
180
|
-
|
|
181
146
|
if (!response.ok) {
|
|
182
147
|
throw new Error(response.statusText);
|
|
183
148
|
}
|
|
184
|
-
|
|
185
149
|
return response ? await response.json() : null;
|
|
186
150
|
} catch (e) {
|
|
187
151
|
if (e instanceof Error) {
|
|
@@ -191,116 +155,91 @@ class EMSClient {
|
|
|
191
155
|
}
|
|
192
156
|
}
|
|
193
157
|
}
|
|
158
|
+
|
|
194
159
|
/**
|
|
195
160
|
* Add optional query-parameters to all requests
|
|
196
161
|
*
|
|
197
162
|
* @param additionalQueryParams
|
|
198
163
|
*/
|
|
199
|
-
|
|
200
|
-
|
|
201
164
|
addQueryParams(additionalQueryParams) {
|
|
202
165
|
for (const key in additionalQueryParams) {
|
|
203
166
|
if (additionalQueryParams.hasOwnProperty(key)) {
|
|
204
167
|
if (additionalQueryParams[key] !== this._queryParams[key]) {
|
|
205
168
|
//changes detected.
|
|
206
169
|
this._queryParams = _lodash.default.assign({}, this._queryParams, additionalQueryParams);
|
|
207
|
-
|
|
208
170
|
this._invalidateSettings();
|
|
209
|
-
|
|
210
171
|
break;
|
|
211
172
|
}
|
|
212
173
|
}
|
|
213
174
|
}
|
|
214
175
|
}
|
|
215
|
-
|
|
216
176
|
async getMainManifest() {
|
|
217
177
|
return await this._getMainCatalog();
|
|
218
178
|
}
|
|
219
|
-
|
|
220
179
|
async getDefaultFileManifest() {
|
|
221
180
|
return await this._getDefaultFileCatalog();
|
|
222
181
|
}
|
|
223
|
-
|
|
224
182
|
async getDefaultTMSManifest() {
|
|
225
183
|
return await this._getDefaultTMSCatalog();
|
|
226
184
|
}
|
|
227
|
-
|
|
228
185
|
async getFileLayers() {
|
|
229
186
|
return await this._loadFileLayers();
|
|
230
187
|
}
|
|
231
|
-
|
|
232
188
|
async getTMSServices() {
|
|
233
189
|
return await this._loadTMSServices();
|
|
234
190
|
}
|
|
235
|
-
|
|
236
191
|
cacheGeoJson(layerId, geoJson) {
|
|
237
192
|
this._cache.set(layerId, geoJson);
|
|
238
|
-
|
|
239
193
|
return;
|
|
240
194
|
}
|
|
241
|
-
|
|
242
195
|
getCachedGeoJson(layerId) {
|
|
243
196
|
return this._cache.get(layerId);
|
|
244
197
|
}
|
|
245
|
-
|
|
246
198
|
getTileApiUrl() {
|
|
247
199
|
return this._tileApiUrl;
|
|
248
200
|
}
|
|
249
|
-
|
|
250
201
|
getFileApiUrl() {
|
|
251
202
|
return this._fileApiUrl;
|
|
252
203
|
}
|
|
253
|
-
|
|
254
204
|
getLandingPageUrl() {
|
|
255
205
|
return this._emsLandingPageUrl;
|
|
256
206
|
}
|
|
257
|
-
|
|
258
207
|
sanitizeHtml(html) {
|
|
259
208
|
return this._sanitizer(html);
|
|
260
209
|
}
|
|
261
|
-
|
|
262
210
|
extendUrlWithParams(url) {
|
|
263
211
|
return unescapeTemplateVars(extendUrl(url, {
|
|
264
212
|
query: this._queryParams
|
|
265
213
|
}));
|
|
266
214
|
}
|
|
267
|
-
|
|
268
215
|
async findFileLayerById(id) {
|
|
269
216
|
const fileLayers = await this.getFileLayers();
|
|
270
|
-
|
|
271
217
|
for (let i = 0; i < fileLayers.length; i++) {
|
|
272
218
|
if (fileLayers[i].hasId(id)) {
|
|
273
219
|
return fileLayers[i];
|
|
274
220
|
}
|
|
275
221
|
}
|
|
276
222
|
}
|
|
277
|
-
|
|
278
223
|
async findTMSServiceById(id) {
|
|
279
224
|
const tmsServices = await this.getTMSServices();
|
|
280
|
-
|
|
281
225
|
for (let i = 0; i < tmsServices.length; i++) {
|
|
282
226
|
if (tmsServices[i].hasId(id)) {
|
|
283
227
|
return tmsServices[i];
|
|
284
228
|
}
|
|
285
229
|
}
|
|
286
230
|
}
|
|
287
|
-
|
|
288
231
|
_getEmsVersion(version) {
|
|
289
232
|
const userVersion = _semver.default.valid(_semver.default.coerce(version));
|
|
290
|
-
|
|
291
233
|
const semverVersion = userVersion ? userVersion : _semver.default.coerce(DEFAULT_EMS_VERSION);
|
|
292
|
-
|
|
293
234
|
if (semverVersion) {
|
|
294
235
|
return `v${_semver.default.major(semverVersion)}.${_semver.default.minor(semverVersion)}`;
|
|
295
236
|
} else {
|
|
296
237
|
throw new Error(`Invalid version: ${version}`);
|
|
297
238
|
}
|
|
298
239
|
}
|
|
299
|
-
|
|
300
240
|
_fetchWithTimeout(url) {
|
|
301
241
|
return new Promise((resolve, reject) => {
|
|
302
242
|
const timer = setTimeout(() => reject(new Error(`Request to ${url} timed out`)), this.EMS_LOAD_TIMEOUT);
|
|
303
|
-
|
|
304
243
|
this._fetchFunction(url).then(response => {
|
|
305
244
|
clearTimeout(timer);
|
|
306
245
|
resolve(response);
|
|
@@ -310,15 +249,12 @@ class EMSClient {
|
|
|
310
249
|
});
|
|
311
250
|
});
|
|
312
251
|
}
|
|
313
|
-
|
|
314
252
|
async _getManifestWithParams(url) {
|
|
315
253
|
const extendedUrl = this.extendUrlWithParams(url);
|
|
316
254
|
return await this.getManifest(extendedUrl);
|
|
317
255
|
}
|
|
318
|
-
|
|
319
256
|
_invalidateSettings() {
|
|
320
257
|
this._cache.reset();
|
|
321
|
-
|
|
322
258
|
this._getMainCatalog = _lodash.default.once(async () => {
|
|
323
259
|
// Preserve manifestServiceUrl parameter for backwards compatibility with EMS v7.2
|
|
324
260
|
if (this._manifestServiceUrl) {
|
|
@@ -327,21 +263,18 @@ class EMSClient {
|
|
|
327
263
|
return await this._getManifestWithParams(this._manifestServiceUrl);
|
|
328
264
|
} else {
|
|
329
265
|
const services = [];
|
|
330
|
-
|
|
331
266
|
if (this._tileApiUrl) {
|
|
332
267
|
services.push({
|
|
333
268
|
type: 'tms',
|
|
334
269
|
manifest: (0, _utils.toAbsoluteUrl)(this._tileApiUrl, `${this._emsVersion}/manifest`)
|
|
335
270
|
});
|
|
336
271
|
}
|
|
337
|
-
|
|
338
272
|
if (this._fileApiUrl) {
|
|
339
273
|
services.push({
|
|
340
274
|
type: 'file',
|
|
341
275
|
manifest: (0, _utils.toAbsoluteUrl)(this._fileApiUrl, `${this._emsVersion}/manifest`)
|
|
342
276
|
});
|
|
343
277
|
}
|
|
344
|
-
|
|
345
278
|
return {
|
|
346
279
|
services: services
|
|
347
280
|
};
|
|
@@ -350,30 +283,27 @@ class EMSClient {
|
|
|
350
283
|
this._getDefaultTMSCatalog = _lodash.default.once(async () => {
|
|
351
284
|
const catalogue = await this._getMainCatalog();
|
|
352
285
|
const firstService = catalogue.services.find(service => service.type === 'tms');
|
|
353
|
-
|
|
354
286
|
if (!firstService) {
|
|
355
287
|
return {
|
|
356
288
|
services: []
|
|
357
289
|
};
|
|
358
290
|
}
|
|
359
|
-
|
|
360
291
|
const url = this._proxyPath + firstService.manifest;
|
|
361
292
|
return await this.getManifest(url);
|
|
362
293
|
});
|
|
363
294
|
this._getDefaultFileCatalog = _lodash.default.once(async () => {
|
|
364
295
|
const catalogue = await this._getMainCatalog();
|
|
365
296
|
const firstService = catalogue.services.find(service => service.type === 'file');
|
|
366
|
-
|
|
367
297
|
if (!firstService) {
|
|
368
298
|
return {
|
|
369
299
|
layers: []
|
|
370
300
|
};
|
|
371
301
|
}
|
|
372
|
-
|
|
373
302
|
const url = this._proxyPath + firstService.manifest;
|
|
374
303
|
return await this.getManifest(url);
|
|
375
|
-
});
|
|
304
|
+
});
|
|
376
305
|
|
|
306
|
+
//Cache the actual instances of TMSService as these in turn cache sub-manifests for the style-files
|
|
377
307
|
this._loadTMSServices = _lodash.default.once(async () => {
|
|
378
308
|
const tmsManifest = await this._getDefaultTMSCatalog();
|
|
379
309
|
return tmsManifest.services.map(serviceConfig => new _tms_service.TMSService(serviceConfig, this, this._proxyPath));
|
|
@@ -383,7 +313,5 @@ class EMSClient {
|
|
|
383
313
|
return fileManifest.layers.map(layerConfig => new _file_layer.FileLayer(layerConfig, this, this._proxyPath));
|
|
384
314
|
});
|
|
385
315
|
}
|
|
386
|
-
|
|
387
316
|
}
|
|
388
|
-
|
|
389
317
|
exports.EMSClient = EMSClient;
|
|
@@ -4,19 +4,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.AbstractEmsService = void 0;
|
|
7
|
-
|
|
8
7
|
var _utils = require("./utils");
|
|
9
|
-
|
|
10
|
-
function
|
|
11
|
-
|
|
8
|
+
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; }
|
|
9
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
10
|
+
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); }
|
|
12
11
|
class AbstractEmsService {
|
|
13
12
|
constructor(config, emsClient, proxyPath) {
|
|
14
13
|
_defineProperty(this, "_emsClient", void 0);
|
|
15
|
-
|
|
16
14
|
_defineProperty(this, "_config", void 0);
|
|
17
|
-
|
|
18
15
|
_defineProperty(this, "_proxyPath", void 0);
|
|
19
|
-
|
|
20
16
|
_defineProperty(this, "_getAbsoluteUrl", url => {
|
|
21
17
|
if (/^https?:\/\//.test(url)) {
|
|
22
18
|
return url;
|
|
@@ -24,41 +20,31 @@ class AbstractEmsService {
|
|
|
24
20
|
return (0, _utils.toAbsoluteUrl)(this.getApiUrl(), url);
|
|
25
21
|
}
|
|
26
22
|
});
|
|
27
|
-
|
|
28
23
|
this._config = config;
|
|
29
24
|
this._emsClient = emsClient;
|
|
30
25
|
this._proxyPath = proxyPath;
|
|
31
26
|
}
|
|
32
|
-
|
|
33
27
|
getAttributions() {
|
|
34
28
|
return this._config.attribution.map(attribution => {
|
|
35
29
|
const url = this._emsClient.getValueInLanguage(attribution.url);
|
|
36
|
-
|
|
37
30
|
const label = this._emsClient.getValueInLanguage(attribution.label);
|
|
38
|
-
|
|
39
31
|
return {
|
|
40
32
|
url: url,
|
|
41
33
|
label: label
|
|
42
34
|
};
|
|
43
35
|
});
|
|
44
36
|
}
|
|
45
|
-
|
|
46
37
|
getMarkdownAttribution() {
|
|
47
38
|
const attributions = this._config.attribution.map(attribution => {
|
|
48
39
|
const url = this._emsClient.getValueInLanguage(attribution.url);
|
|
49
|
-
|
|
50
40
|
const label = this._emsClient.getValueInLanguage(attribution.label);
|
|
51
|
-
|
|
52
41
|
return `[${label}](${url})`;
|
|
53
42
|
});
|
|
54
|
-
|
|
55
43
|
return attributions.join('|');
|
|
56
44
|
}
|
|
45
|
+
|
|
57
46
|
/**
|
|
58
47
|
* Checks if url is absolute. If not, prepend the basePath.
|
|
59
48
|
*/
|
|
60
|
-
|
|
61
|
-
|
|
62
49
|
}
|
|
63
|
-
|
|
64
50
|
exports.AbstractEmsService = AbstractEmsService;
|