@elastic/ems-client 8.5.0 → 8.5.2
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/.buildkite/build.sh +0 -0
- package/.buildkite/pipeline.yml +3 -1
- package/.github/CODEOWNERS +2 -0
- package/.husky/pre-commit +1 -0
- package/.nvmrc +1 -1
- package/CHANGELOG.md +19 -2
- package/CONTRIBUTING.md +4 -5
- package/docs/openapi/Makefile +35 -0
- package/docs/openapi/README.md +41 -0
- package/docs/openapi/components/attribution.yaml +19 -0
- package/docs/openapi/components/examples/file_service_200.json +1 -0
- package/docs/openapi/components/examples/file_service_404.xml +1 -0
- package/docs/openapi/components/examples/tile_service_200.json +1 -0
- package/docs/openapi/components/examples/tile_service_404.html +10 -0
- package/docs/openapi/ems_file_service/bundled.json +533 -0
- package/docs/openapi/ems_file_service/bundled.yaml +347 -0
- package/docs/openapi/ems_file_service/entrypoint.yaml +152 -0
- package/docs/openapi/ems_tile_service/bundled.json +307 -0
- package/docs/openapi/ems_tile_service/bundled.yaml +195 -0
- package/docs/openapi/ems_tile_service/entrypoint.yaml +92 -0
- package/eslint.config.mjs +25 -0
- package/package.json +29 -29
- package/src/ems_client.ts +10 -2
- package/src/tms_service.ts +18 -12
- package/target/ems_client.d.ts +17 -16
- package/target/ems_client.js +318 -0
- package/target/ems_service.js +47 -0
- package/target/file_layer.d.ts +1 -1
- package/target/file_layer.js +176 -0
- package/target/index.js +16 -0
- package/target/node/ems_client.js +19 -13
- package/target/node/ems_service.js +8 -8
- package/target/node/file_layer.js +12 -13
- package/target/node/tms_service.js +43 -36
- package/target/node/utils.js +1 -1
- package/target/tms_service.d.ts +5 -5
- package/target/tms_service.js +409 -0
- package/target/utils.d.ts +3 -3
- package/target/utils.js +86 -0
- package/target/web/ems_client.js +32 -28
- package/target/web/ems_service.js +8 -9
- package/target/web/file_layer.js +23 -25
- package/target/web/tms_service.js +50 -55
- package/target/web/utils.js +1 -1
- package/test/__snapshots__/ems_client.test.ts.snap +24 -24
- package/test/ems_client_util.ts +1 -1
- package/.eslintignore +0 -1
- package/.eslintrc +0 -18
|
@@ -0,0 +1,409 @@
|
|
|
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.d.ts
CHANGED
|
@@ -6,8 +6,8 @@ import { ColorSpecification, DataDrivenPropertyValueSpecification, PropertyValue
|
|
|
6
6
|
* It also handles trailing slashes in tileApiUrl and fileApiUrl parameters.
|
|
7
7
|
*/
|
|
8
8
|
export declare function toAbsoluteUrl(host: string | undefined, path: string): string;
|
|
9
|
-
export
|
|
10
|
-
export
|
|
9
|
+
export type mbColorDefinition = PropertyValueSpecification<ColorSpecification> | DataDrivenPropertyValueSpecification<ColorSpecification>;
|
|
10
|
+
export type layerPaintProperty = {
|
|
11
11
|
'background-color'?: PropertyValueSpecification<ColorSpecification>;
|
|
12
12
|
'circle-color'?: DataDrivenPropertyValueSpecification<ColorSpecification>;
|
|
13
13
|
'circle-stroke-color'?: DataDrivenPropertyValueSpecification<ColorSpecification>;
|
|
@@ -20,6 +20,6 @@ export declare type layerPaintProperty = {
|
|
|
20
20
|
'text-color'?: DataDrivenPropertyValueSpecification<ColorSpecification>;
|
|
21
21
|
'text-halo-color'?: DataDrivenPropertyValueSpecification<ColorSpecification>;
|
|
22
22
|
};
|
|
23
|
-
export
|
|
23
|
+
export type blendMode = Parameters<ChromaStatic['blend']>[2] | 'mix';
|
|
24
24
|
export declare function desaturateColor(paintColor: mbColorDefinition): mbColorDefinition;
|
|
25
25
|
export declare function colorizeColor(sourceColor: mbColorDefinition, destColor: string, operation?: blendMode, percentage?: number): mbColorDefinition;
|
package/target/utils.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
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;
|