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

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 (107) hide show
  1. package/dist/dist.dev.js +1311 -767
  2. package/dist/dist.min.js +1 -1
  3. package/dist/geojson-tile-source.d.ts +79 -0
  4. package/dist/geojson-tile-source.d.ts.map +1 -0
  5. package/dist/{lib/geojson-tiler/geojson-tiler.js → geojson-tile-source.js} +137 -27
  6. package/dist/index.cjs +568 -558
  7. package/dist/index.cjs.map +4 -4
  8. package/dist/index.d.ts +2 -2
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +1 -1
  11. package/dist/lib/geojsonvt/clip.d.ts.map +1 -0
  12. package/dist/lib/geojsonvt/convert.d.ts +10 -0
  13. package/dist/lib/geojsonvt/convert.d.ts.map +1 -0
  14. package/dist/lib/geojsonvt/feature.d.ts.map +1 -0
  15. package/dist/lib/geojsonvt/simplify.d.ts.map +1 -0
  16. package/dist/lib/geojsonvt/tile.d.ts.map +1 -0
  17. package/dist/lib/geojsonvt/transform.d.ts.map +1 -0
  18. package/dist/lib/geojsonvt/wrap.d.ts.map +1 -0
  19. package/dist/lib/parse-mvt.d.ts +3 -2
  20. package/dist/lib/parse-mvt.d.ts.map +1 -1
  21. package/dist/lib/parse-mvt.js +13 -15
  22. package/dist/lib/types.d.ts +1 -39
  23. package/dist/lib/types.d.ts.map +1 -1
  24. package/dist/lib/utils/geometry-utils.d.ts +46 -0
  25. package/dist/lib/utils/geometry-utils.d.ts.map +1 -0
  26. package/dist/{helpers/binary-util-functions.js → lib/utils/geometry-utils.js} +79 -46
  27. package/dist/lib/{binary-vector-tile → vector-tile}/vector-tile-feature.d.ts +27 -15
  28. package/dist/lib/vector-tile/vector-tile-feature.d.ts.map +1 -0
  29. package/dist/lib/vector-tile/vector-tile-feature.js +345 -0
  30. package/dist/lib/{mapbox-vector-tile → vector-tile}/vector-tile-layer.d.ts +10 -1
  31. package/dist/lib/vector-tile/vector-tile-layer.d.ts.map +1 -0
  32. package/dist/lib/{mapbox-vector-tile → vector-tile}/vector-tile-layer.js +16 -1
  33. package/dist/lib/vector-tile/vector-tile.d.ts.map +1 -0
  34. package/dist/mvt-loader.d.ts +20 -9
  35. package/dist/mvt-loader.d.ts.map +1 -1
  36. package/dist/mvt-loader.js +2 -1
  37. package/dist/mvt-source.js +4 -4
  38. package/dist/mvt-worker.js +1172 -735
  39. package/package.json +6 -6
  40. package/src/{lib/geojson-tiler/geojson-tiler.ts → geojson-tile-source.ts} +172 -33
  41. package/src/index.ts +3 -3
  42. package/src/lib/{geojson-tiler → geojsonvt}/convert.ts +2 -2
  43. package/src/lib/{geojson-tiler → geojsonvt}/tile.ts +2 -2
  44. package/src/lib/parse-mvt.ts +24 -33
  45. package/src/lib/types.ts +1 -39
  46. package/src/{helpers/binary-util-functions.ts → lib/utils/geometry-utils.ts} +92 -48
  47. package/src/lib/vector-tile/vector-tile-feature.ts +407 -0
  48. package/src/lib/{mapbox-vector-tile → vector-tile}/vector-tile-layer.ts +28 -2
  49. package/src/mvt-loader.ts +14 -6
  50. package/src/mvt-source.ts +4 -4
  51. package/dist/helpers/binary-util-functions.d.ts +0 -35
  52. package/dist/helpers/binary-util-functions.d.ts.map +0 -1
  53. package/dist/helpers/mapbox-util-functions.d.ts +0 -29
  54. package/dist/helpers/mapbox-util-functions.d.ts.map +0 -1
  55. package/dist/helpers/mapbox-util-functions.js +0 -78
  56. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +0 -1
  57. package/dist/lib/binary-vector-tile/vector-tile-feature.js +0 -163
  58. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts +0 -23
  59. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts.map +0 -1
  60. package/dist/lib/binary-vector-tile/vector-tile-layer.js +0 -96
  61. package/dist/lib/binary-vector-tile/vector-tile.d.ts +0 -9
  62. package/dist/lib/binary-vector-tile/vector-tile.d.ts.map +0 -1
  63. package/dist/lib/binary-vector-tile/vector-tile.js +0 -27
  64. package/dist/lib/geojson-tiler/clip.d.ts.map +0 -1
  65. package/dist/lib/geojson-tiler/convert.d.ts +0 -10
  66. package/dist/lib/geojson-tiler/convert.d.ts.map +0 -1
  67. package/dist/lib/geojson-tiler/feature.d.ts.map +0 -1
  68. package/dist/lib/geojson-tiler/geojson-tiler.d.ts +0 -44
  69. package/dist/lib/geojson-tiler/geojson-tiler.d.ts.map +0 -1
  70. package/dist/lib/geojson-tiler/simplify.d.ts.map +0 -1
  71. package/dist/lib/geojson-tiler/tile.d.ts.map +0 -1
  72. package/dist/lib/geojson-tiler/transform.d.ts.map +0 -1
  73. package/dist/lib/geojson-tiler/wrap.d.ts.map +0 -1
  74. package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts +0 -27
  75. package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts.map +0 -1
  76. package/dist/lib/mapbox-vector-tile/vector-tile-feature.js +0 -178
  77. package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts.map +0 -1
  78. package/dist/lib/mapbox-vector-tile/vector-tile.d.ts.map +0 -1
  79. package/src/helpers/mapbox-util-functions.ts +0 -82
  80. package/src/lib/binary-vector-tile/vector-tile-feature.ts +0 -203
  81. package/src/lib/binary-vector-tile/vector-tile-layer.ts +0 -113
  82. package/src/lib/binary-vector-tile/vector-tile.ts +0 -36
  83. package/src/lib/mapbox-vector-tile/LICENSE.txt +0 -31
  84. package/src/lib/mapbox-vector-tile/vector-tile-feature.ts +0 -207
  85. /package/dist/lib/{geojson-tiler → geojsonvt}/clip.d.ts +0 -0
  86. /package/dist/lib/{geojson-tiler → geojsonvt}/clip.js +0 -0
  87. /package/dist/lib/{geojson-tiler → geojsonvt}/convert.js +0 -0
  88. /package/dist/lib/{geojson-tiler → geojsonvt}/feature.d.ts +0 -0
  89. /package/dist/lib/{geojson-tiler → geojsonvt}/feature.js +0 -0
  90. /package/dist/lib/{geojson-tiler → geojsonvt}/simplify.d.ts +0 -0
  91. /package/dist/lib/{geojson-tiler → geojsonvt}/simplify.js +0 -0
  92. /package/dist/lib/{geojson-tiler → geojsonvt}/tile.d.ts +0 -0
  93. /package/dist/lib/{geojson-tiler → geojsonvt}/tile.js +0 -0
  94. /package/dist/lib/{geojson-tiler → geojsonvt}/transform.d.ts +0 -0
  95. /package/dist/lib/{geojson-tiler → geojsonvt}/transform.js +0 -0
  96. /package/dist/lib/{geojson-tiler → geojsonvt}/wrap.d.ts +0 -0
  97. /package/dist/lib/{geojson-tiler → geojsonvt}/wrap.js +0 -0
  98. /package/dist/lib/{mapbox-vector-tile → vector-tile}/vector-tile.d.ts +0 -0
  99. /package/dist/lib/{mapbox-vector-tile → vector-tile}/vector-tile.js +0 -0
  100. /package/src/lib/{geojson-tiler → geojsonvt}/LICENSE +0 -0
  101. /package/src/lib/{geojson-tiler → geojsonvt}/clip.ts +0 -0
  102. /package/src/lib/{geojson-tiler → geojsonvt}/feature.ts +0 -0
  103. /package/src/lib/{geojson-tiler → geojsonvt}/simplify.ts +0 -0
  104. /package/src/lib/{geojson-tiler → geojsonvt}/transform.ts +0 -0
  105. /package/src/lib/{geojson-tiler → geojsonvt}/wrap.ts +0 -0
  106. /package/src/lib/{binary-vector-tile → vector-tile}/LICENSE.txt +0 -0
  107. /package/src/lib/{mapbox-vector-tile → vector-tile}/vector-tile.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,11 +27,15 @@ 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,
38
+ GeoJSONTileSource: () => GeoJSONTileSource,
34
39
  MVTLoader: () => MVTLoader,
35
40
  MVTSource: () => MVTSource,
36
41
  MVTWorkerLoader: () => MVTWorkerLoader,
@@ -40,9 +45,31 @@ 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 projectToLngLatFlat(data, tileIndex, extent) {
63
+ const { x, y, z } = tileIndex;
64
+ const size = extent * Math.pow(2, z);
65
+ const x0 = extent * x;
66
+ const y0 = extent * y;
67
+ for (let j = 0, jl = data.length; j < jl; j += 2) {
68
+ data[j] = (data[j] + x0) * 360 / size - 180;
69
+ const y2 = 180 - (data[j + 1] + y0) * 360 / size;
70
+ data[j + 1] = 360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90;
71
+ }
72
+ }
46
73
  function classifyRings(rings) {
47
74
  const len = rings.length;
48
75
  if (len <= 1)
@@ -50,8 +77,8 @@ function classifyRings(rings) {
50
77
  const polygons = [];
51
78
  let polygon;
52
79
  let ccw;
53
- for (let i2 = 0; i2 < len; i2++) {
54
- const area = signedArea(rings[i2]);
80
+ for (let i = 0; i < len; i++) {
81
+ const area = signedArea(rings[i]);
55
82
  if (area === 0)
56
83
  continue;
57
84
  if (ccw === void 0)
@@ -59,294 +86,15 @@ function classifyRings(rings) {
59
86
  if (ccw === area < 0) {
60
87
  if (polygon)
61
88
  polygons.push(polygon);
62
- polygon = [rings[i2]];
89
+ polygon = [rings[i]];
63
90
  } else if (polygon)
64
- polygon.push(rings[i2]);
91
+ polygon.push(rings[i]);
65
92
  }
66
93
  if (polygon)
67
94
  polygons.push(polygon);
68
95
  return polygons;
69
96
  }
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) {
97
+ function classifyRingsFlat(geom) {
350
98
  const len = geom.indices.length;
351
99
  const type = "Polygon";
352
100
  if (len <= 1) {
@@ -363,9 +111,9 @@ function classifyRings2(geom) {
363
111
  let polygon = [];
364
112
  let ccw;
365
113
  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;
114
+ for (let endIndex, i = 0, startIndex; i < len; i++) {
115
+ startIndex = geom.indices[i] - offset;
116
+ endIndex = geom.indices[i + 1] - offset || geom.data.length;
369
117
  const shape = geom.data.slice(startIndex, endIndex);
370
118
  const area = (0, import_polygon.getPolygonSignedArea)(shape);
371
119
  if (area === 0) {
@@ -395,43 +143,9 @@ function classifyRings2(geom) {
395
143
  polygons.push(polygon);
396
144
  return { type, areas, indices: polygons, data: geom.data };
397
145
  }
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
146
 
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 {
147
+ // dist/lib/vector-tile/vector-tile-feature.js
148
+ var VectorTileFeature = class {
435
149
  properties;
436
150
  extent;
437
151
  type;
@@ -452,23 +166,55 @@ var BinaryVectorTileFeature = class {
452
166
  this._keys = keys;
453
167
  this._values = values;
454
168
  this._geometryInfo = geometryInfo;
455
- pbf.readFields(readFeature2, this, end);
169
+ pbf.readFields(readFeature, this, end);
456
170
  }
457
- // eslint-disable-next-line complexity, max-statements
458
- loadGeometry() {
171
+ toGeoJSON(options) {
172
+ const coords = this.loadGeometry();
173
+ if (typeof options === "function") {
174
+ return _toGeoJSON(this, coords, options);
175
+ }
176
+ const { x, y, z } = options;
177
+ const size = this.extent * Math.pow(2, z);
178
+ const x0 = this.extent * x;
179
+ const y0 = this.extent * y;
180
+ function project(line) {
181
+ for (let j = 0; j < line.length; j++) {
182
+ const p = line[j];
183
+ p[0] = (p[0] + x0) * 360 / size - 180;
184
+ const y2 = 180 - (p[1] + y0) * 360 / size;
185
+ p[1] = 360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90;
186
+ }
187
+ }
188
+ return _toGeoJSON(this, coords, project);
189
+ }
190
+ /**
191
+ *
192
+ * @param options
193
+ * @returns
194
+ */
195
+ toBinaryCoordinates(options) {
196
+ if (typeof options === "function") {
197
+ return this._toBinaryCoordinates(options);
198
+ }
199
+ const tileIndex = options;
200
+ return this._toBinaryCoordinates((data) => projectToLngLatFlat(data, tileIndex, this.extent));
201
+ }
202
+ // eslint-disable-next-line max-statements
203
+ bbox() {
459
204
  const pbf = this._pbf;
460
205
  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) {
206
+ const end = pbf.readVarint() + pbf.pos;
207
+ let cmd = 1;
208
+ let length = 0;
209
+ let x = 0;
210
+ let y = 0;
211
+ let x1 = Infinity;
212
+ let x2 = -Infinity;
213
+ let y1 = Infinity;
214
+ let y2 = -Infinity;
215
+ while (pbf.pos < end) {
470
216
  if (length <= 0) {
471
- cmdLen = pbf.readVarint();
217
+ const cmdLen = pbf.readVarint();
472
218
  cmd = cmdLen & 7;
473
219
  length = cmdLen >> 3;
474
220
  }
@@ -476,30 +222,28 @@ var BinaryVectorTileFeature = class {
476
222
  if (cmd === 1 || cmd === 2) {
477
223
  x += pbf.readSVarint();
478
224
  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 {
225
+ if (x < x1)
226
+ x1 = x;
227
+ if (x > x2)
228
+ x2 = x;
229
+ if (y < y1)
230
+ y1 = y;
231
+ if (y > y2)
232
+ y2 = y;
233
+ } else if (cmd !== 7) {
491
234
  throw new Error(`unknown command ${cmd}`);
492
235
  }
493
236
  }
494
- return { data, indices };
237
+ return [x1, y1, x2, y2];
495
238
  }
239
+ // BINARY HELPERS
496
240
  /**
497
241
  *
498
242
  * @param transform
499
243
  * @returns result
500
244
  */
501
245
  _toBinaryCoordinates(transform) {
502
- const geom = this.loadGeometry();
246
+ const geom = this.loadFlatGeometry();
503
247
  let geometry;
504
248
  transform(geom.data, this);
505
249
  const coordLength = 2;
@@ -516,7 +260,7 @@ var BinaryVectorTileFeature = class {
516
260
  geometry = { type: "LineString", ...geom };
517
261
  break;
518
262
  case 3:
519
- geometry = classifyRings2(geom);
263
+ geometry = classifyRingsFlat(geom);
520
264
  this._geometryInfo.polygonFeaturesCount++;
521
265
  this._geometryInfo.polygonObjectsCount += geometry.indices.length;
522
266
  for (const indices of geometry.indices) {
@@ -533,20 +277,165 @@ var BinaryVectorTileFeature = class {
533
277
  }
534
278
  return result;
535
279
  }
536
- toBinaryCoordinates(options) {
537
- if (typeof options === "function") {
538
- return this._toBinaryCoordinates(options);
280
+ // GEOJSON HELPER
281
+ // eslint-disable-next-line complexity, max-statements
282
+ loadGeometry() {
283
+ const pbf = this._pbf;
284
+ pbf.pos = this._geometry;
285
+ const end = pbf.readVarint() + pbf.pos;
286
+ let cmd = 1;
287
+ let length = 0;
288
+ let x = 0;
289
+ let y = 0;
290
+ const lines = [];
291
+ let line;
292
+ while (pbf.pos < end) {
293
+ if (length <= 0) {
294
+ const cmdLen = pbf.readVarint();
295
+ cmd = cmdLen & 7;
296
+ length = cmdLen >> 3;
297
+ }
298
+ length--;
299
+ switch (cmd) {
300
+ case 1:
301
+ case 2:
302
+ x += pbf.readSVarint();
303
+ y += pbf.readSVarint();
304
+ if (cmd === 1) {
305
+ if (line)
306
+ lines.push(line);
307
+ line = [];
308
+ }
309
+ if (line)
310
+ line.push([x, y]);
311
+ break;
312
+ case 7:
313
+ if (line) {
314
+ line.push(line[0].slice());
315
+ }
316
+ break;
317
+ default:
318
+ throw new Error(`unknown command ${cmd}`);
319
+ }
539
320
  }
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));
321
+ if (line)
322
+ lines.push(line);
323
+ return lines;
324
+ }
325
+ // eslint-disable-next-line complexity, max-statements
326
+ loadFlatGeometry() {
327
+ const pbf = this._pbf;
328
+ pbf.pos = this._geometry;
329
+ const endPos = pbf.readVarint() + pbf.pos;
330
+ let cmd = 1;
331
+ let cmdLen;
332
+ let length = 0;
333
+ let x = 0;
334
+ let y = 0;
335
+ let i = 0;
336
+ const indices = [];
337
+ const data = [];
338
+ while (pbf.pos < endPos) {
339
+ if (length <= 0) {
340
+ cmdLen = pbf.readVarint();
341
+ cmd = cmdLen & 7;
342
+ length = cmdLen >> 3;
343
+ }
344
+ length--;
345
+ if (cmd === 1 || cmd === 2) {
346
+ x += pbf.readSVarint();
347
+ y += pbf.readSVarint();
348
+ if (cmd === 1) {
349
+ indices.push(i);
350
+ }
351
+ data.push(x, y);
352
+ i += 2;
353
+ } else if (cmd === 7) {
354
+ if (i > 0) {
355
+ const start = indices[indices.length - 1];
356
+ data.push(data[start], data[start + 1]);
357
+ i += 2;
358
+ }
359
+ } else {
360
+ throw new Error(`unknown command ${cmd}`);
361
+ }
362
+ }
363
+ return { data, indices };
545
364
  }
546
365
  };
366
+ __publicField(VectorTileFeature, "types", ["Unknown", "Point", "LineString", "Polygon"]);
367
+ function _toGeoJSON(vtFeature, coords, transform) {
368
+ let type = VectorTileFeature.types[vtFeature.type];
369
+ let i;
370
+ let j;
371
+ let coordinates;
372
+ switch (vtFeature.type) {
373
+ case 1:
374
+ const points = [];
375
+ for (i = 0; i < coords.length; i++) {
376
+ points[i] = coords[i][0];
377
+ }
378
+ coordinates = points;
379
+ transform(coordinates, vtFeature);
380
+ break;
381
+ case 2:
382
+ coordinates = coords;
383
+ for (i = 0; i < coordinates.length; i++) {
384
+ transform(coordinates[i], vtFeature);
385
+ }
386
+ break;
387
+ case 3:
388
+ coordinates = classifyRings(coords);
389
+ for (i = 0; i < coordinates.length; i++) {
390
+ for (j = 0; j < coordinates[i].length; j++) {
391
+ transform(coordinates[i][j], vtFeature);
392
+ }
393
+ }
394
+ break;
395
+ default:
396
+ throw new Error("illegal vector tile type");
397
+ }
398
+ if (coordinates.length === 1) {
399
+ coordinates = coordinates[0];
400
+ } else {
401
+ type = `Multi${type}`;
402
+ }
403
+ const result = {
404
+ type: "Feature",
405
+ geometry: {
406
+ type,
407
+ coordinates
408
+ },
409
+ properties: vtFeature.properties
410
+ };
411
+ if (vtFeature.id !== null) {
412
+ result.id = vtFeature.id;
413
+ }
414
+ return result;
415
+ }
416
+ function readFeature(tag, feature, pbf) {
417
+ if (feature && pbf) {
418
+ if (tag === 1)
419
+ feature.id = pbf.readVarint();
420
+ else if (tag === 2)
421
+ readTag(pbf, feature);
422
+ else if (tag === 3)
423
+ feature.type = pbf.readVarint();
424
+ else if (tag === 4)
425
+ feature._geometry = pbf.pos;
426
+ }
427
+ }
428
+ function readTag(pbf, feature) {
429
+ const end = pbf.readVarint() + pbf.pos;
430
+ while (pbf.pos < end) {
431
+ const key = feature._keys[pbf.readVarint()];
432
+ const value = feature._values[pbf.readVarint()];
433
+ feature.properties[key] = value;
434
+ }
435
+ }
547
436
 
548
- // dist/lib/binary-vector-tile/vector-tile-layer.js
549
- var BinaryVectorTileLayer = class {
437
+ // dist/lib/vector-tile/vector-tile-layer.js
438
+ var VectorTileLayer = class {
550
439
  version;
551
440
  name;
552
441
  extent;
@@ -564,26 +453,39 @@ var BinaryVectorTileLayer = class {
564
453
  this._keys = [];
565
454
  this._values = [];
566
455
  this._features = [];
567
- pbf.readFields(readLayer2, this, end);
456
+ pbf.readFields(readLayer, this, end);
568
457
  this.length = this._features.length;
569
458
  }
570
459
  /**
571
- * return feature `i` from this layer as a `BinaryVectorTileFeature`
460
+ * return feature `i` from this layer as a `VectorTileFeature`
461
+ * @param index
462
+ * @returns feature
463
+ */
464
+ getGeoJSONFeature(i) {
465
+ if (i < 0 || i >= this._features.length) {
466
+ throw new Error("feature index out of bounds");
467
+ }
468
+ this._pbf.pos = this._features[i];
469
+ const end = this._pbf.readVarint() + this._pbf.pos;
470
+ return new VectorTileFeature(this._pbf, end, this.extent, this._keys, this._values);
471
+ }
472
+ /**
473
+ * return binary feature `i` from this layer as a `VectorTileFeature`
572
474
  *
573
475
  * @param index
574
476
  * @param geometryInfo
575
- * @returns {BinaryVectorTileFeature}
477
+ * @returns binary feature
576
478
  */
577
- feature(i2, geometryInfo) {
578
- if (i2 < 0 || i2 >= this._features.length) {
479
+ getBinaryFeature(i, geometryInfo) {
480
+ if (i < 0 || i >= this._features.length) {
579
481
  throw new Error("feature index out of bounds");
580
482
  }
581
- this._pbf.pos = this._features[i2];
483
+ this._pbf.pos = this._features[i];
582
484
  const end = this._pbf.readVarint() + this._pbf.pos;
583
- return new BinaryVectorTileFeature(this._pbf, end, this.extent, this._keys, this._values, geometryInfo);
485
+ return new VectorTileFeature(this._pbf, end, this.extent, this._keys, this._values, geometryInfo);
584
486
  }
585
487
  };
586
- function readLayer2(tag, layer, pbf) {
488
+ function readLayer(tag, layer, pbf) {
587
489
  if (layer && pbf) {
588
490
  if (tag === 15)
589
491
  layer.version = pbf.readVarint();
@@ -596,10 +498,10 @@ function readLayer2(tag, layer, pbf) {
596
498
  else if (tag === 3)
597
499
  layer._keys.push(pbf.readString());
598
500
  else if (tag === 4)
599
- layer._values.push(readValueMessage2(pbf));
501
+ layer._values.push(readValueMessage(pbf));
600
502
  }
601
503
  }
602
- function readValueMessage2(pbf) {
504
+ function readValueMessage(pbf) {
603
505
  let value = null;
604
506
  const end = pbf.readVarint() + pbf.pos;
605
507
  while (pbf.pos < end) {
@@ -609,17 +511,17 @@ function readValueMessage2(pbf) {
609
511
  return value;
610
512
  }
611
513
 
612
- // dist/lib/binary-vector-tile/vector-tile.js
613
- var BinaryVectorTile = class {
514
+ // dist/lib/vector-tile/vector-tile.js
515
+ var VectorTile = class {
614
516
  layers;
615
517
  constructor(pbf, end) {
616
- this.layers = pbf.readFields(readTile2, {}, end);
518
+ this.layers = pbf.readFields(readTile, {}, end);
617
519
  }
618
520
  };
619
- function readTile2(tag, layers, pbf) {
521
+ function readTile(tag, layers, pbf) {
620
522
  if (tag === 3) {
621
523
  if (pbf) {
622
- const layer = new BinaryVectorTileLayer(pbf, pbf.readVarint() + pbf.pos);
524
+ const layer = new VectorTileLayer(pbf, pbf.readVarint() + pbf.pos);
623
525
  if (layer.length && layers) {
624
526
  layers[layer.name] = layer;
625
527
  }
@@ -630,7 +532,7 @@ function readTile2(tag, layers, pbf) {
630
532
  // dist/lib/parse-mvt.js
631
533
  function parseMVT(arrayBuffer, options) {
632
534
  var _a, _b;
633
- const mvtOptions = normalizeOptions(options);
535
+ const mvtOptions = checkOptions(options);
634
536
  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
537
  switch (shape) {
636
538
  case "columnar-table":
@@ -676,15 +578,15 @@ function parseToFlatGeoJson(arrayBuffer, options) {
676
578
  if (arrayBuffer.byteLength <= 0) {
677
579
  return [features, geometryInfo];
678
580
  }
679
- const tile = new BinaryVectorTile(new import_pbf.default(arrayBuffer));
581
+ const tile = new VectorTile(new import_pbf.default(arrayBuffer));
680
582
  const selectedLayers = options && Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);
681
583
  selectedLayers.forEach((layerName) => {
682
584
  const vectorTileLayer = tile.layers[layerName];
683
585
  if (!vectorTileLayer) {
684
586
  return;
685
587
  }
686
- for (let i2 = 0; i2 < vectorTileLayer.length; i2++) {
687
- const vectorTileFeature = vectorTileLayer.feature(i2, geometryInfo);
588
+ for (let i = 0; i < vectorTileLayer.length; i++) {
589
+ const vectorTileFeature = vectorTileLayer.getBinaryFeature(i, geometryInfo);
688
590
  const decodedFeature = getDecodedFeatureBinary(vectorTileFeature, options, layerName);
689
591
  features.push(decodedFeature);
690
592
  }
@@ -703,25 +605,25 @@ function parseToGeojsonFeatures(arrayBuffer, options) {
703
605
  if (!vectorTileLayer) {
704
606
  return;
705
607
  }
706
- for (let i2 = 0; i2 < vectorTileLayer.length; i2++) {
707
- const vectorTileFeature = vectorTileLayer.feature(i2);
608
+ for (let i = 0; i < vectorTileLayer.length; i++) {
609
+ const vectorTileFeature = vectorTileLayer.getGeoJSONFeature(i);
708
610
  const decodedFeature = getDecodedFeature(vectorTileFeature, options, layerName);
709
611
  features.push(decodedFeature);
710
612
  }
711
613
  });
712
614
  return features;
713
615
  }
714
- function normalizeOptions(options) {
616
+ function checkOptions(options) {
715
617
  var _a;
716
618
  if (!(options == null ? void 0 : options.mvt)) {
717
619
  throw new Error("mvt options required");
718
620
  }
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) {
621
+ if (((_a = options.mvt) == null ? void 0 : _a.coordinates) === "wgs84" && !options.mvt.tileIndex) {
723
622
  throw new Error("MVT Loader: WGS84 coordinates need tileIndex property");
724
623
  }
624
+ if (options.gis) {
625
+ import_loader_utils.log.warn('MVTLoader: "options.gis" is deprecated, use "options.mvt.shape" instead')();
626
+ }
725
627
  return options.mvt;
726
628
  }
727
629
  function getDecodedFeature(feature, options, layerName) {
@@ -730,6 +632,7 @@ function getDecodedFeature(feature, options, layerName) {
730
632
  options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinates
731
633
  );
732
634
  if (options.layerProperty) {
635
+ decodedFeature.properties ||= {};
733
636
  decodedFeature.properties[options.layerProperty] = layerName;
734
637
  }
735
638
  return decodedFeature;
@@ -746,16 +649,16 @@ function getDecodedFeatureBinary(feature, options, layerName) {
746
649
  }
747
650
  function transformToLocalCoordinates(line, feature) {
748
651
  const { extent } = feature;
749
- for (let i2 = 0; i2 < line.length; i2++) {
750
- const p = line[i2];
652
+ for (let i = 0; i < line.length; i++) {
653
+ const p = line[i];
751
654
  p[0] /= extent;
752
655
  p[1] /= extent;
753
656
  }
754
657
  }
755
658
  function transformToLocalCoordinatesBinary(data, feature) {
756
659
  const { extent } = feature;
757
- for (let i2 = 0, il = data.length; i2 < il; ++i2) {
758
- data[i2] /= extent;
660
+ for (let i = 0, il = data.length; i < il; ++i) {
661
+ data[i] /= extent;
759
662
  }
760
663
  }
761
664
 
@@ -784,7 +687,7 @@ var MVTWorkerLoader = {
784
687
  coordinates: "local",
785
688
  layerProperty: "layerName",
786
689
  layers: void 0,
787
- tileIndex: null
690
+ tileIndex: void 0
788
691
  }
789
692
  }
790
693
  };
@@ -796,7 +699,7 @@ var MVTLoader = {
796
699
  };
797
700
 
798
701
  // dist/lib/parse-tilejson.js
799
- var isObject = (x2) => x2 !== null && typeof x2 === "object";
702
+ var isObject = (x) => x !== null && typeof x === "object";
800
703
  function parseTileJSON(jsonMetadata, options) {
801
704
  var _a;
802
705
  if (!jsonMetadata || !isObject(jsonMetadata)) {
@@ -1033,10 +936,10 @@ var TileJSONLoader = {
1033
936
  };
1034
937
 
1035
938
  // dist/mvt-source.js
1036
- var import_loader_utils = require("@loaders.gl/loader-utils");
939
+ var import_loader_utils2 = require("@loaders.gl/loader-utils");
1037
940
  var import_images = require("@loaders.gl/images");
1038
941
  var import_mvt = require("@loaders.gl/mvt");
1039
- var MVTSource = class extends import_loader_utils.DataSource {
942
+ var MVTSource = class extends import_loader_utils2.DataSource {
1040
943
  props;
1041
944
  url;
1042
945
  metadataUrl = null;
@@ -1048,7 +951,7 @@ var MVTSource = class extends import_loader_utils.DataSource {
1048
951
  constructor(props) {
1049
952
  super(props);
1050
953
  this.props = props;
1051
- this.url = (0, import_loader_utils.resolvePath)(props.url);
954
+ this.url = (0, import_loader_utils2.resolvePath)(props.url);
1052
955
  this.metadataUrl = props.metadataUrl === void 0 ? `${this.url}/tilejson.json` : props.metadataUrl;
1053
956
  this.extension = props.extension || ".png";
1054
957
  this.data = this.url;
@@ -1083,8 +986,8 @@ var MVTSource = class extends import_loader_utils.DataSource {
1083
986
  return this.mimeType;
1084
987
  }
1085
988
  async getTile(tileParams) {
1086
- const { x: x2, y: y2, zoom: z } = tileParams;
1087
- const tileUrl = this.getTileURL(x2, y2, z);
989
+ const { x, y, z } = tileParams;
990
+ const tileUrl = this.getTileURL(x, y, z);
1088
991
  const response = await this.fetch(tileUrl);
1089
992
  if (!response.ok) {
1090
993
  return null;
@@ -1095,8 +998,8 @@ var MVTSource = class extends import_loader_utils.DataSource {
1095
998
  // Tile Source interface implementation: deck.gl compatible API
1096
999
  // TODO - currently only handles image tiles, not vector tiles
1097
1000
  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: [] });
1001
+ const { x, y, z } = tileParams.index;
1002
+ const arrayBuffer = await this.getTile({ x, y, z, layers: [] });
1100
1003
  if (arrayBuffer === null) {
1101
1004
  return null;
1102
1005
  }
@@ -1104,7 +1007,7 @@ var MVTSource = class extends import_loader_utils.DataSource {
1104
1007
  this.mimeType = this.mimeType || (imageMetadata == null ? void 0 : imageMetadata.mimeType) || "application/vnd.mapbox-vector-tile";
1105
1008
  switch (this.mimeType) {
1106
1009
  case "application/vnd.mapbox-vector-tile":
1107
- return await this._parseVectorTile(arrayBuffer, { x: x2, y: y2, zoom: z, layers: [] });
1010
+ return await this._parseVectorTile(arrayBuffer, { x, y, z, layers: [] });
1108
1011
  default:
1109
1012
  return await this._parseImageTile(arrayBuffer);
1110
1013
  }
@@ -1128,7 +1031,7 @@ var MVTSource = class extends import_loader_utils.DataSource {
1128
1031
  shape: "geojson-table",
1129
1032
  mvt: {
1130
1033
  coordinates: "wgs84",
1131
- tileIndex: { x: tileParams.x, y: tileParams.y, z: tileParams.zoom },
1034
+ tileIndex: { x: tileParams.x, y: tileParams.y, z: tileParams.z },
1132
1035
  ...(_a = this.loadOptions) == null ? void 0 : _a.mvt
1133
1036
  },
1134
1037
  ...this.loadOptions
@@ -1138,14 +1041,14 @@ var MVTSource = class extends import_loader_utils.DataSource {
1138
1041
  getMetadataUrl() {
1139
1042
  return this.metadataUrl;
1140
1043
  }
1141
- getTileURL(x2, y2, z) {
1044
+ getTileURL(x, y, z) {
1142
1045
  switch (this.schema) {
1143
1046
  case "xyz":
1144
- return `${this.url}/${x2}/${y2}/${z}${this.extension}`;
1047
+ return `${this.url}/${x}/${y}/${z}${this.extension}`;
1145
1048
  case "tms":
1146
- return `${this.url}/${z}/${x2}/${y2}${this.extension}`;
1049
+ return `${this.url}/${z}/${x}/${y}${this.extension}`;
1147
1050
  case "template":
1148
- return getURLFromTemplate(this.url, x2, y2, z, "0");
1051
+ return getURLFromTemplate(this.url, x, y, z, "0");
1149
1052
  default:
1150
1053
  throw new Error(this.schema);
1151
1054
  }
@@ -1157,17 +1060,17 @@ function isURLTemplate(s) {
1157
1060
  var xRegex = new RegExp("{x}", "g");
1158
1061
  var yRegex = new RegExp("{y}", "g");
1159
1062
  var zRegex = new RegExp("{z}", "g");
1160
- function getURLFromTemplate(template, x2, y2, z, id = "0") {
1063
+ function getURLFromTemplate(template, x, y, z, id = "0") {
1161
1064
  if (Array.isArray(template)) {
1162
- const i2 = stringHash(id) % template.length;
1163
- template = template[i2];
1065
+ const i = stringHash(id) % template.length;
1066
+ template = template[i];
1164
1067
  }
1165
1068
  let url = template;
1166
- url = url.replace(xRegex, String(x2));
1167
- url = url.replace(yRegex, String(y2));
1069
+ url = url.replace(xRegex, String(x));
1070
+ url = url.replace(yRegex, String(y));
1168
1071
  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));
1072
+ if (Number.isInteger(y) && Number.isInteger(z)) {
1073
+ url = url.replace(/\{-y\}/g, String(Math.pow(2, z) - y - 1));
1171
1074
  }
1172
1075
  return url;
1173
1076
  }
@@ -1175,7 +1078,7 @@ function stringHash(s) {
1175
1078
  return Math.abs(s.split("").reduce((a, b) => (a << 5) - a + b.charCodeAt(0) | 0, 0));
1176
1079
  }
1177
1080
 
1178
- // dist/lib/geojson-tiler/simplify.js
1081
+ // dist/lib/geojsonvt/simplify.js
1179
1082
  function simplify(coords, first, last, sqTolerance) {
1180
1083
  let maxSqDist = sqTolerance;
1181
1084
  const mid = last - first >> 1;
@@ -1185,15 +1088,15 @@ function simplify(coords, first, last, sqTolerance) {
1185
1088
  const ay = coords[first + 1];
1186
1089
  const bx = coords[last];
1187
1090
  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);
1091
+ for (let i = first + 3; i < last; i += 3) {
1092
+ const d = getSqSegDist(coords[i], coords[i + 1], ax, ay, bx, by);
1190
1093
  if (d > maxSqDist) {
1191
- index = i2;
1094
+ index = i;
1192
1095
  maxSqDist = d;
1193
1096
  } else if (d === maxSqDist) {
1194
- const posToMid = Math.abs(i2 - mid);
1097
+ const posToMid = Math.abs(i - mid);
1195
1098
  if (posToMid < minPosToMid) {
1196
- index = i2;
1099
+ index = i;
1197
1100
  minPosToMid = posToMid;
1198
1101
  }
1199
1102
  }
@@ -1206,25 +1109,25 @@ function simplify(coords, first, last, sqTolerance) {
1206
1109
  simplify(coords, index, last, sqTolerance);
1207
1110
  }
1208
1111
  }
1209
- function getSqSegDist(px, py, x2, y2, bx, by) {
1210
- let dx = bx - x2;
1211
- let dy = by - y2;
1112
+ function getSqSegDist(px, py, x, y, bx, by) {
1113
+ let dx = bx - x;
1114
+ let dy = by - y;
1212
1115
  if (dx !== 0 || dy !== 0) {
1213
- const t = ((px - x2) * dx + (py - y2) * dy) / (dx * dx + dy * dy);
1116
+ const t = ((px - x) * dx + (py - y) * dy) / (dx * dx + dy * dy);
1214
1117
  if (t > 1) {
1215
- x2 = bx;
1216
- y2 = by;
1118
+ x = bx;
1119
+ y = by;
1217
1120
  } else if (t > 0) {
1218
- x2 += dx * t;
1219
- y2 += dy * t;
1121
+ x += dx * t;
1122
+ y += dy * t;
1220
1123
  }
1221
1124
  }
1222
- dx = px - x2;
1223
- dy = py - y2;
1125
+ dx = px - x;
1126
+ dy = py - y;
1224
1127
  return dx * dx + dy * dy;
1225
1128
  }
1226
1129
 
1227
- // dist/lib/geojson-tiler/feature.js
1130
+ // dist/lib/geojsonvt/feature.js
1228
1131
  function createFeature(id, type, geom, tags) {
1229
1132
  const feature = {
1230
1133
  // eslint-disable-next-line
@@ -1253,20 +1156,20 @@ function createFeature(id, type, geom, tags) {
1253
1156
  return feature;
1254
1157
  }
1255
1158
  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]);
1159
+ for (let i = 0; i < geom.length; i += 3) {
1160
+ feature.minX = Math.min(feature.minX, geom[i]);
1161
+ feature.minY = Math.min(feature.minY, geom[i + 1]);
1162
+ feature.maxX = Math.max(feature.maxX, geom[i]);
1163
+ feature.maxY = Math.max(feature.maxY, geom[i + 1]);
1261
1164
  }
1262
1165
  }
1263
1166
 
1264
- // dist/lib/geojson-tiler/convert.js
1167
+ // dist/lib/geojsonvt/convert.js
1265
1168
  function convert(data, options) {
1266
1169
  const features = [];
1267
1170
  if (data.type === "FeatureCollection") {
1268
- for (let i2 = 0; i2 < data.features.length; i2++) {
1269
- convertFeature(features, data.features[i2], options, i2);
1171
+ for (let i = 0; i < data.features.length; i++) {
1172
+ convertFeature(features, data.features[i], options, i);
1270
1173
  }
1271
1174
  } else if (data.type === "Feature") {
1272
1175
  convertFeature(features, data, options);
@@ -1337,18 +1240,18 @@ function convertLine(ring, out, tolerance, isPolygon) {
1337
1240
  let x0, y0;
1338
1241
  let size = 0;
1339
1242
  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);
1243
+ const x = projectX(ring[j][0]);
1244
+ const y = projectY(ring[j][1]);
1245
+ out.push(x, y, 0);
1343
1246
  if (j > 0) {
1344
1247
  if (isPolygon) {
1345
- size += (x0 * y2 - x2 * y0) / 2;
1248
+ size += (x0 * y - x * y0) / 2;
1346
1249
  } else {
1347
- size += Math.sqrt(Math.pow(x2 - x0, 2) + Math.pow(y2 - y0, 2));
1250
+ size += Math.sqrt(Math.pow(x - x0, 2) + Math.pow(y - y0, 2));
1348
1251
  }
1349
1252
  }
1350
- x0 = x2;
1351
- y0 = y2;
1253
+ x0 = x;
1254
+ y0 = y;
1352
1255
  }
1353
1256
  const last = out.length - 3;
1354
1257
  out[2] = 1;
@@ -1359,22 +1262,22 @@ function convertLine(ring, out, tolerance, isPolygon) {
1359
1262
  out.end = out.size;
1360
1263
  }
1361
1264
  function convertLines(rings, out, tolerance, isPolygon) {
1362
- for (let i2 = 0; i2 < rings.length; i2++) {
1265
+ for (let i = 0; i < rings.length; i++) {
1363
1266
  const geom = [];
1364
- convertLine(rings[i2], geom, tolerance, isPolygon);
1267
+ convertLine(rings[i], geom, tolerance, isPolygon);
1365
1268
  out.push(geom);
1366
1269
  }
1367
1270
  }
1368
- function projectX(x2) {
1369
- return x2 / 360 + 0.5;
1271
+ function projectX(x) {
1272
+ return x / 360 + 0.5;
1370
1273
  }
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;
1274
+ function projectY(y) {
1275
+ const sin = Math.sin(y * Math.PI / 180);
1276
+ const y2 = 0.5 - 0.25 * Math.log((1 + sin) / (1 - sin)) / Math.PI;
1277
+ return y2 < 0 ? 0 : y2 > 1 ? 1 : y2;
1375
1278
  }
1376
1279
 
1377
- // dist/lib/geojson-tiler/clip.js
1280
+ // dist/lib/geojsonvt/clip.js
1378
1281
  function clip(features, scale, k1, k2, axis, minAll, maxAll, options) {
1379
1282
  k1 /= scale;
1380
1283
  k2 /= scale;
@@ -1437,10 +1340,10 @@ function clip(features, scale, k1, k2, axis, minAll, maxAll, options) {
1437
1340
  return clipped.length ? clipped : null;
1438
1341
  }
1439
1342
  function clipPoints(geom, newGeom, k1, k2, axis) {
1440
- for (let i2 = 0; i2 < geom.length; i2 += 3) {
1441
- const a = geom[i2 + axis];
1343
+ for (let i = 0; i < geom.length; i += 3) {
1344
+ const a = geom[i + axis];
1442
1345
  if (a >= k1 && a <= k2) {
1443
- addPoint(newGeom, geom[i2], geom[i2 + 1], geom[i2 + 2]);
1346
+ addPoint(newGeom, geom[i], geom[i + 1], geom[i + 2]);
1444
1347
  }
1445
1348
  }
1446
1349
  }
@@ -1450,12 +1353,12 @@ function clipLine(geom, newGeom, k1, k2, axis, isPolygon, trackMetrics) {
1450
1353
  let len = geom.start;
1451
1354
  let segLen;
1452
1355
  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];
1356
+ for (let i = 0; i < geom.length - 3; i += 3) {
1357
+ const ax2 = geom[i];
1358
+ const ay2 = geom[i + 1];
1359
+ const az2 = geom[i + 2];
1360
+ const bx = geom[i + 3];
1361
+ const by = geom[i + 4];
1459
1362
  const a2 = axis === 0 ? ax2 : ay2;
1460
1363
  const b = axis === 0 ? bx : by;
1461
1364
  let exited = false;
@@ -1525,21 +1428,21 @@ function clipLines(geom, newGeom, k1, k2, axis, isPolygon) {
1525
1428
  clipLine(line, newGeom, k1, k2, axis, isPolygon, false);
1526
1429
  }
1527
1430
  }
1528
- function addPoint(out, x2, y2, z) {
1529
- out.push(x2, y2, z);
1431
+ function addPoint(out, x, y, z) {
1432
+ out.push(x, y, z);
1530
1433
  }
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);
1434
+ function intersectX(out, ax, ay, bx, by, x) {
1435
+ const t = (x - ax) / (bx - ax);
1436
+ addPoint(out, x, ay + (by - ay) * t, 1);
1534
1437
  return t;
1535
1438
  }
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);
1439
+ function intersectY(out, ax, ay, bx, by, y) {
1440
+ const t = (y - ay) / (by - ay);
1441
+ addPoint(out, ax + (bx - ax) * t, y, 1);
1539
1442
  return t;
1540
1443
  }
1541
1444
 
1542
- // dist/lib/geojson-tiler/wrap.js
1445
+ // dist/lib/geojsonvt/wrap.js
1543
1446
  function wrap(features, options) {
1544
1447
  const buffer = options.buffer / options.extent;
1545
1448
  let merged = features;
@@ -1558,8 +1461,8 @@ function wrap(features, options) {
1558
1461
  }
1559
1462
  function shiftFeatureCoords(features, offset) {
1560
1463
  const newFeatures = [];
1561
- for (let i2 = 0; i2 < features.length; i2++) {
1562
- const feature = features[i2];
1464
+ for (let i = 0; i < features.length; i++) {
1465
+ const feature = features[i];
1563
1466
  const type = feature.type;
1564
1467
  let newGeometry;
1565
1468
  if (type === "Point" || type === "MultiPoint" || type === "LineString") {
@@ -1590,13 +1493,13 @@ function shiftCoords(points, offset) {
1590
1493
  newPoints.start = points.start;
1591
1494
  newPoints.end = points.end;
1592
1495
  }
1593
- for (let i2 = 0; i2 < points.length; i2 += 3) {
1594
- newPoints.push(points[i2] + offset, points[i2 + 1], points[i2 + 2]);
1496
+ for (let i = 0; i < points.length; i += 3) {
1497
+ newPoints.push(points[i] + offset, points[i + 1], points[i + 2]);
1595
1498
  }
1596
1499
  return newPoints;
1597
1500
  }
1598
1501
 
1599
- // dist/lib/geojson-tiler/transform.js
1502
+ // dist/lib/geojsonvt/transform.js
1600
1503
  function transformTile(tile, extent) {
1601
1504
  if (tile.transformed) {
1602
1505
  return tile;
@@ -1625,11 +1528,11 @@ function transformTile(tile, extent) {
1625
1528
  tile.transformed = true;
1626
1529
  return tile;
1627
1530
  }
1628
- function transformPoint(x2, y2, extent, z2, tx, ty) {
1629
- return [Math.round(extent * (x2 * z2 - tx)), Math.round(extent * (y2 * z2 - ty))];
1531
+ function transformPoint(x, y, extent, z2, tx, ty) {
1532
+ return [Math.round(extent * (x * z2 - tx)), Math.round(extent * (y * z2 - ty))];
1630
1533
  }
1631
1534
 
1632
- // dist/lib/geojson-tiler/tile.js
1535
+ // dist/lib/geojsonvt/tile.js
1633
1536
  function createTile(features, z, tx, ty, options) {
1634
1537
  const tolerance = z === options.maxZoom ? 0 : options.tolerance / ((1 << z) * options.extent);
1635
1538
  const tile = {
@@ -1661,22 +1564,22 @@ function addFeature(tile, feature, tolerance, options) {
1661
1564
  tile.maxX = Math.max(tile.maxX, feature.maxX);
1662
1565
  tile.maxY = Math.max(tile.maxY, feature.maxY);
1663
1566
  if (type === "Point" || type === "MultiPoint") {
1664
- for (let i2 = 0; i2 < geom.length; i2 += 3) {
1665
- simplified.push(geom[i2], geom[i2 + 1]);
1567
+ for (let i = 0; i < geom.length; i += 3) {
1568
+ simplified.push(geom[i], geom[i + 1]);
1666
1569
  tile.numPoints++;
1667
1570
  tile.numSimplified++;
1668
1571
  }
1669
1572
  } else if (type === "LineString") {
1670
1573
  addLine(simplified, geom, tile, tolerance, false, false);
1671
1574
  } 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);
1575
+ for (let i = 0; i < geom.length; i++) {
1576
+ addLine(simplified, geom[i], tile, tolerance, type === "Polygon", i === 0);
1674
1577
  }
1675
1578
  } else if (type === "MultiPolygon") {
1676
1579
  for (let k = 0; k < geom.length; k++) {
1677
1580
  const polygon = geom[k];
1678
- for (let i2 = 0; i2 < polygon.length; i2++) {
1679
- addLine(simplified, polygon[i2], tile, tolerance, true, i2 === 0);
1581
+ for (let i = 0; i < polygon.length; i++) {
1582
+ addLine(simplified, polygon[i], tile, tolerance, true, i === 0);
1680
1583
  }
1681
1584
  }
1682
1585
  }
@@ -1707,10 +1610,10 @@ function addLine(result, geom, tile, tolerance, isPolygon, isOuter) {
1707
1610
  return;
1708
1611
  }
1709
1612
  const ring = [];
1710
- for (let i2 = 0; i2 < geom.length; i2 += 3) {
1711
- if (tolerance === 0 || geom[i2 + 2] > sqTolerance) {
1613
+ for (let i = 0; i < geom.length; i += 3) {
1614
+ if (tolerance === 0 || geom[i + 2] > sqTolerance) {
1712
1615
  tile.numSimplified++;
1713
- ring.push(geom[i2], geom[i2 + 1]);
1616
+ ring.push(geom[i], geom[i + 1]);
1714
1617
  }
1715
1618
  tile.numPoints++;
1716
1619
  }
@@ -1720,55 +1623,43 @@ function addLine(result, geom, tile, tolerance, isPolygon, isOuter) {
1720
1623
  }
1721
1624
  function rewind(ring, clockwise) {
1722
1625
  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]);
1626
+ for (let i = 0, j = ring.length - 2; i < ring.length; j = i, i += 2) {
1627
+ area += (ring[i] - ring[j]) * (ring[i + 1] + ring[j + 1]);
1725
1628
  }
1726
1629
  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;
1630
+ for (let i = 0, len = ring.length; i < len / 2; i += 2) {
1631
+ const x = ring[i];
1632
+ const y = ring[i + 1];
1633
+ ring[i] = ring[len - 2 - i];
1634
+ ring[i + 1] = ring[len - 1 - i];
1635
+ ring[len - 2 - i] = x;
1636
+ ring[len - 1 - i] = y;
1734
1637
  }
1735
1638
  }
1736
1639
  }
1737
1640
 
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 {
1641
+ // dist/geojson-tile-source.js
1642
+ var _GeoJSONTileSource = class {
1643
+ mimeType = "application/vnd.mapbox-vector-tile";
1763
1644
  options;
1764
1645
  // tiles and tileCoords are part of the public API
1765
1646
  tiles = {};
1766
1647
  tileCoords = [];
1767
1648
  stats = {};
1768
1649
  total = 0;
1650
+ /** Sync methods can be called: the input data promise has been resolved and initial top-level tiling is done */
1651
+ ready;
1769
1652
  constructor(data, options) {
1770
- this.options = { ...DEFAULT_OPTIONS, ...options };
1771
- options = this.options;
1653
+ this.options = { ..._GeoJSONTileSource.defaultOptions, ...options };
1654
+ this.getTileData = this.getTileData.bind(this);
1655
+ this.ready = this.initializeTilesAsync(data);
1656
+ }
1657
+ async initializeTilesAsync(dataPromise) {
1658
+ const data = await dataPromise;
1659
+ this.initializeTilesSync(data);
1660
+ }
1661
+ initializeTilesSync(data) {
1662
+ const options = this.options;
1772
1663
  const debug = options.debug;
1773
1664
  if (debug)
1774
1665
  console.time("preprocess data");
@@ -1796,30 +1687,62 @@ var GeoJSONTiler = class {
1796
1687
  console.log("tiles generated:", this.total, JSON.stringify(this.stats));
1797
1688
  }
1798
1689
  }
1690
+ async getMetadata() {
1691
+ return {};
1692
+ }
1799
1693
  /**
1800
1694
  * Get a tile at the specified index
1801
- * @param z
1802
- * @param x
1803
- * @param y
1695
+ * @param tileIndex z, x, y of tile
1804
1696
  * @returns
1805
1697
  */
1698
+ async getVectorTile(tileIndex) {
1699
+ await this.ready;
1700
+ const table = this.getTileSync(tileIndex);
1701
+ return table;
1702
+ }
1703
+ async getTile(tileIndex) {
1704
+ await this.ready;
1705
+ return this.getTileSync(tileIndex);
1706
+ }
1707
+ async getTileData(tileParams) {
1708
+ const { x, y, z } = tileParams.index;
1709
+ return await this.getVectorTile({ x, y, z });
1710
+ }
1711
+ // Implementation
1712
+ /**
1713
+ * Synchronously request a tile
1714
+ * @note Application must await `source.ready` before calling sync methods.
1715
+ */
1716
+ getTileSync(tileIndex) {
1717
+ const rawTile = this.getRawTile(tileIndex);
1718
+ if (!rawTile) {
1719
+ return null;
1720
+ }
1721
+ return convertToGeoJSONTable(rawTile, this.options.extent);
1722
+ }
1723
+ /**
1724
+ * Return geojsonvt-style "half formed" vector tile
1725
+ * @note Application must await `source.ready` before calling sync methods.
1726
+ */
1806
1727
  // eslint-disable-next-line complexity, max-statements
1807
- getTile(z, x2, y2) {
1728
+ getRawTile(tileIndex) {
1729
+ const { z, y } = tileIndex;
1730
+ let { x } = tileIndex;
1808
1731
  const { extent, debug } = this.options;
1809
1732
  if (z < 0 || z > 24) {
1810
1733
  return null;
1811
1734
  }
1812
1735
  const z2 = 1 << z;
1813
- x2 = x2 + z2 & z2 - 1;
1814
- const id = toID(z, x2, y2);
1736
+ x = x + z2 & z2 - 1;
1737
+ const id = toID(z, x, y);
1815
1738
  if (this.tiles[id]) {
1816
1739
  return transformTile(this.tiles[id], extent);
1817
1740
  }
1818
1741
  if (debug > 1)
1819
- console.log("drilling down to z%d-%d-%d", z, x2, y2);
1742
+ console.log("drilling down to z%d-%d-%d", z, x, y);
1820
1743
  let z0 = z;
1821
- let x0 = x2;
1822
- let y0 = y2;
1744
+ let x0 = x;
1745
+ let y0 = y;
1823
1746
  let parent;
1824
1747
  while (!parent && z0 > 0) {
1825
1748
  z0--;
@@ -1834,7 +1757,7 @@ var GeoJSONTiler = class {
1834
1757
  console.log("found parent tile z%d-%d-%d", z0, x0, y0);
1835
1758
  console.time("drilling down");
1836
1759
  }
1837
- this.splitTile(parent.source, z0, x0, y0, z, x2, y2);
1760
+ this.splitTile(parent.source, z0, x0, y0, z, x, y);
1838
1761
  if (debug > 1) {
1839
1762
  console.timeEnd("drilling down");
1840
1763
  }
@@ -1849,27 +1772,27 @@ var GeoJSONTiler = class {
1849
1772
  * zoom or the number of points is low as specified in the options.
1850
1773
  */
1851
1774
  // 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];
1775
+ splitTile(features, z, x, y, cz, cx, cy) {
1776
+ const stack = [features, z, x, y];
1854
1777
  const options = this.options;
1855
1778
  const debug = options.debug;
1856
1779
  while (stack.length) {
1857
- y2 = stack.pop();
1858
- x2 = stack.pop();
1780
+ y = stack.pop();
1781
+ x = stack.pop();
1859
1782
  z = stack.pop();
1860
1783
  features = stack.pop();
1861
1784
  const z2 = 1 << z;
1862
- const id = toID(z, x2, y2);
1785
+ const id = toID(z, x, y);
1863
1786
  let tile = this.tiles[id];
1864
1787
  if (!tile) {
1865
1788
  if (debug > 1) {
1866
1789
  console.time("creation");
1867
1790
  }
1868
- tile = this.tiles[id] = createTile(features, z, x2, y2, options);
1869
- this.tileCoords.push({ z, x: x2, y: y2 });
1791
+ tile = this.tiles[id] = createTile(features, z, x, y, options);
1792
+ this.tileCoords.push({ z, x, y });
1870
1793
  if (debug) {
1871
1794
  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);
1795
+ console.log("tile z%d-%d-%d (features: %d, points: %d, simplified: %d)", z, x, y, tile.numFeatures, tile.numPoints, tile.numSimplified);
1873
1796
  console.timeEnd("creation");
1874
1797
  }
1875
1798
  const key = `z${z}`;
@@ -1885,7 +1808,7 @@ var GeoJSONTiler = class {
1885
1808
  continue;
1886
1809
  } else if (cz !== void 0) {
1887
1810
  const zoomSteps = cz - z;
1888
- if (x2 !== cx >> zoomSteps || y2 !== cy >> zoomSteps)
1811
+ if (x !== cx >> zoomSteps || y !== cy >> zoomSteps)
1889
1812
  continue;
1890
1813
  }
1891
1814
  tile.source = null;
@@ -1901,29 +1824,116 @@ var GeoJSONTiler = class {
1901
1824
  let bl = null;
1902
1825
  let tr = null;
1903
1826
  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);
1827
+ let left = clip(features, z2, x - k1, x + k3, 0, tile.minX, tile.maxX, options);
1828
+ let right = clip(features, z2, x + k2, x + k4, 0, tile.minX, tile.maxX, options);
1906
1829
  features = null;
1907
1830
  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);
1831
+ tl = clip(left, z2, y - k1, y + k3, 1, tile.minY, tile.maxY, options);
1832
+ bl = clip(left, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, options);
1910
1833
  left = null;
1911
1834
  }
1912
1835
  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);
1836
+ tr = clip(right, z2, y - k1, y + k3, 1, tile.minY, tile.maxY, options);
1837
+ br = clip(right, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, options);
1915
1838
  right = null;
1916
1839
  }
1917
1840
  if (debug > 1)
1918
1841
  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);
1842
+ stack.push(tl || [], z + 1, x * 2, y * 2);
1843
+ stack.push(bl || [], z + 1, x * 2, y * 2 + 1);
1844
+ stack.push(tr || [], z + 1, x * 2 + 1, y * 2);
1845
+ stack.push(br || [], z + 1, x * 2 + 1, y * 2 + 1);
1923
1846
  }
1924
1847
  }
1925
1848
  };
1926
- function toID(z, x2, y2) {
1927
- return ((1 << z) * y2 + x2) * 32 + z;
1849
+ var GeoJSONTileSource = _GeoJSONTileSource;
1850
+ __publicField(GeoJSONTileSource, "defaultOptions", {
1851
+ maxZoom: 14,
1852
+ // max zoom to preserve detail on
1853
+ indexMaxZoom: 5,
1854
+ // max zoom in the tile index
1855
+ indexMaxPoints: 1e5,
1856
+ // max number of points per tile in the tile index
1857
+ tolerance: 3,
1858
+ // simplification tolerance (higher means simpler)
1859
+ extent: 4096,
1860
+ // tile extent
1861
+ buffer: 64,
1862
+ // tile buffer on each side
1863
+ lineMetrics: false,
1864
+ // whether to calculate line metrics
1865
+ // @ts-expect-error
1866
+ promoteId: void 0,
1867
+ // name of a feature property to be promoted to feature.id
1868
+ generateId: false,
1869
+ // whether to generate feature ids. Cannot be used with promoteId
1870
+ debug: 0
1871
+ // logging level (0, 1 or 2)
1872
+ });
1873
+ function toID(z, x, y) {
1874
+ return ((1 << z) * y + x) * 32 + z;
1875
+ }
1876
+ function convertToGeoJSONTable(vtTile, extent) {
1877
+ const features = [];
1878
+ for (const rawFeature of vtTile.features) {
1879
+ if (!rawFeature || !rawFeature.geometry) {
1880
+ continue;
1881
+ }
1882
+ let type;
1883
+ let coordinates;
1884
+ switch (rawFeature.type) {
1885
+ case 1:
1886
+ if (rawFeature.geometry.length === 1) {
1887
+ type = "Point";
1888
+ coordinates = rawFeature.geometry[0];
1889
+ } else {
1890
+ type = "MultiPoint";
1891
+ coordinates = rawFeature.geometry;
1892
+ }
1893
+ break;
1894
+ case 2:
1895
+ if (rawFeature.geometry.length === 1) {
1896
+ type = "LineString";
1897
+ coordinates = rawFeature.geometry[0];
1898
+ } else {
1899
+ type = "MultiLineString";
1900
+ coordinates = rawFeature.geometry;
1901
+ }
1902
+ break;
1903
+ case 3:
1904
+ if (rawFeature.geometry.length > 1) {
1905
+ type = "MultiPolygon";
1906
+ coordinates = [rawFeature.geometry];
1907
+ } else {
1908
+ type = "Polygon";
1909
+ coordinates = rawFeature.geometry;
1910
+ }
1911
+ break;
1912
+ default:
1913
+ continue;
1914
+ }
1915
+ coordinates = toLngLat(coordinates, extent);
1916
+ const feature = {
1917
+ type: "Feature",
1918
+ geometry: {
1919
+ type,
1920
+ coordinates
1921
+ },
1922
+ properties: rawFeature.tags || {}
1923
+ };
1924
+ features.push(feature);
1925
+ }
1926
+ const table = {
1927
+ shape: "geojson-table",
1928
+ type: "FeatureCollection",
1929
+ features
1930
+ };
1931
+ return table;
1932
+ }
1933
+ function toLngLat(coords, extent) {
1934
+ if (Array.isArray(coords[0])) {
1935
+ return coords.map((c) => toLngLat(c, extent));
1936
+ }
1937
+ return [coords[0] / extent, coords[1] / extent];
1928
1938
  }
1929
1939
  //# sourceMappingURL=index.cjs.map