UNPKG

@elastic/ems-client

Version:

JavaScript client library for the Elastic Maps Service

931 lines (927 loc) 37.2 kB
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); } function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); } 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."); } function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); } function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); } 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; } } }; } 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; } } 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; } 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; } 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; } function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); } function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); } 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); } 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); }); }; } function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } 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); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } 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); } function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); } 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); } function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); } 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; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } 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); } /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ import _ from 'lodash'; import { AbstractEmsService } from './ems_service'; import { colorizeColor } from './utils'; export var TMSService = /*#__PURE__*/function (_AbstractEmsService) { function TMSService(config, emsClient, proxyPath) { var _this; _classCallCheck(this, TMSService); _this = _callSuper(this, TMSService, [config, emsClient, proxyPath]); _defineProperty(_this, "_config", void 0); _defineProperty(_this, "_getRasterStyleJson", _.once(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() { var rasterUrl, url; return _regenerator().w(function (_context) { while (1) switch (_context.n) { case 0: rasterUrl = _this._getStyleUrlForLocale('raster'); if (!rasterUrl) { _context.n = 1; break; } url = _this._proxyPath + _this._getAbsoluteUrl(rasterUrl); return _context.a(2, _this._emsClient.getManifest(_this._emsClient.extendUrlWithParams(url))); case 1: return _context.a(2); case 2: return _context.a(2); } }, _callee); })))); _defineProperty(_this, "_getVectorStyleJsonRaw", _.once(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() { var vectorUrl, url, vectorJson; return _regenerator().w(function (_context2) { while (1) switch (_context2.n) { case 0: vectorUrl = _this._getStyleUrlForLocale('vector'); if (!vectorUrl) { _context2.n = 2; break; } url = _this._proxyPath + _this._getAbsoluteUrl(vectorUrl); _context2.n = 1; return _this._emsClient.getManifest(_this._emsClient.extendUrlWithParams(url)); case 1: vectorJson = _context2.v; return _context2.a(2, _objectSpread({}, vectorJson)); case 2: return _context2.a(2); case 3: return _context2.a(2); } }, _callee2); })))); _defineProperty(_this, "_getVectorStyleJsonInlined", _.once(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() { var vectorJson, inlinedSources, sources, _iterator, _step, _sourceName, url, _sourceJson$tiles, sourceUrl, extendedUrl, sourceJson, tiles, _t, _t2, _t3, _t4, _t5, _t6, _t7; return _regenerator().w(function (_context3) { while (1) switch (_context3.p = _context3.n) { case 0: _context3.n = 1; return _this._getVectorStyleJsonRaw(); case 1: vectorJson = _context3.v; if (!vectorJson) { _context3.n = 12; break; } inlinedSources = {}; sources = vectorJson.sources; _iterator = _createForOfIteratorHelper(Object.getOwnPropertyNames(sources)); _context3.p = 2; _iterator.s(); case 3: if ((_step = _iterator.n()).done) { _context3.n = 6; break; } _sourceName = _step.value; url = sources[_sourceName].url; if (!url) { _context3.n = 5; break; } sourceUrl = _this._proxyPath + _this._getAbsoluteUrl(url); extendedUrl = _this._emsClient.extendUrlWithParams(sourceUrl); _context3.n = 4; return _this._emsClient.getManifest(extendedUrl); case 4: sourceJson = _context3.v; tiles = sourceJson === null || sourceJson === void 0 || (_sourceJson$tiles = sourceJson.tiles) === null || _sourceJson$tiles === void 0 ? void 0 : _sourceJson$tiles.map(function (tileUrl) { var directUrl = _this._proxyPath + _this._getAbsoluteUrl(tileUrl); return _this._emsClient.extendUrlWithParams(directUrl); }); inlinedSources[_sourceName] = _objectSpread(_objectSpread({}, sourceJson), {}, { type: 'vector', tiles: tiles }); case 5: _context3.n = 3; break; case 6: _context3.n = 8; break; case 7: _context3.p = 7; _t = _context3.v; _iterator.e(_t); case 8: _context3.p = 8; _iterator.f(); return _context3.f(8); case 9: _t2 = _objectSpread; _t3 = _objectSpread({}, vectorJson); _t4 = {}; _t5 = inlinedSources; _context3.n = 10; return _this._getSpriteSheetRootPath(); case 10: _t6 = _context3.v; _context3.n = 11; return _this._getUrlTemplateForGlyphs(); case 11: _t7 = _context3.v; return _context3.a(2, _t2(_t3, _t4, { sources: _t5, sprite: _t6, glyphs: _t7 })); case 12: return _context3.a(2); case 13: return _context3.a(2); } }, _callee3, null, [[2, 7, 8, 9]]); })))); _this._config = config; return _this; } /* This method returns an array of objects with the layers and the new layout['text-field'] to apply using map.setLayoutProperty */ _inherits(TMSService, _AbstractEmsService); return _createClass(TMSService, [{ key: "getDefaultRasterStyle", value: function () { var _getDefaultRasterStyle = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() { var _this2 = this; var tileJson, tiles; return _regenerator().w(function (_context4) { while (1) switch (_context4.n) { case 0: _context4.n = 1; return this._getRasterStyleJson(); case 1: tileJson = _context4.v; if (!tileJson) { _context4.n = 2; break; } tiles = tileJson.tiles.map(function (tile) { return _this2._proxyPath + _this2._getAbsoluteUrl(tile); }); return _context4.a(2, _objectSpread(_objectSpread({}, tileJson), { tiles: tiles })); case 2: return _context4.a(2); case 3: return _context4.a(2); } }, _callee4, this); })); function getDefaultRasterStyle() { return _getDefaultRasterStyle.apply(this, arguments); } return getDefaultRasterStyle; }() }, { key: "getUrlTemplate", value: function () { var _getUrlTemplate = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5() { var tileJson, directUrl; return _regenerator().w(function (_context5) { while (1) switch (_context5.n) { case 0: _context5.n = 1; return this._getRasterStyleJson(); case 1: tileJson = _context5.v; if (!tileJson) { _context5.n = 2; break; } directUrl = this._proxyPath + this._getAbsoluteUrl(tileJson.tiles[0]); return _context5.a(2, this._emsClient.extendUrlWithParams(directUrl)); case 2: return _context5.a(2, ''); case 3: return _context5.a(2); } }, _callee5, this); })); function getUrlTemplate() { return _getUrlTemplate.apply(this, arguments); } return getUrlTemplate; }() }, { key: "getUrlTemplateForVector", value: function () { var _getUrlTemplateForVector = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(sourceId) { var _tileJson$sources$sou; var tileJson, url, directUrl; return _regenerator().w(function (_context6) { while (1) switch (_context6.n) { case 0: _context6.n = 1; return this._getVectorStyleJsonInlined(); case 1: tileJson = _context6.v; 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(); if (!url) { _context6.n = 2; break; } directUrl = this._proxyPath + this._getAbsoluteUrl(url); return _context6.a(2, this._emsClient.extendUrlWithParams(directUrl)); case 2: return _context6.a(2, ''); case 3: return _context6.a(2); } }, _callee6, this); })); function getUrlTemplateForVector(_x) { return _getUrlTemplateForVector.apply(this, arguments); } return getUrlTemplateForVector; }() }, { key: "getVectorStyleSheet", value: function () { var _getVectorStyleSheet = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7() { return _regenerator().w(function (_context7) { while (1) switch (_context7.n) { case 0: _context7.n = 1; return this._getVectorStyleJsonInlined(); case 1: return _context7.a(2, _context7.v); } }, _callee7, this); })); function getVectorStyleSheet() { return _getVectorStyleSheet.apply(this, arguments); } return getVectorStyleSheet; }() }, { key: "getVectorStyleSheetRaw", value: function () { var _getVectorStyleSheetRaw = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8() { return _regenerator().w(function (_context8) { while (1) switch (_context8.n) { case 0: _context8.n = 1; return this._getVectorStyleJsonRaw(); case 1: return _context8.a(2, _context8.v); } }, _callee8, this); })); function getVectorStyleSheetRaw() { return _getVectorStyleSheetRaw.apply(this, arguments); } return getVectorStyleSheetRaw; }() }, { key: "getSpriteSheetMeta", value: function () { var _getSpriteSheetMeta = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9() { var isRetina, metaUrl, spritePngs, metaUrlExtended, jsonMeta, _args9 = arguments; return _regenerator().w(function (_context9) { while (1) switch (_context9.n) { case 0: isRetina = _args9.length > 0 && _args9[0] !== undefined ? _args9[0] : false; _context9.n = 1; return this.getSpriteSheetJsonPath(isRetina); case 1: metaUrl = _context9.v; _context9.n = 2; return this.getSpriteSheetPngPath(isRetina); case 2: spritePngs = _context9.v; if (!(metaUrl && spritePngs)) { _context9.n = 4; break; } metaUrlExtended = this._emsClient.extendUrlWithParams(metaUrl); _context9.n = 3; return this._emsClient.getManifest(metaUrlExtended); case 3: jsonMeta = _context9.v; return _context9.a(2, { png: spritePngs, json: jsonMeta }); case 4: return _context9.a(2); case 5: return _context9.a(2); } }, _callee9, this); })); function getSpriteSheetMeta() { return _getSpriteSheetMeta.apply(this, arguments); } return getSpriteSheetMeta; }() }, { key: "getSpriteSheetJsonPath", value: function () { var _getSpriteSheetJsonPath = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0() { var isRetina, spriteSheetRootPath, suffix, _args0 = arguments; return _regenerator().w(function (_context0) { while (1) switch (_context0.n) { case 0: isRetina = _args0.length > 0 && _args0[0] !== undefined ? _args0[0] : false; _context0.n = 1; return this._getSpriteSheetRootPath(); case 1: spriteSheetRootPath = _context0.v; if (!spriteSheetRootPath) { _context0.n = 2; break; } suffix = isRetina ? '@2x' : ''; return _context0.a(2, spriteSheetRootPath + suffix + '.json'); case 2: return _context0.a(2, ''); case 3: return _context0.a(2); } }, _callee0, this); })); function getSpriteSheetJsonPath() { return _getSpriteSheetJsonPath.apply(this, arguments); } return getSpriteSheetJsonPath; }() }, { key: "getSpriteSheetPngPath", value: function () { var _getSpriteSheetPngPath = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1() { var isRetina, spriteSheetRootPath, suffix, _args1 = arguments; return _regenerator().w(function (_context1) { while (1) switch (_context1.n) { case 0: isRetina = _args1.length > 0 && _args1[0] !== undefined ? _args1[0] : false; _context1.n = 1; return this._getSpriteSheetRootPath(); case 1: spriteSheetRootPath = _context1.v; if (!spriteSheetRootPath) { _context1.n = 2; break; } suffix = isRetina ? '@2x' : ''; return _context1.a(2, spriteSheetRootPath + suffix + '.png'); case 2: return _context1.a(2, ''); case 3: return _context1.a(2); } }, _callee1, this); })); function getSpriteSheetPngPath() { return _getSpriteSheetPngPath.apply(this, arguments); } return getSpriteSheetPngPath; }() }, { key: "getDisplayName", value: function getDisplayName() { return this._emsClient.getValueInLanguage(this._config.name); } }, { key: "getMinZoom", value: function () { var _getMinZoom = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10() { var format, _ref4, sources, _ref5, minzoom, _args10 = arguments, _t8, _t9, _t0; return _regenerator().w(function (_context10) { while (1) switch (_context10.n) { case 0: format = _args10.length > 0 && _args10[0] !== undefined ? _args10[0] : 'vector'; _t8 = format; _context10.n = _t8 === 'vector' ? 1 : _t8 === 'raster' ? 4 : 7; break; case 1: _context10.n = 2; return this._getVectorStyleJsonInlined(); case 2: _t9 = _context10.v; if (_t9) { _context10.n = 3; break; } _t9 = { sources: {} }; case 3: _ref4 = _t9; sources = _ref4.sources; return _context10.a(2, Math.min.apply(Math, _toConsumableArray(Object.values(sources).map(function (s) { return s && s instanceof Object && 'minzoom' in s ? s['minzoom'] : null; }).filter(function (minzoom) { return Number.isFinite(minzoom); })))); case 4: _context10.n = 5; return this._getRasterStyleJson(); case 5: _t0 = _context10.v; if (_t0) { _context10.n = 6; break; } _t0 = {}; case 6: _ref5 = _t0; minzoom = _ref5.minzoom; return _context10.a(2, minzoom); case 7: return _context10.a(2); case 8: return _context10.a(2); } }, _callee10, this); })); function getMinZoom() { return _getMinZoom.apply(this, arguments); } return getMinZoom; }() }, { key: "getMaxZoom", value: function () { var _getMaxZoom = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee11() { var format, _ref6, sources, _ref7, maxzoom, _args11 = arguments, _t1, _t10, _t11; return _regenerator().w(function (_context11) { while (1) switch (_context11.n) { case 0: format = _args11.length > 0 && _args11[0] !== undefined ? _args11[0] : 'vector'; _t1 = format; _context11.n = _t1 === 'vector' ? 1 : _t1 === 'raster' ? 4 : 7; break; case 1: _context11.n = 2; return this._getVectorStyleJsonInlined(); case 2: _t10 = _context11.v; if (_t10) { _context11.n = 3; break; } _t10 = { sources: {} }; case 3: _ref6 = _t10; sources = _ref6.sources; return _context11.a(2, Math.max.apply(Math, _toConsumableArray(Object.values(sources).map(function (s) { return s && s instanceof Object && 'maxzoom' in s ? s['maxzoom'] : null; }).filter(function (maxzoom) { return Number.isFinite(maxzoom); })))); case 4: _context11.n = 5; return this._getRasterStyleJson(); case 5: _t11 = _context11.v; if (_t11) { _context11.n = 6; break; } _t11 = {}; case 6: _ref7 = _t11; maxzoom = _ref7.maxzoom; return _context11.a(2, maxzoom); case 7: return _context11.a(2); case 8: return _context11.a(2); } }, _callee11, this); })); function getMaxZoom() { return _getMaxZoom.apply(this, arguments); } return getMaxZoom; }() }, { key: "getId", value: function getId() { return this._config.id; } }, { key: "hasId", value: function hasId(id) { return this._config.id === id; } }, { key: "getApiUrl", value: function getApiUrl() { return this._emsClient.getTileApiUrl(); } }, { key: "_getStyleUrlForLocale", value: function _getStyleUrlForLocale(formatType) { var vectorFormats = this._getFormats(formatType, this._emsClient.getLocale()); if (!vectorFormats.length) { //fallback to default locale vectorFormats = this._getFormats(formatType, this._emsClient.getDefaultLocale()); } if (!vectorFormats.length) { throw new Error("Cannot find ".concat(formatType, " tile layer for locale ").concat(this._emsClient.getLocale(), " or ").concat(this._emsClient.getDefaultLocale())); } var defaultStyle = vectorFormats[0]; if (defaultStyle && Object.prototype.hasOwnProperty.call(defaultStyle, 'url')) { return defaultStyle.url; } } }, { key: "_getFormats", value: function _getFormats(formatType, locale) { return this._config.formats.filter(function (format) { return format.locale === locale && format.format === formatType; }); } }, { key: "_getSpriteSheetRootPath", value: function () { var _getSpriteSheetRootPath2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee12() { var vectorStyleJson; return _regenerator().w(function (_context12) { while (1) switch (_context12.n) { case 0: _context12.n = 1; return this._getVectorStyleJsonRaw(); case 1: vectorStyleJson = _context12.v; if (!(vectorStyleJson !== null && vectorStyleJson !== void 0 && vectorStyleJson.sprite)) { _context12.n = 2; break; } return _context12.a(2, this._proxyPath + this._getAbsoluteUrl(vectorStyleJson.sprite.toString())); case 2: return _context12.a(2, ''); case 3: return _context12.a(2); } }, _callee12, this); })); function _getSpriteSheetRootPath() { return _getSpriteSheetRootPath2.apply(this, arguments); } return _getSpriteSheetRootPath; }() }, { key: "_getUrlTemplateForGlyphs", value: function () { var _getUrlTemplateForGlyphs2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee13() { var vectorStyleJson; return _regenerator().w(function (_context13) { while (1) switch (_context13.n) { case 0: _context13.n = 1; return this._getVectorStyleJsonRaw(); case 1: vectorStyleJson = _context13.v; if (!(vectorStyleJson !== null && vectorStyleJson !== void 0 && vectorStyleJson.glyphs)) { _context13.n = 2; break; } return _context13.a(2, this._proxyPath + this._getAbsoluteUrl(vectorStyleJson.glyphs)); case 2: return _context13.a(2, ''); case 3: return _context13.a(2); } }, _callee13, this); })); function _getUrlTemplateForGlyphs() { return _getUrlTemplateForGlyphs2.apply(this, arguments); } return _getUrlTemplateForGlyphs; }() }], [{ key: "transformLanguageProperty", value: function transformLanguageProperty(layer, lang) { var supportedLang = this.SupportedLanguages.find(function (l) { return l.key === lang; }); if (layer.type === 'symbol' && layer.layout !== undefined && supportedLang !== undefined) { var omtLang = supportedLang.omt; var textField = layer.layout['text-field']; if (textField && typeof textField === 'string') { return TMSService._getTextField(textField, omtLang); } } return; } /* This method returns an array of objects per layer, containing a list of properties with new colors to apply using map.setPaintProperty */ }, { key: "transformColorProperties", value: function transformColorProperties(layer, color, operation, percentage) { if (['background', 'fill', 'line', 'symbol'].indexOf(layer.type) !== -1 && layer.paint) { var paint = layer.paint; if (layer.type === 'symbol' && Object.keys(paint).length === 0) { paint['text-color'] = 'rgb(0,0,0)'; } var types = Object.keys(paint).filter(function (key) { 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; }); return types.map(function (type) { var paintColor = paint[type]; return { property: type, color: paintColor && color ? colorizeColor(paintColor, color, operation, percentage) : paintColor }; }); } else { return []; } } }, { key: "_getTextField", value: function _getTextField(label, lang) { // Capture {name:xx} labels var labelMatch = label.match(/\{name([:_])(.{2})\}/); if (labelMatch && labelMatch[1] != lang) { // Only apply if the languages are different return ['coalesce', ['get', "name:".concat(lang)], ['get', "name".concat(labelMatch[1]).concat(labelMatch[2])]]; } else if (label.includes('latin') && label.includes('nonlatin')) { // Capture the common pattern {name:latin}\n{name:nonlatin} return ['coalesce', ['get', "name:".concat(lang)], ['concat', ['get', 'name:latin'], '\n', ['get', 'name:nonlatin']]]; } // If no case is found, return the input label return label; } }]); }(AbstractEmsService); /* List of supported languages with labels and OMT codes extracted from https://openmaptiles.org/languages Keys are values for i18.locale from Kibana settings and OMT codes for the rest. */ _defineProperty(TMSService, "SupportedLanguages", [{ key: 'ar', omt: 'ar' }, { key: 'az', omt: 'az' }, { key: 'be', omt: 'be' }, { key: 'bg', omt: 'bg' }, { key: 'br', omt: 'br' }, { key: 'bs', omt: 'bs' }, { key: 'ca', omt: 'ca' }, { key: 'cs', omt: 'cs' }, { key: 'cy', omt: 'cy' }, { key: 'da', omt: 'da' }, { key: 'de', omt: 'de' }, { key: 'el', omt: 'el' }, { key: 'en', omt: 'en' }, { key: 'eo', omt: 'eo' }, { key: 'es', omt: 'es' }, { key: 'et', omt: 'et' }, { key: 'fi', omt: 'fi' }, { key: 'fr-fr', omt: 'fr' }, { key: 'fy', omt: 'fy' }, { key: 'ga', omt: 'ga' }, { key: 'gd', omt: 'gd' }, { key: 'he', omt: 'he' }, { key: 'hi-in', omt: 'hi' }, { key: 'hr', omt: 'hr' }, { key: 'hu', omt: 'hu' }, { key: 'hy', omt: 'hy' }, { key: 'is', omt: 'is' }, { key: 'it', omt: 'it' }, { key: 'ja_kana', omt: 'ja_kana' }, { key: 'ja_rm', omt: 'ja_rm' }, { key: 'ja-jp', omt: 'ja' }, { key: 'ka', omt: 'ka' }, { key: 'kk', omt: 'kk' }, { key: 'kn', omt: 'kn' }, { key: 'ko_rm', omt: 'ko_rm' }, { key: 'ko', omt: 'ko' }, { key: 'la', omt: 'la' }, { key: 'lb', omt: 'lb' }, { key: 'lt', omt: 'lt' }, { key: 'lv', omt: 'lv' }, { key: 'mk', omt: 'mk' }, { key: 'mt', omt: 'mt' }, { key: 'nl', omt: 'nl' }, { key: 'no', omt: 'no' }, { key: 'pl', omt: 'pl' }, { key: 'pt-pt', omt: 'pt' }, { key: 'rm', omt: 'rm' }, { key: 'ro', omt: 'ro' }, { key: 'ru-ru', omt: 'ru' }, { key: 'sk', omt: 'sk' }, { key: 'sl', omt: 'sl' }, { key: 'sq', omt: 'sq' }, { key: 'sr-Ltn', omt: 'sr-Ltn' }, { key: 'sr', omt: 'sr' }, { key: 'sv', omt: 'sv' }, { key: 'th', omt: 'th' }, { key: 'tr', omt: 'tr' }, { key: 'uk', omt: 'uk' }, { key: 'zh-cn', omt: 'zh' }]); /* Suggested default operations for the different EMS styles */ _defineProperty(TMSService, "colorOperationDefaults", [{ style: 'road_map', operation: 'mix', percentage: 0.25 }, { style: 'road_map_desaturated', operation: 'screen', percentage: 0.25 }, { style: 'dark_map', operation: 'dodge', percentage: 0.25 }, { style: 'high_contrast', operation: 'screen', percentage: 0.25 }, { style: 'road_map_desaturated_v9', operation: 'screen', percentage: 0.25 }, { style: 'dark_map_v9', operation: 'dodge', percentage: 0.25 }]);