@basemaps/lambda-tiler 7.9.0 → 7.10.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.
Files changed (34) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/build/__tests__/tile.style.json.test.js +13 -7
  3. package/build/__tests__/tile.style.json.test.js.map +1 -1
  4. package/build/routes/__tests__/health.test.js +40 -20
  5. package/build/routes/__tests__/health.test.js.map +1 -1
  6. package/build/routes/__tests__/tile.style.json.test.js +57 -0
  7. package/build/routes/__tests__/tile.style.json.test.js.map +1 -1
  8. package/build/routes/__tests__/xyz.test.js +13 -0
  9. package/build/routes/__tests__/xyz.test.js.map +1 -1
  10. package/build/routes/health.d.ts +17 -0
  11. package/build/routes/health.js +119 -21
  12. package/build/routes/health.js.map +1 -1
  13. package/build/routes/tile.style.json.d.ts +35 -13
  14. package/build/routes/tile.style.json.js +108 -123
  15. package/build/routes/tile.style.json.js.map +1 -1
  16. package/build/routes/tile.xyz.vector.js +9 -9
  17. package/build/routes/tile.xyz.vector.js.map +1 -1
  18. package/build/util/__test__/nztm.style.test.d.ts +1 -0
  19. package/build/util/__test__/nztm.style.test.js +87 -0
  20. package/build/util/__test__/nztm.style.test.js.map +1 -0
  21. package/build/util/nztm.style.d.ts +12 -0
  22. package/build/util/nztm.style.js +45 -0
  23. package/build/util/nztm.style.js.map +1 -0
  24. package/package.json +7 -6
  25. package/src/__tests__/tile.style.json.test.ts +16 -7
  26. package/src/routes/__tests__/health.test.ts +46 -22
  27. package/src/routes/__tests__/tile.style.json.test.ts +60 -0
  28. package/src/routes/__tests__/xyz.test.ts +18 -0
  29. package/src/routes/health.ts +129 -21
  30. package/src/routes/tile.style.json.ts +131 -145
  31. package/src/routes/tile.xyz.vector.ts +10 -6
  32. package/src/util/__test__/nztm.style.test.ts +100 -0
  33. package/src/util/nztm.style.ts +44 -0
  34. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,100 @@
1
+ import assert from 'node:assert';
2
+ import { describe, it } from 'node:test';
3
+
4
+ import { StyleJson } from '@basemaps/config';
5
+
6
+ import { convertStyleToNztmStyle } from '../nztm.style.js';
7
+
8
+ describe('NZTM2000QuadStyle', () => {
9
+ const fakeStyle: StyleJson = {
10
+ version: 8,
11
+ id: 'test',
12
+ name: 'topographic',
13
+ sources: {},
14
+ layers: [],
15
+ glyphs: '/glyphs',
16
+ sprite: '/sprite',
17
+ metadata: { id: 'test' },
18
+ };
19
+
20
+ it('should not modify the source style', () => {
21
+ const baseStyle = {
22
+ ...fakeStyle,
23
+ terrain: { exaggeration: 1.1, source: 'abc' },
24
+ };
25
+
26
+ convertStyleToNztmStyle(baseStyle);
27
+ assert.equal(baseStyle.terrain?.exaggeration, 1.1);
28
+
29
+ convertStyleToNztmStyle(baseStyle, false);
30
+ assert.equal(baseStyle.terrain?.exaggeration, 4.4);
31
+ });
32
+
33
+ it('should convert min/maxzooms', () => {
34
+ const newStyle = convertStyleToNztmStyle({
35
+ ...fakeStyle,
36
+ layers: [{ minzoom: 5, maxzoom: 10, id: 'something', type: '' }],
37
+ });
38
+
39
+ assert.deepEqual(newStyle.layers[0], { minzoom: 3, maxzoom: 8, id: 'something', type: '' });
40
+ });
41
+
42
+ it('should offset terrain', () => {
43
+ const newStyle = convertStyleToNztmStyle({
44
+ ...fakeStyle,
45
+ terrain: { exaggeration: 1.1, source: 'abc' },
46
+ });
47
+
48
+ assert.deepEqual(newStyle.terrain, { exaggeration: 4.4, source: 'abc' });
49
+ });
50
+
51
+ it('should convert stops inside of paint and layout', () => {
52
+ const newStyle = convertStyleToNztmStyle({
53
+ ...fakeStyle,
54
+ layers: [
55
+ {
56
+ layout: {
57
+ 'line-width': {
58
+ stops: [
59
+ [16, 0.75],
60
+ [24, 1.5],
61
+ ],
62
+ },
63
+ },
64
+
65
+ paint: {
66
+ 'line-width': {
67
+ stops: [
68
+ [16, 0.75],
69
+ [24, 1.5],
70
+ ],
71
+ },
72
+ },
73
+ id: 'something',
74
+ type: '',
75
+ },
76
+ ],
77
+ });
78
+
79
+ assert.deepEqual(newStyle.layers[0], {
80
+ layout: {
81
+ 'line-width': {
82
+ stops: [
83
+ [14, 0.75],
84
+ [22, 1.5],
85
+ ],
86
+ },
87
+ },
88
+ paint: {
89
+ 'line-width': {
90
+ stops: [
91
+ [14, 0.75],
92
+ [22, 1.5],
93
+ ],
94
+ },
95
+ },
96
+ id: 'something',
97
+ type: '',
98
+ });
99
+ });
100
+ });
@@ -0,0 +1,44 @@
1
+ import { StyleJson } from '@basemaps/config';
2
+
3
+ /**
4
+ * limited checking to cast a unknown paint/layout into one with stops
5
+ */
6
+ function hasStops(x: unknown): x is { stops: [number, unknown][] } {
7
+ if (x == null) return false;
8
+ return Array.isArray((x as { stops: unknown })['stops']);
9
+ }
10
+
11
+ /**
12
+ * Convert a style json from a WebMercatorQuad style into a NZTM2000Quad style,
13
+ * This creates a clone of the source style and does not modify the source
14
+ *
15
+ * NZTM2000Quad is offset from WebMercatorQuad by two zoom levels
16
+ *
17
+ * @param inputStyle style to convert
18
+ * @param clone Should the input style be cloned or modified
19
+ * @returns a new style converted into NZTM2000Quad zooms
20
+ */
21
+ export function convertStyleToNztmStyle(inputStyle: StyleJson, clone: boolean = true): StyleJson {
22
+ const style = clone ? structuredClone(inputStyle) : inputStyle;
23
+
24
+ for (const layer of style.layers) {
25
+ // Adjust the min/max zoom
26
+ if (layer.minzoom) layer.minzoom = Math.max(0, layer.minzoom - 2);
27
+ if (layer.maxzoom) layer.maxzoom = Math.max(0, layer.maxzoom - 2);
28
+
29
+ // Check all the pain and layout for "stops" then adjust the stops by two
30
+ const stylesToCheck = [layer.paint, layer.layout];
31
+ for (const obj of stylesToCheck) {
32
+ if (obj == null) continue;
33
+ for (const val of Object.values(obj)) {
34
+ if (!hasStops(val)) continue;
35
+ for (const stop of val.stops) stop[0] = Math.max(0, stop[0] - 2);
36
+ }
37
+ }
38
+ }
39
+
40
+ /** Based on {@link DefaultExaggeration} offsetting by 2 two levels changes the exaggeration needed by approx 4x */
41
+ if (style.terrain) style.terrain.exaggeration = style.terrain.exaggeration * 4;
42
+
43
+ return style;
44
+ }