@loaders.gl/mvt 4.2.0-alpha.4 → 4.2.0-alpha.6

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 (93) hide show
  1. package/dist/dist.dev.js +312 -244
  2. package/dist/dist.min.js +14 -0
  3. package/dist/helpers/binary-util-functions.d.ts +1 -1
  4. package/dist/helpers/binary-util-functions.d.ts.map +1 -1
  5. package/dist/helpers/binary-util-functions.js +99 -61
  6. package/dist/helpers/mapbox-util-functions.d.ts +2 -2
  7. package/dist/helpers/mapbox-util-functions.d.ts.map +1 -1
  8. package/dist/helpers/mapbox-util-functions.js +67 -33
  9. package/dist/index.cjs +86 -68
  10. package/dist/index.cjs.map +7 -0
  11. package/dist/index.d.ts +8 -8
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +3 -1
  14. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts +1 -1
  15. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +1 -1
  16. package/dist/lib/binary-vector-tile/vector-tile-feature.js +144 -118
  17. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts +1 -1
  18. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts.map +1 -1
  19. package/dist/lib/binary-vector-tile/vector-tile-layer.js +85 -38
  20. package/dist/lib/binary-vector-tile/vector-tile.d.ts +1 -1
  21. package/dist/lib/binary-vector-tile/vector-tile.d.ts.map +1 -1
  22. package/dist/lib/binary-vector-tile/vector-tile.js +18 -12
  23. package/dist/lib/geojson-tiler/clip.d.ts +1 -1
  24. package/dist/lib/geojson-tiler/clip.d.ts.map +1 -1
  25. package/dist/lib/geojson-tiler/clip.js +180 -142
  26. package/dist/lib/geojson-tiler/convert.d.ts +1 -1
  27. package/dist/lib/geojson-tiler/convert.d.ts.map +1 -1
  28. package/dist/lib/geojson-tiler/convert.js +116 -100
  29. package/dist/lib/geojson-tiler/feature.d.ts +1 -1
  30. package/dist/lib/geojson-tiler/feature.d.ts.map +1 -1
  31. package/dist/lib/geojson-tiler/feature.js +38 -29
  32. package/dist/lib/geojson-tiler/geojson-tiler.d.ts +1 -1
  33. package/dist/lib/geojson-tiler/geojson-tiler.d.ts.map +1 -1
  34. package/dist/lib/geojson-tiler/geojson-tiler.js +198 -159
  35. package/dist/lib/geojson-tiler/simplify.js +60 -40
  36. package/dist/lib/geojson-tiler/tile.js +108 -88
  37. package/dist/lib/geojson-tiler/transform.d.ts +1 -1
  38. package/dist/lib/geojson-tiler/transform.d.ts.map +1 -1
  39. package/dist/lib/geojson-tiler/transform.js +35 -26
  40. package/dist/lib/geojson-tiler/wrap.d.ts +1 -1
  41. package/dist/lib/geojson-tiler/wrap.d.ts.map +1 -1
  42. package/dist/lib/geojson-tiler/wrap.js +74 -53
  43. package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts +1 -1
  44. package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts.map +1 -1
  45. package/dist/lib/mapbox-vector-tile/vector-tile-feature.js +164 -151
  46. package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts +1 -1
  47. package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts.map +1 -1
  48. package/dist/lib/mapbox-vector-tile/vector-tile-layer.js +83 -38
  49. package/dist/lib/mapbox-vector-tile/vector-tile.d.ts +1 -1
  50. package/dist/lib/mapbox-vector-tile/vector-tile.d.ts.map +1 -1
  51. package/dist/lib/mapbox-vector-tile/vector-tile.js +18 -12
  52. package/dist/lib/parse-mvt.d.ts +1 -1
  53. package/dist/lib/parse-mvt.d.ts.map +1 -1
  54. package/dist/lib/parse-mvt.js +142 -115
  55. package/dist/lib/parse-tilejson.js +234 -176
  56. package/dist/lib/types.js +0 -1
  57. package/dist/mvt-loader.d.ts +1 -1
  58. package/dist/mvt-loader.d.ts.map +1 -1
  59. package/dist/mvt-loader.js +42 -22
  60. package/dist/mvt-source.js +153 -139
  61. package/dist/mvt-worker.js +39 -2
  62. package/dist/tilejson-loader.d.ts +1 -1
  63. package/dist/tilejson-loader.d.ts.map +1 -1
  64. package/dist/tilejson-loader.js +32 -31
  65. package/dist/workers/mvt-worker.js +0 -1
  66. package/package.json +12 -8
  67. package/dist/helpers/binary-util-functions.js.map +0 -1
  68. package/dist/helpers/mapbox-util-functions.js.map +0 -1
  69. package/dist/index.js.map +0 -1
  70. package/dist/lib/binary-vector-tile/LICENSE.txt +0 -31
  71. package/dist/lib/binary-vector-tile/vector-tile-feature.js.map +0 -1
  72. package/dist/lib/binary-vector-tile/vector-tile-layer.js.map +0 -1
  73. package/dist/lib/binary-vector-tile/vector-tile.js.map +0 -1
  74. package/dist/lib/geojson-tiler/LICENSE +0 -19
  75. package/dist/lib/geojson-tiler/clip.js.map +0 -1
  76. package/dist/lib/geojson-tiler/convert.js.map +0 -1
  77. package/dist/lib/geojson-tiler/feature.js.map +0 -1
  78. package/dist/lib/geojson-tiler/geojson-tiler.js.map +0 -1
  79. package/dist/lib/geojson-tiler/simplify.js.map +0 -1
  80. package/dist/lib/geojson-tiler/tile.js.map +0 -1
  81. package/dist/lib/geojson-tiler/transform.js.map +0 -1
  82. package/dist/lib/geojson-tiler/wrap.js.map +0 -1
  83. package/dist/lib/mapbox-vector-tile/LICENSE.txt +0 -31
  84. package/dist/lib/mapbox-vector-tile/vector-tile-feature.js.map +0 -1
  85. package/dist/lib/mapbox-vector-tile/vector-tile-layer.js.map +0 -1
  86. package/dist/lib/mapbox-vector-tile/vector-tile.js.map +0 -1
  87. package/dist/lib/parse-mvt.js.map +0 -1
  88. package/dist/lib/parse-tilejson.js.map +0 -1
  89. package/dist/lib/types.js.map +0 -1
  90. package/dist/mvt-loader.js.map +0 -1
  91. package/dist/mvt-source.js.map +0 -1
  92. package/dist/tilejson-loader.js.map +0 -1
  93. package/dist/workers/mvt-worker.js.map +0 -1
@@ -1,103 +1,123 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ // Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
5
+ /**
6
+ * Create a tile from features and tile index
7
+ */
1
8
  export function createTile(features, z, tx, ty, options) {
2
- const tolerance = z === options.maxZoom ? 0 : options.tolerance / ((1 << z) * options.extent);
3
- const tile = {
4
- features: [],
5
- numPoints: 0,
6
- numSimplified: 0,
7
- numFeatures: features.length,
8
- source: null,
9
- x: tx,
10
- y: ty,
11
- z,
12
- transformed: false,
13
- minX: 2,
14
- minY: 1,
15
- maxX: -1,
16
- maxY: 0
17
- };
18
- for (const feature of features) {
19
- addFeature(tile, feature, tolerance, options);
20
- }
21
- return tile;
9
+ const tolerance = z === options.maxZoom ? 0 : options.tolerance / ((1 << z) * options.extent);
10
+ const tile = {
11
+ features: [],
12
+ numPoints: 0,
13
+ numSimplified: 0,
14
+ numFeatures: features.length,
15
+ source: null,
16
+ x: tx,
17
+ y: ty,
18
+ z,
19
+ transformed: false,
20
+ minX: 2,
21
+ minY: 1,
22
+ maxX: -1,
23
+ maxY: 0
24
+ };
25
+ for (const feature of features) {
26
+ addFeature(tile, feature, tolerance, options);
27
+ }
28
+ return tile;
22
29
  }
30
+ // eslint-disable-next-line complexity, max-statements
23
31
  function addFeature(tile, feature, tolerance, options) {
24
- const geom = feature.geometry;
25
- const type = feature.type;
26
- const simplified = [];
27
- tile.minX = Math.min(tile.minX, feature.minX);
28
- tile.minY = Math.min(tile.minY, feature.minY);
29
- tile.maxX = Math.max(tile.maxX, feature.maxX);
30
- tile.maxY = Math.max(tile.maxY, feature.maxY);
31
- if (type === 'Point' || type === 'MultiPoint') {
32
- for (let i = 0; i < geom.length; i += 3) {
33
- simplified.push(geom[i], geom[i + 1]);
34
- tile.numPoints++;
35
- tile.numSimplified++;
32
+ const geom = feature.geometry;
33
+ const type = feature.type;
34
+ const simplified = [];
35
+ tile.minX = Math.min(tile.minX, feature.minX);
36
+ tile.minY = Math.min(tile.minY, feature.minY);
37
+ tile.maxX = Math.max(tile.maxX, feature.maxX);
38
+ tile.maxY = Math.max(tile.maxY, feature.maxY);
39
+ if (type === 'Point' || type === 'MultiPoint') {
40
+ for (let i = 0; i < geom.length; i += 3) {
41
+ simplified.push(geom[i], geom[i + 1]);
42
+ tile.numPoints++;
43
+ tile.numSimplified++;
44
+ }
36
45
  }
37
- } else if (type === 'LineString') {
38
- addLine(simplified, geom, tile, tolerance, false, false);
39
- } else if (type === 'MultiLineString' || type === 'Polygon') {
40
- for (let i = 0; i < geom.length; i++) {
41
- addLine(simplified, geom[i], tile, tolerance, type === 'Polygon', i === 0);
46
+ else if (type === 'LineString') {
47
+ addLine(simplified, geom, tile, tolerance, false, false);
42
48
  }
43
- } else if (type === 'MultiPolygon') {
44
- for (let k = 0; k < geom.length; k++) {
45
- const polygon = geom[k];
46
- for (let i = 0; i < polygon.length; i++) {
47
- addLine(simplified, polygon[i], tile, tolerance, true, i === 0);
48
- }
49
+ else if (type === 'MultiLineString' || type === 'Polygon') {
50
+ for (let i = 0; i < geom.length; i++) {
51
+ addLine(simplified, geom[i], tile, tolerance, type === 'Polygon', i === 0);
52
+ }
49
53
  }
50
- }
51
- if (simplified.length) {
52
- let tags = feature.tags || null;
53
- if (type === 'LineString' && options.lineMetrics) {
54
- tags = {};
55
- for (const key in feature.tags) tags[key] = feature.tags[key];
56
- tags.mapbox_clip_start = geom.start / geom.size;
57
- tags.mapbox_clip_end = geom.end / geom.size;
54
+ else if (type === 'MultiPolygon') {
55
+ for (let k = 0; k < geom.length; k++) {
56
+ const polygon = geom[k];
57
+ for (let i = 0; i < polygon.length; i++) {
58
+ addLine(simplified, polygon[i], tile, tolerance, true, i === 0);
59
+ }
60
+ }
58
61
  }
59
- const tileFeature = {
60
- geometry: simplified,
61
- type: type === 'Polygon' || type === 'MultiPolygon' ? 3 : type === 'LineString' || type === 'MultiLineString' ? 2 : 1,
62
- tags
63
- };
64
- if (feature.id !== null) {
65
- tileFeature.id = feature.id;
62
+ if (simplified.length) {
63
+ let tags = feature.tags || null;
64
+ if (type === 'LineString' && options.lineMetrics) {
65
+ tags = {};
66
+ for (const key in feature.tags)
67
+ tags[key] = feature.tags[key];
68
+ // eslint-disable-next-line camelcase
69
+ tags.mapbox_clip_start = geom.start / geom.size;
70
+ // eslint-disable-next-line camelcase
71
+ tags.mapbox_clip_end = geom.end / geom.size;
72
+ }
73
+ // @ts-expect-error TODO - create sub type?
74
+ const tileFeature = {
75
+ geometry: simplified,
76
+ type: type === 'Polygon' || type === 'MultiPolygon'
77
+ ? 3
78
+ : type === 'LineString' || type === 'MultiLineString'
79
+ ? 2
80
+ : 1,
81
+ tags
82
+ };
83
+ if (feature.id !== null) {
84
+ tileFeature.id = feature.id;
85
+ }
86
+ tile.features.push(tileFeature);
66
87
  }
67
- tile.features.push(tileFeature);
68
- }
69
88
  }
89
+ // eslint-disable-next-line max-params, max-statements
70
90
  function addLine(result, geom, tile, tolerance, isPolygon, isOuter) {
71
- const sqTolerance = tolerance * tolerance;
72
- if (tolerance > 0 && geom.size < (isPolygon ? sqTolerance : tolerance)) {
73
- tile.numPoints += geom.length / 3;
74
- return;
75
- }
76
- const ring = [];
77
- for (let i = 0; i < geom.length; i += 3) {
78
- if (tolerance === 0 || geom[i + 2] > sqTolerance) {
79
- tile.numSimplified++;
80
- ring.push(geom[i], geom[i + 1]);
91
+ const sqTolerance = tolerance * tolerance;
92
+ if (tolerance > 0 && geom.size < (isPolygon ? sqTolerance : tolerance)) {
93
+ tile.numPoints += geom.length / 3;
94
+ return;
81
95
  }
82
- tile.numPoints++;
83
- }
84
- if (isPolygon) rewind(ring, isOuter);
85
- result.push(ring);
96
+ const ring = [];
97
+ for (let i = 0; i < geom.length; i += 3) {
98
+ if (tolerance === 0 || geom[i + 2] > sqTolerance) {
99
+ tile.numSimplified++;
100
+ ring.push(geom[i], geom[i + 1]);
101
+ }
102
+ tile.numPoints++;
103
+ }
104
+ if (isPolygon)
105
+ rewind(ring, isOuter);
106
+ result.push(ring);
86
107
  }
87
108
  function rewind(ring, clockwise) {
88
- let area = 0;
89
- for (let i = 0, j = ring.length - 2; i < ring.length; j = i, i += 2) {
90
- area += (ring[i] - ring[j]) * (ring[i + 1] + ring[j + 1]);
91
- }
92
- if (area > 0 === clockwise) {
93
- for (let i = 0, len = ring.length; i < len / 2; i += 2) {
94
- const x = ring[i];
95
- const y = ring[i + 1];
96
- ring[i] = ring[len - 2 - i];
97
- ring[i + 1] = ring[len - 1 - i];
98
- ring[len - 2 - i] = x;
99
- ring[len - 1 - i] = y;
109
+ let area = 0;
110
+ for (let i = 0, j = ring.length - 2; i < ring.length; j = i, i += 2) {
111
+ area += (ring[i] - ring[j]) * (ring[i + 1] + ring[j + 1]);
112
+ }
113
+ if (area > 0 === clockwise) {
114
+ for (let i = 0, len = ring.length; i < len / 2; i += 2) {
115
+ const x = ring[i];
116
+ const y = ring[i + 1];
117
+ ring[i] = ring[len - 2 - i];
118
+ ring[i + 1] = ring[len - 1 - i];
119
+ ring[len - 2 - i] = x;
120
+ ring[len - 1 - i] = y;
121
+ }
100
122
  }
101
- }
102
123
  }
103
- //# sourceMappingURL=tile.js.map
@@ -1,4 +1,4 @@
1
- import type { GeoJSONTile } from './tile';
1
+ import type { GeoJSONTile } from "./tile.js";
2
2
  /**
3
3
  * Transforms the coordinates of each feature in the given tile from
4
4
  * mercator-projected space into (extent x extent) tile space.
@@ -1 +1 @@
1
- {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../../src/lib/geojson-tiler/transform.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,QAAQ,CAAC;AAExC;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,CAiC5E"}
1
+ {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../../src/lib/geojson-tiler/transform.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,WAAW,EAAC,kBAAe;AAExC;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,CAiC5E"}
@@ -1,32 +1,41 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ // Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
5
+ /**
6
+ * Transforms the coordinates of each feature in the given tile from
7
+ * mercator-projected space into (extent x extent) tile space.
8
+ */
1
9
  export function transformTile(tile, extent) {
2
- if (tile.transformed) {
3
- return tile;
4
- }
5
- const z2 = 1 << tile.z;
6
- const tx = tile.x;
7
- const ty = tile.y;
8
- for (const feature of tile.features) {
9
- const geom = feature.geometry;
10
- const type = feature.type;
11
- feature.geometry = [];
12
- if (type === 1) {
13
- for (let j = 0; j < geom.length; j += 2) {
14
- feature.geometry.push(transformPoint(geom[j], geom[j + 1], extent, z2, tx, ty));
15
- }
16
- } else {
17
- for (let j = 0; j < geom.length; j++) {
18
- const ring = [];
19
- for (let k = 0; k < geom[j].length; k += 2) {
20
- ring.push(transformPoint(geom[j][k], geom[j][k + 1], extent, z2, tx, ty));
10
+ if (tile.transformed) {
11
+ return tile;
12
+ }
13
+ const z2 = 1 << tile.z;
14
+ const tx = tile.x;
15
+ const ty = tile.y;
16
+ for (const feature of tile.features) {
17
+ const geom = feature.geometry;
18
+ const type = feature.type;
19
+ feature.geometry = [];
20
+ if (type === 1) {
21
+ for (let j = 0; j < geom.length; j += 2) {
22
+ feature.geometry.push(transformPoint(geom[j], geom[j + 1], extent, z2, tx, ty));
23
+ }
24
+ }
25
+ else {
26
+ for (let j = 0; j < geom.length; j++) {
27
+ const ring = [];
28
+ for (let k = 0; k < geom[j].length; k += 2) {
29
+ ring.push(transformPoint(geom[j][k], geom[j][k + 1], extent, z2, tx, ty));
30
+ }
31
+ feature.geometry.push(ring);
32
+ }
21
33
  }
22
- feature.geometry.push(ring);
23
- }
24
34
  }
25
- }
26
- tile.transformed = true;
27
- return tile;
35
+ tile.transformed = true;
36
+ return tile;
28
37
  }
38
+ // eslint-disable-next-line max-params
29
39
  function transformPoint(x, y, extent, z2, tx, ty) {
30
- return [Math.round(extent * (x * z2 - tx)), Math.round(extent * (y * z2 - ty))];
40
+ return [Math.round(extent * (x * z2 - tx)), Math.round(extent * (y * z2 - ty))];
31
41
  }
32
- //# sourceMappingURL=transform.js.map
@@ -1,4 +1,4 @@
1
- import type { GeoJSONTileFeature } from './tile';
1
+ import type { GeoJSONTileFeature } from "./tile.js";
2
2
  /**
3
3
  * Options for wrap()
4
4
  */
@@ -1 +1 @@
1
- {"version":3,"file":"wrap.d.ts","sourceRoot":"","sources":["../../../src/lib/geojson-tiler/wrap.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,QAAQ,CAAC;AAI/C;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,MAAM,CAAC,8CAA8C,CAAC;IAC9D,MAAM,EAAE,MAAM,CAAC,0BAA0B,CAAC;IAC1C,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,QAAQ,EAAE,kBAAkB,EAAE,EAAE,OAAO,EAAE,WAAW,wBAkBxE"}
1
+ {"version":3,"file":"wrap.d.ts","sourceRoot":"","sources":["../../../src/lib/geojson-tiler/wrap.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,kBAAkB,EAAC,kBAAe;AAI/C;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,MAAM,CAAC,8CAA8C,CAAC;IAC9D,MAAM,EAAE,MAAM,CAAC,0BAA0B,CAAC;IAC1C,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,QAAQ,EAAE,kBAAkB,EAAE,EAAE,OAAO,EAAE,WAAW,wBAkBxE"}
@@ -1,66 +1,87 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ // Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
1
5
  import { clip } from "./clip.js";
2
6
  import { createFeature } from "./feature.js";
7
+ /**
8
+ * Wrap across antemeridian, by clipping into two tiles, shifting the overflowing x coordinates
9
+ * @param features list of features to be wrapped
10
+ * @param options buffer and extent
11
+ * @returns
12
+ */
3
13
  export function wrap(features, options) {
4
- const buffer = options.buffer / options.extent;
5
- let merged = features;
6
- const left = clip(features, 1, -1 - buffer, buffer, 0, -1, 2, options);
7
- const right = clip(features, 1, 1 - buffer, 2 + buffer, 0, -1, 2, options);
8
- if (left || right) {
9
- merged = clip(features, 1, -buffer, 1 + buffer, 0, -1, 2, options) || [];
10
- if (left) {
11
- merged = shiftFeatureCoords(left, 1).concat(merged);
12
- }
13
- if (right) {
14
- merged = merged.concat(shiftFeatureCoords(right, -1));
14
+ const buffer = options.buffer / options.extent;
15
+ let merged = features;
16
+ const left = clip(features, 1, -1 - buffer, buffer, 0, -1, 2, options); // left world copy
17
+ const right = clip(features, 1, 1 - buffer, 2 + buffer, 0, -1, 2, options); // right world copy
18
+ if (left || right) {
19
+ merged = clip(features, 1, -buffer, 1 + buffer, 0, -1, 2, options) || []; // center world copy
20
+ if (left) {
21
+ merged = shiftFeatureCoords(left, 1).concat(merged); // merge left into center
22
+ }
23
+ if (right) {
24
+ merged = merged.concat(shiftFeatureCoords(right, -1)); // merge right into center
25
+ }
15
26
  }
16
- }
17
- return merged;
27
+ return merged;
18
28
  }
29
+ /**
30
+ * Shift the x coordinates of a list of features
31
+ * @param features list of features to shift x coordinates for
32
+ * @param offset
33
+ * @returns
34
+ */
19
35
  function shiftFeatureCoords(features, offset) {
20
- const newFeatures = [];
21
- for (let i = 0; i < features.length; i++) {
22
- const feature = features[i];
23
- const type = feature.type;
24
- let newGeometry;
25
- if (type === 'Point' || type === 'MultiPoint' || type === 'LineString') {
26
- newGeometry = shiftCoords(feature.geometry, offset);
27
- } else if (type === 'MultiLineString' || type === 'Polygon') {
28
- newGeometry = [];
29
- for (const line of feature.geometry) {
30
- newGeometry.push(shiftCoords(line, offset));
31
- }
32
- } else if (type === 'MultiPolygon') {
33
- newGeometry = [];
34
- for (const polygon of feature.geometry) {
35
- const newPolygon = [];
36
- for (const line of polygon) {
37
- newPolygon.push(shiftCoords(line, offset));
36
+ const newFeatures = [];
37
+ for (let i = 0; i < features.length; i++) {
38
+ const feature = features[i];
39
+ const type = feature.type;
40
+ let newGeometry;
41
+ if (type === 'Point' || type === 'MultiPoint' || type === 'LineString') {
42
+ newGeometry = shiftCoords(feature.geometry, offset);
43
+ }
44
+ else if (type === 'MultiLineString' || type === 'Polygon') {
45
+ newGeometry = [];
46
+ for (const line of feature.geometry) {
47
+ newGeometry.push(shiftCoords(line, offset));
48
+ }
38
49
  }
39
- newGeometry.push(newPolygon);
40
- }
50
+ else if (type === 'MultiPolygon') {
51
+ newGeometry = [];
52
+ for (const polygon of feature.geometry) {
53
+ const newPolygon = [];
54
+ for (const line of polygon) {
55
+ // @ts-expect-error TODO
56
+ newPolygon.push(shiftCoords(line, offset));
57
+ }
58
+ newGeometry.push(newPolygon);
59
+ }
60
+ }
61
+ newFeatures.push(createFeature(feature.id, type, newGeometry, feature.tags));
41
62
  }
42
- newFeatures.push(createFeature(feature.id, type, newGeometry, feature.tags));
43
- }
44
- return newFeatures;
63
+ return newFeatures;
45
64
  }
46
65
  class Points extends Array {
47
- constructor() {
48
- super(...arguments);
49
- this.size = void 0;
50
- this.start = void 0;
51
- this.end = void 0;
52
- }
66
+ size;
67
+ start;
68
+ end;
53
69
  }
70
+ /**
71
+ * Shift the x coordinate of every point
72
+ * @param points
73
+ * @param offset
74
+ * @returns
75
+ */
54
76
  function shiftCoords(points, offset) {
55
- const newPoints = [];
56
- newPoints.size = points.size;
57
- if (points.start !== undefined) {
58
- newPoints.start = points.start;
59
- newPoints.end = points.end;
60
- }
61
- for (let i = 0; i < points.length; i += 3) {
62
- newPoints.push(points[i] + offset, points[i + 1], points[i + 2]);
63
- }
64
- return newPoints;
77
+ const newPoints = [];
78
+ newPoints.size = points.size;
79
+ if (points.start !== undefined) {
80
+ newPoints.start = points.start;
81
+ newPoints.end = points.end;
82
+ }
83
+ for (let i = 0; i < points.length; i += 3) {
84
+ newPoints.push(points[i] + offset, points[i + 1], points[i + 2]);
85
+ }
86
+ return newPoints;
65
87
  }
66
- //# sourceMappingURL=wrap.js.map
@@ -1,5 +1,5 @@
1
1
  import Protobuf from 'pbf';
2
- import { MVTMapboxCoordinates, MVTMapboxGeometry } from '../types';
2
+ import { MVTMapboxCoordinates, MVTMapboxGeometry } from "../types.js";
3
3
  export default class VectorTileFeature {
4
4
  properties: {
5
5
  [x: string]: string | number | boolean | null;
@@ -1 +1 @@
1
- {"version":3,"file":"vector-tile-feature.d.ts","sourceRoot":"","sources":["../../../src/lib/mapbox-vector-tile/vector-tile-feature.ts"],"names":[],"mappings":"AACA,OAAO,QAAQ,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAC,oBAAoB,EAAE,iBAAiB,EAAC,MAAM,UAAU,CAAC;AAGjE,MAAM,CAAC,OAAO,OAAO,iBAAiB;IACpC,UAAU,EAAE;QAAC,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAA;KAAC,CAAC;IAC5D,MAAM,EAAE,GAAG,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAClB,IAAI,EAAE,QAAQ,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,EAAE,CAAC;IAC9C,MAAM,KAAK,KAAK,aAEf;gBAGC,GAAG,EAAE,QAAQ,EACb,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,GAAG,EACX,IAAI,EAAE,MAAM,EAAE,EACd,MAAM,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,EAAE;IAkB9C,YAAY,IAAI,iBAAiB;IA+CjC,IAAI;IAsCJ,UAAU,CAAC,SAAS,KAAA;IAuDpB,SAAS,CACP,OAAO,EAAE;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAC,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE;QAAC,MAAM,EAAE,GAAG,CAAA;KAAC,KAAK,IAAI,CAAC,GAC9F,oBAAoB;CAmBxB"}
1
+ {"version":3,"file":"vector-tile-feature.d.ts","sourceRoot":"","sources":["../../../src/lib/mapbox-vector-tile/vector-tile-feature.ts"],"names":[],"mappings":"AACA,OAAO,QAAQ,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAC,oBAAoB,EAAE,iBAAiB,EAAC,oBAAiB;AAGjE,MAAM,CAAC,OAAO,OAAO,iBAAiB;IACpC,UAAU,EAAE;QAAC,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAA;KAAC,CAAC;IAC5D,MAAM,EAAE,GAAG,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAClB,IAAI,EAAE,QAAQ,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,EAAE,CAAC;IAC9C,MAAM,KAAK,KAAK,aAEf;gBAGC,GAAG,EAAE,QAAQ,EACb,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,GAAG,EACX,IAAI,EAAE,MAAM,EAAE,EACd,MAAM,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,EAAE;IAkB9C,YAAY,IAAI,iBAAiB;IA+CjC,IAAI;IAsCJ,UAAU,CAAC,SAAS,KAAA;IAuDpB,SAAS,CACP,OAAO,EAAE;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAC,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE;QAAC,MAAM,EAAE,GAAG,CAAA;KAAC,KAAK,IAAI,CAAC,GAC9F,oBAAoB;CAmBxB"}