@elastic/ems-client 8.6.3 → 8.8.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,29 +1,3 @@
1
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
3
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
- function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
5
- function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
6
- function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
7
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
8
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
9
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
10
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
11
- function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
12
- function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
13
- function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
14
- function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
15
- function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
16
- function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
17
- function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
18
- function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
19
- function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
20
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
21
- function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
22
- function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
23
- function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
24
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
25
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
26
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
27
1
  /*
28
2
  * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
29
3
  * or more contributor license agreements. Licensed under the Elastic License
@@ -32,913 +6,503 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
32
6
  */
33
7
 
34
8
  import _ from 'lodash';
9
+ import { DataDrivenPropertyValueSpecification, FormattedSpecification, LayerSpecification, StyleSpecification, VectorSourceSpecification } from 'maplibre-gl';
10
+ import { EMSClient, EmsTmsFormat, TMSServiceConfig } from './ems_client';
35
11
  import { AbstractEmsService } from './ems_service';
36
- import { colorizeColor } from './utils';
37
- export var TMSService = /*#__PURE__*/function (_AbstractEmsService) {
38
- function TMSService(config, emsClient, proxyPath) {
39
- var _this;
40
- _classCallCheck(this, TMSService);
41
- _this = _callSuper(this, TMSService, [config, emsClient, proxyPath]);
42
- _defineProperty(_this, "_config", void 0);
43
- _defineProperty(_this, "_getRasterStyleJson", _.once(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
44
- var rasterUrl, url;
45
- return _regeneratorRuntime().wrap(function _callee$(_context) {
46
- while (1) switch (_context.prev = _context.next) {
47
- case 0:
48
- rasterUrl = _this._getStyleUrlForLocale('raster');
49
- if (!rasterUrl) {
50
- _context.next = 6;
51
- break;
52
- }
53
- url = _this._proxyPath + _this._getAbsoluteUrl(rasterUrl);
54
- return _context.abrupt("return", _this._emsClient.getManifest(_this._emsClient.extendUrlWithParams(url)));
55
- case 6:
56
- return _context.abrupt("return");
57
- case 7:
58
- case "end":
59
- return _context.stop();
60
- }
61
- }, _callee);
62
- }))));
63
- _defineProperty(_this, "_getVectorStyleJsonRaw", _.once(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
64
- var vectorUrl, url, vectorJson;
65
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
66
- while (1) switch (_context2.prev = _context2.next) {
67
- case 0:
68
- vectorUrl = _this._getStyleUrlForLocale('vector');
69
- if (!vectorUrl) {
70
- _context2.next = 9;
71
- break;
72
- }
73
- url = _this._proxyPath + _this._getAbsoluteUrl(vectorUrl);
74
- _context2.next = 5;
75
- return _this._emsClient.getManifest(_this._emsClient.extendUrlWithParams(url));
76
- case 5:
77
- vectorJson = _context2.sent;
78
- return _context2.abrupt("return", _objectSpread({}, vectorJson));
79
- case 9:
80
- return _context2.abrupt("return");
81
- case 10:
82
- case "end":
83
- return _context2.stop();
84
- }
85
- }, _callee2);
86
- }))));
87
- _defineProperty(_this, "_getVectorStyleJsonInlined", _.once(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
88
- var vectorJson, inlinedSources, sources, _iterator, _step, _sourceName, url, _sourceJson$tiles, sourceUrl, extendedUrl, sourceJson, tiles;
89
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
90
- while (1) switch (_context3.prev = _context3.next) {
91
- case 0:
92
- _context3.next = 2;
93
- return _this._getVectorStyleJsonRaw();
94
- case 2:
95
- vectorJson = _context3.sent;
96
- if (!vectorJson) {
97
- _context3.next = 44;
98
- break;
99
- }
100
- inlinedSources = {};
101
- sources = vectorJson.sources;
102
- _iterator = _createForOfIteratorHelper(Object.getOwnPropertyNames(sources));
103
- _context3.prev = 7;
104
- _iterator.s();
105
- case 9:
106
- if ((_step = _iterator.n()).done) {
107
- _context3.next = 22;
108
- break;
109
- }
110
- _sourceName = _step.value;
111
- url = sources[_sourceName].url;
112
- if (!url) {
113
- _context3.next = 20;
114
- break;
115
- }
116
- sourceUrl = _this._proxyPath + _this._getAbsoluteUrl(url);
117
- extendedUrl = _this._emsClient.extendUrlWithParams(sourceUrl);
118
- _context3.next = 17;
119
- return _this._emsClient.getManifest(extendedUrl);
120
- case 17:
121
- sourceJson = _context3.sent;
122
- tiles = sourceJson === null || sourceJson === void 0 || (_sourceJson$tiles = sourceJson.tiles) === null || _sourceJson$tiles === void 0 ? void 0 : _sourceJson$tiles.map(function (tileUrl) {
123
- var directUrl = _this._proxyPath + _this._getAbsoluteUrl(tileUrl);
124
- return _this._emsClient.extendUrlWithParams(directUrl);
125
- });
126
- inlinedSources[_sourceName] = _objectSpread(_objectSpread({}, sourceJson), {}, {
127
- type: 'vector',
128
- tiles: tiles
129
- });
130
- case 20:
131
- _context3.next = 9;
132
- break;
133
- case 22:
134
- _context3.next = 27;
135
- break;
136
- case 24:
137
- _context3.prev = 24;
138
- _context3.t0 = _context3["catch"](7);
139
- _iterator.e(_context3.t0);
140
- case 27:
141
- _context3.prev = 27;
142
- _iterator.f();
143
- return _context3.finish(27);
144
- case 30:
145
- _context3.t1 = _objectSpread;
146
- _context3.t2 = _objectSpread({}, vectorJson);
147
- _context3.t3 = {};
148
- _context3.t4 = inlinedSources;
149
- _context3.next = 36;
150
- return _this._getSpriteSheetRootPath();
151
- case 36:
152
- _context3.t5 = _context3.sent;
153
- _context3.next = 39;
154
- return _this._getUrlTemplateForGlyphs();
155
- case 39:
156
- _context3.t6 = _context3.sent;
157
- _context3.t7 = {
158
- sources: _context3.t4,
159
- sprite: _context3.t5,
160
- glyphs: _context3.t6
161
- };
162
- return _context3.abrupt("return", (0, _context3.t1)(_context3.t2, _context3.t3, _context3.t7));
163
- case 44:
164
- return _context3.abrupt("return");
165
- case 45:
166
- case "end":
167
- return _context3.stop();
168
- }
169
- }, _callee3, null, [[7, 24, 27, 30]]);
170
- }))));
171
- _this._config = config;
172
- return _this;
173
- }
12
+ import { layerPaintProperty, colorizeColor, blendMode, mbColorDefinition } from './utils';
13
+ export class TMSService extends AbstractEmsService {
14
+ /*
15
+ List of supported languages with labels and OMT codes extracted
16
+ from https://openmaptiles.org/languages
17
+ Keys are values for i18.locale from Kibana settings
18
+ and OMT codes for the rest.
19
+ */
20
+ static SupportedLanguages = [{
21
+ key: 'ar',
22
+ omt: 'ar'
23
+ }, {
24
+ key: 'az',
25
+ omt: 'az'
26
+ }, {
27
+ key: 'be',
28
+ omt: 'be'
29
+ }, {
30
+ key: 'bg',
31
+ omt: 'bg'
32
+ }, {
33
+ key: 'br',
34
+ omt: 'br'
35
+ }, {
36
+ key: 'bs',
37
+ omt: 'bs'
38
+ }, {
39
+ key: 'ca',
40
+ omt: 'ca'
41
+ }, {
42
+ key: 'cs',
43
+ omt: 'cs'
44
+ }, {
45
+ key: 'cy',
46
+ omt: 'cy'
47
+ }, {
48
+ key: 'da',
49
+ omt: 'da'
50
+ }, {
51
+ key: 'de',
52
+ omt: 'de'
53
+ }, {
54
+ key: 'el',
55
+ omt: 'el'
56
+ }, {
57
+ key: 'en',
58
+ omt: 'en'
59
+ }, {
60
+ key: 'eo',
61
+ omt: 'eo'
62
+ }, {
63
+ key: 'es',
64
+ omt: 'es'
65
+ }, {
66
+ key: 'et',
67
+ omt: 'et'
68
+ }, {
69
+ key: 'fi',
70
+ omt: 'fi'
71
+ }, {
72
+ key: 'fr-fr',
73
+ omt: 'fr'
74
+ }, {
75
+ key: 'fy',
76
+ omt: 'fy'
77
+ }, {
78
+ key: 'ga',
79
+ omt: 'ga'
80
+ }, {
81
+ key: 'gd',
82
+ omt: 'gd'
83
+ }, {
84
+ key: 'he',
85
+ omt: 'he'
86
+ }, {
87
+ key: 'hi-in',
88
+ omt: 'hi'
89
+ }, {
90
+ key: 'hr',
91
+ omt: 'hr'
92
+ }, {
93
+ key: 'hu',
94
+ omt: 'hu'
95
+ }, {
96
+ key: 'hy',
97
+ omt: 'hy'
98
+ }, {
99
+ key: 'is',
100
+ omt: 'is'
101
+ }, {
102
+ key: 'it',
103
+ omt: 'it'
104
+ }, {
105
+ key: 'ja_kana',
106
+ omt: 'ja_kana'
107
+ }, {
108
+ key: 'ja_rm',
109
+ omt: 'ja_rm'
110
+ }, {
111
+ key: 'ja-jp',
112
+ omt: 'ja'
113
+ }, {
114
+ key: 'ka',
115
+ omt: 'ka'
116
+ }, {
117
+ key: 'kk',
118
+ omt: 'kk'
119
+ }, {
120
+ key: 'kn',
121
+ omt: 'kn'
122
+ }, {
123
+ key: 'ko_rm',
124
+ omt: 'ko_rm'
125
+ }, {
126
+ key: 'ko',
127
+ omt: 'ko'
128
+ }, {
129
+ key: 'la',
130
+ omt: 'la'
131
+ }, {
132
+ key: 'lb',
133
+ omt: 'lb'
134
+ }, {
135
+ key: 'lt',
136
+ omt: 'lt'
137
+ }, {
138
+ key: 'lv',
139
+ omt: 'lv'
140
+ }, {
141
+ key: 'mk',
142
+ omt: 'mk'
143
+ }, {
144
+ key: 'mt',
145
+ omt: 'mt'
146
+ }, {
147
+ key: 'nl',
148
+ omt: 'nl'
149
+ }, {
150
+ key: 'no',
151
+ omt: 'no'
152
+ }, {
153
+ key: 'pl',
154
+ omt: 'pl'
155
+ }, {
156
+ key: 'pt-pt',
157
+ omt: 'pt'
158
+ }, {
159
+ key: 'rm',
160
+ omt: 'rm'
161
+ }, {
162
+ key: 'ro',
163
+ omt: 'ro'
164
+ }, {
165
+ key: 'ru-ru',
166
+ omt: 'ru'
167
+ }, {
168
+ key: 'sk',
169
+ omt: 'sk'
170
+ }, {
171
+ key: 'sl',
172
+ omt: 'sl'
173
+ }, {
174
+ key: 'sq',
175
+ omt: 'sq'
176
+ }, {
177
+ key: 'sr-Ltn',
178
+ omt: 'sr-Ltn'
179
+ }, {
180
+ key: 'sr',
181
+ omt: 'sr'
182
+ }, {
183
+ key: 'sv',
184
+ omt: 'sv'
185
+ }, {
186
+ key: 'th',
187
+ omt: 'th'
188
+ }, {
189
+ key: 'tr',
190
+ omt: 'tr'
191
+ }, {
192
+ key: 'uk',
193
+ omt: 'uk'
194
+ }, {
195
+ key: 'zh-cn',
196
+ omt: 'zh'
197
+ }];
174
198
 
175
199
  /*
176
- This method returns an array of objects with the layers and the new
177
- layout['text-field'] to apply using map.setLayoutProperty
200
+ Suggested default operations for the different EMS styles
178
201
  */
179
- _inherits(TMSService, _AbstractEmsService);
180
- return _createClass(TMSService, [{
181
- key: "getDefaultRasterStyle",
182
- value: function () {
183
- var _getDefaultRasterStyle = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
184
- var _this2 = this;
185
- var tileJson, tiles;
186
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
187
- while (1) switch (_context4.prev = _context4.next) {
188
- case 0:
189
- _context4.next = 2;
190
- return this._getRasterStyleJson();
191
- case 2:
192
- tileJson = _context4.sent;
193
- if (!tileJson) {
194
- _context4.next = 8;
195
- break;
196
- }
197
- tiles = tileJson.tiles.map(function (tile) {
198
- return _this2._proxyPath + _this2._getAbsoluteUrl(tile);
199
- });
200
- return _context4.abrupt("return", _objectSpread(_objectSpread({}, tileJson), {
201
- tiles: tiles
202
- }));
203
- case 8:
204
- return _context4.abrupt("return");
205
- case 9:
206
- case "end":
207
- return _context4.stop();
208
- }
209
- }, _callee4, this);
210
- }));
211
- function getDefaultRasterStyle() {
212
- return _getDefaultRasterStyle.apply(this, arguments);
213
- }
214
- return getDefaultRasterStyle;
215
- }()
216
- }, {
217
- key: "getUrlTemplate",
218
- value: function () {
219
- var _getUrlTemplate = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
220
- var tileJson, directUrl;
221
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
222
- while (1) switch (_context5.prev = _context5.next) {
223
- case 0:
224
- _context5.next = 2;
225
- return this._getRasterStyleJson();
226
- case 2:
227
- tileJson = _context5.sent;
228
- if (!tileJson) {
229
- _context5.next = 8;
230
- break;
231
- }
232
- directUrl = this._proxyPath + this._getAbsoluteUrl(tileJson.tiles[0]);
233
- return _context5.abrupt("return", this._emsClient.extendUrlWithParams(directUrl));
234
- case 8:
235
- return _context5.abrupt("return", '');
236
- case 9:
237
- case "end":
238
- return _context5.stop();
239
- }
240
- }, _callee5, this);
241
- }));
242
- function getUrlTemplate() {
243
- return _getUrlTemplate.apply(this, arguments);
244
- }
245
- return getUrlTemplate;
246
- }()
247
- }, {
248
- key: "getUrlTemplateForVector",
249
- value: function () {
250
- var _getUrlTemplateForVector = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(sourceId) {
251
- var _tileJson$sources$sou;
252
- var tileJson, url, directUrl;
253
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
254
- while (1) switch (_context6.prev = _context6.next) {
255
- case 0:
256
- _context6.next = 2;
257
- return this._getVectorStyleJsonInlined();
258
- case 2:
259
- tileJson = _context6.sent;
260
- url = tileJson === null || tileJson === void 0 || (_tileJson$sources$sou = tileJson.sources[sourceId]) === null || _tileJson$sources$sou === void 0 || (_tileJson$sources$sou = _tileJson$sources$sou.tiles) === null || _tileJson$sources$sou === void 0 ? void 0 : _tileJson$sources$sou.pop();
261
- if (!url) {
262
- _context6.next = 9;
263
- break;
264
- }
265
- directUrl = this._proxyPath + this._getAbsoluteUrl(url);
266
- return _context6.abrupt("return", this._emsClient.extendUrlWithParams(directUrl));
267
- case 9:
268
- return _context6.abrupt("return", '');
269
- case 10:
270
- case "end":
271
- return _context6.stop();
272
- }
273
- }, _callee6, this);
274
- }));
275
- function getUrlTemplateForVector(_x) {
276
- return _getUrlTemplateForVector.apply(this, arguments);
277
- }
278
- return getUrlTemplateForVector;
279
- }()
280
- }, {
281
- key: "getVectorStyleSheet",
282
- value: function () {
283
- var _getVectorStyleSheet = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
284
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
285
- while (1) switch (_context7.prev = _context7.next) {
286
- case 0:
287
- _context7.next = 2;
288
- return this._getVectorStyleJsonInlined();
289
- case 2:
290
- return _context7.abrupt("return", _context7.sent);
291
- case 3:
292
- case "end":
293
- return _context7.stop();
294
- }
295
- }, _callee7, this);
296
- }));
297
- function getVectorStyleSheet() {
298
- return _getVectorStyleSheet.apply(this, arguments);
299
- }
300
- return getVectorStyleSheet;
301
- }()
302
- }, {
303
- key: "getVectorStyleSheetRaw",
304
- value: function () {
305
- var _getVectorStyleSheetRaw = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
306
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
307
- while (1) switch (_context8.prev = _context8.next) {
308
- case 0:
309
- _context8.next = 2;
310
- return this._getVectorStyleJsonRaw();
311
- case 2:
312
- return _context8.abrupt("return", _context8.sent);
313
- case 3:
314
- case "end":
315
- return _context8.stop();
316
- }
317
- }, _callee8, this);
318
- }));
319
- function getVectorStyleSheetRaw() {
320
- return _getVectorStyleSheetRaw.apply(this, arguments);
321
- }
322
- return getVectorStyleSheetRaw;
323
- }()
324
- }, {
325
- key: "getSpriteSheetMeta",
326
- value: function () {
327
- var _getSpriteSheetMeta = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
328
- var isRetina,
329
- metaUrl,
330
- spritePngs,
331
- metaUrlExtended,
332
- jsonMeta,
333
- _args9 = arguments;
334
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
335
- while (1) switch (_context9.prev = _context9.next) {
336
- case 0:
337
- isRetina = _args9.length > 0 && _args9[0] !== undefined ? _args9[0] : false;
338
- _context9.next = 3;
339
- return this.getSpriteSheetJsonPath(isRetina);
340
- case 3:
341
- metaUrl = _context9.sent;
342
- _context9.next = 6;
343
- return this.getSpriteSheetPngPath(isRetina);
344
- case 6:
345
- spritePngs = _context9.sent;
346
- if (!(metaUrl && spritePngs)) {
347
- _context9.next = 15;
348
- break;
349
- }
350
- metaUrlExtended = this._emsClient.extendUrlWithParams(metaUrl);
351
- _context9.next = 11;
352
- return this._emsClient.getManifest(metaUrlExtended);
353
- case 11:
354
- jsonMeta = _context9.sent;
355
- return _context9.abrupt("return", {
356
- png: spritePngs,
357
- json: jsonMeta
358
- });
359
- case 15:
360
- return _context9.abrupt("return");
361
- case 16:
362
- case "end":
363
- return _context9.stop();
364
- }
365
- }, _callee9, this);
366
- }));
367
- function getSpriteSheetMeta() {
368
- return _getSpriteSheetMeta.apply(this, arguments);
369
- }
370
- return getSpriteSheetMeta;
371
- }()
372
- }, {
373
- key: "getSpriteSheetJsonPath",
374
- value: function () {
375
- var _getSpriteSheetJsonPath = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
376
- var isRetina,
377
- spriteSheetRootPath,
378
- suffix,
379
- _args10 = arguments;
380
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
381
- while (1) switch (_context10.prev = _context10.next) {
382
- case 0:
383
- isRetina = _args10.length > 0 && _args10[0] !== undefined ? _args10[0] : false;
384
- _context10.next = 3;
385
- return this._getSpriteSheetRootPath();
386
- case 3:
387
- spriteSheetRootPath = _context10.sent;
388
- if (!spriteSheetRootPath) {
389
- _context10.next = 9;
390
- break;
391
- }
392
- suffix = isRetina ? '@2x' : '';
393
- return _context10.abrupt("return", spriteSheetRootPath + suffix + '.json');
394
- case 9:
395
- return _context10.abrupt("return", '');
396
- case 10:
397
- case "end":
398
- return _context10.stop();
399
- }
400
- }, _callee10, this);
401
- }));
402
- function getSpriteSheetJsonPath() {
403
- return _getSpriteSheetJsonPath.apply(this, arguments);
404
- }
405
- return getSpriteSheetJsonPath;
406
- }()
407
- }, {
408
- key: "getSpriteSheetPngPath",
409
- value: function () {
410
- var _getSpriteSheetPngPath = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
411
- var isRetina,
412
- spriteSheetRootPath,
413
- suffix,
414
- _args11 = arguments;
415
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
416
- while (1) switch (_context11.prev = _context11.next) {
417
- case 0:
418
- isRetina = _args11.length > 0 && _args11[0] !== undefined ? _args11[0] : false;
419
- _context11.next = 3;
420
- return this._getSpriteSheetRootPath();
421
- case 3:
422
- spriteSheetRootPath = _context11.sent;
423
- if (!spriteSheetRootPath) {
424
- _context11.next = 9;
425
- break;
426
- }
427
- suffix = isRetina ? '@2x' : '';
428
- return _context11.abrupt("return", spriteSheetRootPath + suffix + '.png');
429
- case 9:
430
- return _context11.abrupt("return", '');
431
- case 10:
432
- case "end":
433
- return _context11.stop();
434
- }
435
- }, _callee11, this);
436
- }));
437
- function getSpriteSheetPngPath() {
438
- return _getSpriteSheetPngPath.apply(this, arguments);
439
- }
440
- return getSpriteSheetPngPath;
441
- }()
202
+ static colorOperationDefaults = [{
203
+ style: 'road_map',
204
+ operation: 'mix',
205
+ percentage: 0.25
442
206
  }, {
443
- key: "getDisplayName",
444
- value: function getDisplayName() {
445
- return this._emsClient.getValueInLanguage(this._config.name);
446
- }
207
+ style: 'road_map_desaturated',
208
+ operation: 'screen',
209
+ percentage: 0.25
447
210
  }, {
448
- key: "getMinZoom",
449
- value: function () {
450
- var _getMinZoom = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
451
- var format,
452
- _ref4,
453
- sources,
454
- _ref5,
455
- minzoom,
456
- _args12 = arguments;
457
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
458
- while (1) switch (_context12.prev = _context12.next) {
459
- case 0:
460
- format = _args12.length > 0 && _args12[0] !== undefined ? _args12[0] : 'vector';
461
- _context12.t0 = format;
462
- _context12.next = _context12.t0 === 'vector' ? 4 : _context12.t0 === 'raster' ? 12 : 20;
463
- break;
464
- case 4:
465
- _context12.next = 6;
466
- return this._getVectorStyleJsonInlined();
467
- case 6:
468
- _context12.t1 = _context12.sent;
469
- if (_context12.t1) {
470
- _context12.next = 9;
471
- break;
472
- }
473
- _context12.t1 = {
474
- sources: {}
475
- };
476
- case 9:
477
- _ref4 = _context12.t1;
478
- sources = _ref4.sources;
479
- return _context12.abrupt("return", Math.min.apply(Math, _toConsumableArray(Object.values(sources).map(function (s) {
480
- return s && s instanceof Object && 'minzoom' in s ? s['minzoom'] : null;
481
- }).filter(function (minzoom) {
482
- return Number.isFinite(minzoom);
483
- }))));
484
- case 12:
485
- _context12.next = 14;
486
- return this._getRasterStyleJson();
487
- case 14:
488
- _context12.t2 = _context12.sent;
489
- if (_context12.t2) {
490
- _context12.next = 17;
491
- break;
492
- }
493
- _context12.t2 = {};
494
- case 17:
495
- _ref5 = _context12.t2;
496
- minzoom = _ref5.minzoom;
497
- return _context12.abrupt("return", minzoom);
498
- case 20:
499
- return _context12.abrupt("return");
500
- case 21:
501
- case "end":
502
- return _context12.stop();
503
- }
504
- }, _callee12, this);
505
- }));
506
- function getMinZoom() {
507
- return _getMinZoom.apply(this, arguments);
508
- }
509
- return getMinZoom;
510
- }()
511
- }, {
512
- key: "getMaxZoom",
513
- value: function () {
514
- var _getMaxZoom = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
515
- var format,
516
- _ref6,
517
- sources,
518
- _ref7,
519
- maxzoom,
520
- _args13 = arguments;
521
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
522
- while (1) switch (_context13.prev = _context13.next) {
523
- case 0:
524
- format = _args13.length > 0 && _args13[0] !== undefined ? _args13[0] : 'vector';
525
- _context13.t0 = format;
526
- _context13.next = _context13.t0 === 'vector' ? 4 : _context13.t0 === 'raster' ? 12 : 20;
527
- break;
528
- case 4:
529
- _context13.next = 6;
530
- return this._getVectorStyleJsonInlined();
531
- case 6:
532
- _context13.t1 = _context13.sent;
533
- if (_context13.t1) {
534
- _context13.next = 9;
535
- break;
536
- }
537
- _context13.t1 = {
538
- sources: {}
539
- };
540
- case 9:
541
- _ref6 = _context13.t1;
542
- sources = _ref6.sources;
543
- return _context13.abrupt("return", Math.max.apply(Math, _toConsumableArray(Object.values(sources).map(function (s) {
544
- return s && s instanceof Object && 'maxzoom' in s ? s['maxzoom'] : null;
545
- }).filter(function (maxzoom) {
546
- return Number.isFinite(maxzoom);
547
- }))));
548
- case 12:
549
- _context13.next = 14;
550
- return this._getRasterStyleJson();
551
- case 14:
552
- _context13.t2 = _context13.sent;
553
- if (_context13.t2) {
554
- _context13.next = 17;
555
- break;
556
- }
557
- _context13.t2 = {};
558
- case 17:
559
- _ref7 = _context13.t2;
560
- maxzoom = _ref7.maxzoom;
561
- return _context13.abrupt("return", maxzoom);
562
- case 20:
563
- return _context13.abrupt("return");
564
- case 21:
565
- case "end":
566
- return _context13.stop();
567
- }
568
- }, _callee13, this);
569
- }));
570
- function getMaxZoom() {
571
- return _getMaxZoom.apply(this, arguments);
572
- }
573
- return getMaxZoom;
574
- }()
211
+ style: 'dark_map',
212
+ operation: 'dodge',
213
+ percentage: 0.25
575
214
  }, {
576
- key: "getId",
577
- value: function getId() {
578
- return this._config.id;
579
- }
215
+ style: 'high_contrast',
216
+ operation: 'screen',
217
+ percentage: 0.25
580
218
  }, {
581
- key: "hasId",
582
- value: function hasId(id) {
583
- return this._config.id === id;
584
- }
219
+ style: 'road_map_desaturated_v9',
220
+ operation: 'screen',
221
+ percentage: 0.25
585
222
  }, {
586
- key: "getApiUrl",
587
- value: function getApiUrl() {
588
- return this._emsClient.getTileApiUrl();
223
+ style: 'dark_map_v9',
224
+ operation: 'dodge',
225
+ percentage: 0.25
226
+ }];
227
+ _config;
228
+ _getRasterStyleJson = _.once(async () => {
229
+ const rasterUrl = this._getStyleUrlForLocale('raster');
230
+ if (rasterUrl) {
231
+ const url = this._proxyPath + this._getAbsoluteUrl(rasterUrl);
232
+ return this._emsClient.getManifest(this._emsClient.extendUrlWithParams(url));
233
+ } else {
234
+ return;
589
235
  }
590
- }, {
591
- key: "_getStyleUrlForLocale",
592
- value: function _getStyleUrlForLocale(formatType) {
593
- var vectorFormats = this._getFormats(formatType, this._emsClient.getLocale());
594
- if (!vectorFormats.length) {
595
- //fallback to default locale
596
- vectorFormats = this._getFormats(formatType, this._emsClient.getDefaultLocale());
597
- }
598
- if (!vectorFormats.length) {
599
- throw new Error("Cannot find ".concat(formatType, " tile layer for locale ").concat(this._emsClient.getLocale(), " or ").concat(this._emsClient.getDefaultLocale()));
600
- }
601
- var defaultStyle = vectorFormats[0];
602
- if (defaultStyle && Object.prototype.hasOwnProperty.call(defaultStyle, 'url')) {
603
- return defaultStyle.url;
604
- }
236
+ });
237
+ _getVectorStyleJsonRaw = _.once(async () => {
238
+ const vectorUrl = this._getStyleUrlForLocale('vector');
239
+ if (vectorUrl) {
240
+ const url = this._proxyPath + this._getAbsoluteUrl(vectorUrl);
241
+ const vectorJson = await this._emsClient.getManifest(this._emsClient.extendUrlWithParams(url));
242
+ return {
243
+ ...vectorJson
244
+ };
245
+ } else {
246
+ return;
605
247
  }
606
- }, {
607
- key: "_getFormats",
608
- value: function _getFormats(formatType, locale) {
609
- return this._config.formats.filter(function (format) {
610
- return format.locale === locale && format.format === formatType;
611
- });
248
+ });
249
+ _getVectorStyleJsonInlined = _.once(async () => {
250
+ const vectorJson = await this._getVectorStyleJsonRaw();
251
+ if (vectorJson) {
252
+ const inlinedSources = {};
253
+ const {
254
+ sources
255
+ } = vectorJson;
256
+ for (const sourceName of Object.getOwnPropertyNames(sources)) {
257
+ const {
258
+ url
259
+ } = sources[sourceName];
260
+ if (url) {
261
+ const sourceUrl = this._proxyPath + this._getAbsoluteUrl(url);
262
+ const extendedUrl = this._emsClient.extendUrlWithParams(sourceUrl);
263
+ const sourceJson = await this._emsClient.getManifest(extendedUrl);
264
+ const tiles = sourceJson?.tiles?.map(tileUrl => {
265
+ const directUrl = this._proxyPath + this._getAbsoluteUrl(tileUrl);
266
+ return this._emsClient.extendUrlWithParams(directUrl);
267
+ });
268
+ inlinedSources[sourceName] = {
269
+ ...sourceJson,
270
+ type: 'vector',
271
+ tiles
272
+ };
273
+ }
274
+ }
275
+ return {
276
+ ...vectorJson,
277
+ sources: inlinedSources,
278
+ sprite: await this._getSpriteSheetRootPath(),
279
+ glyphs: await this._getUrlTemplateForGlyphs()
280
+ };
281
+ } else {
282
+ return;
612
283
  }
613
- }, {
614
- key: "_getSpriteSheetRootPath",
615
- value: function () {
616
- var _getSpriteSheetRootPath2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
617
- var vectorStyleJson;
618
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
619
- while (1) switch (_context14.prev = _context14.next) {
620
- case 0:
621
- _context14.next = 2;
622
- return this._getVectorStyleJsonRaw();
623
- case 2:
624
- vectorStyleJson = _context14.sent;
625
- if (!(vectorStyleJson !== null && vectorStyleJson !== void 0 && vectorStyleJson.sprite)) {
626
- _context14.next = 7;
627
- break;
628
- }
629
- return _context14.abrupt("return", this._proxyPath + this._getAbsoluteUrl(vectorStyleJson.sprite.toString()));
630
- case 7:
631
- return _context14.abrupt("return", '');
632
- case 8:
633
- case "end":
634
- return _context14.stop();
635
- }
636
- }, _callee14, this);
637
- }));
638
- function _getSpriteSheetRootPath() {
639
- return _getSpriteSheetRootPath2.apply(this, arguments);
284
+ });
285
+ constructor(config, emsClient, proxyPath) {
286
+ super(config, emsClient, proxyPath);
287
+ this._config = config;
288
+ }
289
+
290
+ /*
291
+ This method returns an array of objects with the layers and the new
292
+ layout['text-field'] to apply using map.setLayoutProperty
293
+ */
294
+ static transformLanguageProperty(layer, lang) {
295
+ const supportedLang = this.SupportedLanguages.find(l => l.key === lang);
296
+ if (layer.type === 'symbol' && layer.layout !== undefined && supportedLang !== undefined) {
297
+ const omtLang = supportedLang.omt;
298
+ const textField = layer.layout['text-field'];
299
+ if (textField && typeof textField === 'string') {
300
+ return TMSService._getTextField(textField, omtLang);
640
301
  }
641
- return _getSpriteSheetRootPath;
642
- }()
643
- }, {
644
- key: "_getUrlTemplateForGlyphs",
645
- value: function () {
646
- var _getUrlTemplateForGlyphs2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
647
- var vectorStyleJson;
648
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
649
- while (1) switch (_context15.prev = _context15.next) {
650
- case 0:
651
- _context15.next = 2;
652
- return this._getVectorStyleJsonRaw();
653
- case 2:
654
- vectorStyleJson = _context15.sent;
655
- if (!(vectorStyleJson !== null && vectorStyleJson !== void 0 && vectorStyleJson.glyphs)) {
656
- _context15.next = 7;
657
- break;
658
- }
659
- return _context15.abrupt("return", this._proxyPath + this._getAbsoluteUrl(vectorStyleJson.glyphs));
660
- case 7:
661
- return _context15.abrupt("return", '');
662
- case 8:
663
- case "end":
664
- return _context15.stop();
665
- }
666
- }, _callee15, this);
667
- }));
668
- function _getUrlTemplateForGlyphs() {
669
- return _getUrlTemplateForGlyphs2.apply(this, arguments);
302
+ }
303
+ return;
304
+ }
305
+
306
+ /*
307
+ This method returns an array of objects per layer, containing a list of
308
+ properties with new colors to apply using map.setPaintProperty
309
+ */
310
+ static transformColorProperties(layer, color, operation, percentage) {
311
+ if (['background', 'fill', 'line', 'symbol'].indexOf(layer.type) !== -1 && layer.paint) {
312
+ const paint = layer.paint;
313
+ if (layer.type === 'symbol' && Object.keys(paint).length === 0) {
314
+ paint['text-color'] = 'rgb(0,0,0)';
670
315
  }
671
- return _getUrlTemplateForGlyphs;
672
- }()
673
- }], [{
674
- key: "transformLanguageProperty",
675
- value: function transformLanguageProperty(layer, lang) {
676
- var supportedLang = this.SupportedLanguages.find(function (l) {
677
- return l.key === lang;
316
+ const types = Object.keys(paint).filter(key => {
317
+ return ['background-color', 'circle-color', 'circle-stroke-color', 'fill-color', 'fill-extrusion-color', 'fill-outline-color', 'icon-color', 'icon-halo-color', 'line-color', 'text-color', 'text-halo-color'].indexOf(key) !== -1;
318
+ });
319
+ return types.map(type => {
320
+ const paintColor = paint[type];
321
+ return {
322
+ property: type,
323
+ color: paintColor && color ? colorizeColor(paintColor, color, operation, percentage) : paintColor
324
+ };
678
325
  });
679
- if (layer.type === 'symbol' && layer.layout !== undefined && supportedLang !== undefined) {
680
- var omtLang = supportedLang.omt;
681
- var textField = layer.layout['text-field'];
682
- if (textField && typeof textField === 'string') {
683
- return TMSService._getTextField(textField, omtLang);
326
+ } else {
327
+ return [];
328
+ }
329
+ }
330
+ static _getTextField(label, lang) {
331
+ // Capture {name:xx} labels
332
+ const labelMatch = label.match(/\{name([:_])(.{2})\}/);
333
+ if (labelMatch && labelMatch[1] != lang) {
334
+ // Only apply if the languages are different
335
+ return ['coalesce', ['get', `name:${lang}`], ['get', `name${labelMatch[1]}${labelMatch[2]}`]];
336
+ } else if (label.includes('latin') && label.includes('nonlatin')) {
337
+ // Capture the common pattern {name:latin}\n{name:nonlatin}
338
+ return ['coalesce', ['get', `name:${lang}`], ['concat', ['get', 'name:latin'], '\n', ['get', 'name:nonlatin']]];
339
+ }
340
+
341
+ // If no case is found, return the input label
342
+ return label;
343
+ }
344
+ async getDefaultRasterStyle() {
345
+ const tileJson = await this._getRasterStyleJson();
346
+ if (tileJson) {
347
+ const tiles = tileJson.tiles.map(tile => this._proxyPath + this._getAbsoluteUrl(tile));
348
+ return {
349
+ ...tileJson,
350
+ ...{
351
+ tiles
684
352
  }
685
- }
353
+ };
354
+ } else {
686
355
  return;
687
356
  }
688
-
689
- /*
690
- This method returns an array of objects per layer, containing a list of
691
- properties with new colors to apply using map.setPaintProperty
692
- */
693
- }, {
694
- key: "transformColorProperties",
695
- value: function transformColorProperties(layer, color, operation, percentage) {
696
- if (['background', 'fill', 'line', 'symbol'].indexOf(layer.type) !== -1 && layer.paint) {
697
- var paint = layer.paint;
698
- if (layer.type === 'symbol' && Object.keys(paint).length === 0) {
699
- paint['text-color'] = 'rgb(0,0,0)';
357
+ }
358
+ async getUrlTemplate() {
359
+ const tileJson = await this._getRasterStyleJson();
360
+ if (tileJson) {
361
+ const directUrl = this._proxyPath + this._getAbsoluteUrl(tileJson.tiles[0]);
362
+ return this._emsClient.extendUrlWithParams(directUrl);
363
+ } else {
364
+ return '';
365
+ }
366
+ }
367
+ async getUrlTemplateForVector(sourceId) {
368
+ const tileJson = await this._getVectorStyleJsonInlined();
369
+ const url = tileJson?.sources[sourceId]?.tiles?.pop();
370
+ if (url) {
371
+ const directUrl = this._proxyPath + this._getAbsoluteUrl(url);
372
+ return this._emsClient.extendUrlWithParams(directUrl);
373
+ } else {
374
+ return '';
375
+ }
376
+ }
377
+ async getVectorStyleSheet() {
378
+ return await this._getVectorStyleJsonInlined();
379
+ }
380
+ async getVectorStyleSheetRaw() {
381
+ return await this._getVectorStyleJsonRaw();
382
+ }
383
+ async getSpriteSheetMeta(isRetina = false) {
384
+ const metaUrl = await this.getSpriteSheetJsonPath(isRetina);
385
+ const spritePngs = await this.getSpriteSheetPngPath(isRetina);
386
+ if (metaUrl && spritePngs) {
387
+ const metaUrlExtended = this._emsClient.extendUrlWithParams(metaUrl);
388
+ const jsonMeta = await this._emsClient.getManifest(metaUrlExtended);
389
+ return {
390
+ png: spritePngs,
391
+ json: jsonMeta
392
+ };
393
+ } else {
394
+ return;
395
+ }
396
+ }
397
+ async getSpriteSheetJsonPath(isRetina = false) {
398
+ const spriteSheetRootPath = await this._getSpriteSheetRootPath();
399
+ if (spriteSheetRootPath) {
400
+ const suffix = isRetina ? '@2x' : '';
401
+ return spriteSheetRootPath + suffix + '.json';
402
+ } else {
403
+ return '';
404
+ }
405
+ }
406
+ async getSpriteSheetPngPath(isRetina = false) {
407
+ const spriteSheetRootPath = await this._getSpriteSheetRootPath();
408
+ if (spriteSheetRootPath) {
409
+ const suffix = isRetina ? '@2x' : '';
410
+ return spriteSheetRootPath + suffix + '.png';
411
+ } else {
412
+ return '';
413
+ }
414
+ }
415
+ getDisplayName() {
416
+ return this._emsClient.getValueInLanguage(this._config.name);
417
+ }
418
+ async getMinZoom(format = 'vector') {
419
+ switch (format) {
420
+ case 'vector':
421
+ {
422
+ const {
423
+ sources
424
+ } = (await this._getVectorStyleJsonInlined()) || {
425
+ sources: {}
426
+ };
427
+ return Math.min(...Object.values(sources).map(s => {
428
+ return s && s instanceof Object && 'minzoom' in s ? s['minzoom'] : null;
429
+ }).filter(minzoom => Number.isFinite(minzoom)));
430
+ }
431
+ case 'raster':
432
+ {
433
+ const {
434
+ minzoom
435
+ } = (await this._getRasterStyleJson()) || {};
436
+ return minzoom;
700
437
  }
701
- var types = Object.keys(paint).filter(function (key) {
702
- return ['background-color', 'circle-color', 'circle-stroke-color', 'fill-color', 'fill-extrusion-color', 'fill-outline-color', 'icon-color', 'icon-halo-color', 'line-color', 'text-color', 'text-halo-color'].indexOf(key) !== -1;
703
- });
704
- return types.map(function (type) {
705
- var paintColor = paint[type];
706
- return {
707
- property: type,
708
- color: paintColor && color ? colorizeColor(paintColor, color, operation, percentage) : paintColor
438
+ default:
439
+ return;
440
+ }
441
+ }
442
+ async getMaxZoom(format = 'vector') {
443
+ switch (format) {
444
+ case 'vector':
445
+ {
446
+ const {
447
+ sources
448
+ } = (await this._getVectorStyleJsonInlined()) || {
449
+ sources: {}
709
450
  };
710
- });
711
- } else {
712
- return [];
713
- }
451
+ return Math.max(...Object.values(sources).map(s => {
452
+ return s && s instanceof Object && 'maxzoom' in s ? s['maxzoom'] : null;
453
+ }).filter(maxzoom => Number.isFinite(maxzoom)));
454
+ }
455
+ case 'raster':
456
+ {
457
+ const {
458
+ maxzoom
459
+ } = (await this._getRasterStyleJson()) || {};
460
+ return maxzoom;
461
+ }
462
+ default:
463
+ return;
714
464
  }
715
- }, {
716
- key: "_getTextField",
717
- value: function _getTextField(label, lang) {
718
- // Capture {name:xx} labels
719
- var labelMatch = label.match(/\{name([:_])(.{2})\}/);
720
- if (labelMatch && labelMatch[1] != lang) {
721
- // Only apply if the languages are different
722
- return ['coalesce', ['get', "name:".concat(lang)], ['get', "name".concat(labelMatch[1]).concat(labelMatch[2])]];
723
- } else if (label.includes('latin') && label.includes('nonlatin')) {
724
- // Capture the common pattern {name:latin}\n{name:nonlatin}
725
- return ['coalesce', ['get', "name:".concat(lang)], ['concat', ['get', 'name:latin'], '\n', ['get', 'name:nonlatin']]];
726
- }
727
-
728
- // If no case is found, return the input label
729
- return label;
465
+ }
466
+ getId() {
467
+ return this._config.id;
468
+ }
469
+ hasId(id) {
470
+ return this._config.id === id;
471
+ }
472
+ getApiUrl() {
473
+ return this._emsClient.getTileApiUrl();
474
+ }
475
+ _getStyleUrlForLocale(formatType) {
476
+ let vectorFormats = this._getFormats(formatType, this._emsClient.getLocale());
477
+ if (!vectorFormats.length) {
478
+ //fallback to default locale
479
+ vectorFormats = this._getFormats(formatType, this._emsClient.getDefaultLocale());
730
480
  }
731
- }]);
732
- }(AbstractEmsService);
733
- /*
734
- List of supported languages with labels and OMT codes extracted
735
- from https://openmaptiles.org/languages
736
- Keys are values for i18.locale from Kibana settings
737
- and OMT codes for the rest.
738
- */
739
- _defineProperty(TMSService, "SupportedLanguages", [{
740
- key: 'ar',
741
- omt: 'ar'
742
- }, {
743
- key: 'az',
744
- omt: 'az'
745
- }, {
746
- key: 'be',
747
- omt: 'be'
748
- }, {
749
- key: 'bg',
750
- omt: 'bg'
751
- }, {
752
- key: 'br',
753
- omt: 'br'
754
- }, {
755
- key: 'bs',
756
- omt: 'bs'
757
- }, {
758
- key: 'ca',
759
- omt: 'ca'
760
- }, {
761
- key: 'cs',
762
- omt: 'cs'
763
- }, {
764
- key: 'cy',
765
- omt: 'cy'
766
- }, {
767
- key: 'da',
768
- omt: 'da'
769
- }, {
770
- key: 'de',
771
- omt: 'de'
772
- }, {
773
- key: 'el',
774
- omt: 'el'
775
- }, {
776
- key: 'en',
777
- omt: 'en'
778
- }, {
779
- key: 'eo',
780
- omt: 'eo'
781
- }, {
782
- key: 'es',
783
- omt: 'es'
784
- }, {
785
- key: 'et',
786
- omt: 'et'
787
- }, {
788
- key: 'fi',
789
- omt: 'fi'
790
- }, {
791
- key: 'fr-fr',
792
- omt: 'fr'
793
- }, {
794
- key: 'fy',
795
- omt: 'fy'
796
- }, {
797
- key: 'ga',
798
- omt: 'ga'
799
- }, {
800
- key: 'gd',
801
- omt: 'gd'
802
- }, {
803
- key: 'he',
804
- omt: 'he'
805
- }, {
806
- key: 'hi-in',
807
- omt: 'hi'
808
- }, {
809
- key: 'hr',
810
- omt: 'hr'
811
- }, {
812
- key: 'hu',
813
- omt: 'hu'
814
- }, {
815
- key: 'hy',
816
- omt: 'hy'
817
- }, {
818
- key: 'is',
819
- omt: 'is'
820
- }, {
821
- key: 'it',
822
- omt: 'it'
823
- }, {
824
- key: 'ja_kana',
825
- omt: 'ja_kana'
826
- }, {
827
- key: 'ja_rm',
828
- omt: 'ja_rm'
829
- }, {
830
- key: 'ja-jp',
831
- omt: 'ja'
832
- }, {
833
- key: 'ka',
834
- omt: 'ka'
835
- }, {
836
- key: 'kk',
837
- omt: 'kk'
838
- }, {
839
- key: 'kn',
840
- omt: 'kn'
841
- }, {
842
- key: 'ko_rm',
843
- omt: 'ko_rm'
844
- }, {
845
- key: 'ko',
846
- omt: 'ko'
847
- }, {
848
- key: 'la',
849
- omt: 'la'
850
- }, {
851
- key: 'lb',
852
- omt: 'lb'
853
- }, {
854
- key: 'lt',
855
- omt: 'lt'
856
- }, {
857
- key: 'lv',
858
- omt: 'lv'
859
- }, {
860
- key: 'mk',
861
- omt: 'mk'
862
- }, {
863
- key: 'mt',
864
- omt: 'mt'
865
- }, {
866
- key: 'nl',
867
- omt: 'nl'
868
- }, {
869
- key: 'no',
870
- omt: 'no'
871
- }, {
872
- key: 'pl',
873
- omt: 'pl'
874
- }, {
875
- key: 'pt-pt',
876
- omt: 'pt'
877
- }, {
878
- key: 'rm',
879
- omt: 'rm'
880
- }, {
881
- key: 'ro',
882
- omt: 'ro'
883
- }, {
884
- key: 'ru-ru',
885
- omt: 'ru'
886
- }, {
887
- key: 'sk',
888
- omt: 'sk'
889
- }, {
890
- key: 'sl',
891
- omt: 'sl'
892
- }, {
893
- key: 'sq',
894
- omt: 'sq'
895
- }, {
896
- key: 'sr-Ltn',
897
- omt: 'sr-Ltn'
898
- }, {
899
- key: 'sr',
900
- omt: 'sr'
901
- }, {
902
- key: 'sv',
903
- omt: 'sv'
904
- }, {
905
- key: 'th',
906
- omt: 'th'
907
- }, {
908
- key: 'tr',
909
- omt: 'tr'
910
- }, {
911
- key: 'uk',
912
- omt: 'uk'
913
- }, {
914
- key: 'zh-cn',
915
- omt: 'zh'
916
- }]);
917
- /*
918
- Suggested default operations for the different EMS styles
919
- */
920
- _defineProperty(TMSService, "colorOperationDefaults", [{
921
- style: 'road_map',
922
- operation: 'mix',
923
- percentage: 0.25
924
- }, {
925
- style: 'road_map_desaturated',
926
- operation: 'screen',
927
- percentage: 0.25
928
- }, {
929
- style: 'dark_map',
930
- operation: 'dodge',
931
- percentage: 0.25
932
- }, {
933
- style: 'high_contrast',
934
- operation: 'screen',
935
- percentage: 0.25
936
- }, {
937
- style: 'road_map_desaturated_v9',
938
- operation: 'screen',
939
- percentage: 0.25
940
- }, {
941
- style: 'dark_map_v9',
942
- operation: 'dodge',
943
- percentage: 0.25
944
- }]);
481
+ if (!vectorFormats.length) {
482
+ throw new Error(`Cannot find ${formatType} tile layer for locale ${this._emsClient.getLocale()} or ${this._emsClient.getDefaultLocale()}`);
483
+ }
484
+ const defaultStyle = vectorFormats[0];
485
+ if (defaultStyle && Object.prototype.hasOwnProperty.call(defaultStyle, 'url')) {
486
+ return defaultStyle.url;
487
+ }
488
+ }
489
+ _getFormats(formatType, locale) {
490
+ return this._config.formats.filter(format => format.locale === locale && format.format === formatType);
491
+ }
492
+ async _getSpriteSheetRootPath() {
493
+ const vectorStyleJson = await this._getVectorStyleJsonRaw();
494
+ if (vectorStyleJson?.sprite) {
495
+ return this._proxyPath + this._getAbsoluteUrl(vectorStyleJson.sprite.toString());
496
+ } else {
497
+ return '';
498
+ }
499
+ }
500
+ async _getUrlTemplateForGlyphs() {
501
+ const vectorStyleJson = await this._getVectorStyleJsonRaw();
502
+ if (vectorStyleJson?.glyphs) {
503
+ return this._proxyPath + this._getAbsoluteUrl(vectorStyleJson.glyphs);
504
+ } else {
505
+ return '';
506
+ }
507
+ }
508
+ }