@loaders.gl/mvt 4.0.0-alpha.5 → 4.0.0-alpha.7

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 (175) hide show
  1. package/dist/bundle.js +2 -2
  2. package/dist/dist.min.js +1748 -913
  3. package/dist/es5/bundle.js +6 -0
  4. package/dist/es5/bundle.js.map +1 -0
  5. package/dist/es5/helpers/binary-util-functions.js +82 -0
  6. package/dist/es5/helpers/binary-util-functions.js.map +1 -0
  7. package/dist/es5/helpers/mapbox-util-functions.js +50 -0
  8. package/dist/es5/helpers/mapbox-util-functions.js.map +1 -0
  9. package/dist/es5/index.js +26 -0
  10. package/dist/es5/index.js.map +1 -0
  11. package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js +168 -0
  12. package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js.map +1 -0
  13. package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js +62 -0
  14. package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js.map +1 -0
  15. package/dist/es5/lib/binary-vector-tile/vector-tile.js +28 -0
  16. package/dist/es5/lib/binary-vector-tile/vector-tile.js.map +1 -0
  17. package/dist/es5/lib/geojson-tiler/LICENSE +19 -0
  18. package/dist/es5/lib/geojson-tiler/clip.js +237 -0
  19. package/dist/es5/lib/geojson-tiler/clip.js.map +1 -0
  20. package/dist/es5/lib/geojson-tiler/convert.js +161 -0
  21. package/dist/es5/lib/geojson-tiler/convert.js.map +1 -0
  22. package/dist/es5/lib/geojson-tiler/feature.js +62 -0
  23. package/dist/es5/lib/geojson-tiler/feature.js.map +1 -0
  24. package/dist/es5/lib/geojson-tiler/geojson-tiler.js +186 -0
  25. package/dist/es5/lib/geojson-tiler/geojson-tiler.js.map +1 -0
  26. package/dist/es5/lib/geojson-tiler/simplify.js +52 -0
  27. package/dist/es5/lib/geojson-tiler/simplify.js.map +1 -0
  28. package/dist/es5/lib/geojson-tiler/tile.js +121 -0
  29. package/dist/es5/lib/geojson-tiler/tile.js.map +1 -0
  30. package/dist/es5/lib/geojson-tiler/transform.js +50 -0
  31. package/dist/es5/lib/geojson-tiler/transform.js.map +1 -0
  32. package/dist/es5/lib/geojson-tiler/wrap.js +122 -0
  33. package/dist/es5/lib/geojson-tiler/wrap.js.map +1 -0
  34. package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js +184 -0
  35. package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -0
  36. package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js +62 -0
  37. package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js.map +1 -0
  38. package/dist/es5/lib/mapbox-vector-tile/vector-tile.js +28 -0
  39. package/dist/es5/lib/mapbox-vector-tile/vector-tile.js.map +1 -0
  40. package/dist/es5/lib/parse-mvt.js +143 -0
  41. package/dist/es5/lib/parse-mvt.js.map +1 -0
  42. package/dist/es5/lib/types.js +2 -0
  43. package/dist/es5/lib/types.js.map +1 -0
  44. package/dist/es5/mvt-loader.js +58 -0
  45. package/dist/es5/mvt-loader.js.map +1 -0
  46. package/dist/es5/workers/mvt-worker.js +6 -0
  47. package/dist/es5/workers/mvt-worker.js.map +1 -0
  48. package/dist/esm/bundle.js +4 -0
  49. package/dist/esm/bundle.js.map +1 -0
  50. package/dist/esm/helpers/binary-util-functions.js +73 -0
  51. package/dist/esm/helpers/binary-util-functions.js.map +1 -0
  52. package/dist/esm/helpers/mapbox-util-functions.js +41 -0
  53. package/dist/esm/helpers/mapbox-util-functions.js.map +1 -0
  54. package/dist/esm/index.js +3 -0
  55. package/dist/esm/index.js.map +1 -0
  56. package/dist/esm/lib/binary-vector-tile/LICENSE.txt +31 -0
  57. package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js +136 -0
  58. package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js.map +1 -0
  59. package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js +47 -0
  60. package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js.map +1 -0
  61. package/dist/esm/lib/binary-vector-tile/vector-tile.js +19 -0
  62. package/dist/esm/lib/binary-vector-tile/vector-tile.js.map +1 -0
  63. package/dist/esm/lib/geojson-tiler/LICENSE +19 -0
  64. package/dist/esm/lib/geojson-tiler/clip.js +173 -0
  65. package/dist/esm/lib/geojson-tiler/clip.js.map +1 -0
  66. package/dist/esm/lib/geojson-tiler/convert.js +116 -0
  67. package/dist/esm/lib/geojson-tiler/convert.js.map +1 -0
  68. package/dist/esm/lib/geojson-tiler/feature.js +35 -0
  69. package/dist/esm/lib/geojson-tiler/feature.js.map +1 -0
  70. package/dist/esm/lib/geojson-tiler/geojson-tiler.js +171 -0
  71. package/dist/esm/lib/geojson-tiler/geojson-tiler.js.map +1 -0
  72. package/dist/esm/lib/geojson-tiler/simplify.js +46 -0
  73. package/dist/esm/lib/geojson-tiler/simplify.js.map +1 -0
  74. package/dist/esm/lib/geojson-tiler/tile.js +103 -0
  75. package/dist/esm/lib/geojson-tiler/tile.js.map +1 -0
  76. package/dist/esm/lib/geojson-tiler/transform.js +32 -0
  77. package/dist/esm/lib/geojson-tiler/transform.js.map +1 -0
  78. package/dist/esm/lib/geojson-tiler/wrap.js +67 -0
  79. package/dist/esm/lib/geojson-tiler/wrap.js.map +1 -0
  80. package/dist/esm/lib/mapbox-vector-tile/LICENSE.txt +31 -0
  81. package/dist/esm/lib/mapbox-vector-tile/vector-tile-feature.js +163 -0
  82. package/dist/esm/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -0
  83. package/dist/esm/lib/mapbox-vector-tile/vector-tile-layer.js +47 -0
  84. package/dist/esm/lib/mapbox-vector-tile/vector-tile-layer.js.map +1 -0
  85. package/dist/esm/lib/mapbox-vector-tile/vector-tile.js +19 -0
  86. package/dist/esm/lib/mapbox-vector-tile/vector-tile.js.map +1 -0
  87. package/dist/esm/lib/parse-mvt.js +138 -0
  88. package/dist/esm/lib/parse-mvt.js.map +1 -0
  89. package/dist/esm/lib/types.js +2 -0
  90. package/dist/esm/lib/types.js.map +1 -0
  91. package/dist/esm/mvt-loader.js +29 -0
  92. package/dist/esm/mvt-loader.js.map +1 -0
  93. package/dist/esm/workers/mvt-worker.js +4 -0
  94. package/dist/esm/workers/mvt-worker.js.map +1 -0
  95. package/dist/helpers/binary-util-functions.js +111 -77
  96. package/dist/helpers/mapbox-util-functions.d.ts +2 -2
  97. package/dist/helpers/mapbox-util-functions.js +78 -45
  98. package/dist/index.d.ts +2 -0
  99. package/dist/index.d.ts.map +1 -1
  100. package/dist/index.js +9 -2
  101. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +1 -1
  102. package/dist/lib/binary-vector-tile/vector-tile-feature.js +142 -143
  103. package/dist/lib/binary-vector-tile/vector-tile-layer.js +85 -58
  104. package/dist/lib/binary-vector-tile/vector-tile.js +25 -19
  105. package/dist/lib/geojson-tiler/clip.d.ts +16 -0
  106. package/dist/lib/geojson-tiler/clip.d.ts.map +1 -0
  107. package/dist/lib/geojson-tiler/clip.js +209 -0
  108. package/dist/lib/geojson-tiler/convert.d.ts +10 -0
  109. package/dist/lib/geojson-tiler/convert.d.ts.map +1 -0
  110. package/dist/lib/geojson-tiler/convert.js +134 -0
  111. package/dist/lib/geojson-tiler/feature.d.ts +3 -0
  112. package/dist/lib/geojson-tiler/feature.d.ts.map +1 -0
  113. package/dist/lib/geojson-tiler/feature.js +46 -0
  114. package/dist/lib/geojson-tiler/geojson-tiler.d.ts +44 -0
  115. package/dist/lib/geojson-tiler/geojson-tiler.d.ts.map +1 -0
  116. package/dist/lib/geojson-tiler/geojson-tiler.js +210 -0
  117. package/dist/lib/geojson-tiler/simplify.d.ts +10 -0
  118. package/dist/lib/geojson-tiler/simplify.d.ts.map +1 -0
  119. package/dist/lib/geojson-tiler/simplify.js +68 -0
  120. package/dist/lib/geojson-tiler/tile.d.ts +38 -0
  121. package/dist/lib/geojson-tiler/tile.d.ts.map +1 -0
  122. package/dist/lib/geojson-tiler/tile.js +125 -0
  123. package/dist/lib/geojson-tiler/transform.d.ts +7 -0
  124. package/dist/lib/geojson-tiler/transform.d.ts.map +1 -0
  125. package/dist/lib/geojson-tiler/transform.js +43 -0
  126. package/dist/lib/geojson-tiler/wrap.d.ts +17 -0
  127. package/dist/lib/geojson-tiler/wrap.d.ts.map +1 -0
  128. package/dist/lib/geojson-tiler/wrap.js +86 -0
  129. package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts +4 -4
  130. package/dist/lib/mapbox-vector-tile/vector-tile-feature.js +161 -193
  131. package/dist/lib/mapbox-vector-tile/vector-tile-layer.js +83 -58
  132. package/dist/lib/mapbox-vector-tile/vector-tile.js +25 -19
  133. package/dist/lib/parse-mvt.d.ts +6 -9
  134. package/dist/lib/parse-mvt.d.ts.map +1 -1
  135. package/dist/lib/parse-mvt.js +148 -98
  136. package/dist/lib/types.d.ts +48 -7
  137. package/dist/lib/types.d.ts.map +1 -1
  138. package/dist/lib/types.js +2 -2
  139. package/dist/mvt-loader.d.ts.map +1 -1
  140. package/dist/mvt-loader.js +43 -22
  141. package/dist/mvt-worker.js +903 -829
  142. package/dist/workers/mvt-worker.js +5 -4
  143. package/package.json +7 -7
  144. package/src/helpers/mapbox-util-functions.ts +2 -2
  145. package/src/index.ts +7 -0
  146. package/src/lib/binary-vector-tile/vector-tile-feature.ts +6 -1
  147. package/src/lib/geojson-tiler/LICENSE +19 -0
  148. package/src/lib/geojson-tiler/clip.ts +248 -0
  149. package/src/lib/geojson-tiler/convert.ts +158 -0
  150. package/src/lib/geojson-tiler/feature.ts +45 -0
  151. package/src/lib/geojson-tiler/geojson-tiler.ts +281 -0
  152. package/src/lib/geojson-tiler/simplify.ts +77 -0
  153. package/src/lib/geojson-tiler/tile.ts +185 -0
  154. package/src/lib/geojson-tiler/transform.ts +55 -0
  155. package/src/lib/geojson-tiler/wrap.ts +108 -0
  156. package/src/lib/mapbox-vector-tile/vector-tile-feature.ts +4 -4
  157. package/src/lib/parse-mvt.ts +136 -93
  158. package/src/lib/types.ts +53 -7
  159. package/src/mvt-loader.ts +13 -9
  160. package/dist/bundle.js.map +0 -1
  161. package/dist/helpers/binary-util-functions.js.map +0 -1
  162. package/dist/helpers/mapbox-util-functions.js.map +0 -1
  163. package/dist/index.js.map +0 -1
  164. package/dist/lib/binary-vector-tile/vector-tile-feature.js.map +0 -1
  165. package/dist/lib/binary-vector-tile/vector-tile-layer.js.map +0 -1
  166. package/dist/lib/binary-vector-tile/vector-tile.js.map +0 -1
  167. package/dist/lib/mapbox-vector-tile/vector-tile-feature.js.map +0 -1
  168. package/dist/lib/mapbox-vector-tile/vector-tile-layer.js.map +0 -1
  169. package/dist/lib/mapbox-vector-tile/vector-tile.js.map +0 -1
  170. package/dist/lib/parse-mvt.js.map +0 -1
  171. package/dist/lib/types.js.map +0 -1
  172. package/dist/mvt-loader.js.map +0 -1
  173. package/dist/workers/mvt-worker.js.map +0 -1
  174. /package/dist/{lib → es5/lib}/binary-vector-tile/LICENSE.txt +0 -0
  175. /package/dist/{lib → es5/lib}/mapbox-vector-tile/LICENSE.txt +0 -0
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ // loaders.gl, MIT license
3
+ // Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.simplify = void 0;
6
+ /**
7
+ * Calculate simplification data using optimized Douglas-Peucker algorithm
8
+ *
9
+ * @param coords contiguous list of coordinates
10
+ * @param first first coord to simplify
11
+ * @param last last coord to simplify
12
+ * @param sqTolerance tolerance (square distance)
13
+ */
14
+ function simplify(coords, first, last, sqTolerance) {
15
+ let maxSqDist = sqTolerance;
16
+ const mid = (last - first) >> 1;
17
+ let minPosToMid = last - first;
18
+ let index;
19
+ const ax = coords[first];
20
+ const ay = coords[first + 1];
21
+ const bx = coords[last];
22
+ const by = coords[last + 1];
23
+ for (let i = first + 3; i < last; i += 3) {
24
+ const d = getSqSegDist(coords[i], coords[i + 1], ax, ay, bx, by);
25
+ if (d > maxSqDist) {
26
+ index = i;
27
+ maxSqDist = d;
28
+ }
29
+ else if (d === maxSqDist) {
30
+ // a workaround to ensure we choose a pivot close to the middle of the list,
31
+ // reducing recursion depth, for certain degenerate inputs
32
+ // https://github.com/mapbox/geojson-vt/issues/104
33
+ const posToMid = Math.abs(i - mid);
34
+ if (posToMid < minPosToMid) {
35
+ index = i;
36
+ minPosToMid = posToMid;
37
+ }
38
+ }
39
+ }
40
+ if (maxSqDist > sqTolerance) {
41
+ if (index - first > 3)
42
+ simplify(coords, first, index, sqTolerance);
43
+ coords[index + 2] = maxSqDist;
44
+ if (last - index > 3)
45
+ simplify(coords, index, last, sqTolerance);
46
+ }
47
+ }
48
+ exports.simplify = simplify;
49
+ /** square distance from a point to a segment */
50
+ // eslint-disable-next-line max-params
51
+ function getSqSegDist(px, py, x, y, bx, by) {
52
+ let dx = bx - x;
53
+ let dy = by - y;
54
+ if (dx !== 0 || dy !== 0) {
55
+ const t = ((px - x) * dx + (py - y) * dy) / (dx * dx + dy * dy);
56
+ if (t > 1) {
57
+ x = bx;
58
+ y = by;
59
+ }
60
+ else if (t > 0) {
61
+ x += dx * t;
62
+ y += dy * t;
63
+ }
64
+ }
65
+ dx = px - x;
66
+ dy = py - y;
67
+ return dx * dx + dy * dy;
68
+ }
@@ -0,0 +1,38 @@
1
+ export type GeoJSONTileFeature = {
2
+ type: any;
3
+ geometry: any;
4
+ id?: string;
5
+ tags?: string[];
6
+ minX: number;
7
+ maxX: number;
8
+ minY: number;
9
+ maxY: number;
10
+ };
11
+ export type GeoJSONTile = {
12
+ features: GeoJSONTileFeature[];
13
+ type?: number;
14
+ tags?: Record<string, string>;
15
+ x: number;
16
+ y: number;
17
+ z: number;
18
+ minX: number;
19
+ maxX: number;
20
+ minY: number;
21
+ maxY: number;
22
+ transformed: boolean;
23
+ numPoints: number;
24
+ numSimplified: number;
25
+ numFeatures: number;
26
+ source: any | null;
27
+ };
28
+ export type CreateTileOptions = {
29
+ maxZoom?: number;
30
+ tolerance: number;
31
+ extent: number;
32
+ lineMetrics: boolean;
33
+ };
34
+ /**
35
+ * Create a tile from features and tile index
36
+ */
37
+ export declare function createTile(features: any[], z: any, tx: any, ty: any, options: CreateTileOptions): GeoJSONTile;
38
+ //# sourceMappingURL=tile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tile.d.ts","sourceRoot":"","sources":["../../../src/lib/geojson-tiler/tile.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,GAAG,CAAC;IACV,QAAQ,EAAE,GAAG,CAAC;IAGd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAGhB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,EAAE,kBAAkB,EAAE,CAAC;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAG9B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IAGV,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IAEb,WAAW,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,GAAG,GAAG,IAAI,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF;;GAEG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,GAAG,EAAE,EAAE,CAAC,KAAA,EAAE,EAAE,KAAA,EAAE,EAAE,KAAA,EAAE,OAAO,EAAE,iBAAiB,GAAG,WAAW,CAqB9F"}
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ // loaders.gl, MIT license
3
+ // Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.createTile = void 0;
6
+ /**
7
+ * Create a tile from features and tile index
8
+ */
9
+ function createTile(features, z, tx, ty, options) {
10
+ const tolerance = z === options.maxZoom ? 0 : options.tolerance / ((1 << z) * options.extent);
11
+ const tile = {
12
+ features: [],
13
+ numPoints: 0,
14
+ numSimplified: 0,
15
+ numFeatures: features.length,
16
+ source: null,
17
+ x: tx,
18
+ y: ty,
19
+ z,
20
+ transformed: false,
21
+ minX: 2,
22
+ minY: 1,
23
+ maxX: -1,
24
+ maxY: 0
25
+ };
26
+ for (const feature of features) {
27
+ addFeature(tile, feature, tolerance, options);
28
+ }
29
+ return tile;
30
+ }
31
+ exports.createTile = createTile;
32
+ // eslint-disable-next-line complexity, max-statements
33
+ function addFeature(tile, feature, tolerance, options) {
34
+ const geom = feature.geometry;
35
+ const type = feature.type;
36
+ const simplified = [];
37
+ tile.minX = Math.min(tile.minX, feature.minX);
38
+ tile.minY = Math.min(tile.minY, feature.minY);
39
+ tile.maxX = Math.max(tile.maxX, feature.maxX);
40
+ tile.maxY = Math.max(tile.maxY, feature.maxY);
41
+ if (type === 'Point' || type === 'MultiPoint') {
42
+ for (let i = 0; i < geom.length; i += 3) {
43
+ simplified.push(geom[i], geom[i + 1]);
44
+ tile.numPoints++;
45
+ tile.numSimplified++;
46
+ }
47
+ }
48
+ else if (type === 'LineString') {
49
+ addLine(simplified, geom, tile, tolerance, false, false);
50
+ }
51
+ else if (type === 'MultiLineString' || type === 'Polygon') {
52
+ for (let i = 0; i < geom.length; i++) {
53
+ addLine(simplified, geom[i], tile, tolerance, type === 'Polygon', i === 0);
54
+ }
55
+ }
56
+ else if (type === 'MultiPolygon') {
57
+ for (let k = 0; k < geom.length; k++) {
58
+ const polygon = geom[k];
59
+ for (let i = 0; i < polygon.length; i++) {
60
+ addLine(simplified, polygon[i], tile, tolerance, true, i === 0);
61
+ }
62
+ }
63
+ }
64
+ if (simplified.length) {
65
+ let tags = feature.tags || null;
66
+ if (type === 'LineString' && options.lineMetrics) {
67
+ tags = {};
68
+ for (const key in feature.tags)
69
+ tags[key] = feature.tags[key];
70
+ // eslint-disable-next-line camelcase
71
+ tags.mapbox_clip_start = geom.start / geom.size;
72
+ // eslint-disable-next-line camelcase
73
+ tags.mapbox_clip_end = geom.end / geom.size;
74
+ }
75
+ // @ts-expect-error TODO - create sub type?
76
+ const tileFeature = {
77
+ geometry: simplified,
78
+ type: type === 'Polygon' || type === 'MultiPolygon'
79
+ ? 3
80
+ : type === 'LineString' || type === 'MultiLineString'
81
+ ? 2
82
+ : 1,
83
+ tags
84
+ };
85
+ if (feature.id !== null) {
86
+ tileFeature.id = feature.id;
87
+ }
88
+ tile.features.push(tileFeature);
89
+ }
90
+ }
91
+ // eslint-disable-next-line max-params, max-statements
92
+ function addLine(result, geom, tile, tolerance, isPolygon, isOuter) {
93
+ const sqTolerance = tolerance * tolerance;
94
+ if (tolerance > 0 && geom.size < (isPolygon ? sqTolerance : tolerance)) {
95
+ tile.numPoints += geom.length / 3;
96
+ return;
97
+ }
98
+ const ring = [];
99
+ for (let i = 0; i < geom.length; i += 3) {
100
+ if (tolerance === 0 || geom[i + 2] > sqTolerance) {
101
+ tile.numSimplified++;
102
+ ring.push(geom[i], geom[i + 1]);
103
+ }
104
+ tile.numPoints++;
105
+ }
106
+ if (isPolygon)
107
+ rewind(ring, isOuter);
108
+ result.push(ring);
109
+ }
110
+ function rewind(ring, clockwise) {
111
+ let area = 0;
112
+ for (let i = 0, j = ring.length - 2; i < ring.length; j = i, i += 2) {
113
+ area += (ring[i] - ring[j]) * (ring[i + 1] + ring[j + 1]);
114
+ }
115
+ if (area > 0 === clockwise) {
116
+ for (let i = 0, len = ring.length; i < len / 2; i += 2) {
117
+ const x = ring[i];
118
+ const y = ring[i + 1];
119
+ ring[i] = ring[len - 2 - i];
120
+ ring[i + 1] = ring[len - 1 - i];
121
+ ring[len - 2 - i] = x;
122
+ ring[len - 1 - i] = y;
123
+ }
124
+ }
125
+ }
@@ -0,0 +1,7 @@
1
+ import type { GeoJSONTile } from './tile';
2
+ /**
3
+ * Transforms the coordinates of each feature in the given tile from
4
+ * mercator-projected space into (extent x extent) tile space.
5
+ */
6
+ export declare function transformTile(tile: GeoJSONTile, extent: number): GeoJSONTile;
7
+ //# sourceMappingURL=transform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../../src/lib/geojson-tiler/transform.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,QAAQ,CAAC;AAExC;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,CAiC5E"}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ // loaders.gl, MIT license
3
+ // Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.transformTile = void 0;
6
+ /**
7
+ * Transforms the coordinates of each feature in the given tile from
8
+ * mercator-projected space into (extent x extent) tile space.
9
+ */
10
+ function transformTile(tile, extent) {
11
+ if (tile.transformed) {
12
+ return tile;
13
+ }
14
+ const z2 = 1 << tile.z;
15
+ const tx = tile.x;
16
+ const ty = tile.y;
17
+ for (const feature of tile.features) {
18
+ const geom = feature.geometry;
19
+ const type = feature.type;
20
+ feature.geometry = [];
21
+ if (type === 1) {
22
+ for (let j = 0; j < geom.length; j += 2) {
23
+ feature.geometry.push(transformPoint(geom[j], geom[j + 1], extent, z2, tx, ty));
24
+ }
25
+ }
26
+ else {
27
+ for (let j = 0; j < geom.length; j++) {
28
+ const ring = [];
29
+ for (let k = 0; k < geom[j].length; k += 2) {
30
+ ring.push(transformPoint(geom[j][k], geom[j][k + 1], extent, z2, tx, ty));
31
+ }
32
+ feature.geometry.push(ring);
33
+ }
34
+ }
35
+ }
36
+ tile.transformed = true;
37
+ return tile;
38
+ }
39
+ exports.transformTile = transformTile;
40
+ // eslint-disable-next-line max-params
41
+ function transformPoint(x, y, extent, z2, tx, ty) {
42
+ return [Math.round(extent * (x * z2 - tx)), Math.round(extent * (y * z2 - ty))];
43
+ }
@@ -0,0 +1,17 @@
1
+ import type { GeoJSONTileFeature } from './tile';
2
+ /**
3
+ * Options for wrap()
4
+ */
5
+ export type WrapOptions = {
6
+ buffer: number /** number of pixels of buffer for the tile */;
7
+ extent: number /** extent of each tile */;
8
+ lineMetrics: boolean;
9
+ };
10
+ /**
11
+ * Wrap across antemeridian, by clipping into two tiles, shifting the overflowing x coordinates
12
+ * @param features list of features to be wrapped
13
+ * @param options buffer and extent
14
+ * @returns
15
+ */
16
+ export declare function wrap(features: GeoJSONTileFeature[], options: WrapOptions): GeoJSONTileFeature[];
17
+ //# sourceMappingURL=wrap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrap.d.ts","sourceRoot":"","sources":["../../../src/lib/geojson-tiler/wrap.ts"],"names":[],"mappings":"AAGA,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"}
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ // loaders.gl, MIT license
3
+ // Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.wrap = void 0;
6
+ const clip_1 = require("./clip");
7
+ const feature_1 = require("./feature");
8
+ /**
9
+ * Wrap across antemeridian, by clipping into two tiles, shifting the overflowing x coordinates
10
+ * @param features list of features to be wrapped
11
+ * @param options buffer and extent
12
+ * @returns
13
+ */
14
+ function wrap(features, options) {
15
+ const buffer = options.buffer / options.extent;
16
+ let merged = features;
17
+ const left = (0, clip_1.clip)(features, 1, -1 - buffer, buffer, 0, -1, 2, options); // left world copy
18
+ const right = (0, clip_1.clip)(features, 1, 1 - buffer, 2 + buffer, 0, -1, 2, options); // right world copy
19
+ if (left || right) {
20
+ merged = (0, clip_1.clip)(features, 1, -buffer, 1 + buffer, 0, -1, 2, options) || []; // center world copy
21
+ if (left) {
22
+ merged = shiftFeatureCoords(left, 1).concat(merged); // merge left into center
23
+ }
24
+ if (right) {
25
+ merged = merged.concat(shiftFeatureCoords(right, -1)); // merge right into center
26
+ }
27
+ }
28
+ return merged;
29
+ }
30
+ exports.wrap = wrap;
31
+ /**
32
+ * Shift the x coordinates of a list of features
33
+ * @param features list of features to shift x coordinates for
34
+ * @param offset
35
+ * @returns
36
+ */
37
+ function shiftFeatureCoords(features, offset) {
38
+ const newFeatures = [];
39
+ for (let i = 0; i < features.length; i++) {
40
+ const feature = features[i];
41
+ const type = feature.type;
42
+ let newGeometry;
43
+ if (type === 'Point' || type === 'MultiPoint' || type === 'LineString') {
44
+ newGeometry = shiftCoords(feature.geometry, offset);
45
+ }
46
+ else if (type === 'MultiLineString' || type === 'Polygon') {
47
+ newGeometry = [];
48
+ for (const line of feature.geometry) {
49
+ newGeometry.push(shiftCoords(line, offset));
50
+ }
51
+ }
52
+ else if (type === 'MultiPolygon') {
53
+ newGeometry = [];
54
+ for (const polygon of feature.geometry) {
55
+ const newPolygon = [];
56
+ for (const line of polygon) {
57
+ // @ts-expect-error TODO
58
+ newPolygon.push(shiftCoords(line, offset));
59
+ }
60
+ newGeometry.push(newPolygon);
61
+ }
62
+ }
63
+ newFeatures.push((0, feature_1.createFeature)(feature.id, type, newGeometry, feature.tags));
64
+ }
65
+ return newFeatures;
66
+ }
67
+ class Points extends Array {
68
+ }
69
+ /**
70
+ * Shift the x coordinate of every point
71
+ * @param points
72
+ * @param offset
73
+ * @returns
74
+ */
75
+ function shiftCoords(points, offset) {
76
+ const newPoints = [];
77
+ newPoints.size = points.size;
78
+ if (points.start !== undefined) {
79
+ newPoints.start = points.start;
80
+ newPoints.end = points.end;
81
+ }
82
+ for (let i = 0; i < points.length; i += 3) {
83
+ newPoints.push(points[i] + offset, points[i + 1], points[i + 2]);
84
+ }
85
+ return newPoints;
86
+ }
@@ -1,5 +1,5 @@
1
1
  import Protobuf from 'pbf';
2
- import { MvtMapboxCoordinates, MvtMapboxGeometry } from '../types';
2
+ import { MVTMapboxCoordinates, MVTMapboxGeometry } from '../types';
3
3
  export default class VectorTileFeature {
4
4
  properties: {
5
5
  [x: string]: string | number | boolean | null;
@@ -13,15 +13,15 @@ export default class VectorTileFeature {
13
13
  _values: (string | number | boolean | null)[];
14
14
  static get types(): string[];
15
15
  constructor(pbf: Protobuf, end: number, extent: any, keys: string[], values: (string | number | boolean | null)[]);
16
- loadGeometry(): MvtMapboxGeometry;
16
+ loadGeometry(): MVTMapboxGeometry;
17
17
  bbox(): number[];
18
- _toGeoJSON(transform: any): MvtMapboxCoordinates;
18
+ _toGeoJSON(transform: any): MVTMapboxCoordinates;
19
19
  toGeoJSON(options: {
20
20
  x: number;
21
21
  y: number;
22
22
  z: number;
23
23
  } | ((data: number[], feature: {
24
24
  extent: any;
25
- }) => void)): MvtMapboxCoordinates;
25
+ }) => void)): MVTMapboxCoordinates;
26
26
  }
27
27
  //# sourceMappingURL=vector-tile-feature.d.ts.map