@elastic/ems-client 8.5.0 → 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/build.sh +0 -0
- package/.buildkite/pipeline.yml +3 -1
- package/.github/CODEOWNERS +2 -0
- package/.husky/pre-commit +1 -0
- package/.nvmrc +1 -1
- package/CHANGELOG.md +19 -2
- package/CONTRIBUTING.md +4 -5
- package/docs/openapi/Makefile +35 -0
- package/docs/openapi/README.md +41 -0
- package/docs/openapi/components/attribution.yaml +19 -0
- package/docs/openapi/components/examples/file_service_200.json +1 -0
- package/docs/openapi/components/examples/file_service_404.xml +1 -0
- package/docs/openapi/components/examples/tile_service_200.json +1 -0
- package/docs/openapi/components/examples/tile_service_404.html +10 -0
- package/docs/openapi/ems_file_service/bundled.json +533 -0
- package/docs/openapi/ems_file_service/bundled.yaml +347 -0
- package/docs/openapi/ems_file_service/entrypoint.yaml +152 -0
- package/docs/openapi/ems_tile_service/bundled.json +307 -0
- package/docs/openapi/ems_tile_service/bundled.yaml +195 -0
- package/docs/openapi/ems_tile_service/entrypoint.yaml +92 -0
- package/eslint.config.mjs +25 -0
- package/package.json +29 -29
- package/src/ems_client.ts +10 -2
- package/src/tms_service.ts +18 -12
- package/target/ems_client.d.ts +17 -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 +19 -13
- package/target/node/ems_service.js +8 -8
- package/target/node/file_layer.js +12 -13
- package/target/node/tms_service.js +43 -36
- package/target/node/utils.js +1 -1
- 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 +32 -28
- package/target/web/ems_service.js +8 -9
- package/target/web/file_layer.js +23 -25
- package/target/web/tms_service.js +50 -55
- package/target/web/utils.js +1 -1
- 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
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,18 +14,17 @@ 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
|
-
const LATEST_API_URL_PATH = 'latest';
|
|
28
|
-
exports.LATEST_API_URL_PATH = LATEST_API_URL_PATH;
|
|
27
|
+
const LATEST_API_URL_PATH = exports.LATEST_API_URL_PATH = 'latest';
|
|
29
28
|
/**
|
|
30
29
|
* plugins cannot have upstream dependencies on core/*-kibana.
|
|
31
30
|
* Work-around by copy-pasting modifyUrl routine here.
|
|
@@ -155,7 +154,11 @@ class EMSClient {
|
|
|
155
154
|
if (!response.ok) {
|
|
156
155
|
throw new Error(response.statusText);
|
|
157
156
|
}
|
|
158
|
-
|
|
157
|
+
if (response) {
|
|
158
|
+
return await response.json();
|
|
159
|
+
} else {
|
|
160
|
+
throw new Error('Response not found');
|
|
161
|
+
}
|
|
159
162
|
} catch (e) {
|
|
160
163
|
if (e instanceof Error) {
|
|
161
164
|
throw e;
|
|
@@ -172,7 +175,7 @@ class EMSClient {
|
|
|
172
175
|
*/
|
|
173
176
|
addQueryParams(additionalQueryParams) {
|
|
174
177
|
for (const key in additionalQueryParams) {
|
|
175
|
-
if (
|
|
178
|
+
if (Object.prototype.hasOwnProperty.call(additionalQueryParams, key)) {
|
|
176
179
|
if (additionalQueryParams[key] !== this._queryParams[key]) {
|
|
177
180
|
//changes detected.
|
|
178
181
|
this._queryParams = _lodash.default.assign({}, this._queryParams, additionalQueryParams);
|
|
@@ -204,6 +207,9 @@ class EMSClient {
|
|
|
204
207
|
getCachedGeoJson(layerId) {
|
|
205
208
|
return this._cache.get(layerId);
|
|
206
209
|
}
|
|
210
|
+
getEmsVersion() {
|
|
211
|
+
return this._emsVersion;
|
|
212
|
+
}
|
|
207
213
|
getTileApiUrl() {
|
|
208
214
|
return this._tileApiUrl;
|
|
209
215
|
}
|
|
@@ -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);
|
|
@@ -7,23 +7,22 @@ exports.FileLayer = exports.EMSFormatType = void 0;
|
|
|
7
7
|
var _url = _interopRequireDefault(require("url"));
|
|
8
8
|
var _ems_service = require("./ems_service");
|
|
9
9
|
var topojson = _interopRequireWildcard(require("topojson-client"));
|
|
10
|
-
function _getRequireWildcardCache(
|
|
11
|
-
function _interopRequireWildcard(
|
|
12
|
-
function _interopRequireDefault(
|
|
13
|
-
function _defineProperty(
|
|
14
|
-
function _toPropertyKey(
|
|
15
|
-
function _toPrimitive(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
let EMSFormatType = /*#__PURE__*/function (EMSFormatType) {
|
|
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 && {}.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
|
+
let EMSFormatType = exports.EMSFormatType = /*#__PURE__*/function (EMSFormatType) {
|
|
22
22
|
EMSFormatType["geojson"] = "geojson";
|
|
23
23
|
EMSFormatType["topojson"] = "topojson";
|
|
24
24
|
return EMSFormatType;
|
|
25
25
|
}({});
|
|
26
|
-
exports.EMSFormatType = EMSFormatType;
|
|
27
26
|
class FileLayer extends _ems_service.AbstractEmsService {
|
|
28
27
|
constructor(config, emsClient, proxyPath) {
|
|
29
28
|
super(config, emsClient, proxyPath);
|
|
@@ -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;
|