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

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 (87) hide show
  1. package/dist/dist.dev.js +821 -680
  2. package/dist/dist.min.js +1 -1
  3. package/dist/index.cjs +795 -656
  4. package/dist/index.cjs.map +4 -4
  5. package/dist/index.d.ts +6 -5
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +5 -1
  8. package/dist/lib/get-schemas-from-tilejson.d.ts +4 -0
  9. package/dist/lib/get-schemas-from-tilejson.d.ts.map +1 -0
  10. package/dist/lib/get-schemas-from-tilejson.js +55 -0
  11. package/dist/lib/parse-tilejson.d.ts +9 -4
  12. package/dist/lib/parse-tilejson.d.ts.map +1 -1
  13. package/dist/lib/parse-tilejson.js +6 -6
  14. package/dist/lib/types.d.ts +39 -1
  15. package/dist/lib/types.d.ts.map +1 -1
  16. package/dist/lib/types.js +1 -1
  17. package/dist/lib/utils/geometry-utils.js +1 -1
  18. package/dist/lib/vector-tiler/{clip.d.ts → features/clip-features.d.ts} +4 -4
  19. package/dist/lib/vector-tiler/features/clip-features.d.ts.map +1 -0
  20. package/dist/lib/vector-tiler/{clip.js → features/clip-features.js} +4 -4
  21. package/dist/lib/vector-tiler/{convert.d.ts → features/convert-feature.d.ts} +7 -7
  22. package/dist/lib/vector-tiler/features/convert-feature.d.ts.map +1 -0
  23. package/dist/lib/vector-tiler/features/convert-feature.js +140 -0
  24. package/dist/lib/vector-tiler/features/proto-feature.d.ts +30 -0
  25. package/dist/lib/vector-tiler/features/proto-feature.d.ts.map +1 -0
  26. package/dist/lib/vector-tiler/features/proto-feature.js +52 -0
  27. package/dist/lib/vector-tiler/{simplify.d.ts → features/simplify-path.d.ts} +2 -2
  28. package/dist/lib/vector-tiler/features/simplify-path.d.ts.map +1 -0
  29. package/dist/lib/vector-tiler/{simplify.js → features/simplify-path.js} +3 -3
  30. package/dist/lib/vector-tiler/{wrap.d.ts → features/wrap-features.d.ts} +5 -5
  31. package/dist/lib/vector-tiler/features/wrap-features.d.ts.map +1 -0
  32. package/dist/lib/vector-tiler/{wrap.js → features/wrap-features.js} +33 -26
  33. package/dist/lib/vector-tiler/proto-tile.d.ts +40 -0
  34. package/dist/lib/vector-tiler/proto-tile.d.ts.map +1 -0
  35. package/dist/lib/vector-tiler/proto-tile.js +138 -0
  36. package/dist/lib/vector-tiler/tile-to-geojson.d.ts +12 -0
  37. package/dist/lib/vector-tiler/tile-to-geojson.d.ts.map +1 -0
  38. package/dist/lib/vector-tiler/tile-to-geojson.js +81 -0
  39. package/dist/lib/vector-tiler/transform-tile.d.ts +7 -0
  40. package/dist/lib/vector-tiler/transform-tile.d.ts.map +1 -0
  41. package/dist/lib/vector-tiler/transform-tile.js +41 -0
  42. package/dist/mvt-loader.d.ts +2 -0
  43. package/dist/mvt-loader.d.ts.map +1 -1
  44. package/dist/mvt-loader.js +1 -1
  45. package/dist/mvt-source.d.ts +31 -14
  46. package/dist/mvt-source.d.ts.map +1 -1
  47. package/dist/mvt-source.js +26 -6
  48. package/dist/mvt-worker.js +4 -4
  49. package/dist/table-tile-source.d.ts +66 -36
  50. package/dist/table-tile-source.d.ts.map +1 -1
  51. package/dist/table-tile-source.js +167 -117
  52. package/dist/tilejson-loader.js +1 -1
  53. package/package.json +9 -6
  54. package/src/index.ts +13 -6
  55. package/src/lib/get-schemas-from-tilejson.ts +64 -0
  56. package/src/lib/parse-tilejson.ts +19 -12
  57. package/src/lib/types.ts +40 -2
  58. package/src/lib/utils/geometry-utils.ts +1 -1
  59. package/src/lib/vector-tiler/{clip.ts → features/clip-features.ts} +8 -8
  60. package/src/lib/vector-tiler/{convert.ts → features/convert-feature.ts} +91 -70
  61. package/src/lib/vector-tiler/features/proto-feature.ts +104 -0
  62. package/src/lib/vector-tiler/{simplify.ts → features/simplify-path.ts} +8 -3
  63. package/src/lib/vector-tiler/{wrap.ts → features/wrap-features.ts} +44 -29
  64. package/src/lib/vector-tiler/proto-tile.ts +217 -0
  65. package/src/lib/vector-tiler/tile-to-geojson.ts +105 -0
  66. package/src/lib/vector-tiler/transform-tile.ts +57 -0
  67. package/src/mvt-loader.ts +2 -0
  68. package/src/mvt-source.ts +42 -18
  69. package/src/table-tile-source.ts +130 -85
  70. package/src/tilejson-loader.ts +2 -2
  71. package/dist/lib/vector-tiler/clip.d.ts.map +0 -1
  72. package/dist/lib/vector-tiler/convert.d.ts.map +0 -1
  73. package/dist/lib/vector-tiler/convert.js +0 -139
  74. package/dist/lib/vector-tiler/feature.d.ts +0 -3
  75. package/dist/lib/vector-tiler/feature.d.ts.map +0 -1
  76. package/dist/lib/vector-tiler/feature.js +0 -44
  77. package/dist/lib/vector-tiler/simplify.d.ts.map +0 -1
  78. package/dist/lib/vector-tiler/tile.d.ts +0 -38
  79. package/dist/lib/vector-tiler/tile.d.ts.map +0 -1
  80. package/dist/lib/vector-tiler/tile.js +0 -123
  81. package/dist/lib/vector-tiler/transform.d.ts +0 -7
  82. package/dist/lib/vector-tiler/transform.d.ts.map +0 -1
  83. package/dist/lib/vector-tiler/transform.js +0 -41
  84. package/dist/lib/vector-tiler/wrap.d.ts.map +0 -1
  85. package/src/lib/vector-tiler/feature.ts +0 -47
  86. package/src/lib/vector-tiler/tile.ts +0 -187
  87. package/src/lib/vector-tiler/transform.ts +0 -57
package/dist/index.cjs CHANGED
@@ -43,6 +43,295 @@ __export(dist_exports, {
43
43
  });
44
44
  module.exports = __toCommonJS(dist_exports);
45
45
 
46
+ // dist/lib/get-schemas-from-tilejson.js
47
+ function getSchemaFromTileJSONLayer(layer) {
48
+ const fields = [];
49
+ if (layer.fields) {
50
+ for (const field of layer.fields) {
51
+ fields.push({
52
+ name: field.name,
53
+ type: getDataTypeFromTileJSONField(field),
54
+ metadata: getMetadataFromTileJSONField(field)
55
+ });
56
+ }
57
+ }
58
+ return {
59
+ metadata: getMetadataFromTileJSONLayer(layer),
60
+ fields
61
+ };
62
+ }
63
+ function getMetadataFromTileJSONLayer(layer) {
64
+ const metadata = {};
65
+ for (const [key, value] of Object.entries(layer)) {
66
+ if (key !== "fields" && value) {
67
+ metadata[key] = JSON.stringify(value);
68
+ }
69
+ }
70
+ return metadata;
71
+ }
72
+ function getDataTypeFromTileJSONField(field) {
73
+ switch (field.type.toLowerCase()) {
74
+ case "float32":
75
+ return "float32";
76
+ case "number":
77
+ case "float64":
78
+ return "float64";
79
+ case "string":
80
+ case "utf8":
81
+ return "utf8";
82
+ case "boolean":
83
+ return "bool";
84
+ default:
85
+ return "null";
86
+ }
87
+ }
88
+ function getMetadataFromTileJSONField(field) {
89
+ const metadata = {};
90
+ for (const [key, value] of Object.entries(field)) {
91
+ if (key !== "name" && value) {
92
+ metadata[key] = JSON.stringify(value);
93
+ }
94
+ }
95
+ return metadata;
96
+ }
97
+
98
+ // dist/lib/parse-tilejson.js
99
+ var isObject = (x) => x !== null && typeof x === "object";
100
+ function parseTileJSON(jsonMetadata, options) {
101
+ var _a;
102
+ if (!jsonMetadata || !isObject(jsonMetadata)) {
103
+ return null;
104
+ }
105
+ let tileJSON = {
106
+ name: jsonMetadata.name || "",
107
+ description: jsonMetadata.description || ""
108
+ };
109
+ if (typeof jsonMetadata.generator === "string") {
110
+ tileJSON.generator = jsonMetadata.generator;
111
+ }
112
+ if (typeof jsonMetadata.generator_options === "string") {
113
+ tileJSON.generatorOptions = jsonMetadata.generator_options;
114
+ }
115
+ tileJSON.boundingBox = parseBounds(jsonMetadata.bounds) || parseBounds(jsonMetadata.antimeridian_adjusted_bounds);
116
+ tileJSON.center = parseCenter(jsonMetadata.center);
117
+ tileJSON.maxZoom = safeParseFloat(jsonMetadata.maxzoom);
118
+ tileJSON.minZoom = safeParseFloat(jsonMetadata.minzoom);
119
+ if (typeof (jsonMetadata == null ? void 0 : jsonMetadata.json) === "string") {
120
+ try {
121
+ tileJSON.metaJson = JSON.parse(jsonMetadata.json);
122
+ } catch (error) {
123
+ console.warn("Failed to parse tilejson.json field", error);
124
+ }
125
+ }
126
+ const tilestats = jsonMetadata.tilestats || ((_a = tileJSON.metaJson) == null ? void 0 : _a.tilestats);
127
+ const tileStatsLayers = parseTilestatsLayers(tilestats, options);
128
+ const tileJSONlayers = parseTileJSONLayers(jsonMetadata.vector_layers);
129
+ const layers = mergeLayers(tileJSONlayers, tileStatsLayers);
130
+ tileJSON = {
131
+ ...tileJSON,
132
+ layers
133
+ };
134
+ if (tileJSON.maxZoom === null && layers.length > 0) {
135
+ tileJSON.maxZoom = layers[0].maxZoom || null;
136
+ }
137
+ if (tileJSON.minZoom === null && layers.length > 0) {
138
+ tileJSON.minZoom = layers[0].minZoom || null;
139
+ }
140
+ return tileJSON;
141
+ }
142
+ function parseTileJSONLayers(layers) {
143
+ if (!Array.isArray(layers)) {
144
+ return [];
145
+ }
146
+ return layers.map((layer) => parseTileJSONLayer(layer));
147
+ }
148
+ function parseTileJSONLayer(layer) {
149
+ const fields = Object.entries(layer.fields || []).map(([key, datatype]) => ({
150
+ name: key,
151
+ ...attributeTypeToFieldType(String(datatype))
152
+ }));
153
+ const layer2 = { ...layer };
154
+ delete layer2.fields;
155
+ return {
156
+ name: layer.id || "",
157
+ ...layer2,
158
+ fields
159
+ };
160
+ }
161
+ function parseTilestatsLayers(tilestats, options) {
162
+ if (isObject(tilestats) && Array.isArray(tilestats.layers)) {
163
+ return tilestats.layers.map((layer) => parseTilestatsForLayer(layer, options));
164
+ }
165
+ return [];
166
+ }
167
+ function parseTilestatsForLayer(layer, options) {
168
+ const fields = [];
169
+ const indexedAttributes = {};
170
+ const attributes = layer.attributes || [];
171
+ for (const attribute of attributes) {
172
+ const name = attribute.attribute;
173
+ if (typeof name === "string") {
174
+ if (name.split("|").length > 1) {
175
+ const fname = name.split("|")[0];
176
+ indexedAttributes[fname] = indexedAttributes[fname] || [];
177
+ indexedAttributes[fname].push(attribute);
178
+ console.warn("ignoring tilestats indexed field", fname);
179
+ } else if (!fields[name]) {
180
+ fields.push(attributeToField(attribute, options));
181
+ } else {
182
+ }
183
+ }
184
+ }
185
+ return {
186
+ name: layer.layer || "",
187
+ dominantGeometry: layer.geometry,
188
+ fields
189
+ };
190
+ }
191
+ function mergeLayers(layers, tilestatsLayers) {
192
+ return layers.map((layer) => {
193
+ const tilestatsLayer = tilestatsLayers.find((tsLayer) => tsLayer.name === layer.name);
194
+ const fields = (tilestatsLayer == null ? void 0 : tilestatsLayer.fields) || layer.fields || [];
195
+ const mergedLayer = {
196
+ ...layer,
197
+ ...tilestatsLayer,
198
+ fields
199
+ };
200
+ mergedLayer.schema = getSchemaFromTileJSONLayer(mergedLayer);
201
+ return mergedLayer;
202
+ });
203
+ }
204
+ function parseBounds(bounds) {
205
+ const result = fromArrayOrString(bounds);
206
+ if (Array.isArray(result) && result.length === 4 && [result[0], result[2]].every(isLng) && [result[1], result[3]].every(isLat)) {
207
+ return [
208
+ [result[0], result[1]],
209
+ [result[2], result[3]]
210
+ ];
211
+ }
212
+ return void 0;
213
+ }
214
+ function parseCenter(center) {
215
+ const result = fromArrayOrString(center);
216
+ if (Array.isArray(result) && result.length === 3 && isLng(result[0]) && isLat(result[1]) && isZoom(result[2])) {
217
+ return result;
218
+ }
219
+ return null;
220
+ }
221
+ function safeParseFloat(input) {
222
+ const result = typeof input === "string" ? parseFloat(input) : typeof input === "number" ? input : null;
223
+ return result === null || isNaN(result) ? null : result;
224
+ }
225
+ function isLat(num) {
226
+ return Number.isFinite(num) && num <= 90 && num >= -90;
227
+ }
228
+ function isLng(num) {
229
+ return Number.isFinite(num) && num <= 180 && num >= -180;
230
+ }
231
+ function isZoom(num) {
232
+ return Number.isFinite(num) && num >= 0 && num <= 22;
233
+ }
234
+ function fromArrayOrString(data) {
235
+ if (typeof data === "string") {
236
+ return data.split(",").map(parseFloat);
237
+ } else if (Array.isArray(data)) {
238
+ return data;
239
+ }
240
+ return null;
241
+ }
242
+ var attrTypeMap = {
243
+ number: {
244
+ type: "float32"
245
+ },
246
+ numeric: {
247
+ type: "float32"
248
+ },
249
+ string: {
250
+ type: "utf8"
251
+ },
252
+ vachar: {
253
+ type: "utf8"
254
+ },
255
+ float: {
256
+ type: "float32"
257
+ },
258
+ int: {
259
+ type: "int32"
260
+ },
261
+ int4: {
262
+ type: "int32"
263
+ },
264
+ boolean: {
265
+ type: "boolean"
266
+ },
267
+ bool: {
268
+ type: "boolean"
269
+ }
270
+ };
271
+ function attributeToField(attribute = {}, options) {
272
+ var _a;
273
+ const fieldTypes = attributeTypeToFieldType(attribute.type);
274
+ const field = {
275
+ name: attribute.attribute,
276
+ // what happens if attribute type is string...
277
+ // filterProps: getFilterProps(fieldTypes.type, attribute),
278
+ ...fieldTypes
279
+ };
280
+ if (typeof attribute.min === "number") {
281
+ field.min = attribute.min;
282
+ }
283
+ if (typeof attribute.max === "number") {
284
+ field.max = attribute.max;
285
+ }
286
+ if (typeof attribute.count === "number") {
287
+ field.uniqueValueCount = attribute.count;
288
+ }
289
+ if (attribute.values) {
290
+ field.values = attribute.values;
291
+ }
292
+ if (field.values && typeof options.maxValues === "number") {
293
+ field.values = (_a = field.values) == null ? void 0 : _a.slice(0, options.maxValues);
294
+ }
295
+ return field;
296
+ }
297
+ function attributeTypeToFieldType(aType) {
298
+ const type = aType.toLowerCase();
299
+ if (!type || !attrTypeMap[type]) {
300
+ }
301
+ return attrTypeMap[type] || { type: "string" };
302
+ }
303
+
304
+ // dist/tilejson-loader.js
305
+ var VERSION = true ? "4.3.0-alpha.3" : "latest";
306
+ var TileJSONLoader = {
307
+ dataType: null,
308
+ batchType: null,
309
+ name: "TileJSON",
310
+ id: "tilejson",
311
+ module: "pmtiles",
312
+ version: VERSION,
313
+ worker: true,
314
+ extensions: ["json"],
315
+ mimeTypes: ["application/json"],
316
+ text: true,
317
+ options: {
318
+ tilejson: {
319
+ maxValues: void 0
320
+ }
321
+ },
322
+ parse: async (arrayBuffer, options) => {
323
+ const jsonString = new TextDecoder().decode(arrayBuffer);
324
+ const json = JSON.parse(jsonString);
325
+ const tilejsonOptions = { ...TileJSONLoader.options.tilejson, ...options == null ? void 0 : options.tilejson };
326
+ return parseTileJSON(json, tilejsonOptions);
327
+ },
328
+ parseTextSync: (text, options) => {
329
+ const json = JSON.parse(text);
330
+ const tilejsonOptions = { ...TileJSONLoader.options.tilejson, ...options == null ? void 0 : options.tilejson };
331
+ return parseTileJSON(json, tilejsonOptions);
332
+ }
333
+ };
334
+
46
335
  // dist/lib/parse-mvt.js
47
336
  var import_gis = require("@loaders.gl/gis");
48
337
  var import_loader_utils = require("@loaders.gl/loader-utils");
@@ -71,7 +360,7 @@ function convertToLocalCoordinates(coordinates, extent) {
71
360
  p[1] /= extent;
72
361
  }
73
362
  function convertToLocalCoordinatesFlat(data, extent) {
74
- for (let i = 0, il = data.length; i < il; ++i) {
363
+ for (let i = 0; i < data.length; ++i) {
75
364
  data[i] /= extent;
76
365
  }
77
366
  }
@@ -610,7 +899,7 @@ function parseToBinary(arrayBuffer, options) {
610
899
  return binaryData;
611
900
  }
612
901
  function parseToFlatGeoJson(arrayBuffer, options) {
613
- const features = [];
902
+ const features2 = [];
614
903
  const geometryInfo = {
615
904
  coordLength: 2,
616
905
  pointPositionsCount: 0,
@@ -624,7 +913,7 @@ function parseToFlatGeoJson(arrayBuffer, options) {
624
913
  polygonFeaturesCount: 0
625
914
  };
626
915
  if (arrayBuffer.byteLength <= 0) {
627
- return [features, geometryInfo];
916
+ return [features2, geometryInfo];
628
917
  }
629
918
  const tile = new VectorTile(new import_pbf.default(arrayBuffer));
630
919
  const selectedLayers = options && Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);
@@ -636,16 +925,16 @@ function parseToFlatGeoJson(arrayBuffer, options) {
636
925
  for (let i = 0; i < vectorTileLayer.length; i++) {
637
926
  const vectorTileFeature = vectorTileLayer.getBinaryFeature(i, geometryInfo);
638
927
  const decodedFeature = getDecodedFeatureBinary(vectorTileFeature, options, layerName);
639
- features.push(decodedFeature);
928
+ features2.push(decodedFeature);
640
929
  }
641
930
  });
642
- return [features, geometryInfo];
931
+ return [features2, geometryInfo];
643
932
  }
644
933
  function parseToGeojsonFeatures(arrayBuffer, options) {
645
934
  if (arrayBuffer.byteLength <= 0) {
646
935
  return [];
647
936
  }
648
- const features = [];
937
+ const features2 = [];
649
938
  const tile = new VectorTile(new import_pbf.default(arrayBuffer));
650
939
  const selectedLayers = Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);
651
940
  selectedLayers.forEach((layerName) => {
@@ -656,10 +945,10 @@ function parseToGeojsonFeatures(arrayBuffer, options) {
656
945
  for (let i = 0; i < vectorTileLayer.length; i++) {
657
946
  const vectorTileFeature = vectorTileLayer.getGeoJSONFeature(i);
658
947
  const decodedFeature = getDecodedFeature(vectorTileFeature, options, layerName);
659
- features.push(decodedFeature);
948
+ features2.push(decodedFeature);
660
949
  }
661
950
  });
662
- return features;
951
+ return features2;
663
952
  }
664
953
  function checkOptions(options) {
665
954
  var _a;
@@ -691,14 +980,14 @@ function getDecodedFeatureBinary(feature, options, layerName) {
691
980
  }
692
981
 
693
982
  // dist/mvt-loader.js
694
- var VERSION = true ? "4.3.0-alpha.1" : "latest";
983
+ var VERSION2 = true ? "4.3.0-alpha.3" : "latest";
695
984
  var MVTWorkerLoader = {
696
985
  dataType: null,
697
986
  batchType: null,
698
987
  name: "Mapbox Vector Tile",
699
988
  id: "mvt",
700
989
  module: "mvt",
701
- version: VERSION,
990
+ version: VERSION2,
702
991
  // Note: ArcGIS uses '.pbf' extension and 'application/octet-stream'
703
992
  extensions: ["mvt", "pbf"],
704
993
  mimeTypes: [
@@ -726,248 +1015,31 @@ var MVTLoader = {
726
1015
  binary: true
727
1016
  };
728
1017
 
729
- // dist/lib/parse-tilejson.js
730
- var isObject = (x) => x !== null && typeof x === "object";
731
- function parseTileJSON(jsonMetadata, options) {
732
- var _a;
733
- if (!jsonMetadata || !isObject(jsonMetadata)) {
734
- return null;
735
- }
736
- let tileJSON = {
737
- name: jsonMetadata.name || "",
738
- description: jsonMetadata.description || ""
739
- };
740
- if (typeof jsonMetadata.generator === "string") {
741
- tileJSON.generator = jsonMetadata.generator;
742
- }
743
- if (typeof jsonMetadata.generator_options === "string") {
744
- tileJSON.generatorOptions = jsonMetadata.generator_options;
745
- }
746
- tileJSON.boundingBox = parseBounds(jsonMetadata.bounds) || parseBounds(jsonMetadata.antimeridian_adjusted_bounds);
747
- tileJSON.center = parseCenter(jsonMetadata.center);
748
- tileJSON.maxZoom = safeParseFloat(jsonMetadata.maxzoom);
749
- tileJSON.minZoom = safeParseFloat(jsonMetadata.minzoom);
750
- if (typeof (jsonMetadata == null ? void 0 : jsonMetadata.json) === "string") {
751
- try {
752
- tileJSON.metaJson = JSON.parse(jsonMetadata.json);
753
- } catch (error) {
754
- console.warn("Failed to parse tilejson.json field", error);
755
- }
756
- }
757
- const tilestats = jsonMetadata.tilestats || ((_a = tileJSON.metaJson) == null ? void 0 : _a.tilestats);
758
- const tileStatsLayers = parseTilestatsLayers(tilestats, options);
759
- const tileJSONlayers = parseTileJSONLayers(jsonMetadata.vector_layers);
760
- const layers = mergeLayers(tileJSONlayers, tileStatsLayers);
761
- tileJSON = {
762
- ...tileJSON,
763
- layers
764
- };
765
- if (tileJSON.maxZoom === null && layers.length > 0) {
766
- tileJSON.maxZoom = layers[0].maxZoom || null;
767
- }
768
- if (tileJSON.minZoom === null && layers.length > 0) {
769
- tileJSON.minZoom = layers[0].minZoom || null;
770
- }
771
- return tileJSON;
772
- }
773
- function parseTileJSONLayers(layers) {
774
- if (!Array.isArray(layers)) {
775
- return [];
776
- }
777
- return layers.map((layer) => parseTileJSONLayer(layer));
778
- }
779
- function parseTileJSONLayer(layer) {
780
- const fields = Object.entries(layer.fields || []).map(([key, datatype]) => ({
781
- name: key,
782
- ...attributeTypeToFieldType(String(datatype))
783
- }));
784
- const layer2 = { ...layer };
785
- delete layer2.fields;
786
- return {
787
- name: layer.id || "",
788
- ...layer2,
789
- fields
790
- };
791
- }
792
- function parseTilestatsLayers(tilestats, options) {
793
- if (isObject(tilestats) && Array.isArray(tilestats.layers)) {
794
- return tilestats.layers.map((layer) => parseTilestatsForLayer(layer, options));
795
- }
796
- return [];
797
- }
798
- function parseTilestatsForLayer(layer, options) {
799
- const fields = [];
800
- const indexedAttributes = {};
801
- const attributes = layer.attributes || [];
802
- for (const attribute of attributes) {
803
- const name = attribute.attribute;
804
- if (typeof name === "string") {
805
- if (name.split("|").length > 1) {
806
- const fname = name.split("|")[0];
807
- indexedAttributes[fname] = indexedAttributes[fname] || [];
808
- indexedAttributes[fname].push(attribute);
809
- console.warn("ignoring tilestats indexed field", fname);
810
- } else if (!fields[name]) {
811
- fields.push(attributeToField(attribute, options));
812
- } else {
813
- }
814
- }
815
- }
816
- return {
817
- name: layer.layer || "",
818
- dominantGeometry: layer.geometry,
819
- fields
820
- };
821
- }
822
- function mergeLayers(layers, tilestatsLayers) {
823
- return layers.map((layer) => {
824
- const tilestatsLayer = tilestatsLayers.find((tsLayer) => tsLayer.name === layer.name);
825
- const fields = (tilestatsLayer == null ? void 0 : tilestatsLayer.fields) || [];
826
- const layer2 = { ...layer };
827
- delete layer2.fields;
828
- return {
829
- ...layer2,
830
- ...tilestatsLayer,
831
- fields
832
- };
833
- });
834
- }
835
- function parseBounds(bounds) {
836
- const result = fromArrayOrString(bounds);
837
- if (Array.isArray(result) && result.length === 4 && [result[0], result[2]].every(isLng) && [result[1], result[3]].every(isLat)) {
838
- return [
839
- [result[0], result[1]],
840
- [result[2], result[3]]
841
- ];
842
- }
843
- return void 0;
844
- }
845
- function parseCenter(center) {
846
- const result = fromArrayOrString(center);
847
- if (Array.isArray(result) && result.length === 3 && isLng(result[0]) && isLat(result[1]) && isZoom(result[2])) {
848
- return result;
849
- }
850
- return null;
851
- }
852
- function safeParseFloat(input) {
853
- const result = typeof input === "string" ? parseFloat(input) : typeof input === "number" ? input : null;
854
- return result === null || isNaN(result) ? null : result;
855
- }
856
- function isLat(num) {
857
- return Number.isFinite(num) && num <= 90 && num >= -90;
858
- }
859
- function isLng(num) {
860
- return Number.isFinite(num) && num <= 180 && num >= -180;
861
- }
862
- function isZoom(num) {
863
- return Number.isFinite(num) && num >= 0 && num <= 22;
864
- }
865
- function fromArrayOrString(data) {
866
- if (typeof data === "string") {
867
- return data.split(",").map(parseFloat);
868
- } else if (Array.isArray(data)) {
869
- return data;
870
- }
871
- return null;
872
- }
873
- var attrTypeMap = {
874
- number: {
875
- type: "float32"
876
- },
877
- numeric: {
878
- type: "float32"
879
- },
880
- string: {
881
- type: "utf8"
882
- },
883
- vachar: {
884
- type: "utf8"
885
- },
886
- float: {
887
- type: "float32"
888
- },
889
- int: {
890
- type: "int32"
891
- },
892
- int4: {
893
- type: "int32"
894
- },
895
- boolean: {
896
- type: "boolean"
897
- },
898
- bool: {
899
- type: "boolean"
900
- }
901
- };
902
- function attributeToField(attribute = {}, options) {
903
- var _a;
904
- const fieldTypes = attributeTypeToFieldType(attribute.type);
905
- const field = {
906
- name: attribute.attribute,
907
- // what happens if attribute type is string...
908
- // filterProps: getFilterProps(fieldTypes.type, attribute),
909
- ...fieldTypes
910
- };
911
- if (typeof attribute.min === "number") {
912
- field.min = attribute.min;
913
- }
914
- if (typeof attribute.max === "number") {
915
- field.max = attribute.max;
916
- }
917
- if (typeof attribute.count === "number") {
918
- field.uniqueValueCount = attribute.count;
919
- }
920
- if (attribute.values) {
921
- field.values = attribute.values;
922
- }
923
- if (field.values && typeof options.maxValues === "number") {
924
- field.values = (_a = field.values) == null ? void 0 : _a.slice(0, options.maxValues);
925
- }
926
- return field;
927
- }
928
- function attributeTypeToFieldType(aType) {
929
- const type = aType.toLowerCase();
930
- if (!type || !attrTypeMap[type]) {
931
- }
932
- return attrTypeMap[type] || { type: "string" };
933
- }
934
-
935
- // dist/tilejson-loader.js
936
- var VERSION2 = true ? "4.3.0-alpha.1" : "latest";
937
- var TileJSONLoader = {
938
- dataType: null,
939
- batchType: null,
940
- name: "TileJSON",
941
- id: "tilejson",
942
- module: "pmtiles",
943
- version: VERSION2,
944
- worker: true,
945
- extensions: ["json"],
946
- mimeTypes: ["application/json"],
947
- text: true,
1018
+ // dist/mvt-source.js
1019
+ var import_loader_utils2 = require("@loaders.gl/loader-utils");
1020
+ var import_images = require("@loaders.gl/images");
1021
+ var import_mvt = require("@loaders.gl/mvt");
1022
+ var MVTSource = {
1023
+ name: "MVT",
1024
+ id: "mvt",
1025
+ module: "mvt",
1026
+ version: "0.0.0",
1027
+ extensions: ["mvt"],
1028
+ mimeTypes: ["application/octet-stream"],
948
1029
  options: {
949
- tilejson: {
950
- maxValues: void 0
1030
+ mvt: {
1031
+ // TODO - add options here
951
1032
  }
952
1033
  },
953
- parse: async (arrayBuffer, options) => {
954
- const jsonString = new TextDecoder().decode(arrayBuffer);
955
- const json = JSON.parse(jsonString);
956
- const tilejsonOptions = { ...TileJSONLoader.options.tilejson, ...options == null ? void 0 : options.tilejson };
957
- return parseTileJSON(json, tilejsonOptions);
958
- },
959
- parseTextSync: (text, options) => {
960
- const json = JSON.parse(text);
961
- const tilejsonOptions = { ...TileJSONLoader.options.tilejson, ...options == null ? void 0 : options.tilejson };
962
- return parseTileJSON(json, tilejsonOptions);
1034
+ type: "mvt",
1035
+ fromUrl: true,
1036
+ fromBlob: false,
1037
+ testURL: (url) => true,
1038
+ createDataSource(url, props) {
1039
+ return new MVTTileSource(url, props);
963
1040
  }
964
1041
  };
965
-
966
- // dist/mvt-source.js
967
- var import_loader_utils2 = require("@loaders.gl/loader-utils");
968
- var import_images = require("@loaders.gl/images");
969
- var import_mvt = require("@loaders.gl/mvt");
970
- var MVTSource = class extends import_loader_utils2.DataSource {
1042
+ var MVTTileSource = class extends import_loader_utils2.DataSource {
971
1043
  props;
972
1044
  url;
973
1045
  metadataUrl = null;
@@ -976,12 +1048,13 @@ var MVTSource = class extends import_loader_utils2.DataSource {
976
1048
  metadata;
977
1049
  extension;
978
1050
  mimeType = null;
979
- constructor(props) {
1051
+ constructor(url, props) {
1052
+ var _a, _b;
980
1053
  super(props);
981
1054
  this.props = props;
982
- this.url = (0, import_loader_utils2.resolvePath)(props.url);
983
- this.metadataUrl = props.metadataUrl === void 0 ? `${this.url}/tilejson.json` : props.metadataUrl;
984
- this.extension = props.extension || ".png";
1055
+ this.url = (0, import_loader_utils2.resolvePath)(url);
1056
+ this.metadataUrl = ((_a = props.mvt) == null ? void 0 : _a.metadataUrl) || `${this.url}/tilejson.json`;
1057
+ this.extension = ((_b = props.mvt) == null ? void 0 : _b.extension) || ".png";
985
1058
  this.data = this.url;
986
1059
  this.getTileData = this.getTileData.bind(this);
987
1060
  this.metadata = this.getMetadata();
@@ -1093,26 +1166,305 @@ function getURLFromTemplate(template, x, y, z, id = "0") {
1093
1166
  const i = stringHash(id) % template.length;
1094
1167
  template = template[i];
1095
1168
  }
1096
- let url = template;
1097
- url = url.replace(xRegex, String(x));
1098
- url = url.replace(yRegex, String(y));
1099
- url = url.replace(zRegex, String(z));
1100
- if (Number.isInteger(y) && Number.isInteger(z)) {
1101
- url = url.replace(/\{-y\}/g, String(Math.pow(2, z) - y - 1));
1169
+ let url = template;
1170
+ url = url.replace(xRegex, String(x));
1171
+ url = url.replace(yRegex, String(y));
1172
+ url = url.replace(zRegex, String(z));
1173
+ if (Number.isInteger(y) && Number.isInteger(z)) {
1174
+ url = url.replace(/\{-y\}/g, String(Math.pow(2, z) - y - 1));
1175
+ }
1176
+ return url;
1177
+ }
1178
+ function stringHash(s) {
1179
+ return Math.abs(s.split("").reduce((a, b) => (a << 5) - a + b.charCodeAt(0) | 0, 0));
1180
+ }
1181
+
1182
+ // dist/table-tile-source.js
1183
+ var import_loader_utils3 = require("@loaders.gl/loader-utils");
1184
+ var import_schema = require("@loaders.gl/schema");
1185
+ var import_stats = require("@probe.gl/stats");
1186
+
1187
+ // dist/lib/vector-tiler/proto-tile.js
1188
+ function createProtoTile(features2, z, tx, ty, options) {
1189
+ const tolerance = z === options.maxZoom ? 0 : options.tolerance / ((1 << z) * options.extent);
1190
+ const tile = {
1191
+ protoFeatures: [],
1192
+ sourceFeatures: null,
1193
+ numPoints: 0,
1194
+ numSimplified: 0,
1195
+ numFeatures: features2.length,
1196
+ x: tx,
1197
+ y: ty,
1198
+ z,
1199
+ transformed: false,
1200
+ minX: 2,
1201
+ minY: 1,
1202
+ maxX: -1,
1203
+ maxY: 0
1204
+ };
1205
+ for (const feature of features2) {
1206
+ addProtoFeature(tile, feature, tolerance, options);
1207
+ }
1208
+ return tile;
1209
+ }
1210
+ function addProtoFeature(tile, feature, tolerance, options) {
1211
+ const geometry = feature.geometry;
1212
+ const type = feature.type;
1213
+ const simplifiedGeometry = [];
1214
+ tile.minX = Math.min(tile.minX, feature.minX);
1215
+ tile.minY = Math.min(tile.minY, feature.minY);
1216
+ tile.maxX = Math.max(tile.maxX, feature.maxX);
1217
+ tile.maxY = Math.max(tile.maxY, feature.maxY);
1218
+ let simplifiedType;
1219
+ switch (type) {
1220
+ case "Point":
1221
+ case "MultiPoint":
1222
+ simplifiedType = 1;
1223
+ for (let i = 0; i < geometry.length; i += 3) {
1224
+ simplifiedGeometry.push(geometry[i], geometry[i + 1]);
1225
+ tile.numPoints++;
1226
+ tile.numSimplified++;
1227
+ }
1228
+ break;
1229
+ case "LineString":
1230
+ simplifiedType = 2;
1231
+ addProtoLine(simplifiedGeometry, geometry, tile, tolerance, false, false);
1232
+ break;
1233
+ case "MultiLineString":
1234
+ simplifiedType = 2;
1235
+ for (let i = 0; i < geometry.length; i++) {
1236
+ addProtoLine(simplifiedGeometry, geometry[i], tile, tolerance, false, i === 0);
1237
+ }
1238
+ break;
1239
+ case "Polygon":
1240
+ simplifiedType = 3;
1241
+ for (let i = 0; i < geometry.length; i++) {
1242
+ addProtoLine(simplifiedGeometry, geometry[i], tile, tolerance, true, i === 0);
1243
+ }
1244
+ break;
1245
+ case "MultiPolygon":
1246
+ simplifiedType = 3;
1247
+ for (let k = 0; k < geometry.length; k++) {
1248
+ const polygon = geometry[k];
1249
+ for (let i = 0; i < polygon.length; i++) {
1250
+ addProtoLine(simplifiedGeometry, polygon[i], tile, tolerance, true, i === 0);
1251
+ }
1252
+ }
1253
+ break;
1254
+ default:
1255
+ throw new Error(`Unknown geometry type: ${type}`);
1256
+ }
1257
+ if (simplifiedGeometry.length) {
1258
+ let tags = feature.tags || null;
1259
+ if (type === "LineString" && options.lineMetrics) {
1260
+ tags = {};
1261
+ for (const key in feature.tags) {
1262
+ tags[key] = feature.tags[key];
1263
+ }
1264
+ tags.mapbox_clip_start = geometry.start / geometry.size;
1265
+ tags.mapbox_clip_end = geometry.end / geometry.size;
1266
+ }
1267
+ const tileFeature = {
1268
+ geometry: simplifiedGeometry,
1269
+ simplifiedType,
1270
+ // @ts-expect-error
1271
+ tags
1272
+ };
1273
+ if (feature.id !== null) {
1274
+ tileFeature.id = feature.id;
1275
+ }
1276
+ tile.protoFeatures.push(tileFeature);
1277
+ }
1278
+ }
1279
+ function addProtoLine(result, geometry, tile, tolerance, isPolygon, isOuter) {
1280
+ const sqTolerance = tolerance * tolerance;
1281
+ if (tolerance > 0 && geometry.size < (isPolygon ? sqTolerance : tolerance)) {
1282
+ tile.numPoints += geometry.length / 3;
1283
+ return;
1284
+ }
1285
+ const ring = [];
1286
+ for (let i = 0; i < geometry.length; i += 3) {
1287
+ if (tolerance === 0 || geometry[i + 2] > sqTolerance) {
1288
+ tile.numSimplified++;
1289
+ ring.push(geometry[i], geometry[i + 1]);
1290
+ }
1291
+ tile.numPoints++;
1292
+ }
1293
+ if (isPolygon)
1294
+ rewind(ring, isOuter);
1295
+ result.push(ring);
1296
+ }
1297
+ function rewind(ring, clockwise) {
1298
+ let area = 0;
1299
+ for (let i = 0, j = ring.length - 2; i < ring.length; j = i, i += 2) {
1300
+ area += (ring[i] - ring[j]) * (ring[i + 1] + ring[j + 1]);
1301
+ }
1302
+ if (area > 0 === clockwise) {
1303
+ for (let i = 0, len = ring.length; i < len / 2; i += 2) {
1304
+ const x = ring[i];
1305
+ const y = ring[i + 1];
1306
+ ring[i] = ring[len - 2 - i];
1307
+ ring[i + 1] = ring[len - 1 - i];
1308
+ ring[len - 2 - i] = x;
1309
+ ring[len - 1 - i] = y;
1310
+ }
1311
+ }
1312
+ }
1313
+
1314
+ // dist/lib/vector-tiler/transform-tile.js
1315
+ function transformTile(protoTile, extent) {
1316
+ if (protoTile.transformed) {
1317
+ return protoTile;
1318
+ }
1319
+ const z2 = 1 << protoTile.z;
1320
+ const tx = protoTile.x;
1321
+ const ty = protoTile.y;
1322
+ for (const protoFeature of protoTile.protoFeatures) {
1323
+ const geom = protoFeature.geometry;
1324
+ const simplifiedType = protoFeature.simplifiedType;
1325
+ protoFeature.geometry = [];
1326
+ if (simplifiedType === 1) {
1327
+ for (let j = 0; j < geom.length; j += 2) {
1328
+ protoFeature.geometry.push(transformPoint(geom[j], geom[j + 1], extent, z2, tx, ty));
1329
+ }
1330
+ } else {
1331
+ for (let j = 0; j < geom.length; j++) {
1332
+ const ring = [];
1333
+ for (let k = 0; k < geom[j].length; k += 2) {
1334
+ ring.push(transformPoint(geom[j][k], geom[j][k + 1], extent, z2, tx, ty));
1335
+ }
1336
+ protoFeature.geometry.push(ring);
1337
+ }
1338
+ }
1339
+ }
1340
+ protoTile.transformed = true;
1341
+ return protoTile;
1342
+ }
1343
+ function transformPoint(x, y, extent, z2, tx, ty) {
1344
+ return [Math.round(extent * (x * z2 - tx)), Math.round(extent * (y * z2 - ty))];
1345
+ }
1346
+
1347
+ // dist/lib/vector-tiler/tile-to-geojson.js
1348
+ function convertTileToGeoJSON(protoTile, props) {
1349
+ const features2 = [];
1350
+ for (const rawFeature of protoTile.protoFeatures) {
1351
+ if (!rawFeature || !rawFeature.geometry) {
1352
+ continue;
1353
+ }
1354
+ let type;
1355
+ let coordinates;
1356
+ switch (rawFeature.simplifiedType) {
1357
+ case 1:
1358
+ if (rawFeature.geometry.length === 1) {
1359
+ type = "Point";
1360
+ coordinates = rawFeature.geometry[0];
1361
+ } else {
1362
+ type = "MultiPoint";
1363
+ coordinates = rawFeature.geometry;
1364
+ }
1365
+ break;
1366
+ case 2:
1367
+ if (rawFeature.geometry.length === 1) {
1368
+ type = "LineString";
1369
+ coordinates = rawFeature.geometry[0];
1370
+ } else {
1371
+ type = "MultiLineString";
1372
+ coordinates = rawFeature.geometry;
1373
+ }
1374
+ break;
1375
+ case 3:
1376
+ if (rawFeature.geometry.length > 1) {
1377
+ type = "MultiPolygon";
1378
+ coordinates = [rawFeature.geometry];
1379
+ } else {
1380
+ type = "Polygon";
1381
+ coordinates = rawFeature.geometry;
1382
+ }
1383
+ break;
1384
+ default:
1385
+ throw new Error(`${rawFeature.simplifiedType}is not a valid simplified type`);
1386
+ }
1387
+ switch (props.coordinates) {
1388
+ case "EPSG:4326":
1389
+ case "wgs84":
1390
+ projectToLngLat(coordinates, props.tileIndex, props.extent);
1391
+ break;
1392
+ default:
1393
+ convertToLocalCoordinates(coordinates, props.extent);
1394
+ break;
1395
+ }
1396
+ const feature = {
1397
+ type: "Feature",
1398
+ geometry: {
1399
+ type,
1400
+ coordinates
1401
+ },
1402
+ properties: rawFeature.tags || {},
1403
+ id: rawFeature.id
1404
+ };
1405
+ features2.push(feature);
1406
+ }
1407
+ if (features2.length === 0) {
1408
+ return null;
1102
1409
  }
1103
- return url;
1104
- }
1105
- function stringHash(s) {
1106
- return Math.abs(s.split("").reduce((a, b) => (a << 5) - a + b.charCodeAt(0) | 0, 0));
1410
+ const table = {
1411
+ shape: "geojson-table",
1412
+ type: "FeatureCollection",
1413
+ features: features2
1414
+ };
1415
+ return table;
1107
1416
  }
1108
1417
 
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");
1418
+ // dist/lib/vector-tiler/features/proto-feature.js
1419
+ function createProtoFeature(id, type, geometry, tags) {
1420
+ const feature = {
1421
+ // eslint-disable-next-line
1422
+ id: id == null ? null : id,
1423
+ type,
1424
+ simplifiedType: void 0,
1425
+ // TODO
1426
+ geometry,
1427
+ tags,
1428
+ minX: Infinity,
1429
+ minY: Infinity,
1430
+ maxX: -Infinity,
1431
+ maxY: -Infinity
1432
+ };
1433
+ switch (type) {
1434
+ case "Point":
1435
+ case "MultiPoint":
1436
+ case "LineString":
1437
+ calcLineBBox(feature, geometry);
1438
+ break;
1439
+ case "MultiLineString":
1440
+ for (const line of geometry) {
1441
+ calcLineBBox(feature, line);
1442
+ }
1443
+ break;
1444
+ case "Polygon":
1445
+ calcLineBBox(feature, geometry[0]);
1446
+ break;
1447
+ case "MultiPolygon":
1448
+ for (const polygon of geometry) {
1449
+ calcLineBBox(feature, polygon[0]);
1450
+ }
1451
+ break;
1452
+ default:
1453
+ throw new Error(String(type));
1454
+ }
1455
+ return feature;
1456
+ }
1457
+ function calcLineBBox(feature, geometry) {
1458
+ for (let i = 0; i < geometry.length; i += 3) {
1459
+ feature.minX = Math.min(feature.minX, geometry[i]);
1460
+ feature.minY = Math.min(feature.minY, geometry[i + 1]);
1461
+ feature.maxX = Math.max(feature.maxX, geometry[i]);
1462
+ feature.maxY = Math.max(feature.maxY, geometry[i + 1]);
1463
+ }
1464
+ }
1113
1465
 
1114
- // dist/lib/vector-tiler/simplify.js
1115
- function simplify(coords, first, last, sqTolerance) {
1466
+ // dist/lib/vector-tiler/features/simplify-path.js
1467
+ function simplifyPath(coords, first, last, sqTolerance) {
1116
1468
  let maxSqDist = sqTolerance;
1117
1469
  const mid = last - first >> 1;
1118
1470
  let minPosToMid = last - first;
@@ -1136,10 +1488,10 @@ function simplify(coords, first, last, sqTolerance) {
1136
1488
  }
1137
1489
  if (maxSqDist > sqTolerance) {
1138
1490
  if (index - first > 3)
1139
- simplify(coords, first, index, sqTolerance);
1491
+ simplifyPath(coords, first, index, sqTolerance);
1140
1492
  coords[index + 2] = maxSqDist;
1141
1493
  if (last - index > 3)
1142
- simplify(coords, index, last, sqTolerance);
1494
+ simplifyPath(coords, index, last, sqTolerance);
1143
1495
  }
1144
1496
  }
1145
1497
  function getSqSegDist(px, py, x, y, bx, by) {
@@ -1160,58 +1512,25 @@ function getSqSegDist(px, py, x, y, bx, by) {
1160
1512
  return dx * dx + dy * dy;
1161
1513
  }
1162
1514
 
1163
- // dist/lib/vector-tiler/feature.js
1164
- function createFeature(id, type, geom, tags) {
1165
- const feature = {
1166
- // eslint-disable-next-line
1167
- id: id == null ? null : id,
1168
- type,
1169
- geometry: geom,
1170
- tags,
1171
- minX: Infinity,
1172
- minY: Infinity,
1173
- maxX: -Infinity,
1174
- maxY: -Infinity
1175
- };
1176
- if (type === "Point" || type === "MultiPoint" || type === "LineString") {
1177
- calcLineBBox(feature, geom);
1178
- } else if (type === "Polygon") {
1179
- calcLineBBox(feature, geom[0]);
1180
- } else if (type === "MultiLineString") {
1181
- for (const line of geom) {
1182
- calcLineBBox(feature, line);
1183
- }
1184
- } else if (type === "MultiPolygon") {
1185
- for (const polygon of geom) {
1186
- calcLineBBox(feature, polygon[0]);
1187
- }
1188
- }
1189
- return feature;
1190
- }
1191
- function calcLineBBox(feature, geom) {
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]);
1197
- }
1198
- }
1199
-
1200
- // dist/lib/vector-tiler/convert.js
1201
- function convert(data, options) {
1202
- const features = [];
1203
- if (data.type === "FeatureCollection") {
1204
- for (let i = 0; i < data.features.length; i++) {
1205
- convertFeature(features, data.features[i], options, i);
1206
- }
1207
- } else if (data.type === "Feature") {
1208
- convertFeature(features, data, options);
1209
- } else {
1210
- convertFeature(features, { geometry: data }, options);
1515
+ // dist/lib/vector-tiler/features/convert-feature.js
1516
+ function convertFeaturesToProtoFeature(data, options) {
1517
+ const protoFeatures = [];
1518
+ switch (data.type) {
1519
+ case "FeatureCollection":
1520
+ let i = 0;
1521
+ for (const feature of data.features) {
1522
+ protoFeatures.push(convertFeature(feature, options, i++));
1523
+ }
1524
+ break;
1525
+ case "Feature":
1526
+ protoFeatures.push(convertFeature(data, options));
1527
+ break;
1528
+ default:
1529
+ protoFeatures.push(convertFeature({ geometry: data }, options));
1211
1530
  }
1212
- return features;
1531
+ return protoFeatures;
1213
1532
  }
1214
- function convertFeature(features, geojson, options, index) {
1533
+ function convertFeature(geojson, options, index) {
1215
1534
  if (!geojson.geometry) {
1216
1535
  return;
1217
1536
  }
@@ -1225,46 +1544,52 @@ function convertFeature(features, geojson, options, index) {
1225
1544
  } else if (options.generateId) {
1226
1545
  id = index || 0;
1227
1546
  }
1228
- if (type === "Point") {
1229
- convertPoint(coords, geometry);
1230
- } else if (type === "MultiPoint") {
1231
- for (const p of coords) {
1232
- convertPoint(p, geometry);
1233
- }
1234
- } else if (type === "LineString") {
1235
- convertLine(coords, geometry, tolerance, false);
1236
- } else if (type === "MultiLineString") {
1237
- if (options.lineMetrics) {
1238
- for (const line of coords) {
1239
- geometry = [];
1240
- convertLine(line, geometry, tolerance, false);
1241
- features.push(createFeature(id, "LineString", geometry, geojson.properties));
1547
+ switch (type) {
1548
+ case "Point":
1549
+ convertPoint(coords, geometry);
1550
+ break;
1551
+ case "MultiPoint":
1552
+ for (const p of coords) {
1553
+ convertPoint(p, geometry);
1242
1554
  }
1243
- return;
1244
- } else {
1245
- convertLines(coords, geometry, tolerance, false);
1246
- }
1247
- } else if (type === "Polygon") {
1248
- convertLines(coords, geometry, tolerance, true);
1249
- } else if (type === "MultiPolygon") {
1250
- for (const polygon of coords) {
1251
- const newPolygon = [];
1252
- convertLines(polygon, newPolygon, tolerance, true);
1253
- geometry.push(newPolygon);
1254
- }
1255
- } else if (type === "GeometryCollection") {
1256
- for (const singleGeometry of geojson.geometry.geometries) {
1257
- convertFeature(features, {
1258
- id,
1259
- geometry: singleGeometry,
1260
- properties: geojson.properties
1261
- }, options, index);
1262
- }
1263
- return;
1264
- } else {
1265
- throw new Error("Input data is not a valid GeoJSON object.");
1555
+ break;
1556
+ case "LineString":
1557
+ convertLine(coords, geometry, tolerance, false);
1558
+ break;
1559
+ case "MultiLineString":
1560
+ if (options.lineMetrics) {
1561
+ for (const line of coords) {
1562
+ geometry = [];
1563
+ convertLine(line, geometry, tolerance, false);
1564
+ features.push(createProtoFeature(id, "LineString", geometry, geojson.properties));
1565
+ }
1566
+ return;
1567
+ convertLines(coords, geometry, tolerance, false);
1568
+ }
1569
+ break;
1570
+ case "Polygon":
1571
+ convertLines(coords, geometry, tolerance, true);
1572
+ break;
1573
+ case "MultiPolygon":
1574
+ for (const polygon of coords) {
1575
+ const newPolygon = [];
1576
+ convertLines(polygon, newPolygon, tolerance, true);
1577
+ geometry.push(newPolygon);
1578
+ }
1579
+ break;
1580
+ case "GeometryCollection":
1581
+ for (const singleGeometry of geojson.geometry.geometries) {
1582
+ convertFeature(features, {
1583
+ id,
1584
+ geometry: singleGeometry,
1585
+ properties: geojson.properties
1586
+ }, options, index);
1587
+ }
1588
+ break;
1589
+ default:
1590
+ throw new Error("Input data is not a valid GeoJSON object.");
1266
1591
  }
1267
- features.push(createFeature(id, type, geometry, geojson.properties));
1592
+ return createProtoFeature(id, type, geometry, geojson.properties);
1268
1593
  }
1269
1594
  function convertPoint(coords, out) {
1270
1595
  out.push(projectX(coords[0]), projectY(coords[1]), 0);
@@ -1288,7 +1613,7 @@ function convertLine(ring, out, tolerance, isPolygon) {
1288
1613
  }
1289
1614
  const last = out.length - 3;
1290
1615
  out[2] = 1;
1291
- simplify(out, 0, last, tolerance);
1616
+ simplifyPath(out, 0, last, tolerance);
1292
1617
  out[last + 2] = 1;
1293
1618
  out.size = Math.abs(size);
1294
1619
  out.start = 0;
@@ -1310,17 +1635,17 @@ function projectY(y) {
1310
1635
  return y2 < 0 ? 0 : y2 > 1 ? 1 : y2;
1311
1636
  }
1312
1637
 
1313
- // dist/lib/vector-tiler/clip.js
1314
- function clip(features, scale, k1, k2, axis, minAll, maxAll, options) {
1638
+ // dist/lib/vector-tiler/features/clip-features.js
1639
+ function clipFeatures(features2, scale, k1, k2, axis, minAll, maxAll, options) {
1315
1640
  k1 /= scale;
1316
1641
  k2 /= scale;
1317
1642
  if (minAll >= k1 && maxAll < k2) {
1318
- return features;
1643
+ return features2;
1319
1644
  } else if (maxAll < k1 || minAll >= k2) {
1320
1645
  return null;
1321
1646
  }
1322
1647
  const clipped = [];
1323
- for (const feature of features) {
1648
+ for (const feature of features2) {
1324
1649
  const geometry = feature.geometry;
1325
1650
  let type = feature.type;
1326
1651
  const min = axis === 0 ? feature.minX : feature.minY;
@@ -1352,7 +1677,7 @@ function clip(features, scale, k1, k2, axis, minAll, maxAll, options) {
1352
1677
  if (newGeometry.length) {
1353
1678
  if (options.lineMetrics && type === "LineString") {
1354
1679
  for (const line of newGeometry) {
1355
- clipped.push(createFeature(feature.id, type, line, feature.tags));
1680
+ clipped.push(createProtoFeature(feature.id, type, line, feature.tags));
1356
1681
  }
1357
1682
  continue;
1358
1683
  }
@@ -1367,7 +1692,7 @@ function clip(features, scale, k1, k2, axis, minAll, maxAll, options) {
1367
1692
  if (type === "Point" || type === "MultiPoint") {
1368
1693
  type = newGeometry.length === 3 ? "Point" : "MultiPoint";
1369
1694
  }
1370
- clipped.push(createFeature(feature.id, type, newGeometry, feature.tags));
1695
+ clipped.push(createProtoFeature(feature.id, type, newGeometry, feature.tags));
1371
1696
  }
1372
1697
  }
1373
1698
  return clipped.length ? clipped : null;
@@ -1475,14 +1800,14 @@ function intersectY(out, ax, ay, bx, by, y) {
1475
1800
  return t;
1476
1801
  }
1477
1802
 
1478
- // dist/lib/vector-tiler/wrap.js
1479
- function wrap(features, options) {
1803
+ // dist/lib/vector-tiler/features/wrap-features.js
1804
+ function wrapFeatures(features2, options) {
1480
1805
  const buffer = options.buffer / options.extent;
1481
- let merged = features;
1482
- const left = clip(features, 1, -1 - buffer, buffer, 0, -1, 2, options);
1483
- const right = clip(features, 1, 1 - buffer, 2 + buffer, 0, -1, 2, options);
1806
+ let merged = features2;
1807
+ const left = clipFeatures(features2, 1, -1 - buffer, buffer, 0, -1, 2, options);
1808
+ const right = clipFeatures(features2, 1, 1 - buffer, 2 + buffer, 0, -1, 2, options);
1484
1809
  if (left || right) {
1485
- merged = clip(features, 1, -buffer, 1 + buffer, 0, -1, 2, options) || [];
1810
+ merged = clipFeatures(features2, 1, -buffer, 1 + buffer, 0, -1, 2, options) || [];
1486
1811
  if (left) {
1487
1812
  merged = shiftFeatureCoords(left, 1).concat(merged);
1488
1813
  }
@@ -1492,30 +1817,39 @@ function wrap(features, options) {
1492
1817
  }
1493
1818
  return merged;
1494
1819
  }
1495
- function shiftFeatureCoords(features, offset) {
1820
+ function shiftFeatureCoords(features2, offset) {
1496
1821
  const newFeatures = [];
1497
- for (let i = 0; i < features.length; i++) {
1498
- const feature = features[i];
1822
+ for (let i = 0; i < features2.length; i++) {
1823
+ const feature = features2[i];
1499
1824
  const type = feature.type;
1500
1825
  let newGeometry;
1501
- if (type === "Point" || type === "MultiPoint" || type === "LineString") {
1502
- newGeometry = shiftCoords(feature.geometry, offset);
1503
- } else if (type === "MultiLineString" || type === "Polygon") {
1504
- newGeometry = [];
1505
- for (const line of feature.geometry) {
1506
- newGeometry.push(shiftCoords(line, offset));
1507
- }
1508
- } else if (type === "MultiPolygon") {
1509
- newGeometry = [];
1510
- for (const polygon of feature.geometry) {
1511
- const newPolygon = [];
1512
- for (const line of polygon) {
1513
- newPolygon.push(shiftCoords(line, offset));
1826
+ switch (type) {
1827
+ case "Point":
1828
+ case "MultiPoint":
1829
+ case "LineString":
1830
+ newGeometry = shiftCoords(feature.geometry, offset);
1831
+ break;
1832
+ case "MultiLineString":
1833
+ case "Polygon":
1834
+ newGeometry = [];
1835
+ for (const line of feature.geometry) {
1836
+ newGeometry.push(shiftCoords(line, offset));
1514
1837
  }
1515
- newGeometry.push(newPolygon);
1516
- }
1838
+ break;
1839
+ case "MultiPolygon":
1840
+ newGeometry = [];
1841
+ for (const polygon of feature.geometry) {
1842
+ const newPolygon = [];
1843
+ for (const line of polygon) {
1844
+ newPolygon.push(shiftCoords(line, offset));
1845
+ }
1846
+ newGeometry.push(newPolygon);
1847
+ }
1848
+ break;
1849
+ default:
1850
+ throw new Error(String(type));
1517
1851
  }
1518
- newFeatures.push(createFeature(feature.id, type, newGeometry, feature.tags));
1852
+ newFeatures.push(createProtoFeature(feature.id, type, newGeometry, feature.tags));
1519
1853
  }
1520
1854
  return newFeatures;
1521
1855
  }
@@ -1532,148 +1866,48 @@ function shiftCoords(points, offset) {
1532
1866
  return newPoints;
1533
1867
  }
1534
1868
 
1535
- // dist/lib/vector-tiler/transform.js
1536
- function transformTile(tile, extent) {
1537
- if (tile.transformed) {
1538
- return tile;
1539
- }
1540
- const z2 = 1 << tile.z;
1541
- const tx = tile.x;
1542
- const ty = tile.y;
1543
- for (const feature of tile.features) {
1544
- const geom = feature.geometry;
1545
- const type = feature.type;
1546
- feature.geometry = [];
1547
- if (type === 1) {
1548
- for (let j = 0; j < geom.length; j += 2) {
1549
- feature.geometry.push(transformPoint(geom[j], geom[j + 1], extent, z2, tx, ty));
1550
- }
1551
- } else {
1552
- for (let j = 0; j < geom.length; j++) {
1553
- const ring = [];
1554
- for (let k = 0; k < geom[j].length; k += 2) {
1555
- ring.push(transformPoint(geom[j][k], geom[j][k + 1], extent, z2, tx, ty));
1556
- }
1557
- feature.geometry.push(ring);
1558
- }
1559
- }
1560
- }
1561
- tile.transformed = true;
1562
- return tile;
1563
- }
1564
- function transformPoint(x, y, extent, z2, tx, ty) {
1565
- return [Math.round(extent * (x * z2 - tx)), Math.round(extent * (y * z2 - ty))];
1566
- }
1567
-
1568
- // dist/lib/vector-tiler/tile.js
1569
- function createTile(features, z, tx, ty, options) {
1570
- const tolerance = z === options.maxZoom ? 0 : options.tolerance / ((1 << z) * options.extent);
1571
- const tile = {
1572
- features: [],
1573
- numPoints: 0,
1574
- numSimplified: 0,
1575
- numFeatures: features.length,
1576
- source: null,
1577
- x: tx,
1578
- y: ty,
1579
- z,
1580
- transformed: false,
1581
- minX: 2,
1582
- minY: 1,
1583
- maxX: -1,
1584
- maxY: 0
1585
- };
1586
- for (const feature of features) {
1587
- addFeature(tile, feature, tolerance, options);
1588
- }
1589
- return tile;
1590
- }
1591
- function addFeature(tile, feature, tolerance, options) {
1592
- const geom = feature.geometry;
1593
- const type = feature.type;
1594
- const simplified = [];
1595
- tile.minX = Math.min(tile.minX, feature.minX);
1596
- tile.minY = Math.min(tile.minY, feature.minY);
1597
- tile.maxX = Math.max(tile.maxX, feature.maxX);
1598
- tile.maxY = Math.max(tile.maxY, feature.maxY);
1599
- if (type === "Point" || type === "MultiPoint") {
1600
- for (let i = 0; i < geom.length; i += 3) {
1601
- simplified.push(geom[i], geom[i + 1]);
1602
- tile.numPoints++;
1603
- tile.numSimplified++;
1604
- }
1605
- } else if (type === "LineString") {
1606
- addLine(simplified, geom, tile, tolerance, false, false);
1607
- } else if (type === "MultiLineString" || type === "Polygon") {
1608
- for (let i = 0; i < geom.length; i++) {
1609
- addLine(simplified, geom[i], tile, tolerance, type === "Polygon", i === 0);
1610
- }
1611
- } else if (type === "MultiPolygon") {
1612
- for (let k = 0; k < geom.length; k++) {
1613
- const polygon = geom[k];
1614
- for (let i = 0; i < polygon.length; i++) {
1615
- addLine(simplified, polygon[i], tile, tolerance, true, i === 0);
1616
- }
1617
- }
1618
- }
1619
- if (simplified.length) {
1620
- let tags = feature.tags || null;
1621
- if (type === "LineString" && options.lineMetrics) {
1622
- tags = {};
1623
- for (const key in feature.tags)
1624
- tags[key] = feature.tags[key];
1625
- tags.mapbox_clip_start = geom.start / geom.size;
1626
- tags.mapbox_clip_end = geom.end / geom.size;
1627
- }
1628
- const tileFeature = {
1629
- geometry: simplified,
1630
- type: type === "Polygon" || type === "MultiPolygon" ? 3 : type === "LineString" || type === "MultiLineString" ? 2 : 1,
1631
- tags
1632
- };
1633
- if (feature.id !== null) {
1634
- tileFeature.id = feature.id;
1635
- }
1636
- tile.features.push(tileFeature);
1637
- }
1638
- }
1639
- function addLine(result, geom, tile, tolerance, isPolygon, isOuter) {
1640
- const sqTolerance = tolerance * tolerance;
1641
- if (tolerance > 0 && geom.size < (isPolygon ? sqTolerance : tolerance)) {
1642
- tile.numPoints += geom.length / 3;
1643
- return;
1644
- }
1645
- const ring = [];
1646
- for (let i = 0; i < geom.length; i += 3) {
1647
- if (tolerance === 0 || geom[i + 2] > sqTolerance) {
1648
- tile.numSimplified++;
1649
- ring.push(geom[i], geom[i + 1]);
1869
+ // dist/table-tile-source.js
1870
+ var TableTileSource = {
1871
+ name: "TableTiler",
1872
+ id: "table-tiler",
1873
+ version: "0.0.0",
1874
+ extensions: ["mvt"],
1875
+ mimeTypes: ["application/octet-stream"],
1876
+ options: {
1877
+ table: {
1878
+ coordinates: "local",
1879
+ promoteId: void 0,
1880
+ maxZoom: 14,
1881
+ indexMaxZoom: 5,
1882
+ maxPointsPerTile: 1e4,
1883
+ tolerance: 3,
1884
+ extent: 4096,
1885
+ buffer: 64,
1886
+ generateId: void 0
1650
1887
  }
1651
- tile.numPoints++;
1652
- }
1653
- if (isPolygon)
1654
- rewind(ring, isOuter);
1655
- result.push(ring);
1656
- }
1657
- function rewind(ring, clockwise) {
1658
- let area = 0;
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]);
1888
+ },
1889
+ type: "table",
1890
+ testURL: (url) => url.endsWith(".geojson"),
1891
+ createDataSource(url, options) {
1892
+ var _a, _b;
1893
+ const needsLoading = typeof url === "string" || url instanceof Blob;
1894
+ const loader = (_b = (_a = options == null ? void 0 : options.table) == null ? void 0 : _a.loaders) == null ? void 0 : _b[0];
1895
+ const tablePromise = needsLoading ? loadTable(url, loader) : url;
1896
+ return new DynamicVectorTileSource(tablePromise, options);
1661
1897
  }
1662
- if (area > 0 === clockwise) {
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;
1670
- }
1898
+ // @ts-expect-error
1899
+ };
1900
+ async function loadTable(url, loader) {
1901
+ if (typeof url === "string") {
1902
+ const response = await fetch(url);
1903
+ const data2 = await response.arrayBuffer();
1904
+ return await loader.parse(data2);
1671
1905
  }
1906
+ const data = await url.arrayBuffer();
1907
+ return await loader.parse(data);
1672
1908
  }
1673
-
1674
- // dist/table-tile-source.js
1675
- var _TableTileSource = class {
1676
- /** Stats for this TableTileSource */
1909
+ var _DynamicVectorTileSource = class {
1910
+ /** Stats for this DynamicVectorTileSource */
1677
1911
  stats = new import_stats.Stats({
1678
1912
  id: "table-tile-source",
1679
1913
  stats: [new import_stats.Stat("tiles", "count"), new import_stats.Stat("features", "count")]
@@ -1682,6 +1916,7 @@ var _TableTileSource = class {
1682
1916
  mimeType = "application/vnd.mapbox-vector-tile";
1683
1917
  localCoordinates = true;
1684
1918
  /** The props that this tile source was created with */
1919
+ // @ts-expect-error
1685
1920
  props;
1686
1921
  /* Schema of the data */
1687
1922
  schema = null;
@@ -1694,7 +1929,7 @@ var _TableTileSource = class {
1694
1929
  /** Metadata for the tile source (generated TileJSON/tilestats */
1695
1930
  metadata;
1696
1931
  constructor(table, props) {
1697
- this.props = { ..._TableTileSource.defaultProps, ...props };
1932
+ this.props = { ...TableTileSource.options.table, ...props == null ? void 0 : props.table };
1698
1933
  this.getTileData = this.getTileData.bind(this);
1699
1934
  this.ready = this.initializeTilesAsync(table);
1700
1935
  this.metadata = this.getMetadata();
@@ -1738,11 +1973,11 @@ var _TableTileSource = class {
1738
1973
  * @note Application must await `source.ready` before calling sync methods.
1739
1974
  */
1740
1975
  getTileSync(tileIndex) {
1741
- const rawTile = this.getRawTile(tileIndex);
1742
- if (!rawTile) {
1976
+ const protoTile = this.getProtoTile(tileIndex);
1977
+ if (!protoTile) {
1743
1978
  return null;
1744
1979
  }
1745
- return convertToGeoJSONTable(rawTile, {
1980
+ return convertTileToGeoJSON(protoTile, {
1746
1981
  coordinates: this.props.coordinates,
1747
1982
  tileIndex,
1748
1983
  extent: this.props.extent
@@ -1759,28 +1994,28 @@ var _TableTileSource = class {
1759
1994
  if (this.props.promoteId && this.props.generateId) {
1760
1995
  throw new Error("promoteId and generateId cannot be used together.");
1761
1996
  }
1762
- import_loader_utils3.log.log(1, "TableTileSource creating root tiles", this.props)();
1997
+ import_loader_utils3.log.log(1, "DynamicVectorTileSource creating root tiles", this.props)();
1763
1998
  import_loader_utils3.log.time(1, "preprocess table")();
1764
- let features = convert(table, this.props);
1999
+ let features2 = convertFeaturesToProtoFeature(table, this.props);
1765
2000
  import_loader_utils3.log.timeEnd(1, "preprocess table")();
1766
2001
  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")();
2002
+ features2 = wrapFeatures(features2, this.props);
2003
+ if (features2.length === 0) {
2004
+ import_loader_utils3.log.log(1, "DynamicVectorTileSource: no features generated")();
1770
2005
  return;
1771
2006
  }
1772
- this.splitTile(features, 0, 0, 0);
2007
+ this.splitTile(features2, 0, 0, 0);
1773
2008
  const rootTile = this.tiles[0];
1774
2009
  import_loader_utils3.log.log(1, `root tile features: ${rootTile.numFeatures}, points: ${rootTile.numPoints}`)();
1775
2010
  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)();
2011
+ import_loader_utils3.log.log(1, `DynamicVectorTileSource: tiles generated: ${this.stats.get("total").count}`, this.stats)();
1777
2012
  }
1778
2013
  /**
1779
2014
  * Return geojsonvt-style "half formed" vector tile
1780
2015
  * @note Application must await `source.ready` before calling sync methods.
1781
2016
  */
1782
2017
  // eslint-disable-next-line complexity, max-statements
1783
- getRawTile(tileIndex) {
2018
+ getProtoTile(tileIndex) {
1784
2019
  const { z, y } = tileIndex;
1785
2020
  let { x } = tileIndex;
1786
2021
  const { extent } = this.props;
@@ -1804,12 +2039,12 @@ var _TableTileSource = class {
1804
2039
  y0 = y0 >> 1;
1805
2040
  parent = this.tiles[toID(z0, x0, y0)];
1806
2041
  }
1807
- if (!parent || !parent.source) {
2042
+ if (!parent || !parent.sourceFeatures) {
1808
2043
  return null;
1809
2044
  }
1810
2045
  import_loader_utils3.log.log(1, "found parent tile z%d-%d-%d", z0, x0, y0)();
1811
2046
  import_loader_utils3.log.time(1, "drilling down")();
1812
- this.splitTile(parent.source, z0, x0, y0, z, x, y);
2047
+ this.splitTile(parent.sourceFeatures, z0, x0, y0, z, x, y);
1813
2048
  import_loader_utils3.log.timeEnd(1, "drilling down")();
1814
2049
  return this.tiles[id] ? transformTile(this.tiles[id], extent) : null;
1815
2050
  }
@@ -1822,33 +2057,33 @@ var _TableTileSource = class {
1822
2057
  * zoom or the number of points is low as specified in the props.
1823
2058
  */
1824
2059
  // eslint-disable-next-line max-params, max-statements, complexity
1825
- splitTile(features, z, x, y, cz, cx, cy) {
1826
- const stack = [features, z, x, y];
2060
+ splitTile(features2, z, x, y, cz, cx, cy) {
2061
+ const stack = [features2, z, x, y];
1827
2062
  while (stack.length) {
1828
2063
  y = stack.pop();
1829
2064
  x = stack.pop();
1830
2065
  z = stack.pop();
1831
- features = stack.pop();
2066
+ features2 = stack.pop();
1832
2067
  const z2 = 1 << z;
1833
2068
  const id = toID(z, x, y);
1834
2069
  let tile = this.tiles[id];
1835
2070
  if (!tile) {
1836
2071
  import_loader_utils3.log.time(2, "tile creation")();
1837
- tile = this.tiles[id] = createTile(features, z, x, y, this.props);
2072
+ tile = this.tiles[id] = createProtoTile(features2, z, x, y, this.props);
1838
2073
  this.tileCoords.push({ z, x, y });
1839
2074
  const key = `z${z}`;
1840
2075
  let stat = this.stats.get(key, "count");
1841
2076
  stat.incrementCount();
1842
2077
  stat = this.stats.get("total");
1843
2078
  stat.incrementCount();
1844
- stat = _TableTileSource.stats.get(key, "count");
2079
+ stat = _DynamicVectorTileSource.stats.get(key, "count");
1845
2080
  stat.incrementCount();
1846
- stat = _TableTileSource.stats.get("total");
2081
+ stat = _DynamicVectorTileSource.stats.get("total");
1847
2082
  stat.incrementCount();
1848
2083
  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
2084
  import_loader_utils3.log.timeEnd(2, "tile creation")();
1850
2085
  }
1851
- tile.source = features;
2086
+ tile.sourceFeatures = features2;
1852
2087
  if (cz === void 0) {
1853
2088
  if (z === this.props.indexMaxZoom || tile.numPoints <= this.props.maxPointsPerTile) {
1854
2089
  continue;
@@ -1861,8 +2096,8 @@ var _TableTileSource = class {
1861
2096
  continue;
1862
2097
  }
1863
2098
  }
1864
- tile.source = null;
1865
- if (features.length === 0)
2099
+ tile.sourceFeatures = null;
2100
+ if (features2.length === 0)
1866
2101
  continue;
1867
2102
  import_loader_utils3.log.time(2, "clipping tile")();
1868
2103
  const k1 = 0.5 * this.props.buffer / this.props.extent;
@@ -1873,17 +2108,17 @@ var _TableTileSource = class {
1873
2108
  let bl = null;
1874
2109
  let tr = null;
1875
2110
  let br = null;
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);
1878
- features = null;
2111
+ let left = clipFeatures(features2, z2, x - k1, x + k3, 0, tile.minX, tile.maxX, this.props);
2112
+ let right = clipFeatures(features2, z2, x + k2, x + k4, 0, tile.minX, tile.maxX, this.props);
2113
+ features2 = null;
1879
2114
  if (left) {
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);
2115
+ tl = clipFeatures(left, z2, y - k1, y + k3, 1, tile.minY, tile.maxY, this.props);
2116
+ bl = clipFeatures(left, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, this.props);
1882
2117
  left = null;
1883
2118
  }
1884
2119
  if (right) {
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);
2120
+ tr = clipFeatures(right, z2, y - k1, y + k3, 1, tile.minY, tile.maxY, this.props);
2121
+ br = clipFeatures(right, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, this.props);
1887
2122
  right = null;
1888
2123
  }
1889
2124
  import_loader_utils3.log.timeEnd(2, "clipping tile")();
@@ -1894,109 +2129,13 @@ var _TableTileSource = class {
1894
2129
  }
1895
2130
  }
1896
2131
  };
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({
2132
+ var DynamicVectorTileSource = _DynamicVectorTileSource;
2133
+ /** Global stats for all DynamicVectorTileSources */
2134
+ __publicField(DynamicVectorTileSource, "stats", new import_stats.Stats({
1925
2135
  id: "table-tile-source-all",
1926
2136
  stats: [new import_stats.Stat("count", "tiles"), new import_stats.Stat("count", "features")]
1927
2137
  }));
1928
2138
  function toID(z, x, y) {
1929
2139
  return ((1 << z) * y + x) * 32 + z;
1930
2140
  }
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;
2001
- }
2002
2141
  //# sourceMappingURL=index.cjs.map