@elastic/ems-client 8.3.3 → 8.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.backportrc.json +5 -17
- package/.buildkite/build.sh +16 -0
- package/.buildkite/pipeline.yml +6 -0
- package/.buildkite/pull-requests.json +30 -0
- package/.nvmrc +1 -0
- package/CHANGELOG.md +13 -0
- package/CONTRIBUTING.md +18 -0
- package/catalog-info.yaml +68 -0
- package/package.json +7 -4
- package/src/ems_client.ts +33 -33
- package/src/index.ts +1 -1
- package/src/tms_service.ts +5 -1
- package/target/ems_client.d.ts +2 -2
- package/target/index.d.ts +1 -1
- package/target/node/ems_client.js +55 -125
- package/target/node/ems_service.js +11 -21
- package/target/node/file_layer.js +16 -60
- package/target/node/index.js +6 -4
- package/target/node/tms_service.js +33 -99
- package/target/node/utils.js +8 -10
- package/target/origin.d.ts +4 -0
- package/target/tms_service.d.ts +1 -1
- package/target/web/ems_client.js +295 -462
- package/target/web/ems_service.js +10 -26
- package/target/web/file_layer.js +62 -117
- package/target/web/index.js +2 -1
- package/target/web/tms_service.js +447 -650
- package/target/web/utils.js +10 -8
- package/test/ems_client.test.ts +33 -0
- package/.ci/jobs/defaults.yml +0 -67
- package/.ci/jobs/elastic+ems-client+master.yml +0 -18
- package/.ci/jobs/elastic+ems-client+pull-request.yml +0 -19
|
@@ -4,74 +4,60 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.FileLayer = exports.EMSFormatType = void 0;
|
|
7
|
-
|
|
8
7
|
var _url = _interopRequireDefault(require("url"));
|
|
9
|
-
|
|
10
8
|
var _ems_service = require("./ems_service");
|
|
11
|
-
|
|
12
9
|
var topojson = _interopRequireWildcard(require("topojson-client"));
|
|
13
|
-
|
|
14
10
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
15
|
-
|
|
16
11
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
17
|
-
|
|
18
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
13
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
14
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
15
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /*
|
|
16
|
+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
17
|
+
* or more contributor license agreements. Licensed under the Elastic License
|
|
18
|
+
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
19
|
+
* 2.0.
|
|
20
|
+
*/
|
|
21
|
+
let EMSFormatType = /*#__PURE__*/function (EMSFormatType) {
|
|
26
22
|
EMSFormatType["geojson"] = "geojson";
|
|
27
23
|
EMSFormatType["topojson"] = "topojson";
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
return EMSFormatType;
|
|
25
|
+
}({});
|
|
26
|
+
exports.EMSFormatType = EMSFormatType;
|
|
30
27
|
class FileLayer extends _ems_service.AbstractEmsService {
|
|
31
28
|
constructor(config, emsClient, proxyPath) {
|
|
32
29
|
super(config, emsClient, proxyPath);
|
|
33
|
-
|
|
34
30
|
_defineProperty(this, "_config", void 0);
|
|
35
|
-
|
|
36
31
|
this._config = config;
|
|
37
32
|
}
|
|
38
|
-
|
|
39
33
|
async getGeoJson() {
|
|
40
34
|
const cachedGeoJson = this._emsClient.getCachedGeoJson(this.getId());
|
|
41
|
-
|
|
42
35
|
if (cachedGeoJson) {
|
|
43
36
|
return cachedGeoJson;
|
|
44
37
|
}
|
|
45
|
-
|
|
46
38
|
const format = this.getDefaultFormatType();
|
|
47
39
|
const fetchUrl = this.getDefaultFormatUrl();
|
|
48
40
|
let geojson;
|
|
49
41
|
const fetchedJson = await this._emsClient.getManifest(fetchUrl);
|
|
50
|
-
|
|
51
42
|
if (fetchedJson) {
|
|
52
43
|
if (format === 'geojson') {
|
|
53
44
|
geojson = fetchedJson;
|
|
54
45
|
} else if (format === 'topojson') {
|
|
55
46
|
const meta = this.getDefaultFormatMeta();
|
|
56
|
-
const featureCollectionPath =
|
|
57
|
-
|
|
47
|
+
const featureCollectionPath = meta?.feature_collection_path ?? 'data';
|
|
48
|
+
// @ts-expect-error see https://github.com/DefinitelyTyped/DefinitelyTyped/pull/52156
|
|
58
49
|
geojson = topojson.feature(fetchedJson, featureCollectionPath);
|
|
59
50
|
} else {
|
|
60
51
|
return;
|
|
61
52
|
}
|
|
62
|
-
|
|
63
53
|
this._emsClient.cacheGeoJson(this.getId(), geojson);
|
|
64
|
-
|
|
65
54
|
return geojson;
|
|
66
55
|
}
|
|
67
|
-
|
|
68
56
|
return;
|
|
69
57
|
}
|
|
70
|
-
|
|
71
58
|
getFields() {
|
|
72
59
|
return this._config.fields;
|
|
73
60
|
}
|
|
74
|
-
|
|
75
61
|
getFieldsInLanguage() {
|
|
76
62
|
return this.getFields().map(field => {
|
|
77
63
|
return {
|
|
@@ -81,84 +67,61 @@ class FileLayer extends _ems_service.AbstractEmsService {
|
|
|
81
67
|
};
|
|
82
68
|
});
|
|
83
69
|
}
|
|
84
|
-
|
|
85
70
|
getDisplayName() {
|
|
86
71
|
const layerName = this._emsClient.getValueInLanguage(this._config.layer_name);
|
|
87
|
-
|
|
88
72
|
return layerName ? layerName : '';
|
|
89
73
|
}
|
|
90
|
-
|
|
91
74
|
getId() {
|
|
92
75
|
return this._config.layer_id;
|
|
93
76
|
}
|
|
94
|
-
|
|
95
77
|
hasId(id) {
|
|
96
78
|
const matchesLegacyId = this._config.legacy_ids.indexOf(id) >= 0;
|
|
97
79
|
return this._config.layer_id === id || matchesLegacyId;
|
|
98
80
|
}
|
|
99
|
-
|
|
100
81
|
getEMSHotLink() {
|
|
101
82
|
const landingPageString = this._emsClient.getLandingPageUrl();
|
|
102
|
-
|
|
103
83
|
const urlObject = _url.default.parse(landingPageString, true);
|
|
104
|
-
|
|
105
84
|
urlObject.hash = `file/${this.getId()}`;
|
|
106
|
-
urlObject.query = {
|
|
85
|
+
urlObject.query = {
|
|
86
|
+
...urlObject.query,
|
|
107
87
|
locale: this._emsClient.getLocale()
|
|
108
88
|
};
|
|
109
89
|
return _url.default.format(urlObject);
|
|
110
90
|
}
|
|
111
|
-
|
|
112
91
|
getDefaultFormatType() {
|
|
113
92
|
const format = this._getDefaultFormat();
|
|
114
|
-
|
|
115
93
|
return format.type;
|
|
116
94
|
}
|
|
117
|
-
|
|
118
95
|
getFormatOfType(type) {
|
|
119
96
|
const format = this._getFormatOfType(type);
|
|
120
|
-
|
|
121
97
|
return format.type;
|
|
122
98
|
}
|
|
123
|
-
|
|
124
99
|
getDefaultFormatMeta() {
|
|
125
100
|
const format = this._getDefaultFormat();
|
|
126
|
-
|
|
127
101
|
return this._getFormatMeta(format);
|
|
128
102
|
}
|
|
129
|
-
|
|
130
103
|
getFormatOfTypeMeta(type) {
|
|
131
104
|
const format = this._getFormatOfType(type);
|
|
132
|
-
|
|
133
105
|
return this._getFormatMeta(format);
|
|
134
106
|
}
|
|
135
|
-
|
|
136
107
|
getDefaultFormatUrl() {
|
|
137
108
|
const format = this._getDefaultFormat();
|
|
138
|
-
|
|
139
109
|
return this._getFormatUrl(format);
|
|
140
110
|
}
|
|
141
|
-
|
|
142
111
|
getFormatOfTypeUrl(type) {
|
|
143
112
|
const format = this._getFormatOfType(type);
|
|
144
|
-
|
|
145
113
|
return this._getFormatUrl(format);
|
|
146
114
|
}
|
|
147
|
-
|
|
148
115
|
getCreatedAt() {
|
|
149
116
|
return this._config.created_at;
|
|
150
117
|
}
|
|
151
|
-
|
|
152
118
|
getApiUrl() {
|
|
153
119
|
return this._emsClient.getFileApiUrl();
|
|
154
120
|
}
|
|
155
|
-
|
|
156
121
|
_getFormatUrl(format) {
|
|
157
122
|
const url = this._proxyPath + this._getAbsoluteUrl(format.url);
|
|
158
|
-
|
|
159
123
|
return this._emsClient.extendUrlWithParams(url);
|
|
160
124
|
}
|
|
161
|
-
|
|
162
125
|
_getFormatMeta(format) {
|
|
163
126
|
if ('meta' in format) {
|
|
164
127
|
return format.meta;
|
|
@@ -166,27 +129,20 @@ class FileLayer extends _ems_service.AbstractEmsService {
|
|
|
166
129
|
return;
|
|
167
130
|
}
|
|
168
131
|
}
|
|
169
|
-
|
|
170
132
|
_getDefaultFormat() {
|
|
171
133
|
const defaultFormat = this._config.formats.find(format => {
|
|
172
134
|
return format.legacy_default;
|
|
173
135
|
});
|
|
174
|
-
|
|
175
136
|
if (defaultFormat) {
|
|
176
137
|
return defaultFormat;
|
|
177
138
|
}
|
|
178
|
-
|
|
179
139
|
return this._config.formats[0];
|
|
180
140
|
}
|
|
181
|
-
|
|
182
141
|
_getFormatOfType(type) {
|
|
183
142
|
const requestedFormat = this._config.formats.find(format => {
|
|
184
143
|
return format.type === type;
|
|
185
144
|
});
|
|
186
|
-
|
|
187
145
|
return requestedFormat || this._getDefaultFormat();
|
|
188
146
|
}
|
|
189
|
-
|
|
190
147
|
}
|
|
191
|
-
|
|
192
148
|
exports.FileLayer = FileLayer;
|
package/target/node/index.js
CHANGED
|
@@ -33,6 +33,12 @@ Object.defineProperty(exports, "FileLayerField", {
|
|
|
33
33
|
return _ems_client.FileLayerField;
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
|
+
Object.defineProperty(exports, "LATEST_API_URL_PATH", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _ems_client.LATEST_API_URL_PATH;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
36
42
|
Object.defineProperty(exports, "TMSService", {
|
|
37
43
|
enumerable: true,
|
|
38
44
|
get: function () {
|
|
@@ -45,11 +51,7 @@ Object.defineProperty(exports, "blendMode", {
|
|
|
45
51
|
return _utils.blendMode;
|
|
46
52
|
}
|
|
47
53
|
});
|
|
48
|
-
|
|
49
54
|
var _ems_client = require("./ems_client");
|
|
50
|
-
|
|
51
55
|
var _file_layer = require("./file_layer");
|
|
52
|
-
|
|
53
56
|
var _tms_service = require("./tms_service");
|
|
54
|
-
|
|
55
57
|
var _utils = require("./utils");
|
|
@@ -4,94 +4,71 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.TMSService = void 0;
|
|
7
|
-
|
|
8
7
|
var _lodash = _interopRequireDefault(require("lodash"));
|
|
9
|
-
|
|
10
8
|
var _ems_service = require("./ems_service");
|
|
11
|
-
|
|
12
9
|
var _utils = require("./utils");
|
|
13
|
-
|
|
14
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
|
-
function
|
|
17
|
-
|
|
11
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
12
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
13
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /*
|
|
14
|
+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
15
|
+
* or more contributor license agreements. Licensed under the Elastic License
|
|
16
|
+
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
17
|
+
* 2.0.
|
|
18
|
+
*/
|
|
18
19
|
class TMSService extends _ems_service.AbstractEmsService {
|
|
19
|
-
/*
|
|
20
|
-
List of supported languages with labels and OMT codes extracted
|
|
21
|
-
from https://openmaptiles.org/languages
|
|
22
|
-
Keys are values for i18.locale from Kibana settings
|
|
23
|
-
and OMT codes for the rest.
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
/*
|
|
27
|
-
Suggested default operations for the different EMS styles
|
|
28
|
-
*/
|
|
29
20
|
constructor(config, emsClient, proxyPath) {
|
|
30
21
|
super(config, emsClient, proxyPath);
|
|
31
|
-
|
|
32
22
|
_defineProperty(this, "_config", void 0);
|
|
33
|
-
|
|
34
23
|
_defineProperty(this, "_getRasterStyleJson", _lodash.default.once(async () => {
|
|
35
24
|
const rasterUrl = this._getStyleUrlForLocale('raster');
|
|
36
|
-
|
|
37
25
|
if (rasterUrl) {
|
|
38
26
|
const url = this._proxyPath + this._getAbsoluteUrl(rasterUrl);
|
|
39
|
-
|
|
40
27
|
return this._emsClient.getManifest(this._emsClient.extendUrlWithParams(url));
|
|
41
28
|
} else {
|
|
42
29
|
return;
|
|
43
30
|
}
|
|
44
31
|
}));
|
|
45
|
-
|
|
46
32
|
_defineProperty(this, "_getVectorStyleJsonRaw", _lodash.default.once(async () => {
|
|
47
33
|
const vectorUrl = this._getStyleUrlForLocale('vector');
|
|
48
|
-
|
|
49
34
|
if (vectorUrl) {
|
|
50
35
|
const url = this._proxyPath + this._getAbsoluteUrl(vectorUrl);
|
|
51
|
-
|
|
52
36
|
const vectorJson = await this._emsClient.getManifest(this._emsClient.extendUrlWithParams(url));
|
|
53
|
-
return {
|
|
37
|
+
return {
|
|
38
|
+
...vectorJson
|
|
54
39
|
};
|
|
55
40
|
} else {
|
|
56
41
|
return;
|
|
57
42
|
}
|
|
58
43
|
}));
|
|
59
|
-
|
|
60
44
|
_defineProperty(this, "_getVectorStyleJsonInlined", _lodash.default.once(async () => {
|
|
61
45
|
const vectorJson = await this._getVectorStyleJsonRaw();
|
|
62
|
-
|
|
63
46
|
if (vectorJson) {
|
|
64
47
|
const inlinedSources = {};
|
|
65
48
|
const {
|
|
66
49
|
sources
|
|
67
50
|
} = vectorJson;
|
|
68
|
-
|
|
69
51
|
for (const sourceName of Object.getOwnPropertyNames(sources)) {
|
|
70
52
|
const {
|
|
71
53
|
url
|
|
72
54
|
} = sources[sourceName];
|
|
73
|
-
|
|
74
55
|
if (url) {
|
|
75
|
-
var _sourceJson$tiles;
|
|
76
|
-
|
|
77
56
|
const sourceUrl = this._proxyPath + this._getAbsoluteUrl(url);
|
|
78
|
-
|
|
79
57
|
const extendedUrl = this._emsClient.extendUrlWithParams(sourceUrl);
|
|
80
|
-
|
|
81
58
|
const sourceJson = await this._emsClient.getManifest(extendedUrl);
|
|
82
|
-
const tiles = sourceJson
|
|
59
|
+
const tiles = sourceJson?.tiles?.map(tileUrl => {
|
|
83
60
|
const directUrl = this._proxyPath + this._getAbsoluteUrl(tileUrl);
|
|
84
|
-
|
|
85
61
|
return this._emsClient.extendUrlWithParams(directUrl);
|
|
86
62
|
});
|
|
87
|
-
inlinedSources[sourceName] = {
|
|
63
|
+
inlinedSources[sourceName] = {
|
|
64
|
+
...sourceJson,
|
|
88
65
|
type: 'vector',
|
|
89
66
|
tiles
|
|
90
67
|
};
|
|
91
68
|
}
|
|
92
69
|
}
|
|
93
|
-
|
|
94
|
-
|
|
70
|
+
return {
|
|
71
|
+
...vectorJson,
|
|
95
72
|
sources: inlinedSources,
|
|
96
73
|
sprite: await this._getSpriteSheetRootPath(),
|
|
97
74
|
glyphs: await this._getUrlTemplateForGlyphs()
|
|
@@ -100,43 +77,35 @@ class TMSService extends _ems_service.AbstractEmsService {
|
|
|
100
77
|
return;
|
|
101
78
|
}
|
|
102
79
|
}));
|
|
103
|
-
|
|
104
80
|
this._config = config;
|
|
105
81
|
}
|
|
82
|
+
|
|
106
83
|
/*
|
|
107
84
|
This method returns an array of objects with the layers and the new
|
|
108
85
|
layout['text-field'] to apply using map.setLayoutProperty
|
|
109
86
|
*/
|
|
110
|
-
|
|
111
|
-
|
|
112
87
|
static transformLanguageProperty(layer, lang) {
|
|
113
88
|
const supportedLang = this.SupportedLanguages.find(l => l.key === lang);
|
|
114
|
-
|
|
115
89
|
if (layer.type === 'symbol' && layer.layout !== undefined && supportedLang !== undefined) {
|
|
116
90
|
const omtLang = supportedLang.omt;
|
|
117
91
|
const textField = layer.layout['text-field'];
|
|
118
|
-
|
|
119
92
|
if (textField && typeof textField === 'string') {
|
|
120
93
|
return TMSService._getTextField(textField, omtLang);
|
|
121
94
|
}
|
|
122
95
|
}
|
|
123
|
-
|
|
124
96
|
return;
|
|
125
97
|
}
|
|
98
|
+
|
|
126
99
|
/*
|
|
127
100
|
This method returns an array of objects per layer, containing a list of
|
|
128
101
|
properties with new colors to apply using map.setPaintProperty
|
|
129
102
|
*/
|
|
130
|
-
|
|
131
|
-
|
|
132
103
|
static transformColorProperties(layer, color, operation, percentage) {
|
|
133
104
|
if (['background', 'fill', 'line', 'symbol'].indexOf(layer.type) !== -1 && layer.paint) {
|
|
134
105
|
const paint = layer.paint;
|
|
135
|
-
|
|
136
106
|
if (layer.type === 'symbol' && Object.keys(paint).length === 0) {
|
|
137
107
|
paint['text-color'] = 'rgb(0,0,0)';
|
|
138
108
|
}
|
|
139
|
-
|
|
140
109
|
const types = Object.keys(paint).filter(key => {
|
|
141
110
|
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;
|
|
142
111
|
});
|
|
@@ -151,29 +120,26 @@ class TMSService extends _ems_service.AbstractEmsService {
|
|
|
151
120
|
return [];
|
|
152
121
|
}
|
|
153
122
|
}
|
|
154
|
-
|
|
155
123
|
static _getTextField(label, lang) {
|
|
156
124
|
// Capture {name:xx} labels
|
|
157
125
|
const labelMatch = label.match(/\{name([:_])(.{2})\}/);
|
|
158
|
-
|
|
159
126
|
if (labelMatch && labelMatch[1] != lang) {
|
|
160
127
|
// Only apply if the languages are different
|
|
161
128
|
return ['coalesce', ['get', `name:${lang}`], ['get', `name${labelMatch[1]}${labelMatch[2]}`]];
|
|
162
129
|
} else if (label.includes('latin') && label.includes('nonlatin')) {
|
|
163
130
|
// Capture the common pattern {name:latin}\n{name:nonlatin}
|
|
164
131
|
return ['coalesce', ['get', `name:${lang}`], ['concat', ['get', 'name:latin'], '\n', ['get', 'name:nonlatin']]];
|
|
165
|
-
}
|
|
166
|
-
|
|
132
|
+
}
|
|
167
133
|
|
|
134
|
+
// If no case is found, return the input label
|
|
168
135
|
return label;
|
|
169
136
|
}
|
|
170
|
-
|
|
171
137
|
async getDefaultRasterStyle() {
|
|
172
138
|
const tileJson = await this._getRasterStyleJson();
|
|
173
|
-
|
|
174
139
|
if (tileJson) {
|
|
175
140
|
const tiles = tileJson.tiles.map(tile => this._proxyPath + this._getAbsoluteUrl(tile));
|
|
176
|
-
return {
|
|
141
|
+
return {
|
|
142
|
+
...tileJson,
|
|
177
143
|
...{
|
|
178
144
|
tiles
|
|
179
145
|
}
|
|
@@ -182,49 +148,36 @@ class TMSService extends _ems_service.AbstractEmsService {
|
|
|
182
148
|
return;
|
|
183
149
|
}
|
|
184
150
|
}
|
|
185
|
-
|
|
186
151
|
async getUrlTemplate() {
|
|
187
152
|
const tileJson = await this._getRasterStyleJson();
|
|
188
|
-
|
|
189
153
|
if (tileJson) {
|
|
190
154
|
const directUrl = this._proxyPath + this._getAbsoluteUrl(tileJson.tiles[0]);
|
|
191
|
-
|
|
192
155
|
return this._emsClient.extendUrlWithParams(directUrl);
|
|
193
156
|
} else {
|
|
194
157
|
return '';
|
|
195
158
|
}
|
|
196
159
|
}
|
|
197
|
-
|
|
198
160
|
async getUrlTemplateForVector(sourceId) {
|
|
199
|
-
var _tileJson$sources$sou, _tileJson$sources$sou2;
|
|
200
|
-
|
|
201
161
|
const tileJson = await this._getVectorStyleJsonInlined();
|
|
202
|
-
const url = tileJson
|
|
203
|
-
|
|
162
|
+
const url = tileJson?.sources[sourceId]?.tiles?.pop();
|
|
204
163
|
if (url) {
|
|
205
164
|
const directUrl = this._proxyPath + this._getAbsoluteUrl(url);
|
|
206
|
-
|
|
207
165
|
return this._emsClient.extendUrlWithParams(directUrl);
|
|
208
166
|
} else {
|
|
209
167
|
return '';
|
|
210
168
|
}
|
|
211
169
|
}
|
|
212
|
-
|
|
213
170
|
async getVectorStyleSheet() {
|
|
214
171
|
return await this._getVectorStyleJsonInlined();
|
|
215
172
|
}
|
|
216
|
-
|
|
217
173
|
async getVectorStyleSheetRaw() {
|
|
218
174
|
return await this._getVectorStyleJsonRaw();
|
|
219
175
|
}
|
|
220
|
-
|
|
221
176
|
async getSpriteSheetMeta(isRetina = false) {
|
|
222
177
|
const metaUrl = await this.getSpriteSheetJsonPath(isRetina);
|
|
223
178
|
const spritePngs = await this.getSpriteSheetPngPath(isRetina);
|
|
224
|
-
|
|
225
179
|
if (metaUrl && spritePngs) {
|
|
226
180
|
const metaUrlExtended = this._emsClient.extendUrlWithParams(metaUrl);
|
|
227
|
-
|
|
228
181
|
const jsonMeta = await this._emsClient.getManifest(metaUrlExtended);
|
|
229
182
|
return {
|
|
230
183
|
png: spritePngs,
|
|
@@ -234,10 +187,8 @@ class TMSService extends _ems_service.AbstractEmsService {
|
|
|
234
187
|
return;
|
|
235
188
|
}
|
|
236
189
|
}
|
|
237
|
-
|
|
238
190
|
async getSpriteSheetJsonPath(isRetina = false) {
|
|
239
191
|
const spriteSheetRootPath = await this._getSpriteSheetRootPath();
|
|
240
|
-
|
|
241
192
|
if (spriteSheetRootPath) {
|
|
242
193
|
const suffix = isRetina ? '@2x' : '';
|
|
243
194
|
return spriteSheetRootPath + suffix + '.json';
|
|
@@ -245,10 +196,8 @@ class TMSService extends _ems_service.AbstractEmsService {
|
|
|
245
196
|
return '';
|
|
246
197
|
}
|
|
247
198
|
}
|
|
248
|
-
|
|
249
199
|
async getSpriteSheetPngPath(isRetina = false) {
|
|
250
200
|
const spriteSheetRootPath = await this._getSpriteSheetRootPath();
|
|
251
|
-
|
|
252
201
|
if (spriteSheetRootPath) {
|
|
253
202
|
const suffix = isRetina ? '@2x' : '';
|
|
254
203
|
return spriteSheetRootPath + suffix + '.png';
|
|
@@ -256,11 +205,9 @@ class TMSService extends _ems_service.AbstractEmsService {
|
|
|
256
205
|
return '';
|
|
257
206
|
}
|
|
258
207
|
}
|
|
259
|
-
|
|
260
208
|
getDisplayName() {
|
|
261
209
|
return this._emsClient.getValueInLanguage(this._config.name);
|
|
262
210
|
}
|
|
263
|
-
|
|
264
211
|
async getMinZoom(format = 'vector') {
|
|
265
212
|
switch (format) {
|
|
266
213
|
case 'vector':
|
|
@@ -272,18 +219,15 @@ class TMSService extends _ems_service.AbstractEmsService {
|
|
|
272
219
|
return Math.min(...Object.values(sources).map(({
|
|
273
220
|
minzoom
|
|
274
221
|
}) => minzoom).filter(minzoom => Number.isFinite(minzoom)));
|
|
275
|
-
|
|
276
222
|
case 'raster':
|
|
277
223
|
const {
|
|
278
224
|
minzoom
|
|
279
225
|
} = (await this._getRasterStyleJson()) || {};
|
|
280
226
|
return minzoom;
|
|
281
|
-
|
|
282
227
|
default:
|
|
283
228
|
return;
|
|
284
229
|
}
|
|
285
230
|
}
|
|
286
|
-
|
|
287
231
|
async getMaxZoom(format = 'vector') {
|
|
288
232
|
switch (format) {
|
|
289
233
|
case 'vector':
|
|
@@ -295,78 +239,66 @@ class TMSService extends _ems_service.AbstractEmsService {
|
|
|
295
239
|
return Math.max(...Object.values(sources).map(({
|
|
296
240
|
maxzoom
|
|
297
241
|
}) => maxzoom).filter(maxzoom => Number.isFinite(maxzoom)));
|
|
298
|
-
|
|
299
242
|
case 'raster':
|
|
300
243
|
const {
|
|
301
244
|
maxzoom
|
|
302
245
|
} = (await this._getRasterStyleJson()) || {};
|
|
303
246
|
return maxzoom;
|
|
304
|
-
|
|
305
247
|
default:
|
|
306
248
|
return;
|
|
307
249
|
}
|
|
308
250
|
}
|
|
309
|
-
|
|
310
251
|
getId() {
|
|
311
252
|
return this._config.id;
|
|
312
253
|
}
|
|
313
|
-
|
|
314
254
|
hasId(id) {
|
|
315
255
|
return this._config.id === id;
|
|
316
256
|
}
|
|
317
|
-
|
|
318
257
|
getApiUrl() {
|
|
319
258
|
return this._emsClient.getTileApiUrl();
|
|
320
259
|
}
|
|
321
|
-
|
|
322
260
|
_getStyleUrlForLocale(formatType) {
|
|
323
261
|
let vectorFormats = this._getFormats(formatType, this._emsClient.getLocale());
|
|
324
|
-
|
|
325
262
|
if (!vectorFormats.length) {
|
|
326
263
|
//fallback to default locale
|
|
327
264
|
vectorFormats = this._getFormats(formatType, this._emsClient.getDefaultLocale());
|
|
328
265
|
}
|
|
329
|
-
|
|
330
266
|
if (!vectorFormats.length) {
|
|
331
267
|
// eslint-disable-next-line max-len
|
|
332
268
|
throw new Error(`Cannot find ${formatType} tile layer for locale ${this._emsClient.getLocale()} or ${this._emsClient.getDefaultLocale()}`);
|
|
333
269
|
}
|
|
334
|
-
|
|
335
270
|
const defaultStyle = vectorFormats[0];
|
|
336
|
-
|
|
337
271
|
if (defaultStyle && defaultStyle.hasOwnProperty('url')) {
|
|
338
272
|
return defaultStyle.url;
|
|
339
273
|
}
|
|
340
274
|
}
|
|
341
|
-
|
|
342
275
|
_getFormats(formatType, locale) {
|
|
343
276
|
return this._config.formats.filter(format => format.locale === locale && format.format === formatType);
|
|
344
277
|
}
|
|
345
|
-
|
|
346
278
|
async _getSpriteSheetRootPath() {
|
|
347
279
|
const vectorStyleJson = await this._getVectorStyleJsonRaw();
|
|
348
|
-
|
|
349
|
-
if (vectorStyleJson !== null && vectorStyleJson !== void 0 && vectorStyleJson.sprite) {
|
|
280
|
+
if (vectorStyleJson?.sprite) {
|
|
350
281
|
return this._proxyPath + this._getAbsoluteUrl(vectorStyleJson.sprite);
|
|
351
282
|
} else {
|
|
352
283
|
return '';
|
|
353
284
|
}
|
|
354
285
|
}
|
|
355
|
-
|
|
356
286
|
async _getUrlTemplateForGlyphs() {
|
|
357
287
|
const vectorStyleJson = await this._getVectorStyleJsonRaw();
|
|
358
|
-
|
|
359
|
-
if (vectorStyleJson !== null && vectorStyleJson !== void 0 && vectorStyleJson.glyphs) {
|
|
288
|
+
if (vectorStyleJson?.glyphs) {
|
|
360
289
|
return this._proxyPath + this._getAbsoluteUrl(vectorStyleJson.glyphs);
|
|
361
290
|
} else {
|
|
362
291
|
return '';
|
|
363
292
|
}
|
|
364
293
|
}
|
|
365
|
-
|
|
366
294
|
}
|
|
367
|
-
|
|
368
295
|
exports.TMSService = TMSService;
|
|
369
|
-
|
|
296
|
+
/*
|
|
297
|
+
List of supported languages with labels and OMT codes extracted
|
|
298
|
+
from https://openmaptiles.org/languages
|
|
299
|
+
Keys are values for i18.locale from Kibana settings
|
|
300
|
+
and OMT codes for the rest.
|
|
301
|
+
*/
|
|
370
302
|
_defineProperty(TMSService, "SupportedLanguages", [{
|
|
371
303
|
key: 'ar',
|
|
372
304
|
omt: 'ar'
|
|
@@ -545,7 +477,9 @@ _defineProperty(TMSService, "SupportedLanguages", [{
|
|
|
545
477
|
key: 'zh-cn',
|
|
546
478
|
omt: 'zh'
|
|
547
479
|
}]);
|
|
548
|
-
|
|
480
|
+
/*
|
|
481
|
+
Suggested default operations for the different EMS styles
|
|
482
|
+
*/
|
|
549
483
|
_defineProperty(TMSService, "colorOperationDefaults", [{
|
|
550
484
|
style: 'road_map',
|
|
551
485
|
operation: 'mix',
|