@elastic/ems-client 8.5.1 → 8.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.buildkite/pipeline.yml +1 -1
- package/.husky/pre-commit +1 -0
- package/CHANGELOG.md +5 -0
- package/eslint.config.mjs +25 -0
- package/package.json +28 -28
- package/src/ems_client.ts +6 -2
- package/src/tms_service.ts +18 -12
- package/target/ems_client.d.ts +16 -16
- package/target/ems_client.js +318 -0
- package/target/ems_service.js +47 -0
- package/target/file_layer.d.ts +1 -1
- package/target/file_layer.js +176 -0
- package/target/index.js +16 -0
- package/target/node/ems_client.js +15 -11
- package/target/node/ems_service.js +8 -8
- package/target/node/file_layer.js +10 -10
- package/target/node/tms_service.js +43 -36
- package/target/node/utils.js +1 -1
- package/target/origin.d.ts +4 -0
- package/target/tms_service.d.ts +5 -5
- package/target/tms_service.js +409 -0
- package/target/utils.d.ts +3 -3
- package/target/utils.js +86 -0
- package/target/web/ems_client.js +26 -27
- package/target/web/ems_service.js +7 -8
- package/target/web/file_layer.js +20 -22
- package/target/web/tms_service.js +44 -49
- package/test/__snapshots__/ems_client.test.ts.snap +24 -24
- package/test/ems_client_util.ts +1 -1
- package/.eslintignore +0 -1
- package/.eslintrc +0 -18
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
4
|
+
* or more contributor license agreements. Licensed under the Elastic License
|
|
5
|
+
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
6
|
+
* 2.0.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.AbstractEmsService = void 0;
|
|
10
|
+
const utils_1 = require("./utils");
|
|
11
|
+
class AbstractEmsService {
|
|
12
|
+
constructor(config, emsClient, proxyPath) {
|
|
13
|
+
/**
|
|
14
|
+
* Checks if url is absolute. If not, prepend the basePath.
|
|
15
|
+
*/
|
|
16
|
+
this._getAbsoluteUrl = (url) => {
|
|
17
|
+
if (/^https?:\/\//.test(url)) {
|
|
18
|
+
return url;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
return (0, utils_1.toAbsoluteUrl)(this.getApiUrl(), url);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
this._config = config;
|
|
25
|
+
this._emsClient = emsClient;
|
|
26
|
+
this._proxyPath = proxyPath;
|
|
27
|
+
}
|
|
28
|
+
getAttributions() {
|
|
29
|
+
return this._config.attribution.map((attribution) => {
|
|
30
|
+
const url = this._emsClient.getValueInLanguage(attribution.url);
|
|
31
|
+
const label = this._emsClient.getValueInLanguage(attribution.label);
|
|
32
|
+
return {
|
|
33
|
+
url: url,
|
|
34
|
+
label: label,
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
getMarkdownAttribution() {
|
|
39
|
+
const attributions = this._config.attribution.map((attribution) => {
|
|
40
|
+
const url = this._emsClient.getValueInLanguage(attribution.url);
|
|
41
|
+
const label = this._emsClient.getValueInLanguage(attribution.label);
|
|
42
|
+
return `[${label}](${url})`;
|
|
43
|
+
});
|
|
44
|
+
return attributions.join('|');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.AbstractEmsService = AbstractEmsService;
|
package/target/file_layer.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare enum EMSFormatType {
|
|
|
5
5
|
geojson = "geojson",
|
|
6
6
|
topojson = "topojson"
|
|
7
7
|
}
|
|
8
|
-
export
|
|
8
|
+
export type EMSFormatTypeStrings = keyof typeof EMSFormatType;
|
|
9
9
|
export declare class FileLayer extends AbstractEmsService {
|
|
10
10
|
protected readonly _config: FileLayerConfig;
|
|
11
11
|
constructor(config: FileLayerConfig, emsClient: EMSClient, proxyPath: string);
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
4
|
+
* or more contributor license agreements. Licensed under the Elastic License
|
|
5
|
+
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
6
|
+
* 2.0.
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
25
|
+
if (mod && mod.__esModule) return mod;
|
|
26
|
+
var result = {};
|
|
27
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
28
|
+
__setModuleDefault(result, mod);
|
|
29
|
+
return result;
|
|
30
|
+
};
|
|
31
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
32
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
33
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
34
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
35
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
36
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
37
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
41
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
42
|
+
};
|
|
43
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
+
exports.FileLayer = exports.EMSFormatType = void 0;
|
|
45
|
+
const url_1 = __importDefault(require("url"));
|
|
46
|
+
const ems_service_1 = require("./ems_service");
|
|
47
|
+
const topojson = __importStar(require("topojson-client"));
|
|
48
|
+
var EMSFormatType;
|
|
49
|
+
(function (EMSFormatType) {
|
|
50
|
+
EMSFormatType["geojson"] = "geojson";
|
|
51
|
+
EMSFormatType["topojson"] = "topojson";
|
|
52
|
+
})(EMSFormatType || (exports.EMSFormatType = EMSFormatType = {}));
|
|
53
|
+
class FileLayer extends ems_service_1.AbstractEmsService {
|
|
54
|
+
constructor(config, emsClient, proxyPath) {
|
|
55
|
+
super(config, emsClient, proxyPath);
|
|
56
|
+
this._config = config;
|
|
57
|
+
}
|
|
58
|
+
getGeoJson() {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
var _a;
|
|
61
|
+
const cachedGeoJson = this._emsClient.getCachedGeoJson(this.getId());
|
|
62
|
+
if (cachedGeoJson) {
|
|
63
|
+
return cachedGeoJson;
|
|
64
|
+
}
|
|
65
|
+
const format = this.getDefaultFormatType();
|
|
66
|
+
const fetchUrl = this.getDefaultFormatUrl();
|
|
67
|
+
let geojson;
|
|
68
|
+
const fetchedJson = yield this._emsClient.getManifest(fetchUrl);
|
|
69
|
+
if (fetchedJson) {
|
|
70
|
+
if (format === 'geojson') {
|
|
71
|
+
geojson = fetchedJson;
|
|
72
|
+
}
|
|
73
|
+
else if (format === 'topojson') {
|
|
74
|
+
const meta = this.getDefaultFormatMeta();
|
|
75
|
+
const featureCollectionPath = (_a = meta === null || meta === void 0 ? void 0 : meta.feature_collection_path) !== null && _a !== void 0 ? _a : 'data';
|
|
76
|
+
// @ts-expect-error see https://github.com/DefinitelyTyped/DefinitelyTyped/pull/52156
|
|
77
|
+
geojson = topojson.feature(fetchedJson, featureCollectionPath);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
this._emsClient.cacheGeoJson(this.getId(), geojson);
|
|
83
|
+
return geojson;
|
|
84
|
+
}
|
|
85
|
+
return;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
getFields() {
|
|
89
|
+
return this._config.fields;
|
|
90
|
+
}
|
|
91
|
+
getFieldsInLanguage() {
|
|
92
|
+
return this.getFields().map((field) => {
|
|
93
|
+
return {
|
|
94
|
+
type: field.type,
|
|
95
|
+
name: field.id,
|
|
96
|
+
description: this._emsClient.getValueInLanguage(field.label),
|
|
97
|
+
};
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
getDisplayName() {
|
|
101
|
+
const layerName = this._emsClient.getValueInLanguage(this._config.layer_name);
|
|
102
|
+
return layerName ? layerName : '';
|
|
103
|
+
}
|
|
104
|
+
getId() {
|
|
105
|
+
return this._config.layer_id;
|
|
106
|
+
}
|
|
107
|
+
hasId(id) {
|
|
108
|
+
const matchesLegacyId = this._config.legacy_ids.indexOf(id) >= 0;
|
|
109
|
+
return this._config.layer_id === id || matchesLegacyId;
|
|
110
|
+
}
|
|
111
|
+
getEMSHotLink() {
|
|
112
|
+
const landingPageString = this._emsClient.getLandingPageUrl();
|
|
113
|
+
const urlObject = url_1.default.parse(landingPageString, true);
|
|
114
|
+
urlObject.hash = `file/${this.getId()}`;
|
|
115
|
+
urlObject.query = Object.assign(Object.assign({}, urlObject.query), { locale: this._emsClient.getLocale() });
|
|
116
|
+
return url_1.default.format(urlObject);
|
|
117
|
+
}
|
|
118
|
+
getDefaultFormatType() {
|
|
119
|
+
const format = this._getDefaultFormat();
|
|
120
|
+
return format.type;
|
|
121
|
+
}
|
|
122
|
+
getFormatOfType(type) {
|
|
123
|
+
const format = this._getFormatOfType(type);
|
|
124
|
+
return format.type;
|
|
125
|
+
}
|
|
126
|
+
getDefaultFormatMeta() {
|
|
127
|
+
const format = this._getDefaultFormat();
|
|
128
|
+
return this._getFormatMeta(format);
|
|
129
|
+
}
|
|
130
|
+
getFormatOfTypeMeta(type) {
|
|
131
|
+
const format = this._getFormatOfType(type);
|
|
132
|
+
return this._getFormatMeta(format);
|
|
133
|
+
}
|
|
134
|
+
getDefaultFormatUrl() {
|
|
135
|
+
const format = this._getDefaultFormat();
|
|
136
|
+
return this._getFormatUrl(format);
|
|
137
|
+
}
|
|
138
|
+
getFormatOfTypeUrl(type) {
|
|
139
|
+
const format = this._getFormatOfType(type);
|
|
140
|
+
return this._getFormatUrl(format);
|
|
141
|
+
}
|
|
142
|
+
getCreatedAt() {
|
|
143
|
+
return this._config.created_at;
|
|
144
|
+
}
|
|
145
|
+
getApiUrl() {
|
|
146
|
+
return this._emsClient.getFileApiUrl();
|
|
147
|
+
}
|
|
148
|
+
_getFormatUrl(format) {
|
|
149
|
+
const url = this._proxyPath + this._getAbsoluteUrl(format.url);
|
|
150
|
+
return this._emsClient.extendUrlWithParams(url);
|
|
151
|
+
}
|
|
152
|
+
_getFormatMeta(format) {
|
|
153
|
+
if ('meta' in format) {
|
|
154
|
+
return format.meta;
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
_getDefaultFormat() {
|
|
161
|
+
const defaultFormat = this._config.formats.find((format) => {
|
|
162
|
+
return format.legacy_default;
|
|
163
|
+
});
|
|
164
|
+
if (defaultFormat) {
|
|
165
|
+
return defaultFormat;
|
|
166
|
+
}
|
|
167
|
+
return this._config.formats[0];
|
|
168
|
+
}
|
|
169
|
+
_getFormatOfType(type) {
|
|
170
|
+
const requestedFormat = this._config.formats.find((format) => {
|
|
171
|
+
return format.type === type;
|
|
172
|
+
});
|
|
173
|
+
return requestedFormat || this._getDefaultFormat();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
exports.FileLayer = FileLayer;
|
package/target/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
4
|
+
* or more contributor license agreements. Licensed under the Elastic License
|
|
5
|
+
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
6
|
+
* 2.0.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.TMSService = exports.FileLayer = exports.LATEST_API_URL_PATH = exports.EMSClient = void 0;
|
|
10
|
+
var ems_client_1 = require("./ems_client");
|
|
11
|
+
Object.defineProperty(exports, "EMSClient", { enumerable: true, get: function () { return ems_client_1.EMSClient; } });
|
|
12
|
+
Object.defineProperty(exports, "LATEST_API_URL_PATH", { enumerable: true, get: function () { return ems_client_1.LATEST_API_URL_PATH; } });
|
|
13
|
+
var file_layer_1 = require("./file_layer");
|
|
14
|
+
Object.defineProperty(exports, "FileLayer", { enumerable: true, get: function () { return file_layer_1.FileLayer; } });
|
|
15
|
+
var tms_service_1 = require("./tms_service");
|
|
16
|
+
Object.defineProperty(exports, "TMSService", { enumerable: true, get: function () { return tms_service_1.TMSService; } });
|
|
@@ -14,15 +14,15 @@ var _minor = _interopRequireDefault(require("semver/functions/minor"));
|
|
|
14
14
|
var _url = require("url");
|
|
15
15
|
var _utils = require("./utils");
|
|
16
16
|
var _lruCache = _interopRequireDefault(require("lru-cache"));
|
|
17
|
-
function _interopRequireDefault(
|
|
18
|
-
function _defineProperty(
|
|
19
|
-
function _toPropertyKey(
|
|
20
|
-
function _toPrimitive(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
18
|
+
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; }
|
|
19
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
20
|
+
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); } /*
|
|
21
|
+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
22
|
+
* or more contributor license agreements. Licensed under the Elastic License
|
|
23
|
+
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
24
|
+
* 2.0.
|
|
25
|
+
*/
|
|
26
26
|
const REST_API_REGEX = /\d{4}-\d{2}-\d{2}/;
|
|
27
27
|
const LATEST_API_URL_PATH = exports.LATEST_API_URL_PATH = 'latest';
|
|
28
28
|
/**
|
|
@@ -154,7 +154,11 @@ class EMSClient {
|
|
|
154
154
|
if (!response.ok) {
|
|
155
155
|
throw new Error(response.statusText);
|
|
156
156
|
}
|
|
157
|
-
|
|
157
|
+
if (response) {
|
|
158
|
+
return await response.json();
|
|
159
|
+
} else {
|
|
160
|
+
throw new Error('Response not found');
|
|
161
|
+
}
|
|
158
162
|
} catch (e) {
|
|
159
163
|
if (e instanceof Error) {
|
|
160
164
|
throw e;
|
|
@@ -171,7 +175,7 @@ class EMSClient {
|
|
|
171
175
|
*/
|
|
172
176
|
addQueryParams(additionalQueryParams) {
|
|
173
177
|
for (const key in additionalQueryParams) {
|
|
174
|
-
if (
|
|
178
|
+
if (Object.prototype.hasOwnProperty.call(additionalQueryParams, key)) {
|
|
175
179
|
if (additionalQueryParams[key] !== this._queryParams[key]) {
|
|
176
180
|
//changes detected.
|
|
177
181
|
this._queryParams = _lodash.default.assign({}, this._queryParams, additionalQueryParams);
|
|
@@ -5,14 +5,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.AbstractEmsService = void 0;
|
|
7
7
|
var _utils = require("./utils");
|
|
8
|
-
function _defineProperty(
|
|
9
|
-
function _toPropertyKey(
|
|
10
|
-
function _toPrimitive(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
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; }
|
|
9
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
10
|
+
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); } /*
|
|
11
|
+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
12
|
+
* or more contributor license agreements. Licensed under the Elastic License
|
|
13
|
+
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
14
|
+
* 2.0.
|
|
15
|
+
*/
|
|
16
16
|
class AbstractEmsService {
|
|
17
17
|
constructor(config, emsClient, proxyPath) {
|
|
18
18
|
_defineProperty(this, "_emsClient", void 0);
|
|
@@ -8,16 +8,16 @@ var _url = _interopRequireDefault(require("url"));
|
|
|
8
8
|
var _ems_service = require("./ems_service");
|
|
9
9
|
var topojson = _interopRequireWildcard(require("topojson-client"));
|
|
10
10
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
11
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u &&
|
|
12
|
-
function _interopRequireDefault(
|
|
13
|
-
function _defineProperty(
|
|
14
|
-
function _toPropertyKey(
|
|
15
|
-
function _toPrimitive(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
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; }
|
|
14
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
15
|
+
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); } /*
|
|
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
21
|
let EMSFormatType = exports.EMSFormatType = /*#__PURE__*/function (EMSFormatType) {
|
|
22
22
|
EMSFormatType["geojson"] = "geojson";
|
|
23
23
|
EMSFormatType["topojson"] = "topojson";
|
|
@@ -7,15 +7,15 @@ exports.TMSService = void 0;
|
|
|
7
7
|
var _lodash = _interopRequireDefault(require("lodash"));
|
|
8
8
|
var _ems_service = require("./ems_service");
|
|
9
9
|
var _utils = require("./utils");
|
|
10
|
-
function _interopRequireDefault(
|
|
11
|
-
function _defineProperty(
|
|
12
|
-
function _toPropertyKey(
|
|
13
|
-
function _toPrimitive(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
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; }
|
|
12
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
13
|
+
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); } /*
|
|
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
|
+
*/
|
|
19
19
|
class TMSService extends _ems_service.AbstractEmsService {
|
|
20
20
|
constructor(config, emsClient, proxyPath) {
|
|
21
21
|
super(config, emsClient, proxyPath);
|
|
@@ -211,19 +211,23 @@ class TMSService extends _ems_service.AbstractEmsService {
|
|
|
211
211
|
async getMinZoom(format = 'vector') {
|
|
212
212
|
switch (format) {
|
|
213
213
|
case 'vector':
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
214
|
+
{
|
|
215
|
+
const {
|
|
216
|
+
sources
|
|
217
|
+
} = (await this._getVectorStyleJsonInlined()) || {
|
|
218
|
+
sources: {}
|
|
219
|
+
};
|
|
220
|
+
return Math.min(...Object.values(sources).map(s => {
|
|
221
|
+
return s && s instanceof Object && 'minzoom' in s ? s['minzoom'] : null;
|
|
222
|
+
}).filter(minzoom => Number.isFinite(minzoom)));
|
|
223
|
+
}
|
|
222
224
|
case 'raster':
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
225
|
+
{
|
|
226
|
+
const {
|
|
227
|
+
minzoom
|
|
228
|
+
} = (await this._getRasterStyleJson()) || {};
|
|
229
|
+
return minzoom;
|
|
230
|
+
}
|
|
227
231
|
default:
|
|
228
232
|
return;
|
|
229
233
|
}
|
|
@@ -231,19 +235,23 @@ class TMSService extends _ems_service.AbstractEmsService {
|
|
|
231
235
|
async getMaxZoom(format = 'vector') {
|
|
232
236
|
switch (format) {
|
|
233
237
|
case 'vector':
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
238
|
+
{
|
|
239
|
+
const {
|
|
240
|
+
sources
|
|
241
|
+
} = (await this._getVectorStyleJsonInlined()) || {
|
|
242
|
+
sources: {}
|
|
243
|
+
};
|
|
244
|
+
return Math.max(...Object.values(sources).map(s => {
|
|
245
|
+
return s && s instanceof Object && 'maxzoom' in s ? s['maxzoom'] : null;
|
|
246
|
+
}).filter(maxzoom => Number.isFinite(maxzoom)));
|
|
247
|
+
}
|
|
242
248
|
case 'raster':
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
249
|
+
{
|
|
250
|
+
const {
|
|
251
|
+
maxzoom
|
|
252
|
+
} = (await this._getRasterStyleJson()) || {};
|
|
253
|
+
return maxzoom;
|
|
254
|
+
}
|
|
247
255
|
default:
|
|
248
256
|
return;
|
|
249
257
|
}
|
|
@@ -264,11 +272,10 @@ class TMSService extends _ems_service.AbstractEmsService {
|
|
|
264
272
|
vectorFormats = this._getFormats(formatType, this._emsClient.getDefaultLocale());
|
|
265
273
|
}
|
|
266
274
|
if (!vectorFormats.length) {
|
|
267
|
-
// eslint-disable-next-line max-len
|
|
268
275
|
throw new Error(`Cannot find ${formatType} tile layer for locale ${this._emsClient.getLocale()} or ${this._emsClient.getDefaultLocale()}`);
|
|
269
276
|
}
|
|
270
277
|
const defaultStyle = vectorFormats[0];
|
|
271
|
-
if (defaultStyle &&
|
|
278
|
+
if (defaultStyle && Object.prototype.hasOwnProperty.call(defaultStyle, 'url')) {
|
|
272
279
|
return defaultStyle.url;
|
|
273
280
|
}
|
|
274
281
|
}
|
|
@@ -278,7 +285,7 @@ class TMSService extends _ems_service.AbstractEmsService {
|
|
|
278
285
|
async _getSpriteSheetRootPath() {
|
|
279
286
|
const vectorStyleJson = await this._getVectorStyleJsonRaw();
|
|
280
287
|
if (vectorStyleJson?.sprite) {
|
|
281
|
-
return this._proxyPath + this._getAbsoluteUrl(vectorStyleJson.sprite);
|
|
288
|
+
return this._proxyPath + this._getAbsoluteUrl(vectorStyleJson.sprite.toString());
|
|
282
289
|
} else {
|
|
283
290
|
return '';
|
|
284
291
|
}
|
package/target/node/utils.js
CHANGED
|
@@ -7,7 +7,7 @@ exports.colorizeColor = colorizeColor;
|
|
|
7
7
|
exports.desaturateColor = desaturateColor;
|
|
8
8
|
exports.toAbsoluteUrl = toAbsoluteUrl;
|
|
9
9
|
var _chromaJs = _interopRequireDefault(require("chroma-js"));
|
|
10
|
-
function _interopRequireDefault(
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
11
|
/*
|
|
12
12
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
13
13
|
* or more contributor license agreements. Licensed under the Elastic License
|
package/target/tms_service.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { DataDrivenPropertyValueSpecification, FormattedSpecification, LayerSpec
|
|
|
2
2
|
import { EMSClient, TMSServiceConfig } from './ems_client';
|
|
3
3
|
import { AbstractEmsService } from './ems_service';
|
|
4
4
|
import { layerPaintProperty, blendMode, mbColorDefinition } from './utils';
|
|
5
|
-
export
|
|
5
|
+
export type EmsSprite = {
|
|
6
6
|
height: number;
|
|
7
7
|
pixelRatio: number;
|
|
8
8
|
width: number;
|
|
@@ -10,16 +10,16 @@ export declare type EmsSprite = {
|
|
|
10
10
|
y: number;
|
|
11
11
|
sdf?: boolean;
|
|
12
12
|
};
|
|
13
|
-
export
|
|
13
|
+
export type EmsSpriteSheet = {
|
|
14
14
|
[spriteName: string]: EmsSprite;
|
|
15
15
|
};
|
|
16
|
-
|
|
16
|
+
type EmsVectorSources = {
|
|
17
17
|
[sourceName: string]: VectorSourceSpecification;
|
|
18
18
|
};
|
|
19
|
-
|
|
19
|
+
type EmsVectorStyle = StyleSpecification & {
|
|
20
20
|
sources: EmsVectorSources;
|
|
21
21
|
};
|
|
22
|
-
|
|
22
|
+
type EmsRasterStyle = {
|
|
23
23
|
tilejson: string;
|
|
24
24
|
name: string;
|
|
25
25
|
attribution: string;
|