@elastic/ems-client 8.5.2 → 8.6.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.
@@ -1,176 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
4
- * or more contributor license agreements. Licensed under the Elastic License
5
- * 2.0; you may not use this file except in compliance with the Elastic License
6
- * 2.0.
7
- */
8
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
- if (k2 === undefined) k2 = k;
10
- var desc = Object.getOwnPropertyDescriptor(m, k);
11
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
- desc = { enumerable: true, get: function() { return m[k]; } };
13
- }
14
- Object.defineProperty(o, k2, desc);
15
- }) : (function(o, m, k, k2) {
16
- if (k2 === undefined) k2 = k;
17
- o[k2] = m[k];
18
- }));
19
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20
- Object.defineProperty(o, "default", { enumerable: true, value: v });
21
- }) : function(o, v) {
22
- o["default"] = v;
23
- });
24
- var __importStar = (this && this.__importStar) || function (mod) {
25
- if (mod && mod.__esModule) return mod;
26
- var result = {};
27
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
- __setModuleDefault(result, mod);
29
- return result;
30
- };
31
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
32
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
33
- return new (P || (P = Promise))(function (resolve, reject) {
34
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
35
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
36
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
37
- step((generator = generator.apply(thisArg, _arguments || [])).next());
38
- });
39
- };
40
- var __importDefault = (this && this.__importDefault) || function (mod) {
41
- return (mod && mod.__esModule) ? mod : { "default": mod };
42
- };
43
- Object.defineProperty(exports, "__esModule", { value: true });
44
- exports.FileLayer = exports.EMSFormatType = void 0;
45
- const url_1 = __importDefault(require("url"));
46
- const ems_service_1 = require("./ems_service");
47
- const topojson = __importStar(require("topojson-client"));
48
- var EMSFormatType;
49
- (function (EMSFormatType) {
50
- EMSFormatType["geojson"] = "geojson";
51
- EMSFormatType["topojson"] = "topojson";
52
- })(EMSFormatType || (exports.EMSFormatType = EMSFormatType = {}));
53
- class FileLayer extends ems_service_1.AbstractEmsService {
54
- constructor(config, emsClient, proxyPath) {
55
- super(config, emsClient, proxyPath);
56
- this._config = config;
57
- }
58
- getGeoJson() {
59
- return __awaiter(this, void 0, void 0, function* () {
60
- var _a;
61
- const cachedGeoJson = this._emsClient.getCachedGeoJson(this.getId());
62
- if (cachedGeoJson) {
63
- return cachedGeoJson;
64
- }
65
- const format = this.getDefaultFormatType();
66
- const fetchUrl = this.getDefaultFormatUrl();
67
- let geojson;
68
- const fetchedJson = yield this._emsClient.getManifest(fetchUrl);
69
- if (fetchedJson) {
70
- if (format === 'geojson') {
71
- geojson = fetchedJson;
72
- }
73
- else if (format === 'topojson') {
74
- const meta = this.getDefaultFormatMeta();
75
- const featureCollectionPath = (_a = meta === null || meta === void 0 ? void 0 : meta.feature_collection_path) !== null && _a !== void 0 ? _a : 'data';
76
- // @ts-expect-error see https://github.com/DefinitelyTyped/DefinitelyTyped/pull/52156
77
- geojson = topojson.feature(fetchedJson, featureCollectionPath);
78
- }
79
- else {
80
- return;
81
- }
82
- this._emsClient.cacheGeoJson(this.getId(), geojson);
83
- return geojson;
84
- }
85
- return;
86
- });
87
- }
88
- getFields() {
89
- return this._config.fields;
90
- }
91
- getFieldsInLanguage() {
92
- return this.getFields().map((field) => {
93
- return {
94
- type: field.type,
95
- name: field.id,
96
- description: this._emsClient.getValueInLanguage(field.label),
97
- };
98
- });
99
- }
100
- getDisplayName() {
101
- const layerName = this._emsClient.getValueInLanguage(this._config.layer_name);
102
- return layerName ? layerName : '';
103
- }
104
- getId() {
105
- return this._config.layer_id;
106
- }
107
- hasId(id) {
108
- const matchesLegacyId = this._config.legacy_ids.indexOf(id) >= 0;
109
- return this._config.layer_id === id || matchesLegacyId;
110
- }
111
- getEMSHotLink() {
112
- const landingPageString = this._emsClient.getLandingPageUrl();
113
- const urlObject = url_1.default.parse(landingPageString, true);
114
- urlObject.hash = `file/${this.getId()}`;
115
- urlObject.query = Object.assign(Object.assign({}, urlObject.query), { locale: this._emsClient.getLocale() });
116
- return url_1.default.format(urlObject);
117
- }
118
- getDefaultFormatType() {
119
- const format = this._getDefaultFormat();
120
- return format.type;
121
- }
122
- getFormatOfType(type) {
123
- const format = this._getFormatOfType(type);
124
- return format.type;
125
- }
126
- getDefaultFormatMeta() {
127
- const format = this._getDefaultFormat();
128
- return this._getFormatMeta(format);
129
- }
130
- getFormatOfTypeMeta(type) {
131
- const format = this._getFormatOfType(type);
132
- return this._getFormatMeta(format);
133
- }
134
- getDefaultFormatUrl() {
135
- const format = this._getDefaultFormat();
136
- return this._getFormatUrl(format);
137
- }
138
- getFormatOfTypeUrl(type) {
139
- const format = this._getFormatOfType(type);
140
- return this._getFormatUrl(format);
141
- }
142
- getCreatedAt() {
143
- return this._config.created_at;
144
- }
145
- getApiUrl() {
146
- return this._emsClient.getFileApiUrl();
147
- }
148
- _getFormatUrl(format) {
149
- const url = this._proxyPath + this._getAbsoluteUrl(format.url);
150
- return this._emsClient.extendUrlWithParams(url);
151
- }
152
- _getFormatMeta(format) {
153
- if ('meta' in format) {
154
- return format.meta;
155
- }
156
- else {
157
- return;
158
- }
159
- }
160
- _getDefaultFormat() {
161
- const defaultFormat = this._config.formats.find((format) => {
162
- return format.legacy_default;
163
- });
164
- if (defaultFormat) {
165
- return defaultFormat;
166
- }
167
- return this._config.formats[0];
168
- }
169
- _getFormatOfType(type) {
170
- const requestedFormat = this._config.formats.find((format) => {
171
- return format.type === type;
172
- });
173
- return requestedFormat || this._getDefaultFormat();
174
- }
175
- }
176
- exports.FileLayer = FileLayer;
package/target/index.js DELETED
@@ -1,16 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
4
- * or more contributor license agreements. Licensed under the Elastic License
5
- * 2.0; you may not use this file except in compliance with the Elastic License
6
- * 2.0.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.TMSService = exports.FileLayer = exports.LATEST_API_URL_PATH = exports.EMSClient = void 0;
10
- var ems_client_1 = require("./ems_client");
11
- Object.defineProperty(exports, "EMSClient", { enumerable: true, get: function () { return ems_client_1.EMSClient; } });
12
- Object.defineProperty(exports, "LATEST_API_URL_PATH", { enumerable: true, get: function () { return ems_client_1.LATEST_API_URL_PATH; } });
13
- var file_layer_1 = require("./file_layer");
14
- Object.defineProperty(exports, "FileLayer", { enumerable: true, get: function () { return file_layer_1.FileLayer; } });
15
- var tms_service_1 = require("./tms_service");
16
- Object.defineProperty(exports, "TMSService", { enumerable: true, get: function () { return tms_service_1.TMSService; } });
@@ -1,409 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
4
- * or more contributor license agreements. Licensed under the Elastic License
5
- * 2.0; you may not use this file except in compliance with the Elastic License
6
- * 2.0.
7
- */
8
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
- return new (P || (P = Promise))(function (resolve, reject) {
11
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
- step((generator = generator.apply(thisArg, _arguments || [])).next());
15
- });
16
- };
17
- var __importDefault = (this && this.__importDefault) || function (mod) {
18
- return (mod && mod.__esModule) ? mod : { "default": mod };
19
- };
20
- Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.TMSService = void 0;
22
- const lodash_1 = __importDefault(require("lodash"));
23
- const ems_service_1 = require("./ems_service");
24
- const utils_1 = require("./utils");
25
- class TMSService extends ems_service_1.AbstractEmsService {
26
- constructor(config, emsClient, proxyPath) {
27
- super(config, emsClient, proxyPath);
28
- this._getRasterStyleJson = lodash_1.default.once(() => __awaiter(this, void 0, void 0, function* () {
29
- const rasterUrl = this._getStyleUrlForLocale('raster');
30
- if (rasterUrl) {
31
- const url = this._proxyPath + this._getAbsoluteUrl(rasterUrl);
32
- return this._emsClient.getManifest(this._emsClient.extendUrlWithParams(url));
33
- }
34
- else {
35
- return;
36
- }
37
- }));
38
- this._getVectorStyleJsonRaw = lodash_1.default.once(() => __awaiter(this, void 0, void 0, function* () {
39
- const vectorUrl = this._getStyleUrlForLocale('vector');
40
- if (vectorUrl) {
41
- const url = this._proxyPath + this._getAbsoluteUrl(vectorUrl);
42
- const vectorJson = yield this._emsClient.getManifest(this._emsClient.extendUrlWithParams(url));
43
- return Object.assign({}, vectorJson);
44
- }
45
- else {
46
- return;
47
- }
48
- }));
49
- this._getVectorStyleJsonInlined = lodash_1.default.once(() => __awaiter(this, void 0, void 0, function* () {
50
- var _a;
51
- const vectorJson = yield this._getVectorStyleJsonRaw();
52
- if (vectorJson) {
53
- const inlinedSources = {};
54
- const { sources } = vectorJson;
55
- for (const sourceName of Object.getOwnPropertyNames(sources)) {
56
- const { url } = sources[sourceName];
57
- if (url) {
58
- const sourceUrl = this._proxyPath + this._getAbsoluteUrl(url);
59
- const extendedUrl = this._emsClient.extendUrlWithParams(sourceUrl);
60
- const sourceJson = yield this._emsClient.getManifest(extendedUrl);
61
- const tiles = (_a = sourceJson === null || sourceJson === void 0 ? void 0 : sourceJson.tiles) === null || _a === void 0 ? void 0 : _a.map((tileUrl) => {
62
- const directUrl = this._proxyPath + this._getAbsoluteUrl(tileUrl);
63
- return this._emsClient.extendUrlWithParams(directUrl);
64
- });
65
- inlinedSources[sourceName] = Object.assign(Object.assign({}, sourceJson), { type: 'vector', tiles });
66
- }
67
- }
68
- return Object.assign(Object.assign({}, vectorJson), { sources: inlinedSources, sprite: yield this._getSpriteSheetRootPath(), glyphs: yield this._getUrlTemplateForGlyphs() });
69
- }
70
- else {
71
- return;
72
- }
73
- }));
74
- this._config = config;
75
- }
76
- /*
77
- This method returns an array of objects with the layers and the new
78
- layout['text-field'] to apply using map.setLayoutProperty
79
- */
80
- static transformLanguageProperty(layer, lang) {
81
- const supportedLang = this.SupportedLanguages.find((l) => l.key === lang);
82
- if (layer.type === 'symbol' && layer.layout !== undefined && supportedLang !== undefined) {
83
- const omtLang = supportedLang.omt;
84
- const textField = layer.layout['text-field'];
85
- if (textField && typeof textField === 'string') {
86
- return TMSService._getTextField(textField, omtLang);
87
- }
88
- }
89
- return;
90
- }
91
- /*
92
- This method returns an array of objects per layer, containing a list of
93
- properties with new colors to apply using map.setPaintProperty
94
- */
95
- static transformColorProperties(layer, color, operation, percentage) {
96
- if (['background', 'fill', 'line', 'symbol'].indexOf(layer.type) !== -1 && layer.paint) {
97
- const paint = layer.paint;
98
- if (layer.type === 'symbol' && Object.keys(paint).length === 0) {
99
- paint['text-color'] = 'rgb(0,0,0)';
100
- }
101
- const types = Object.keys(paint).filter((key) => {
102
- return ([
103
- 'background-color',
104
- 'circle-color',
105
- 'circle-stroke-color',
106
- 'fill-color',
107
- 'fill-extrusion-color',
108
- 'fill-outline-color',
109
- 'icon-color',
110
- 'icon-halo-color',
111
- 'line-color',
112
- 'text-color',
113
- 'text-halo-color',
114
- ].indexOf(key) !== -1);
115
- });
116
- return types.map((type) => {
117
- const paintColor = paint[type];
118
- return {
119
- property: type,
120
- color: paintColor && color
121
- ? (0, utils_1.colorizeColor)(paintColor, color, operation, percentage)
122
- : paintColor,
123
- };
124
- });
125
- }
126
- else {
127
- return [];
128
- }
129
- }
130
- static _getTextField(label, lang) {
131
- // Capture {name:xx} labels
132
- const labelMatch = label.match(/\{name([:_])(.{2})\}/);
133
- if (labelMatch && labelMatch[1] != lang) {
134
- // Only apply if the languages are different
135
- return ['coalesce', ['get', `name:${lang}`], ['get', `name${labelMatch[1]}${labelMatch[2]}`]];
136
- }
137
- else if (label.includes('latin') && label.includes('nonlatin')) {
138
- // Capture the common pattern {name:latin}\n{name:nonlatin}
139
- return [
140
- 'coalesce',
141
- ['get', `name:${lang}`],
142
- ['concat', ['get', 'name:latin'], '\n', ['get', 'name:nonlatin']],
143
- ];
144
- }
145
- // If no case is found, return the input label
146
- return label;
147
- }
148
- getDefaultRasterStyle() {
149
- return __awaiter(this, void 0, void 0, function* () {
150
- const tileJson = yield this._getRasterStyleJson();
151
- if (tileJson) {
152
- const tiles = tileJson.tiles.map((tile) => this._proxyPath + this._getAbsoluteUrl(tile));
153
- return Object.assign(Object.assign({}, tileJson), { tiles });
154
- }
155
- else {
156
- return;
157
- }
158
- });
159
- }
160
- getUrlTemplate() {
161
- return __awaiter(this, void 0, void 0, function* () {
162
- const tileJson = yield this._getRasterStyleJson();
163
- if (tileJson) {
164
- const directUrl = this._proxyPath + this._getAbsoluteUrl(tileJson.tiles[0]);
165
- return this._emsClient.extendUrlWithParams(directUrl);
166
- }
167
- else {
168
- return '';
169
- }
170
- });
171
- }
172
- getUrlTemplateForVector(sourceId) {
173
- return __awaiter(this, void 0, void 0, function* () {
174
- var _a, _b;
175
- const tileJson = yield this._getVectorStyleJsonInlined();
176
- const url = (_b = (_a = tileJson === null || tileJson === void 0 ? void 0 : tileJson.sources[sourceId]) === null || _a === void 0 ? void 0 : _a.tiles) === null || _b === void 0 ? void 0 : _b.pop();
177
- if (url) {
178
- const directUrl = this._proxyPath + this._getAbsoluteUrl(url);
179
- return this._emsClient.extendUrlWithParams(directUrl);
180
- }
181
- else {
182
- return '';
183
- }
184
- });
185
- }
186
- getVectorStyleSheet() {
187
- return __awaiter(this, void 0, void 0, function* () {
188
- return yield this._getVectorStyleJsonInlined();
189
- });
190
- }
191
- getVectorStyleSheetRaw() {
192
- return __awaiter(this, void 0, void 0, function* () {
193
- return yield this._getVectorStyleJsonRaw();
194
- });
195
- }
196
- getSpriteSheetMeta() {
197
- return __awaiter(this, arguments, void 0, function* (isRetina = false) {
198
- const metaUrl = yield this.getSpriteSheetJsonPath(isRetina);
199
- const spritePngs = yield this.getSpriteSheetPngPath(isRetina);
200
- if (metaUrl && spritePngs) {
201
- const metaUrlExtended = this._emsClient.extendUrlWithParams(metaUrl);
202
- const jsonMeta = yield this._emsClient.getManifest(metaUrlExtended);
203
- return {
204
- png: spritePngs,
205
- json: jsonMeta,
206
- };
207
- }
208
- else {
209
- return;
210
- }
211
- });
212
- }
213
- getSpriteSheetJsonPath() {
214
- return __awaiter(this, arguments, void 0, function* (isRetina = false) {
215
- const spriteSheetRootPath = yield this._getSpriteSheetRootPath();
216
- if (spriteSheetRootPath) {
217
- const suffix = isRetina ? '@2x' : '';
218
- return spriteSheetRootPath + suffix + '.json';
219
- }
220
- else {
221
- return '';
222
- }
223
- });
224
- }
225
- getSpriteSheetPngPath() {
226
- return __awaiter(this, arguments, void 0, function* (isRetina = false) {
227
- const spriteSheetRootPath = yield this._getSpriteSheetRootPath();
228
- if (spriteSheetRootPath) {
229
- const suffix = isRetina ? '@2x' : '';
230
- return spriteSheetRootPath + suffix + '.png';
231
- }
232
- else {
233
- return '';
234
- }
235
- });
236
- }
237
- getDisplayName() {
238
- return this._emsClient.getValueInLanguage(this._config.name);
239
- }
240
- getMinZoom() {
241
- return __awaiter(this, arguments, void 0, function* (format = 'vector') {
242
- switch (format) {
243
- case 'vector': {
244
- const { sources } = (yield this._getVectorStyleJsonInlined()) || { sources: {} };
245
- return Math.min(...Object.values(sources)
246
- .map((s) => {
247
- return s && s instanceof Object && 'minzoom' in s ?
248
- s['minzoom'] :
249
- null;
250
- })
251
- .filter((minzoom) => Number.isFinite(minzoom)));
252
- }
253
- case 'raster': {
254
- const { minzoom } = (yield this._getRasterStyleJson()) || {};
255
- return minzoom;
256
- }
257
- default:
258
- return;
259
- }
260
- });
261
- }
262
- getMaxZoom() {
263
- return __awaiter(this, arguments, void 0, function* (format = 'vector') {
264
- switch (format) {
265
- case 'vector': {
266
- const { sources } = (yield this._getVectorStyleJsonInlined()) || { sources: {} };
267
- return Math.max(...Object.values(sources)
268
- .map((s) => {
269
- return s && s instanceof Object && 'maxzoom' in s ?
270
- s['maxzoom'] :
271
- null;
272
- })
273
- .filter((maxzoom) => Number.isFinite(maxzoom)));
274
- }
275
- case 'raster': {
276
- const { maxzoom } = (yield this._getRasterStyleJson()) || {};
277
- return maxzoom;
278
- }
279
- default:
280
- return;
281
- }
282
- });
283
- }
284
- getId() {
285
- return this._config.id;
286
- }
287
- hasId(id) {
288
- return this._config.id === id;
289
- }
290
- getApiUrl() {
291
- return this._emsClient.getTileApiUrl();
292
- }
293
- _getStyleUrlForLocale(formatType) {
294
- let vectorFormats = this._getFormats(formatType, this._emsClient.getLocale());
295
- if (!vectorFormats.length) {
296
- //fallback to default locale
297
- vectorFormats = this._getFormats(formatType, this._emsClient.getDefaultLocale());
298
- }
299
- if (!vectorFormats.length) {
300
- throw new Error(`Cannot find ${formatType} tile layer for locale ${this._emsClient.getLocale()} or ${this._emsClient.getDefaultLocale()}`);
301
- }
302
- const defaultStyle = vectorFormats[0];
303
- if (defaultStyle && Object.prototype.hasOwnProperty.call(defaultStyle, 'url')) {
304
- return defaultStyle.url;
305
- }
306
- }
307
- _getFormats(formatType, locale) {
308
- return this._config.formats.filter((format) => format.locale === locale && format.format === formatType);
309
- }
310
- _getSpriteSheetRootPath() {
311
- return __awaiter(this, void 0, void 0, function* () {
312
- const vectorStyleJson = yield this._getVectorStyleJsonRaw();
313
- if (vectorStyleJson === null || vectorStyleJson === void 0 ? void 0 : vectorStyleJson.sprite) {
314
- return this._proxyPath + this._getAbsoluteUrl(vectorStyleJson.sprite);
315
- }
316
- else {
317
- return '';
318
- }
319
- });
320
- }
321
- _getUrlTemplateForGlyphs() {
322
- return __awaiter(this, void 0, void 0, function* () {
323
- const vectorStyleJson = yield this._getVectorStyleJsonRaw();
324
- if (vectorStyleJson === null || vectorStyleJson === void 0 ? void 0 : vectorStyleJson.glyphs) {
325
- return this._proxyPath + this._getAbsoluteUrl(vectorStyleJson.glyphs);
326
- }
327
- else {
328
- return '';
329
- }
330
- });
331
- }
332
- }
333
- exports.TMSService = TMSService;
334
- /*
335
- List of supported languages with labels and OMT codes extracted
336
- from https://openmaptiles.org/languages
337
-
338
- Keys are values for i18.locale from Kibana settings
339
- and OMT codes for the rest.
340
- */
341
- TMSService.SupportedLanguages = [
342
- { key: 'ar', omt: 'ar' },
343
- { key: 'az', omt: 'az' },
344
- { key: 'be', omt: 'be' },
345
- { key: 'bg', omt: 'bg' },
346
- { key: 'br', omt: 'br' },
347
- { key: 'bs', omt: 'bs' },
348
- { key: 'ca', omt: 'ca' },
349
- { key: 'cs', omt: 'cs' },
350
- { key: 'cy', omt: 'cy' },
351
- { key: 'da', omt: 'da' },
352
- { key: 'de', omt: 'de' },
353
- { key: 'el', omt: 'el' },
354
- { key: 'en', omt: 'en' },
355
- { key: 'eo', omt: 'eo' },
356
- { key: 'es', omt: 'es' },
357
- { key: 'et', omt: 'et' },
358
- { key: 'fi', omt: 'fi' },
359
- { key: 'fr-fr', omt: 'fr' },
360
- { key: 'fy', omt: 'fy' },
361
- { key: 'ga', omt: 'ga' },
362
- { key: 'gd', omt: 'gd' },
363
- { key: 'he', omt: 'he' },
364
- { key: 'hi-in', omt: 'hi' },
365
- { key: 'hr', omt: 'hr' },
366
- { key: 'hu', omt: 'hu' },
367
- { key: 'hy', omt: 'hy' },
368
- { key: 'is', omt: 'is' },
369
- { key: 'it', omt: 'it' },
370
- { key: 'ja_kana', omt: 'ja_kana' },
371
- { key: 'ja_rm', omt: 'ja_rm' },
372
- { key: 'ja-jp', omt: 'ja' },
373
- { key: 'ka', omt: 'ka' },
374
- { key: 'kk', omt: 'kk' },
375
- { key: 'kn', omt: 'kn' },
376
- { key: 'ko_rm', omt: 'ko_rm' },
377
- { key: 'ko', omt: 'ko' },
378
- { key: 'la', omt: 'la' },
379
- { key: 'lb', omt: 'lb' },
380
- { key: 'lt', omt: 'lt' },
381
- { key: 'lv', omt: 'lv' },
382
- { key: 'mk', omt: 'mk' },
383
- { key: 'mt', omt: 'mt' },
384
- { key: 'nl', omt: 'nl' },
385
- { key: 'no', omt: 'no' },
386
- { key: 'pl', omt: 'pl' },
387
- { key: 'pt-pt', omt: 'pt' },
388
- { key: 'rm', omt: 'rm' },
389
- { key: 'ro', omt: 'ro' },
390
- { key: 'ru-ru', omt: 'ru' },
391
- { key: 'sk', omt: 'sk' },
392
- { key: 'sl', omt: 'sl' },
393
- { key: 'sq', omt: 'sq' },
394
- { key: 'sr-Ltn', omt: 'sr-Ltn' },
395
- { key: 'sr', omt: 'sr' },
396
- { key: 'sv', omt: 'sv' },
397
- { key: 'th', omt: 'th' },
398
- { key: 'tr', omt: 'tr' },
399
- { key: 'uk', omt: 'uk' },
400
- { key: 'zh-cn', omt: 'zh' },
401
- ];
402
- /*
403
- Suggested default operations for the different EMS styles
404
- */
405
- TMSService.colorOperationDefaults = [
406
- { style: 'road_map', operation: 'mix', percentage: 0.25 },
407
- { style: 'road_map_desaturated', operation: 'screen', percentage: 0.25 },
408
- { style: 'dark_map', operation: 'dodge', percentage: 0.25 },
409
- ];
package/target/utils.js DELETED
@@ -1,86 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
4
- * or more contributor license agreements. Licensed under the Elastic License
5
- * 2.0; you may not use this file except in compliance with the Elastic License
6
- * 2.0.
7
- */
8
- var __importDefault = (this && this.__importDefault) || function (mod) {
9
- return (mod && mod.__esModule) ? mod : { "default": mod };
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.colorizeColor = exports.desaturateColor = exports.toAbsoluteUrl = void 0;
13
- const chroma_js_1 = __importDefault(require("chroma-js"));
14
- /**
15
- * Resolves a target URL path relative to the host.
16
- * This is specifically useed by the Kibana proxy re-routing.
17
- * It also handles trailing slashes in tileApiUrl and fileApiUrl parameters.
18
- */
19
- function toAbsoluteUrl(host, path) {
20
- if (!host) {
21
- return path;
22
- }
23
- const hostEndWithSlash = host[host.length - 1] === '/';
24
- const pathStartsWithSlash = path[0] === '/';
25
- if (hostEndWithSlash === true && pathStartsWithSlash === true) {
26
- return host + path.slice(1);
27
- }
28
- else if (hostEndWithSlash !== pathStartsWithSlash) {
29
- return host + path;
30
- }
31
- else {
32
- return host + '/' + path;
33
- }
34
- }
35
- exports.toAbsoluteUrl = toAbsoluteUrl;
36
- /*
37
- Function to transform a maplibre color definition by a given function.
38
- */
39
- function transformColor(paintColor, func) {
40
- if (typeof paintColor == 'string') {
41
- const modifiedColor = func(paintColor);
42
- return `rgba(${modifiedColor.rgba().join(',')})`;
43
- }
44
- else if (typeof paintColor == 'object' &&
45
- 'stops' in paintColor &&
46
- Array.isArray(paintColor === null || paintColor === void 0 ? void 0 : paintColor.stops)) {
47
- const stops = paintColor['stops'].map((stop) => {
48
- const newColor = transformColor(stop[1], func);
49
- return [stop[0], newColor];
50
- });
51
- const newPaintColor = Object.assign({}, paintColor, { stops });
52
- return newPaintColor;
53
- }
54
- else
55
- return paintColor;
56
- }
57
- /*
58
- This is the function used to generate the current EMS desaturated roadmap
59
- */
60
- function desaturateColor(paintColor) {
61
- return transformColor(paintColor, (color) => {
62
- return (0, chroma_js_1.default)(color).desaturate(1.1).brighten(0.33);
63
- });
64
- }
65
- exports.desaturateColor = desaturateColor;
66
- /*
67
- Blends an original maplibre color definition with a destination
68
- color. Accepts different blending modes and an additional `mix`
69
- option that needs a percentage.
70
-
71
- More details:
72
-
73
- https://gka.github.io/chroma.js/#chroma-blend
74
- https://gka.github.io/chroma.js/#chroma-mix
75
- */
76
- function colorizeColor(sourceColor, destColor, operation = 'screen', percentage = 0.5) {
77
- return transformColor(sourceColor, (color) => {
78
- if (operation !== 'mix') {
79
- return chroma_js_1.default.blend((0, chroma_js_1.default)(color), destColor, operation);
80
- }
81
- else {
82
- return chroma_js_1.default.mix((0, chroma_js_1.default)(color), destColor, percentage);
83
- }
84
- });
85
- }
86
- exports.colorizeColor = colorizeColor;