@versatiles/style 4.1.2 → 4.2.0
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/README.MD +50 -26
- package/dist/browser.d.ts +4 -0
- package/dist/browser.js +2 -0
- package/dist/guess_style/guess_style.d.ts +5 -0
- package/dist/{lib → guess_style}/guess_style.js +43 -13
- package/dist/guess_style/index.d.ts +2 -0
- package/dist/guess_style/index.js +1 -0
- package/dist/guess_style/types.d.ts +23 -0
- package/dist/guess_style/types.js +1 -0
- package/dist/index.d.ts +5 -11
- package/dist/index.js +2 -15
- package/dist/shortbread/index.d.ts +2 -0
- package/dist/shortbread/index.js +2 -0
- package/dist/shortbread/layers.d.ts +5 -0
- package/dist/{lib/shortbread → shortbread}/layers.js +16 -15
- package/dist/shortbread/template.d.ts +2 -0
- package/dist/{lib/shortbread → shortbread}/template.js +1 -1
- package/dist/{lib → style_builder}/decorator.d.ts +2 -1
- package/dist/{lib → style_builder}/decorator.js +2 -2
- package/dist/style_builder/index.d.ts +1 -0
- package/dist/style_builder/index.js +1 -0
- package/dist/style_builder/recolor.d.ts +22 -0
- package/dist/style_builder/style_builder.d.ts +14 -0
- package/dist/{lib/build_style.js → style_builder/style_builder.js} +6 -7
- package/dist/style_builder/types.d.ts +49 -0
- package/dist/style_builder/types.js +1 -0
- package/dist/{style → styles}/colorful.d.ts +2 -2
- package/dist/{style → styles}/colorful.js +1 -1
- package/dist/{style → styles}/graybeard.d.ts +1 -1
- package/dist/{style → styles}/graybeard.js +1 -1
- package/dist/styles/index.d.ts +9 -0
- package/dist/styles/index.js +12 -0
- package/dist/{style → styles}/neutrino.d.ts +2 -2
- package/dist/{style → styles}/neutrino.js +1 -1
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.js +2 -0
- package/dist/types/maplibre.d.ts +22 -0
- package/dist/types/maplibre.js +1 -0
- package/dist/types/tilejson.d.ts +37 -0
- package/dist/types/tilejson.js +103 -0
- package/dist/types/vector_layer.d.ts +14 -0
- package/dist/types/vector_layer.js +50 -0
- package/package.json +7 -6
- package/dist/lib/build_style.d.ts +0 -12
- package/dist/lib/guess_style.d.ts +0 -2
- package/dist/lib/recolor.d.ts +0 -4
- package/dist/lib/shortbread/layers.d.ts +0 -4
- package/dist/lib/shortbread/template.d.ts +0 -2
- package/dist/lib/types.d.ts +0 -145
- package/dist/lib/types.js +0 -97
- /package/dist/{lib → guess_style}/random_color.d.ts +0 -0
- /package/dist/{lib → guess_style}/random_color.js +0 -0
- /package/dist/{lib/shortbread → shortbread}/properties.d.ts +0 -0
- /package/dist/{lib/shortbread → shortbread}/properties.js +0 -0
- /package/dist/{lib → style_builder}/recolor.js +0 -0
package/README.MD
CHANGED
|
@@ -1,31 +1,33 @@
|
|
|
1
|
+
[](https://www.npmjs.com/package/@versatiles/style)
|
|
1
2
|
[](https://codecov.io/gh/versatiles-org/versatiles-style)
|
|
2
|
-
[](https://github.com/versatiles-org/versatiles-style/actions/workflows/ci.yml)
|
|
3
4
|
|
|
4
5
|
# VersaTiles Style
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
Generates styles and sprites for MapLibre.
|
|
7
8
|
|
|
8
9
|

|
|
9
10
|
|
|
10
11
|
# Styles
|
|
11
12
|
|
|
12
13
|
* Colorful - colorful, full featured map
|
|
14
|
+
* Graybeard - gray, full featured map
|
|
13
15
|
* Neutrino - light basemap
|
|
14
|
-
* Graybeard - gray basemap
|
|
15
16
|
|
|
16
|
-
#
|
|
17
|
+
# Use styles for versatiles.org
|
|
17
18
|
|
|
18
|
-
You
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
You in the the [latest release](https://github.com/versatiles-org/versatiles-style/releases/latest/) you can find:
|
|
20
|
+
- [`styles.tar.gz`](https://github.com/versatiles-org/versatiles-style/releases/latest/download/styles.tar.gz) containing all styles, each in multiple languages.
|
|
21
|
+
Be aware that these styles use `tiles.versatiles.org` as source for tiles, fonts (glyphs) and icons (sprites).
|
|
22
|
+
- [`sprites.tar.gz`](https://github.com/versatiles-org/versatiles-style/releases/latest/download/sprites.tar.gz) containing sprites, used e.g. for map icons
|
|
23
|
+
- [`versatiles-style.tar.gz`](https://github.com/versatiles-org/versatiles-style/releases/latest/download/versatiles-style.tar.gz) containing a JavaScript file to generate your own style in the browser.
|
|
22
24
|
|
|
23
25
|
# Create styles in the frontend (web browser)
|
|
24
26
|
|
|
25
27
|
Download latest release:
|
|
26
28
|
|
|
27
29
|
```bash
|
|
28
|
-
wget "https://github.com/versatiles-org/versatiles-style/releases/latest/download/versatiles-style.
|
|
30
|
+
wget "https://github.com/versatiles-org/versatiles-style/releases/latest/download/versatiles-style.tar.gz"
|
|
29
31
|
```
|
|
30
32
|
|
|
31
33
|
Use it in:
|
|
@@ -35,38 +37,39 @@ Use it in:
|
|
|
35
37
|
<script src="maplibre-gl.js"></script>
|
|
36
38
|
<script src="versatiles-style.js"></script>
|
|
37
39
|
<script>
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
40
|
+
const style = VersaTilesStyle.styles.graybeard({
|
|
41
|
+
tiles: ['/tiles/osm/{z}/{x}/{y}'],
|
|
42
|
+
sprite: '/assets/styles/swr-bright/sprite',
|
|
43
|
+
glyphs: '/assets/fonts/{fontstack}/{range}.pbf',
|
|
44
|
+
baseUrl: 'https://example.org/',
|
|
45
|
+
languageSuffix: '_de',
|
|
46
|
+
colors: { label: '#222' },
|
|
47
|
+
recolor: { gamma: 0.5 }
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const map = new maplibregl.Map({
|
|
51
|
+
container: 'map',
|
|
52
|
+
style
|
|
53
|
+
});
|
|
51
54
|
<script>
|
|
52
55
|
```
|
|
53
56
|
|
|
54
57
|
# Create styles in the backend (Node.js)
|
|
55
58
|
|
|
56
|
-
Install
|
|
59
|
+
Install `@versatiles/style` via NPM:
|
|
57
60
|
|
|
58
61
|
```bash
|
|
59
|
-
npm install versatiles
|
|
62
|
+
npm install @versatiles/style
|
|
60
63
|
```
|
|
61
64
|
|
|
62
65
|
Use it in Node.js:
|
|
63
66
|
|
|
64
67
|
```javascript
|
|
65
|
-
import { styles } from 'versatiles
|
|
68
|
+
import { styles } from '@versatiles/style';
|
|
66
69
|
let style = styles.colorful({
|
|
67
70
|
languageSuffix: '_en',
|
|
68
71
|
});
|
|
69
|
-
writeFileSync('style.json', JSON.stringify(style
|
|
72
|
+
writeFileSync('style.json', JSON.stringify(style));
|
|
70
73
|
```
|
|
71
74
|
|
|
72
75
|
# API
|
|
@@ -169,3 +172,24 @@ interface {
|
|
|
169
172
|
* <code>options: StylemakerOptions<default></code> (optional)
|
|
170
173
|
|
|
171
174
|
**Returns:** <code>MaplibreStyle</code>
|
|
175
|
+
|
|
176
|
+
# Build
|
|
177
|
+
|
|
178
|
+
Please note that for building new sprites you need `optipng`.
|
|
179
|
+
|
|
180
|
+
## SVG Sources
|
|
181
|
+
|
|
182
|
+
* SVG sources should consist only of paths and not contain any `transform()`s.
|
|
183
|
+
* Colors and styles are ignored.
|
|
184
|
+
* All lengths must be in pixels without unit.
|
|
185
|
+
|
|
186
|
+
## Configuration
|
|
187
|
+
|
|
188
|
+
Iconsets can be defined in [`scripts/config-sprites.ts`](./scripts/config-sprites.ts);
|
|
189
|
+
* `colors` are applied to each path in the order they appear in the source SVG.
|
|
190
|
+
* `size` applies to the height
|
|
191
|
+
|
|
192
|
+
# Licenses
|
|
193
|
+
|
|
194
|
+
* Sourcecode: [Unlicense](./UNLICENSE.md)
|
|
195
|
+
* Iconsets and rendered Spritemaps: [CC0 1.0 Universal](./icons/LICENSE.md)
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { MaplibreStyle } from '../types';
|
|
2
|
+
import type { Container } from '@versatiles/container';
|
|
3
|
+
import type { GuessContainerOptions, GuessStyleOptions } from './types';
|
|
4
|
+
export declare function guessStyle(opt: GuessStyleOptions): MaplibreStyle;
|
|
5
|
+
export declare function guessStyleFromContainer(container: Container, options: GuessContainerOptions): Promise<MaplibreStyle>;
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/prefer-includes */
|
|
2
1
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
3
|
-
import { isTileJSONSpecification } from '
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
export
|
|
2
|
+
import { isTileJSONSpecification, isVectorLayers } from '../types';
|
|
3
|
+
import { resolveUrl } from '../lib/utils';
|
|
4
|
+
import randomColorGenerator from './random_color';
|
|
5
|
+
import { colorful } from '../styles';
|
|
6
|
+
export function guessStyle(opt) {
|
|
8
7
|
const { format } = opt;
|
|
9
8
|
const tilejsonBasic = {
|
|
10
|
-
tilejson:
|
|
9
|
+
tilejson: '3.0.0',
|
|
11
10
|
attribution: opt.attribution,
|
|
12
11
|
tiles: opt.tiles,
|
|
13
12
|
scheme: opt.scheme,
|
|
@@ -42,11 +41,12 @@ export default function guess(opt) {
|
|
|
42
41
|
break;
|
|
43
42
|
case 'pbf':
|
|
44
43
|
const { vectorLayers } = opt;
|
|
45
|
-
if (vectorLayers
|
|
46
|
-
throw Error('property vector_layers is
|
|
47
|
-
}
|
|
44
|
+
if (!isVectorLayers(vectorLayers))
|
|
45
|
+
throw Error('property vector_layers is invalid');
|
|
48
46
|
tilejson = { ...tilejsonBasic, type: 'vector', format, vector_layers: vectorLayers };
|
|
49
47
|
break;
|
|
48
|
+
default:
|
|
49
|
+
throw Error(`format "${String(format)}" is not supported`);
|
|
50
50
|
}
|
|
51
51
|
if (!isTileJSONSpecification(tilejson))
|
|
52
52
|
throw Error();
|
|
@@ -74,6 +74,36 @@ export default function guess(opt) {
|
|
|
74
74
|
style.center = opt.center;
|
|
75
75
|
return style;
|
|
76
76
|
}
|
|
77
|
+
export async function guessStyleFromContainer(container, options) {
|
|
78
|
+
const header = await container.getHeader();
|
|
79
|
+
const metadata = await container.getMetadata();
|
|
80
|
+
const format = header.tileFormat;
|
|
81
|
+
switch (format) {
|
|
82
|
+
case 'avif':
|
|
83
|
+
case 'jpg':
|
|
84
|
+
case 'pbf':
|
|
85
|
+
case 'png':
|
|
86
|
+
case 'webp':
|
|
87
|
+
break;
|
|
88
|
+
default:
|
|
89
|
+
throw Error(`format "${String(format)}" is not supported`);
|
|
90
|
+
}
|
|
91
|
+
let vectorLayers;
|
|
92
|
+
if (typeof metadata === 'string') {
|
|
93
|
+
const t = JSON.parse(metadata);
|
|
94
|
+
if (('vector_layers' in t) && Array.isArray(t.vector_layers))
|
|
95
|
+
vectorLayers = t.vector_layers;
|
|
96
|
+
}
|
|
97
|
+
const guessStyleOptions = {
|
|
98
|
+
...options,
|
|
99
|
+
format,
|
|
100
|
+
bounds: header.bbox,
|
|
101
|
+
minzoom: header.zoomMin,
|
|
102
|
+
maxzoom: header.zoomMax,
|
|
103
|
+
vectorLayers,
|
|
104
|
+
};
|
|
105
|
+
return guessStyle(guessStyleOptions);
|
|
106
|
+
}
|
|
77
107
|
function isShortbread(spec) {
|
|
78
108
|
if (typeof spec !== 'object')
|
|
79
109
|
return false;
|
|
@@ -86,7 +116,7 @@ function isShortbread(spec) {
|
|
|
86
116
|
return shortbreadIds.every(id => layerIds.has(id));
|
|
87
117
|
}
|
|
88
118
|
function getShortbreadStyle(spec, builderOption) {
|
|
89
|
-
return
|
|
119
|
+
return colorful({
|
|
90
120
|
hideLabels: true,
|
|
91
121
|
tiles: spec.tiles,
|
|
92
122
|
baseUrl: builderOption.baseUrl,
|
|
@@ -109,13 +139,13 @@ function getInspectorStyle(spec) {
|
|
|
109
139
|
hue = 'orange';
|
|
110
140
|
if (/contour|building/.test(vector_layer.id))
|
|
111
141
|
hue = 'monochrome';
|
|
112
|
-
if (
|
|
142
|
+
if (vector_layer.id.includes('building'))
|
|
113
143
|
luminosity = 'dark';
|
|
114
144
|
if (/contour|landuse/.test(vector_layer.id))
|
|
115
145
|
hue = 'yellow';
|
|
116
146
|
if (/wood|forest|park|landcover|land/.test(vector_layer.id))
|
|
117
147
|
hue = 'green';
|
|
118
|
-
if (
|
|
148
|
+
if (vector_layer.id.includes('point')) {
|
|
119
149
|
saturation = 'strong';
|
|
120
150
|
luminosity = 'light';
|
|
121
151
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { guessStyle, guessStyleFromContainer } from './guess_style';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface GuessContainerOptions {
|
|
2
|
+
tiles: string[];
|
|
3
|
+
attribution?: string;
|
|
4
|
+
baseUrl?: string;
|
|
5
|
+
bounds?: [number, number, number, number];
|
|
6
|
+
center?: [number, number];
|
|
7
|
+
description?: string;
|
|
8
|
+
fillzoom?: number;
|
|
9
|
+
glyphs?: string;
|
|
10
|
+
grids?: string[];
|
|
11
|
+
legend?: string;
|
|
12
|
+
maxzoom?: number;
|
|
13
|
+
minzoom?: number;
|
|
14
|
+
name?: string;
|
|
15
|
+
scheme?: 'tms' | 'xyz';
|
|
16
|
+
sprite?: string;
|
|
17
|
+
template?: string;
|
|
18
|
+
}
|
|
19
|
+
/** Options for creating TileJSON, extending the basic specification with format and optional vector layers. */
|
|
20
|
+
export interface GuessStyleOptions extends GuessContainerOptions {
|
|
21
|
+
format: 'avif' | 'jpg' | 'pbf' | 'png' | 'webp';
|
|
22
|
+
vectorLayers?: unknown[];
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export declare const styles: {
|
|
7
|
-
colorful: (options?: StylemakerOptions<Colorful>) => MaplibreStyle;
|
|
8
|
-
graybeard: (options?: StylemakerOptions<Graybeard>) => MaplibreStyle;
|
|
9
|
-
neutrino: (options?: StylemakerOptions<Neutrino>) => MaplibreStyle;
|
|
10
|
-
};
|
|
11
|
-
export { default as guessStyle } from './lib/guess_style.js';
|
|
1
|
+
export type * from './styles';
|
|
2
|
+
export * as styles from './styles';
|
|
3
|
+
export { guessStyle, guessStyleFromContainer } from './guess_style';
|
|
4
|
+
export type { GuessStyleOptions, GuessContainerOptions } from './guess_style';
|
|
5
|
+
export type { VectorLayer } from './types';
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import Neutrino from './style/neutrino.js';
|
|
4
|
-
export const styles = {
|
|
5
|
-
colorful: function colorful(options) {
|
|
6
|
-
return new Colorful().build(options);
|
|
7
|
-
},
|
|
8
|
-
graybeard: function graybeard(options) {
|
|
9
|
-
return new Graybeard().build(options);
|
|
10
|
-
},
|
|
11
|
-
neutrino: function neutrino(options) {
|
|
12
|
-
return new Neutrino().build(options);
|
|
13
|
-
},
|
|
14
|
-
};
|
|
15
|
-
export { default as guessStyle } from './lib/guess_style.js';
|
|
1
|
+
export * as styles from './styles';
|
|
2
|
+
export { guessStyle, guessStyleFromContainer } from './guess_style';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
|
-
export
|
|
2
|
+
export function getShortbreadLayers(option) {
|
|
3
3
|
const { languageSuffix } = option;
|
|
4
|
+
const nameField = languageSuffix ? '{name_' + languageSuffix + '}' : '{name}';
|
|
4
5
|
return [
|
|
5
6
|
// background
|
|
6
7
|
{ id: 'background', type: 'background' },
|
|
@@ -335,7 +336,7 @@ export default function getLayers(option) {
|
|
|
335
336
|
type: 'symbol',
|
|
336
337
|
'source-layer': 'street_labels',
|
|
337
338
|
filter: ['==', 'kind', t],
|
|
338
|
-
layout: { 'text-field':
|
|
339
|
+
layout: { 'text-field': nameField },
|
|
339
340
|
})),
|
|
340
341
|
// label-place of small places
|
|
341
342
|
...[/*'locality', 'island', 'farm', 'dwelling',*/ 'neighbourhood', 'quarter', 'suburb', 'hamlet', 'village', 'town'].map((id) => ({
|
|
@@ -343,7 +344,7 @@ export default function getLayers(option) {
|
|
|
343
344
|
type: 'symbol',
|
|
344
345
|
'source-layer': 'place_labels',
|
|
345
346
|
filter: ['==', 'kind', id],
|
|
346
|
-
layout: { 'text-field':
|
|
347
|
+
layout: { 'text-field': nameField },
|
|
347
348
|
})),
|
|
348
349
|
// label-boundary
|
|
349
350
|
{
|
|
@@ -351,7 +352,7 @@ export default function getLayers(option) {
|
|
|
351
352
|
type: 'symbol',
|
|
352
353
|
'source-layer': 'boundary_labels',
|
|
353
354
|
filter: ['in', 'admin_level', 4, '4'],
|
|
354
|
-
layout: { 'text-field':
|
|
355
|
+
layout: { 'text-field': nameField },
|
|
355
356
|
},
|
|
356
357
|
// label-place-* of large places
|
|
357
358
|
...['city', 'state_capital', 'capital'].map((id) => ({
|
|
@@ -359,7 +360,7 @@ export default function getLayers(option) {
|
|
|
359
360
|
type: 'symbol',
|
|
360
361
|
'source-layer': 'place_labels',
|
|
361
362
|
filter: ['==', 'kind', id],
|
|
362
|
-
layout: { 'text-field':
|
|
363
|
+
layout: { 'text-field': nameField },
|
|
363
364
|
})),
|
|
364
365
|
{
|
|
365
366
|
id: 'label-boundary-country-small',
|
|
@@ -369,7 +370,7 @@ export default function getLayers(option) {
|
|
|
369
370
|
['in', 'admin_level', 2, '2'],
|
|
370
371
|
['<=', 'way_area', 10000000],
|
|
371
372
|
],
|
|
372
|
-
layout: { 'text-field':
|
|
373
|
+
layout: { 'text-field': nameField },
|
|
373
374
|
},
|
|
374
375
|
{
|
|
375
376
|
id: 'label-boundary-country-medium',
|
|
@@ -380,7 +381,7 @@ export default function getLayers(option) {
|
|
|
380
381
|
['<', 'way_area', 90000000],
|
|
381
382
|
['>', 'way_area', 10000000],
|
|
382
383
|
],
|
|
383
|
-
layout: { 'text-field':
|
|
384
|
+
layout: { 'text-field': nameField },
|
|
384
385
|
},
|
|
385
386
|
{
|
|
386
387
|
id: 'label-boundary-country-large',
|
|
@@ -390,7 +391,7 @@ export default function getLayers(option) {
|
|
|
390
391
|
['in', 'admin_level', 2, '2'],
|
|
391
392
|
['>=', 'way_area', 90000000],
|
|
392
393
|
],
|
|
393
|
-
layout: { 'text-field':
|
|
394
|
+
layout: { 'text-field': nameField },
|
|
394
395
|
},
|
|
395
396
|
// marking
|
|
396
397
|
{
|
|
@@ -446,14 +447,14 @@ export default function getLayers(option) {
|
|
|
446
447
|
type: 'symbol',
|
|
447
448
|
'source-layer': 'public_transport',
|
|
448
449
|
filter: ['==', 'kind', 'bus_stop'],
|
|
449
|
-
layout: { 'text-field':
|
|
450
|
+
layout: { 'text-field': nameField },
|
|
450
451
|
},
|
|
451
452
|
{
|
|
452
453
|
id: 'symbol-transit-tram',
|
|
453
454
|
type: 'symbol',
|
|
454
455
|
'source-layer': 'public_transport',
|
|
455
456
|
filter: ['==', 'kind', 'tram_stop'],
|
|
456
|
-
layout: { 'text-field':
|
|
457
|
+
layout: { 'text-field': nameField },
|
|
457
458
|
},
|
|
458
459
|
{
|
|
459
460
|
id: 'symbol-transit-subway',
|
|
@@ -463,7 +464,7 @@ export default function getLayers(option) {
|
|
|
463
464
|
['in', 'kind', 'station', 'halt'],
|
|
464
465
|
['==', 'station', 'subway'],
|
|
465
466
|
],
|
|
466
|
-
layout: { 'text-field':
|
|
467
|
+
layout: { 'text-field': nameField },
|
|
467
468
|
},
|
|
468
469
|
{
|
|
469
470
|
id: 'symbol-transit-lightrail',
|
|
@@ -473,7 +474,7 @@ export default function getLayers(option) {
|
|
|
473
474
|
['in', 'kind', 'station', 'halt'],
|
|
474
475
|
['==', 'station', 'light_rail'],
|
|
475
476
|
],
|
|
476
|
-
layout: { 'text-field':
|
|
477
|
+
layout: { 'text-field': nameField },
|
|
477
478
|
},
|
|
478
479
|
{
|
|
479
480
|
id: 'symbol-transit-station',
|
|
@@ -483,7 +484,7 @@ export default function getLayers(option) {
|
|
|
483
484
|
['in', 'kind', 'station', 'halt'],
|
|
484
485
|
['!in', 'station', 'light_rail', 'subway'],
|
|
485
486
|
],
|
|
486
|
-
layout: { 'text-field':
|
|
487
|
+
layout: { 'text-field': nameField },
|
|
487
488
|
},
|
|
488
489
|
{
|
|
489
490
|
id: 'symbol-transit-airfield',
|
|
@@ -493,7 +494,7 @@ export default function getLayers(option) {
|
|
|
493
494
|
['==', 'kind', 'aerodrome'],
|
|
494
495
|
['!has', 'iata'],
|
|
495
496
|
],
|
|
496
|
-
layout: { 'text-field':
|
|
497
|
+
layout: { 'text-field': nameField },
|
|
497
498
|
},
|
|
498
499
|
{
|
|
499
500
|
id: 'symbol-transit-airport',
|
|
@@ -503,7 +504,7 @@ export default function getLayers(option) {
|
|
|
503
504
|
['==', 'kind', 'aerodrome'],
|
|
504
505
|
['has', 'iata'],
|
|
505
506
|
],
|
|
506
|
-
layout: { 'text-field':
|
|
507
|
+
layout: { 'text-field': nameField },
|
|
507
508
|
},
|
|
508
509
|
];
|
|
509
510
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Color from 'color';
|
|
2
2
|
import expandBraces from 'brace-expansion';
|
|
3
|
-
import maplibreProperties from '
|
|
4
|
-
import { deepMerge } from '
|
|
3
|
+
import maplibreProperties from '../shortbread/properties';
|
|
4
|
+
import { deepMerge } from '../lib/utils';
|
|
5
5
|
export function decorate(layers, rules) {
|
|
6
6
|
const layerIds = layers.map(l => l.id);
|
|
7
7
|
const layerIdSet = new Set(layerIds);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { LanguageSuffix } from './types';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type StyleBuilder from './style_builder';
|
|
2
|
+
import type { StyleBuilderColors } from './types';
|
|
3
|
+
export interface RecolorOptions {
|
|
4
|
+
/** If true, inverts the colors. */
|
|
5
|
+
invert?: boolean;
|
|
6
|
+
/** The degree to rotate the hue of the color (in degrees). */
|
|
7
|
+
rotate?: number;
|
|
8
|
+
/** Adjusts the saturation level of the color. Positive values increase saturation, negative values decrease it. */
|
|
9
|
+
saturate?: number;
|
|
10
|
+
/** Adjusts the gamma of the color. Affects the brightness in a non-linear manner. */
|
|
11
|
+
gamma?: number;
|
|
12
|
+
/** Adjusts the contrast of the color. Higher values produce more contrast. */
|
|
13
|
+
contrast?: number;
|
|
14
|
+
/** Adjusts the brightness of the color. Positive values make it brighter, negative values make it darker. */
|
|
15
|
+
brightness?: number;
|
|
16
|
+
/** Specifies the intensity of the tinting effect. Ranges from 0 (no effect) to 1 (full effect). */
|
|
17
|
+
tint?: number;
|
|
18
|
+
/** Specifies the color used for tinting, in a string format (e.g., '#FF0000'). */
|
|
19
|
+
tintColor?: string;
|
|
20
|
+
}
|
|
21
|
+
export declare function getDefaultRecolorFlags(): RecolorOptions;
|
|
22
|
+
export declare function recolor<Subclass extends StyleBuilder<Subclass>>(colors: StyleBuilderColors<Subclass>, opt?: RecolorOptions): void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import Color from 'color';
|
|
2
|
+
import type { MaplibreStyle } from '../types/maplibre';
|
|
3
|
+
import type { StyleBuilderColorStrings, StyleBuilderColors, StyleBuilderFontStrings, StyleBuilderOptions } from './types';
|
|
4
|
+
import type { StyleRules, StyleRulesOptions } from './types';
|
|
5
|
+
export default abstract class StyleBuilder<Subclass extends StyleBuilder<Subclass>> {
|
|
6
|
+
#private;
|
|
7
|
+
abstract readonly name: string;
|
|
8
|
+
abstract readonly defaultColors: StyleBuilderColorStrings<Subclass>;
|
|
9
|
+
abstract readonly defaultFonts: StyleBuilderFontStrings<Subclass>;
|
|
10
|
+
build(options?: StyleBuilderOptions<Subclass>): MaplibreStyle;
|
|
11
|
+
getColors(colors: StyleBuilderColorStrings<Subclass>): StyleBuilderColors<Subclass>;
|
|
12
|
+
protected transformDefaultColors(callback: (color: Color) => Color): void;
|
|
13
|
+
protected abstract getStyleRules(options: StyleRulesOptions<Subclass>): StyleRules;
|
|
14
|
+
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import Color from 'color';
|
|
2
|
-
import getShortbreadTemplate from '
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
// Stylemaker class definition
|
|
2
|
+
import { getShortbreadTemplate, getShortbreadLayers } from '../shortbread';
|
|
3
|
+
import { decorate } from './decorator';
|
|
4
|
+
import { getDefaultRecolorFlags, recolor } from './recolor';
|
|
5
|
+
import { deepClone, resolveUrl } from '../lib/utils';
|
|
6
|
+
// StyleBuilder class definition
|
|
8
7
|
export default class StyleBuilder {
|
|
9
8
|
#sourceName = 'versatiles-shortbread';
|
|
10
9
|
build(options) {
|
|
@@ -15,7 +14,7 @@ export default class StyleBuilder {
|
|
|
15
14
|
const sprite = options.sprite ?? '/assets/sprites/sprites';
|
|
16
15
|
const tiles = options.tiles ?? ['/tiles/osm/{z}/{x}/{y}'];
|
|
17
16
|
const hideLabels = options.hideLabels ?? false;
|
|
18
|
-
const languageSuffix = options
|
|
17
|
+
const { languageSuffix } = options;
|
|
19
18
|
const recolorOptions = options.recolor ?? getDefaultRecolorFlags();
|
|
20
19
|
const colors = this.getColors(this.defaultColors);
|
|
21
20
|
if (options.colors) {
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type Color from 'color';
|
|
2
|
+
import type StyleBuilder from './style_builder';
|
|
3
|
+
import type { RecolorOptions } from './recolor';
|
|
4
|
+
/** Represents language suffixes used in map styles. */
|
|
5
|
+
export type LanguageSuffix = 'de' | 'en' | undefined;
|
|
6
|
+
export interface StyleBuilderOptions<T extends StyleBuilder<T>> {
|
|
7
|
+
/** The base URL for loading external resources like tiles, sprites, and fonts. */
|
|
8
|
+
baseUrl?: string;
|
|
9
|
+
/** The URL template for loading font glyphs, formatted with `{fontstack}` and `{range}` placeholders. */
|
|
10
|
+
glyphs?: string;
|
|
11
|
+
/** The URL for loading sprite images and metadata. */
|
|
12
|
+
sprite?: string;
|
|
13
|
+
/** An array of URL templates for loading map tiles, with `{z}`, `{x}`, and `{y}` placeholders. */
|
|
14
|
+
tiles?: string[];
|
|
15
|
+
/** If true, hides all map labels. */
|
|
16
|
+
hideLabels?: boolean;
|
|
17
|
+
/** Suffix to append to language-specific resources, such as `"-en"` for English. */
|
|
18
|
+
languageSuffix?: LanguageSuffix;
|
|
19
|
+
/** An object specifying overrides for default color values, keyed by the color names. */
|
|
20
|
+
colors?: Partial<StyleBuilderColorStrings<T>>;
|
|
21
|
+
/** An object specifying overrides for default font names, keyed by the font names. */
|
|
22
|
+
fonts?: Partial<StyleBuilderFontStrings<T>>;
|
|
23
|
+
/** Options for color adjustments and transformations applied to the entire style. */
|
|
24
|
+
recolor?: RecolorOptions;
|
|
25
|
+
}
|
|
26
|
+
/** Defines the keys for color properties in a style builder. */
|
|
27
|
+
export type StyleBuilderColorKeys<T extends StyleBuilder<T>> = keyof T['defaultColors'];
|
|
28
|
+
/** Defines the keys for font properties in a style builder. */
|
|
29
|
+
export type StyleBuilderFontKeys<T extends StyleBuilder<T>> = keyof T['defaultFonts'];
|
|
30
|
+
/** Records string values for color properties in a style builder. */
|
|
31
|
+
export type StyleBuilderColorStrings<T extends StyleBuilder<T>> = Record<StyleBuilderColorKeys<T>, string>;
|
|
32
|
+
/** Records string values for font properties in a style builder. */
|
|
33
|
+
export type StyleBuilderFontStrings<T extends StyleBuilder<T>> = Record<StyleBuilderFontKeys<T>, string>;
|
|
34
|
+
/** Records Color objects for color properties in a style builder. */
|
|
35
|
+
export type StyleBuilderColors<T extends StyleBuilder<T>> = Record<StyleBuilderColorKeys<T>, Color>;
|
|
36
|
+
/** Records string values for font properties in a style builder. */
|
|
37
|
+
export type StyleBuilderFonts<T extends StyleBuilder<T>> = Record<StyleBuilderFontKeys<T>, string>;
|
|
38
|
+
/** Defines options for style rules in a style builder. */
|
|
39
|
+
export interface StyleRulesOptions<T extends StyleBuilder<T>> {
|
|
40
|
+
colors: StyleBuilderColors<T>;
|
|
41
|
+
fonts: StyleBuilderFontStrings<T>;
|
|
42
|
+
languageSuffix: LanguageSuffix;
|
|
43
|
+
}
|
|
44
|
+
/** Defines the value type for a style rule. */
|
|
45
|
+
export type StyleRuleValue = boolean | number | object | string;
|
|
46
|
+
/** Defines the structure of a style rule, which is a record of properties to style values. */
|
|
47
|
+
export type StyleRule = Record<string, StyleRuleValue | undefined>;
|
|
48
|
+
/** Defines the structure of style rules, which is a record of selectors to style rules. */
|
|
49
|
+
export type StyleRules = Record<string, StyleRule | undefined>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import StyleBuilder from '../
|
|
2
|
-
import type { StyleRules, StyleRulesOptions } from '../
|
|
1
|
+
import StyleBuilder from '../style_builder/style_builder';
|
|
2
|
+
import type { StyleRules, StyleRulesOptions } from '../style_builder/types';
|
|
3
3
|
export default class Colorful extends StyleBuilder<Colorful> {
|
|
4
4
|
readonly name: string;
|
|
5
5
|
defaultFonts: {
|