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