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

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 (74) hide show
  1. package/dist/dist.dev.js +777 -688
  2. package/dist/dist.min.js +1 -1
  3. package/dist/index.cjs +746 -659
  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/parse-tilejson.js +1 -1
  9. package/dist/lib/utils/geometry-utils.js +1 -1
  10. package/dist/lib/vector-tiler/{clip.d.ts → features/clip-features.d.ts} +4 -4
  11. package/dist/lib/vector-tiler/features/clip-features.d.ts.map +1 -0
  12. package/dist/lib/vector-tiler/{clip.js → features/clip-features.js} +4 -4
  13. package/dist/lib/vector-tiler/{convert.d.ts → features/convert-feature.d.ts} +7 -7
  14. package/dist/lib/vector-tiler/features/convert-feature.d.ts.map +1 -0
  15. package/dist/lib/vector-tiler/features/convert-feature.js +140 -0
  16. package/dist/lib/vector-tiler/features/proto-feature.d.ts +30 -0
  17. package/dist/lib/vector-tiler/features/proto-feature.d.ts.map +1 -0
  18. package/dist/lib/vector-tiler/features/proto-feature.js +52 -0
  19. package/dist/lib/vector-tiler/{simplify.d.ts → features/simplify-path.d.ts} +2 -2
  20. package/dist/lib/vector-tiler/features/simplify-path.d.ts.map +1 -0
  21. package/dist/lib/vector-tiler/{simplify.js → features/simplify-path.js} +3 -3
  22. package/dist/lib/vector-tiler/{wrap.d.ts → features/wrap-features.d.ts} +5 -5
  23. package/dist/lib/vector-tiler/features/wrap-features.d.ts.map +1 -0
  24. package/dist/lib/vector-tiler/{wrap.js → features/wrap-features.js} +33 -26
  25. package/dist/lib/vector-tiler/proto-tile.d.ts +40 -0
  26. package/dist/lib/vector-tiler/proto-tile.d.ts.map +1 -0
  27. package/dist/lib/vector-tiler/proto-tile.js +138 -0
  28. package/dist/lib/vector-tiler/tile-to-geojson.d.ts +12 -0
  29. package/dist/lib/vector-tiler/tile-to-geojson.d.ts.map +1 -0
  30. package/dist/lib/vector-tiler/tile-to-geojson.js +81 -0
  31. package/dist/lib/vector-tiler/transform-tile.d.ts +7 -0
  32. package/dist/lib/vector-tiler/transform-tile.d.ts.map +1 -0
  33. package/dist/lib/vector-tiler/transform-tile.js +41 -0
  34. package/dist/mvt-loader.js +1 -1
  35. package/dist/mvt-source.d.ts +31 -14
  36. package/dist/mvt-source.d.ts.map +1 -1
  37. package/dist/mvt-source.js +26 -6
  38. package/dist/mvt-worker.js +4 -4
  39. package/dist/table-tile-source.d.ts +66 -36
  40. package/dist/table-tile-source.d.ts.map +1 -1
  41. package/dist/table-tile-source.js +167 -117
  42. package/dist/tilejson-loader.js +1 -1
  43. package/package.json +6 -6
  44. package/src/index.ts +13 -6
  45. package/src/lib/parse-tilejson.ts +1 -1
  46. package/src/lib/utils/geometry-utils.ts +1 -1
  47. package/src/lib/vector-tiler/{clip.ts → features/clip-features.ts} +8 -8
  48. package/src/lib/vector-tiler/{convert.ts → features/convert-feature.ts} +91 -70
  49. package/src/lib/vector-tiler/features/proto-feature.ts +104 -0
  50. package/src/lib/vector-tiler/{simplify.ts → features/simplify-path.ts} +8 -3
  51. package/src/lib/vector-tiler/{wrap.ts → features/wrap-features.ts} +44 -29
  52. package/src/lib/vector-tiler/proto-tile.ts +217 -0
  53. package/src/lib/vector-tiler/tile-to-geojson.ts +105 -0
  54. package/src/lib/vector-tiler/transform-tile.ts +57 -0
  55. package/src/mvt-source.ts +42 -18
  56. package/src/table-tile-source.ts +130 -85
  57. package/src/tilejson-loader.ts +2 -2
  58. package/dist/lib/vector-tiler/clip.d.ts.map +0 -1
  59. package/dist/lib/vector-tiler/convert.d.ts.map +0 -1
  60. package/dist/lib/vector-tiler/convert.js +0 -139
  61. package/dist/lib/vector-tiler/feature.d.ts +0 -3
  62. package/dist/lib/vector-tiler/feature.d.ts.map +0 -1
  63. package/dist/lib/vector-tiler/feature.js +0 -44
  64. package/dist/lib/vector-tiler/simplify.d.ts.map +0 -1
  65. package/dist/lib/vector-tiler/tile.d.ts +0 -38
  66. package/dist/lib/vector-tiler/tile.d.ts.map +0 -1
  67. package/dist/lib/vector-tiler/tile.js +0 -123
  68. package/dist/lib/vector-tiler/transform.d.ts +0 -7
  69. package/dist/lib/vector-tiler/transform.d.ts.map +0 -1
  70. package/dist/lib/vector-tiler/transform.js +0 -41
  71. package/dist/lib/vector-tiler/wrap.d.ts.map +0 -1
  72. package/src/lib/vector-tiler/feature.ts +0 -47
  73. package/src/lib/vector-tiler/tile.ts +0 -187
  74. package/src/lib/vector-tiler/transform.ts +0 -57
package/dist/index.cjs CHANGED
@@ -43,6 +43,243 @@ __export(dist_exports, {
43
43
  });
44
44
  module.exports = __toCommonJS(dist_exports);
45
45
 
46
+ // dist/lib/parse-tilejson.js
47
+ var isObject = (x) => x !== null && typeof x === "object";
48
+ function parseTileJSON(jsonMetadata, options) {
49
+ var _a;
50
+ if (!jsonMetadata || !isObject(jsonMetadata)) {
51
+ return null;
52
+ }
53
+ let tileJSON = {
54
+ name: jsonMetadata.name || "",
55
+ description: jsonMetadata.description || ""
56
+ };
57
+ if (typeof jsonMetadata.generator === "string") {
58
+ tileJSON.generator = jsonMetadata.generator;
59
+ }
60
+ if (typeof jsonMetadata.generator_options === "string") {
61
+ tileJSON.generatorOptions = jsonMetadata.generator_options;
62
+ }
63
+ tileJSON.boundingBox = parseBounds(jsonMetadata.bounds) || parseBounds(jsonMetadata.antimeridian_adjusted_bounds);
64
+ tileJSON.center = parseCenter(jsonMetadata.center);
65
+ tileJSON.maxZoom = safeParseFloat(jsonMetadata.maxzoom);
66
+ tileJSON.minZoom = safeParseFloat(jsonMetadata.minzoom);
67
+ if (typeof (jsonMetadata == null ? void 0 : jsonMetadata.json) === "string") {
68
+ try {
69
+ tileJSON.metaJson = JSON.parse(jsonMetadata.json);
70
+ } catch (error) {
71
+ console.warn("Failed to parse tilejson.json field", error);
72
+ }
73
+ }
74
+ const tilestats = jsonMetadata.tilestats || ((_a = tileJSON.metaJson) == null ? void 0 : _a.tilestats);
75
+ const tileStatsLayers = parseTilestatsLayers(tilestats, options);
76
+ const tileJSONlayers = parseTileJSONLayers(jsonMetadata.vector_layers);
77
+ const layers = mergeLayers(tileJSONlayers, tileStatsLayers);
78
+ tileJSON = {
79
+ ...tileJSON,
80
+ layers
81
+ };
82
+ if (tileJSON.maxZoom === null && layers.length > 0) {
83
+ tileJSON.maxZoom = layers[0].maxZoom || null;
84
+ }
85
+ if (tileJSON.minZoom === null && layers.length > 0) {
86
+ tileJSON.minZoom = layers[0].minZoom || null;
87
+ }
88
+ return tileJSON;
89
+ }
90
+ function parseTileJSONLayers(layers) {
91
+ if (!Array.isArray(layers)) {
92
+ return [];
93
+ }
94
+ return layers.map((layer) => parseTileJSONLayer(layer));
95
+ }
96
+ function parseTileJSONLayer(layer) {
97
+ const fields = Object.entries(layer.fields || []).map(([key, datatype]) => ({
98
+ name: key,
99
+ ...attributeTypeToFieldType(String(datatype))
100
+ }));
101
+ const layer2 = { ...layer };
102
+ delete layer2.fields;
103
+ return {
104
+ name: layer.id || "",
105
+ ...layer2,
106
+ fields
107
+ };
108
+ }
109
+ function parseTilestatsLayers(tilestats, options) {
110
+ if (isObject(tilestats) && Array.isArray(tilestats.layers)) {
111
+ return tilestats.layers.map((layer) => parseTilestatsForLayer(layer, options));
112
+ }
113
+ return [];
114
+ }
115
+ function parseTilestatsForLayer(layer, options) {
116
+ const fields = [];
117
+ const indexedAttributes = {};
118
+ const attributes = layer.attributes || [];
119
+ for (const attribute of attributes) {
120
+ const name = attribute.attribute;
121
+ if (typeof name === "string") {
122
+ if (name.split("|").length > 1) {
123
+ const fname = name.split("|")[0];
124
+ indexedAttributes[fname] = indexedAttributes[fname] || [];
125
+ indexedAttributes[fname].push(attribute);
126
+ console.warn("ignoring tilestats indexed field", fname);
127
+ } else if (!fields[name]) {
128
+ fields.push(attributeToField(attribute, options));
129
+ } else {
130
+ }
131
+ }
132
+ }
133
+ return {
134
+ name: layer.layer || "",
135
+ dominantGeometry: layer.geometry,
136
+ fields
137
+ };
138
+ }
139
+ function mergeLayers(layers, tilestatsLayers) {
140
+ return layers.map((layer) => {
141
+ const tilestatsLayer = tilestatsLayers.find((tsLayer) => tsLayer.name === layer.name);
142
+ const fields = (tilestatsLayer == null ? void 0 : tilestatsLayer.fields) || [];
143
+ const layer2 = { ...layer };
144
+ delete layer2.fields;
145
+ return {
146
+ ...layer2,
147
+ ...tilestatsLayer,
148
+ fields
149
+ };
150
+ });
151
+ }
152
+ function parseBounds(bounds) {
153
+ const result = fromArrayOrString(bounds);
154
+ if (Array.isArray(result) && result.length === 4 && [result[0], result[2]].every(isLng) && [result[1], result[3]].every(isLat)) {
155
+ return [
156
+ [result[0], result[1]],
157
+ [result[2], result[3]]
158
+ ];
159
+ }
160
+ return void 0;
161
+ }
162
+ function parseCenter(center) {
163
+ const result = fromArrayOrString(center);
164
+ if (Array.isArray(result) && result.length === 3 && isLng(result[0]) && isLat(result[1]) && isZoom(result[2])) {
165
+ return result;
166
+ }
167
+ return null;
168
+ }
169
+ function safeParseFloat(input) {
170
+ const result = typeof input === "string" ? parseFloat(input) : typeof input === "number" ? input : null;
171
+ return result === null || isNaN(result) ? null : result;
172
+ }
173
+ function isLat(num) {
174
+ return Number.isFinite(num) && num <= 90 && num >= -90;
175
+ }
176
+ function isLng(num) {
177
+ return Number.isFinite(num) && num <= 180 && num >= -180;
178
+ }
179
+ function isZoom(num) {
180
+ return Number.isFinite(num) && num >= 0 && num <= 22;
181
+ }
182
+ function fromArrayOrString(data) {
183
+ if (typeof data === "string") {
184
+ return data.split(",").map(parseFloat);
185
+ } else if (Array.isArray(data)) {
186
+ return data;
187
+ }
188
+ return null;
189
+ }
190
+ var attrTypeMap = {
191
+ number: {
192
+ type: "float32"
193
+ },
194
+ numeric: {
195
+ type: "float32"
196
+ },
197
+ string: {
198
+ type: "utf8"
199
+ },
200
+ vachar: {
201
+ type: "utf8"
202
+ },
203
+ float: {
204
+ type: "float32"
205
+ },
206
+ int: {
207
+ type: "int32"
208
+ },
209
+ int4: {
210
+ type: "int32"
211
+ },
212
+ boolean: {
213
+ type: "boolean"
214
+ },
215
+ bool: {
216
+ type: "boolean"
217
+ }
218
+ };
219
+ function attributeToField(attribute = {}, options) {
220
+ var _a;
221
+ const fieldTypes = attributeTypeToFieldType(attribute.type);
222
+ const field = {
223
+ name: attribute.attribute,
224
+ // what happens if attribute type is string...
225
+ // filterProps: getFilterProps(fieldTypes.type, attribute),
226
+ ...fieldTypes
227
+ };
228
+ if (typeof attribute.min === "number") {
229
+ field.min = attribute.min;
230
+ }
231
+ if (typeof attribute.max === "number") {
232
+ field.max = attribute.max;
233
+ }
234
+ if (typeof attribute.count === "number") {
235
+ field.uniqueValueCount = attribute.count;
236
+ }
237
+ if (attribute.values) {
238
+ field.values = attribute.values;
239
+ }
240
+ if (field.values && typeof options.maxValues === "number") {
241
+ field.values = (_a = field.values) == null ? void 0 : _a.slice(0, options.maxValues);
242
+ }
243
+ return field;
244
+ }
245
+ function attributeTypeToFieldType(aType) {
246
+ const type = aType.toLowerCase();
247
+ if (!type || !attrTypeMap[type]) {
248
+ }
249
+ return attrTypeMap[type] || { type: "string" };
250
+ }
251
+
252
+ // dist/tilejson-loader.js
253
+ var VERSION = true ? "4.3.0-alpha.2" : "latest";
254
+ var TileJSONLoader = {
255
+ dataType: null,
256
+ batchType: null,
257
+ name: "TileJSON",
258
+ id: "tilejson",
259
+ module: "pmtiles",
260
+ version: VERSION,
261
+ worker: true,
262
+ extensions: ["json"],
263
+ mimeTypes: ["application/json"],
264
+ text: true,
265
+ options: {
266
+ tilejson: {
267
+ maxValues: void 0
268
+ }
269
+ },
270
+ parse: async (arrayBuffer, options) => {
271
+ const jsonString = new TextDecoder().decode(arrayBuffer);
272
+ const json = JSON.parse(jsonString);
273
+ const tilejsonOptions = { ...TileJSONLoader.options.tilejson, ...options == null ? void 0 : options.tilejson };
274
+ return parseTileJSON(json, tilejsonOptions);
275
+ },
276
+ parseTextSync: (text, options) => {
277
+ const json = JSON.parse(text);
278
+ const tilejsonOptions = { ...TileJSONLoader.options.tilejson, ...options == null ? void 0 : options.tilejson };
279
+ return parseTileJSON(json, tilejsonOptions);
280
+ }
281
+ };
282
+
46
283
  // dist/lib/parse-mvt.js
47
284
  var import_gis = require("@loaders.gl/gis");
48
285
  var import_loader_utils = require("@loaders.gl/loader-utils");
@@ -71,7 +308,7 @@ function convertToLocalCoordinates(coordinates, extent) {
71
308
  p[1] /= extent;
72
309
  }
73
310
  function convertToLocalCoordinatesFlat(data, extent) {
74
- for (let i = 0, il = data.length; i < il; ++i) {
311
+ for (let i = 0; i < data.length; ++i) {
75
312
  data[i] /= extent;
76
313
  }
77
314
  }
@@ -610,7 +847,7 @@ function parseToBinary(arrayBuffer, options) {
610
847
  return binaryData;
611
848
  }
612
849
  function parseToFlatGeoJson(arrayBuffer, options) {
613
- const features = [];
850
+ const features2 = [];
614
851
  const geometryInfo = {
615
852
  coordLength: 2,
616
853
  pointPositionsCount: 0,
@@ -624,7 +861,7 @@ function parseToFlatGeoJson(arrayBuffer, options) {
624
861
  polygonFeaturesCount: 0
625
862
  };
626
863
  if (arrayBuffer.byteLength <= 0) {
627
- return [features, geometryInfo];
864
+ return [features2, geometryInfo];
628
865
  }
629
866
  const tile = new VectorTile(new import_pbf.default(arrayBuffer));
630
867
  const selectedLayers = options && Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);
@@ -636,16 +873,16 @@ function parseToFlatGeoJson(arrayBuffer, options) {
636
873
  for (let i = 0; i < vectorTileLayer.length; i++) {
637
874
  const vectorTileFeature = vectorTileLayer.getBinaryFeature(i, geometryInfo);
638
875
  const decodedFeature = getDecodedFeatureBinary(vectorTileFeature, options, layerName);
639
- features.push(decodedFeature);
876
+ features2.push(decodedFeature);
640
877
  }
641
878
  });
642
- return [features, geometryInfo];
879
+ return [features2, geometryInfo];
643
880
  }
644
881
  function parseToGeojsonFeatures(arrayBuffer, options) {
645
882
  if (arrayBuffer.byteLength <= 0) {
646
883
  return [];
647
884
  }
648
- const features = [];
885
+ const features2 = [];
649
886
  const tile = new VectorTile(new import_pbf.default(arrayBuffer));
650
887
  const selectedLayers = Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);
651
888
  selectedLayers.forEach((layerName) => {
@@ -656,10 +893,10 @@ function parseToGeojsonFeatures(arrayBuffer, options) {
656
893
  for (let i = 0; i < vectorTileLayer.length; i++) {
657
894
  const vectorTileFeature = vectorTileLayer.getGeoJSONFeature(i);
658
895
  const decodedFeature = getDecodedFeature(vectorTileFeature, options, layerName);
659
- features.push(decodedFeature);
896
+ features2.push(decodedFeature);
660
897
  }
661
898
  });
662
- return features;
899
+ return features2;
663
900
  }
664
901
  function checkOptions(options) {
665
902
  var _a;
@@ -691,14 +928,14 @@ function getDecodedFeatureBinary(feature, options, layerName) {
691
928
  }
692
929
 
693
930
  // dist/mvt-loader.js
694
- var VERSION = true ? "4.3.0-alpha.1" : "latest";
931
+ var VERSION2 = true ? "4.3.0-alpha.2" : "latest";
695
932
  var MVTWorkerLoader = {
696
933
  dataType: null,
697
934
  batchType: null,
698
935
  name: "Mapbox Vector Tile",
699
936
  id: "mvt",
700
937
  module: "mvt",
701
- version: VERSION,
938
+ version: VERSION2,
702
939
  // Note: ArcGIS uses '.pbf' extension and 'application/octet-stream'
703
940
  extensions: ["mvt", "pbf"],
704
941
  mimeTypes: [
@@ -726,248 +963,31 @@ var MVTLoader = {
726
963
  binary: true
727
964
  };
728
965
 
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,
948
- options: {
949
- tilejson: {
950
- maxValues: void 0
951
- }
952
- },
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);
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 = {
971
+ name: "MVT",
972
+ id: "mvt",
973
+ module: "mvt",
974
+ version: "0.0.0",
975
+ extensions: ["mvt"],
976
+ mimeTypes: ["application/octet-stream"],
977
+ options: {
978
+ mvt: {
979
+ // TODO - add options here
980
+ }
981
+ },
982
+ type: "mvt",
983
+ fromUrl: true,
984
+ fromBlob: false,
985
+ testURL: (url) => true,
986
+ createDataSource(url, props) {
987
+ return new MVTTileSource(url, props);
963
988
  }
964
989
  };
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 {
990
+ var MVTTileSource = class extends import_loader_utils2.DataSource {
971
991
  props;
972
992
  url;
973
993
  metadataUrl = null;
@@ -976,12 +996,13 @@ var MVTSource = class extends import_loader_utils2.DataSource {
976
996
  metadata;
977
997
  extension;
978
998
  mimeType = null;
979
- constructor(props) {
999
+ constructor(url, props) {
1000
+ var _a, _b;
980
1001
  super(props);
981
1002
  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";
1003
+ this.url = (0, import_loader_utils2.resolvePath)(url);
1004
+ this.metadataUrl = ((_a = props.mvt) == null ? void 0 : _a.metadataUrl) || `${this.url}/tilejson.json`;
1005
+ this.extension = ((_b = props.mvt) == null ? void 0 : _b.extension) || ".png";
985
1006
  this.data = this.url;
986
1007
  this.getTileData = this.getTileData.bind(this);
987
1008
  this.metadata = this.getMetadata();
@@ -1093,26 +1114,305 @@ function getURLFromTemplate(template, x, y, z, id = "0") {
1093
1114
  const i = stringHash(id) % template.length;
1094
1115
  template = template[i];
1095
1116
  }
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));
1117
+ let url = template;
1118
+ url = url.replace(xRegex, String(x));
1119
+ url = url.replace(yRegex, String(y));
1120
+ url = url.replace(zRegex, String(z));
1121
+ if (Number.isInteger(y) && Number.isInteger(z)) {
1122
+ url = url.replace(/\{-y\}/g, String(Math.pow(2, z) - y - 1));
1123
+ }
1124
+ return url;
1125
+ }
1126
+ function stringHash(s) {
1127
+ return Math.abs(s.split("").reduce((a, b) => (a << 5) - a + b.charCodeAt(0) | 0, 0));
1128
+ }
1129
+
1130
+ // dist/table-tile-source.js
1131
+ var import_loader_utils3 = require("@loaders.gl/loader-utils");
1132
+ var import_schema = require("@loaders.gl/schema");
1133
+ var import_stats = require("@probe.gl/stats");
1134
+
1135
+ // dist/lib/vector-tiler/proto-tile.js
1136
+ function createProtoTile(features2, z, tx, ty, options) {
1137
+ const tolerance = z === options.maxZoom ? 0 : options.tolerance / ((1 << z) * options.extent);
1138
+ const tile = {
1139
+ protoFeatures: [],
1140
+ sourceFeatures: null,
1141
+ numPoints: 0,
1142
+ numSimplified: 0,
1143
+ numFeatures: features2.length,
1144
+ x: tx,
1145
+ y: ty,
1146
+ z,
1147
+ transformed: false,
1148
+ minX: 2,
1149
+ minY: 1,
1150
+ maxX: -1,
1151
+ maxY: 0
1152
+ };
1153
+ for (const feature of features2) {
1154
+ addProtoFeature(tile, feature, tolerance, options);
1155
+ }
1156
+ return tile;
1157
+ }
1158
+ function addProtoFeature(tile, feature, tolerance, options) {
1159
+ const geometry = feature.geometry;
1160
+ const type = feature.type;
1161
+ const simplifiedGeometry = [];
1162
+ tile.minX = Math.min(tile.minX, feature.minX);
1163
+ tile.minY = Math.min(tile.minY, feature.minY);
1164
+ tile.maxX = Math.max(tile.maxX, feature.maxX);
1165
+ tile.maxY = Math.max(tile.maxY, feature.maxY);
1166
+ let simplifiedType;
1167
+ switch (type) {
1168
+ case "Point":
1169
+ case "MultiPoint":
1170
+ simplifiedType = 1;
1171
+ for (let i = 0; i < geometry.length; i += 3) {
1172
+ simplifiedGeometry.push(geometry[i], geometry[i + 1]);
1173
+ tile.numPoints++;
1174
+ tile.numSimplified++;
1175
+ }
1176
+ break;
1177
+ case "LineString":
1178
+ simplifiedType = 2;
1179
+ addProtoLine(simplifiedGeometry, geometry, tile, tolerance, false, false);
1180
+ break;
1181
+ case "MultiLineString":
1182
+ simplifiedType = 2;
1183
+ for (let i = 0; i < geometry.length; i++) {
1184
+ addProtoLine(simplifiedGeometry, geometry[i], tile, tolerance, false, i === 0);
1185
+ }
1186
+ break;
1187
+ case "Polygon":
1188
+ simplifiedType = 3;
1189
+ for (let i = 0; i < geometry.length; i++) {
1190
+ addProtoLine(simplifiedGeometry, geometry[i], tile, tolerance, true, i === 0);
1191
+ }
1192
+ break;
1193
+ case "MultiPolygon":
1194
+ simplifiedType = 3;
1195
+ for (let k = 0; k < geometry.length; k++) {
1196
+ const polygon = geometry[k];
1197
+ for (let i = 0; i < polygon.length; i++) {
1198
+ addProtoLine(simplifiedGeometry, polygon[i], tile, tolerance, true, i === 0);
1199
+ }
1200
+ }
1201
+ break;
1202
+ default:
1203
+ throw new Error(`Unknown geometry type: ${type}`);
1204
+ }
1205
+ if (simplifiedGeometry.length) {
1206
+ let tags = feature.tags || null;
1207
+ if (type === "LineString" && options.lineMetrics) {
1208
+ tags = {};
1209
+ for (const key in feature.tags) {
1210
+ tags[key] = feature.tags[key];
1211
+ }
1212
+ tags.mapbox_clip_start = geometry.start / geometry.size;
1213
+ tags.mapbox_clip_end = geometry.end / geometry.size;
1214
+ }
1215
+ const tileFeature = {
1216
+ geometry: simplifiedGeometry,
1217
+ simplifiedType,
1218
+ // @ts-expect-error
1219
+ tags
1220
+ };
1221
+ if (feature.id !== null) {
1222
+ tileFeature.id = feature.id;
1223
+ }
1224
+ tile.protoFeatures.push(tileFeature);
1225
+ }
1226
+ }
1227
+ function addProtoLine(result, geometry, tile, tolerance, isPolygon, isOuter) {
1228
+ const sqTolerance = tolerance * tolerance;
1229
+ if (tolerance > 0 && geometry.size < (isPolygon ? sqTolerance : tolerance)) {
1230
+ tile.numPoints += geometry.length / 3;
1231
+ return;
1232
+ }
1233
+ const ring = [];
1234
+ for (let i = 0; i < geometry.length; i += 3) {
1235
+ if (tolerance === 0 || geometry[i + 2] > sqTolerance) {
1236
+ tile.numSimplified++;
1237
+ ring.push(geometry[i], geometry[i + 1]);
1238
+ }
1239
+ tile.numPoints++;
1240
+ }
1241
+ if (isPolygon)
1242
+ rewind(ring, isOuter);
1243
+ result.push(ring);
1244
+ }
1245
+ function rewind(ring, clockwise) {
1246
+ let area = 0;
1247
+ for (let i = 0, j = ring.length - 2; i < ring.length; j = i, i += 2) {
1248
+ area += (ring[i] - ring[j]) * (ring[i + 1] + ring[j + 1]);
1249
+ }
1250
+ if (area > 0 === clockwise) {
1251
+ for (let i = 0, len = ring.length; i < len / 2; i += 2) {
1252
+ const x = ring[i];
1253
+ const y = ring[i + 1];
1254
+ ring[i] = ring[len - 2 - i];
1255
+ ring[i + 1] = ring[len - 1 - i];
1256
+ ring[len - 2 - i] = x;
1257
+ ring[len - 1 - i] = y;
1258
+ }
1259
+ }
1260
+ }
1261
+
1262
+ // dist/lib/vector-tiler/transform-tile.js
1263
+ function transformTile(protoTile, extent) {
1264
+ if (protoTile.transformed) {
1265
+ return protoTile;
1266
+ }
1267
+ const z2 = 1 << protoTile.z;
1268
+ const tx = protoTile.x;
1269
+ const ty = protoTile.y;
1270
+ for (const protoFeature of protoTile.protoFeatures) {
1271
+ const geom = protoFeature.geometry;
1272
+ const simplifiedType = protoFeature.simplifiedType;
1273
+ protoFeature.geometry = [];
1274
+ if (simplifiedType === 1) {
1275
+ for (let j = 0; j < geom.length; j += 2) {
1276
+ protoFeature.geometry.push(transformPoint(geom[j], geom[j + 1], extent, z2, tx, ty));
1277
+ }
1278
+ } else {
1279
+ for (let j = 0; j < geom.length; j++) {
1280
+ const ring = [];
1281
+ for (let k = 0; k < geom[j].length; k += 2) {
1282
+ ring.push(transformPoint(geom[j][k], geom[j][k + 1], extent, z2, tx, ty));
1283
+ }
1284
+ protoFeature.geometry.push(ring);
1285
+ }
1286
+ }
1287
+ }
1288
+ protoTile.transformed = true;
1289
+ return protoTile;
1290
+ }
1291
+ function transformPoint(x, y, extent, z2, tx, ty) {
1292
+ return [Math.round(extent * (x * z2 - tx)), Math.round(extent * (y * z2 - ty))];
1293
+ }
1294
+
1295
+ // dist/lib/vector-tiler/tile-to-geojson.js
1296
+ function convertTileToGeoJSON(protoTile, props) {
1297
+ const features2 = [];
1298
+ for (const rawFeature of protoTile.protoFeatures) {
1299
+ if (!rawFeature || !rawFeature.geometry) {
1300
+ continue;
1301
+ }
1302
+ let type;
1303
+ let coordinates;
1304
+ switch (rawFeature.simplifiedType) {
1305
+ case 1:
1306
+ if (rawFeature.geometry.length === 1) {
1307
+ type = "Point";
1308
+ coordinates = rawFeature.geometry[0];
1309
+ } else {
1310
+ type = "MultiPoint";
1311
+ coordinates = rawFeature.geometry;
1312
+ }
1313
+ break;
1314
+ case 2:
1315
+ if (rawFeature.geometry.length === 1) {
1316
+ type = "LineString";
1317
+ coordinates = rawFeature.geometry[0];
1318
+ } else {
1319
+ type = "MultiLineString";
1320
+ coordinates = rawFeature.geometry;
1321
+ }
1322
+ break;
1323
+ case 3:
1324
+ if (rawFeature.geometry.length > 1) {
1325
+ type = "MultiPolygon";
1326
+ coordinates = [rawFeature.geometry];
1327
+ } else {
1328
+ type = "Polygon";
1329
+ coordinates = rawFeature.geometry;
1330
+ }
1331
+ break;
1332
+ default:
1333
+ throw new Error(`${rawFeature.simplifiedType}is not a valid simplified type`);
1334
+ }
1335
+ switch (props.coordinates) {
1336
+ case "EPSG:4326":
1337
+ case "wgs84":
1338
+ projectToLngLat(coordinates, props.tileIndex, props.extent);
1339
+ break;
1340
+ default:
1341
+ convertToLocalCoordinates(coordinates, props.extent);
1342
+ break;
1343
+ }
1344
+ const feature = {
1345
+ type: "Feature",
1346
+ geometry: {
1347
+ type,
1348
+ coordinates
1349
+ },
1350
+ properties: rawFeature.tags || {},
1351
+ id: rawFeature.id
1352
+ };
1353
+ features2.push(feature);
1354
+ }
1355
+ if (features2.length === 0) {
1356
+ return null;
1102
1357
  }
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));
1358
+ const table = {
1359
+ shape: "geojson-table",
1360
+ type: "FeatureCollection",
1361
+ features: features2
1362
+ };
1363
+ return table;
1107
1364
  }
1108
1365
 
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");
1366
+ // dist/lib/vector-tiler/features/proto-feature.js
1367
+ function createProtoFeature(id, type, geometry, tags) {
1368
+ const feature = {
1369
+ // eslint-disable-next-line
1370
+ id: id == null ? null : id,
1371
+ type,
1372
+ simplifiedType: void 0,
1373
+ // TODO
1374
+ geometry,
1375
+ tags,
1376
+ minX: Infinity,
1377
+ minY: Infinity,
1378
+ maxX: -Infinity,
1379
+ maxY: -Infinity
1380
+ };
1381
+ switch (type) {
1382
+ case "Point":
1383
+ case "MultiPoint":
1384
+ case "LineString":
1385
+ calcLineBBox(feature, geometry);
1386
+ break;
1387
+ case "MultiLineString":
1388
+ for (const line of geometry) {
1389
+ calcLineBBox(feature, line);
1390
+ }
1391
+ break;
1392
+ case "Polygon":
1393
+ calcLineBBox(feature, geometry[0]);
1394
+ break;
1395
+ case "MultiPolygon":
1396
+ for (const polygon of geometry) {
1397
+ calcLineBBox(feature, polygon[0]);
1398
+ }
1399
+ break;
1400
+ default:
1401
+ throw new Error(String(type));
1402
+ }
1403
+ return feature;
1404
+ }
1405
+ function calcLineBBox(feature, geometry) {
1406
+ for (let i = 0; i < geometry.length; i += 3) {
1407
+ feature.minX = Math.min(feature.minX, geometry[i]);
1408
+ feature.minY = Math.min(feature.minY, geometry[i + 1]);
1409
+ feature.maxX = Math.max(feature.maxX, geometry[i]);
1410
+ feature.maxY = Math.max(feature.maxY, geometry[i + 1]);
1411
+ }
1412
+ }
1113
1413
 
1114
- // dist/lib/vector-tiler/simplify.js
1115
- function simplify(coords, first, last, sqTolerance) {
1414
+ // dist/lib/vector-tiler/features/simplify-path.js
1415
+ function simplifyPath(coords, first, last, sqTolerance) {
1116
1416
  let maxSqDist = sqTolerance;
1117
1417
  const mid = last - first >> 1;
1118
1418
  let minPosToMid = last - first;
@@ -1136,10 +1436,10 @@ function simplify(coords, first, last, sqTolerance) {
1136
1436
  }
1137
1437
  if (maxSqDist > sqTolerance) {
1138
1438
  if (index - first > 3)
1139
- simplify(coords, first, index, sqTolerance);
1439
+ simplifyPath(coords, first, index, sqTolerance);
1140
1440
  coords[index + 2] = maxSqDist;
1141
1441
  if (last - index > 3)
1142
- simplify(coords, index, last, sqTolerance);
1442
+ simplifyPath(coords, index, last, sqTolerance);
1143
1443
  }
1144
1444
  }
1145
1445
  function getSqSegDist(px, py, x, y, bx, by) {
@@ -1160,58 +1460,25 @@ function getSqSegDist(px, py, x, y, bx, by) {
1160
1460
  return dx * dx + dy * dy;
1161
1461
  }
1162
1462
 
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);
1463
+ // dist/lib/vector-tiler/features/convert-feature.js
1464
+ function convertFeaturesToProtoFeature(data, options) {
1465
+ const protoFeatures = [];
1466
+ switch (data.type) {
1467
+ case "FeatureCollection":
1468
+ let i = 0;
1469
+ for (const feature of data.features) {
1470
+ protoFeatures.push(convertFeature(feature, options, i++));
1471
+ }
1472
+ break;
1473
+ case "Feature":
1474
+ protoFeatures.push(convertFeature(data, options));
1475
+ break;
1476
+ default:
1477
+ protoFeatures.push(convertFeature({ geometry: data }, options));
1211
1478
  }
1212
- return features;
1479
+ return protoFeatures;
1213
1480
  }
1214
- function convertFeature(features, geojson, options, index) {
1481
+ function convertFeature(geojson, options, index) {
1215
1482
  if (!geojson.geometry) {
1216
1483
  return;
1217
1484
  }
@@ -1225,46 +1492,52 @@ function convertFeature(features, geojson, options, index) {
1225
1492
  } else if (options.generateId) {
1226
1493
  id = index || 0;
1227
1494
  }
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));
1495
+ switch (type) {
1496
+ case "Point":
1497
+ convertPoint(coords, geometry);
1498
+ break;
1499
+ case "MultiPoint":
1500
+ for (const p of coords) {
1501
+ convertPoint(p, geometry);
1242
1502
  }
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.");
1503
+ break;
1504
+ case "LineString":
1505
+ convertLine(coords, geometry, tolerance, false);
1506
+ break;
1507
+ case "MultiLineString":
1508
+ if (options.lineMetrics) {
1509
+ for (const line of coords) {
1510
+ geometry = [];
1511
+ convertLine(line, geometry, tolerance, false);
1512
+ features.push(createProtoFeature(id, "LineString", geometry, geojson.properties));
1513
+ }
1514
+ return;
1515
+ convertLines(coords, geometry, tolerance, false);
1516
+ }
1517
+ break;
1518
+ case "Polygon":
1519
+ convertLines(coords, geometry, tolerance, true);
1520
+ break;
1521
+ case "MultiPolygon":
1522
+ for (const polygon of coords) {
1523
+ const newPolygon = [];
1524
+ convertLines(polygon, newPolygon, tolerance, true);
1525
+ geometry.push(newPolygon);
1526
+ }
1527
+ break;
1528
+ case "GeometryCollection":
1529
+ for (const singleGeometry of geojson.geometry.geometries) {
1530
+ convertFeature(features, {
1531
+ id,
1532
+ geometry: singleGeometry,
1533
+ properties: geojson.properties
1534
+ }, options, index);
1535
+ }
1536
+ break;
1537
+ default:
1538
+ throw new Error("Input data is not a valid GeoJSON object.");
1266
1539
  }
1267
- features.push(createFeature(id, type, geometry, geojson.properties));
1540
+ return createProtoFeature(id, type, geometry, geojson.properties);
1268
1541
  }
1269
1542
  function convertPoint(coords, out) {
1270
1543
  out.push(projectX(coords[0]), projectY(coords[1]), 0);
@@ -1288,7 +1561,7 @@ function convertLine(ring, out, tolerance, isPolygon) {
1288
1561
  }
1289
1562
  const last = out.length - 3;
1290
1563
  out[2] = 1;
1291
- simplify(out, 0, last, tolerance);
1564
+ simplifyPath(out, 0, last, tolerance);
1292
1565
  out[last + 2] = 1;
1293
1566
  out.size = Math.abs(size);
1294
1567
  out.start = 0;
@@ -1310,17 +1583,17 @@ function projectY(y) {
1310
1583
  return y2 < 0 ? 0 : y2 > 1 ? 1 : y2;
1311
1584
  }
1312
1585
 
1313
- // dist/lib/vector-tiler/clip.js
1314
- function clip(features, scale, k1, k2, axis, minAll, maxAll, options) {
1586
+ // dist/lib/vector-tiler/features/clip-features.js
1587
+ function clipFeatures(features2, scale, k1, k2, axis, minAll, maxAll, options) {
1315
1588
  k1 /= scale;
1316
1589
  k2 /= scale;
1317
1590
  if (minAll >= k1 && maxAll < k2) {
1318
- return features;
1591
+ return features2;
1319
1592
  } else if (maxAll < k1 || minAll >= k2) {
1320
1593
  return null;
1321
1594
  }
1322
1595
  const clipped = [];
1323
- for (const feature of features) {
1596
+ for (const feature of features2) {
1324
1597
  const geometry = feature.geometry;
1325
1598
  let type = feature.type;
1326
1599
  const min = axis === 0 ? feature.minX : feature.minY;
@@ -1352,7 +1625,7 @@ function clip(features, scale, k1, k2, axis, minAll, maxAll, options) {
1352
1625
  if (newGeometry.length) {
1353
1626
  if (options.lineMetrics && type === "LineString") {
1354
1627
  for (const line of newGeometry) {
1355
- clipped.push(createFeature(feature.id, type, line, feature.tags));
1628
+ clipped.push(createProtoFeature(feature.id, type, line, feature.tags));
1356
1629
  }
1357
1630
  continue;
1358
1631
  }
@@ -1367,7 +1640,7 @@ function clip(features, scale, k1, k2, axis, minAll, maxAll, options) {
1367
1640
  if (type === "Point" || type === "MultiPoint") {
1368
1641
  type = newGeometry.length === 3 ? "Point" : "MultiPoint";
1369
1642
  }
1370
- clipped.push(createFeature(feature.id, type, newGeometry, feature.tags));
1643
+ clipped.push(createProtoFeature(feature.id, type, newGeometry, feature.tags));
1371
1644
  }
1372
1645
  }
1373
1646
  return clipped.length ? clipped : null;
@@ -1475,14 +1748,14 @@ function intersectY(out, ax, ay, bx, by, y) {
1475
1748
  return t;
1476
1749
  }
1477
1750
 
1478
- // dist/lib/vector-tiler/wrap.js
1479
- function wrap(features, options) {
1751
+ // dist/lib/vector-tiler/features/wrap-features.js
1752
+ function wrapFeatures(features2, options) {
1480
1753
  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);
1754
+ let merged = features2;
1755
+ const left = clipFeatures(features2, 1, -1 - buffer, buffer, 0, -1, 2, options);
1756
+ const right = clipFeatures(features2, 1, 1 - buffer, 2 + buffer, 0, -1, 2, options);
1484
1757
  if (left || right) {
1485
- merged = clip(features, 1, -buffer, 1 + buffer, 0, -1, 2, options) || [];
1758
+ merged = clipFeatures(features2, 1, -buffer, 1 + buffer, 0, -1, 2, options) || [];
1486
1759
  if (left) {
1487
1760
  merged = shiftFeatureCoords(left, 1).concat(merged);
1488
1761
  }
@@ -1492,30 +1765,39 @@ function wrap(features, options) {
1492
1765
  }
1493
1766
  return merged;
1494
1767
  }
1495
- function shiftFeatureCoords(features, offset) {
1768
+ function shiftFeatureCoords(features2, offset) {
1496
1769
  const newFeatures = [];
1497
- for (let i = 0; i < features.length; i++) {
1498
- const feature = features[i];
1770
+ for (let i = 0; i < features2.length; i++) {
1771
+ const feature = features2[i];
1499
1772
  const type = feature.type;
1500
1773
  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));
1774
+ switch (type) {
1775
+ case "Point":
1776
+ case "MultiPoint":
1777
+ case "LineString":
1778
+ newGeometry = shiftCoords(feature.geometry, offset);
1779
+ break;
1780
+ case "MultiLineString":
1781
+ case "Polygon":
1782
+ newGeometry = [];
1783
+ for (const line of feature.geometry) {
1784
+ newGeometry.push(shiftCoords(line, offset));
1514
1785
  }
1515
- newGeometry.push(newPolygon);
1516
- }
1786
+ break;
1787
+ case "MultiPolygon":
1788
+ newGeometry = [];
1789
+ for (const polygon of feature.geometry) {
1790
+ const newPolygon = [];
1791
+ for (const line of polygon) {
1792
+ newPolygon.push(shiftCoords(line, offset));
1793
+ }
1794
+ newGeometry.push(newPolygon);
1795
+ }
1796
+ break;
1797
+ default:
1798
+ throw new Error(String(type));
1517
1799
  }
1518
- newFeatures.push(createFeature(feature.id, type, newGeometry, feature.tags));
1800
+ newFeatures.push(createProtoFeature(feature.id, type, newGeometry, feature.tags));
1519
1801
  }
1520
1802
  return newFeatures;
1521
1803
  }
@@ -1532,148 +1814,48 @@ function shiftCoords(points, offset) {
1532
1814
  return newPoints;
1533
1815
  }
1534
1816
 
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]);
1817
+ // dist/table-tile-source.js
1818
+ var TableTileSource = {
1819
+ name: "TableTiler",
1820
+ id: "table-tiler",
1821
+ version: "0.0.0",
1822
+ extensions: ["mvt"],
1823
+ mimeTypes: ["application/octet-stream"],
1824
+ options: {
1825
+ table: {
1826
+ coordinates: "local",
1827
+ promoteId: void 0,
1828
+ maxZoom: 14,
1829
+ indexMaxZoom: 5,
1830
+ maxPointsPerTile: 1e4,
1831
+ tolerance: 3,
1832
+ extent: 4096,
1833
+ buffer: 64,
1834
+ generateId: void 0
1650
1835
  }
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]);
1836
+ },
1837
+ type: "table",
1838
+ testURL: (url) => url.endsWith(".geojson"),
1839
+ createDataSource(url, options) {
1840
+ var _a, _b;
1841
+ const needsLoading = typeof url === "string" || url instanceof Blob;
1842
+ const loader = (_b = (_a = options == null ? void 0 : options.table) == null ? void 0 : _a.loaders) == null ? void 0 : _b[0];
1843
+ const tablePromise = needsLoading ? loadTable(url, loader) : url;
1844
+ return new DynamicVectorTileSource(tablePromise, options);
1661
1845
  }
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
- }
1846
+ // @ts-expect-error
1847
+ };
1848
+ async function loadTable(url, loader) {
1849
+ if (typeof url === "string") {
1850
+ const response = await fetch(url);
1851
+ const data2 = await response.arrayBuffer();
1852
+ return await loader.parse(data2);
1671
1853
  }
1854
+ const data = await url.arrayBuffer();
1855
+ return await loader.parse(data);
1672
1856
  }
1673
-
1674
- // dist/table-tile-source.js
1675
- var _TableTileSource = class {
1676
- /** Stats for this TableTileSource */
1857
+ var _DynamicVectorTileSource = class {
1858
+ /** Stats for this DynamicVectorTileSource */
1677
1859
  stats = new import_stats.Stats({
1678
1860
  id: "table-tile-source",
1679
1861
  stats: [new import_stats.Stat("tiles", "count"), new import_stats.Stat("features", "count")]
@@ -1682,6 +1864,7 @@ var _TableTileSource = class {
1682
1864
  mimeType = "application/vnd.mapbox-vector-tile";
1683
1865
  localCoordinates = true;
1684
1866
  /** The props that this tile source was created with */
1867
+ // @ts-expect-error
1685
1868
  props;
1686
1869
  /* Schema of the data */
1687
1870
  schema = null;
@@ -1694,7 +1877,7 @@ var _TableTileSource = class {
1694
1877
  /** Metadata for the tile source (generated TileJSON/tilestats */
1695
1878
  metadata;
1696
1879
  constructor(table, props) {
1697
- this.props = { ..._TableTileSource.defaultProps, ...props };
1880
+ this.props = { ...TableTileSource.options.table, ...props == null ? void 0 : props.table };
1698
1881
  this.getTileData = this.getTileData.bind(this);
1699
1882
  this.ready = this.initializeTilesAsync(table);
1700
1883
  this.metadata = this.getMetadata();
@@ -1738,11 +1921,11 @@ var _TableTileSource = class {
1738
1921
  * @note Application must await `source.ready` before calling sync methods.
1739
1922
  */
1740
1923
  getTileSync(tileIndex) {
1741
- const rawTile = this.getRawTile(tileIndex);
1742
- if (!rawTile) {
1924
+ const protoTile = this.getProtoTile(tileIndex);
1925
+ if (!protoTile) {
1743
1926
  return null;
1744
1927
  }
1745
- return convertToGeoJSONTable(rawTile, {
1928
+ return convertTileToGeoJSON(protoTile, {
1746
1929
  coordinates: this.props.coordinates,
1747
1930
  tileIndex,
1748
1931
  extent: this.props.extent
@@ -1759,28 +1942,28 @@ var _TableTileSource = class {
1759
1942
  if (this.props.promoteId && this.props.generateId) {
1760
1943
  throw new Error("promoteId and generateId cannot be used together.");
1761
1944
  }
1762
- import_loader_utils3.log.log(1, "TableTileSource creating root tiles", this.props)();
1945
+ import_loader_utils3.log.log(1, "DynamicVectorTileSource creating root tiles", this.props)();
1763
1946
  import_loader_utils3.log.time(1, "preprocess table")();
1764
- let features = convert(table, this.props);
1947
+ let features2 = convertFeaturesToProtoFeature(table, this.props);
1765
1948
  import_loader_utils3.log.timeEnd(1, "preprocess table")();
1766
1949
  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")();
1950
+ features2 = wrapFeatures(features2, this.props);
1951
+ if (features2.length === 0) {
1952
+ import_loader_utils3.log.log(1, "DynamicVectorTileSource: no features generated")();
1770
1953
  return;
1771
1954
  }
1772
- this.splitTile(features, 0, 0, 0);
1955
+ this.splitTile(features2, 0, 0, 0);
1773
1956
  const rootTile = this.tiles[0];
1774
1957
  import_loader_utils3.log.log(1, `root tile features: ${rootTile.numFeatures}, points: ${rootTile.numPoints}`)();
1775
1958
  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)();
1959
+ import_loader_utils3.log.log(1, `DynamicVectorTileSource: tiles generated: ${this.stats.get("total").count}`, this.stats)();
1777
1960
  }
1778
1961
  /**
1779
1962
  * Return geojsonvt-style "half formed" vector tile
1780
1963
  * @note Application must await `source.ready` before calling sync methods.
1781
1964
  */
1782
1965
  // eslint-disable-next-line complexity, max-statements
1783
- getRawTile(tileIndex) {
1966
+ getProtoTile(tileIndex) {
1784
1967
  const { z, y } = tileIndex;
1785
1968
  let { x } = tileIndex;
1786
1969
  const { extent } = this.props;
@@ -1804,12 +1987,12 @@ var _TableTileSource = class {
1804
1987
  y0 = y0 >> 1;
1805
1988
  parent = this.tiles[toID(z0, x0, y0)];
1806
1989
  }
1807
- if (!parent || !parent.source) {
1990
+ if (!parent || !parent.sourceFeatures) {
1808
1991
  return null;
1809
1992
  }
1810
1993
  import_loader_utils3.log.log(1, "found parent tile z%d-%d-%d", z0, x0, y0)();
1811
1994
  import_loader_utils3.log.time(1, "drilling down")();
1812
- this.splitTile(parent.source, z0, x0, y0, z, x, y);
1995
+ this.splitTile(parent.sourceFeatures, z0, x0, y0, z, x, y);
1813
1996
  import_loader_utils3.log.timeEnd(1, "drilling down")();
1814
1997
  return this.tiles[id] ? transformTile(this.tiles[id], extent) : null;
1815
1998
  }
@@ -1822,33 +2005,33 @@ var _TableTileSource = class {
1822
2005
  * zoom or the number of points is low as specified in the props.
1823
2006
  */
1824
2007
  // 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];
2008
+ splitTile(features2, z, x, y, cz, cx, cy) {
2009
+ const stack = [features2, z, x, y];
1827
2010
  while (stack.length) {
1828
2011
  y = stack.pop();
1829
2012
  x = stack.pop();
1830
2013
  z = stack.pop();
1831
- features = stack.pop();
2014
+ features2 = stack.pop();
1832
2015
  const z2 = 1 << z;
1833
2016
  const id = toID(z, x, y);
1834
2017
  let tile = this.tiles[id];
1835
2018
  if (!tile) {
1836
2019
  import_loader_utils3.log.time(2, "tile creation")();
1837
- tile = this.tiles[id] = createTile(features, z, x, y, this.props);
2020
+ tile = this.tiles[id] = createProtoTile(features2, z, x, y, this.props);
1838
2021
  this.tileCoords.push({ z, x, y });
1839
2022
  const key = `z${z}`;
1840
2023
  let stat = this.stats.get(key, "count");
1841
2024
  stat.incrementCount();
1842
2025
  stat = this.stats.get("total");
1843
2026
  stat.incrementCount();
1844
- stat = _TableTileSource.stats.get(key, "count");
2027
+ stat = _DynamicVectorTileSource.stats.get(key, "count");
1845
2028
  stat.incrementCount();
1846
- stat = _TableTileSource.stats.get("total");
2029
+ stat = _DynamicVectorTileSource.stats.get("total");
1847
2030
  stat.incrementCount();
1848
2031
  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
2032
  import_loader_utils3.log.timeEnd(2, "tile creation")();
1850
2033
  }
1851
- tile.source = features;
2034
+ tile.sourceFeatures = features2;
1852
2035
  if (cz === void 0) {
1853
2036
  if (z === this.props.indexMaxZoom || tile.numPoints <= this.props.maxPointsPerTile) {
1854
2037
  continue;
@@ -1861,8 +2044,8 @@ var _TableTileSource = class {
1861
2044
  continue;
1862
2045
  }
1863
2046
  }
1864
- tile.source = null;
1865
- if (features.length === 0)
2047
+ tile.sourceFeatures = null;
2048
+ if (features2.length === 0)
1866
2049
  continue;
1867
2050
  import_loader_utils3.log.time(2, "clipping tile")();
1868
2051
  const k1 = 0.5 * this.props.buffer / this.props.extent;
@@ -1873,17 +2056,17 @@ var _TableTileSource = class {
1873
2056
  let bl = null;
1874
2057
  let tr = null;
1875
2058
  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;
2059
+ let left = clipFeatures(features2, z2, x - k1, x + k3, 0, tile.minX, tile.maxX, this.props);
2060
+ let right = clipFeatures(features2, z2, x + k2, x + k4, 0, tile.minX, tile.maxX, this.props);
2061
+ features2 = null;
1879
2062
  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);
2063
+ tl = clipFeatures(left, z2, y - k1, y + k3, 1, tile.minY, tile.maxY, this.props);
2064
+ bl = clipFeatures(left, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, this.props);
1882
2065
  left = null;
1883
2066
  }
1884
2067
  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);
2068
+ tr = clipFeatures(right, z2, y - k1, y + k3, 1, tile.minY, tile.maxY, this.props);
2069
+ br = clipFeatures(right, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, this.props);
1887
2070
  right = null;
1888
2071
  }
1889
2072
  import_loader_utils3.log.timeEnd(2, "clipping tile")();
@@ -1894,109 +2077,13 @@ var _TableTileSource = class {
1894
2077
  }
1895
2078
  }
1896
2079
  };
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({
2080
+ var DynamicVectorTileSource = _DynamicVectorTileSource;
2081
+ /** Global stats for all DynamicVectorTileSources */
2082
+ __publicField(DynamicVectorTileSource, "stats", new import_stats.Stats({
1925
2083
  id: "table-tile-source-all",
1926
2084
  stats: [new import_stats.Stat("count", "tiles"), new import_stats.Stat("count", "features")]
1927
2085
  }));
1928
2086
  function toID(z, x, y) {
1929
2087
  return ((1 << z) * y + x) * 32 + z;
1930
2088
  }
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
2089
  //# sourceMappingURL=index.cjs.map