@versatiles/style 3.6.0 → 3.6.1
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 +5 -5
- package/dist/index.test.js +14 -9
- package/dist/lib/style_guesser.d.ts +2 -2
- package/dist/lib/style_guesser.js +35 -10
- package/dist/lib/style_guesser.test.js +2 -2
- package/dist/lib/types.d.ts +11 -5
- package/dist/lib/types.js +4 -4
- package/package.json +1 -1
package/README.MD
CHANGED
|
@@ -125,7 +125,7 @@ interface {
|
|
|
125
125
|
|
|
126
126
|
### Method: `colorful(options)`
|
|
127
127
|
|
|
128
|
-
<sup><a href="https://github.com/versatiles-org/versatiles-style/blob/
|
|
128
|
+
<sup><a href="https://github.com/versatiles-org/versatiles-style/blob/516812e/src/index.ts#L4">\[src]</a></sup>
|
|
129
129
|
|
|
130
130
|
**Parameters:**
|
|
131
131
|
|
|
@@ -135,7 +135,7 @@ interface {
|
|
|
135
135
|
|
|
136
136
|
### Method: `graybeard(options)`
|
|
137
137
|
|
|
138
|
-
<sup><a href="https://github.com/versatiles-org/versatiles-style/blob/
|
|
138
|
+
<sup><a href="https://github.com/versatiles-org/versatiles-style/blob/516812e/src/index.ts#L9">\[src]</a></sup>
|
|
139
139
|
|
|
140
140
|
**Parameters:**
|
|
141
141
|
|
|
@@ -145,17 +145,17 @@ interface {
|
|
|
145
145
|
|
|
146
146
|
### Method: `guessStyle(spec)`
|
|
147
147
|
|
|
148
|
-
<sup><a href="https://github.com/versatiles-org/versatiles-style/blob/
|
|
148
|
+
<sup><a href="https://github.com/versatiles-org/versatiles-style/blob/516812e/src/lib/style_guesser.ts#L12">\[src]</a></sup>
|
|
149
149
|
|
|
150
150
|
**Parameters:**
|
|
151
151
|
|
|
152
|
-
* <code>spec:
|
|
152
|
+
* <code>spec: TileJSONOption</code>
|
|
153
153
|
|
|
154
154
|
**Returns:** <code>MaplibreStyle</code>
|
|
155
155
|
|
|
156
156
|
### Method: `neutrino(options)`
|
|
157
157
|
|
|
158
|
-
<sup><a href="https://github.com/versatiles-org/versatiles-style/blob/
|
|
158
|
+
<sup><a href="https://github.com/versatiles-org/versatiles-style/blob/516812e/src/index.ts#L14">\[src]</a></sup>
|
|
159
159
|
|
|
160
160
|
**Parameters:**
|
|
161
161
|
|
package/dist/index.test.js
CHANGED
|
@@ -35,28 +35,33 @@ describe('Colorful', () => {
|
|
|
35
35
|
expect(paint['fill-color']).toBe('#ff0000');
|
|
36
36
|
});
|
|
37
37
|
describe('guessStyle', () => {
|
|
38
|
+
const tiles = ['https://fancy.map/tiles/{z}/{x}/{y}'];
|
|
39
|
+
const vector_layers = [{ id: 'hallo', fields: { label: 'String' } }];
|
|
38
40
|
it('should build raster styles', () => {
|
|
39
41
|
const style = builders.guessStyle({
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
format: 'avif',
|
|
42
|
+
tiles,
|
|
43
|
+
format: 'png',
|
|
43
44
|
});
|
|
44
45
|
expect(style).toStrictEqual({
|
|
45
46
|
layers: [{ id: 'raster', source: 'rasterSource', type: 'raster' }],
|
|
46
|
-
sources: { rasterSource: { format: '
|
|
47
|
+
sources: { rasterSource: { format: 'png', tilejson: '3.0.0', tiles, type: 'raster' } },
|
|
47
48
|
version: 8,
|
|
48
49
|
});
|
|
49
50
|
});
|
|
50
51
|
it('should build vector styles', () => {
|
|
51
52
|
const style = builders.guessStyle({
|
|
52
|
-
|
|
53
|
-
tiles: [],
|
|
53
|
+
tiles,
|
|
54
54
|
format: 'pbf',
|
|
55
|
-
vector_layers
|
|
55
|
+
vector_layers,
|
|
56
56
|
});
|
|
57
57
|
expect(style).toStrictEqual({
|
|
58
|
-
layers: [
|
|
59
|
-
|
|
58
|
+
layers: [
|
|
59
|
+
{ id: 'background', paint: { 'background-color': '#fff' }, type: 'background' },
|
|
60
|
+
{ id: 'vectorSource-hallo-fill', filter: ['==', '$type', 'Polygon'], paint: { 'fill-antialias': true, 'fill-color': 'hsla(14,50%,52%,0.6)', 'fill-opacity': 0.3, 'fill-outline-color': 'hsla(14,50%,52%,0.6)' }, source: 'vectorSource', 'source-layer': 'hallo', type: 'fill' },
|
|
61
|
+
{ id: 'vectorSource-hallo-line', filter: ['==', '$type', 'LineString'], layout: { 'line-cap': 'round', 'line-join': 'round' }, paint: { 'line-color': 'hsla(14,50%,52%,0.6)' }, source: 'vectorSource', 'source-layer': 'hallo', type: 'line' },
|
|
62
|
+
{ id: 'vectorSource-hallo-circle', filter: ['==', '$type', 'Point'], paint: { 'circle-color': 'hsla(14,50%,52%,0.6)', 'circle-radius': 2 }, source: 'vectorSource', 'source-layer': 'hallo', type: 'circle' },
|
|
63
|
+
],
|
|
64
|
+
sources: { vectorSource: { format: 'pbf', tilejson: '3.0.0', tiles, type: 'vector', vector_layers } },
|
|
60
65
|
'version': 8,
|
|
61
66
|
});
|
|
62
67
|
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { MaplibreStyle,
|
|
2
|
-
export default function guess(spec:
|
|
1
|
+
import type { MaplibreStyle, TileJSONOption } from './types.js';
|
|
2
|
+
export default function guess(spec: TileJSONOption): MaplibreStyle;
|
|
@@ -4,21 +4,46 @@ import { isTileJSONSpecification } from './types.js';
|
|
|
4
4
|
import randomColorGenerator from './random_color.js';
|
|
5
5
|
import Colorful from '../style/colorful.js';
|
|
6
6
|
export default function guess(spec) {
|
|
7
|
-
|
|
7
|
+
let tilejson;
|
|
8
|
+
const { format } = spec;
|
|
9
|
+
switch (format) {
|
|
10
|
+
case 'avif':
|
|
11
|
+
case 'jpg':
|
|
12
|
+
case 'png':
|
|
13
|
+
case 'webp':
|
|
14
|
+
tilejson = {
|
|
15
|
+
tilejson: '3.0.0',
|
|
16
|
+
type: 'raster',
|
|
17
|
+
...spec,
|
|
18
|
+
format,
|
|
19
|
+
};
|
|
20
|
+
break;
|
|
21
|
+
case 'pbf':
|
|
22
|
+
const { vector_layers } = spec;
|
|
23
|
+
if (vector_layers == null) {
|
|
24
|
+
throw Error('property vector_layers is required for vector tiles');
|
|
25
|
+
}
|
|
26
|
+
tilejson = {
|
|
27
|
+
tilejson: '3.0.0',
|
|
28
|
+
type: 'vector',
|
|
29
|
+
...spec,
|
|
30
|
+
format,
|
|
31
|
+
vector_layers,
|
|
32
|
+
};
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
if (!isTileJSONSpecification(tilejson))
|
|
8
36
|
throw Error();
|
|
9
|
-
|
|
10
|
-
|
|
37
|
+
switch (tilejson.type) {
|
|
38
|
+
case 'raster':
|
|
39
|
+
return getImageStyle(tilejson);
|
|
11
40
|
case 'vector':
|
|
12
|
-
if (isShortbread(
|
|
13
|
-
return getShortbreadStyle(
|
|
41
|
+
if (isShortbread(tilejson)) {
|
|
42
|
+
return getShortbreadStyle(tilejson);
|
|
14
43
|
}
|
|
15
44
|
else {
|
|
16
|
-
return getInspectorStyle(
|
|
45
|
+
return getInspectorStyle(tilejson);
|
|
17
46
|
}
|
|
18
|
-
case 'raster':
|
|
19
|
-
return getImageStyle(spec);
|
|
20
|
-
default:
|
|
21
|
-
throw Error('spec.type must be: "vector" or "raster"');
|
|
22
47
|
}
|
|
23
48
|
}
|
|
24
49
|
function isShortbread(spec) {
|
|
@@ -5,7 +5,7 @@ describe('guessStyle', () => {
|
|
|
5
5
|
it('should build raster styles', () => {
|
|
6
6
|
const type = 'raster';
|
|
7
7
|
const format = 'avif';
|
|
8
|
-
expect(guessStyle({
|
|
8
|
+
expect(guessStyle({ tiles, format }))
|
|
9
9
|
.toStrictEqual({
|
|
10
10
|
version: 8,
|
|
11
11
|
sources: { rasterSource: { format, tilejson: '3.0.0', tiles, type } },
|
|
@@ -16,7 +16,7 @@ describe('guessStyle', () => {
|
|
|
16
16
|
const type = 'vector';
|
|
17
17
|
const format = 'pbf';
|
|
18
18
|
const vector_layers = [{ id: 'geometry', fields: { label: 'String', height: 'Number' } }];
|
|
19
|
-
expect(guessStyle({
|
|
19
|
+
expect(guessStyle({ tiles, format, vector_layers }))
|
|
20
20
|
.toStrictEqual({
|
|
21
21
|
version: 8,
|
|
22
22
|
sources: { vectorSource: { format, tilejson: '3.0.0', tiles, type, vector_layers } },
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -12,9 +12,8 @@ export interface VectorLayer {
|
|
|
12
12
|
minzoom?: number;
|
|
13
13
|
maxzoom?: number;
|
|
14
14
|
}
|
|
15
|
-
export interface
|
|
15
|
+
export interface TileJSONSpecificationBasic {
|
|
16
16
|
tilejson?: '3.0.0';
|
|
17
|
-
type: 'raster';
|
|
18
17
|
attribution?: string;
|
|
19
18
|
tiles: string[];
|
|
20
19
|
scheme?: 'tms' | 'xyz';
|
|
@@ -28,14 +27,21 @@ export interface TileJSONSpecificationRaster {
|
|
|
28
27
|
maxzoom?: number;
|
|
29
28
|
name?: string;
|
|
30
29
|
template?: string;
|
|
30
|
+
}
|
|
31
|
+
export interface TileJSONSpecificationRaster extends TileJSONSpecificationBasic {
|
|
32
|
+
type: 'raster';
|
|
31
33
|
format: 'avif' | 'jpg' | 'png' | 'webp';
|
|
32
34
|
}
|
|
33
|
-
export interface TileJSONSpecificationVector extends
|
|
34
|
-
vector_layers: VectorLayer[];
|
|
35
|
-
format: 'pbf';
|
|
35
|
+
export interface TileJSONSpecificationVector extends TileJSONSpecificationBasic {
|
|
36
36
|
type: 'vector';
|
|
37
|
+
format: 'pbf';
|
|
38
|
+
vector_layers: VectorLayer[];
|
|
37
39
|
}
|
|
38
40
|
export type TileJSONSpecification = TileJSONSpecificationRaster | TileJSONSpecificationVector;
|
|
41
|
+
export interface TileJSONOption extends TileJSONSpecificationBasic {
|
|
42
|
+
format: 'avif' | 'jpg' | 'pbf' | 'png' | 'webp';
|
|
43
|
+
vector_layers?: VectorLayer[];
|
|
44
|
+
}
|
|
39
45
|
export type MaplibreStyleRaster = Omit<StyleSpecification, 'sources'> & {
|
|
40
46
|
'sources': {
|
|
41
47
|
[_: string]: TileJSONSpecificationRaster;
|
package/dist/lib/types.js
CHANGED
|
@@ -44,19 +44,19 @@ export function isTileJSONSpecification(obj) {
|
|
|
44
44
|
if (typeof spec.template !== 'undefined' && typeof spec.template !== 'string') {
|
|
45
45
|
throw Error('spec.template must be a string if present');
|
|
46
46
|
}
|
|
47
|
+
if (!Array.isArray(spec.tiles) || spec.tiles.length === 0 || spec.tiles.some(url => typeof url !== 'string')) {
|
|
48
|
+
throw Error('spec.tiles must be an array of strings');
|
|
49
|
+
}
|
|
47
50
|
if (spec.type === 'raster') {
|
|
48
51
|
if (!['avif', 'jpg', 'png', 'webp'].includes(spec.format)) {
|
|
49
52
|
throw Error('spec.format must be "avif", "jpg", "png", or "webp"');
|
|
50
53
|
}
|
|
51
|
-
if (!Array.isArray(spec.tiles) || spec.tiles.some(url => typeof url !== 'string')) {
|
|
52
|
-
throw Error('spec.tiles must be an array of strings');
|
|
53
|
-
}
|
|
54
54
|
}
|
|
55
55
|
else if (spec.type === 'vector') {
|
|
56
56
|
if (spec.format !== 'pbf') {
|
|
57
57
|
throw Error('spec.format must be "pbf"');
|
|
58
58
|
}
|
|
59
|
-
if (!Array.isArray(spec.vector_layers) || spec.vector_layers.some(layer => !validateVectorLayer(layer))) {
|
|
59
|
+
if (!Array.isArray(spec.vector_layers) || spec.vector_layers.length === 0 || spec.vector_layers.some(layer => !validateVectorLayer(layer))) {
|
|
60
60
|
throw Error('spec.vector_layers must be an array of VectorLayer');
|
|
61
61
|
}
|
|
62
62
|
}
|