@versatiles/style 5.2.6 → 5.2.7
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/dist/index.d.ts +274 -14
- package/dist/index.js +3650 -11
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
- package/src/color/abstract.ts +83 -0
- package/src/color/hsl.test.ts +182 -0
- package/src/color/hsl.ts +122 -0
- package/src/color/hsv.test.ts +174 -0
- package/src/color/hsv.ts +100 -0
- package/src/color/index.test.ts +119 -0
- package/src/color/index.ts +38 -0
- package/src/color/random.test.ts +35 -0
- package/src/color/random.ts +165 -0
- package/src/color/rgb.test.ts +227 -0
- package/src/color/rgb.ts +248 -0
- package/src/color/utils.test.ts +86 -0
- package/src/color/utils.ts +13 -0
- package/src/guess_style/guess_style.test.ts +134 -0
- package/src/guess_style/guess_style.ts +166 -0
- package/{dist/guess_style/index.d.ts → src/guess_style/index.ts} +1 -0
- package/src/index.test.ts +77 -0
- package/src/index.ts +18 -0
- package/src/lib/utils.test.ts +197 -0
- package/src/lib/utils.ts +134 -0
- package/{dist/shortbread/index.d.ts → src/shortbread/index.ts} +1 -0
- package/src/shortbread/layers.test.ts +36 -0
- package/src/shortbread/layers.ts +564 -0
- package/src/shortbread/properties.test.ts +44 -0
- package/src/shortbread/properties.ts +142 -0
- package/src/shortbread/template.test.ts +43 -0
- package/src/shortbread/template.ts +343 -0
- package/src/style_builder/decorator.test.ts +67 -0
- package/src/style_builder/decorator.ts +135 -0
- package/src/style_builder/recolor.test.ts +306 -0
- package/src/style_builder/recolor.ts +110 -0
- package/src/style_builder/style_builder.test.ts +103 -0
- package/src/style_builder/style_builder.ts +134 -0
- package/src/style_builder/types.ts +141 -0
- package/src/styles/LICENSE.md +41 -0
- package/src/styles/colorful.ts +1041 -0
- package/src/styles/eclipse.ts +11 -0
- package/{dist/styles/empty.d.ts → src/styles/empty.ts} +7 -3
- package/src/styles/graybeard.ts +11 -0
- package/src/styles/index.ts +33 -0
- package/src/styles/neutrino.ts +429 -0
- package/{dist/types/index.d.ts → src/types/index.ts} +1 -0
- package/{dist/types/maplibre.d.ts → src/types/maplibre.ts} +3 -0
- package/src/types/tilejson.test.ts +94 -0
- package/src/types/tilejson.ts +125 -0
- package/src/types/vector_layer.test.ts +64 -0
- package/src/types/vector_layer.ts +69 -0
- package/dist/color/abstract.d.ts +0 -34
- package/dist/color/abstract.js +0 -53
- package/dist/color/abstract.js.map +0 -1
- package/dist/color/hsl.d.ts +0 -23
- package/dist/color/hsl.js +0 -98
- package/dist/color/hsl.js.map +0 -1
- package/dist/color/hsv.d.ts +0 -20
- package/dist/color/hsv.js +0 -100
- package/dist/color/hsv.js.map +0 -1
- package/dist/color/index.d.ts +0 -6
- package/dist/color/index.js +0 -29
- package/dist/color/index.js.map +0 -1
- package/dist/color/random.d.ts +0 -9
- package/dist/color/random.js +0 -134
- package/dist/color/random.js.map +0 -1
- package/dist/color/rgb.d.ts +0 -28
- package/dist/color/rgb.js +0 -195
- package/dist/color/rgb.js.map +0 -1
- package/dist/color/utils.d.ts +0 -3
- package/dist/color/utils.js +0 -10
- package/dist/color/utils.js.map +0 -1
- package/dist/guess_style/guess_style.d.ts +0 -8
- package/dist/guess_style/guess_style.js +0 -147
- package/dist/guess_style/guess_style.js.map +0 -1
- package/dist/guess_style/index.js +0 -2
- package/dist/guess_style/index.js.map +0 -1
- package/dist/lib/utils.d.ts +0 -6
- package/dist/lib/utils.js +0 -126
- package/dist/lib/utils.js.map +0 -1
- package/dist/shortbread/index.js +0 -3
- package/dist/shortbread/index.js.map +0 -1
- package/dist/shortbread/layers.d.ts +0 -5
- package/dist/shortbread/layers.js +0 -521
- package/dist/shortbread/layers.js.map +0 -1
- package/dist/shortbread/properties.d.ts +0 -7
- package/dist/shortbread/properties.js +0 -125
- package/dist/shortbread/properties.js.map +0 -1
- package/dist/shortbread/template.d.ts +0 -4
- package/dist/shortbread/template.js +0 -339
- package/dist/shortbread/template.js.map +0 -1
- package/dist/style_builder/decorator.d.ts +0 -4
- package/dist/style_builder/decorator.js +0 -127
- package/dist/style_builder/decorator.js.map +0 -1
- package/dist/style_builder/recolor.d.ts +0 -22
- package/dist/style_builder/recolor.js +0 -89
- package/dist/style_builder/recolor.js.map +0 -1
- package/dist/style_builder/style_builder.d.ts +0 -15
- package/dist/style_builder/style_builder.js +0 -106
- package/dist/style_builder/style_builder.js.map +0 -1
- package/dist/style_builder/types.d.ts +0 -122
- package/dist/style_builder/types.js +0 -3
- package/dist/style_builder/types.js.map +0 -1
- package/dist/styles/colorful.d.ts +0 -11
- package/dist/styles/colorful.js +0 -956
- package/dist/styles/colorful.js.map +0 -1
- package/dist/styles/eclipse.d.ts +0 -5
- package/dist/styles/eclipse.js +0 -9
- package/dist/styles/eclipse.js.map +0 -1
- package/dist/styles/empty.js +0 -8
- package/dist/styles/empty.js.map +0 -1
- package/dist/styles/graybeard.d.ts +0 -5
- package/dist/styles/graybeard.js +0 -9
- package/dist/styles/graybeard.js.map +0 -1
- package/dist/styles/index.d.ts +0 -11
- package/dist/styles/index.js +0 -20
- package/dist/styles/index.js.map +0 -1
- package/dist/styles/neutrino.d.ts +0 -11
- package/dist/styles/neutrino.js +0 -401
- package/dist/styles/neutrino.js.map +0 -1
- package/dist/types/index.js +0 -3
- package/dist/types/index.js.map +0 -1
- package/dist/types/maplibre.js +0 -2
- package/dist/types/maplibre.js.map +0 -1
- package/dist/types/tilejson.d.ts +0 -32
- package/dist/types/tilejson.js +0 -87
- package/dist/types/tilejson.js.map +0 -1
- package/dist/types/vector_layer.d.ts +0 -14
- package/dist/types/vector_layer.js +0 -51
- package/dist/types/vector_layer.js.map +0 -1
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
|
|
2
|
+
export interface ShortbreadProperty {
|
|
3
|
+
readonly key: string;
|
|
4
|
+
readonly parent: 'layer' | 'layout' | 'paint';
|
|
5
|
+
readonly valueType: 'array' | 'boolean' | 'color' | 'enum' | 'filter' | 'fonts' | 'formatted' | 'number' | 'padding' | 'resolvedImage' | 'variableAnchorOffsetCollection';
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
type ShortbreadPropertyDef = ShortbreadProperty & {
|
|
9
|
+
readonly types: string;
|
|
10
|
+
readonly short?: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const propertyLookup = new Map<string, ShortbreadProperty[]>();
|
|
14
|
+
|
|
15
|
+
const propertyDefs: ShortbreadPropertyDef[] = [
|
|
16
|
+
{ parent: 'layer', types: 'background,fill,line,symbol', key: 'filter', valueType: 'filter' },
|
|
17
|
+
{ parent: 'layer', types: 'background,fill,line,symbol', key: 'maxzoom', valueType: 'number' },
|
|
18
|
+
{ parent: 'layer', types: 'background,fill,line,symbol', key: 'minzoom', valueType: 'number' },
|
|
19
|
+
|
|
20
|
+
{ parent: 'layout', types: 'background,fill,line,symbol', key: 'visibility', valueType: 'enum' },
|
|
21
|
+
{ parent: 'layout', types: 'fill', key: 'fill-sort-key', valueType: 'number' },
|
|
22
|
+
{ parent: 'layout', types: 'line', key: 'line-cap', valueType: 'enum' },
|
|
23
|
+
{ parent: 'layout', types: 'line', key: 'line-join', valueType: 'enum' },
|
|
24
|
+
{ parent: 'layout', types: 'line', key: 'line-miter-limit', valueType: 'number' },
|
|
25
|
+
{ parent: 'layout', types: 'line', key: 'line-round-limit', valueType: 'number' },
|
|
26
|
+
{ parent: 'layout', types: 'line', key: 'line-sort-key', valueType: 'number' },
|
|
27
|
+
{ parent: 'layout', types: 'symbol', key: 'icon-allow-overlap', valueType: 'boolean' },
|
|
28
|
+
{ parent: 'layout', types: 'symbol', key: 'icon-anchor', valueType: 'enum' },
|
|
29
|
+
{ parent: 'layout', types: 'symbol', key: 'icon-ignore-placement', valueType: 'boolean' },
|
|
30
|
+
{ parent: 'layout', types: 'symbol', key: 'icon-image', short: 'image', valueType: 'resolvedImage' },
|
|
31
|
+
{ parent: 'layout', types: 'symbol', key: 'icon-keep-upright', valueType: 'boolean' },
|
|
32
|
+
{ parent: 'layout', types: 'symbol', key: 'icon-offset', valueType: 'array' },
|
|
33
|
+
{ parent: 'layout', types: 'symbol', key: 'icon-optional', valueType: 'boolean' },
|
|
34
|
+
{ parent: 'layout', types: 'symbol', key: 'icon-overlap', valueType: 'enum' },
|
|
35
|
+
{ parent: 'layout', types: 'symbol', key: 'icon-padding', valueType: 'padding' },
|
|
36
|
+
{ parent: 'layout', types: 'symbol', key: 'icon-pitch-alignment', valueType: 'enum' },
|
|
37
|
+
{ parent: 'layout', types: 'symbol', key: 'icon-rotate', valueType: 'number' },
|
|
38
|
+
{ parent: 'layout', types: 'symbol', key: 'icon-rotation-alignment', valueType: 'enum' },
|
|
39
|
+
{ parent: 'layout', types: 'symbol', key: 'icon-size', valueType: 'number' },
|
|
40
|
+
{ parent: 'layout', types: 'symbol', key: 'icon-text-fit-padding', valueType: 'array' },
|
|
41
|
+
{ parent: 'layout', types: 'symbol', key: 'icon-text-fit', valueType: 'enum' },
|
|
42
|
+
{ parent: 'layout', types: 'symbol', key: 'symbol-avoid-edges', valueType: 'boolean' },
|
|
43
|
+
{ parent: 'layout', types: 'symbol', key: 'symbol-placement', valueType: 'enum' },
|
|
44
|
+
{ parent: 'layout', types: 'symbol', key: 'symbol-sort-key', valueType: 'number' },
|
|
45
|
+
{ parent: 'layout', types: 'symbol', key: 'symbol-spacing', valueType: 'number' },
|
|
46
|
+
{ parent: 'layout', types: 'symbol', key: 'symbol-z-order', valueType: 'enum' },
|
|
47
|
+
{ parent: 'layout', types: 'symbol', key: 'text-allow-overlap', valueType: 'boolean' },
|
|
48
|
+
{ parent: 'layout', types: 'symbol', key: 'text-anchor', valueType: 'enum' },
|
|
49
|
+
{ parent: 'layout', types: 'symbol', key: 'text-field', short: 'text', valueType: 'formatted' },
|
|
50
|
+
{ parent: 'layout', types: 'symbol', key: 'text-font', short: 'font', valueType: 'fonts' },
|
|
51
|
+
{ parent: 'layout', types: 'symbol', key: 'text-ignore-placement', valueType: 'boolean' },
|
|
52
|
+
{ parent: 'layout', types: 'symbol', key: 'text-justify', valueType: 'enum' },
|
|
53
|
+
{ parent: 'layout', types: 'symbol', key: 'text-keep-upright', valueType: 'boolean' },
|
|
54
|
+
{ parent: 'layout', types: 'symbol', key: 'text-letter-spacing', valueType: 'number' },
|
|
55
|
+
{ parent: 'layout', types: 'symbol', key: 'text-line-height', valueType: 'number' },
|
|
56
|
+
{ parent: 'layout', types: 'symbol', key: 'text-max-angle', valueType: 'number' },
|
|
57
|
+
{ parent: 'layout', types: 'symbol', key: 'text-max-width', valueType: 'number' },
|
|
58
|
+
{ parent: 'layout', types: 'symbol', key: 'text-offset', valueType: 'array' },
|
|
59
|
+
{ parent: 'layout', types: 'symbol', key: 'text-optional', valueType: 'boolean' },
|
|
60
|
+
{ parent: 'layout', types: 'symbol', key: 'text-overlap', valueType: 'enum' },
|
|
61
|
+
{ parent: 'layout', types: 'symbol', key: 'text-padding', valueType: 'number' },
|
|
62
|
+
{ parent: 'layout', types: 'symbol', key: 'text-pitch-alignment', valueType: 'enum' },
|
|
63
|
+
{ parent: 'layout', types: 'symbol', key: 'text-radial-offset', valueType: 'number' },
|
|
64
|
+
{ parent: 'layout', types: 'symbol', key: 'text-rotate', valueType: 'number' },
|
|
65
|
+
{ parent: 'layout', types: 'symbol', key: 'text-rotation-alignment', valueType: 'enum' },
|
|
66
|
+
{ parent: 'layout', types: 'symbol', key: 'text-size', short: 'size', valueType: 'number' },
|
|
67
|
+
{ parent: 'layout', types: 'symbol', key: 'text-transform', valueType: 'enum' },
|
|
68
|
+
{ parent: 'layout', types: 'symbol', key: 'text-variable-anchor-offset', valueType: 'variableAnchorOffsetCollection' },
|
|
69
|
+
{ parent: 'layout', types: 'symbol', key: 'text-variable-anchor', valueType: 'array' },
|
|
70
|
+
{ parent: 'layout', types: 'symbol', key: 'text-writing-mode', valueType: 'array' },
|
|
71
|
+
|
|
72
|
+
{ parent: 'paint', types: 'background', key: 'background-color', short: 'color', valueType: 'color' },
|
|
73
|
+
{ parent: 'paint', types: 'background', key: 'background-opacity', short: 'opacity', valueType: 'number' },
|
|
74
|
+
{ parent: 'paint', types: 'background', key: 'background-pattern', short: 'image', valueType: 'resolvedImage' },
|
|
75
|
+
{ parent: 'paint', types: 'fill', key: 'fill-antialias', valueType: 'boolean' },
|
|
76
|
+
{ parent: 'paint', types: 'fill', key: 'fill-color', short: 'color', valueType: 'color' },
|
|
77
|
+
{ parent: 'paint', types: 'fill', key: 'fill-extrusion-base', valueType: 'number' },
|
|
78
|
+
{ parent: 'paint', types: 'fill', key: 'fill-extrusion-color', valueType: 'color' },
|
|
79
|
+
{ parent: 'paint', types: 'fill', key: 'fill-extrusion-height', valueType: 'number' },
|
|
80
|
+
{ parent: 'paint', types: 'fill', key: 'fill-extrusion-opacity', valueType: 'number' },
|
|
81
|
+
{ parent: 'paint', types: 'fill', key: 'fill-extrusion-pattern', valueType: 'resolvedImage' },
|
|
82
|
+
{ parent: 'paint', types: 'fill', key: 'fill-extrusion-translate-anchor', valueType: 'enum' },
|
|
83
|
+
{ parent: 'paint', types: 'fill', key: 'fill-extrusion-translate', valueType: 'array' },
|
|
84
|
+
{ parent: 'paint', types: 'fill', key: 'fill-extrusion-vertical-gradient', valueType: 'boolean' },
|
|
85
|
+
{ parent: 'paint', types: 'fill', key: 'fill-opacity', short: 'opacity', valueType: 'number' },
|
|
86
|
+
{ parent: 'paint', types: 'fill', key: 'fill-outline-color', valueType: 'color' },
|
|
87
|
+
{ parent: 'paint', types: 'fill', key: 'fill-pattern', short: 'image', valueType: 'resolvedImage' },
|
|
88
|
+
{ parent: 'paint', types: 'fill', key: 'fill-translate-anchor', valueType: 'enum' },
|
|
89
|
+
{ parent: 'paint', types: 'fill', key: 'fill-translate', valueType: 'array' },
|
|
90
|
+
{ parent: 'paint', types: 'line', key: 'line-blur', valueType: 'number' },
|
|
91
|
+
{ parent: 'paint', types: 'line', key: 'line-color', short: 'color', valueType: 'color' },
|
|
92
|
+
{ parent: 'paint', types: 'line', key: 'line-dasharray', valueType: 'array' },
|
|
93
|
+
{ parent: 'paint', types: 'line', key: 'line-gap-width', valueType: 'number' },
|
|
94
|
+
{ parent: 'paint', types: 'line', key: 'line-gradient', valueType: 'color' },
|
|
95
|
+
{ parent: 'paint', types: 'line', key: 'line-offset', valueType: 'number' },
|
|
96
|
+
{ parent: 'paint', types: 'line', key: 'line-opacity', short: 'opacity', valueType: 'number' },
|
|
97
|
+
{ parent: 'paint', types: 'line', key: 'line-pattern', short: 'image', valueType: 'resolvedImage' },
|
|
98
|
+
{ parent: 'paint', types: 'line', key: 'line-translate-anchor', valueType: 'enum' },
|
|
99
|
+
{ parent: 'paint', types: 'line', key: 'line-translate', valueType: 'array' },
|
|
100
|
+
{ parent: 'paint', types: 'line', key: 'line-width', short: 'size', valueType: 'number' },
|
|
101
|
+
{ parent: 'paint', types: 'symbol', key: 'icon-color', short: 'color', valueType: 'color' },
|
|
102
|
+
{ parent: 'paint', types: 'symbol', key: 'icon-halo-blur', valueType: 'number' },
|
|
103
|
+
{ parent: 'paint', types: 'symbol', key: 'icon-halo-color', valueType: 'color' },
|
|
104
|
+
{ parent: 'paint', types: 'symbol', key: 'icon-halo-width', valueType: 'number' },
|
|
105
|
+
{ parent: 'paint', types: 'symbol', key: 'icon-opacity', short: 'opacity', valueType: 'number' },
|
|
106
|
+
{ parent: 'paint', types: 'symbol', key: 'icon-translate-anchor', valueType: 'enum' },
|
|
107
|
+
{ parent: 'paint', types: 'symbol', key: 'icon-translate', valueType: 'array' },
|
|
108
|
+
{ parent: 'paint', types: 'symbol', key: 'text-color', short: 'color', valueType: 'color' },
|
|
109
|
+
{ parent: 'paint', types: 'symbol', key: 'text-halo-blur', valueType: 'number' },
|
|
110
|
+
{ parent: 'paint', types: 'symbol', key: 'text-halo-color', valueType: 'color' },
|
|
111
|
+
{ parent: 'paint', types: 'symbol', key: 'text-halo-width', valueType: 'number' },
|
|
112
|
+
{ parent: 'paint', types: 'symbol', key: 'text-opacity', short: 'opacity', valueType: 'number' },
|
|
113
|
+
{ parent: 'paint', types: 'symbol', key: 'text-translate-anchor', valueType: 'enum' },
|
|
114
|
+
{ parent: 'paint', types: 'symbol', key: 'text-translate', valueType: 'array' },
|
|
115
|
+
];
|
|
116
|
+
|
|
117
|
+
propertyDefs.forEach((propertyDef: ShortbreadPropertyDef) => {
|
|
118
|
+
const types: string = propertyDef.types;
|
|
119
|
+
|
|
120
|
+
types.split(',').forEach((type: string) => {
|
|
121
|
+
|
|
122
|
+
function add(propertyKey: string): void {
|
|
123
|
+
const key = type + '/' + propertyKey;
|
|
124
|
+
const property: ShortbreadProperty = {
|
|
125
|
+
key: propertyDef.key,
|
|
126
|
+
parent: propertyDef.parent,
|
|
127
|
+
valueType: propertyDef.valueType,
|
|
128
|
+
};
|
|
129
|
+
const propertyList: ShortbreadProperty[] | undefined = propertyLookup.get(key);
|
|
130
|
+
if (propertyList) {
|
|
131
|
+
propertyList.push(property);
|
|
132
|
+
} else {
|
|
133
|
+
propertyLookup.set(key, [property]);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
add(propertyDef.key);
|
|
138
|
+
if (propertyDef.short != null) add(propertyDef.short);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
export default propertyLookup;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { VectorSourceSpecification } from '@maplibre/maplibre-gl-style-spec';
|
|
2
|
+
import { getShortbreadTemplate } from './template.js';
|
|
3
|
+
|
|
4
|
+
describe('getShortbreadTemplate', () => {
|
|
5
|
+
const styleTemplate = getShortbreadTemplate();
|
|
6
|
+
|
|
7
|
+
it('returns a style object with the correct version', () => {
|
|
8
|
+
expect(styleTemplate).toHaveProperty('version', 8);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('has the expected name for the style', () => {
|
|
12
|
+
expect(styleTemplate).toHaveProperty('name', 'versatiles');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('contains metadata with expected properties', () => {
|
|
16
|
+
expect(styleTemplate).toHaveProperty('metadata');
|
|
17
|
+
expect(styleTemplate.metadata).toHaveProperty('license', 'https://creativecommons.org/publicdomain/zero/1.0/');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('specifies glyphs and sprite URLs correctly', () => {
|
|
21
|
+
expect(styleTemplate).toHaveProperty('glyphs', 'https://tiles.versatiles.org/assets/glyphs/{fontstack}/{range}.pbf');
|
|
22
|
+
expect(styleTemplate).toHaveProperty('sprite', [{ id: 'basics', url: 'https://tiles.versatiles.org/assets/sprites/basics/sprites' }]);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('defines sources with required properties', () => {
|
|
26
|
+
expect(styleTemplate).toHaveProperty('sources');
|
|
27
|
+
const sources = styleTemplate.sources['versatiles-shortbread'] as VectorSourceSpecification;
|
|
28
|
+
expect(sources).toHaveProperty('type', 'vector');
|
|
29
|
+
expect(sources).toHaveProperty('scheme', 'xyz');
|
|
30
|
+
expect(sources).toHaveProperty('tiles');
|
|
31
|
+
expect(sources.tiles).toContain('https://tiles.versatiles.org/tiles/osm/{z}/{x}/{y}');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('sets bounds to the expected global extent', () => {
|
|
35
|
+
const expectedBounds = [-180, -85.0511287798066, 180, 85.0511287798066];
|
|
36
|
+
expect(styleTemplate.sources['versatiles-shortbread']).toHaveProperty('bounds', expectedBounds);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('has layers array initialized as empty', () => {
|
|
40
|
+
expect(styleTemplate).toHaveProperty('layers');
|
|
41
|
+
expect(styleTemplate.layers).toEqual([]);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
import { StyleSpecification } from "@maplibre/maplibre-gl-style-spec";
|
|
2
|
+
import { VectorLayer } from "../types/vector_layer.js";
|
|
3
|
+
|
|
4
|
+
const maxzoom = 14;
|
|
5
|
+
|
|
6
|
+
export function getShortbreadTemplate(): StyleSpecification {
|
|
7
|
+
return {
|
|
8
|
+
version: 8,
|
|
9
|
+
name: 'versatiles',
|
|
10
|
+
metadata: {
|
|
11
|
+
license: 'https://creativecommons.org/publicdomain/zero/1.0/',
|
|
12
|
+
},
|
|
13
|
+
glyphs: 'https://tiles.versatiles.org/assets/glyphs/{fontstack}/{range}.pbf',
|
|
14
|
+
sprite: [{ id: 'basics', url: 'https://tiles.versatiles.org/assets/sprites/basics/sprites' }],
|
|
15
|
+
sources: {
|
|
16
|
+
'versatiles-shortbread': {
|
|
17
|
+
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
|
|
18
|
+
tiles: [
|
|
19
|
+
'https://tiles.versatiles.org/tiles/osm/{z}/{x}/{y}',
|
|
20
|
+
],
|
|
21
|
+
type: 'vector',
|
|
22
|
+
scheme: 'xyz',
|
|
23
|
+
bounds: [
|
|
24
|
+
-180,
|
|
25
|
+
-85.0511287798066,
|
|
26
|
+
180,
|
|
27
|
+
85.0511287798066,
|
|
28
|
+
],
|
|
29
|
+
minzoom: 0,
|
|
30
|
+
maxzoom
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
layers: [],
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function getShortbreadVectorLayers(): VectorLayer[] {
|
|
38
|
+
return [
|
|
39
|
+
{
|
|
40
|
+
id: 'place_labels',
|
|
41
|
+
fields: {
|
|
42
|
+
kind: 'String',
|
|
43
|
+
name: 'String',
|
|
44
|
+
name_de: 'String',
|
|
45
|
+
name_en: 'String',
|
|
46
|
+
population: 'Number',
|
|
47
|
+
},
|
|
48
|
+
minzoom: 3,
|
|
49
|
+
maxzoom,
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
id: 'boundaries',
|
|
53
|
+
fields: {
|
|
54
|
+
admin_level: 'Number',
|
|
55
|
+
coastline: 'Boolean',
|
|
56
|
+
disputed: 'Boolean',
|
|
57
|
+
maritime: 'Boolean',
|
|
58
|
+
},
|
|
59
|
+
minzoom: 0,
|
|
60
|
+
maxzoom,
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
id: 'boundary_labels',
|
|
64
|
+
fields: {
|
|
65
|
+
admin_level: 'Number',
|
|
66
|
+
land_area: 'Number',
|
|
67
|
+
name: 'String',
|
|
68
|
+
name_de: 'String',
|
|
69
|
+
name_en: 'String',
|
|
70
|
+
name_single: 'String',
|
|
71
|
+
way_area: 'Number',
|
|
72
|
+
},
|
|
73
|
+
minzoom: 2,
|
|
74
|
+
maxzoom,
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
id: 'addresses',
|
|
78
|
+
fields: {
|
|
79
|
+
housename: 'String',
|
|
80
|
+
housenumber: 'String',
|
|
81
|
+
},
|
|
82
|
+
minzoom: 14,
|
|
83
|
+
maxzoom,
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
id: 'water_lines',
|
|
87
|
+
fields: {
|
|
88
|
+
bridge: 'Boolean',
|
|
89
|
+
kind: 'String',
|
|
90
|
+
tunnel: 'Boolean',
|
|
91
|
+
},
|
|
92
|
+
minzoom: 4,
|
|
93
|
+
maxzoom,
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
id: 'water_lines_labels',
|
|
97
|
+
fields: {
|
|
98
|
+
bridge: 'Boolean',
|
|
99
|
+
kind: 'String',
|
|
100
|
+
name: 'String',
|
|
101
|
+
name_de: 'String',
|
|
102
|
+
name_en: 'String',
|
|
103
|
+
tunnel: 'Boolean',
|
|
104
|
+
},
|
|
105
|
+
minzoom: 4,
|
|
106
|
+
maxzoom,
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
id: 'dam_lines',
|
|
110
|
+
fields: {
|
|
111
|
+
kind: 'String',
|
|
112
|
+
},
|
|
113
|
+
minzoom: 12,
|
|
114
|
+
maxzoom,
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
id: 'dam_polygons',
|
|
118
|
+
fields: {
|
|
119
|
+
kind: 'String',
|
|
120
|
+
},
|
|
121
|
+
minzoom: 12,
|
|
122
|
+
maxzoom,
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
id: 'pier_lines',
|
|
126
|
+
fields: {
|
|
127
|
+
kind: 'String',
|
|
128
|
+
},
|
|
129
|
+
minzoom: 12,
|
|
130
|
+
maxzoom,
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
id: 'pier_polygons',
|
|
134
|
+
fields: {
|
|
135
|
+
kind: 'String',
|
|
136
|
+
},
|
|
137
|
+
minzoom: 12,
|
|
138
|
+
maxzoom,
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
id: 'bridges',
|
|
142
|
+
fields: {
|
|
143
|
+
kind: 'String',
|
|
144
|
+
},
|
|
145
|
+
minzoom: 12,
|
|
146
|
+
maxzoom,
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
id: 'street_polygons',
|
|
150
|
+
fields: {
|
|
151
|
+
bridge: 'Boolean',
|
|
152
|
+
kind: 'String',
|
|
153
|
+
rail: 'Boolean',
|
|
154
|
+
service: 'String',
|
|
155
|
+
surface: 'String',
|
|
156
|
+
tunnel: 'Boolean',
|
|
157
|
+
},
|
|
158
|
+
minzoom: 11,
|
|
159
|
+
maxzoom,
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
id: 'streets_polygons_labels',
|
|
163
|
+
fields: {
|
|
164
|
+
kind: 'String',
|
|
165
|
+
name: 'String',
|
|
166
|
+
name_de: 'String',
|
|
167
|
+
name_en: 'String',
|
|
168
|
+
},
|
|
169
|
+
minzoom: 14,
|
|
170
|
+
maxzoom,
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
id: 'ferries',
|
|
174
|
+
fields: {
|
|
175
|
+
kind: 'String',
|
|
176
|
+
name: 'String',
|
|
177
|
+
name_de: 'String',
|
|
178
|
+
name_en: 'String',
|
|
179
|
+
},
|
|
180
|
+
minzoom: 8,
|
|
181
|
+
maxzoom,
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
id: 'streets',
|
|
185
|
+
fields: {
|
|
186
|
+
bicycle: 'String',
|
|
187
|
+
bridge: 'Boolean',
|
|
188
|
+
horse: 'String',
|
|
189
|
+
kind: 'String',
|
|
190
|
+
link: 'Boolean',
|
|
191
|
+
oneway: 'Boolean',
|
|
192
|
+
oneway_reverse: 'Boolean',
|
|
193
|
+
rail: 'Boolean',
|
|
194
|
+
service: 'String',
|
|
195
|
+
surface: 'String',
|
|
196
|
+
tracktype: 'String',
|
|
197
|
+
tunnel: 'Boolean',
|
|
198
|
+
},
|
|
199
|
+
minzoom: 5,
|
|
200
|
+
maxzoom,
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
id: 'street_labels',
|
|
204
|
+
fields: {
|
|
205
|
+
kind: 'String',
|
|
206
|
+
name: 'String',
|
|
207
|
+
name_de: 'String',
|
|
208
|
+
name_en: 'String',
|
|
209
|
+
ref: 'String',
|
|
210
|
+
ref_cols: 'Number',
|
|
211
|
+
ref_rows: 'Number',
|
|
212
|
+
tunnel: 'Boolean',
|
|
213
|
+
},
|
|
214
|
+
minzoom: 10,
|
|
215
|
+
maxzoom,
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
id: 'street_labels_points',
|
|
219
|
+
fields: {
|
|
220
|
+
kind: 'String',
|
|
221
|
+
name: 'String',
|
|
222
|
+
name_de: 'String',
|
|
223
|
+
name_en: 'String',
|
|
224
|
+
ref: 'String',
|
|
225
|
+
},
|
|
226
|
+
minzoom: 12,
|
|
227
|
+
maxzoom,
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
id: 'aerialways',
|
|
231
|
+
fields: {
|
|
232
|
+
kind: 'String',
|
|
233
|
+
},
|
|
234
|
+
minzoom: 12,
|
|
235
|
+
maxzoom,
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
id: 'public_transport',
|
|
239
|
+
fields: {
|
|
240
|
+
iata: 'String',
|
|
241
|
+
kind: 'String',
|
|
242
|
+
name: 'String',
|
|
243
|
+
name_de: 'String',
|
|
244
|
+
name_en: 'String',
|
|
245
|
+
station: 'String',
|
|
246
|
+
},
|
|
247
|
+
minzoom: 11,
|
|
248
|
+
maxzoom,
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
id: 'buildings',
|
|
252
|
+
fields: {
|
|
253
|
+
amenity: 'String',
|
|
254
|
+
dummy: 'Number',
|
|
255
|
+
name: 'String',
|
|
256
|
+
name_de: 'String',
|
|
257
|
+
name_en: 'String',
|
|
258
|
+
},
|
|
259
|
+
minzoom: 14,
|
|
260
|
+
maxzoom,
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
id: 'water_polygons',
|
|
264
|
+
fields: {
|
|
265
|
+
kind: 'String',
|
|
266
|
+
way_area: 'Number',
|
|
267
|
+
},
|
|
268
|
+
minzoom: 4,
|
|
269
|
+
maxzoom,
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
id: 'ocean',
|
|
273
|
+
fields: {
|
|
274
|
+
x: 'Number',
|
|
275
|
+
y: 'Number',
|
|
276
|
+
},
|
|
277
|
+
minzoom: 0,
|
|
278
|
+
maxzoom,
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
id: 'water_polygons_labels',
|
|
282
|
+
fields: {
|
|
283
|
+
kind: 'String',
|
|
284
|
+
name: 'String',
|
|
285
|
+
name_de: 'String',
|
|
286
|
+
name_en: 'String',
|
|
287
|
+
way_area: 'Number',
|
|
288
|
+
},
|
|
289
|
+
minzoom: 14,
|
|
290
|
+
maxzoom,
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
id: 'land',
|
|
294
|
+
fields: {
|
|
295
|
+
kind: 'String',
|
|
296
|
+
},
|
|
297
|
+
minzoom: 7,
|
|
298
|
+
maxzoom,
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
id: 'sites',
|
|
302
|
+
fields: {
|
|
303
|
+
amenity: 'String',
|
|
304
|
+
kind: 'String',
|
|
305
|
+
name: 'String',
|
|
306
|
+
name_de: 'String',
|
|
307
|
+
name_en: 'String',
|
|
308
|
+
},
|
|
309
|
+
minzoom: 14,
|
|
310
|
+
maxzoom,
|
|
311
|
+
},
|
|
312
|
+
{
|
|
313
|
+
id: 'pois',
|
|
314
|
+
fields: {
|
|
315
|
+
amenity: 'String',
|
|
316
|
+
atm: 'Boolean',
|
|
317
|
+
cuisine: 'String',
|
|
318
|
+
denomination: 'String',
|
|
319
|
+
emergency: 'String',
|
|
320
|
+
highway: 'String',
|
|
321
|
+
historic: 'String',
|
|
322
|
+
information: 'String',
|
|
323
|
+
leisure: 'String',
|
|
324
|
+
man_made: 'String',
|
|
325
|
+
name: 'String',
|
|
326
|
+
name_de: 'String',
|
|
327
|
+
name_en: 'String',
|
|
328
|
+
'recycling:clothes': 'Boolean',
|
|
329
|
+
'recycling:glass_bottles': 'Boolean',
|
|
330
|
+
'recycling:paper': 'Boolean',
|
|
331
|
+
'recycling:scrap_metal': 'Boolean',
|
|
332
|
+
religion: 'String',
|
|
333
|
+
shop: 'String',
|
|
334
|
+
sport: 'String',
|
|
335
|
+
tourism: 'String',
|
|
336
|
+
'tower:type': 'String',
|
|
337
|
+
vending: 'String',
|
|
338
|
+
},
|
|
339
|
+
minzoom: 14,
|
|
340
|
+
maxzoom,
|
|
341
|
+
},
|
|
342
|
+
]
|
|
343
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { decorate } from './decorator.js';
|
|
2
|
+
import { Color } from '../color/index.js';
|
|
3
|
+
import type { MaplibreLayer } from '../types/maplibre.js';
|
|
4
|
+
import { CachedRecolor } from './recolor.js';
|
|
5
|
+
|
|
6
|
+
describe('decorate function', () => {
|
|
7
|
+
const mockLayers: MaplibreLayer[] = [
|
|
8
|
+
{ id: 'layer1', type: 'fill', layout: {}, paint: {}, source: 'versatiles-shortbread' },
|
|
9
|
+
{ id: 'layer2', type: 'line', layout: {}, paint: {}, source: 'versatiles-shortbread' },
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
const mockRules = {
|
|
13
|
+
'layer1': {
|
|
14
|
+
color: '#ff0000',
|
|
15
|
+
visibility: 'none',
|
|
16
|
+
},
|
|
17
|
+
'layer2': {
|
|
18
|
+
color: 'rgba(0, 255, 0, 0.5)',
|
|
19
|
+
visibility: 'visible',
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const noRecolor = new CachedRecolor();
|
|
24
|
+
|
|
25
|
+
it('should return an array of layers', () => {
|
|
26
|
+
const result = decorate(mockLayers, mockRules, noRecolor);
|
|
27
|
+
expect(Array.isArray(result)).toBe(true);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should apply styles from rules to the corresponding layers', () => {
|
|
31
|
+
const result = decorate(mockLayers, mockRules, noRecolor);
|
|
32
|
+
|
|
33
|
+
result.forEach(layer => {
|
|
34
|
+
if (layer.id === 'layer1') {
|
|
35
|
+
expect(layer.paint).toHaveProperty('fill-color', 'rgb(255,0,0)');
|
|
36
|
+
expect(layer.layout).toHaveProperty('visibility', 'none');
|
|
37
|
+
}
|
|
38
|
+
if (layer.id === 'layer2') {
|
|
39
|
+
expect(layer.paint).toHaveProperty('line-color', 'rgba(0,255,0,0.5)');
|
|
40
|
+
expect(layer.layout).toHaveProperty('visibility', 'visible');
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should handle color conversion correctly', () => {
|
|
46
|
+
const colorRule = {
|
|
47
|
+
'layer1': {
|
|
48
|
+
paintColor: Color.parse('#ff0000'),
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
const result = decorate(mockLayers, colorRule, noRecolor);
|
|
52
|
+
const layer0: MaplibreLayer = result[0];
|
|
53
|
+
|
|
54
|
+
expect(layer0).toBeDefined();
|
|
55
|
+
if (typeof layer0 === 'undefined') return;
|
|
56
|
+
|
|
57
|
+
expect(layer0.paint).toBeDefined();
|
|
58
|
+
if (typeof layer0.paint === 'undefined') return;
|
|
59
|
+
|
|
60
|
+
expect(layer0.paint).toHaveProperty('fill-color', 'rgb(255,0,0)');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('should discard layers that have no style rules applied', () => {
|
|
64
|
+
const result = decorate(mockLayers, {}, noRecolor);
|
|
65
|
+
expect(result.length).toBe(0);
|
|
66
|
+
});
|
|
67
|
+
});
|