@versatiles/style 3.7.0 → 3.8.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 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/c839905/src/index.ts#L4">\[src]</a></sup>
128
+ <sup><a href="https://github.com/versatiles-org/versatiles-style/blob/326466c/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/c839905/src/index.ts#L9">\[src]</a></sup>
138
+ <sup><a href="https://github.com/versatiles-org/versatiles-style/blob/326466c/src/index.ts#L9">\[src]</a></sup>
139
139
 
140
140
  **Parameters:**
141
141
 
@@ -145,7 +145,7 @@ interface {
145
145
 
146
146
  ### Method: `guessStyle(opt)`
147
147
 
148
- <sup><a href="https://github.com/versatiles-org/versatiles-style/blob/c839905/src/lib/style_guesser.ts#L12">\[src]</a></sup>
148
+ <sup><a href="https://github.com/versatiles-org/versatiles-style/blob/326466c/src/lib/style_guesser.ts#L12">\[src]</a></sup>
149
149
 
150
150
  **Parameters:**
151
151
 
@@ -155,7 +155,7 @@ interface {
155
155
 
156
156
  ### Method: `neutrino(options)`
157
157
 
158
- <sup><a href="https://github.com/versatiles-org/versatiles-style/blob/c839905/src/index.ts#L14">\[src]</a></sup>
158
+ <sup><a href="https://github.com/versatiles-org/versatiles-style/blob/326466c/src/index.ts#L14">\[src]</a></sup>
159
159
 
160
160
  **Parameters:**
161
161
 
@@ -12,6 +12,7 @@ export default function getTemplate() {
12
12
  sprite: 'https://tiles.versatiles.org/sprites/sprites',
13
13
  sources: {
14
14
  'versatiles-shortbread': {
15
+ tilejson: '3.0.0',
15
16
  attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
16
17
  tiles: [
17
18
  'https://tiles.versatiles.org/tiles/osm/{z}/{x}/{y}',
@@ -45,17 +45,29 @@ export default function guess(opt) {
45
45
  }
46
46
  if (!isTileJSONSpecification(tilejson))
47
47
  throw Error();
48
+ let style;
48
49
  switch (tilejson.type) {
49
50
  case 'raster':
50
- return getImageStyle(tilejson);
51
+ style = getImageStyle(tilejson);
52
+ break;
51
53
  case 'vector':
52
54
  if (isShortbread(tilejson)) {
53
- return getShortbreadStyle(tilejson, { baseUrl: opt.baseUrl, glyphs: opt.glyphs, sprite: opt.sprite });
55
+ style = getShortbreadStyle(tilejson, { baseUrl: opt.baseUrl, glyphs: opt.glyphs, sprite: opt.sprite });
54
56
  }
55
57
  else {
56
- return getInspectorStyle(tilejson);
58
+ style = getInspectorStyle(tilejson);
57
59
  }
58
60
  }
61
+ if (opt.minzoom ?? 0)
62
+ style.zoom ??= opt.minzoom;
63
+ if (opt.bounds)
64
+ style.center ??= [
65
+ (opt.bounds[0] + opt.bounds[2]) / 2,
66
+ (opt.bounds[1] + opt.bounds[3]) / 2,
67
+ ];
68
+ if (opt.center)
69
+ style.center = opt.center;
70
+ return style;
59
71
  }
60
72
  function isShortbread(spec) {
61
73
  if (typeof spec !== 'object')
@@ -69,14 +81,13 @@ function isShortbread(spec) {
69
81
  return shortbreadIds.every(id => layerIds.has(id));
70
82
  }
71
83
  function getShortbreadStyle(spec, builderOption) {
72
- const style = new Colorful().build({
84
+ return new Colorful().build({
73
85
  hideLabels: true,
74
86
  tiles: spec.tiles,
75
87
  baseUrl: builderOption.baseUrl,
76
88
  glyphs: builderOption.glyphs,
77
89
  sprite: builderOption.sprite,
78
90
  });
79
- return style;
80
91
  }
81
92
  function getInspectorStyle(spec) {
82
93
  const sourceName = 'vectorSource';
@@ -1,7 +1,10 @@
1
1
  /* eslint-disable @typescript-eslint/naming-convention */
2
+ import getTemplate from './shortbread/template.js';
2
3
  import guessStyle from './style_guesser.js';
3
4
  describe('guessStyle', () => {
4
5
  const tiles = ['https://example.com/tiles/{z}/{x}/{y}'];
6
+ const vectorLayersSomething = [{ id: 'geometry', fields: { label: 'String', height: 'Number' } }];
7
+ const vectorLayersShortbread = getTemplate().sources['versatiles-shortbread'].vector_layers;
5
8
  it('should build raster styles', () => {
6
9
  const type = 'raster';
7
10
  const format = 'avif';
@@ -12,14 +15,13 @@ describe('guessStyle', () => {
12
15
  layers: [{ id: 'raster', source: 'rasterSource', type }],
13
16
  });
14
17
  });
15
- it('should build vector styles', () => {
18
+ it('should build vector inspector styles', () => {
16
19
  const type = 'vector';
17
20
  const format = 'pbf';
18
- const vectorLayers = [{ id: 'geometry', fields: { label: 'String', height: 'Number' } }];
19
- expect(guessStyle({ tiles, format, vectorLayers }))
21
+ expect(guessStyle({ tiles, format, vectorLayers: vectorLayersSomething }))
20
22
  .toStrictEqual({
21
23
  version: 8,
22
- sources: { vectorSource: { format, tilejson: '3.0.0', tiles, type, vector_layers: vectorLayers } },
24
+ sources: { vectorSource: { format, tilejson: '3.0.0', tiles, type, vector_layers: vectorLayersSomething } },
23
25
  layers: [
24
26
  {
25
27
  id: 'background',
@@ -54,4 +56,69 @@ describe('guessStyle', () => {
54
56
  ],
55
57
  });
56
58
  });
59
+ it('should build shortbread vector styles', () => {
60
+ const type = 'vector';
61
+ const format = 'pbf';
62
+ const style = guessStyle({ tiles, format, vectorLayers: vectorLayersShortbread, baseUrl: 'http://example.com' });
63
+ expect(style.layers.length).toBe(236);
64
+ style.layers = [];
65
+ expect(style).toStrictEqual({
66
+ glyphs: 'http://example.com/assets/fonts/{fontstack}/{range}.pbf',
67
+ metadata: {
68
+ license: 'https://creativecommons.org/publicdomain/zero/1.0/',
69
+ 'maputnik:renderer': 'mbgljs',
70
+ },
71
+ name: 'versatiles-colorful',
72
+ sprite: 'http://example.com/assets/sprites/sprites',
73
+ layers: [],
74
+ sources: {
75
+ 'versatiles-shortbread': {
76
+ attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
77
+ bounds: [-180, -85.0511287798066, 180, 85.0511287798066],
78
+ format,
79
+ maxzoom: 14,
80
+ minzoom: 0,
81
+ scheme: 'xyz',
82
+ tilejson: '3.0.0',
83
+ tiles,
84
+ type,
85
+ vector_layers: vectorLayersShortbread,
86
+ },
87
+ },
88
+ version: 8,
89
+ });
90
+ });
91
+ const cases = [
92
+ { type: 'image', options: { tiles, format: 'png' } },
93
+ { type: 'inspector', options: { tiles, format: 'pbf', vectorLayers: vectorLayersSomething } },
94
+ { type: 'shortbread', options: { tiles, format: 'pbf', vectorLayers: vectorLayersShortbread } },
95
+ ];
96
+ describe('minzoom sets zoom', () => {
97
+ cases.forEach(({ type, options }) => {
98
+ it(type, () => {
99
+ expect(guessStyle({ ...options, minzoom: 5 })).toHaveProperty('zoom', 5);
100
+ });
101
+ });
102
+ });
103
+ describe('bounds sets center', () => {
104
+ cases.forEach(({ type, options }) => {
105
+ it(type, () => {
106
+ expect(guessStyle({ ...options, bounds: [1, 2, 3, 4] })).toHaveProperty('center', [2, 3]);
107
+ });
108
+ });
109
+ });
110
+ describe('center sets center', () => {
111
+ cases.forEach(({ type, options }) => {
112
+ it(type, () => {
113
+ expect(guessStyle({ ...options, center: [12, 34] })).toHaveProperty('center', [12, 34]);
114
+ });
115
+ });
116
+ });
117
+ describe('center overrides bounds', () => {
118
+ cases.forEach(({ type, options }) => {
119
+ it(type, () => {
120
+ expect(guessStyle({ ...options, bounds: [1, 2, 3, 4], center: [12, 34] })).toHaveProperty('center', [12, 34]);
121
+ });
122
+ });
123
+ });
57
124
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versatiles/style",
3
- "version": "3.7.0",
3
+ "version": "3.8.0",
4
4
  "description": "Generate StyleJSON for MapLibre",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",