@loaders.gl/mvt 4.2.1 → 4.3.0-alpha.2

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 (120) hide show
  1. package/dist/dist.dev.js +1784 -847
  2. package/dist/dist.min.js +1 -1
  3. package/dist/index.cjs +713 -640
  4. package/dist/index.cjs.map +4 -4
  5. package/dist/index.d.ts +2 -2
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +1 -1
  8. package/dist/lib/parse-mvt.d.ts +2 -1
  9. package/dist/lib/parse-mvt.d.ts.map +1 -1
  10. package/dist/lib/parse-mvt.js +15 -45
  11. package/dist/lib/parse-tilejson.d.ts +4 -4
  12. package/dist/lib/parse-tilejson.d.ts.map +1 -1
  13. package/dist/lib/types.d.ts +1 -39
  14. package/dist/lib/types.d.ts.map +1 -1
  15. package/dist/lib/utils/geometry-utils.d.ts +83 -0
  16. package/dist/lib/utils/geometry-utils.d.ts.map +1 -0
  17. package/dist/lib/utils/geometry-utils.js +206 -0
  18. package/dist/lib/vector-tile/vector-tile-feature.d.ts +72 -0
  19. package/dist/lib/vector-tile/vector-tile-feature.d.ts.map +1 -0
  20. package/dist/lib/vector-tile/vector-tile-feature.js +342 -0
  21. package/dist/lib/{mapbox-vector-tile → vector-tile}/vector-tile-layer.d.ts +10 -1
  22. package/dist/lib/vector-tile/vector-tile-layer.d.ts.map +1 -0
  23. package/dist/lib/{mapbox-vector-tile → vector-tile}/vector-tile-layer.js +16 -1
  24. package/dist/lib/vector-tile/vector-tile.d.ts.map +1 -0
  25. package/dist/lib/{geojson-tiler → vector-tiler}/clip.d.ts +3 -3
  26. package/dist/lib/vector-tiler/clip.d.ts.map +1 -0
  27. package/dist/lib/vector-tiler/convert.d.ts +18 -0
  28. package/dist/lib/vector-tiler/convert.d.ts.map +1 -0
  29. package/dist/lib/{geojson-tiler → vector-tiler}/convert.js +8 -1
  30. package/dist/lib/vector-tiler/feature.d.ts +3 -0
  31. package/dist/lib/vector-tiler/feature.d.ts.map +1 -0
  32. package/dist/lib/vector-tiler/simplify.d.ts.map +1 -0
  33. package/dist/lib/{geojson-tiler → vector-tiler}/tile.d.ts +4 -4
  34. package/dist/lib/vector-tiler/tile.d.ts.map +1 -0
  35. package/dist/lib/vector-tiler/transform.d.ts +7 -0
  36. package/dist/lib/vector-tiler/transform.d.ts.map +1 -0
  37. package/dist/lib/{geojson-tiler → vector-tiler}/wrap.d.ts +2 -2
  38. package/dist/lib/vector-tiler/wrap.d.ts.map +1 -0
  39. package/dist/mvt-loader.d.ts +19 -8
  40. package/dist/mvt-loader.d.ts.map +1 -1
  41. package/dist/mvt-loader.js +3 -2
  42. package/dist/mvt-source.d.ts +4 -4
  43. package/dist/mvt-source.d.ts.map +1 -1
  44. package/dist/mvt-source.js +7 -7
  45. package/dist/mvt-worker.js +1244 -762
  46. package/dist/table-tile-source.d.ts +118 -0
  47. package/dist/table-tile-source.d.ts.map +1 -0
  48. package/dist/table-tile-source.js +370 -0
  49. package/dist/tilejson-loader.js +1 -1
  50. package/package.json +7 -6
  51. package/src/index.ts +3 -3
  52. package/src/lib/parse-mvt.ts +28 -66
  53. package/src/lib/parse-tilejson.ts +5 -5
  54. package/src/lib/types.ts +1 -39
  55. package/src/lib/utils/geometry-utils.ts +234 -0
  56. package/src/lib/vector-tile/vector-tile-feature.ts +416 -0
  57. package/src/lib/{mapbox-vector-tile → vector-tile}/vector-tile-layer.ts +28 -2
  58. package/src/lib/{geojson-tiler → vector-tiler}/clip.ts +4 -4
  59. package/src/lib/{geojson-tiler → vector-tiler}/convert.ts +19 -9
  60. package/src/lib/{geojson-tiler → vector-tiler}/feature.ts +3 -3
  61. package/src/lib/{geojson-tiler → vector-tiler}/tile.ts +10 -10
  62. package/src/lib/{geojson-tiler → vector-tiler}/transform.ts +2 -2
  63. package/src/lib/{geojson-tiler → vector-tiler}/wrap.ts +5 -5
  64. package/src/mvt-loader.ts +14 -6
  65. package/src/mvt-source.ts +9 -10
  66. package/src/table-tile-source.ts +508 -0
  67. package/dist/helpers/binary-util-functions.d.ts +0 -35
  68. package/dist/helpers/binary-util-functions.d.ts.map +0 -1
  69. package/dist/helpers/binary-util-functions.js +0 -114
  70. package/dist/helpers/mapbox-util-functions.d.ts +0 -29
  71. package/dist/helpers/mapbox-util-functions.d.ts.map +0 -1
  72. package/dist/helpers/mapbox-util-functions.js +0 -78
  73. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts +0 -41
  74. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +0 -1
  75. package/dist/lib/binary-vector-tile/vector-tile-feature.js +0 -163
  76. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts +0 -23
  77. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts.map +0 -1
  78. package/dist/lib/binary-vector-tile/vector-tile-layer.js +0 -96
  79. package/dist/lib/binary-vector-tile/vector-tile.d.ts +0 -9
  80. package/dist/lib/binary-vector-tile/vector-tile.d.ts.map +0 -1
  81. package/dist/lib/binary-vector-tile/vector-tile.js +0 -27
  82. package/dist/lib/geojson-tiler/clip.d.ts.map +0 -1
  83. package/dist/lib/geojson-tiler/convert.d.ts +0 -10
  84. package/dist/lib/geojson-tiler/convert.d.ts.map +0 -1
  85. package/dist/lib/geojson-tiler/feature.d.ts +0 -3
  86. package/dist/lib/geojson-tiler/feature.d.ts.map +0 -1
  87. package/dist/lib/geojson-tiler/geojson-tiler.d.ts +0 -44
  88. package/dist/lib/geojson-tiler/geojson-tiler.d.ts.map +0 -1
  89. package/dist/lib/geojson-tiler/geojson-tiler.js +0 -209
  90. package/dist/lib/geojson-tiler/simplify.d.ts.map +0 -1
  91. package/dist/lib/geojson-tiler/tile.d.ts.map +0 -1
  92. package/dist/lib/geojson-tiler/transform.d.ts +0 -7
  93. package/dist/lib/geojson-tiler/transform.d.ts.map +0 -1
  94. package/dist/lib/geojson-tiler/wrap.d.ts.map +0 -1
  95. package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts +0 -27
  96. package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts.map +0 -1
  97. package/dist/lib/mapbox-vector-tile/vector-tile-feature.js +0 -178
  98. package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts.map +0 -1
  99. package/dist/lib/mapbox-vector-tile/vector-tile.d.ts.map +0 -1
  100. package/src/helpers/binary-util-functions.ts +0 -125
  101. package/src/helpers/mapbox-util-functions.ts +0 -82
  102. package/src/lib/binary-vector-tile/vector-tile-feature.ts +0 -203
  103. package/src/lib/binary-vector-tile/vector-tile-layer.ts +0 -113
  104. package/src/lib/binary-vector-tile/vector-tile.ts +0 -36
  105. package/src/lib/geojson-tiler/geojson-tiler.ts +0 -283
  106. package/src/lib/mapbox-vector-tile/LICENSE.txt +0 -31
  107. package/src/lib/mapbox-vector-tile/vector-tile-feature.ts +0 -207
  108. /package/dist/lib/{mapbox-vector-tile → vector-tile}/vector-tile.d.ts +0 -0
  109. /package/dist/lib/{mapbox-vector-tile → vector-tile}/vector-tile.js +0 -0
  110. /package/dist/lib/{geojson-tiler → vector-tiler}/clip.js +0 -0
  111. /package/dist/lib/{geojson-tiler → vector-tiler}/feature.js +0 -0
  112. /package/dist/lib/{geojson-tiler → vector-tiler}/simplify.d.ts +0 -0
  113. /package/dist/lib/{geojson-tiler → vector-tiler}/simplify.js +0 -0
  114. /package/dist/lib/{geojson-tiler → vector-tiler}/tile.js +0 -0
  115. /package/dist/lib/{geojson-tiler → vector-tiler}/transform.js +0 -0
  116. /package/dist/lib/{geojson-tiler → vector-tiler}/wrap.js +0 -0
  117. /package/src/lib/{binary-vector-tile → vector-tile}/LICENSE.txt +0 -0
  118. /package/src/lib/{mapbox-vector-tile → vector-tile}/vector-tile.ts +0 -0
  119. /package/src/lib/{geojson-tiler → vector-tiler}/LICENSE +0 -0
  120. /package/src/lib/{geojson-tiler → vector-tiler}/simplify.ts +0 -0
package/dist/index.cjs CHANGED
@@ -5,6 +5,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
9
  var __export = (target, all) => {
9
10
  for (var name in all)
10
11
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -26,23 +27,82 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
27
  mod
27
28
  ));
28
29
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var __publicField = (obj, key, value) => {
31
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
32
+ return value;
33
+ };
29
34
 
30
35
  // dist/index.js
31
36
  var dist_exports = {};
32
37
  __export(dist_exports, {
33
- GeoJSONTiler: () => GeoJSONTiler,
34
38
  MVTLoader: () => MVTLoader,
35
39
  MVTSource: () => MVTSource,
36
40
  MVTWorkerLoader: () => MVTWorkerLoader,
41
+ TableTileSource: () => TableTileSource,
37
42
  TileJSONLoader: () => TileJSONLoader
38
43
  });
39
44
  module.exports = __toCommonJS(dist_exports);
40
45
 
41
46
  // dist/lib/parse-mvt.js
42
47
  var import_gis = require("@loaders.gl/gis");
48
+ var import_loader_utils = require("@loaders.gl/loader-utils");
43
49
  var import_pbf = __toESM(require("pbf"), 1);
44
50
 
45
- // dist/helpers/mapbox-util-functions.js
51
+ // dist/lib/utils/geometry-utils.js
52
+ var import_polygon = require("@math.gl/polygon");
53
+ function signedArea(ring) {
54
+ let sum = 0;
55
+ for (let i = 0, j = ring.length - 1, p1, p2; i < ring.length; j = i++) {
56
+ p1 = ring[i];
57
+ p2 = ring[j];
58
+ sum += (p2[0] - p1[0]) * (p1[1] + p2[1]);
59
+ }
60
+ return sum;
61
+ }
62
+ function convertToLocalCoordinates(coordinates, extent) {
63
+ if (Array.isArray(coordinates[0])) {
64
+ for (const subcoords of coordinates) {
65
+ convertToLocalCoordinates(subcoords, extent);
66
+ }
67
+ return;
68
+ }
69
+ const p = coordinates;
70
+ p[0] /= extent;
71
+ p[1] /= extent;
72
+ }
73
+ function convertToLocalCoordinatesFlat(data, extent) {
74
+ for (let i = 0, il = data.length; i < il; ++i) {
75
+ data[i] /= extent;
76
+ }
77
+ }
78
+ function projectToLngLat(line, tileIndex, extent) {
79
+ if (typeof line[0][0] !== "number") {
80
+ for (const point of line) {
81
+ projectToLngLat(point, tileIndex, extent);
82
+ }
83
+ return;
84
+ }
85
+ const size = extent * Math.pow(2, tileIndex.z);
86
+ const x0 = extent * tileIndex.x;
87
+ const y0 = extent * tileIndex.y;
88
+ for (let j = 0; j < line.length; j++) {
89
+ const p = line[j];
90
+ p[0] = (p[0] + x0) * 360 / size - 180;
91
+ const y2 = 180 - (p[1] + y0) * 360 / size;
92
+ p[1] = 360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90;
93
+ }
94
+ }
95
+ function projectToLngLatFlat(data, tileIndex, extent) {
96
+ const { x, y, z } = tileIndex;
97
+ const size = extent * Math.pow(2, z);
98
+ const x0 = extent * x;
99
+ const y0 = extent * y;
100
+ for (let j = 0, jl = data.length; j < jl; j += 2) {
101
+ data[j] = (data[j] + x0) * 360 / size - 180;
102
+ const y2 = 180 - (data[j + 1] + y0) * 360 / size;
103
+ data[j + 1] = 360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90;
104
+ }
105
+ }
46
106
  function classifyRings(rings) {
47
107
  const len = rings.length;
48
108
  if (len <= 1)
@@ -50,8 +110,8 @@ function classifyRings(rings) {
50
110
  const polygons = [];
51
111
  let polygon;
52
112
  let ccw;
53
- for (let i2 = 0; i2 < len; i2++) {
54
- const area = signedArea(rings[i2]);
113
+ for (let i = 0; i < len; i++) {
114
+ const area = signedArea(rings[i]);
55
115
  if (area === 0)
56
116
  continue;
57
117
  if (ccw === void 0)
@@ -59,294 +119,15 @@ function classifyRings(rings) {
59
119
  if (ccw === area < 0) {
60
120
  if (polygon)
61
121
  polygons.push(polygon);
62
- polygon = [rings[i2]];
122
+ polygon = [rings[i]];
63
123
  } else if (polygon)
64
- polygon.push(rings[i2]);
124
+ polygon.push(rings[i]);
65
125
  }
66
126
  if (polygon)
67
127
  polygons.push(polygon);
68
128
  return polygons;
69
129
  }
70
- function signedArea(ring) {
71
- let sum = 0;
72
- for (let i2 = 0, j = ring.length - 1, p1, p2; i2 < ring.length; j = i2++) {
73
- p1 = ring[i2];
74
- p2 = ring[j];
75
- sum += (p2[0] - p1[0]) * (p1[1] + p2[1]);
76
- }
77
- return sum;
78
- }
79
- function readFeature(tag, feature, pbf) {
80
- if (feature && pbf) {
81
- if (tag === 1)
82
- feature.id = pbf.readVarint();
83
- else if (tag === 2)
84
- readTag(pbf, feature);
85
- else if (tag === 3)
86
- feature.type = pbf.readVarint();
87
- else if (tag === 4)
88
- feature._geometry = pbf.pos;
89
- }
90
- }
91
- function readTag(pbf, feature) {
92
- const end = pbf.readVarint() + pbf.pos;
93
- while (pbf.pos < end) {
94
- const key = feature._keys[pbf.readVarint()];
95
- const value = feature._values[pbf.readVarint()];
96
- feature.properties[key] = value;
97
- }
98
- }
99
-
100
- // dist/lib/mapbox-vector-tile/vector-tile-feature.js
101
- var VectorTileFeature = class {
102
- properties;
103
- extent;
104
- type;
105
- id;
106
- _pbf;
107
- _geometry;
108
- _keys;
109
- _values;
110
- static get types() {
111
- return ["Unknown", "Point", "LineString", "Polygon"];
112
- }
113
- constructor(pbf, end, extent, keys, values) {
114
- this.properties = {};
115
- this.extent = extent;
116
- this.type = 0;
117
- this.id = null;
118
- this._pbf = pbf;
119
- this._geometry = -1;
120
- this._keys = keys;
121
- this._values = values;
122
- pbf.readFields(readFeature, this, end);
123
- }
124
- // eslint-disable-next-line complexity, max-statements
125
- loadGeometry() {
126
- const pbf = this._pbf;
127
- pbf.pos = this._geometry;
128
- const end = pbf.readVarint() + pbf.pos;
129
- let cmd2 = 1;
130
- let length2 = 0;
131
- let x2 = 0;
132
- let y2 = 0;
133
- const lines = [];
134
- let line;
135
- while (pbf.pos < end) {
136
- if (length2 <= 0) {
137
- const cmdLen2 = pbf.readVarint();
138
- cmd2 = cmdLen2 & 7;
139
- length2 = cmdLen2 >> 3;
140
- }
141
- length2--;
142
- if (cmd2 === 1 || cmd2 === 2) {
143
- x2 += pbf.readSVarint();
144
- y2 += pbf.readSVarint();
145
- if (cmd2 === 1) {
146
- if (line)
147
- lines.push(line);
148
- line = [];
149
- }
150
- if (line)
151
- line.push([x2, y2]);
152
- } else if (cmd2 === 7) {
153
- if (line) {
154
- line.push(line[0].slice());
155
- }
156
- } else {
157
- throw new Error(`unknown command ${cmd2}`);
158
- }
159
- }
160
- if (line)
161
- lines.push(line);
162
- return lines;
163
- }
164
- // eslint-disable-next-line max-statements
165
- bbox() {
166
- const pbf = this._pbf;
167
- pbf.pos = this._geometry;
168
- const end = pbf.readVarint() + pbf.pos;
169
- let cmd2 = 1;
170
- let length2 = 0;
171
- let x2 = 0;
172
- let y2 = 0;
173
- let x1 = Infinity;
174
- let x22 = -Infinity;
175
- let y1 = Infinity;
176
- let y22 = -Infinity;
177
- while (pbf.pos < end) {
178
- if (length2 <= 0) {
179
- const cmdLen2 = pbf.readVarint();
180
- cmd2 = cmdLen2 & 7;
181
- length2 = cmdLen2 >> 3;
182
- }
183
- length2--;
184
- if (cmd2 === 1 || cmd2 === 2) {
185
- x2 += pbf.readSVarint();
186
- y2 += pbf.readSVarint();
187
- if (x2 < x1)
188
- x1 = x2;
189
- if (x2 > x22)
190
- x22 = x2;
191
- if (y2 < y1)
192
- y1 = y2;
193
- if (y2 > y22)
194
- y22 = y2;
195
- } else if (cmd2 !== 7) {
196
- throw new Error(`unknown command ${cmd2}`);
197
- }
198
- }
199
- return [x1, y1, x22, y22];
200
- }
201
- _toGeoJSON(transform) {
202
- let coords = this.loadGeometry();
203
- let type = VectorTileFeature.types[this.type];
204
- let i2;
205
- let j;
206
- switch (this.type) {
207
- case 1:
208
- const points = [];
209
- for (i2 = 0; i2 < coords.length; i2++) {
210
- points[i2] = coords[i2][0];
211
- }
212
- coords = points;
213
- transform(coords, this);
214
- break;
215
- case 2:
216
- for (i2 = 0; i2 < coords.length; i2++) {
217
- transform(coords[i2], this);
218
- }
219
- break;
220
- case 3:
221
- coords = classifyRings(coords);
222
- for (i2 = 0; i2 < coords.length; i2++) {
223
- for (j = 0; j < coords[i2].length; j++) {
224
- transform(coords[i2][j], this);
225
- }
226
- }
227
- break;
228
- }
229
- if (coords.length === 1) {
230
- coords = coords[0];
231
- } else {
232
- type = `Multi${type}`;
233
- }
234
- const result = {
235
- type: "Feature",
236
- geometry: {
237
- type,
238
- coordinates: coords
239
- },
240
- properties: this.properties
241
- };
242
- if (this.id !== null) {
243
- result.id = this.id;
244
- }
245
- return result;
246
- }
247
- toGeoJSON(options) {
248
- if (typeof options === "function") {
249
- return this._toGeoJSON(options);
250
- }
251
- const { x: x2, y: y2, z } = options;
252
- const size = this.extent * Math.pow(2, z);
253
- const x0 = this.extent * x2;
254
- const y0 = this.extent * y2;
255
- function project2(line) {
256
- for (let j = 0; j < line.length; j++) {
257
- const p = line[j];
258
- p[0] = (p[0] + x0) * 360 / size - 180;
259
- const y22 = 180 - (p[1] + y0) * 360 / size;
260
- p[1] = 360 / Math.PI * Math.atan(Math.exp(y22 * Math.PI / 180)) - 90;
261
- }
262
- }
263
- return this._toGeoJSON(project2);
264
- }
265
- };
266
-
267
- // dist/lib/mapbox-vector-tile/vector-tile-layer.js
268
- var VectorTileLayer = class {
269
- version;
270
- name;
271
- extent;
272
- length;
273
- _pbf;
274
- _keys;
275
- _values;
276
- _features;
277
- constructor(pbf, end) {
278
- this.version = 1;
279
- this.name = "";
280
- this.extent = 4096;
281
- this.length = 0;
282
- this._pbf = pbf;
283
- this._keys = [];
284
- this._values = [];
285
- this._features = [];
286
- pbf.readFields(readLayer, this, end);
287
- this.length = this._features.length;
288
- }
289
- /**
290
- * return feature `i` from this layer as a `VectorTileFeature`
291
- * @param index
292
- * @returns feature
293
- */
294
- feature(i2) {
295
- if (i2 < 0 || i2 >= this._features.length) {
296
- throw new Error("feature index out of bounds");
297
- }
298
- this._pbf.pos = this._features[i2];
299
- const end = this._pbf.readVarint() + this._pbf.pos;
300
- return new VectorTileFeature(this._pbf, end, this.extent, this._keys, this._values);
301
- }
302
- };
303
- function readLayer(tag, layer, pbf) {
304
- if (layer && pbf) {
305
- if (tag === 15)
306
- layer.version = pbf.readVarint();
307
- else if (tag === 1)
308
- layer.name = pbf.readString();
309
- else if (tag === 5)
310
- layer.extent = pbf.readVarint();
311
- else if (tag === 2)
312
- layer._features.push(pbf.pos);
313
- else if (tag === 3)
314
- layer._keys.push(pbf.readString());
315
- else if (tag === 4)
316
- layer._values.push(readValueMessage(pbf));
317
- }
318
- }
319
- function readValueMessage(pbf) {
320
- let value = null;
321
- const end = pbf.readVarint() + pbf.pos;
322
- while (pbf.pos < end) {
323
- const tag = pbf.readVarint() >> 3;
324
- 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;
325
- }
326
- return value;
327
- }
328
-
329
- // dist/lib/mapbox-vector-tile/vector-tile.js
330
- var VectorTile = class {
331
- layers;
332
- constructor(pbf, end) {
333
- this.layers = pbf.readFields(readTile, {}, end);
334
- }
335
- };
336
- function readTile(tag, layers, pbf) {
337
- if (tag === 3) {
338
- if (pbf) {
339
- const layer = new VectorTileLayer(pbf, pbf.readVarint() + pbf.pos);
340
- if (layer.length && layers) {
341
- layers[layer.name] = layer;
342
- }
343
- }
344
- }
345
- }
346
-
347
- // dist/helpers/binary-util-functions.js
348
- var import_polygon = require("@math.gl/polygon");
349
- function classifyRings2(geom) {
130
+ function classifyRingsFlat(geom) {
350
131
  const len = geom.indices.length;
351
132
  const type = "Polygon";
352
133
  if (len <= 1) {
@@ -363,9 +144,9 @@ function classifyRings2(geom) {
363
144
  let polygon = [];
364
145
  let ccw;
365
146
  let offset = 0;
366
- for (let endIndex, i2 = 0, startIndex; i2 < len; i2++) {
367
- startIndex = geom.indices[i2] - offset;
368
- endIndex = geom.indices[i2 + 1] - offset || geom.data.length;
147
+ for (let endIndex, i = 0, startIndex; i < len; i++) {
148
+ startIndex = geom.indices[i] - offset;
149
+ endIndex = geom.indices[i + 1] - offset || geom.data.length;
369
150
  const shape = geom.data.slice(startIndex, endIndex);
370
151
  const area = (0, import_polygon.getPolygonSignedArea)(shape);
371
152
  if (area === 0) {
@@ -395,43 +176,9 @@ function classifyRings2(geom) {
395
176
  polygons.push(polygon);
396
177
  return { type, areas, indices: polygons, data: geom.data };
397
178
  }
398
- function project(data, x0, y0, size) {
399
- for (let j = 0, jl = data.length; j < jl; j += 2) {
400
- data[j] = (data[j] + x0) * 360 / size - 180;
401
- const y2 = 180 - (data[j + 1] + y0) * 360 / size;
402
- data[j + 1] = 360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90;
403
- }
404
- }
405
- function readFeature2(tag, feature, pbf) {
406
- if (feature && pbf) {
407
- if (tag === 1)
408
- feature.id = pbf.readVarint();
409
- else if (tag === 2)
410
- readTag2(pbf, feature);
411
- else if (tag === 3)
412
- feature.type = pbf.readVarint();
413
- else if (tag === 4)
414
- feature._geometry = pbf.pos;
415
- }
416
- }
417
- function readTag2(pbf, feature) {
418
- const end = pbf.readVarint() + pbf.pos;
419
- while (pbf.pos < end) {
420
- const key = feature._keys[pbf.readVarint()];
421
- const value = feature._values[pbf.readVarint()];
422
- feature.properties[key] = value;
423
- }
424
- }
425
179
 
426
- // dist/lib/binary-vector-tile/vector-tile-feature.js
427
- var endPos;
428
- var cmd;
429
- var cmdLen;
430
- var length;
431
- var x;
432
- var y;
433
- var i;
434
- var BinaryVectorTileFeature = class {
180
+ // dist/lib/vector-tile/vector-tile-feature.js
181
+ var VectorTileFeature = class {
435
182
  properties;
436
183
  extent;
437
184
  type;
@@ -452,23 +199,48 @@ var BinaryVectorTileFeature = class {
452
199
  this._keys = keys;
453
200
  this._values = values;
454
201
  this._geometryInfo = geometryInfo;
455
- pbf.readFields(readFeature2, this, end);
202
+ pbf.readFields(readFeature, this, end);
456
203
  }
457
- // eslint-disable-next-line complexity, max-statements
458
- loadGeometry() {
204
+ toGeoJSONFeature(coordinates, tileIndex) {
205
+ const coords = this.loadGeometry();
206
+ switch (coordinates) {
207
+ case "wgs84":
208
+ return _toGeoJSONFeature(this, coords, (line) => projectToLngLat(line, tileIndex, this.extent));
209
+ default:
210
+ return _toGeoJSONFeature(this, coords, convertToLocalCoordinates);
211
+ }
212
+ }
213
+ /**
214
+ *
215
+ * @param options
216
+ * @returns
217
+ */
218
+ toBinaryFeature(coordinates, tileIndex) {
219
+ const geom = this.loadFlatGeometry();
220
+ switch (coordinates) {
221
+ case "wgs84":
222
+ return this._toBinaryCoordinates(geom, (coords) => projectToLngLatFlat(coords, tileIndex, this.extent));
223
+ default:
224
+ return this._toBinaryCoordinates(geom, convertToLocalCoordinatesFlat);
225
+ }
226
+ }
227
+ /** Read a bounding box from the feature */
228
+ // eslint-disable-next-line max-statements
229
+ bbox() {
459
230
  const pbf = this._pbf;
460
231
  pbf.pos = this._geometry;
461
- endPos = pbf.readVarint() + pbf.pos;
462
- cmd = 1;
463
- length = 0;
464
- x = 0;
465
- y = 0;
466
- i = 0;
467
- const indices = [];
468
- const data = [];
469
- while (pbf.pos < endPos) {
232
+ const end = pbf.readVarint() + pbf.pos;
233
+ let cmd = 1;
234
+ let length = 0;
235
+ let x = 0;
236
+ let y = 0;
237
+ let x1 = Infinity;
238
+ let x2 = -Infinity;
239
+ let y1 = Infinity;
240
+ let y2 = -Infinity;
241
+ while (pbf.pos < end) {
470
242
  if (length <= 0) {
471
- cmdLen = pbf.readVarint();
243
+ const cmdLen = pbf.readVarint();
472
244
  cmd = cmdLen & 7;
473
245
  length = cmdLen >> 3;
474
246
  }
@@ -476,32 +248,29 @@ var BinaryVectorTileFeature = class {
476
248
  if (cmd === 1 || cmd === 2) {
477
249
  x += pbf.readSVarint();
478
250
  y += pbf.readSVarint();
479
- if (cmd === 1) {
480
- indices.push(i);
481
- }
482
- data.push(x, y);
483
- i += 2;
484
- } else if (cmd === 7) {
485
- if (i > 0) {
486
- const start = indices[indices.length - 1];
487
- data.push(data[start], data[start + 1]);
488
- i += 2;
489
- }
490
- } else {
251
+ if (x < x1)
252
+ x1 = x;
253
+ if (x > x2)
254
+ x2 = x;
255
+ if (y < y1)
256
+ y1 = y;
257
+ if (y > y2)
258
+ y2 = y;
259
+ } else if (cmd !== 7) {
491
260
  throw new Error(`unknown command ${cmd}`);
492
261
  }
493
262
  }
494
- return { data, indices };
263
+ return [x1, y1, x2, y2];
495
264
  }
265
+ // BINARY HELPERS
496
266
  /**
497
267
  *
498
268
  * @param transform
499
269
  * @returns result
500
270
  */
501
- _toBinaryCoordinates(transform) {
502
- const geom = this.loadGeometry();
271
+ _toBinaryCoordinates(geom, transform) {
503
272
  let geometry;
504
- transform(geom.data, this);
273
+ transform(geom.data, this.extent);
505
274
  const coordLength = 2;
506
275
  switch (this.type) {
507
276
  case 1:
@@ -516,7 +285,7 @@ var BinaryVectorTileFeature = class {
516
285
  geometry = { type: "LineString", ...geom };
517
286
  break;
518
287
  case 3:
519
- geometry = classifyRings2(geom);
288
+ geometry = classifyRingsFlat(geom);
520
289
  this._geometryInfo.polygonFeaturesCount++;
521
290
  this._geometryInfo.polygonObjectsCount += geometry.indices.length;
522
291
  for (const indices of geometry.indices) {
@@ -533,20 +302,188 @@ var BinaryVectorTileFeature = class {
533
302
  }
534
303
  return result;
535
304
  }
536
- toBinaryCoordinates(options) {
537
- if (typeof options === "function") {
538
- return this._toBinaryCoordinates(options);
305
+ // GEOJSON HELPER
306
+ // eslint-disable-next-line complexity, max-statements
307
+ loadGeometry() {
308
+ const pbf = this._pbf;
309
+ pbf.pos = this._geometry;
310
+ const end = pbf.readVarint() + pbf.pos;
311
+ let cmd = 1;
312
+ let length = 0;
313
+ let x = 0;
314
+ let y = 0;
315
+ const lines = [];
316
+ let line;
317
+ while (pbf.pos < end) {
318
+ if (length <= 0) {
319
+ const cmdLen = pbf.readVarint();
320
+ cmd = cmdLen & 7;
321
+ length = cmdLen >> 3;
322
+ }
323
+ length--;
324
+ switch (cmd) {
325
+ case 1:
326
+ case 2:
327
+ x += pbf.readSVarint();
328
+ y += pbf.readSVarint();
329
+ if (cmd === 1) {
330
+ if (line)
331
+ lines.push(line);
332
+ line = [];
333
+ }
334
+ if (line)
335
+ line.push([x, y]);
336
+ break;
337
+ case 7:
338
+ if (line) {
339
+ line.push(line[0].slice());
340
+ }
341
+ break;
342
+ default:
343
+ throw new Error(`unknown command ${cmd}`);
344
+ }
345
+ }
346
+ if (line)
347
+ lines.push(line);
348
+ return lines;
349
+ }
350
+ /**
351
+ * Expands the protobuf data to an intermediate Flat GeoJSON
352
+ * data format, which maps closely to the binary data buffers.
353
+ * It is similar to GeoJSON, but rather than storing the coordinates
354
+ * in multidimensional arrays, we have a 1D `data` with all the
355
+ * coordinates, and then index into this using the `indices`
356
+ * parameter, e.g.
357
+ *
358
+ * geometry: {
359
+ * type: 'Point', data: [1,2], indices: [0]
360
+ * }
361
+ * geometry: {
362
+ * type: 'LineString', data: [1,2,3,4,...], indices: [0]
363
+ * }
364
+ * geometry: {
365
+ * type: 'Polygon', data: [1,2,3,4,...], indices: [[0, 2]]
366
+ * }
367
+ * Thus the indices member lets us look up the relevant range
368
+ * from the data array.
369
+ * The Multi* versions of the above types share the same data
370
+ * structure, just with multiple elements in the indices array
371
+ */
372
+ // eslint-disable-next-line complexity, max-statements
373
+ loadFlatGeometry() {
374
+ const pbf = this._pbf;
375
+ pbf.pos = this._geometry;
376
+ const endPos = pbf.readVarint() + pbf.pos;
377
+ let cmd = 1;
378
+ let cmdLen;
379
+ let length = 0;
380
+ let x = 0;
381
+ let y = 0;
382
+ let i = 0;
383
+ const indices = [];
384
+ const data = [];
385
+ while (pbf.pos < endPos) {
386
+ if (length <= 0) {
387
+ cmdLen = pbf.readVarint();
388
+ cmd = cmdLen & 7;
389
+ length = cmdLen >> 3;
390
+ }
391
+ length--;
392
+ if (cmd === 1 || cmd === 2) {
393
+ x += pbf.readSVarint();
394
+ y += pbf.readSVarint();
395
+ if (cmd === 1) {
396
+ indices.push(i);
397
+ }
398
+ data.push(x, y);
399
+ i += 2;
400
+ } else if (cmd === 7) {
401
+ if (i > 0) {
402
+ const start = indices[indices.length - 1];
403
+ data.push(data[start], data[start + 1]);
404
+ i += 2;
405
+ }
406
+ } else {
407
+ throw new Error(`unknown command ${cmd}`);
408
+ }
539
409
  }
540
- const { x: x2, y: y2, z } = options;
541
- const size = this.extent * Math.pow(2, z);
542
- const x0 = this.extent * x2;
543
- const y0 = this.extent * y2;
544
- return this._toBinaryCoordinates((data) => project(data, x0, y0, size));
410
+ return { data, indices };
545
411
  }
546
412
  };
413
+ __publicField(VectorTileFeature, "types", ["Unknown", "Point", "LineString", "Polygon"]);
414
+ function _toGeoJSONFeature(vtFeature, coords, transform) {
415
+ let type = VectorTileFeature.types[vtFeature.type];
416
+ let i;
417
+ let j;
418
+ let coordinates;
419
+ switch (vtFeature.type) {
420
+ case 1:
421
+ const points = [];
422
+ for (i = 0; i < coords.length; i++) {
423
+ points[i] = coords[i][0];
424
+ }
425
+ coordinates = points;
426
+ transform(coordinates, vtFeature.extent);
427
+ break;
428
+ case 2:
429
+ coordinates = coords;
430
+ for (i = 0; i < coordinates.length; i++) {
431
+ transform(coordinates[i], vtFeature.extent);
432
+ }
433
+ break;
434
+ case 3:
435
+ coordinates = classifyRings(coords);
436
+ for (i = 0; i < coordinates.length; i++) {
437
+ for (j = 0; j < coordinates[i].length; j++) {
438
+ transform(coordinates[i][j], vtFeature.extent);
439
+ }
440
+ }
441
+ break;
442
+ default:
443
+ throw new Error("illegal vector tile type");
444
+ }
445
+ if (coordinates.length === 1) {
446
+ coordinates = coordinates[0];
447
+ } else {
448
+ type = `Multi${type}`;
449
+ }
450
+ const result = {
451
+ type: "Feature",
452
+ geometry: {
453
+ type,
454
+ coordinates
455
+ },
456
+ properties: vtFeature.properties
457
+ };
458
+ if (vtFeature.id !== null) {
459
+ result.properties ||= {};
460
+ result.properties.id = vtFeature.id;
461
+ }
462
+ return result;
463
+ }
464
+ function readFeature(tag, feature, pbf) {
465
+ if (feature && pbf) {
466
+ if (tag === 1)
467
+ feature.id = pbf.readVarint();
468
+ else if (tag === 2)
469
+ readTag(pbf, feature);
470
+ else if (tag === 3)
471
+ feature.type = pbf.readVarint();
472
+ else if (tag === 4)
473
+ feature._geometry = pbf.pos;
474
+ }
475
+ }
476
+ function readTag(pbf, feature) {
477
+ const end = pbf.readVarint() + pbf.pos;
478
+ while (pbf.pos < end) {
479
+ const key = feature._keys[pbf.readVarint()];
480
+ const value = feature._values[pbf.readVarint()];
481
+ feature.properties[key] = value;
482
+ }
483
+ }
547
484
 
548
- // dist/lib/binary-vector-tile/vector-tile-layer.js
549
- var BinaryVectorTileLayer = class {
485
+ // dist/lib/vector-tile/vector-tile-layer.js
486
+ var VectorTileLayer = class {
550
487
  version;
551
488
  name;
552
489
  extent;
@@ -564,26 +501,39 @@ var BinaryVectorTileLayer = class {
564
501
  this._keys = [];
565
502
  this._values = [];
566
503
  this._features = [];
567
- pbf.readFields(readLayer2, this, end);
504
+ pbf.readFields(readLayer, this, end);
568
505
  this.length = this._features.length;
569
506
  }
570
507
  /**
571
- * return feature `i` from this layer as a `BinaryVectorTileFeature`
508
+ * return feature `i` from this layer as a `VectorTileFeature`
509
+ * @param index
510
+ * @returns feature
511
+ */
512
+ getGeoJSONFeature(i) {
513
+ if (i < 0 || i >= this._features.length) {
514
+ throw new Error("feature index out of bounds");
515
+ }
516
+ this._pbf.pos = this._features[i];
517
+ const end = this._pbf.readVarint() + this._pbf.pos;
518
+ return new VectorTileFeature(this._pbf, end, this.extent, this._keys, this._values);
519
+ }
520
+ /**
521
+ * return binary feature `i` from this layer as a `VectorTileFeature`
572
522
  *
573
523
  * @param index
574
524
  * @param geometryInfo
575
- * @returns {BinaryVectorTileFeature}
525
+ * @returns binary feature
576
526
  */
577
- feature(i2, geometryInfo) {
578
- if (i2 < 0 || i2 >= this._features.length) {
527
+ getBinaryFeature(i, geometryInfo) {
528
+ if (i < 0 || i >= this._features.length) {
579
529
  throw new Error("feature index out of bounds");
580
530
  }
581
- this._pbf.pos = this._features[i2];
531
+ this._pbf.pos = this._features[i];
582
532
  const end = this._pbf.readVarint() + this._pbf.pos;
583
- return new BinaryVectorTileFeature(this._pbf, end, this.extent, this._keys, this._values, geometryInfo);
533
+ return new VectorTileFeature(this._pbf, end, this.extent, this._keys, this._values, geometryInfo);
584
534
  }
585
535
  };
586
- function readLayer2(tag, layer, pbf) {
536
+ function readLayer(tag, layer, pbf) {
587
537
  if (layer && pbf) {
588
538
  if (tag === 15)
589
539
  layer.version = pbf.readVarint();
@@ -596,10 +546,10 @@ function readLayer2(tag, layer, pbf) {
596
546
  else if (tag === 3)
597
547
  layer._keys.push(pbf.readString());
598
548
  else if (tag === 4)
599
- layer._values.push(readValueMessage2(pbf));
549
+ layer._values.push(readValueMessage(pbf));
600
550
  }
601
551
  }
602
- function readValueMessage2(pbf) {
552
+ function readValueMessage(pbf) {
603
553
  let value = null;
604
554
  const end = pbf.readVarint() + pbf.pos;
605
555
  while (pbf.pos < end) {
@@ -609,17 +559,17 @@ function readValueMessage2(pbf) {
609
559
  return value;
610
560
  }
611
561
 
612
- // dist/lib/binary-vector-tile/vector-tile.js
613
- var BinaryVectorTile = class {
562
+ // dist/lib/vector-tile/vector-tile.js
563
+ var VectorTile = class {
614
564
  layers;
615
565
  constructor(pbf, end) {
616
- this.layers = pbf.readFields(readTile2, {}, end);
566
+ this.layers = pbf.readFields(readTile, {}, end);
617
567
  }
618
568
  };
619
- function readTile2(tag, layers, pbf) {
569
+ function readTile(tag, layers, pbf) {
620
570
  if (tag === 3) {
621
571
  if (pbf) {
622
- const layer = new BinaryVectorTileLayer(pbf, pbf.readVarint() + pbf.pos);
572
+ const layer = new VectorTileLayer(pbf, pbf.readVarint() + pbf.pos);
623
573
  if (layer.length && layers) {
624
574
  layers[layer.name] = layer;
625
575
  }
@@ -630,7 +580,7 @@ function readTile2(tag, layers, pbf) {
630
580
  // dist/lib/parse-mvt.js
631
581
  function parseMVT(arrayBuffer, options) {
632
582
  var _a, _b;
633
- const mvtOptions = normalizeOptions(options);
583
+ const mvtOptions = checkOptions(options);
634
584
  const shape = ((_a = options == null ? void 0 : options.gis) == null ? void 0 : _a.format) || ((_b = options == null ? void 0 : options.mvt) == null ? void 0 : _b.shape) || (options == null ? void 0 : options.shape);
635
585
  switch (shape) {
636
586
  case "columnar-table":
@@ -676,15 +626,15 @@ function parseToFlatGeoJson(arrayBuffer, options) {
676
626
  if (arrayBuffer.byteLength <= 0) {
677
627
  return [features, geometryInfo];
678
628
  }
679
- const tile = new BinaryVectorTile(new import_pbf.default(arrayBuffer));
629
+ const tile = new VectorTile(new import_pbf.default(arrayBuffer));
680
630
  const selectedLayers = options && Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);
681
631
  selectedLayers.forEach((layerName) => {
682
632
  const vectorTileLayer = tile.layers[layerName];
683
633
  if (!vectorTileLayer) {
684
634
  return;
685
635
  }
686
- for (let i2 = 0; i2 < vectorTileLayer.length; i2++) {
687
- const vectorTileFeature = vectorTileLayer.feature(i2, geometryInfo);
636
+ for (let i = 0; i < vectorTileLayer.length; i++) {
637
+ const vectorTileFeature = vectorTileLayer.getBinaryFeature(i, geometryInfo);
688
638
  const decodedFeature = getDecodedFeatureBinary(vectorTileFeature, options, layerName);
689
639
  features.push(decodedFeature);
690
640
  }
@@ -703,64 +653,45 @@ function parseToGeojsonFeatures(arrayBuffer, options) {
703
653
  if (!vectorTileLayer) {
704
654
  return;
705
655
  }
706
- for (let i2 = 0; i2 < vectorTileLayer.length; i2++) {
707
- const vectorTileFeature = vectorTileLayer.feature(i2);
656
+ for (let i = 0; i < vectorTileLayer.length; i++) {
657
+ const vectorTileFeature = vectorTileLayer.getGeoJSONFeature(i);
708
658
  const decodedFeature = getDecodedFeature(vectorTileFeature, options, layerName);
709
659
  features.push(decodedFeature);
710
660
  }
711
661
  });
712
662
  return features;
713
663
  }
714
- function normalizeOptions(options) {
664
+ function checkOptions(options) {
715
665
  var _a;
716
666
  if (!(options == null ? void 0 : options.mvt)) {
717
667
  throw new Error("mvt options required");
718
668
  }
719
- const wgs84Coordinates = ((_a = options.mvt) == null ? void 0 : _a.coordinates) === "wgs84";
720
- const { tileIndex } = options.mvt;
721
- const hasTileIndex = tileIndex && Number.isFinite(tileIndex.x) && Number.isFinite(tileIndex.y) && Number.isFinite(tileIndex.z);
722
- if (wgs84Coordinates && !hasTileIndex) {
669
+ if (((_a = options.mvt) == null ? void 0 : _a.coordinates) === "wgs84" && !options.mvt.tileIndex) {
723
670
  throw new Error("MVT Loader: WGS84 coordinates need tileIndex property");
724
671
  }
672
+ if (options.gis) {
673
+ import_loader_utils.log.warn('MVTLoader: "options.gis" is deprecated, use "options.mvt.shape" instead')();
674
+ }
725
675
  return options.mvt;
726
676
  }
727
677
  function getDecodedFeature(feature, options, layerName) {
728
- const decodedFeature = feature.toGeoJSON(
729
- // @ts-expect-error What is going on here?
730
- options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinates
731
- );
678
+ const decodedFeature = feature.toGeoJSONFeature(options.coordinates || "local", options.tileIndex);
732
679
  if (options.layerProperty) {
680
+ decodedFeature.properties ||= {};
733
681
  decodedFeature.properties[options.layerProperty] = layerName;
734
682
  }
735
683
  return decodedFeature;
736
684
  }
737
685
  function getDecodedFeatureBinary(feature, options, layerName) {
738
- const decodedFeature = feature.toBinaryCoordinates(
739
- // @ts-expect-error
740
- options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinatesBinary
741
- );
686
+ const decodedFeature = feature.toBinaryFeature(options.coordinates || "local", options.tileIndex);
742
687
  if (options.layerProperty && decodedFeature.properties) {
743
688
  decodedFeature.properties[options.layerProperty] = layerName;
744
689
  }
745
690
  return decodedFeature;
746
691
  }
747
- function transformToLocalCoordinates(line, feature) {
748
- const { extent } = feature;
749
- for (let i2 = 0; i2 < line.length; i2++) {
750
- const p = line[i2];
751
- p[0] /= extent;
752
- p[1] /= extent;
753
- }
754
- }
755
- function transformToLocalCoordinatesBinary(data, feature) {
756
- const { extent } = feature;
757
- for (let i2 = 0, il = data.length; i2 < il; ++i2) {
758
- data[i2] /= extent;
759
- }
760
- }
761
692
 
762
693
  // dist/mvt-loader.js
763
- var VERSION = true ? "4.2.0" : "latest";
694
+ var VERSION = true ? "4.3.0-alpha.1" : "latest";
764
695
  var MVTWorkerLoader = {
765
696
  dataType: null,
766
697
  batchType: null,
@@ -784,7 +715,7 @@ var MVTWorkerLoader = {
784
715
  coordinates: "local",
785
716
  layerProperty: "layerName",
786
717
  layers: void 0,
787
- tileIndex: null
718
+ tileIndex: void 0
788
719
  }
789
720
  }
790
721
  };
@@ -796,7 +727,7 @@ var MVTLoader = {
796
727
  };
797
728
 
798
729
  // dist/lib/parse-tilejson.js
799
- var isObject = (x2) => x2 !== null && typeof x2 === "object";
730
+ var isObject = (x) => x !== null && typeof x === "object";
800
731
  function parseTileJSON(jsonMetadata, options) {
801
732
  var _a;
802
733
  if (!jsonMetadata || !isObject(jsonMetadata)) {
@@ -1002,7 +933,7 @@ function attributeTypeToFieldType(aType) {
1002
933
  }
1003
934
 
1004
935
  // dist/tilejson-loader.js
1005
- var VERSION2 = true ? "4.2.0" : "latest";
936
+ var VERSION2 = true ? "4.3.0-alpha.1" : "latest";
1006
937
  var TileJSONLoader = {
1007
938
  dataType: null,
1008
939
  batchType: null,
@@ -1033,10 +964,10 @@ var TileJSONLoader = {
1033
964
  };
1034
965
 
1035
966
  // dist/mvt-source.js
1036
- var import_loader_utils = require("@loaders.gl/loader-utils");
967
+ var import_loader_utils2 = require("@loaders.gl/loader-utils");
1037
968
  var import_images = require("@loaders.gl/images");
1038
969
  var import_mvt = require("@loaders.gl/mvt");
1039
- var MVTSource = class extends import_loader_utils.DataSource {
970
+ var MVTSource = class extends import_loader_utils2.DataSource {
1040
971
  props;
1041
972
  url;
1042
973
  metadataUrl = null;
@@ -1048,7 +979,7 @@ var MVTSource = class extends import_loader_utils.DataSource {
1048
979
  constructor(props) {
1049
980
  super(props);
1050
981
  this.props = props;
1051
- this.url = (0, import_loader_utils.resolvePath)(props.url);
982
+ this.url = (0, import_loader_utils2.resolvePath)(props.url);
1052
983
  this.metadataUrl = props.metadataUrl === void 0 ? `${this.url}/tilejson.json` : props.metadataUrl;
1053
984
  this.extension = props.extension || ".png";
1054
985
  this.data = this.url;
@@ -1082,9 +1013,9 @@ var MVTSource = class extends import_loader_utils.DataSource {
1082
1013
  getTileMIMEType() {
1083
1014
  return this.mimeType;
1084
1015
  }
1085
- async getTile(tileParams) {
1086
- const { x: x2, y: y2, zoom: z } = tileParams;
1087
- const tileUrl = this.getTileURL(x2, y2, z);
1016
+ async getTile(parameters) {
1017
+ const { x, y, z } = parameters;
1018
+ const tileUrl = this.getTileURL(x, y, z);
1088
1019
  const response = await this.fetch(tileUrl);
1089
1020
  if (!response.ok) {
1090
1021
  return null;
@@ -1094,9 +1025,9 @@ var MVTSource = class extends import_loader_utils.DataSource {
1094
1025
  }
1095
1026
  // Tile Source interface implementation: deck.gl compatible API
1096
1027
  // TODO - currently only handles image tiles, not vector tiles
1097
- async getTileData(tileParams) {
1098
- const { x: x2, y: y2, z } = tileParams.index;
1099
- const arrayBuffer = await this.getTile({ x: x2, y: y2, zoom: z, layers: [] });
1028
+ async getTileData(parameters) {
1029
+ const { x, y, z } = parameters.index;
1030
+ const arrayBuffer = await this.getTile({ x, y, z, layers: [] });
1100
1031
  if (arrayBuffer === null) {
1101
1032
  return null;
1102
1033
  }
@@ -1104,7 +1035,7 @@ var MVTSource = class extends import_loader_utils.DataSource {
1104
1035
  this.mimeType = this.mimeType || (imageMetadata == null ? void 0 : imageMetadata.mimeType) || "application/vnd.mapbox-vector-tile";
1105
1036
  switch (this.mimeType) {
1106
1037
  case "application/vnd.mapbox-vector-tile":
1107
- return await this._parseVectorTile(arrayBuffer, { x: x2, y: y2, zoom: z, layers: [] });
1038
+ return await this._parseVectorTile(arrayBuffer, { x, y, z, layers: [] });
1108
1039
  default:
1109
1040
  return await this._parseImageTile(arrayBuffer);
1110
1041
  }
@@ -1128,7 +1059,7 @@ var MVTSource = class extends import_loader_utils.DataSource {
1128
1059
  shape: "geojson-table",
1129
1060
  mvt: {
1130
1061
  coordinates: "wgs84",
1131
- tileIndex: { x: tileParams.x, y: tileParams.y, z: tileParams.zoom },
1062
+ tileIndex: { x: tileParams.x, y: tileParams.y, z: tileParams.z },
1132
1063
  ...(_a = this.loadOptions) == null ? void 0 : _a.mvt
1133
1064
  },
1134
1065
  ...this.loadOptions
@@ -1138,14 +1069,14 @@ var MVTSource = class extends import_loader_utils.DataSource {
1138
1069
  getMetadataUrl() {
1139
1070
  return this.metadataUrl;
1140
1071
  }
1141
- getTileURL(x2, y2, z) {
1072
+ getTileURL(x, y, z) {
1142
1073
  switch (this.schema) {
1143
1074
  case "xyz":
1144
- return `${this.url}/${x2}/${y2}/${z}${this.extension}`;
1075
+ return `${this.url}/${x}/${y}/${z}${this.extension}`;
1145
1076
  case "tms":
1146
- return `${this.url}/${z}/${x2}/${y2}${this.extension}`;
1077
+ return `${this.url}/${z}/${x}/${y}${this.extension}`;
1147
1078
  case "template":
1148
- return getURLFromTemplate(this.url, x2, y2, z, "0");
1079
+ return getURLFromTemplate(this.url, x, y, z, "0");
1149
1080
  default:
1150
1081
  throw new Error(this.schema);
1151
1082
  }
@@ -1157,17 +1088,17 @@ function isURLTemplate(s) {
1157
1088
  var xRegex = new RegExp("{x}", "g");
1158
1089
  var yRegex = new RegExp("{y}", "g");
1159
1090
  var zRegex = new RegExp("{z}", "g");
1160
- function getURLFromTemplate(template, x2, y2, z, id = "0") {
1091
+ function getURLFromTemplate(template, x, y, z, id = "0") {
1161
1092
  if (Array.isArray(template)) {
1162
- const i2 = stringHash(id) % template.length;
1163
- template = template[i2];
1093
+ const i = stringHash(id) % template.length;
1094
+ template = template[i];
1164
1095
  }
1165
1096
  let url = template;
1166
- url = url.replace(xRegex, String(x2));
1167
- url = url.replace(yRegex, String(y2));
1097
+ url = url.replace(xRegex, String(x));
1098
+ url = url.replace(yRegex, String(y));
1168
1099
  url = url.replace(zRegex, String(z));
1169
- if (Number.isInteger(y2) && Number.isInteger(z)) {
1170
- url = url.replace(/\{-y\}/g, String(Math.pow(2, z) - y2 - 1));
1100
+ if (Number.isInteger(y) && Number.isInteger(z)) {
1101
+ url = url.replace(/\{-y\}/g, String(Math.pow(2, z) - y - 1));
1171
1102
  }
1172
1103
  return url;
1173
1104
  }
@@ -1175,7 +1106,12 @@ function stringHash(s) {
1175
1106
  return Math.abs(s.split("").reduce((a, b) => (a << 5) - a + b.charCodeAt(0) | 0, 0));
1176
1107
  }
1177
1108
 
1178
- // dist/lib/geojson-tiler/simplify.js
1109
+ // dist/table-tile-source.js
1110
+ var import_loader_utils3 = require("@loaders.gl/loader-utils");
1111
+ var import_schema = require("@loaders.gl/schema");
1112
+ var import_stats = require("@probe.gl/stats");
1113
+
1114
+ // dist/lib/vector-tiler/simplify.js
1179
1115
  function simplify(coords, first, last, sqTolerance) {
1180
1116
  let maxSqDist = sqTolerance;
1181
1117
  const mid = last - first >> 1;
@@ -1185,15 +1121,15 @@ function simplify(coords, first, last, sqTolerance) {
1185
1121
  const ay = coords[first + 1];
1186
1122
  const bx = coords[last];
1187
1123
  const by = coords[last + 1];
1188
- for (let i2 = first + 3; i2 < last; i2 += 3) {
1189
- const d = getSqSegDist(coords[i2], coords[i2 + 1], ax, ay, bx, by);
1124
+ for (let i = first + 3; i < last; i += 3) {
1125
+ const d = getSqSegDist(coords[i], coords[i + 1], ax, ay, bx, by);
1190
1126
  if (d > maxSqDist) {
1191
- index = i2;
1127
+ index = i;
1192
1128
  maxSqDist = d;
1193
1129
  } else if (d === maxSqDist) {
1194
- const posToMid = Math.abs(i2 - mid);
1130
+ const posToMid = Math.abs(i - mid);
1195
1131
  if (posToMid < minPosToMid) {
1196
- index = i2;
1132
+ index = i;
1197
1133
  minPosToMid = posToMid;
1198
1134
  }
1199
1135
  }
@@ -1206,25 +1142,25 @@ function simplify(coords, first, last, sqTolerance) {
1206
1142
  simplify(coords, index, last, sqTolerance);
1207
1143
  }
1208
1144
  }
1209
- function getSqSegDist(px, py, x2, y2, bx, by) {
1210
- let dx = bx - x2;
1211
- let dy = by - y2;
1145
+ function getSqSegDist(px, py, x, y, bx, by) {
1146
+ let dx = bx - x;
1147
+ let dy = by - y;
1212
1148
  if (dx !== 0 || dy !== 0) {
1213
- const t = ((px - x2) * dx + (py - y2) * dy) / (dx * dx + dy * dy);
1149
+ const t = ((px - x) * dx + (py - y) * dy) / (dx * dx + dy * dy);
1214
1150
  if (t > 1) {
1215
- x2 = bx;
1216
- y2 = by;
1151
+ x = bx;
1152
+ y = by;
1217
1153
  } else if (t > 0) {
1218
- x2 += dx * t;
1219
- y2 += dy * t;
1154
+ x += dx * t;
1155
+ y += dy * t;
1220
1156
  }
1221
1157
  }
1222
- dx = px - x2;
1223
- dy = py - y2;
1158
+ dx = px - x;
1159
+ dy = py - y;
1224
1160
  return dx * dx + dy * dy;
1225
1161
  }
1226
1162
 
1227
- // dist/lib/geojson-tiler/feature.js
1163
+ // dist/lib/vector-tiler/feature.js
1228
1164
  function createFeature(id, type, geom, tags) {
1229
1165
  const feature = {
1230
1166
  // eslint-disable-next-line
@@ -1253,20 +1189,20 @@ function createFeature(id, type, geom, tags) {
1253
1189
  return feature;
1254
1190
  }
1255
1191
  function calcLineBBox(feature, geom) {
1256
- for (let i2 = 0; i2 < geom.length; i2 += 3) {
1257
- feature.minX = Math.min(feature.minX, geom[i2]);
1258
- feature.minY = Math.min(feature.minY, geom[i2 + 1]);
1259
- feature.maxX = Math.max(feature.maxX, geom[i2]);
1260
- feature.maxY = Math.max(feature.maxY, geom[i2 + 1]);
1192
+ for (let i = 0; i < geom.length; i += 3) {
1193
+ feature.minX = Math.min(feature.minX, geom[i]);
1194
+ feature.minY = Math.min(feature.minY, geom[i + 1]);
1195
+ feature.maxX = Math.max(feature.maxX, geom[i]);
1196
+ feature.maxY = Math.max(feature.maxY, geom[i + 1]);
1261
1197
  }
1262
1198
  }
1263
1199
 
1264
- // dist/lib/geojson-tiler/convert.js
1200
+ // dist/lib/vector-tiler/convert.js
1265
1201
  function convert(data, options) {
1266
1202
  const features = [];
1267
1203
  if (data.type === "FeatureCollection") {
1268
- for (let i2 = 0; i2 < data.features.length; i2++) {
1269
- convertFeature(features, data.features[i2], options, i2);
1204
+ for (let i = 0; i < data.features.length; i++) {
1205
+ convertFeature(features, data.features[i], options, i);
1270
1206
  }
1271
1207
  } else if (data.type === "Feature") {
1272
1208
  convertFeature(features, data, options);
@@ -1337,18 +1273,18 @@ function convertLine(ring, out, tolerance, isPolygon) {
1337
1273
  let x0, y0;
1338
1274
  let size = 0;
1339
1275
  for (let j = 0; j < ring.length; j++) {
1340
- const x2 = projectX(ring[j][0]);
1341
- const y2 = projectY(ring[j][1]);
1342
- out.push(x2, y2, 0);
1276
+ const x = projectX(ring[j][0]);
1277
+ const y = projectY(ring[j][1]);
1278
+ out.push(x, y, 0);
1343
1279
  if (j > 0) {
1344
1280
  if (isPolygon) {
1345
- size += (x0 * y2 - x2 * y0) / 2;
1281
+ size += (x0 * y - x * y0) / 2;
1346
1282
  } else {
1347
- size += Math.sqrt(Math.pow(x2 - x0, 2) + Math.pow(y2 - y0, 2));
1283
+ size += Math.sqrt(Math.pow(x - x0, 2) + Math.pow(y - y0, 2));
1348
1284
  }
1349
1285
  }
1350
- x0 = x2;
1351
- y0 = y2;
1286
+ x0 = x;
1287
+ y0 = y;
1352
1288
  }
1353
1289
  const last = out.length - 3;
1354
1290
  out[2] = 1;
@@ -1359,22 +1295,22 @@ function convertLine(ring, out, tolerance, isPolygon) {
1359
1295
  out.end = out.size;
1360
1296
  }
1361
1297
  function convertLines(rings, out, tolerance, isPolygon) {
1362
- for (let i2 = 0; i2 < rings.length; i2++) {
1298
+ for (let i = 0; i < rings.length; i++) {
1363
1299
  const geom = [];
1364
- convertLine(rings[i2], geom, tolerance, isPolygon);
1300
+ convertLine(rings[i], geom, tolerance, isPolygon);
1365
1301
  out.push(geom);
1366
1302
  }
1367
1303
  }
1368
- function projectX(x2) {
1369
- return x2 / 360 + 0.5;
1304
+ function projectX(x) {
1305
+ return x / 360 + 0.5;
1370
1306
  }
1371
- function projectY(y2) {
1372
- const sin = Math.sin(y2 * Math.PI / 180);
1373
- const y22 = 0.5 - 0.25 * Math.log((1 + sin) / (1 - sin)) / Math.PI;
1374
- return y22 < 0 ? 0 : y22 > 1 ? 1 : y22;
1307
+ function projectY(y) {
1308
+ const sin = Math.sin(y * Math.PI / 180);
1309
+ const y2 = 0.5 - 0.25 * Math.log((1 + sin) / (1 - sin)) / Math.PI;
1310
+ return y2 < 0 ? 0 : y2 > 1 ? 1 : y2;
1375
1311
  }
1376
1312
 
1377
- // dist/lib/geojson-tiler/clip.js
1313
+ // dist/lib/vector-tiler/clip.js
1378
1314
  function clip(features, scale, k1, k2, axis, minAll, maxAll, options) {
1379
1315
  k1 /= scale;
1380
1316
  k2 /= scale;
@@ -1437,10 +1373,10 @@ function clip(features, scale, k1, k2, axis, minAll, maxAll, options) {
1437
1373
  return clipped.length ? clipped : null;
1438
1374
  }
1439
1375
  function clipPoints(geom, newGeom, k1, k2, axis) {
1440
- for (let i2 = 0; i2 < geom.length; i2 += 3) {
1441
- const a = geom[i2 + axis];
1376
+ for (let i = 0; i < geom.length; i += 3) {
1377
+ const a = geom[i + axis];
1442
1378
  if (a >= k1 && a <= k2) {
1443
- addPoint(newGeom, geom[i2], geom[i2 + 1], geom[i2 + 2]);
1379
+ addPoint(newGeom, geom[i], geom[i + 1], geom[i + 2]);
1444
1380
  }
1445
1381
  }
1446
1382
  }
@@ -1450,12 +1386,12 @@ function clipLine(geom, newGeom, k1, k2, axis, isPolygon, trackMetrics) {
1450
1386
  let len = geom.start;
1451
1387
  let segLen;
1452
1388
  let t;
1453
- for (let i2 = 0; i2 < geom.length - 3; i2 += 3) {
1454
- const ax2 = geom[i2];
1455
- const ay2 = geom[i2 + 1];
1456
- const az2 = geom[i2 + 2];
1457
- const bx = geom[i2 + 3];
1458
- const by = geom[i2 + 4];
1389
+ for (let i = 0; i < geom.length - 3; i += 3) {
1390
+ const ax2 = geom[i];
1391
+ const ay2 = geom[i + 1];
1392
+ const az2 = geom[i + 2];
1393
+ const bx = geom[i + 3];
1394
+ const by = geom[i + 4];
1459
1395
  const a2 = axis === 0 ? ax2 : ay2;
1460
1396
  const b = axis === 0 ? bx : by;
1461
1397
  let exited = false;
@@ -1525,21 +1461,21 @@ function clipLines(geom, newGeom, k1, k2, axis, isPolygon) {
1525
1461
  clipLine(line, newGeom, k1, k2, axis, isPolygon, false);
1526
1462
  }
1527
1463
  }
1528
- function addPoint(out, x2, y2, z) {
1529
- out.push(x2, y2, z);
1464
+ function addPoint(out, x, y, z) {
1465
+ out.push(x, y, z);
1530
1466
  }
1531
- function intersectX(out, ax, ay, bx, by, x2) {
1532
- const t = (x2 - ax) / (bx - ax);
1533
- addPoint(out, x2, ay + (by - ay) * t, 1);
1467
+ function intersectX(out, ax, ay, bx, by, x) {
1468
+ const t = (x - ax) / (bx - ax);
1469
+ addPoint(out, x, ay + (by - ay) * t, 1);
1534
1470
  return t;
1535
1471
  }
1536
- function intersectY(out, ax, ay, bx, by, y2) {
1537
- const t = (y2 - ay) / (by - ay);
1538
- addPoint(out, ax + (bx - ax) * t, y2, 1);
1472
+ function intersectY(out, ax, ay, bx, by, y) {
1473
+ const t = (y - ay) / (by - ay);
1474
+ addPoint(out, ax + (bx - ax) * t, y, 1);
1539
1475
  return t;
1540
1476
  }
1541
1477
 
1542
- // dist/lib/geojson-tiler/wrap.js
1478
+ // dist/lib/vector-tiler/wrap.js
1543
1479
  function wrap(features, options) {
1544
1480
  const buffer = options.buffer / options.extent;
1545
1481
  let merged = features;
@@ -1558,8 +1494,8 @@ function wrap(features, options) {
1558
1494
  }
1559
1495
  function shiftFeatureCoords(features, offset) {
1560
1496
  const newFeatures = [];
1561
- for (let i2 = 0; i2 < features.length; i2++) {
1562
- const feature = features[i2];
1497
+ for (let i = 0; i < features.length; i++) {
1498
+ const feature = features[i];
1563
1499
  const type = feature.type;
1564
1500
  let newGeometry;
1565
1501
  if (type === "Point" || type === "MultiPoint" || type === "LineString") {
@@ -1590,13 +1526,13 @@ function shiftCoords(points, offset) {
1590
1526
  newPoints.start = points.start;
1591
1527
  newPoints.end = points.end;
1592
1528
  }
1593
- for (let i2 = 0; i2 < points.length; i2 += 3) {
1594
- newPoints.push(points[i2] + offset, points[i2 + 1], points[i2 + 2]);
1529
+ for (let i = 0; i < points.length; i += 3) {
1530
+ newPoints.push(points[i] + offset, points[i + 1], points[i + 2]);
1595
1531
  }
1596
1532
  return newPoints;
1597
1533
  }
1598
1534
 
1599
- // dist/lib/geojson-tiler/transform.js
1535
+ // dist/lib/vector-tiler/transform.js
1600
1536
  function transformTile(tile, extent) {
1601
1537
  if (tile.transformed) {
1602
1538
  return tile;
@@ -1625,11 +1561,11 @@ function transformTile(tile, extent) {
1625
1561
  tile.transformed = true;
1626
1562
  return tile;
1627
1563
  }
1628
- function transformPoint(x2, y2, extent, z2, tx, ty) {
1629
- return [Math.round(extent * (x2 * z2 - tx)), Math.round(extent * (y2 * z2 - ty))];
1564
+ function transformPoint(x, y, extent, z2, tx, ty) {
1565
+ return [Math.round(extent * (x * z2 - tx)), Math.round(extent * (y * z2 - ty))];
1630
1566
  }
1631
1567
 
1632
- // dist/lib/geojson-tiler/tile.js
1568
+ // dist/lib/vector-tiler/tile.js
1633
1569
  function createTile(features, z, tx, ty, options) {
1634
1570
  const tolerance = z === options.maxZoom ? 0 : options.tolerance / ((1 << z) * options.extent);
1635
1571
  const tile = {
@@ -1661,22 +1597,22 @@ function addFeature(tile, feature, tolerance, options) {
1661
1597
  tile.maxX = Math.max(tile.maxX, feature.maxX);
1662
1598
  tile.maxY = Math.max(tile.maxY, feature.maxY);
1663
1599
  if (type === "Point" || type === "MultiPoint") {
1664
- for (let i2 = 0; i2 < geom.length; i2 += 3) {
1665
- simplified.push(geom[i2], geom[i2 + 1]);
1600
+ for (let i = 0; i < geom.length; i += 3) {
1601
+ simplified.push(geom[i], geom[i + 1]);
1666
1602
  tile.numPoints++;
1667
1603
  tile.numSimplified++;
1668
1604
  }
1669
1605
  } else if (type === "LineString") {
1670
1606
  addLine(simplified, geom, tile, tolerance, false, false);
1671
1607
  } else if (type === "MultiLineString" || type === "Polygon") {
1672
- for (let i2 = 0; i2 < geom.length; i2++) {
1673
- addLine(simplified, geom[i2], tile, tolerance, type === "Polygon", i2 === 0);
1608
+ for (let i = 0; i < geom.length; i++) {
1609
+ addLine(simplified, geom[i], tile, tolerance, type === "Polygon", i === 0);
1674
1610
  }
1675
1611
  } else if (type === "MultiPolygon") {
1676
1612
  for (let k = 0; k < geom.length; k++) {
1677
1613
  const polygon = geom[k];
1678
- for (let i2 = 0; i2 < polygon.length; i2++) {
1679
- addLine(simplified, polygon[i2], tile, tolerance, true, i2 === 0);
1614
+ for (let i = 0; i < polygon.length; i++) {
1615
+ addLine(simplified, polygon[i], tile, tolerance, true, i === 0);
1680
1616
  }
1681
1617
  }
1682
1618
  }
@@ -1707,10 +1643,10 @@ function addLine(result, geom, tile, tolerance, isPolygon, isOuter) {
1707
1643
  return;
1708
1644
  }
1709
1645
  const ring = [];
1710
- for (let i2 = 0; i2 < geom.length; i2 += 3) {
1711
- if (tolerance === 0 || geom[i2 + 2] > sqTolerance) {
1646
+ for (let i = 0; i < geom.length; i += 3) {
1647
+ if (tolerance === 0 || geom[i + 2] > sqTolerance) {
1712
1648
  tile.numSimplified++;
1713
- ring.push(geom[i2], geom[i2 + 1]);
1649
+ ring.push(geom[i], geom[i + 1]);
1714
1650
  }
1715
1651
  tile.numPoints++;
1716
1652
  }
@@ -1720,106 +1656,147 @@ function addLine(result, geom, tile, tolerance, isPolygon, isOuter) {
1720
1656
  }
1721
1657
  function rewind(ring, clockwise) {
1722
1658
  let area = 0;
1723
- for (let i2 = 0, j = ring.length - 2; i2 < ring.length; j = i2, i2 += 2) {
1724
- area += (ring[i2] - ring[j]) * (ring[i2 + 1] + ring[j + 1]);
1659
+ for (let i = 0, j = ring.length - 2; i < ring.length; j = i, i += 2) {
1660
+ area += (ring[i] - ring[j]) * (ring[i + 1] + ring[j + 1]);
1725
1661
  }
1726
1662
  if (area > 0 === clockwise) {
1727
- for (let i2 = 0, len = ring.length; i2 < len / 2; i2 += 2) {
1728
- const x2 = ring[i2];
1729
- const y2 = ring[i2 + 1];
1730
- ring[i2] = ring[len - 2 - i2];
1731
- ring[i2 + 1] = ring[len - 1 - i2];
1732
- ring[len - 2 - i2] = x2;
1733
- ring[len - 1 - i2] = y2;
1663
+ for (let i = 0, len = ring.length; i < len / 2; i += 2) {
1664
+ const x = ring[i];
1665
+ const y = ring[i + 1];
1666
+ ring[i] = ring[len - 2 - i];
1667
+ ring[i + 1] = ring[len - 1 - i];
1668
+ ring[len - 2 - i] = x;
1669
+ ring[len - 1 - i] = y;
1734
1670
  }
1735
1671
  }
1736
1672
  }
1737
1673
 
1738
- // dist/lib/geojson-tiler/geojson-tiler.js
1739
- var DEFAULT_OPTIONS = {
1740
- maxZoom: 14,
1741
- // max zoom to preserve detail on
1742
- indexMaxZoom: 5,
1743
- // max zoom in the tile index
1744
- indexMaxPoints: 1e5,
1745
- // max number of points per tile in the tile index
1746
- tolerance: 3,
1747
- // simplification tolerance (higher means simpler)
1748
- extent: 4096,
1749
- // tile extent
1750
- buffer: 64,
1751
- // tile buffer on each side
1752
- lineMetrics: false,
1753
- // whether to calculate line metrics
1754
- // @ts-expect-error Ensures all these required params have defaults
1755
- promoteId: void 0,
1756
- // name of a feature property to be promoted to feature.id
1757
- generateId: false,
1758
- // whether to generate feature ids. Cannot be used with promoteId
1759
- debug: 0
1760
- // logging level (0, 1 or 2)
1761
- };
1762
- var GeoJSONTiler = class {
1763
- options;
1764
- // tiles and tileCoords are part of the public API
1674
+ // dist/table-tile-source.js
1675
+ var _TableTileSource = class {
1676
+ /** Stats for this TableTileSource */
1677
+ stats = new import_stats.Stats({
1678
+ id: "table-tile-source",
1679
+ stats: [new import_stats.Stat("tiles", "count"), new import_stats.Stat("features", "count")]
1680
+ });
1681
+ /** MIME type of the tiles emitted by this tile source */
1682
+ mimeType = "application/vnd.mapbox-vector-tile";
1683
+ localCoordinates = true;
1684
+ /** The props that this tile source was created with */
1685
+ props;
1686
+ /* Schema of the data */
1687
+ schema = null;
1688
+ /** Map of generated tiles, indexed by stringified tile coordinates */
1765
1689
  tiles = {};
1690
+ /** Array of tile coordinates */
1766
1691
  tileCoords = [];
1767
- stats = {};
1768
- total = 0;
1769
- constructor(data, options) {
1770
- this.options = { ...DEFAULT_OPTIONS, ...options };
1771
- options = this.options;
1772
- const debug = options.debug;
1773
- if (debug)
1774
- console.time("preprocess data");
1775
- if (this.options.maxZoom < 0 || this.options.maxZoom > 24) {
1692
+ /** Input data has loaded, initial top-level tiling is done, sync methods can now be called */
1693
+ ready;
1694
+ /** Metadata for the tile source (generated TileJSON/tilestats */
1695
+ metadata;
1696
+ constructor(table, props) {
1697
+ this.props = { ..._TableTileSource.defaultProps, ...props };
1698
+ this.getTileData = this.getTileData.bind(this);
1699
+ this.ready = this.initializeTilesAsync(table);
1700
+ this.metadata = this.getMetadata();
1701
+ }
1702
+ async initializeTilesAsync(tablePromise) {
1703
+ const table = await tablePromise;
1704
+ this.schema = (0, import_schema.deduceTableSchema)(table);
1705
+ this.createRootTiles(table);
1706
+ }
1707
+ async getMetadata() {
1708
+ await this.ready;
1709
+ return { schema: this.schema, minZoom: 0, maxZoom: this.props.maxZoom };
1710
+ }
1711
+ async getSchema() {
1712
+ await this.ready;
1713
+ return this.schema;
1714
+ }
1715
+ /**
1716
+ * Get a tile at the specified index
1717
+ * @param tileIndex z, x, y of tile
1718
+ * @returns
1719
+ */
1720
+ async getVectorTile(tileIndex) {
1721
+ await this.ready;
1722
+ const table = this.getTileSync(tileIndex);
1723
+ import_loader_utils3.log.info(2, "getVectorTile", tileIndex, table)();
1724
+ return table;
1725
+ }
1726
+ async getTile(tileIndex) {
1727
+ await this.ready;
1728
+ return this.getTileSync(tileIndex);
1729
+ }
1730
+ async getTileData(tileParams) {
1731
+ const { x, y, z } = tileParams.index;
1732
+ const tile = await this.getVectorTile({ x, y, z });
1733
+ return (tile == null ? void 0 : tile.features) || [];
1734
+ }
1735
+ // Implementation
1736
+ /**
1737
+ * Synchronously request a tile
1738
+ * @note Application must await `source.ready` before calling sync methods.
1739
+ */
1740
+ getTileSync(tileIndex) {
1741
+ const rawTile = this.getRawTile(tileIndex);
1742
+ if (!rawTile) {
1743
+ return null;
1744
+ }
1745
+ return convertToGeoJSONTable(rawTile, {
1746
+ coordinates: this.props.coordinates,
1747
+ tileIndex,
1748
+ extent: this.props.extent
1749
+ });
1750
+ }
1751
+ /**
1752
+ * Create the initial tiles
1753
+ * @note the tiles stores all the features together with additional data
1754
+ */
1755
+ createRootTiles(table) {
1756
+ if (this.props.maxZoom < 0 || this.props.maxZoom > 24) {
1776
1757
  throw new Error("maxZoom should be in the 0-24 range");
1777
1758
  }
1778
- if (options.promoteId && this.options.generateId) {
1759
+ if (this.props.promoteId && this.props.generateId) {
1779
1760
  throw new Error("promoteId and generateId cannot be used together.");
1780
1761
  }
1781
- let features = convert(data, options);
1782
- if (debug) {
1783
- console.timeEnd("preprocess data");
1784
- console.log("index: maxZoom: %d, maxPoints: %d", options.indexMaxZoom, options.indexMaxPoints);
1785
- console.time("generate tiles");
1786
- }
1787
- features = wrap(features, this.options);
1788
- if (features.length) {
1789
- this.splitTile(features, 0, 0, 0);
1790
- }
1791
- if (debug) {
1792
- if (features.length) {
1793
- console.log("features: %d, points: %d", this.tiles[0].numFeatures, this.tiles[0].numPoints);
1794
- }
1795
- console.timeEnd("generate tiles");
1796
- console.log("tiles generated:", this.total, JSON.stringify(this.stats));
1762
+ import_loader_utils3.log.log(1, "TableTileSource creating root tiles", this.props)();
1763
+ import_loader_utils3.log.time(1, "preprocess table")();
1764
+ let features = convert(table, this.props);
1765
+ import_loader_utils3.log.timeEnd(1, "preprocess table")();
1766
+ import_loader_utils3.log.time(1, "generate tiles")();
1767
+ features = wrap(features, this.props);
1768
+ if (features.length === 0) {
1769
+ import_loader_utils3.log.log(1, "TableTileSource: no features generated")();
1770
+ return;
1797
1771
  }
1772
+ this.splitTile(features, 0, 0, 0);
1773
+ const rootTile = this.tiles[0];
1774
+ import_loader_utils3.log.log(1, `root tile features: ${rootTile.numFeatures}, points: ${rootTile.numPoints}`)();
1775
+ import_loader_utils3.log.timeEnd(1, "generate tiles")();
1776
+ import_loader_utils3.log.log(1, `TableTileSource: tiles generated: ${this.stats.get("total").count}`, this.stats)();
1798
1777
  }
1799
1778
  /**
1800
- * Get a tile at the specified index
1801
- * @param z
1802
- * @param x
1803
- * @param y
1804
- * @returns
1779
+ * Return geojsonvt-style "half formed" vector tile
1780
+ * @note Application must await `source.ready` before calling sync methods.
1805
1781
  */
1806
1782
  // eslint-disable-next-line complexity, max-statements
1807
- getTile(z, x2, y2) {
1808
- const { extent, debug } = this.options;
1783
+ getRawTile(tileIndex) {
1784
+ const { z, y } = tileIndex;
1785
+ let { x } = tileIndex;
1786
+ const { extent } = this.props;
1809
1787
  if (z < 0 || z > 24) {
1810
1788
  return null;
1811
1789
  }
1812
1790
  const z2 = 1 << z;
1813
- x2 = x2 + z2 & z2 - 1;
1814
- const id = toID(z, x2, y2);
1791
+ x = x + z2 & z2 - 1;
1792
+ const id = toID(z, x, y);
1815
1793
  if (this.tiles[id]) {
1816
1794
  return transformTile(this.tiles[id], extent);
1817
1795
  }
1818
- if (debug > 1)
1819
- console.log("drilling down to z%d-%d-%d", z, x2, y2);
1796
+ import_loader_utils3.log.log(import_loader_utils3.log, "drilling down to z%d-%d-%d", z, x, y)();
1820
1797
  let z0 = z;
1821
- let x0 = x2;
1822
- let y0 = y2;
1798
+ let x0 = x;
1799
+ let y0 = y;
1823
1800
  let parent;
1824
1801
  while (!parent && z0 > 0) {
1825
1802
  z0--;
@@ -1830,14 +1807,10 @@ var GeoJSONTiler = class {
1830
1807
  if (!parent || !parent.source) {
1831
1808
  return null;
1832
1809
  }
1833
- if (debug > 1) {
1834
- console.log("found parent tile z%d-%d-%d", z0, x0, y0);
1835
- console.time("drilling down");
1836
- }
1837
- this.splitTile(parent.source, z0, x0, y0, z, x2, y2);
1838
- if (debug > 1) {
1839
- console.timeEnd("drilling down");
1840
- }
1810
+ import_loader_utils3.log.log(1, "found parent tile z%d-%d-%d", z0, x0, y0)();
1811
+ import_loader_utils3.log.time(1, "drilling down")();
1812
+ this.splitTile(parent.source, z0, x0, y0, z, x, y);
1813
+ import_loader_utils3.log.timeEnd(1, "drilling down")();
1841
1814
  return this.tiles[id] ? transformTile(this.tiles[id], extent) : null;
1842
1815
  }
1843
1816
  /**
@@ -1846,54 +1819,53 @@ var GeoJSONTiler = class {
1846
1819
  * @param cz, cx, and cy are the coordinates of the target tile
1847
1820
  *
1848
1821
  * If no target tile is specified, splitting stops when we reach the maximum
1849
- * zoom or the number of points is low as specified in the options.
1822
+ * zoom or the number of points is low as specified in the props.
1850
1823
  */
1851
1824
  // eslint-disable-next-line max-params, max-statements, complexity
1852
- splitTile(features, z, x2, y2, cz, cx, cy) {
1853
- const stack = [features, z, x2, y2];
1854
- const options = this.options;
1855
- const debug = options.debug;
1825
+ splitTile(features, z, x, y, cz, cx, cy) {
1826
+ const stack = [features, z, x, y];
1856
1827
  while (stack.length) {
1857
- y2 = stack.pop();
1858
- x2 = stack.pop();
1828
+ y = stack.pop();
1829
+ x = stack.pop();
1859
1830
  z = stack.pop();
1860
1831
  features = stack.pop();
1861
1832
  const z2 = 1 << z;
1862
- const id = toID(z, x2, y2);
1833
+ const id = toID(z, x, y);
1863
1834
  let tile = this.tiles[id];
1864
1835
  if (!tile) {
1865
- if (debug > 1) {
1866
- console.time("creation");
1867
- }
1868
- tile = this.tiles[id] = createTile(features, z, x2, y2, options);
1869
- this.tileCoords.push({ z, x: x2, y: y2 });
1870
- if (debug) {
1871
- if (debug > 1) {
1872
- console.log("tile z%d-%d-%d (features: %d, points: %d, simplified: %d)", z, x2, y2, tile.numFeatures, tile.numPoints, tile.numSimplified);
1873
- console.timeEnd("creation");
1874
- }
1875
- const key = `z${z}`;
1876
- this.stats[key] = (this.stats[key] || 0) + 1;
1877
- this.total++;
1878
- }
1836
+ import_loader_utils3.log.time(2, "tile creation")();
1837
+ tile = this.tiles[id] = createTile(features, z, x, y, this.props);
1838
+ this.tileCoords.push({ z, x, y });
1839
+ const key = `z${z}`;
1840
+ let stat = this.stats.get(key, "count");
1841
+ stat.incrementCount();
1842
+ stat = this.stats.get("total");
1843
+ stat.incrementCount();
1844
+ stat = _TableTileSource.stats.get(key, "count");
1845
+ stat.incrementCount();
1846
+ stat = _TableTileSource.stats.get("total");
1847
+ stat.incrementCount();
1848
+ import_loader_utils3.log.log(2, "tile z%d-%d-%d (features: %d, points: %d, simplified: %d)", z, x, y, tile.numFeatures, tile.numPoints, tile.numSimplified)();
1849
+ import_loader_utils3.log.timeEnd(2, "tile creation")();
1879
1850
  }
1880
1851
  tile.source = features;
1881
1852
  if (cz === void 0) {
1882
- if (z === options.indexMaxZoom || tile.numPoints <= options.indexMaxPoints)
1853
+ if (z === this.props.indexMaxZoom || tile.numPoints <= this.props.maxPointsPerTile) {
1883
1854
  continue;
1884
- } else if (z === options.maxZoom || z === cz) {
1855
+ }
1856
+ } else if (z === this.props.maxZoom || z === cz) {
1885
1857
  continue;
1886
1858
  } else if (cz !== void 0) {
1887
1859
  const zoomSteps = cz - z;
1888
- if (x2 !== cx >> zoomSteps || y2 !== cy >> zoomSteps)
1860
+ if (x !== cx >> zoomSteps || y !== cy >> zoomSteps) {
1889
1861
  continue;
1862
+ }
1890
1863
  }
1891
1864
  tile.source = null;
1892
1865
  if (features.length === 0)
1893
1866
  continue;
1894
- if (debug > 1)
1895
- console.time("clipping");
1896
- const k1 = 0.5 * options.buffer / options.extent;
1867
+ import_loader_utils3.log.time(2, "clipping tile")();
1868
+ const k1 = 0.5 * this.props.buffer / this.props.extent;
1897
1869
  const k2 = 0.5 - k1;
1898
1870
  const k3 = 0.5 + k1;
1899
1871
  const k4 = 1 + k1;
@@ -1901,29 +1873,130 @@ var GeoJSONTiler = class {
1901
1873
  let bl = null;
1902
1874
  let tr = null;
1903
1875
  let br = null;
1904
- let left = clip(features, z2, x2 - k1, x2 + k3, 0, tile.minX, tile.maxX, options);
1905
- let right = clip(features, z2, x2 + k2, x2 + k4, 0, tile.minX, tile.maxX, options);
1876
+ let left = clip(features, z2, x - k1, x + k3, 0, tile.minX, tile.maxX, this.props);
1877
+ let right = clip(features, z2, x + k2, x + k4, 0, tile.minX, tile.maxX, this.props);
1906
1878
  features = null;
1907
1879
  if (left) {
1908
- tl = clip(left, z2, y2 - k1, y2 + k3, 1, tile.minY, tile.maxY, options);
1909
- bl = clip(left, z2, y2 + k2, y2 + k4, 1, tile.minY, tile.maxY, options);
1880
+ tl = clip(left, z2, y - k1, y + k3, 1, tile.minY, tile.maxY, this.props);
1881
+ bl = clip(left, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, this.props);
1910
1882
  left = null;
1911
1883
  }
1912
1884
  if (right) {
1913
- tr = clip(right, z2, y2 - k1, y2 + k3, 1, tile.minY, tile.maxY, options);
1914
- br = clip(right, z2, y2 + k2, y2 + k4, 1, tile.minY, tile.maxY, options);
1885
+ tr = clip(right, z2, y - k1, y + k3, 1, tile.minY, tile.maxY, this.props);
1886
+ br = clip(right, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, this.props);
1915
1887
  right = null;
1916
1888
  }
1917
- if (debug > 1)
1918
- console.timeEnd("clipping");
1919
- stack.push(tl || [], z + 1, x2 * 2, y2 * 2);
1920
- stack.push(bl || [], z + 1, x2 * 2, y2 * 2 + 1);
1921
- stack.push(tr || [], z + 1, x2 * 2 + 1, y2 * 2);
1922
- stack.push(br || [], z + 1, x2 * 2 + 1, y2 * 2 + 1);
1889
+ import_loader_utils3.log.timeEnd(2, "clipping tile")();
1890
+ stack.push(tl || [], z + 1, x * 2, y * 2);
1891
+ stack.push(bl || [], z + 1, x * 2, y * 2 + 1);
1892
+ stack.push(tr || [], z + 1, x * 2 + 1, y * 2);
1893
+ stack.push(br || [], z + 1, x * 2 + 1, y * 2 + 1);
1923
1894
  }
1924
1895
  }
1925
1896
  };
1926
- function toID(z, x2, y2) {
1927
- return ((1 << z) * y2 + x2) * 32 + z;
1897
+ var TableTileSource = _TableTileSource;
1898
+ __publicField(TableTileSource, "defaultProps", {
1899
+ coordinates: "wgs84",
1900
+ // coordinates in tile coordinates or lng/lat
1901
+ maxZoom: 14,
1902
+ // max zoom to preserve detail on
1903
+ indexMaxZoom: 5,
1904
+ // max zoom in the tile index
1905
+ maxPointsPerTile: 1e5,
1906
+ // max number of points per tile in the tile index
1907
+ tolerance: 3,
1908
+ // simplification tolerance (higher means simpler)
1909
+ extent: 4096,
1910
+ // tile extent
1911
+ buffer: 64,
1912
+ // tile buffer on each side
1913
+ lineMetrics: false,
1914
+ // whether to calculate line metrics
1915
+ // @ts-expect-error
1916
+ promoteId: void 0,
1917
+ // name of a feature property to be promoted to feature.id
1918
+ generateId: false,
1919
+ // whether to generate feature ids. Cannot be used with promoteId
1920
+ debug: 0
1921
+ // logging level (0, 1 or 2)
1922
+ });
1923
+ /** Global stats for all TableTileSources */
1924
+ __publicField(TableTileSource, "stats", new import_stats.Stats({
1925
+ id: "table-tile-source-all",
1926
+ stats: [new import_stats.Stat("count", "tiles"), new import_stats.Stat("count", "features")]
1927
+ }));
1928
+ function toID(z, x, y) {
1929
+ return ((1 << z) * y + x) * 32 + z;
1930
+ }
1931
+ function convertToGeoJSONTable(vtTile, props) {
1932
+ const features = [];
1933
+ for (const rawFeature of vtTile.features) {
1934
+ if (!rawFeature || !rawFeature.geometry) {
1935
+ continue;
1936
+ }
1937
+ let type;
1938
+ let coordinates;
1939
+ switch (rawFeature.type) {
1940
+ case 1:
1941
+ if (rawFeature.geometry.length === 1) {
1942
+ type = "Point";
1943
+ coordinates = rawFeature.geometry[0];
1944
+ } else {
1945
+ type = "MultiPoint";
1946
+ coordinates = rawFeature.geometry;
1947
+ }
1948
+ break;
1949
+ case 2:
1950
+ if (rawFeature.geometry.length === 1) {
1951
+ type = "LineString";
1952
+ coordinates = rawFeature.geometry[0];
1953
+ } else {
1954
+ type = "MultiLineString";
1955
+ coordinates = rawFeature.geometry;
1956
+ }
1957
+ break;
1958
+ case 3:
1959
+ if (rawFeature.geometry.length > 1) {
1960
+ type = "MultiPolygon";
1961
+ coordinates = [rawFeature.geometry];
1962
+ } else {
1963
+ type = "Polygon";
1964
+ coordinates = rawFeature.geometry;
1965
+ }
1966
+ break;
1967
+ default:
1968
+ continue;
1969
+ }
1970
+ switch (props.coordinates) {
1971
+ case "EPSG:4326":
1972
+ case "wgs84":
1973
+ projectToLngLat(coordinates, props.tileIndex, props.extent);
1974
+ break;
1975
+ case "local":
1976
+ convertToLocalCoordinates(coordinates, props.extent);
1977
+ break;
1978
+ default:
1979
+ throw new Error(`Unsupported CRS ${props.coordinates}`);
1980
+ }
1981
+ const feature = {
1982
+ type: "Feature",
1983
+ geometry: {
1984
+ type,
1985
+ coordinates
1986
+ },
1987
+ properties: rawFeature.tags || {},
1988
+ id: rawFeature.id
1989
+ };
1990
+ features.push(feature);
1991
+ }
1992
+ if (features.length === 0) {
1993
+ return null;
1994
+ }
1995
+ const table = {
1996
+ shape: "geojson-table",
1997
+ type: "FeatureCollection",
1998
+ features
1999
+ };
2000
+ return table;
1928
2001
  }
1929
2002
  //# sourceMappingURL=index.cjs.map