@loaders.gl/mvt 4.0.0-alpha.4 → 4.0.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 (198) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/bundle.js +2 -2
  4. package/dist/dist.min.js +3124 -0
  5. package/dist/es5/bundle.js +6 -0
  6. package/dist/es5/bundle.js.map +1 -0
  7. package/dist/es5/helpers/binary-util-functions.js +82 -0
  8. package/dist/es5/helpers/binary-util-functions.js.map +1 -0
  9. package/dist/es5/helpers/mapbox-util-functions.js +50 -0
  10. package/dist/es5/helpers/mapbox-util-functions.js.map +1 -0
  11. package/dist/es5/index.js +26 -0
  12. package/dist/es5/index.js.map +1 -0
  13. package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js +168 -0
  14. package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js.map +1 -0
  15. package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js +62 -0
  16. package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js.map +1 -0
  17. package/dist/es5/lib/binary-vector-tile/vector-tile.js +28 -0
  18. package/dist/es5/lib/binary-vector-tile/vector-tile.js.map +1 -0
  19. package/dist/es5/lib/geojson-tiler/LICENSE +19 -0
  20. package/dist/es5/lib/geojson-tiler/clip.js +237 -0
  21. package/dist/es5/lib/geojson-tiler/clip.js.map +1 -0
  22. package/dist/es5/lib/geojson-tiler/convert.js +161 -0
  23. package/dist/es5/lib/geojson-tiler/convert.js.map +1 -0
  24. package/dist/es5/lib/geojson-tiler/feature.js +62 -0
  25. package/dist/es5/lib/geojson-tiler/feature.js.map +1 -0
  26. package/dist/es5/lib/geojson-tiler/geojson-tiler.js +186 -0
  27. package/dist/es5/lib/geojson-tiler/geojson-tiler.js.map +1 -0
  28. package/dist/es5/lib/geojson-tiler/simplify.js +52 -0
  29. package/dist/es5/lib/geojson-tiler/simplify.js.map +1 -0
  30. package/dist/es5/lib/geojson-tiler/tile.js +121 -0
  31. package/dist/es5/lib/geojson-tiler/tile.js.map +1 -0
  32. package/dist/es5/lib/geojson-tiler/transform.js +50 -0
  33. package/dist/es5/lib/geojson-tiler/transform.js.map +1 -0
  34. package/dist/es5/lib/geojson-tiler/wrap.js +122 -0
  35. package/dist/es5/lib/geojson-tiler/wrap.js.map +1 -0
  36. package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js +184 -0
  37. package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -0
  38. package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js +62 -0
  39. package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js.map +1 -0
  40. package/dist/es5/lib/mapbox-vector-tile/vector-tile.js +28 -0
  41. package/dist/es5/lib/mapbox-vector-tile/vector-tile.js.map +1 -0
  42. package/dist/es5/lib/parse-mvt.js +143 -0
  43. package/dist/es5/lib/parse-mvt.js.map +1 -0
  44. package/dist/es5/lib/types.js +2 -0
  45. package/dist/es5/lib/types.js.map +1 -0
  46. package/dist/es5/mvt-loader.js +58 -0
  47. package/dist/es5/mvt-loader.js.map +1 -0
  48. package/dist/es5/workers/mvt-worker.js +6 -0
  49. package/dist/es5/workers/mvt-worker.js.map +1 -0
  50. package/dist/esm/bundle.js +4 -0
  51. package/dist/esm/bundle.js.map +1 -0
  52. package/dist/esm/helpers/binary-util-functions.js +73 -0
  53. package/dist/esm/helpers/binary-util-functions.js.map +1 -0
  54. package/dist/esm/helpers/mapbox-util-functions.js +41 -0
  55. package/dist/esm/helpers/mapbox-util-functions.js.map +1 -0
  56. package/dist/esm/index.js +3 -0
  57. package/dist/esm/index.js.map +1 -0
  58. package/dist/esm/lib/binary-vector-tile/LICENSE.txt +31 -0
  59. package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js +136 -0
  60. package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js.map +1 -0
  61. package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js +47 -0
  62. package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js.map +1 -0
  63. package/dist/esm/lib/binary-vector-tile/vector-tile.js +19 -0
  64. package/dist/esm/lib/binary-vector-tile/vector-tile.js.map +1 -0
  65. package/dist/esm/lib/geojson-tiler/LICENSE +19 -0
  66. package/dist/esm/lib/geojson-tiler/clip.js +173 -0
  67. package/dist/esm/lib/geojson-tiler/clip.js.map +1 -0
  68. package/dist/esm/lib/geojson-tiler/convert.js +116 -0
  69. package/dist/esm/lib/geojson-tiler/convert.js.map +1 -0
  70. package/dist/esm/lib/geojson-tiler/feature.js +35 -0
  71. package/dist/esm/lib/geojson-tiler/feature.js.map +1 -0
  72. package/dist/esm/lib/geojson-tiler/geojson-tiler.js +171 -0
  73. package/dist/esm/lib/geojson-tiler/geojson-tiler.js.map +1 -0
  74. package/dist/esm/lib/geojson-tiler/simplify.js +46 -0
  75. package/dist/esm/lib/geojson-tiler/simplify.js.map +1 -0
  76. package/dist/esm/lib/geojson-tiler/tile.js +103 -0
  77. package/dist/esm/lib/geojson-tiler/tile.js.map +1 -0
  78. package/dist/esm/lib/geojson-tiler/transform.js +32 -0
  79. package/dist/esm/lib/geojson-tiler/transform.js.map +1 -0
  80. package/dist/esm/lib/geojson-tiler/wrap.js +67 -0
  81. package/dist/esm/lib/geojson-tiler/wrap.js.map +1 -0
  82. package/dist/esm/lib/mapbox-vector-tile/LICENSE.txt +31 -0
  83. package/dist/esm/lib/mapbox-vector-tile/vector-tile-feature.js +163 -0
  84. package/dist/esm/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -0
  85. package/dist/esm/lib/mapbox-vector-tile/vector-tile-layer.js +47 -0
  86. package/dist/esm/lib/mapbox-vector-tile/vector-tile-layer.js.map +1 -0
  87. package/dist/esm/lib/mapbox-vector-tile/vector-tile.js +19 -0
  88. package/dist/esm/lib/mapbox-vector-tile/vector-tile.js.map +1 -0
  89. package/dist/esm/lib/parse-mvt.js +138 -0
  90. package/dist/esm/lib/parse-mvt.js.map +1 -0
  91. package/dist/esm/lib/types.js +2 -0
  92. package/dist/esm/lib/types.js.map +1 -0
  93. package/dist/esm/mvt-loader.js +29 -0
  94. package/dist/esm/mvt-loader.js.map +1 -0
  95. package/dist/esm/workers/mvt-worker.js +4 -0
  96. package/dist/esm/workers/mvt-worker.js.map +1 -0
  97. package/dist/helpers/binary-util-functions.d.ts +35 -0
  98. package/dist/helpers/binary-util-functions.d.ts.map +1 -0
  99. package/dist/helpers/binary-util-functions.js +111 -74
  100. package/dist/helpers/mapbox-util-functions.d.ts +29 -0
  101. package/dist/helpers/mapbox-util-functions.d.ts.map +1 -0
  102. package/dist/helpers/mapbox-util-functions.js +78 -45
  103. package/dist/index.d.ts +4 -0
  104. package/dist/index.d.ts.map +1 -0
  105. package/dist/index.js +9 -2
  106. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts +41 -0
  107. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +1 -0
  108. package/dist/lib/binary-vector-tile/vector-tile-feature.js +142 -142
  109. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts +23 -0
  110. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts.map +1 -0
  111. package/dist/lib/binary-vector-tile/vector-tile-layer.js +85 -58
  112. package/dist/lib/binary-vector-tile/vector-tile.d.ts +9 -0
  113. package/dist/lib/binary-vector-tile/vector-tile.d.ts.map +1 -0
  114. package/dist/lib/binary-vector-tile/vector-tile.js +25 -19
  115. package/dist/lib/geojson-tiler/clip.d.ts +16 -0
  116. package/dist/lib/geojson-tiler/clip.d.ts.map +1 -0
  117. package/dist/lib/geojson-tiler/clip.js +209 -0
  118. package/dist/lib/geojson-tiler/convert.d.ts +10 -0
  119. package/dist/lib/geojson-tiler/convert.d.ts.map +1 -0
  120. package/dist/lib/geojson-tiler/convert.js +134 -0
  121. package/dist/lib/geojson-tiler/feature.d.ts +3 -0
  122. package/dist/lib/geojson-tiler/feature.d.ts.map +1 -0
  123. package/dist/lib/geojson-tiler/feature.js +46 -0
  124. package/dist/lib/geojson-tiler/geojson-tiler.d.ts +44 -0
  125. package/dist/lib/geojson-tiler/geojson-tiler.d.ts.map +1 -0
  126. package/dist/lib/geojson-tiler/geojson-tiler.js +210 -0
  127. package/dist/lib/geojson-tiler/simplify.d.ts +10 -0
  128. package/dist/lib/geojson-tiler/simplify.d.ts.map +1 -0
  129. package/dist/lib/geojson-tiler/simplify.js +68 -0
  130. package/dist/lib/geojson-tiler/tile.d.ts +38 -0
  131. package/dist/lib/geojson-tiler/tile.d.ts.map +1 -0
  132. package/dist/lib/geojson-tiler/tile.js +125 -0
  133. package/dist/lib/geojson-tiler/transform.d.ts +7 -0
  134. package/dist/lib/geojson-tiler/transform.d.ts.map +1 -0
  135. package/dist/lib/geojson-tiler/transform.js +43 -0
  136. package/dist/lib/geojson-tiler/wrap.d.ts +17 -0
  137. package/dist/lib/geojson-tiler/wrap.d.ts.map +1 -0
  138. package/dist/lib/geojson-tiler/wrap.js +86 -0
  139. package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts +27 -0
  140. package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts.map +1 -0
  141. package/dist/lib/mapbox-vector-tile/vector-tile-feature.js +161 -193
  142. package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts +20 -0
  143. package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts.map +1 -0
  144. package/dist/lib/mapbox-vector-tile/vector-tile-layer.js +83 -58
  145. package/dist/lib/mapbox-vector-tile/vector-tile.d.ts +9 -0
  146. package/dist/lib/mapbox-vector-tile/vector-tile.d.ts.map +1 -0
  147. package/dist/lib/mapbox-vector-tile/vector-tile.js +25 -19
  148. package/dist/lib/parse-mvt.d.ts +14 -0
  149. package/dist/lib/parse-mvt.d.ts.map +1 -0
  150. package/dist/lib/parse-mvt.js +149 -98
  151. package/dist/lib/types.d.ts +69 -0
  152. package/dist/lib/types.d.ts.map +1 -0
  153. package/dist/lib/types.js +2 -2
  154. package/dist/mvt-loader.d.ts +10 -0
  155. package/dist/mvt-loader.d.ts.map +1 -0
  156. package/dist/mvt-loader.js +43 -22
  157. package/dist/mvt-worker.js +845 -766
  158. package/dist/workers/mvt-worker.d.ts +2 -0
  159. package/dist/workers/mvt-worker.d.ts.map +1 -0
  160. package/dist/workers/mvt-worker.js +5 -4
  161. package/package.json +10 -9
  162. package/src/helpers/binary-util-functions.ts +9 -7
  163. package/src/helpers/mapbox-util-functions.ts +2 -2
  164. package/src/index.ts +7 -0
  165. package/src/lib/binary-vector-tile/vector-tile-feature.ts +42 -45
  166. package/src/lib/binary-vector-tile/vector-tile-layer.ts +4 -4
  167. package/src/lib/geojson-tiler/LICENSE +19 -0
  168. package/src/lib/geojson-tiler/clip.ts +248 -0
  169. package/src/lib/geojson-tiler/convert.ts +158 -0
  170. package/src/lib/geojson-tiler/feature.ts +45 -0
  171. package/src/lib/geojson-tiler/geojson-tiler.ts +281 -0
  172. package/src/lib/geojson-tiler/simplify.ts +77 -0
  173. package/src/lib/geojson-tiler/tile.ts +185 -0
  174. package/src/lib/geojson-tiler/transform.ts +55 -0
  175. package/src/lib/geojson-tiler/wrap.ts +108 -0
  176. package/src/lib/mapbox-vector-tile/vector-tile-feature.ts +4 -4
  177. package/src/lib/parse-mvt.ts +138 -93
  178. package/src/lib/types.ts +49 -72
  179. package/src/mvt-loader.ts +13 -9
  180. package/dist/bundle.js.map +0 -1
  181. package/dist/helpers/binary-util-functions.js.map +0 -1
  182. package/dist/helpers/mapbox-util-functions.js.map +0 -1
  183. package/dist/index.js.map +0 -1
  184. package/dist/lib/binary-vector-tile/features-to-binary.js +0 -327
  185. package/dist/lib/binary-vector-tile/features-to-binary.js.map +0 -1
  186. package/dist/lib/binary-vector-tile/vector-tile-feature.js.map +0 -1
  187. package/dist/lib/binary-vector-tile/vector-tile-layer.js.map +0 -1
  188. package/dist/lib/binary-vector-tile/vector-tile.js.map +0 -1
  189. package/dist/lib/mapbox-vector-tile/vector-tile-feature.js.map +0 -1
  190. package/dist/lib/mapbox-vector-tile/vector-tile-layer.js.map +0 -1
  191. package/dist/lib/mapbox-vector-tile/vector-tile.js.map +0 -1
  192. package/dist/lib/parse-mvt.js.map +0 -1
  193. package/dist/lib/types.js.map +0 -1
  194. package/dist/mvt-loader.js.map +0 -1
  195. package/dist/workers/mvt-worker.js.map +0 -1
  196. package/src/lib/binary-vector-tile/features-to-binary.ts +0 -518
  197. /package/dist/{lib → es5/lib}/binary-vector-tile/LICENSE.txt +0 -0
  198. /package/dist/{lib → es5/lib}/mapbox-vector-tile/LICENSE.txt +0 -0
@@ -1,5 +1,9 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import { classifyRings, project, readFeature } from '../../helpers/binary-util-functions';
1
+ "use strict";
2
+ // This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.TEST_EXPORTS = void 0;
5
+ const binary_util_functions_1 = require("../../helpers/binary-util-functions");
6
+ // Reduce GC by reusing variables
3
7
  let endPos;
4
8
  let cmd;
5
9
  let cmdLen;
@@ -7,150 +11,146 @@ let length;
7
11
  let x;
8
12
  let y;
9
13
  let i;
10
- export const TEST_EXPORTS = {
11
- classifyRings
14
+ exports.TEST_EXPORTS = {
15
+ classifyRings: binary_util_functions_1.classifyRings
12
16
  };
13
- export default class VectorTileFeature {
14
- static get types() {
15
- return ['Unknown', 'Point', 'LineString', 'Polygon'];
16
- }
17
-
18
- constructor(pbf, end, extent, keys, values, firstPassData) {
19
- _defineProperty(this, "properties", void 0);
20
-
21
- _defineProperty(this, "extent", void 0);
22
-
23
- _defineProperty(this, "type", void 0);
24
-
25
- _defineProperty(this, "id", void 0);
26
-
27
- _defineProperty(this, "_pbf", void 0);
28
-
29
- _defineProperty(this, "_geometry", void 0);
30
-
31
- _defineProperty(this, "_keys", void 0);
32
-
33
- _defineProperty(this, "_values", void 0);
34
-
35
- _defineProperty(this, "_firstPassData", void 0);
36
-
37
- this.properties = {};
38
- this.extent = extent;
39
- this.type = 0;
40
- this.id = null;
41
- this._pbf = pbf;
42
- this._geometry = -1;
43
- this._keys = keys;
44
- this._values = values;
45
- this._firstPassData = firstPassData;
46
- pbf.readFields(readFeature, this, end);
47
- }
48
-
49
- loadGeometry() {
50
- const pbf = this._pbf;
51
- pbf.pos = this._geometry;
52
- endPos = pbf.readVarint() + pbf.pos;
53
- cmd = 1;
54
- length = 0;
55
- x = 0;
56
- y = 0;
57
- i = 0;
58
- const lines = [];
59
- const data = [];
60
-
61
- while (pbf.pos < endPos) {
62
- if (length <= 0) {
63
- cmdLen = pbf.readVarint();
64
- cmd = cmdLen & 0x7;
65
- length = cmdLen >> 3;
66
- }
67
-
68
- length--;
69
-
70
- if (cmd === 1 || cmd === 2) {
71
- x += pbf.readSVarint();
72
- y += pbf.readSVarint();
73
-
74
- if (cmd === 1) {
75
- lines.push(i);
76
- }
77
-
78
- data.push(x, y);
79
- i += 2;
80
- } else if (cmd === 7) {
81
- if (i > 0) {
82
- const start = lines[lines.length - 1];
83
- data.push(data[start], data[start + 1]);
84
- i += 2;
85
- }
86
- } else {
87
- throw new Error("unknown command ".concat(cmd));
88
- }
17
+ class VectorTileFeature {
18
+ // eslint-disable-next-line max-params
19
+ constructor(pbf, end, extent, keys, values, geometryInfo) {
20
+ // Public
21
+ this.properties = {};
22
+ this.extent = extent;
23
+ this.type = 0;
24
+ this.id = null;
25
+ // Private
26
+ this._pbf = pbf;
27
+ this._geometry = -1;
28
+ this._keys = keys;
29
+ this._values = values;
30
+ this._geometryInfo = geometryInfo;
31
+ pbf.readFields(binary_util_functions_1.readFeature, this, end);
89
32
  }
90
-
91
- return {
92
- data,
93
- lines
94
- };
95
- }
96
-
97
- _toBinaryCoordinates(transform) {
98
- let geom = this.loadGeometry();
99
- transform(geom.data, this);
100
- const coordLength = 2;
101
-
102
- switch (this.type) {
103
- case 1:
104
- this._firstPassData.pointFeaturesCount++;
105
- this._firstPassData.pointPositionsCount += geom.lines.length;
106
- break;
107
-
108
- case 2:
109
- this._firstPassData.lineFeaturesCount++;
110
- this._firstPassData.linePathsCount += geom.lines.length;
111
- this._firstPassData.linePositionsCount += geom.data.length / coordLength;
112
- break;
113
-
114
- case 3:
115
- const classified = classifyRings(geom);
116
- this._firstPassData.polygonFeaturesCount++;
117
- this._firstPassData.polygonObjectsCount += classified.lines.length;
118
-
119
- for (const lines of classified.lines) {
120
- this._firstPassData.polygonRingsCount += lines.length;
33
+ // eslint-disable-next-line complexity, max-statements
34
+ loadGeometry() {
35
+ const pbf = this._pbf;
36
+ pbf.pos = this._geometry;
37
+ endPos = pbf.readVarint() + pbf.pos;
38
+ cmd = 1;
39
+ length = 0;
40
+ x = 0;
41
+ y = 0;
42
+ i = 0;
43
+ // Note: I attempted to replace the `data` array with a
44
+ // Float32Array, but performance was worse, both using
45
+ // `set()` and direct index access. Also, we cannot
46
+ // know how large the buffer should be, so it would
47
+ // increase memory usage
48
+ const indices = []; // Indices where geometries start
49
+ const data = []; // Flat array of coordinate data
50
+ while (pbf.pos < endPos) {
51
+ if (length <= 0) {
52
+ cmdLen = pbf.readVarint();
53
+ cmd = cmdLen & 0x7;
54
+ length = cmdLen >> 3;
55
+ }
56
+ length--;
57
+ if (cmd === 1 || cmd === 2) {
58
+ x += pbf.readSVarint();
59
+ y += pbf.readSVarint();
60
+ if (cmd === 1) {
61
+ // New line
62
+ indices.push(i);
63
+ }
64
+ data.push(x, y);
65
+ i += 2;
66
+ }
67
+ else if (cmd === 7) {
68
+ // Workaround for https://github.com/mapbox/mapnik-vector-tile/issues/90
69
+ if (i > 0) {
70
+ const start = indices[indices.length - 1]; // start index of polygon
71
+ data.push(data[start], data[start + 1]); // closePolygon
72
+ i += 2;
73
+ }
74
+ }
75
+ else {
76
+ throw new Error(`unknown command ${cmd}`);
77
+ }
121
78
  }
122
-
123
- this._firstPassData.polygonPositionsCount += classified.data.length / coordLength;
124
- geom = classified;
125
- break;
126
- }
127
-
128
- geom.type = VectorTileFeature.types[this.type];
129
-
130
- if (geom.lines.length > 1) {
131
- geom.type = "Multi".concat(geom.type);
79
+ return { data, indices };
132
80
  }
133
-
134
- const result = {
135
- type: 'Feature',
136
- geometry: geom,
137
- properties: this.properties
138
- };
139
-
140
- if (this.id !== null) {
141
- result.id = this.id;
81
+ /**
82
+ *
83
+ * @param transform
84
+ * @returns result
85
+ */
86
+ _toBinaryCoordinates(transform) {
87
+ // Expands the protobuf data to an intermediate Flat GeoJSON
88
+ // data format, which maps closely to the binary data buffers.
89
+ // It is similar to GeoJSON, but rather than storing the coordinates
90
+ // in multidimensional arrays, we have a 1D `data` with all the
91
+ // coordinates, and then index into this using the `indices`
92
+ // parameter, e.g.
93
+ //
94
+ // geometry: {
95
+ // type: 'Point', data: [1,2], indices: [0]
96
+ // }
97
+ // geometry: {
98
+ // type: 'LineString', data: [1,2,3,4,...], indices: [0]
99
+ // }
100
+ // geometry: {
101
+ // type: 'Polygon', data: [1,2,3,4,...], indices: [[0, 2]]
102
+ // }
103
+ // Thus the indices member lets us look up the relevant range
104
+ // from the data array.
105
+ // The Multi* versions of the above types share the same data
106
+ // structure, just with multiple elements in the indices array
107
+ const geom = this.loadGeometry();
108
+ let geometry;
109
+ // Apply the supplied transformation to data
110
+ transform(geom.data, this);
111
+ const coordLength = 2;
112
+ // eslint-disable-next-line default-case
113
+ switch (this.type) {
114
+ case 1: // Point
115
+ this._geometryInfo.pointFeaturesCount++;
116
+ this._geometryInfo.pointPositionsCount += geom.indices.length;
117
+ geometry = { type: 'Point', ...geom };
118
+ break;
119
+ case 2: // LineString
120
+ this._geometryInfo.lineFeaturesCount++;
121
+ this._geometryInfo.linePathsCount += geom.indices.length;
122
+ this._geometryInfo.linePositionsCount += geom.data.length / coordLength;
123
+ geometry = { type: 'LineString', ...geom };
124
+ break;
125
+ case 3: // Polygon
126
+ geometry = (0, binary_util_functions_1.classifyRings)(geom);
127
+ // Unlike Point & LineString geom.indices is a 2D array, thanks
128
+ // to the classifyRings method
129
+ this._geometryInfo.polygonFeaturesCount++;
130
+ this._geometryInfo.polygonObjectsCount += geometry.indices.length;
131
+ for (const indices of geometry.indices) {
132
+ this._geometryInfo.polygonRingsCount += indices.length;
133
+ }
134
+ this._geometryInfo.polygonPositionsCount += geometry.data.length / coordLength;
135
+ break;
136
+ default:
137
+ throw new Error(`Invalid geometry type: ${this.type}`);
138
+ }
139
+ const result = { type: 'Feature', geometry, properties: this.properties };
140
+ if (this.id !== null) {
141
+ result.id = this.id;
142
+ }
143
+ return result;
142
144
  }
143
-
144
- return result;
145
- }
146
-
147
- toBinaryCoordinates(options) {
148
- if (typeof options === 'function') {
149
- return this._toBinaryCoordinates(options);
145
+ toBinaryCoordinates(options) {
146
+ if (typeof options === 'function') {
147
+ return this._toBinaryCoordinates(options);
148
+ }
149
+ const { x, y, z } = options;
150
+ const size = this.extent * Math.pow(2, z);
151
+ const x0 = this.extent * x;
152
+ const y0 = this.extent * y;
153
+ return this._toBinaryCoordinates((data) => (0, binary_util_functions_1.project)(data, x0, y0, size));
150
154
  }
151
-
152
- return this._toBinaryCoordinates(project);
153
- }
154
-
155
155
  }
156
- //# sourceMappingURL=vector-tile-feature.js.map
156
+ exports.default = VectorTileFeature;
@@ -0,0 +1,23 @@
1
+ import VectorTileFeature from './vector-tile-feature';
2
+ import Protobuf from 'pbf';
3
+ import { GeojsonGeometryInfo } from '@loaders.gl/schema';
4
+ export default class VectorTileLayer {
5
+ version: number;
6
+ name: string;
7
+ extent: number;
8
+ length: number;
9
+ _pbf: Protobuf;
10
+ _keys: string[];
11
+ _values: (string | number | boolean | null)[];
12
+ _features: number[];
13
+ constructor(pbf: Protobuf, end: number);
14
+ /**
15
+ * return feature `i` from this layer as a `VectorTileFeature`
16
+ *
17
+ * @param index
18
+ * @param geometryInfo
19
+ * @returns {VectorTileFeature}
20
+ */
21
+ feature(i: number, geometryInfo: GeojsonGeometryInfo): VectorTileFeature;
22
+ }
23
+ //# sourceMappingURL=vector-tile-layer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vector-tile-layer.d.ts","sourceRoot":"","sources":["../../../src/lib/binary-vector-tile/vector-tile-layer.ts"],"names":[],"mappings":"AAGA,OAAO,iBAAiB,MAAM,uBAAuB,CAAC;AACtD,OAAO,QAAQ,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAC,mBAAmB,EAAC,MAAM,oBAAoB,CAAC;AAEvD,MAAM,CAAC,OAAO,OAAO,eAAe;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,EAAE,CAAC;IAC9C,SAAS,EAAE,MAAM,EAAE,CAAC;gBACR,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM;IAkBtC;;;;;;OAMG;IACH,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,mBAAmB,GAAG,iBAAiB;CAiBzE"}
@@ -1,64 +1,91 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import VectorTileFeature from './vector-tile-feature';
3
- export default class VectorTileLayer {
4
- constructor(pbf, end) {
5
- _defineProperty(this, "version", void 0);
6
-
7
- _defineProperty(this, "name", void 0);
8
-
9
- _defineProperty(this, "extent", void 0);
10
-
11
- _defineProperty(this, "length", void 0);
12
-
13
- _defineProperty(this, "_pbf", void 0);
14
-
15
- _defineProperty(this, "_keys", void 0);
16
-
17
- _defineProperty(this, "_values", void 0);
18
-
19
- _defineProperty(this, "_features", void 0);
20
-
21
- this.version = 1;
22
- this.name = '';
23
- this.extent = 4096;
24
- this.length = 0;
25
- this._pbf = pbf;
26
- this._keys = [];
27
- this._values = [];
28
- this._features = [];
29
- pbf.readFields(readLayer, this, end);
30
- this.length = this._features.length;
31
- }
32
-
33
- feature(i, firstPassData) {
34
- if (i < 0 || i >= this._features.length) {
35
- throw new Error('feature index out of bounds');
1
+ "use strict";
2
+ /* eslint-disable indent */
3
+ // This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.
4
+ var __importDefault = (this && this.__importDefault) || function (mod) {
5
+ return (mod && mod.__esModule) ? mod : { "default": mod };
6
+ };
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ const vector_tile_feature_1 = __importDefault(require("./vector-tile-feature"));
9
+ class VectorTileLayer {
10
+ constructor(pbf, end) {
11
+ // Public
12
+ this.version = 1;
13
+ this.name = '';
14
+ this.extent = 4096;
15
+ this.length = 0;
16
+ // Private
17
+ this._pbf = pbf;
18
+ this._keys = [];
19
+ this._values = [];
20
+ this._features = [];
21
+ pbf.readFields(readLayer, this, end);
22
+ this.length = this._features.length;
23
+ }
24
+ /**
25
+ * return feature `i` from this layer as a `VectorTileFeature`
26
+ *
27
+ * @param index
28
+ * @param geometryInfo
29
+ * @returns {VectorTileFeature}
30
+ */
31
+ feature(i, geometryInfo) {
32
+ if (i < 0 || i >= this._features.length) {
33
+ throw new Error('feature index out of bounds');
34
+ }
35
+ this._pbf.pos = this._features[i];
36
+ const end = this._pbf.readVarint() + this._pbf.pos;
37
+ return new vector_tile_feature_1.default(this._pbf, end, this.extent, this._keys, this._values, geometryInfo);
36
38
  }
37
-
38
- this._pbf.pos = this._features[i];
39
-
40
- const end = this._pbf.readVarint() + this._pbf.pos;
41
-
42
- return new VectorTileFeature(this._pbf, end, this.extent, this._keys, this._values, firstPassData);
43
- }
44
-
45
39
  }
46
-
40
+ exports.default = VectorTileLayer;
41
+ /**
42
+ *
43
+ * @param tag
44
+ * @param layer
45
+ * @param pbf
46
+ */
47
47
  function readLayer(tag, layer, pbf) {
48
- if (layer && pbf) {
49
- if (tag === 15) layer.version = pbf.readVarint();else if (tag === 1) layer.name = pbf.readString();else if (tag === 5) layer.extent = pbf.readVarint();else if (tag === 2) layer._features.push(pbf.pos);else if (tag === 3) layer._keys.push(pbf.readString());else if (tag === 4) layer._values.push(readValueMessage(pbf));
50
- }
48
+ if (layer && pbf) {
49
+ if (tag === 15)
50
+ layer.version = pbf.readVarint();
51
+ else if (tag === 1)
52
+ layer.name = pbf.readString();
53
+ else if (tag === 5)
54
+ layer.extent = pbf.readVarint();
55
+ else if (tag === 2)
56
+ layer._features.push(pbf.pos);
57
+ else if (tag === 3)
58
+ layer._keys.push(pbf.readString());
59
+ else if (tag === 4)
60
+ layer._values.push(readValueMessage(pbf));
61
+ }
51
62
  }
52
-
63
+ /**
64
+ *
65
+ * @param pbf
66
+ * @returns value
67
+ */
53
68
  function readValueMessage(pbf) {
54
- let value = null;
55
- const end = pbf.readVarint() + pbf.pos;
56
-
57
- while (pbf.pos < end) {
58
- const tag = pbf.readVarint() >> 3;
59
- value = tag === 1 ? pbf.readString() : tag === 2 ? pbf.readFloat() : tag === 3 ? pbf.readDouble() : tag === 4 ? pbf.readVarint64() : tag === 5 ? pbf.readVarint() : tag === 6 ? pbf.readSVarint() : tag === 7 ? pbf.readBoolean() : null;
60
- }
61
-
62
- return value;
69
+ let value = null;
70
+ const end = pbf.readVarint() + pbf.pos;
71
+ while (pbf.pos < end) {
72
+ const tag = pbf.readVarint() >> 3;
73
+ value =
74
+ tag === 1
75
+ ? pbf.readString()
76
+ : tag === 2
77
+ ? pbf.readFloat()
78
+ : tag === 3
79
+ ? pbf.readDouble()
80
+ : tag === 4
81
+ ? pbf.readVarint64()
82
+ : tag === 5
83
+ ? pbf.readVarint()
84
+ : tag === 6
85
+ ? pbf.readSVarint()
86
+ : tag === 7
87
+ ? pbf.readBoolean()
88
+ : null;
89
+ }
90
+ return value;
63
91
  }
64
- //# sourceMappingURL=vector-tile-layer.js.map
@@ -0,0 +1,9 @@
1
+ import VectorTileLayer from './vector-tile-layer';
2
+ import Protobuf from 'pbf';
3
+ export default class VectorTile {
4
+ layers: {
5
+ [x: string]: VectorTileLayer;
6
+ };
7
+ constructor(pbf: Protobuf, end?: number);
8
+ }
9
+ //# sourceMappingURL=vector-tile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vector-tile.d.ts","sourceRoot":"","sources":["../../../src/lib/binary-vector-tile/vector-tile.ts"],"names":[],"mappings":"AAEA,OAAO,eAAe,MAAM,qBAAqB,CAAC;AAClD,OAAO,QAAQ,MAAM,KAAK,CAAC;AAE3B,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,MAAM,EAAE;QAAC,CAAC,CAAC,EAAE,MAAM,GAAG,eAAe,CAAA;KAAC,CAAC;gBAC3B,GAAG,EAAE,QAAQ,EAAE,GAAG,CAAC,EAAE,MAAM;CAGxC"}
@@ -1,23 +1,29 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import VectorTileLayer from './vector-tile-layer';
3
- export default class VectorTile {
4
- constructor(pbf, end) {
5
- _defineProperty(this, "layers", void 0);
6
-
7
- this.layers = pbf.readFields(readTile, {}, end);
8
- }
9
-
1
+ "use strict";
2
+ // This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const vector_tile_layer_1 = __importDefault(require("./vector-tile-layer"));
8
+ class VectorTile {
9
+ constructor(pbf, end) {
10
+ this.layers = pbf.readFields(readTile, {}, end);
11
+ }
10
12
  }
11
-
13
+ exports.default = VectorTile;
14
+ /**
15
+ *
16
+ * @param tag
17
+ * @param layers
18
+ * @param pbf
19
+ */
12
20
  function readTile(tag, layers, pbf) {
13
- if (tag === 3) {
14
- if (pbf) {
15
- const layer = new VectorTileLayer(pbf, pbf.readVarint() + pbf.pos);
16
-
17
- if (layer.length && layers) {
18
- layers[layer.name] = layer;
19
- }
21
+ if (tag === 3) {
22
+ if (pbf) {
23
+ const layer = new vector_tile_layer_1.default(pbf, pbf.readVarint() + pbf.pos);
24
+ if (layer.length && layers) {
25
+ layers[layer.name] = layer;
26
+ }
27
+ }
20
28
  }
21
- }
22
29
  }
23
- //# sourceMappingURL=vector-tile.js.map
@@ -0,0 +1,16 @@
1
+ import type { GeoJSONTileFeature } from './tile';
2
+ /**
3
+ * Clip features between two vertical or horizontal axis-parallel lines:
4
+ * | |
5
+ * ___|___ | /
6
+ * / | \____|____/
7
+ * | |
8
+ *
9
+ * @param k1 and k2 are the line coordinates
10
+ * @param axis: 0 for x, 1 for y
11
+ * @param minAll and maxAll: minimum and maximum coordinate value for all features
12
+ */
13
+ export declare function clip(features: GeoJSONTileFeature[], scale: number, k1: number, k2: number, axis: any, minAll: number, maxAll: number, options: {
14
+ lineMetrics: boolean;
15
+ }): GeoJSONTileFeature[] | null;
16
+ //# sourceMappingURL=clip.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clip.d.ts","sourceRoot":"","sources":["../../../src/lib/geojson-tiler/clip.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,QAAQ,CAAC;AAK/C;;;;;;;;;;GAUG;AAEH,wBAAgB,IAAI,CAClB,QAAQ,EAAE,kBAAkB,EAAE,EAC9B,KAAK,EAAE,MAAM,EACb,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,IAAI,KAAA,EACJ,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,OAAO,EAAE;IAAC,WAAW,EAAE,OAAO,CAAA;CAAC,GAC9B,kBAAkB,EAAE,GAAG,IAAI,CA4E7B"}