@elastic/ems-client 7.17.2 → 7.17.3
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 +3 -0
- package/.buildkite/compare_dependencies.js +67 -0
- package/.buildkite/pipeline.yml +2 -0
- package/CHANGELOG.md +6 -0
- package/package.json +4 -4
- package/target/ems_client.d.ts +16 -16
- package/target/file_layer.d.ts +1 -1
- package/target/tms_service.d.ts +6 -6
- package/target/ems_client.js +0 -318
- package/target/ems_service.js +0 -47
- package/target/file_layer.js +0 -176
- package/target/index.js +0 -16
- package/target/tms_service.js +0 -409
- package/target/utils.js +0 -86
package/.buildkite/build.sh
CHANGED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
3
|
+
* or more contributor license agreements. Licensed under the Elastic License
|
|
4
|
+
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
5
|
+
* 2.0.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/* Script that will check the current package.json dependencies
|
|
9
|
+
against Kibana (using BUILDKITE_BRANCH to determine the branch)
|
|
10
|
+
and exits with a 1 status code if, for any shared dependency,
|
|
11
|
+
EMS Client is behind */
|
|
12
|
+
|
|
13
|
+
const fs = require('node:fs');
|
|
14
|
+
const semver = require('semver');
|
|
15
|
+
|
|
16
|
+
const DEFAULT_BRANCH = 'main';
|
|
17
|
+
const branch = process.env.KIBANA_BRANCH || DEFAULT_BRANCH;
|
|
18
|
+
const kibanaPackageUrl = `https://raw.githubusercontent.com/elastic/kibana/${branch}/package.json`;
|
|
19
|
+
|
|
20
|
+
const processDependency = function (dependency, srcDeps, dstDeps, dstDevDeps) {
|
|
21
|
+
if (!(dependency in dstDeps) && !(dependency in dstDevDeps)) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
const source = srcDeps[dependency].replace('^', '');
|
|
25
|
+
const destination = dstDeps[dependency] || dstDevDeps[dependency];
|
|
26
|
+
|
|
27
|
+
if (semver.satisfies(source, destination)) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if ( dependency in dstDevDeps){
|
|
32
|
+
console.log(`⚠ ${dependency}: ${source} vs ${destination}`);
|
|
33
|
+
return true
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
console.log(`🛑 ${dependency}: ${source} vs ${destination}`);
|
|
37
|
+
return false;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const main = async function () {
|
|
41
|
+
const kibanaPackage = await fetch(kibanaPackageUrl);
|
|
42
|
+
const kibanaPackageJson = await kibanaPackage.json();
|
|
43
|
+
const kibanaDeps = kibanaPackageJson['dependencies'];
|
|
44
|
+
const kibanaDevDeps = kibanaPackageJson['devDependencies'];
|
|
45
|
+
|
|
46
|
+
const emsClientPackageJson = JSON.parse(fs.readFileSync('package.json'));
|
|
47
|
+
const emsClientDeps = {
|
|
48
|
+
...emsClientPackageJson['dependencies'],
|
|
49
|
+
...emsClientPackageJson['devDependencies']
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
console.log(`ems-client@${emsClientPackageJson['version']}`);
|
|
53
|
+
console.log(`kibana@${kibanaPackageJson['version']}`);
|
|
54
|
+
|
|
55
|
+
const results = Object.keys(emsClientDeps).map((dep) =>
|
|
56
|
+
processDependency(dep, emsClientDeps, kibanaDeps, kibanaDevDeps)
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
process.exit(results.every(r => r) ? 0 : 1);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
main()
|
|
63
|
+
.then(console.log)
|
|
64
|
+
.catch((error) => {
|
|
65
|
+
console.error(error);
|
|
66
|
+
process.exit(1);
|
|
67
|
+
});
|
package/.buildkite/pipeline.yml
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file.
|
|
|
3
3
|
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
5
5
|
|
|
6
|
+
## [7.17.3] - 2024-07-10
|
|
7
|
+
|
|
8
|
+
### Changed
|
|
9
|
+
|
|
10
|
+
- Update dependencies #243
|
|
11
|
+
|
|
6
12
|
## [7.17.2] - 2024-07-05
|
|
7
13
|
|
|
8
14
|
## Changed
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elastic/ems-client",
|
|
3
|
-
"version": "7.17.
|
|
3
|
+
"version": "7.17.3",
|
|
4
4
|
"description": "JavaScript client library for the Elastic Maps Service",
|
|
5
5
|
"main": "target/node/index.js",
|
|
6
6
|
"browser": "target/web/index.js",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"@types/lru-cache": "^5.1.0",
|
|
40
40
|
"@types/topojson-client": "^3.1.4",
|
|
41
41
|
"@types/topojson-specification": "^1.0.5",
|
|
42
|
-
"lodash": "^4.17.
|
|
43
|
-
"lru-cache": "^
|
|
42
|
+
"lodash": "^4.17.21",
|
|
43
|
+
"lru-cache": "^4.1.5",
|
|
44
44
|
"semver": "7.6.2",
|
|
45
45
|
"topojson-client": "^3.1.0"
|
|
46
46
|
},
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"eslint-plugin-prettier": "^3.1.3",
|
|
64
64
|
"husky": "^4.2.5",
|
|
65
65
|
"jest": "^26.4.0",
|
|
66
|
-
"node-fetch": "^2.6.
|
|
66
|
+
"node-fetch": "^2.6.7",
|
|
67
67
|
"prettier": "^2.0.5",
|
|
68
68
|
"ts-jest": "^26.2.0",
|
|
69
69
|
"typescript": "4.6.3"
|
package/target/ems_client.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { TMSService } from './tms_service';
|
|
2
2
|
import { EMSFormatType, FileLayer } from './file_layer';
|
|
3
3
|
import { FeatureCollection } from 'geojson';
|
|
4
|
-
type LocalizedStrings = {
|
|
4
|
+
declare type LocalizedStrings = {
|
|
5
5
|
[key: string]: string;
|
|
6
6
|
};
|
|
7
|
-
type BaseClientConfig = {
|
|
7
|
+
declare type BaseClientConfig = {
|
|
8
8
|
appName?: string;
|
|
9
9
|
manifestServiceUrl?: string;
|
|
10
10
|
tileApiUrl: string;
|
|
@@ -17,35 +17,35 @@ type BaseClientConfig = {
|
|
|
17
17
|
proxyPath?: string;
|
|
18
18
|
cacheSize?: number;
|
|
19
19
|
};
|
|
20
|
-
type DeprecatedClientConfig = BaseClientConfig & {
|
|
20
|
+
declare type DeprecatedClientConfig = BaseClientConfig & {
|
|
21
21
|
kbnVersion: string;
|
|
22
22
|
};
|
|
23
|
-
type ClientConfig = BaseClientConfig & {
|
|
23
|
+
declare type ClientConfig = BaseClientConfig & {
|
|
24
24
|
appVersion: string;
|
|
25
25
|
};
|
|
26
|
-
type EmsCatalogService = {
|
|
26
|
+
declare type EmsCatalogService = {
|
|
27
27
|
id?: string;
|
|
28
28
|
name?: string;
|
|
29
29
|
manifest: string;
|
|
30
30
|
type: string;
|
|
31
31
|
};
|
|
32
|
-
type EmsCatalogManifest = {
|
|
32
|
+
declare type EmsCatalogManifest = {
|
|
33
33
|
version?: string;
|
|
34
34
|
services: EmsCatalogService[];
|
|
35
35
|
};
|
|
36
|
-
type EmsTmsCatalog = {
|
|
36
|
+
declare type EmsTmsCatalog = {
|
|
37
37
|
version?: string;
|
|
38
38
|
services: TMSServiceConfig[];
|
|
39
39
|
};
|
|
40
|
-
export type EmsTmsFormat = {
|
|
40
|
+
export declare type EmsTmsFormat = {
|
|
41
41
|
locale: string;
|
|
42
42
|
format: string;
|
|
43
43
|
url: string;
|
|
44
44
|
};
|
|
45
|
-
export type BaseEmsServiceConfig = {
|
|
45
|
+
export declare type BaseEmsServiceConfig = {
|
|
46
46
|
attribution: EmsLayerAttribution[];
|
|
47
47
|
};
|
|
48
|
-
export type FileLayerConfig = BaseEmsServiceConfig & {
|
|
48
|
+
export declare type FileLayerConfig = BaseEmsServiceConfig & {
|
|
49
49
|
layer_id: string;
|
|
50
50
|
created_at: string;
|
|
51
51
|
formats: (EmsFileLayerFormatGeoJson | EmsFileLayerFormatTopoJson)[];
|
|
@@ -53,7 +53,7 @@ export type FileLayerConfig = BaseEmsServiceConfig & {
|
|
|
53
53
|
legacy_ids: string[];
|
|
54
54
|
layer_name: LocalizedStrings;
|
|
55
55
|
};
|
|
56
|
-
export type FileLayerField = {
|
|
56
|
+
export declare type FileLayerField = {
|
|
57
57
|
type: string;
|
|
58
58
|
id: string;
|
|
59
59
|
label: LocalizedStrings;
|
|
@@ -61,27 +61,27 @@ export type FileLayerField = {
|
|
|
61
61
|
regex?: string;
|
|
62
62
|
alias?: string[];
|
|
63
63
|
};
|
|
64
|
-
export type TMSServiceConfig = BaseEmsServiceConfig & {
|
|
64
|
+
export declare type TMSServiceConfig = BaseEmsServiceConfig & {
|
|
65
65
|
id: string;
|
|
66
66
|
name: {
|
|
67
67
|
en: string;
|
|
68
68
|
};
|
|
69
69
|
formats: EmsTmsFormat[];
|
|
70
70
|
};
|
|
71
|
-
type EmsFileCatalog = {
|
|
71
|
+
declare type EmsFileCatalog = {
|
|
72
72
|
version?: string;
|
|
73
73
|
layers: FileLayerConfig[];
|
|
74
74
|
};
|
|
75
|
-
export type EmsLayerAttribution = {
|
|
75
|
+
export declare type EmsLayerAttribution = {
|
|
76
76
|
label: LocalizedStrings;
|
|
77
77
|
url: LocalizedStrings;
|
|
78
78
|
};
|
|
79
|
-
export type EmsFileLayerFormatGeoJson = {
|
|
79
|
+
export declare type EmsFileLayerFormatGeoJson = {
|
|
80
80
|
type: EMSFormatType.geojson;
|
|
81
81
|
url: string;
|
|
82
82
|
legacy_default: boolean;
|
|
83
83
|
};
|
|
84
|
-
export type EmsFileLayerFormatTopoJson = {
|
|
84
|
+
export declare type EmsFileLayerFormatTopoJson = {
|
|
85
85
|
type: EMSFormatType.topojson;
|
|
86
86
|
url: string;
|
|
87
87
|
legacy_default: boolean;
|
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 type EMSFormatTypeStrings = keyof typeof EMSFormatType;
|
|
8
|
+
export declare 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);
|
package/target/tms_service.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EMSClient, TMSServiceConfig } from './ems_client';
|
|
2
2
|
import { AbstractEmsService } from './ems_service';
|
|
3
|
-
type EmsVectorSource = {
|
|
3
|
+
declare type EmsVectorSource = {
|
|
4
4
|
type: 'vector';
|
|
5
5
|
url: string;
|
|
6
6
|
tiles: string[];
|
|
@@ -10,10 +10,10 @@ type EmsVectorSource = {
|
|
|
10
10
|
maxzoom?: number;
|
|
11
11
|
attribution?: string;
|
|
12
12
|
};
|
|
13
|
-
type EmsVectorSources = {
|
|
13
|
+
declare type EmsVectorSources = {
|
|
14
14
|
[sourceName: string]: EmsVectorSource;
|
|
15
15
|
};
|
|
16
|
-
type EmsVectorStyle = {
|
|
16
|
+
declare type EmsVectorStyle = {
|
|
17
17
|
sources: EmsVectorSources;
|
|
18
18
|
sprite: string;
|
|
19
19
|
glyphs: string;
|
|
@@ -28,17 +28,17 @@ type EmsVectorStyle = {
|
|
|
28
28
|
version: number;
|
|
29
29
|
zoom?: number;
|
|
30
30
|
};
|
|
31
|
-
type EmsSprite = {
|
|
31
|
+
declare type EmsSprite = {
|
|
32
32
|
height: number;
|
|
33
33
|
pixelRatio: number;
|
|
34
34
|
width: number;
|
|
35
35
|
x: number;
|
|
36
36
|
y: number;
|
|
37
37
|
};
|
|
38
|
-
type EmsSpriteSheet = {
|
|
38
|
+
declare type EmsSpriteSheet = {
|
|
39
39
|
[spriteName: string]: EmsSprite;
|
|
40
40
|
};
|
|
41
|
-
type EmsRasterStyle = {
|
|
41
|
+
declare type EmsRasterStyle = {
|
|
42
42
|
tilejson: string;
|
|
43
43
|
name: string;
|
|
44
44
|
attribution: string;
|
package/target/ems_client.js
DELETED
|
@@ -1,318 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.EMSClient = exports.LATEST_API_URL_PATH = void 0;
|
|
16
|
-
/*
|
|
17
|
-
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
18
|
-
* or more contributor license agreements. Licensed under the Elastic License
|
|
19
|
-
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
20
|
-
* 2.0.
|
|
21
|
-
*/
|
|
22
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
23
|
-
const tms_service_1 = require("./tms_service");
|
|
24
|
-
const file_layer_1 = require("./file_layer");
|
|
25
|
-
const coerce_1 = __importDefault(require("semver/functions/coerce"));
|
|
26
|
-
const valid_1 = __importDefault(require("semver/functions/valid"));
|
|
27
|
-
const major_1 = __importDefault(require("semver/functions/major"));
|
|
28
|
-
const minor_1 = __importDefault(require("semver/functions/minor"));
|
|
29
|
-
const url_1 = require("url");
|
|
30
|
-
const utils_1 = require("./utils");
|
|
31
|
-
const lru_cache_1 = __importDefault(require("lru-cache"));
|
|
32
|
-
const REST_API_REGEX = /\d{4}-\d{2}-\d{2}/;
|
|
33
|
-
exports.LATEST_API_URL_PATH = 'latest';
|
|
34
|
-
/**
|
|
35
|
-
* plugins cannot have upstream dependencies on core/*-kibana.
|
|
36
|
-
* Work-around by copy-pasting modifyUrl routine here.
|
|
37
|
-
* @param url
|
|
38
|
-
* @param block
|
|
39
|
-
*/
|
|
40
|
-
function modifyUrlLocal(url, block) {
|
|
41
|
-
const parsed = (0, url_1.parse)(url, true);
|
|
42
|
-
// copy over the most specific version of each
|
|
43
|
-
// property. By default, the parsed url includes
|
|
44
|
-
// several conflicting properties (like path and
|
|
45
|
-
// pathname + search, or search and query) and keeping
|
|
46
|
-
// track of which property is actually used when they
|
|
47
|
-
// are formatted is harder than necessary
|
|
48
|
-
const meaningfulParts = {
|
|
49
|
-
protocol: parsed.protocol,
|
|
50
|
-
slashes: parsed.slashes,
|
|
51
|
-
auth: parsed.auth,
|
|
52
|
-
hostname: parsed.hostname,
|
|
53
|
-
port: parsed.port,
|
|
54
|
-
pathname: parsed.pathname,
|
|
55
|
-
query: parsed.query || {},
|
|
56
|
-
hash: parsed.hash,
|
|
57
|
-
};
|
|
58
|
-
// the block modifies the meaningfulParts object, or returns a new one
|
|
59
|
-
const modifiedParts = block(meaningfulParts) || meaningfulParts;
|
|
60
|
-
// format the modified/replaced meaningfulParts back into a url
|
|
61
|
-
return (0, url_1.format)({
|
|
62
|
-
protocol: modifiedParts.protocol,
|
|
63
|
-
slashes: modifiedParts.slashes,
|
|
64
|
-
auth: modifiedParts.auth,
|
|
65
|
-
hostname: modifiedParts.hostname,
|
|
66
|
-
port: modifiedParts.port,
|
|
67
|
-
pathname: modifiedParts.pathname,
|
|
68
|
-
query: modifiedParts.query,
|
|
69
|
-
hash: modifiedParts.hash,
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
const extendUrl = (url, props) => modifyUrlLocal(url, (parsed) => lodash_1.default.merge(parsed, props));
|
|
73
|
-
/**
|
|
74
|
-
* Unescape a url template that was escaped by encodeURI() so leaflet
|
|
75
|
-
* will be able to correctly locate the variables in the template
|
|
76
|
-
* @param {String} url
|
|
77
|
-
* @return {String}
|
|
78
|
-
*/
|
|
79
|
-
const unescapeTemplateVars = (url) => {
|
|
80
|
-
const ENCODED_TEMPLATE_VARS_RE = /%7B(\w+?)%7D/g;
|
|
81
|
-
return url.replace(ENCODED_TEMPLATE_VARS_RE, (total, varName) => `{${varName}}`);
|
|
82
|
-
};
|
|
83
|
-
//this is not the default locale from Kibana, but the default locale supported by the Elastic Maps Service
|
|
84
|
-
const DEFAULT_LANGUAGE = 'en';
|
|
85
|
-
class EMSClient {
|
|
86
|
-
constructor(config) {
|
|
87
|
-
this.EMS_LOAD_TIMEOUT = 32000;
|
|
88
|
-
this._isRestApi = false;
|
|
89
|
-
// Remove kbnVersion in 8.0
|
|
90
|
-
if ('kbnVersion' in config) {
|
|
91
|
-
console.warn('The "kbnVersion" parameter for ems-client is deprecated. Please use "appVersion" instead.');
|
|
92
|
-
this._appVersion = config.kbnVersion;
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
this._appVersion = config.appVersion;
|
|
96
|
-
}
|
|
97
|
-
this._queryParams = {
|
|
98
|
-
elastic_tile_service_tos: 'agree',
|
|
99
|
-
my_app_name: config.appName || 'kibana',
|
|
100
|
-
my_app_version: this._appVersion,
|
|
101
|
-
};
|
|
102
|
-
this._sanitizer = config.htmlSanitizer ? config.htmlSanitizer : (x) => x;
|
|
103
|
-
this._tileApiUrl = config.tileApiUrl;
|
|
104
|
-
this._fileApiUrl = config.fileApiUrl;
|
|
105
|
-
this._emsVersion = this._getEmsVersion(config.emsVersion);
|
|
106
|
-
this._isRestApi = this._emsVersion == config.emsVersion;
|
|
107
|
-
this._emsLandingPageUrl = config.landingPageUrl || '';
|
|
108
|
-
this._language = config.language || DEFAULT_LANGUAGE;
|
|
109
|
-
this._fetchFunction = config.fetchFunction;
|
|
110
|
-
this._proxyPath = config.proxyPath || '';
|
|
111
|
-
this._cache = new lru_cache_1.default({
|
|
112
|
-
max: config.cacheSize || 10,
|
|
113
|
-
});
|
|
114
|
-
this._invalidateSettings();
|
|
115
|
-
}
|
|
116
|
-
getDefaultLocale() {
|
|
117
|
-
return DEFAULT_LANGUAGE;
|
|
118
|
-
}
|
|
119
|
-
getLocale() {
|
|
120
|
-
return this._language;
|
|
121
|
-
}
|
|
122
|
-
getValueInLanguage(i18nObject) {
|
|
123
|
-
if (!i18nObject) {
|
|
124
|
-
return '';
|
|
125
|
-
}
|
|
126
|
-
return i18nObject[this._language] ? i18nObject[this._language] : i18nObject[DEFAULT_LANGUAGE];
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* this internal method is overridden by the tests to simulate custom manifest.
|
|
130
|
-
*/
|
|
131
|
-
getManifest(endpointUrl) {
|
|
132
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
133
|
-
try {
|
|
134
|
-
const url = extendUrl(endpointUrl, { query: this._queryParams });
|
|
135
|
-
const response = yield this._fetchWithTimeout(url);
|
|
136
|
-
if (!response.ok) {
|
|
137
|
-
throw new Error(response.statusText);
|
|
138
|
-
}
|
|
139
|
-
if (response) {
|
|
140
|
-
return (yield response.json());
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
throw new Error('Response not found');
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
catch (e) {
|
|
147
|
-
if (e instanceof Error) {
|
|
148
|
-
throw e;
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
throw new Error('Unknown error');
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Add optional query-parameters to all requests
|
|
158
|
-
*
|
|
159
|
-
* @param additionalQueryParams
|
|
160
|
-
*/
|
|
161
|
-
addQueryParams(additionalQueryParams) {
|
|
162
|
-
for (const key in additionalQueryParams) {
|
|
163
|
-
if (Object.prototype.hasOwnProperty.call(additionalQueryParams, key)) {
|
|
164
|
-
if (additionalQueryParams[key] !== this._queryParams[key]) {
|
|
165
|
-
//changes detected.
|
|
166
|
-
this._queryParams = lodash_1.default.assign({}, this._queryParams, additionalQueryParams);
|
|
167
|
-
this._invalidateSettings();
|
|
168
|
-
break;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
getMainManifest() {
|
|
174
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
175
|
-
return yield this._getMainCatalog();
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
getDefaultFileManifest() {
|
|
179
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
180
|
-
return yield this._getDefaultFileCatalog();
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
getDefaultTMSManifest() {
|
|
184
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
185
|
-
return yield this._getDefaultTMSCatalog();
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
getFileLayers() {
|
|
189
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
190
|
-
return yield this._loadFileLayers();
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
getTMSServices() {
|
|
194
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
195
|
-
return yield this._loadTMSServices();
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
cacheGeoJson(layerId, geoJson) {
|
|
199
|
-
this._cache.set(layerId, geoJson);
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
getCachedGeoJson(layerId) {
|
|
203
|
-
return this._cache.get(layerId);
|
|
204
|
-
}
|
|
205
|
-
getEmsVersion() {
|
|
206
|
-
return this._emsVersion;
|
|
207
|
-
}
|
|
208
|
-
getTileApiUrl() {
|
|
209
|
-
return this._tileApiUrl;
|
|
210
|
-
}
|
|
211
|
-
getFileApiUrl() {
|
|
212
|
-
return this._fileApiUrl;
|
|
213
|
-
}
|
|
214
|
-
getLandingPageUrl() {
|
|
215
|
-
return this._emsLandingPageUrl;
|
|
216
|
-
}
|
|
217
|
-
sanitizeHtml(html) {
|
|
218
|
-
return this._sanitizer(html);
|
|
219
|
-
}
|
|
220
|
-
extendUrlWithParams(url) {
|
|
221
|
-
return unescapeTemplateVars(extendUrl(url, {
|
|
222
|
-
query: this._queryParams,
|
|
223
|
-
}));
|
|
224
|
-
}
|
|
225
|
-
findFileLayerById(id) {
|
|
226
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
227
|
-
const fileLayers = yield this.getFileLayers();
|
|
228
|
-
for (let i = 0; i < fileLayers.length; i++) {
|
|
229
|
-
if (fileLayers[i].hasId(id)) {
|
|
230
|
-
return fileLayers[i];
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
findTMSServiceById(id) {
|
|
236
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
237
|
-
const tmsServices = yield this.getTMSServices();
|
|
238
|
-
for (let i = 0; i < tmsServices.length; i++) {
|
|
239
|
-
if (tmsServices[i].hasId(id)) {
|
|
240
|
-
return tmsServices[i];
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
_getEmsVersion(version) {
|
|
246
|
-
if (version === null || version === void 0 ? void 0 : version.match(REST_API_REGEX)) {
|
|
247
|
-
return version;
|
|
248
|
-
}
|
|
249
|
-
const semverVersion = (0, valid_1.default)((0, coerce_1.default)(version));
|
|
250
|
-
if (semverVersion) {
|
|
251
|
-
return `v${(0, major_1.default)(semverVersion)}.${(0, minor_1.default)(semverVersion)}`;
|
|
252
|
-
}
|
|
253
|
-
else {
|
|
254
|
-
throw new Error(`Invalid version: ${version}`);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
_fetchWithTimeout(url) {
|
|
258
|
-
return new Promise((resolve, reject) => {
|
|
259
|
-
const timer = setTimeout(() => reject(new Error(`Request to ${url} timed out`)), this.EMS_LOAD_TIMEOUT);
|
|
260
|
-
this._fetchFunction(url).then((response) => {
|
|
261
|
-
clearTimeout(timer);
|
|
262
|
-
resolve(response);
|
|
263
|
-
}, (err) => {
|
|
264
|
-
clearTimeout(timer);
|
|
265
|
-
reject(err);
|
|
266
|
-
});
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
_invalidateSettings() {
|
|
270
|
-
this._cache.reset();
|
|
271
|
-
this._getMainCatalog = lodash_1.default.once(() => __awaiter(this, void 0, void 0, function* () {
|
|
272
|
-
const services = [];
|
|
273
|
-
if (this._tileApiUrl) {
|
|
274
|
-
const version = this._isRestApi ? exports.LATEST_API_URL_PATH : this._emsVersion;
|
|
275
|
-
services.push({
|
|
276
|
-
type: 'tms',
|
|
277
|
-
manifest: (0, utils_1.toAbsoluteUrl)(this._tileApiUrl, `${version}/manifest`),
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
if (this._fileApiUrl) {
|
|
281
|
-
const version = this._isRestApi ? exports.LATEST_API_URL_PATH : this._emsVersion;
|
|
282
|
-
services.push({
|
|
283
|
-
type: 'file',
|
|
284
|
-
manifest: (0, utils_1.toAbsoluteUrl)(this._fileApiUrl, `${version}/manifest`),
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
return { services: services };
|
|
288
|
-
}));
|
|
289
|
-
this._getDefaultTMSCatalog = lodash_1.default.once(() => __awaiter(this, void 0, void 0, function* () {
|
|
290
|
-
const catalogue = yield this._getMainCatalog();
|
|
291
|
-
const firstService = catalogue.services.find((service) => service.type === 'tms');
|
|
292
|
-
if (!firstService) {
|
|
293
|
-
return { services: [] };
|
|
294
|
-
}
|
|
295
|
-
const url = this._proxyPath + firstService.manifest;
|
|
296
|
-
return yield this.getManifest(url);
|
|
297
|
-
}));
|
|
298
|
-
this._getDefaultFileCatalog = lodash_1.default.once(() => __awaiter(this, void 0, void 0, function* () {
|
|
299
|
-
const catalogue = yield this._getMainCatalog();
|
|
300
|
-
const firstService = catalogue.services.find((service) => service.type === 'file');
|
|
301
|
-
if (!firstService) {
|
|
302
|
-
return { layers: [] };
|
|
303
|
-
}
|
|
304
|
-
const url = this._proxyPath + firstService.manifest;
|
|
305
|
-
return yield this.getManifest(url);
|
|
306
|
-
}));
|
|
307
|
-
//Cache the actual instances of TMSService as these in turn cache sub-manifests for the style-files
|
|
308
|
-
this._loadTMSServices = lodash_1.default.once(() => __awaiter(this, void 0, void 0, function* () {
|
|
309
|
-
const tmsManifest = yield this._getDefaultTMSCatalog();
|
|
310
|
-
return tmsManifest.services.map((serviceConfig) => new tms_service_1.TMSService(serviceConfig, this, this._proxyPath));
|
|
311
|
-
}));
|
|
312
|
-
this._loadFileLayers = lodash_1.default.once(() => __awaiter(this, void 0, void 0, function* () {
|
|
313
|
-
const fileManifest = yield this._getDefaultFileCatalog();
|
|
314
|
-
return fileManifest.layers.map((layerConfig) => new file_layer_1.FileLayer(layerConfig, this, this._proxyPath));
|
|
315
|
-
}));
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
exports.EMSClient = EMSClient;
|
package/target/ems_service.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
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.js
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
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; } });
|
package/target/tms_service.js
DELETED
|
@@ -1,409 +0,0 @@
|
|
|
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
-
};
|
|
20
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.TMSService = void 0;
|
|
22
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
23
|
-
const ems_service_1 = require("./ems_service");
|
|
24
|
-
const utils_1 = require("./utils");
|
|
25
|
-
class TMSService extends ems_service_1.AbstractEmsService {
|
|
26
|
-
constructor(config, emsClient, proxyPath) {
|
|
27
|
-
super(config, emsClient, proxyPath);
|
|
28
|
-
this._getRasterStyleJson = lodash_1.default.once(() => __awaiter(this, void 0, void 0, function* () {
|
|
29
|
-
const rasterUrl = this._getStyleUrlForLocale('raster');
|
|
30
|
-
if (rasterUrl) {
|
|
31
|
-
const url = this._proxyPath + this._getAbsoluteUrl(rasterUrl);
|
|
32
|
-
return this._emsClient.getManifest(this._emsClient.extendUrlWithParams(url));
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
}));
|
|
38
|
-
this._getVectorStyleJsonRaw = lodash_1.default.once(() => __awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
const vectorUrl = this._getStyleUrlForLocale('vector');
|
|
40
|
-
if (vectorUrl) {
|
|
41
|
-
const url = this._proxyPath + this._getAbsoluteUrl(vectorUrl);
|
|
42
|
-
const vectorJson = yield this._emsClient.getManifest(this._emsClient.extendUrlWithParams(url));
|
|
43
|
-
return Object.assign({}, vectorJson);
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
}));
|
|
49
|
-
this._getVectorStyleJsonInlined = lodash_1.default.once(() => __awaiter(this, void 0, void 0, function* () {
|
|
50
|
-
var _a;
|
|
51
|
-
const vectorJson = yield this._getVectorStyleJsonRaw();
|
|
52
|
-
if (vectorJson) {
|
|
53
|
-
const inlinedSources = {};
|
|
54
|
-
const { sources } = vectorJson;
|
|
55
|
-
for (const sourceName of Object.getOwnPropertyNames(sources)) {
|
|
56
|
-
const { url } = sources[sourceName];
|
|
57
|
-
if (url) {
|
|
58
|
-
const sourceUrl = this._proxyPath + this._getAbsoluteUrl(url);
|
|
59
|
-
const extendedUrl = this._emsClient.extendUrlWithParams(sourceUrl);
|
|
60
|
-
const sourceJson = yield this._emsClient.getManifest(extendedUrl);
|
|
61
|
-
const tiles = (_a = sourceJson === null || sourceJson === void 0 ? void 0 : sourceJson.tiles) === null || _a === void 0 ? void 0 : _a.map((tileUrl) => {
|
|
62
|
-
const directUrl = this._proxyPath + this._getAbsoluteUrl(tileUrl);
|
|
63
|
-
return this._emsClient.extendUrlWithParams(directUrl);
|
|
64
|
-
});
|
|
65
|
-
inlinedSources[sourceName] = Object.assign(Object.assign({}, sourceJson), { type: 'vector', tiles });
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return Object.assign(Object.assign({}, vectorJson), { sources: inlinedSources, sprite: yield this._getSpriteSheetRootPath(), glyphs: yield this._getUrlTemplateForGlyphs() });
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
}));
|
|
74
|
-
this._config = config;
|
|
75
|
-
}
|
|
76
|
-
/*
|
|
77
|
-
This method returns an array of objects with the layers and the new
|
|
78
|
-
layout['text-field'] to apply using map.setLayoutProperty
|
|
79
|
-
*/
|
|
80
|
-
static transformLanguageProperty(layer, lang) {
|
|
81
|
-
const supportedLang = this.SupportedLanguages.find((l) => l.key === lang);
|
|
82
|
-
if (layer.type === 'symbol' && layer.layout !== undefined && supportedLang !== undefined) {
|
|
83
|
-
const omtLang = supportedLang.omt;
|
|
84
|
-
const textField = layer.layout['text-field'];
|
|
85
|
-
if (textField && typeof textField === 'string') {
|
|
86
|
-
return TMSService._getTextField(textField, omtLang);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
/*
|
|
92
|
-
This method returns an array of objects per layer, containing a list of
|
|
93
|
-
properties with new colors to apply using map.setPaintProperty
|
|
94
|
-
*/
|
|
95
|
-
static transformColorProperties(layer, color, operation, percentage) {
|
|
96
|
-
if (['background', 'fill', 'line', 'symbol'].indexOf(layer.type) !== -1 && layer.paint) {
|
|
97
|
-
const paint = layer.paint;
|
|
98
|
-
if (layer.type === 'symbol' && Object.keys(paint).length === 0) {
|
|
99
|
-
paint['text-color'] = 'rgb(0,0,0)';
|
|
100
|
-
}
|
|
101
|
-
const types = Object.keys(paint).filter((key) => {
|
|
102
|
-
return ([
|
|
103
|
-
'background-color',
|
|
104
|
-
'circle-color',
|
|
105
|
-
'circle-stroke-color',
|
|
106
|
-
'fill-color',
|
|
107
|
-
'fill-extrusion-color',
|
|
108
|
-
'fill-outline-color',
|
|
109
|
-
'icon-color',
|
|
110
|
-
'icon-halo-color',
|
|
111
|
-
'line-color',
|
|
112
|
-
'text-color',
|
|
113
|
-
'text-halo-color',
|
|
114
|
-
].indexOf(key) !== -1);
|
|
115
|
-
});
|
|
116
|
-
return types.map((type) => {
|
|
117
|
-
const paintColor = paint[type];
|
|
118
|
-
return {
|
|
119
|
-
property: type,
|
|
120
|
-
color: paintColor && color
|
|
121
|
-
? (0, utils_1.colorizeColor)(paintColor, color, operation, percentage)
|
|
122
|
-
: paintColor,
|
|
123
|
-
};
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
return [];
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
static _getTextField(label, lang) {
|
|
131
|
-
// Capture {name:xx} labels
|
|
132
|
-
const labelMatch = label.match(/\{name([:_])(.{2})\}/);
|
|
133
|
-
if (labelMatch && labelMatch[1] != lang) {
|
|
134
|
-
// Only apply if the languages are different
|
|
135
|
-
return ['coalesce', ['get', `name:${lang}`], ['get', `name${labelMatch[1]}${labelMatch[2]}`]];
|
|
136
|
-
}
|
|
137
|
-
else if (label.includes('latin') && label.includes('nonlatin')) {
|
|
138
|
-
// Capture the common pattern {name:latin}\n{name:nonlatin}
|
|
139
|
-
return [
|
|
140
|
-
'coalesce',
|
|
141
|
-
['get', `name:${lang}`],
|
|
142
|
-
['concat', ['get', 'name:latin'], '\n', ['get', 'name:nonlatin']],
|
|
143
|
-
];
|
|
144
|
-
}
|
|
145
|
-
// If no case is found, return the input label
|
|
146
|
-
return label;
|
|
147
|
-
}
|
|
148
|
-
getDefaultRasterStyle() {
|
|
149
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
-
const tileJson = yield this._getRasterStyleJson();
|
|
151
|
-
if (tileJson) {
|
|
152
|
-
const tiles = tileJson.tiles.map((tile) => this._proxyPath + this._getAbsoluteUrl(tile));
|
|
153
|
-
return Object.assign(Object.assign({}, tileJson), { tiles });
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
getUrlTemplate() {
|
|
161
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
162
|
-
const tileJson = yield this._getRasterStyleJson();
|
|
163
|
-
if (tileJson) {
|
|
164
|
-
const directUrl = this._proxyPath + this._getAbsoluteUrl(tileJson.tiles[0]);
|
|
165
|
-
return this._emsClient.extendUrlWithParams(directUrl);
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
return '';
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
getUrlTemplateForVector(sourceId) {
|
|
173
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
174
|
-
var _a, _b;
|
|
175
|
-
const tileJson = yield this._getVectorStyleJsonInlined();
|
|
176
|
-
const url = (_b = (_a = tileJson === null || tileJson === void 0 ? void 0 : tileJson.sources[sourceId]) === null || _a === void 0 ? void 0 : _a.tiles) === null || _b === void 0 ? void 0 : _b.pop();
|
|
177
|
-
if (url) {
|
|
178
|
-
const directUrl = this._proxyPath + this._getAbsoluteUrl(url);
|
|
179
|
-
return this._emsClient.extendUrlWithParams(directUrl);
|
|
180
|
-
}
|
|
181
|
-
else {
|
|
182
|
-
return '';
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
getVectorStyleSheet() {
|
|
187
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
-
return yield this._getVectorStyleJsonInlined();
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
getVectorStyleSheetRaw() {
|
|
192
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
193
|
-
return yield this._getVectorStyleJsonRaw();
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
getSpriteSheetMeta() {
|
|
197
|
-
return __awaiter(this, arguments, void 0, function* (isRetina = false) {
|
|
198
|
-
const metaUrl = yield this.getSpriteSheetJsonPath(isRetina);
|
|
199
|
-
const spritePngs = yield this.getSpriteSheetPngPath(isRetina);
|
|
200
|
-
if (metaUrl && spritePngs) {
|
|
201
|
-
const metaUrlExtended = this._emsClient.extendUrlWithParams(metaUrl);
|
|
202
|
-
const jsonMeta = yield this._emsClient.getManifest(metaUrlExtended);
|
|
203
|
-
return {
|
|
204
|
-
png: spritePngs,
|
|
205
|
-
json: jsonMeta,
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
else {
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
getSpriteSheetJsonPath() {
|
|
214
|
-
return __awaiter(this, arguments, void 0, function* (isRetina = false) {
|
|
215
|
-
const spriteSheetRootPath = yield this._getSpriteSheetRootPath();
|
|
216
|
-
if (spriteSheetRootPath) {
|
|
217
|
-
const suffix = isRetina ? '@2x' : '';
|
|
218
|
-
return spriteSheetRootPath + suffix + '.json';
|
|
219
|
-
}
|
|
220
|
-
else {
|
|
221
|
-
return '';
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
getSpriteSheetPngPath() {
|
|
226
|
-
return __awaiter(this, arguments, void 0, function* (isRetina = false) {
|
|
227
|
-
const spriteSheetRootPath = yield this._getSpriteSheetRootPath();
|
|
228
|
-
if (spriteSheetRootPath) {
|
|
229
|
-
const suffix = isRetina ? '@2x' : '';
|
|
230
|
-
return spriteSheetRootPath + suffix + '.png';
|
|
231
|
-
}
|
|
232
|
-
else {
|
|
233
|
-
return '';
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
getDisplayName() {
|
|
238
|
-
return this._emsClient.getValueInLanguage(this._config.name);
|
|
239
|
-
}
|
|
240
|
-
getMinZoom() {
|
|
241
|
-
return __awaiter(this, arguments, void 0, function* (format = 'vector') {
|
|
242
|
-
switch (format) {
|
|
243
|
-
case 'vector': {
|
|
244
|
-
const { sources } = (yield this._getVectorStyleJsonInlined()) || { sources: {} };
|
|
245
|
-
return Math.min(...Object.values(sources)
|
|
246
|
-
.map((s) => {
|
|
247
|
-
return s && s instanceof Object && 'minzoom' in s ?
|
|
248
|
-
s['minzoom'] :
|
|
249
|
-
null;
|
|
250
|
-
})
|
|
251
|
-
.filter((minzoom) => Number.isFinite(minzoom)));
|
|
252
|
-
}
|
|
253
|
-
case 'raster': {
|
|
254
|
-
const { minzoom } = (yield this._getRasterStyleJson()) || {};
|
|
255
|
-
return minzoom;
|
|
256
|
-
}
|
|
257
|
-
default:
|
|
258
|
-
return;
|
|
259
|
-
}
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
getMaxZoom() {
|
|
263
|
-
return __awaiter(this, arguments, void 0, function* (format = 'vector') {
|
|
264
|
-
switch (format) {
|
|
265
|
-
case 'vector': {
|
|
266
|
-
const { sources } = (yield this._getVectorStyleJsonInlined()) || { sources: {} };
|
|
267
|
-
return Math.max(...Object.values(sources)
|
|
268
|
-
.map((s) => {
|
|
269
|
-
return s && s instanceof Object && 'maxzoom' in s ?
|
|
270
|
-
s['maxzoom'] :
|
|
271
|
-
null;
|
|
272
|
-
})
|
|
273
|
-
.filter((maxzoom) => Number.isFinite(maxzoom)));
|
|
274
|
-
}
|
|
275
|
-
case 'raster': {
|
|
276
|
-
const { maxzoom } = (yield this._getRasterStyleJson()) || {};
|
|
277
|
-
return maxzoom;
|
|
278
|
-
}
|
|
279
|
-
default:
|
|
280
|
-
return;
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
getId() {
|
|
285
|
-
return this._config.id;
|
|
286
|
-
}
|
|
287
|
-
hasId(id) {
|
|
288
|
-
return this._config.id === id;
|
|
289
|
-
}
|
|
290
|
-
getApiUrl() {
|
|
291
|
-
return this._emsClient.getTileApiUrl();
|
|
292
|
-
}
|
|
293
|
-
_getStyleUrlForLocale(formatType) {
|
|
294
|
-
let vectorFormats = this._getFormats(formatType, this._emsClient.getLocale());
|
|
295
|
-
if (!vectorFormats.length) {
|
|
296
|
-
//fallback to default locale
|
|
297
|
-
vectorFormats = this._getFormats(formatType, this._emsClient.getDefaultLocale());
|
|
298
|
-
}
|
|
299
|
-
if (!vectorFormats.length) {
|
|
300
|
-
throw new Error(`Cannot find ${formatType} tile layer for locale ${this._emsClient.getLocale()} or ${this._emsClient.getDefaultLocale()}`);
|
|
301
|
-
}
|
|
302
|
-
const defaultStyle = vectorFormats[0];
|
|
303
|
-
if (defaultStyle && Object.prototype.hasOwnProperty.call(defaultStyle, 'url')) {
|
|
304
|
-
return defaultStyle.url;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
_getFormats(formatType, locale) {
|
|
308
|
-
return this._config.formats.filter((format) => format.locale === locale && format.format === formatType);
|
|
309
|
-
}
|
|
310
|
-
_getSpriteSheetRootPath() {
|
|
311
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
312
|
-
const vectorStyleJson = yield this._getVectorStyleJsonRaw();
|
|
313
|
-
if (vectorStyleJson === null || vectorStyleJson === void 0 ? void 0 : vectorStyleJson.sprite) {
|
|
314
|
-
return this._proxyPath + this._getAbsoluteUrl(vectorStyleJson.sprite);
|
|
315
|
-
}
|
|
316
|
-
else {
|
|
317
|
-
return '';
|
|
318
|
-
}
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
_getUrlTemplateForGlyphs() {
|
|
322
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
323
|
-
const vectorStyleJson = yield this._getVectorStyleJsonRaw();
|
|
324
|
-
if (vectorStyleJson === null || vectorStyleJson === void 0 ? void 0 : vectorStyleJson.glyphs) {
|
|
325
|
-
return this._proxyPath + this._getAbsoluteUrl(vectorStyleJson.glyphs);
|
|
326
|
-
}
|
|
327
|
-
else {
|
|
328
|
-
return '';
|
|
329
|
-
}
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
exports.TMSService = TMSService;
|
|
334
|
-
/*
|
|
335
|
-
List of supported languages with labels and OMT codes extracted
|
|
336
|
-
from https://openmaptiles.org/languages
|
|
337
|
-
|
|
338
|
-
Keys are values for i18.locale from Kibana settings
|
|
339
|
-
and OMT codes for the rest.
|
|
340
|
-
*/
|
|
341
|
-
TMSService.SupportedLanguages = [
|
|
342
|
-
{ key: 'ar', omt: 'ar' },
|
|
343
|
-
{ key: 'az', omt: 'az' },
|
|
344
|
-
{ key: 'be', omt: 'be' },
|
|
345
|
-
{ key: 'bg', omt: 'bg' },
|
|
346
|
-
{ key: 'br', omt: 'br' },
|
|
347
|
-
{ key: 'bs', omt: 'bs' },
|
|
348
|
-
{ key: 'ca', omt: 'ca' },
|
|
349
|
-
{ key: 'cs', omt: 'cs' },
|
|
350
|
-
{ key: 'cy', omt: 'cy' },
|
|
351
|
-
{ key: 'da', omt: 'da' },
|
|
352
|
-
{ key: 'de', omt: 'de' },
|
|
353
|
-
{ key: 'el', omt: 'el' },
|
|
354
|
-
{ key: 'en', omt: 'en' },
|
|
355
|
-
{ key: 'eo', omt: 'eo' },
|
|
356
|
-
{ key: 'es', omt: 'es' },
|
|
357
|
-
{ key: 'et', omt: 'et' },
|
|
358
|
-
{ key: 'fi', omt: 'fi' },
|
|
359
|
-
{ key: 'fr-fr', omt: 'fr' },
|
|
360
|
-
{ key: 'fy', omt: 'fy' },
|
|
361
|
-
{ key: 'ga', omt: 'ga' },
|
|
362
|
-
{ key: 'gd', omt: 'gd' },
|
|
363
|
-
{ key: 'he', omt: 'he' },
|
|
364
|
-
{ key: 'hi-in', omt: 'hi' },
|
|
365
|
-
{ key: 'hr', omt: 'hr' },
|
|
366
|
-
{ key: 'hu', omt: 'hu' },
|
|
367
|
-
{ key: 'hy', omt: 'hy' },
|
|
368
|
-
{ key: 'is', omt: 'is' },
|
|
369
|
-
{ key: 'it', omt: 'it' },
|
|
370
|
-
{ key: 'ja_kana', omt: 'ja_kana' },
|
|
371
|
-
{ key: 'ja_rm', omt: 'ja_rm' },
|
|
372
|
-
{ key: 'ja-jp', omt: 'ja' },
|
|
373
|
-
{ key: 'ka', omt: 'ka' },
|
|
374
|
-
{ key: 'kk', omt: 'kk' },
|
|
375
|
-
{ key: 'kn', omt: 'kn' },
|
|
376
|
-
{ key: 'ko_rm', omt: 'ko_rm' },
|
|
377
|
-
{ key: 'ko', omt: 'ko' },
|
|
378
|
-
{ key: 'la', omt: 'la' },
|
|
379
|
-
{ key: 'lb', omt: 'lb' },
|
|
380
|
-
{ key: 'lt', omt: 'lt' },
|
|
381
|
-
{ key: 'lv', omt: 'lv' },
|
|
382
|
-
{ key: 'mk', omt: 'mk' },
|
|
383
|
-
{ key: 'mt', omt: 'mt' },
|
|
384
|
-
{ key: 'nl', omt: 'nl' },
|
|
385
|
-
{ key: 'no', omt: 'no' },
|
|
386
|
-
{ key: 'pl', omt: 'pl' },
|
|
387
|
-
{ key: 'pt-pt', omt: 'pt' },
|
|
388
|
-
{ key: 'rm', omt: 'rm' },
|
|
389
|
-
{ key: 'ro', omt: 'ro' },
|
|
390
|
-
{ key: 'ru-ru', omt: 'ru' },
|
|
391
|
-
{ key: 'sk', omt: 'sk' },
|
|
392
|
-
{ key: 'sl', omt: 'sl' },
|
|
393
|
-
{ key: 'sq', omt: 'sq' },
|
|
394
|
-
{ key: 'sr-Ltn', omt: 'sr-Ltn' },
|
|
395
|
-
{ key: 'sr', omt: 'sr' },
|
|
396
|
-
{ key: 'sv', omt: 'sv' },
|
|
397
|
-
{ key: 'th', omt: 'th' },
|
|
398
|
-
{ key: 'tr', omt: 'tr' },
|
|
399
|
-
{ key: 'uk', omt: 'uk' },
|
|
400
|
-
{ key: 'zh-cn', omt: 'zh' },
|
|
401
|
-
];
|
|
402
|
-
/*
|
|
403
|
-
Suggested default operations for the different EMS styles
|
|
404
|
-
*/
|
|
405
|
-
TMSService.colorOperationDefaults = [
|
|
406
|
-
{ style: 'road_map', operation: 'mix', percentage: 0.25 },
|
|
407
|
-
{ style: 'road_map_desaturated', operation: 'screen', percentage: 0.25 },
|
|
408
|
-
{ style: 'dark_map', operation: 'dodge', percentage: 0.25 },
|
|
409
|
-
];
|
package/target/utils.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.colorizeColor = exports.desaturateColor = exports.toAbsoluteUrl = void 0;
|
|
13
|
-
const chroma_js_1 = __importDefault(require("chroma-js"));
|
|
14
|
-
/**
|
|
15
|
-
* Resolves a target URL path relative to the host.
|
|
16
|
-
* This is specifically useed by the Kibana proxy re-routing.
|
|
17
|
-
* It also handles trailing slashes in tileApiUrl and fileApiUrl parameters.
|
|
18
|
-
*/
|
|
19
|
-
function toAbsoluteUrl(host, path) {
|
|
20
|
-
if (!host) {
|
|
21
|
-
return path;
|
|
22
|
-
}
|
|
23
|
-
const hostEndWithSlash = host[host.length - 1] === '/';
|
|
24
|
-
const pathStartsWithSlash = path[0] === '/';
|
|
25
|
-
if (hostEndWithSlash === true && pathStartsWithSlash === true) {
|
|
26
|
-
return host + path.slice(1);
|
|
27
|
-
}
|
|
28
|
-
else if (hostEndWithSlash !== pathStartsWithSlash) {
|
|
29
|
-
return host + path;
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
return host + '/' + path;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
exports.toAbsoluteUrl = toAbsoluteUrl;
|
|
36
|
-
/*
|
|
37
|
-
Function to transform a maplibre color definition by a given function.
|
|
38
|
-
*/
|
|
39
|
-
function transformColor(paintColor, func) {
|
|
40
|
-
if (typeof paintColor == 'string') {
|
|
41
|
-
const modifiedColor = func(paintColor);
|
|
42
|
-
return `rgba(${modifiedColor.rgba().join(',')})`;
|
|
43
|
-
}
|
|
44
|
-
else if (typeof paintColor == 'object' &&
|
|
45
|
-
'stops' in paintColor &&
|
|
46
|
-
Array.isArray(paintColor === null || paintColor === void 0 ? void 0 : paintColor.stops)) {
|
|
47
|
-
const stops = paintColor['stops'].map((stop) => {
|
|
48
|
-
const newColor = transformColor(stop[1], func);
|
|
49
|
-
return [stop[0], newColor];
|
|
50
|
-
});
|
|
51
|
-
const newPaintColor = Object.assign({}, paintColor, { stops });
|
|
52
|
-
return newPaintColor;
|
|
53
|
-
}
|
|
54
|
-
else
|
|
55
|
-
return paintColor;
|
|
56
|
-
}
|
|
57
|
-
/*
|
|
58
|
-
This is the function used to generate the current EMS desaturated roadmap
|
|
59
|
-
*/
|
|
60
|
-
function desaturateColor(paintColor) {
|
|
61
|
-
return transformColor(paintColor, (color) => {
|
|
62
|
-
return (0, chroma_js_1.default)(color).desaturate(1.1).brighten(0.33);
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
exports.desaturateColor = desaturateColor;
|
|
66
|
-
/*
|
|
67
|
-
Blends an original maplibre color definition with a destination
|
|
68
|
-
color. Accepts different blending modes and an additional `mix`
|
|
69
|
-
option that needs a percentage.
|
|
70
|
-
|
|
71
|
-
More details:
|
|
72
|
-
|
|
73
|
-
https://gka.github.io/chroma.js/#chroma-blend
|
|
74
|
-
https://gka.github.io/chroma.js/#chroma-mix
|
|
75
|
-
*/
|
|
76
|
-
function colorizeColor(sourceColor, destColor, operation = 'screen', percentage = 0.5) {
|
|
77
|
-
return transformColor(sourceColor, (color) => {
|
|
78
|
-
if (operation !== 'mix') {
|
|
79
|
-
return chroma_js_1.default.blend((0, chroma_js_1.default)(color), destColor, operation);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
return chroma_js_1.default.mix((0, chroma_js_1.default)(color), destColor, percentage);
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
exports.colorizeColor = colorizeColor;
|