@elastic/ems-client 8.3.0 → 8.3.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/.backportrc.json +2 -1
- package/CHANGELOG.md +17 -2
- package/package.json +3 -1
- package/src/index.ts +1 -0
- package/src/tms_service.ts +202 -13
- package/src/utils.ts +89 -0
- package/target/index.d.ts +1 -0
- package/target/node/index.js +9 -1
- package/target/node/tms_service.js +308 -13
- package/target/node/utils.js +60 -0
- package/target/tms_service.d.ts +19 -3
- package/target/utils.d.ts +19 -0
- package/target/web/index.js +2 -1
- package/target/web/tms_service.js +386 -19
- package/target/web/utils.js +57 -0
- package/test/ems_client.test.ts +11 -4
- package/test/ems_client_colour.test.ts +140 -0
- package/test/ems_client_lang.test.ts +122 -0
- package/test/ems_client_util.ts +12 -0
- package/test/ems_mocks/sample_style_bright_vector_source.json +2 -2
- package/target/origin.d.ts +0 -4
|
@@ -0,0 +1,140 @@
|
|
|
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
|
+
import { FillLayerSpecification, LayerSpecification } from 'maplibre-gl';
|
|
9
|
+
import { TMSService } from '../src';
|
|
10
|
+
import { mlLayerTypes } from './ems_client_util';
|
|
11
|
+
import chroma from 'chroma-js';
|
|
12
|
+
|
|
13
|
+
function chroma2css(color: chroma.Color): string {
|
|
14
|
+
return `rgba(${color.rgba().join(',')})`;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
describe('Transform colours', () => {
|
|
18
|
+
it('should return an empty array for non symbol layers without any paint property to update', () => {
|
|
19
|
+
mlLayerTypes
|
|
20
|
+
.filter((l) => l != 'symbol')
|
|
21
|
+
.forEach((type) => {
|
|
22
|
+
const layer = {
|
|
23
|
+
id: 'layer',
|
|
24
|
+
type,
|
|
25
|
+
layout: {},
|
|
26
|
+
} as LayerSpecification;
|
|
27
|
+
expect(TMSService.transformColorProperties(layer, '#FF0000', 'burn', 0)).toEqual([]);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('should return an empty array for non symbol layer with an empty paint property', () => {
|
|
32
|
+
const layer = {
|
|
33
|
+
id: 'layer',
|
|
34
|
+
type: 'fill',
|
|
35
|
+
paint: {},
|
|
36
|
+
} as LayerSpecification;
|
|
37
|
+
|
|
38
|
+
expect(TMSService.transformColorProperties(layer, '#FF0000', 'lighten', 0)).toEqual([]);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('should return a text-color for symbol layers without a paint property', () => {
|
|
42
|
+
const inColor = chroma('#D36086');
|
|
43
|
+
const textColor = chroma('rgba(0,0,0,1)');
|
|
44
|
+
const inOp = 'lighten';
|
|
45
|
+
const outColor = chroma.blend(textColor, inColor, inOp);
|
|
46
|
+
|
|
47
|
+
const transform = TMSService.transformColorProperties;
|
|
48
|
+
|
|
49
|
+
const layerWithTextColor = {
|
|
50
|
+
id: 'layer',
|
|
51
|
+
type: 'symbol',
|
|
52
|
+
paint: {
|
|
53
|
+
'text-color': chroma2css(textColor),
|
|
54
|
+
},
|
|
55
|
+
} as LayerSpecification;
|
|
56
|
+
|
|
57
|
+
const layerWithoutTextColor = {
|
|
58
|
+
id: 'layer',
|
|
59
|
+
type: 'symbol',
|
|
60
|
+
paint: {},
|
|
61
|
+
} as LayerSpecification;
|
|
62
|
+
|
|
63
|
+
const resultWithTextColor = transform(layerWithTextColor, inColor.hex('rgba'), inOp, 0);
|
|
64
|
+
const resultWithoutTextColor = transform(layerWithoutTextColor, inColor.hex('rgba'), inOp, 0);
|
|
65
|
+
|
|
66
|
+
expect(resultWithTextColor).toEqual([
|
|
67
|
+
{
|
|
68
|
+
color: chroma2css(outColor),
|
|
69
|
+
property: 'text-color',
|
|
70
|
+
},
|
|
71
|
+
]);
|
|
72
|
+
expect(resultWithoutTextColor).toEqual([
|
|
73
|
+
{
|
|
74
|
+
color: chroma2css(outColor),
|
|
75
|
+
property: 'text-color',
|
|
76
|
+
},
|
|
77
|
+
]);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('should work with color expressions with stops', () => {
|
|
81
|
+
const inColor = chroma('#D36086');
|
|
82
|
+
const fillColors = [chroma('rgba(0,0,0,1)'), chroma('rgba(255,0,0,1)')];
|
|
83
|
+
const inOp = 'lighten';
|
|
84
|
+
|
|
85
|
+
const outColors = fillColors.map((fillColor) => {
|
|
86
|
+
return chroma.blend(fillColor, inColor, inOp);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const transform = TMSService.transformColorProperties;
|
|
90
|
+
|
|
91
|
+
const layerWithTextColor = {
|
|
92
|
+
id: 'layer',
|
|
93
|
+
type: 'fill',
|
|
94
|
+
source: '',
|
|
95
|
+
paint: {
|
|
96
|
+
'fill-color': {
|
|
97
|
+
base: 1,
|
|
98
|
+
stops: fillColors.map((fillColor) => {
|
|
99
|
+
return [1, chroma2css(fillColor)];
|
|
100
|
+
}),
|
|
101
|
+
} as unknown,
|
|
102
|
+
},
|
|
103
|
+
} as FillLayerSpecification;
|
|
104
|
+
|
|
105
|
+
const { color } = transform(layerWithTextColor, inColor.hex('rgba'), inOp, 0)[0];
|
|
106
|
+
|
|
107
|
+
expect(color).toEqual({
|
|
108
|
+
base: 1,
|
|
109
|
+
stops: outColors.map((fillColor) => {
|
|
110
|
+
return [1, chroma2css(fillColor)];
|
|
111
|
+
}),
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('should return the same colors if no input color is specified', () => {
|
|
116
|
+
const fillColors = ['#ff0000', '#00ff00', '#0000ff'];
|
|
117
|
+
|
|
118
|
+
const transform = TMSService.transformColorProperties;
|
|
119
|
+
|
|
120
|
+
const fillColorPaint = {
|
|
121
|
+
base: 1,
|
|
122
|
+
stops: fillColors.map((fillColor) => {
|
|
123
|
+
return [1, fillColor];
|
|
124
|
+
}),
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const layerWithFillColor = {
|
|
128
|
+
id: 'layer',
|
|
129
|
+
type: 'fill',
|
|
130
|
+
paint: {
|
|
131
|
+
'fill-color': fillColorPaint,
|
|
132
|
+
} as unknown,
|
|
133
|
+
} as FillLayerSpecification;
|
|
134
|
+
|
|
135
|
+
const { color, property } = transform(layerWithFillColor)[0];
|
|
136
|
+
|
|
137
|
+
expect(property).toEqual('fill-color');
|
|
138
|
+
expect(color).toEqual(fillColorPaint);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
@@ -0,0 +1,122 @@
|
|
|
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
|
+
import { LayerSpecification } from 'maplibre-gl';
|
|
9
|
+
import { TMSService } from '../src';
|
|
10
|
+
import { mlLayerTypes } from './ems_client_util';
|
|
11
|
+
|
|
12
|
+
describe('Support for languages', () => {
|
|
13
|
+
it('should return undefined for non symbol layers', () => {
|
|
14
|
+
mlLayerTypes
|
|
15
|
+
.filter((l) => l !== 'symbol')
|
|
16
|
+
.forEach((type) => {
|
|
17
|
+
const layer = {
|
|
18
|
+
id: 'aLayer',
|
|
19
|
+
type,
|
|
20
|
+
} as LayerSpecification;
|
|
21
|
+
|
|
22
|
+
expect(TMSService.transformLanguageProperty(layer, 'en')).toBeUndefined();
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should return undefined for non layers without a layout', () => {
|
|
27
|
+
const layer = {
|
|
28
|
+
id: 'aLayer',
|
|
29
|
+
type: 'symbol',
|
|
30
|
+
} as LayerSpecification;
|
|
31
|
+
|
|
32
|
+
expect(TMSService.transformLanguageProperty(layer, 'en')).toBeUndefined();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('should return nothing for inexistent languages', () => {
|
|
36
|
+
const enDashLayer = {
|
|
37
|
+
id: 'sampLayer',
|
|
38
|
+
type: 'symbol',
|
|
39
|
+
layout: {
|
|
40
|
+
'text-field': '{name_en}',
|
|
41
|
+
},
|
|
42
|
+
} as LayerSpecification;
|
|
43
|
+
const invalidLang = 'I_DONT_EXIST';
|
|
44
|
+
|
|
45
|
+
expect(TMSService.transformLanguageProperty(enDashLayer, invalidLang)).toBeUndefined();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('should handle {name_XX} and {name:XX} definitions', () => {
|
|
49
|
+
const enDashLayer = {
|
|
50
|
+
id: 'sampLayer',
|
|
51
|
+
type: 'symbol',
|
|
52
|
+
layout: {
|
|
53
|
+
'text-field': '{name_en}',
|
|
54
|
+
},
|
|
55
|
+
} as LayerSpecification;
|
|
56
|
+
|
|
57
|
+
const transformLangEn = TMSService.transformLanguageProperty(enDashLayer, 'en');
|
|
58
|
+
|
|
59
|
+
expect(transformLangEn).toEqual(['coalesce', ['get', 'name:en'], ['get', 'name_en']]);
|
|
60
|
+
const enColonLayer = {
|
|
61
|
+
id: 'sampLayer',
|
|
62
|
+
type: 'symbol',
|
|
63
|
+
layout: {
|
|
64
|
+
'text-field': '{name:en}',
|
|
65
|
+
},
|
|
66
|
+
} as LayerSpecification;
|
|
67
|
+
|
|
68
|
+
const transformLangJa = TMSService.transformLanguageProperty(enColonLayer, 'ja-jp');
|
|
69
|
+
|
|
70
|
+
expect(transformLangJa).toEqual(['coalesce', ['get', 'name:ja'], ['get', 'name:en']]);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('should handle {name:latin}\\n{name:nonlatin} definitions', () => {
|
|
74
|
+
const layer = {
|
|
75
|
+
id: 'sampLayer',
|
|
76
|
+
type: 'symbol',
|
|
77
|
+
layout: {
|
|
78
|
+
'text-field': '{name:latin}\n{name:nonlatin}',
|
|
79
|
+
},
|
|
80
|
+
} as LayerSpecification;
|
|
81
|
+
|
|
82
|
+
const transform = TMSService.transformLanguageProperty(layer, 'ja-jp');
|
|
83
|
+
|
|
84
|
+
expect(transform).toEqual([
|
|
85
|
+
'coalesce',
|
|
86
|
+
['get', 'name:ja'],
|
|
87
|
+
['concat', ['get', 'name:latin'], '\n', ['get', 'name:nonlatin']],
|
|
88
|
+
]);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('should handle {name:latin} {name:nonlatin} definitions', () => {
|
|
92
|
+
const layer = {
|
|
93
|
+
id: 'sampLayer',
|
|
94
|
+
type: 'symbol',
|
|
95
|
+
layout: {
|
|
96
|
+
'text-field': '{name:latin} {name:nonlatin}',
|
|
97
|
+
},
|
|
98
|
+
} as LayerSpecification;
|
|
99
|
+
|
|
100
|
+
const transform = TMSService.transformLanguageProperty(layer, 'ja-jp');
|
|
101
|
+
|
|
102
|
+
expect(transform).toEqual([
|
|
103
|
+
'coalesce',
|
|
104
|
+
['get', 'name:ja'],
|
|
105
|
+
['concat', ['get', 'name:latin'], '\n', ['get', 'name:nonlatin']],
|
|
106
|
+
]);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('should handle text field properties that are not translated', () => {
|
|
110
|
+
const layer = {
|
|
111
|
+
id: 'sampLayer',
|
|
112
|
+
type: 'symbol',
|
|
113
|
+
layout: {
|
|
114
|
+
'text-field': '{ref}',
|
|
115
|
+
},
|
|
116
|
+
} as LayerSpecification;
|
|
117
|
+
|
|
118
|
+
const transform = TMSService.transformLanguageProperty(layer, 'ja-jp');
|
|
119
|
+
|
|
120
|
+
expect(transform).toBe('{ref}');
|
|
121
|
+
});
|
|
122
|
+
});
|
package/test/ems_client_util.ts
CHANGED
|
@@ -94,3 +94,15 @@ export function getEMSClient(options = {}) {
|
|
|
94
94
|
});
|
|
95
95
|
return { emsClient, getManifestMock };
|
|
96
96
|
}
|
|
97
|
+
|
|
98
|
+
export const mlLayerTypes = [
|
|
99
|
+
'background',
|
|
100
|
+
'circle',
|
|
101
|
+
'fill-extrusion',
|
|
102
|
+
'fill',
|
|
103
|
+
'heatmap',
|
|
104
|
+
'hillshade',
|
|
105
|
+
'line',
|
|
106
|
+
'raster',
|
|
107
|
+
'symbol',
|
|
108
|
+
];
|
package/target/origin.d.ts
DELETED