@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/dist.dev.js CHANGED
@@ -801,6 +801,293 @@ var __exports__ = (() => {
801
801
  });
802
802
  __reExport(bundle_exports, __toESM(require_core(), 1));
803
803
 
804
+ // src/lib/get-schemas-from-tilejson.ts
805
+ function getSchemaFromTileJSONLayer(layer) {
806
+ const fields = [];
807
+ if (layer.fields) {
808
+ for (const field of layer.fields) {
809
+ fields.push({
810
+ name: field.name,
811
+ type: getDataTypeFromTileJSONField(field),
812
+ metadata: getMetadataFromTileJSONField(field)
813
+ });
814
+ }
815
+ }
816
+ return {
817
+ metadata: getMetadataFromTileJSONLayer(layer),
818
+ fields
819
+ };
820
+ }
821
+ function getMetadataFromTileJSONLayer(layer) {
822
+ const metadata = {};
823
+ for (const [key, value] of Object.entries(layer)) {
824
+ if (key !== "fields" && value) {
825
+ metadata[key] = JSON.stringify(value);
826
+ }
827
+ }
828
+ return metadata;
829
+ }
830
+ function getDataTypeFromTileJSONField(field) {
831
+ switch (field.type.toLowerCase()) {
832
+ case "float32":
833
+ return "float32";
834
+ case "number":
835
+ case "float64":
836
+ return "float64";
837
+ case "string":
838
+ case "utf8":
839
+ return "utf8";
840
+ case "boolean":
841
+ return "bool";
842
+ default:
843
+ return "null";
844
+ }
845
+ }
846
+ function getMetadataFromTileJSONField(field) {
847
+ const metadata = {};
848
+ for (const [key, value] of Object.entries(field)) {
849
+ if (key !== "name" && value) {
850
+ metadata[key] = JSON.stringify(value);
851
+ }
852
+ }
853
+ return metadata;
854
+ }
855
+
856
+ // src/lib/parse-tilejson.ts
857
+ var isObject = (x) => x !== null && typeof x === "object";
858
+ function parseTileJSON(jsonMetadata, options) {
859
+ if (!jsonMetadata || !isObject(jsonMetadata)) {
860
+ return null;
861
+ }
862
+ let tileJSON = {
863
+ name: jsonMetadata.name || "",
864
+ description: jsonMetadata.description || ""
865
+ };
866
+ if (typeof jsonMetadata.generator === "string") {
867
+ tileJSON.generator = jsonMetadata.generator;
868
+ }
869
+ if (typeof jsonMetadata.generator_options === "string") {
870
+ tileJSON.generatorOptions = jsonMetadata.generator_options;
871
+ }
872
+ tileJSON.boundingBox = parseBounds(jsonMetadata.bounds) || parseBounds(jsonMetadata.antimeridian_adjusted_bounds);
873
+ tileJSON.center = parseCenter(jsonMetadata.center);
874
+ tileJSON.maxZoom = safeParseFloat(jsonMetadata.maxzoom);
875
+ tileJSON.minZoom = safeParseFloat(jsonMetadata.minzoom);
876
+ if (typeof jsonMetadata?.json === "string") {
877
+ try {
878
+ tileJSON.metaJson = JSON.parse(jsonMetadata.json);
879
+ } catch (error) {
880
+ console.warn("Failed to parse tilejson.json field", error);
881
+ }
882
+ }
883
+ const tilestats = jsonMetadata.tilestats || tileJSON.metaJson?.tilestats;
884
+ const tileStatsLayers = parseTilestatsLayers(tilestats, options);
885
+ const tileJSONlayers = parseTileJSONLayers(jsonMetadata.vector_layers);
886
+ const layers = mergeLayers(tileJSONlayers, tileStatsLayers);
887
+ tileJSON = {
888
+ ...tileJSON,
889
+ layers
890
+ };
891
+ if (tileJSON.maxZoom === null && layers.length > 0) {
892
+ tileJSON.maxZoom = layers[0].maxZoom || null;
893
+ }
894
+ if (tileJSON.minZoom === null && layers.length > 0) {
895
+ tileJSON.minZoom = layers[0].minZoom || null;
896
+ }
897
+ return tileJSON;
898
+ }
899
+ function parseTileJSONLayers(layers) {
900
+ if (!Array.isArray(layers)) {
901
+ return [];
902
+ }
903
+ return layers.map((layer) => parseTileJSONLayer(layer));
904
+ }
905
+ function parseTileJSONLayer(layer) {
906
+ const fields = Object.entries(layer.fields || []).map(([key, datatype]) => ({
907
+ name: key,
908
+ ...attributeTypeToFieldType(String(datatype))
909
+ }));
910
+ const layer2 = { ...layer };
911
+ delete layer2.fields;
912
+ return {
913
+ name: layer.id || "",
914
+ ...layer2,
915
+ fields
916
+ };
917
+ }
918
+ function parseTilestatsLayers(tilestats, options) {
919
+ if (isObject(tilestats) && Array.isArray(tilestats.layers)) {
920
+ return tilestats.layers.map((layer) => parseTilestatsForLayer(layer, options));
921
+ }
922
+ return [];
923
+ }
924
+ function parseTilestatsForLayer(layer, options) {
925
+ const fields = [];
926
+ const indexedAttributes = {};
927
+ const attributes = layer.attributes || [];
928
+ for (const attribute of attributes) {
929
+ const name = attribute.attribute;
930
+ if (typeof name === "string") {
931
+ if (name.split("|").length > 1) {
932
+ const fname = name.split("|")[0];
933
+ indexedAttributes[fname] = indexedAttributes[fname] || [];
934
+ indexedAttributes[fname].push(attribute);
935
+ console.warn("ignoring tilestats indexed field", fname);
936
+ } else if (!fields[name]) {
937
+ fields.push(attributeToField(attribute, options));
938
+ } else {
939
+ }
940
+ }
941
+ }
942
+ return {
943
+ name: layer.layer || "",
944
+ dominantGeometry: layer.geometry,
945
+ fields
946
+ };
947
+ }
948
+ function mergeLayers(layers, tilestatsLayers) {
949
+ return layers.map((layer) => {
950
+ const tilestatsLayer = tilestatsLayers.find((tsLayer) => tsLayer.name === layer.name);
951
+ const fields = tilestatsLayer?.fields || layer.fields || [];
952
+ const mergedLayer = {
953
+ ...layer,
954
+ ...tilestatsLayer,
955
+ fields
956
+ };
957
+ mergedLayer.schema = getSchemaFromTileJSONLayer(mergedLayer);
958
+ return mergedLayer;
959
+ });
960
+ }
961
+ function parseBounds(bounds) {
962
+ const result = fromArrayOrString(bounds);
963
+ if (Array.isArray(result) && result.length === 4 && [result[0], result[2]].every(isLng) && [result[1], result[3]].every(isLat)) {
964
+ return [
965
+ [result[0], result[1]],
966
+ [result[2], result[3]]
967
+ ];
968
+ }
969
+ return void 0;
970
+ }
971
+ function parseCenter(center) {
972
+ const result = fromArrayOrString(center);
973
+ if (Array.isArray(result) && result.length === 3 && isLng(result[0]) && isLat(result[1]) && isZoom(result[2])) {
974
+ return result;
975
+ }
976
+ return null;
977
+ }
978
+ function safeParseFloat(input) {
979
+ const result = typeof input === "string" ? parseFloat(input) : typeof input === "number" ? input : null;
980
+ return result === null || isNaN(result) ? null : result;
981
+ }
982
+ function isLat(num) {
983
+ return Number.isFinite(num) && num <= 90 && num >= -90;
984
+ }
985
+ function isLng(num) {
986
+ return Number.isFinite(num) && num <= 180 && num >= -180;
987
+ }
988
+ function isZoom(num) {
989
+ return Number.isFinite(num) && num >= 0 && num <= 22;
990
+ }
991
+ function fromArrayOrString(data) {
992
+ if (typeof data === "string") {
993
+ return data.split(",").map(parseFloat);
994
+ } else if (Array.isArray(data)) {
995
+ return data;
996
+ }
997
+ return null;
998
+ }
999
+ var attrTypeMap = {
1000
+ number: {
1001
+ type: "float32"
1002
+ },
1003
+ numeric: {
1004
+ type: "float32"
1005
+ },
1006
+ string: {
1007
+ type: "utf8"
1008
+ },
1009
+ vachar: {
1010
+ type: "utf8"
1011
+ },
1012
+ float: {
1013
+ type: "float32"
1014
+ },
1015
+ int: {
1016
+ type: "int32"
1017
+ },
1018
+ int4: {
1019
+ type: "int32"
1020
+ },
1021
+ boolean: {
1022
+ type: "boolean"
1023
+ },
1024
+ bool: {
1025
+ type: "boolean"
1026
+ }
1027
+ };
1028
+ function attributeToField(attribute = {}, options) {
1029
+ const fieldTypes = attributeTypeToFieldType(attribute.type);
1030
+ const field = {
1031
+ name: attribute.attribute,
1032
+ // what happens if attribute type is string...
1033
+ // filterProps: getFilterProps(fieldTypes.type, attribute),
1034
+ ...fieldTypes
1035
+ };
1036
+ if (typeof attribute.min === "number") {
1037
+ field.min = attribute.min;
1038
+ }
1039
+ if (typeof attribute.max === "number") {
1040
+ field.max = attribute.max;
1041
+ }
1042
+ if (typeof attribute.count === "number") {
1043
+ field.uniqueValueCount = attribute.count;
1044
+ }
1045
+ if (attribute.values) {
1046
+ field.values = attribute.values;
1047
+ }
1048
+ if (field.values && typeof options.maxValues === "number") {
1049
+ field.values = field.values?.slice(0, options.maxValues);
1050
+ }
1051
+ return field;
1052
+ }
1053
+ function attributeTypeToFieldType(aType) {
1054
+ const type = aType.toLowerCase();
1055
+ if (!type || !attrTypeMap[type]) {
1056
+ }
1057
+ return attrTypeMap[type] || { type: "string" };
1058
+ }
1059
+
1060
+ // src/tilejson-loader.ts
1061
+ var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
1062
+ var TileJSONLoader = {
1063
+ dataType: null,
1064
+ batchType: null,
1065
+ name: "TileJSON",
1066
+ id: "tilejson",
1067
+ module: "pmtiles",
1068
+ version: VERSION,
1069
+ worker: true,
1070
+ extensions: ["json"],
1071
+ mimeTypes: ["application/json"],
1072
+ text: true,
1073
+ options: {
1074
+ tilejson: {
1075
+ maxValues: void 0
1076
+ }
1077
+ },
1078
+ parse: async (arrayBuffer, options) => {
1079
+ const jsonString = new TextDecoder().decode(arrayBuffer);
1080
+ const json = JSON.parse(jsonString);
1081
+ const tilejsonOptions = { ...TileJSONLoader.options.tilejson, ...options?.tilejson };
1082
+ return parseTileJSON(json, tilejsonOptions);
1083
+ },
1084
+ parseTextSync: (text, options) => {
1085
+ const json = JSON.parse(text);
1086
+ const tilejsonOptions = { ...TileJSONLoader.options.tilejson, ...options?.tilejson };
1087
+ return parseTileJSON(json, tilejsonOptions);
1088
+ }
1089
+ };
1090
+
804
1091
  // ../schema/src/lib/table/simple-table/data-type.ts
805
1092
  function getDataTypeFromValue(value, defaultNumberType = "float32") {
806
1093
  if (value instanceof Date) {
@@ -886,12 +1173,12 @@ var __exports__ = (() => {
886
1173
  }
887
1174
  return { fields, metadata: {} };
888
1175
  }
889
- function deduceSchemaFromGeoJSON(features) {
890
- if (!features.length) {
1176
+ function deduceSchemaFromGeoJSON(features2) {
1177
+ if (!features2.length) {
891
1178
  throw new Error("deduce from empty table");
892
1179
  }
893
1180
  const fields = [];
894
- const row0 = features[0].properties || {};
1181
+ const row0 = features2[0].properties || {};
895
1182
  for (const [columnName, value] of Object.entries(row0)) {
896
1183
  fields.push(deduceFieldFromValue(value, columnName));
897
1184
  }
@@ -1489,11 +1776,11 @@ var __exports__ = (() => {
1489
1776
  };
1490
1777
 
1491
1778
  // ../gis/src/lib/binary-features/flat-geojson-to-binary.ts
1492
- function flatGeojsonToBinary(features, geometryInfo, options) {
1493
- const propArrayTypes = extractNumericPropTypes(features);
1779
+ function flatGeojsonToBinary(features2, geometryInfo, options) {
1780
+ const propArrayTypes = extractNumericPropTypes(features2);
1494
1781
  const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
1495
1782
  return fillArrays(
1496
- features,
1783
+ features2,
1497
1784
  {
1498
1785
  propArrayTypes,
1499
1786
  ...geometryInfo
@@ -1505,9 +1792,9 @@ var __exports__ = (() => {
1505
1792
  }
1506
1793
  );
1507
1794
  }
1508
- function extractNumericPropTypes(features) {
1795
+ function extractNumericPropTypes(features2) {
1509
1796
  const propArrayTypes = {};
1510
- for (const feature of features) {
1797
+ for (const feature of features2) {
1511
1798
  if (feature.properties) {
1512
1799
  for (const key in feature.properties) {
1513
1800
  const val = feature.properties[key];
@@ -1517,7 +1804,7 @@ var __exports__ = (() => {
1517
1804
  }
1518
1805
  return propArrayTypes;
1519
1806
  }
1520
- function fillArrays(features, geometryInfo, options) {
1807
+ function fillArrays(features2, geometryInfo, options) {
1521
1808
  const {
1522
1809
  pointPositionsCount,
1523
1810
  pointFeaturesCount,
@@ -1532,8 +1819,8 @@ var __exports__ = (() => {
1532
1819
  coordLength
1533
1820
  } = geometryInfo;
1534
1821
  const { numericPropKeys = [], PositionDataType = Float32Array, triangulate = true } = options;
1535
- const hasGlobalId = features[0] && "id" in features[0];
1536
- const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
1822
+ const hasGlobalId = features2[0] && "id" in features2[0];
1823
+ const GlobalFeatureIdsDataType = features2.length > 65535 ? Uint32Array : Uint16Array;
1537
1824
  const points = {
1538
1825
  type: "Point",
1539
1826
  positions: new PositionDataType(pointPositionsCount * coordLength),
@@ -1588,7 +1875,7 @@ var __exports__ = (() => {
1588
1875
  polygonFeature: 0,
1589
1876
  feature: 0
1590
1877
  };
1591
- for (const feature of features) {
1878
+ for (const feature of features2) {
1592
1879
  const geometry = feature.geometry;
1593
1880
  const properties = feature.properties || {};
1594
1881
  switch (geometry.type) {
@@ -1832,7 +2119,7 @@ var __exports__ = (() => {
1832
2119
  var navigator_ = globalThis.navigator || {};
1833
2120
 
1834
2121
  // ../../node_modules/@probe.gl/log/node_modules/@probe.gl/env/dist/utils/globals.js
1835
- var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "untranspiled source";
2122
+ var VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "untranspiled source";
1836
2123
  var isBrowser3 = isBrowser2();
1837
2124
 
1838
2125
  // ../../node_modules/@probe.gl/log/dist/utils/local-storage.js
@@ -2017,7 +2304,7 @@ var __exports__ = (() => {
2017
2304
  id: ""
2018
2305
  };
2019
2306
  _defineProperty(this, "id", void 0);
2020
- _defineProperty(this, "VERSION", VERSION);
2307
+ _defineProperty(this, "VERSION", VERSION2);
2021
2308
  _defineProperty(this, "_startTs", getHiResTimestamp());
2022
2309
  _defineProperty(this, "_deltaTs", getHiResTimestamp());
2023
2310
  _defineProperty(this, "_storage", void 0);
@@ -2220,7 +2507,7 @@ var __exports__ = (() => {
2220
2507
  return noop;
2221
2508
  }
2222
2509
  };
2223
- _defineProperty(Log, "VERSION", VERSION);
2510
+ _defineProperty(Log, "VERSION", VERSION2);
2224
2511
  function normalizeLogLevel(logLevel) {
2225
2512
  if (!logLevel) {
2226
2513
  return 0;
@@ -2330,8 +2617,8 @@ var __exports__ = (() => {
2330
2617
  });
2331
2618
 
2332
2619
  // ../loader-utils/src/lib/log-utils/log.ts
2333
- var VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
2334
- var version = VERSION2[0] >= "0" && VERSION2[0] <= "9" ? `v${VERSION2}` : "";
2620
+ var VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
2621
+ var version = VERSION3[0] >= "0" && VERSION3[0] <= "9" ? `v${VERSION3}` : "";
2335
2622
  function createLog() {
2336
2623
  const log2 = new Log({ id: "loaders.gl" });
2337
2624
  globalThis.loaders = globalThis.loaders || {};
@@ -2429,7 +2716,7 @@ var __exports__ = (() => {
2429
2716
  p[1] /= extent;
2430
2717
  }
2431
2718
  function convertToLocalCoordinatesFlat(data, extent) {
2432
- for (let i = 0, il = data.length; i < il; ++i) {
2719
+ for (let i = 0; i < data.length; ++i) {
2433
2720
  data[i] /= extent;
2434
2721
  }
2435
2722
  }
@@ -2981,7 +3268,7 @@ var __exports__ = (() => {
2981
3268
  return binaryData;
2982
3269
  }
2983
3270
  function parseToFlatGeoJson(arrayBuffer, options) {
2984
- const features = [];
3271
+ const features2 = [];
2985
3272
  const geometryInfo = {
2986
3273
  coordLength: 2,
2987
3274
  pointPositionsCount: 0,
@@ -2995,7 +3282,7 @@ var __exports__ = (() => {
2995
3282
  polygonFeaturesCount: 0
2996
3283
  };
2997
3284
  if (arrayBuffer.byteLength <= 0) {
2998
- return [features, geometryInfo];
3285
+ return [features2, geometryInfo];
2999
3286
  }
3000
3287
  const tile = new VectorTile(new import_pbf.default(arrayBuffer));
3001
3288
  const selectedLayers = options && Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);
@@ -3007,16 +3294,16 @@ var __exports__ = (() => {
3007
3294
  for (let i = 0; i < vectorTileLayer.length; i++) {
3008
3295
  const vectorTileFeature = vectorTileLayer.getBinaryFeature(i, geometryInfo);
3009
3296
  const decodedFeature = getDecodedFeatureBinary(vectorTileFeature, options, layerName);
3010
- features.push(decodedFeature);
3297
+ features2.push(decodedFeature);
3011
3298
  }
3012
3299
  });
3013
- return [features, geometryInfo];
3300
+ return [features2, geometryInfo];
3014
3301
  }
3015
3302
  function parseToGeojsonFeatures(arrayBuffer, options) {
3016
3303
  if (arrayBuffer.byteLength <= 0) {
3017
3304
  return [];
3018
3305
  }
3019
- const features = [];
3306
+ const features2 = [];
3020
3307
  const tile = new VectorTile(new import_pbf.default(arrayBuffer));
3021
3308
  const selectedLayers = Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);
3022
3309
  selectedLayers.forEach((layerName) => {
@@ -3027,10 +3314,10 @@ var __exports__ = (() => {
3027
3314
  for (let i = 0; i < vectorTileLayer.length; i++) {
3028
3315
  const vectorTileFeature = vectorTileLayer.getGeoJSONFeature(i);
3029
3316
  const decodedFeature = getDecodedFeature(vectorTileFeature, options, layerName);
3030
- features.push(decodedFeature);
3317
+ features2.push(decodedFeature);
3031
3318
  }
3032
3319
  });
3033
- return features;
3320
+ return features2;
3034
3321
  }
3035
3322
  function checkOptions(options) {
3036
3323
  if (!options?.mvt) {
@@ -3064,14 +3351,14 @@ var __exports__ = (() => {
3064
3351
  }
3065
3352
 
3066
3353
  // src/mvt-loader.ts
3067
- var VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
3354
+ var VERSION4 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
3068
3355
  var MVTWorkerLoader = {
3069
3356
  dataType: null,
3070
3357
  batchType: null,
3071
3358
  name: "Mapbox Vector Tile",
3072
3359
  id: "mvt",
3073
3360
  module: "mvt",
3074
- version: VERSION3,
3361
+ version: VERSION4,
3075
3362
  // Note: ArcGIS uses '.pbf' extension and 'application/octet-stream'
3076
3363
  extensions: ["mvt", "pbf"],
3077
3364
  mimeTypes: [
@@ -3099,241 +3386,6 @@ var __exports__ = (() => {
3099
3386
  binary: true
3100
3387
  };
3101
3388
 
3102
- // src/lib/parse-tilejson.ts
3103
- var isObject = (x) => x !== null && typeof x === "object";
3104
- function parseTileJSON(jsonMetadata, options) {
3105
- if (!jsonMetadata || !isObject(jsonMetadata)) {
3106
- return null;
3107
- }
3108
- let tileJSON = {
3109
- name: jsonMetadata.name || "",
3110
- description: jsonMetadata.description || ""
3111
- };
3112
- if (typeof jsonMetadata.generator === "string") {
3113
- tileJSON.generator = jsonMetadata.generator;
3114
- }
3115
- if (typeof jsonMetadata.generator_options === "string") {
3116
- tileJSON.generatorOptions = jsonMetadata.generator_options;
3117
- }
3118
- tileJSON.boundingBox = parseBounds(jsonMetadata.bounds) || parseBounds(jsonMetadata.antimeridian_adjusted_bounds);
3119
- tileJSON.center = parseCenter(jsonMetadata.center);
3120
- tileJSON.maxZoom = safeParseFloat(jsonMetadata.maxzoom);
3121
- tileJSON.minZoom = safeParseFloat(jsonMetadata.minzoom);
3122
- if (typeof jsonMetadata?.json === "string") {
3123
- try {
3124
- tileJSON.metaJson = JSON.parse(jsonMetadata.json);
3125
- } catch (error) {
3126
- console.warn("Failed to parse tilejson.json field", error);
3127
- }
3128
- }
3129
- const tilestats = jsonMetadata.tilestats || tileJSON.metaJson?.tilestats;
3130
- const tileStatsLayers = parseTilestatsLayers(tilestats, options);
3131
- const tileJSONlayers = parseTileJSONLayers(jsonMetadata.vector_layers);
3132
- const layers = mergeLayers(tileJSONlayers, tileStatsLayers);
3133
- tileJSON = {
3134
- ...tileJSON,
3135
- layers
3136
- };
3137
- if (tileJSON.maxZoom === null && layers.length > 0) {
3138
- tileJSON.maxZoom = layers[0].maxZoom || null;
3139
- }
3140
- if (tileJSON.minZoom === null && layers.length > 0) {
3141
- tileJSON.minZoom = layers[0].minZoom || null;
3142
- }
3143
- return tileJSON;
3144
- }
3145
- function parseTileJSONLayers(layers) {
3146
- if (!Array.isArray(layers)) {
3147
- return [];
3148
- }
3149
- return layers.map((layer) => parseTileJSONLayer(layer));
3150
- }
3151
- function parseTileJSONLayer(layer) {
3152
- const fields = Object.entries(layer.fields || []).map(([key, datatype]) => ({
3153
- name: key,
3154
- ...attributeTypeToFieldType(String(datatype))
3155
- }));
3156
- const layer2 = { ...layer };
3157
- delete layer2.fields;
3158
- return {
3159
- name: layer.id || "",
3160
- ...layer2,
3161
- fields
3162
- };
3163
- }
3164
- function parseTilestatsLayers(tilestats, options) {
3165
- if (isObject(tilestats) && Array.isArray(tilestats.layers)) {
3166
- return tilestats.layers.map((layer) => parseTilestatsForLayer(layer, options));
3167
- }
3168
- return [];
3169
- }
3170
- function parseTilestatsForLayer(layer, options) {
3171
- const fields = [];
3172
- const indexedAttributes = {};
3173
- const attributes = layer.attributes || [];
3174
- for (const attribute of attributes) {
3175
- const name = attribute.attribute;
3176
- if (typeof name === "string") {
3177
- if (name.split("|").length > 1) {
3178
- const fname = name.split("|")[0];
3179
- indexedAttributes[fname] = indexedAttributes[fname] || [];
3180
- indexedAttributes[fname].push(attribute);
3181
- console.warn("ignoring tilestats indexed field", fname);
3182
- } else if (!fields[name]) {
3183
- fields.push(attributeToField(attribute, options));
3184
- } else {
3185
- }
3186
- }
3187
- }
3188
- return {
3189
- name: layer.layer || "",
3190
- dominantGeometry: layer.geometry,
3191
- fields
3192
- };
3193
- }
3194
- function mergeLayers(layers, tilestatsLayers) {
3195
- return layers.map((layer) => {
3196
- const tilestatsLayer = tilestatsLayers.find((tsLayer) => tsLayer.name === layer.name);
3197
- const fields = tilestatsLayer?.fields || [];
3198
- const layer2 = { ...layer };
3199
- delete layer2.fields;
3200
- return {
3201
- ...layer2,
3202
- ...tilestatsLayer,
3203
- fields
3204
- };
3205
- });
3206
- }
3207
- function parseBounds(bounds) {
3208
- const result = fromArrayOrString(bounds);
3209
- if (Array.isArray(result) && result.length === 4 && [result[0], result[2]].every(isLng) && [result[1], result[3]].every(isLat)) {
3210
- return [
3211
- [result[0], result[1]],
3212
- [result[2], result[3]]
3213
- ];
3214
- }
3215
- return void 0;
3216
- }
3217
- function parseCenter(center) {
3218
- const result = fromArrayOrString(center);
3219
- if (Array.isArray(result) && result.length === 3 && isLng(result[0]) && isLat(result[1]) && isZoom(result[2])) {
3220
- return result;
3221
- }
3222
- return null;
3223
- }
3224
- function safeParseFloat(input) {
3225
- const result = typeof input === "string" ? parseFloat(input) : typeof input === "number" ? input : null;
3226
- return result === null || isNaN(result) ? null : result;
3227
- }
3228
- function isLat(num) {
3229
- return Number.isFinite(num) && num <= 90 && num >= -90;
3230
- }
3231
- function isLng(num) {
3232
- return Number.isFinite(num) && num <= 180 && num >= -180;
3233
- }
3234
- function isZoom(num) {
3235
- return Number.isFinite(num) && num >= 0 && num <= 22;
3236
- }
3237
- function fromArrayOrString(data) {
3238
- if (typeof data === "string") {
3239
- return data.split(",").map(parseFloat);
3240
- } else if (Array.isArray(data)) {
3241
- return data;
3242
- }
3243
- return null;
3244
- }
3245
- var attrTypeMap = {
3246
- number: {
3247
- type: "float32"
3248
- },
3249
- numeric: {
3250
- type: "float32"
3251
- },
3252
- string: {
3253
- type: "utf8"
3254
- },
3255
- vachar: {
3256
- type: "utf8"
3257
- },
3258
- float: {
3259
- type: "float32"
3260
- },
3261
- int: {
3262
- type: "int32"
3263
- },
3264
- int4: {
3265
- type: "int32"
3266
- },
3267
- boolean: {
3268
- type: "boolean"
3269
- },
3270
- bool: {
3271
- type: "boolean"
3272
- }
3273
- };
3274
- function attributeToField(attribute = {}, options) {
3275
- const fieldTypes = attributeTypeToFieldType(attribute.type);
3276
- const field = {
3277
- name: attribute.attribute,
3278
- // what happens if attribute type is string...
3279
- // filterProps: getFilterProps(fieldTypes.type, attribute),
3280
- ...fieldTypes
3281
- };
3282
- if (typeof attribute.min === "number") {
3283
- field.min = attribute.min;
3284
- }
3285
- if (typeof attribute.max === "number") {
3286
- field.max = attribute.max;
3287
- }
3288
- if (typeof attribute.count === "number") {
3289
- field.uniqueValueCount = attribute.count;
3290
- }
3291
- if (attribute.values) {
3292
- field.values = attribute.values;
3293
- }
3294
- if (field.values && typeof options.maxValues === "number") {
3295
- field.values = field.values?.slice(0, options.maxValues);
3296
- }
3297
- return field;
3298
- }
3299
- function attributeTypeToFieldType(aType) {
3300
- const type = aType.toLowerCase();
3301
- if (!type || !attrTypeMap[type]) {
3302
- }
3303
- return attrTypeMap[type] || { type: "string" };
3304
- }
3305
-
3306
- // src/tilejson-loader.ts
3307
- var VERSION4 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
3308
- var TileJSONLoader = {
3309
- dataType: null,
3310
- batchType: null,
3311
- name: "TileJSON",
3312
- id: "tilejson",
3313
- module: "pmtiles",
3314
- version: VERSION4,
3315
- worker: true,
3316
- extensions: ["json"],
3317
- mimeTypes: ["application/json"],
3318
- text: true,
3319
- options: {
3320
- tilejson: {
3321
- maxValues: void 0
3322
- }
3323
- },
3324
- parse: async (arrayBuffer, options) => {
3325
- const jsonString = new TextDecoder().decode(arrayBuffer);
3326
- const json = JSON.parse(jsonString);
3327
- const tilejsonOptions = { ...TileJSONLoader.options.tilejson, ...options?.tilejson };
3328
- return parseTileJSON(json, tilejsonOptions);
3329
- },
3330
- parseTextSync: (text, options) => {
3331
- const json = JSON.parse(text);
3332
- const tilejsonOptions = { ...TileJSONLoader.options.tilejson, ...options?.tilejson };
3333
- return parseTileJSON(json, tilejsonOptions);
3334
- }
3335
- };
3336
-
3337
3389
  // ../images/src/lib/utils/version.ts
3338
3390
  var VERSION5 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
3339
3391
 
@@ -3743,7 +3795,27 @@ var __exports__ = (() => {
3743
3795
  };
3744
3796
 
3745
3797
  // src/mvt-source.ts
3746
- var MVTSource = class extends DataSource {
3798
+ var MVTSource = {
3799
+ name: "MVT",
3800
+ id: "mvt",
3801
+ module: "mvt",
3802
+ version: "0.0.0",
3803
+ extensions: ["mvt"],
3804
+ mimeTypes: ["application/octet-stream"],
3805
+ options: {
3806
+ mvt: {
3807
+ // TODO - add options here
3808
+ }
3809
+ },
3810
+ type: "mvt",
3811
+ fromUrl: true,
3812
+ fromBlob: false,
3813
+ testURL: (url) => true,
3814
+ createDataSource(url, props) {
3815
+ return new MVTTileSource(url, props);
3816
+ }
3817
+ };
3818
+ var MVTTileSource = class extends DataSource {
3747
3819
  props;
3748
3820
  url;
3749
3821
  metadataUrl = null;
@@ -3752,12 +3824,12 @@ var __exports__ = (() => {
3752
3824
  metadata;
3753
3825
  extension;
3754
3826
  mimeType = null;
3755
- constructor(props) {
3827
+ constructor(url, props) {
3756
3828
  super(props);
3757
3829
  this.props = props;
3758
- this.url = resolvePath(props.url);
3759
- this.metadataUrl = props.metadataUrl === void 0 ? `${this.url}/tilejson.json` : props.metadataUrl;
3760
- this.extension = props.extension || ".png";
3830
+ this.url = resolvePath(url);
3831
+ this.metadataUrl = props.mvt?.metadataUrl || `${this.url}/tilejson.json`;
3832
+ this.extension = props.mvt?.extension || ".png";
3761
3833
  this.data = this.url;
3762
3834
  this.getTileData = this.getTileData.bind(this);
3763
3835
  this.metadata = this.getMetadata();
@@ -4073,35 +4145,314 @@ var __exports__ = (() => {
4073
4145
  }
4074
4146
  };
4075
4147
 
4076
- // src/lib/vector-tiler/simplify.ts
4077
- function simplify(coords, first, last, sqTolerance) {
4078
- let maxSqDist = sqTolerance;
4079
- const mid = last - first >> 1;
4080
- let minPosToMid = last - first;
4081
- let index;
4082
- const ax = coords[first];
4083
- const ay = coords[first + 1];
4084
- const bx = coords[last];
4085
- const by = coords[last + 1];
4086
- for (let i = first + 3; i < last; i += 3) {
4087
- const d = getSqSegDist(coords[i], coords[i + 1], ax, ay, bx, by);
4088
- if (d > maxSqDist) {
4089
- index = i;
4090
- maxSqDist = d;
4091
- } else if (d === maxSqDist) {
4092
- const posToMid = Math.abs(i - mid);
4093
- if (posToMid < minPosToMid) {
4094
- index = i;
4148
+ // src/lib/vector-tiler/proto-tile.ts
4149
+ function createProtoTile(features2, z, tx, ty, options) {
4150
+ const tolerance = z === options.maxZoom ? 0 : options.tolerance / ((1 << z) * options.extent);
4151
+ const tile = {
4152
+ protoFeatures: [],
4153
+ sourceFeatures: null,
4154
+ numPoints: 0,
4155
+ numSimplified: 0,
4156
+ numFeatures: features2.length,
4157
+ x: tx,
4158
+ y: ty,
4159
+ z,
4160
+ transformed: false,
4161
+ minX: 2,
4162
+ minY: 1,
4163
+ maxX: -1,
4164
+ maxY: 0
4165
+ };
4166
+ for (const feature of features2) {
4167
+ addProtoFeature(tile, feature, tolerance, options);
4168
+ }
4169
+ return tile;
4170
+ }
4171
+ function addProtoFeature(tile, feature, tolerance, options) {
4172
+ const geometry = feature.geometry;
4173
+ const type = feature.type;
4174
+ const simplifiedGeometry = [];
4175
+ tile.minX = Math.min(tile.minX, feature.minX);
4176
+ tile.minY = Math.min(tile.minY, feature.minY);
4177
+ tile.maxX = Math.max(tile.maxX, feature.maxX);
4178
+ tile.maxY = Math.max(tile.maxY, feature.maxY);
4179
+ let simplifiedType;
4180
+ switch (type) {
4181
+ case "Point":
4182
+ case "MultiPoint":
4183
+ simplifiedType = 1;
4184
+ for (let i = 0; i < geometry.length; i += 3) {
4185
+ simplifiedGeometry.push(geometry[i], geometry[i + 1]);
4186
+ tile.numPoints++;
4187
+ tile.numSimplified++;
4188
+ }
4189
+ break;
4190
+ case "LineString":
4191
+ simplifiedType = 2;
4192
+ addProtoLine(simplifiedGeometry, geometry, tile, tolerance, false, false);
4193
+ break;
4194
+ case "MultiLineString":
4195
+ simplifiedType = 2;
4196
+ for (let i = 0; i < geometry.length; i++) {
4197
+ addProtoLine(simplifiedGeometry, geometry[i], tile, tolerance, false, i === 0);
4198
+ }
4199
+ break;
4200
+ case "Polygon":
4201
+ simplifiedType = 3;
4202
+ for (let i = 0; i < geometry.length; i++) {
4203
+ addProtoLine(simplifiedGeometry, geometry[i], tile, tolerance, true, i === 0);
4204
+ }
4205
+ break;
4206
+ case "MultiPolygon":
4207
+ simplifiedType = 3;
4208
+ for (let k = 0; k < geometry.length; k++) {
4209
+ const polygon = geometry[k];
4210
+ for (let i = 0; i < polygon.length; i++) {
4211
+ addProtoLine(simplifiedGeometry, polygon[i], tile, tolerance, true, i === 0);
4212
+ }
4213
+ }
4214
+ break;
4215
+ default:
4216
+ throw new Error(`Unknown geometry type: ${type}`);
4217
+ }
4218
+ if (simplifiedGeometry.length) {
4219
+ let tags = feature.tags || null;
4220
+ if (type === "LineString" && options.lineMetrics) {
4221
+ tags = {};
4222
+ for (const key in feature.tags) {
4223
+ tags[key] = feature.tags[key];
4224
+ }
4225
+ tags.mapbox_clip_start = geometry.start / geometry.size;
4226
+ tags.mapbox_clip_end = geometry.end / geometry.size;
4227
+ }
4228
+ const tileFeature = {
4229
+ geometry: simplifiedGeometry,
4230
+ simplifiedType,
4231
+ // @ts-expect-error
4232
+ tags
4233
+ };
4234
+ if (feature.id !== null) {
4235
+ tileFeature.id = feature.id;
4236
+ }
4237
+ tile.protoFeatures.push(tileFeature);
4238
+ }
4239
+ }
4240
+ function addProtoLine(result, geometry, tile, tolerance, isPolygon, isOuter) {
4241
+ const sqTolerance = tolerance * tolerance;
4242
+ if (tolerance > 0 && geometry.size < (isPolygon ? sqTolerance : tolerance)) {
4243
+ tile.numPoints += geometry.length / 3;
4244
+ return;
4245
+ }
4246
+ const ring = [];
4247
+ for (let i = 0; i < geometry.length; i += 3) {
4248
+ if (tolerance === 0 || geometry[i + 2] > sqTolerance) {
4249
+ tile.numSimplified++;
4250
+ ring.push(geometry[i], geometry[i + 1]);
4251
+ }
4252
+ tile.numPoints++;
4253
+ }
4254
+ if (isPolygon)
4255
+ rewind(ring, isOuter);
4256
+ result.push(ring);
4257
+ }
4258
+ function rewind(ring, clockwise) {
4259
+ let area2 = 0;
4260
+ for (let i = 0, j = ring.length - 2; i < ring.length; j = i, i += 2) {
4261
+ area2 += (ring[i] - ring[j]) * (ring[i + 1] + ring[j + 1]);
4262
+ }
4263
+ if (area2 > 0 === clockwise) {
4264
+ for (let i = 0, len = ring.length; i < len / 2; i += 2) {
4265
+ const x = ring[i];
4266
+ const y = ring[i + 1];
4267
+ ring[i] = ring[len - 2 - i];
4268
+ ring[i + 1] = ring[len - 1 - i];
4269
+ ring[len - 2 - i] = x;
4270
+ ring[len - 1 - i] = y;
4271
+ }
4272
+ }
4273
+ }
4274
+
4275
+ // src/lib/vector-tiler/transform-tile.ts
4276
+ function transformTile(protoTile, extent) {
4277
+ if (protoTile.transformed) {
4278
+ return protoTile;
4279
+ }
4280
+ const z2 = 1 << protoTile.z;
4281
+ const tx = protoTile.x;
4282
+ const ty = protoTile.y;
4283
+ for (const protoFeature of protoTile.protoFeatures) {
4284
+ const geom = protoFeature.geometry;
4285
+ const simplifiedType = protoFeature.simplifiedType;
4286
+ protoFeature.geometry = [];
4287
+ if (simplifiedType === 1) {
4288
+ for (let j = 0; j < geom.length; j += 2) {
4289
+ protoFeature.geometry.push(transformPoint(geom[j], geom[j + 1], extent, z2, tx, ty));
4290
+ }
4291
+ } else {
4292
+ for (let j = 0; j < geom.length; j++) {
4293
+ const ring = [];
4294
+ for (let k = 0; k < geom[j].length; k += 2) {
4295
+ ring.push(transformPoint(geom[j][k], geom[j][k + 1], extent, z2, tx, ty));
4296
+ }
4297
+ protoFeature.geometry.push(ring);
4298
+ }
4299
+ }
4300
+ }
4301
+ protoTile.transformed = true;
4302
+ return protoTile;
4303
+ }
4304
+ function transformPoint(x, y, extent, z2, tx, ty) {
4305
+ return [Math.round(extent * (x * z2 - tx)), Math.round(extent * (y * z2 - ty))];
4306
+ }
4307
+
4308
+ // src/lib/vector-tiler/tile-to-geojson.ts
4309
+ function convertTileToGeoJSON(protoTile, props) {
4310
+ const features2 = [];
4311
+ for (const rawFeature of protoTile.protoFeatures) {
4312
+ if (!rawFeature || !rawFeature.geometry) {
4313
+ continue;
4314
+ }
4315
+ let type;
4316
+ let coordinates;
4317
+ switch (rawFeature.simplifiedType) {
4318
+ case 1:
4319
+ if (rawFeature.geometry.length === 1) {
4320
+ type = "Point";
4321
+ coordinates = rawFeature.geometry[0];
4322
+ } else {
4323
+ type = "MultiPoint";
4324
+ coordinates = rawFeature.geometry;
4325
+ }
4326
+ break;
4327
+ case 2:
4328
+ if (rawFeature.geometry.length === 1) {
4329
+ type = "LineString";
4330
+ coordinates = rawFeature.geometry[0];
4331
+ } else {
4332
+ type = "MultiLineString";
4333
+ coordinates = rawFeature.geometry;
4334
+ }
4335
+ break;
4336
+ case 3:
4337
+ if (rawFeature.geometry.length > 1) {
4338
+ type = "MultiPolygon";
4339
+ coordinates = [rawFeature.geometry];
4340
+ } else {
4341
+ type = "Polygon";
4342
+ coordinates = rawFeature.geometry;
4343
+ }
4344
+ break;
4345
+ default:
4346
+ throw new Error(`${rawFeature.simplifiedType}is not a valid simplified type`);
4347
+ }
4348
+ switch (props.coordinates) {
4349
+ case "EPSG:4326":
4350
+ case "wgs84":
4351
+ projectToLngLat(coordinates, props.tileIndex, props.extent);
4352
+ break;
4353
+ default:
4354
+ convertToLocalCoordinates(coordinates, props.extent);
4355
+ break;
4356
+ }
4357
+ const feature = {
4358
+ type: "Feature",
4359
+ geometry: {
4360
+ type,
4361
+ coordinates
4362
+ },
4363
+ properties: rawFeature.tags || {},
4364
+ id: rawFeature.id
4365
+ };
4366
+ features2.push(feature);
4367
+ }
4368
+ if (features2.length === 0) {
4369
+ return null;
4370
+ }
4371
+ const table = {
4372
+ shape: "geojson-table",
4373
+ type: "FeatureCollection",
4374
+ features: features2
4375
+ };
4376
+ return table;
4377
+ }
4378
+
4379
+ // src/lib/vector-tiler/features/proto-feature.ts
4380
+ function createProtoFeature(id, type, geometry, tags) {
4381
+ const feature = {
4382
+ // eslint-disable-next-line
4383
+ id: id == null ? null : id,
4384
+ type,
4385
+ simplifiedType: void 0,
4386
+ // TODO
4387
+ geometry,
4388
+ tags,
4389
+ minX: Infinity,
4390
+ minY: Infinity,
4391
+ maxX: -Infinity,
4392
+ maxY: -Infinity
4393
+ };
4394
+ switch (type) {
4395
+ case "Point":
4396
+ case "MultiPoint":
4397
+ case "LineString":
4398
+ calcLineBBox(feature, geometry);
4399
+ break;
4400
+ case "MultiLineString":
4401
+ for (const line of geometry) {
4402
+ calcLineBBox(feature, line);
4403
+ }
4404
+ break;
4405
+ case "Polygon":
4406
+ calcLineBBox(feature, geometry[0]);
4407
+ break;
4408
+ case "MultiPolygon":
4409
+ for (const polygon of geometry) {
4410
+ calcLineBBox(feature, polygon[0]);
4411
+ }
4412
+ break;
4413
+ default:
4414
+ throw new Error(String(type));
4415
+ }
4416
+ return feature;
4417
+ }
4418
+ function calcLineBBox(feature, geometry) {
4419
+ for (let i = 0; i < geometry.length; i += 3) {
4420
+ feature.minX = Math.min(feature.minX, geometry[i]);
4421
+ feature.minY = Math.min(feature.minY, geometry[i + 1]);
4422
+ feature.maxX = Math.max(feature.maxX, geometry[i]);
4423
+ feature.maxY = Math.max(feature.maxY, geometry[i + 1]);
4424
+ }
4425
+ }
4426
+
4427
+ // src/lib/vector-tiler/features/simplify-path.ts
4428
+ function simplifyPath(coords, first, last, sqTolerance) {
4429
+ let maxSqDist = sqTolerance;
4430
+ const mid = last - first >> 1;
4431
+ let minPosToMid = last - first;
4432
+ let index;
4433
+ const ax = coords[first];
4434
+ const ay = coords[first + 1];
4435
+ const bx = coords[last];
4436
+ const by = coords[last + 1];
4437
+ for (let i = first + 3; i < last; i += 3) {
4438
+ const d = getSqSegDist(coords[i], coords[i + 1], ax, ay, bx, by);
4439
+ if (d > maxSqDist) {
4440
+ index = i;
4441
+ maxSqDist = d;
4442
+ } else if (d === maxSqDist) {
4443
+ const posToMid = Math.abs(i - mid);
4444
+ if (posToMid < minPosToMid) {
4445
+ index = i;
4095
4446
  minPosToMid = posToMid;
4096
4447
  }
4097
4448
  }
4098
4449
  }
4099
4450
  if (maxSqDist > sqTolerance) {
4100
4451
  if (index - first > 3)
4101
- simplify(coords, first, index, sqTolerance);
4452
+ simplifyPath(coords, first, index, sqTolerance);
4102
4453
  coords[index + 2] = maxSqDist;
4103
4454
  if (last - index > 3)
4104
- simplify(coords, index, last, sqTolerance);
4455
+ simplifyPath(coords, index, last, sqTolerance);
4105
4456
  }
4106
4457
  }
4107
4458
  function getSqSegDist(px, py, x, y, bx, by) {
@@ -4122,58 +4473,25 @@ var __exports__ = (() => {
4122
4473
  return dx * dx + dy * dy;
4123
4474
  }
4124
4475
 
4125
- // src/lib/vector-tiler/feature.ts
4126
- function createFeature(id, type, geom, tags) {
4127
- const feature = {
4128
- // eslint-disable-next-line
4129
- id: id == null ? null : id,
4130
- type,
4131
- geometry: geom,
4132
- tags,
4133
- minX: Infinity,
4134
- minY: Infinity,
4135
- maxX: -Infinity,
4136
- maxY: -Infinity
4137
- };
4138
- if (type === "Point" || type === "MultiPoint" || type === "LineString") {
4139
- calcLineBBox(feature, geom);
4140
- } else if (type === "Polygon") {
4141
- calcLineBBox(feature, geom[0]);
4142
- } else if (type === "MultiLineString") {
4143
- for (const line of geom) {
4144
- calcLineBBox(feature, line);
4145
- }
4146
- } else if (type === "MultiPolygon") {
4147
- for (const polygon of geom) {
4148
- calcLineBBox(feature, polygon[0]);
4149
- }
4150
- }
4151
- return feature;
4152
- }
4153
- function calcLineBBox(feature, geom) {
4154
- for (let i = 0; i < geom.length; i += 3) {
4155
- feature.minX = Math.min(feature.minX, geom[i]);
4156
- feature.minY = Math.min(feature.minY, geom[i + 1]);
4157
- feature.maxX = Math.max(feature.maxX, geom[i]);
4158
- feature.maxY = Math.max(feature.maxY, geom[i + 1]);
4159
- }
4160
- }
4161
-
4162
- // src/lib/vector-tiler/convert.ts
4163
- function convert(data, options) {
4164
- const features = [];
4165
- if (data.type === "FeatureCollection") {
4166
- for (let i = 0; i < data.features.length; i++) {
4167
- convertFeature(features, data.features[i], options, i);
4168
- }
4169
- } else if (data.type === "Feature") {
4170
- convertFeature(features, data, options);
4171
- } else {
4172
- convertFeature(features, { geometry: data }, options);
4476
+ // src/lib/vector-tiler/features/convert-feature.ts
4477
+ function convertFeaturesToProtoFeature(data, options) {
4478
+ const protoFeatures = [];
4479
+ switch (data.type) {
4480
+ case "FeatureCollection":
4481
+ let i = 0;
4482
+ for (const feature of data.features) {
4483
+ protoFeatures.push(convertFeature(feature, options, i++));
4484
+ }
4485
+ break;
4486
+ case "Feature":
4487
+ protoFeatures.push(convertFeature(data, options));
4488
+ break;
4489
+ default:
4490
+ protoFeatures.push(convertFeature({ geometry: data }, options));
4173
4491
  }
4174
- return features;
4492
+ return protoFeatures;
4175
4493
  }
4176
- function convertFeature(features, geojson, options, index) {
4494
+ function convertFeature(geojson, options, index) {
4177
4495
  if (!geojson.geometry) {
4178
4496
  return;
4179
4497
  }
@@ -4187,51 +4505,57 @@ var __exports__ = (() => {
4187
4505
  } else if (options.generateId) {
4188
4506
  id = index || 0;
4189
4507
  }
4190
- if (type === "Point") {
4191
- convertPoint(coords, geometry);
4192
- } else if (type === "MultiPoint") {
4193
- for (const p of coords) {
4194
- convertPoint(p, geometry);
4195
- }
4196
- } else if (type === "LineString") {
4197
- convertLine(coords, geometry, tolerance, false);
4198
- } else if (type === "MultiLineString") {
4199
- if (options.lineMetrics) {
4200
- for (const line of coords) {
4201
- geometry = [];
4202
- convertLine(line, geometry, tolerance, false);
4203
- features.push(createFeature(id, "LineString", geometry, geojson.properties));
4508
+ switch (type) {
4509
+ case "Point":
4510
+ convertPoint(coords, geometry);
4511
+ break;
4512
+ case "MultiPoint":
4513
+ for (const p of coords) {
4514
+ convertPoint(p, geometry);
4204
4515
  }
4205
- return;
4206
- } else {
4207
- convertLines(coords, geometry, tolerance, false);
4208
- }
4209
- } else if (type === "Polygon") {
4210
- convertLines(coords, geometry, tolerance, true);
4211
- } else if (type === "MultiPolygon") {
4212
- for (const polygon of coords) {
4213
- const newPolygon = [];
4214
- convertLines(polygon, newPolygon, tolerance, true);
4215
- geometry.push(newPolygon);
4216
- }
4217
- } else if (type === "GeometryCollection") {
4218
- for (const singleGeometry of geojson.geometry.geometries) {
4219
- convertFeature(
4220
- features,
4221
- {
4222
- id,
4223
- geometry: singleGeometry,
4224
- properties: geojson.properties
4225
- },
4226
- options,
4227
- index
4228
- );
4229
- }
4230
- return;
4231
- } else {
4232
- throw new Error("Input data is not a valid GeoJSON object.");
4516
+ break;
4517
+ case "LineString":
4518
+ convertLine(coords, geometry, tolerance, false);
4519
+ break;
4520
+ case "MultiLineString":
4521
+ if (options.lineMetrics) {
4522
+ for (const line of coords) {
4523
+ geometry = [];
4524
+ convertLine(line, geometry, tolerance, false);
4525
+ features.push(createProtoFeature(id, "LineString", geometry, geojson.properties));
4526
+ }
4527
+ return;
4528
+ convertLines(coords, geometry, tolerance, false);
4529
+ }
4530
+ break;
4531
+ case "Polygon":
4532
+ convertLines(coords, geometry, tolerance, true);
4533
+ break;
4534
+ case "MultiPolygon":
4535
+ for (const polygon of coords) {
4536
+ const newPolygon = [];
4537
+ convertLines(polygon, newPolygon, tolerance, true);
4538
+ geometry.push(newPolygon);
4539
+ }
4540
+ break;
4541
+ case "GeometryCollection":
4542
+ for (const singleGeometry of geojson.geometry.geometries) {
4543
+ convertFeature(
4544
+ features,
4545
+ {
4546
+ id,
4547
+ geometry: singleGeometry,
4548
+ properties: geojson.properties
4549
+ },
4550
+ options,
4551
+ index
4552
+ );
4553
+ }
4554
+ break;
4555
+ default:
4556
+ throw new Error("Input data is not a valid GeoJSON object.");
4233
4557
  }
4234
- features.push(createFeature(id, type, geometry, geojson.properties));
4558
+ return createProtoFeature(id, type, geometry, geojson.properties);
4235
4559
  }
4236
4560
  function convertPoint(coords, out) {
4237
4561
  out.push(projectX(coords[0]), projectY(coords[1]), 0);
@@ -4255,7 +4579,7 @@ var __exports__ = (() => {
4255
4579
  }
4256
4580
  const last = out.length - 3;
4257
4581
  out[2] = 1;
4258
- simplify(out, 0, last, tolerance);
4582
+ simplifyPath(out, 0, last, tolerance);
4259
4583
  out[last + 2] = 1;
4260
4584
  out.size = Math.abs(size);
4261
4585
  out.start = 0;
@@ -4277,17 +4601,17 @@ var __exports__ = (() => {
4277
4601
  return y2 < 0 ? 0 : y2 > 1 ? 1 : y2;
4278
4602
  }
4279
4603
 
4280
- // src/lib/vector-tiler/clip.ts
4281
- function clip(features, scale, k1, k2, axis, minAll, maxAll, options) {
4604
+ // src/lib/vector-tiler/features/clip-features.ts
4605
+ function clipFeatures(features2, scale, k1, k2, axis, minAll, maxAll, options) {
4282
4606
  k1 /= scale;
4283
4607
  k2 /= scale;
4284
4608
  if (minAll >= k1 && maxAll < k2) {
4285
- return features;
4609
+ return features2;
4286
4610
  } else if (maxAll < k1 || minAll >= k2) {
4287
4611
  return null;
4288
4612
  }
4289
4613
  const clipped = [];
4290
- for (const feature of features) {
4614
+ for (const feature of features2) {
4291
4615
  const geometry = feature.geometry;
4292
4616
  let type = feature.type;
4293
4617
  const min = axis === 0 ? feature.minX : feature.minY;
@@ -4319,7 +4643,7 @@ var __exports__ = (() => {
4319
4643
  if (newGeometry.length) {
4320
4644
  if (options.lineMetrics && type === "LineString") {
4321
4645
  for (const line of newGeometry) {
4322
- clipped.push(createFeature(feature.id, type, line, feature.tags));
4646
+ clipped.push(createProtoFeature(feature.id, type, line, feature.tags));
4323
4647
  }
4324
4648
  continue;
4325
4649
  }
@@ -4334,7 +4658,7 @@ var __exports__ = (() => {
4334
4658
  if (type === "Point" || type === "MultiPoint") {
4335
4659
  type = newGeometry.length === 3 ? "Point" : "MultiPoint";
4336
4660
  }
4337
- clipped.push(createFeature(feature.id, type, newGeometry, feature.tags));
4661
+ clipped.push(createProtoFeature(feature.id, type, newGeometry, feature.tags));
4338
4662
  }
4339
4663
  }
4340
4664
  return clipped.length ? clipped : null;
@@ -4442,14 +4766,14 @@ var __exports__ = (() => {
4442
4766
  return t;
4443
4767
  }
4444
4768
 
4445
- // src/lib/vector-tiler/wrap.ts
4446
- function wrap(features, options) {
4769
+ // src/lib/vector-tiler/features/wrap-features.ts
4770
+ function wrapFeatures(features2, options) {
4447
4771
  const buffer = options.buffer / options.extent;
4448
- let merged = features;
4449
- const left = clip(features, 1, -1 - buffer, buffer, 0, -1, 2, options);
4450
- const right = clip(features, 1, 1 - buffer, 2 + buffer, 0, -1, 2, options);
4772
+ let merged = features2;
4773
+ const left = clipFeatures(features2, 1, -1 - buffer, buffer, 0, -1, 2, options);
4774
+ const right = clipFeatures(features2, 1, 1 - buffer, 2 + buffer, 0, -1, 2, options);
4451
4775
  if (left || right) {
4452
- merged = clip(features, 1, -buffer, 1 + buffer, 0, -1, 2, options) || [];
4776
+ merged = clipFeatures(features2, 1, -buffer, 1 + buffer, 0, -1, 2, options) || [];
4453
4777
  if (left) {
4454
4778
  merged = shiftFeatureCoords(left, 1).concat(merged);
4455
4779
  }
@@ -4459,30 +4783,39 @@ var __exports__ = (() => {
4459
4783
  }
4460
4784
  return merged;
4461
4785
  }
4462
- function shiftFeatureCoords(features, offset) {
4786
+ function shiftFeatureCoords(features2, offset) {
4463
4787
  const newFeatures = [];
4464
- for (let i = 0; i < features.length; i++) {
4465
- const feature = features[i];
4788
+ for (let i = 0; i < features2.length; i++) {
4789
+ const feature = features2[i];
4466
4790
  const type = feature.type;
4467
4791
  let newGeometry;
4468
- if (type === "Point" || type === "MultiPoint" || type === "LineString") {
4469
- newGeometry = shiftCoords(feature.geometry, offset);
4470
- } else if (type === "MultiLineString" || type === "Polygon") {
4471
- newGeometry = [];
4472
- for (const line of feature.geometry) {
4473
- newGeometry.push(shiftCoords(line, offset));
4474
- }
4475
- } else if (type === "MultiPolygon") {
4476
- newGeometry = [];
4477
- for (const polygon of feature.geometry) {
4478
- const newPolygon = [];
4479
- for (const line of polygon) {
4480
- newPolygon.push(shiftCoords(line, offset));
4792
+ switch (type) {
4793
+ case "Point":
4794
+ case "MultiPoint":
4795
+ case "LineString":
4796
+ newGeometry = shiftCoords(feature.geometry, offset);
4797
+ break;
4798
+ case "MultiLineString":
4799
+ case "Polygon":
4800
+ newGeometry = [];
4801
+ for (const line of feature.geometry) {
4802
+ newGeometry.push(shiftCoords(line, offset));
4481
4803
  }
4482
- newGeometry.push(newPolygon);
4483
- }
4804
+ break;
4805
+ case "MultiPolygon":
4806
+ newGeometry = [];
4807
+ for (const polygon of feature.geometry) {
4808
+ const newPolygon = [];
4809
+ for (const line of polygon) {
4810
+ newPolygon.push(shiftCoords(line, offset));
4811
+ }
4812
+ newGeometry.push(newPolygon);
4813
+ }
4814
+ break;
4815
+ default:
4816
+ throw new Error(String(type));
4484
4817
  }
4485
- newFeatures.push(createFeature(feature.id, type, newGeometry, feature.tags));
4818
+ newFeatures.push(createProtoFeature(feature.id, type, newGeometry, feature.tags));
4486
4819
  }
4487
4820
  return newFeatures;
4488
4821
  }
@@ -4499,148 +4832,47 @@ var __exports__ = (() => {
4499
4832
  return newPoints;
4500
4833
  }
4501
4834
 
4502
- // src/lib/vector-tiler/transform.ts
4503
- function transformTile(tile, extent) {
4504
- if (tile.transformed) {
4505
- return tile;
4506
- }
4507
- const z2 = 1 << tile.z;
4508
- const tx = tile.x;
4509
- const ty = tile.y;
4510
- for (const feature of tile.features) {
4511
- const geom = feature.geometry;
4512
- const type = feature.type;
4513
- feature.geometry = [];
4514
- if (type === 1) {
4515
- for (let j = 0; j < geom.length; j += 2) {
4516
- feature.geometry.push(transformPoint(geom[j], geom[j + 1], extent, z2, tx, ty));
4517
- }
4518
- } else {
4519
- for (let j = 0; j < geom.length; j++) {
4520
- const ring = [];
4521
- for (let k = 0; k < geom[j].length; k += 2) {
4522
- ring.push(transformPoint(geom[j][k], geom[j][k + 1], extent, z2, tx, ty));
4523
- }
4524
- feature.geometry.push(ring);
4525
- }
4526
- }
4527
- }
4528
- tile.transformed = true;
4529
- return tile;
4530
- }
4531
- function transformPoint(x, y, extent, z2, tx, ty) {
4532
- return [Math.round(extent * (x * z2 - tx)), Math.round(extent * (y * z2 - ty))];
4533
- }
4534
-
4535
- // src/lib/vector-tiler/tile.ts
4536
- function createTile(features, z, tx, ty, options) {
4537
- const tolerance = z === options.maxZoom ? 0 : options.tolerance / ((1 << z) * options.extent);
4538
- const tile = {
4539
- features: [],
4540
- numPoints: 0,
4541
- numSimplified: 0,
4542
- numFeatures: features.length,
4543
- source: null,
4544
- x: tx,
4545
- y: ty,
4546
- z,
4547
- transformed: false,
4548
- minX: 2,
4549
- minY: 1,
4550
- maxX: -1,
4551
- maxY: 0
4552
- };
4553
- for (const feature of features) {
4554
- addFeature(tile, feature, tolerance, options);
4555
- }
4556
- return tile;
4557
- }
4558
- function addFeature(tile, feature, tolerance, options) {
4559
- const geom = feature.geometry;
4560
- const type = feature.type;
4561
- const simplified = [];
4562
- tile.minX = Math.min(tile.minX, feature.minX);
4563
- tile.minY = Math.min(tile.minY, feature.minY);
4564
- tile.maxX = Math.max(tile.maxX, feature.maxX);
4565
- tile.maxY = Math.max(tile.maxY, feature.maxY);
4566
- if (type === "Point" || type === "MultiPoint") {
4567
- for (let i = 0; i < geom.length; i += 3) {
4568
- simplified.push(geom[i], geom[i + 1]);
4569
- tile.numPoints++;
4570
- tile.numSimplified++;
4571
- }
4572
- } else if (type === "LineString") {
4573
- addLine(simplified, geom, tile, tolerance, false, false);
4574
- } else if (type === "MultiLineString" || type === "Polygon") {
4575
- for (let i = 0; i < geom.length; i++) {
4576
- addLine(simplified, geom[i], tile, tolerance, type === "Polygon", i === 0);
4577
- }
4578
- } else if (type === "MultiPolygon") {
4579
- for (let k = 0; k < geom.length; k++) {
4580
- const polygon = geom[k];
4581
- for (let i = 0; i < polygon.length; i++) {
4582
- addLine(simplified, polygon[i], tile, tolerance, true, i === 0);
4583
- }
4584
- }
4585
- }
4586
- if (simplified.length) {
4587
- let tags = feature.tags || null;
4588
- if (type === "LineString" && options.lineMetrics) {
4589
- tags = {};
4590
- for (const key in feature.tags)
4591
- tags[key] = feature.tags[key];
4592
- tags.mapbox_clip_start = geom.start / geom.size;
4593
- tags.mapbox_clip_end = geom.end / geom.size;
4594
- }
4595
- const tileFeature = {
4596
- geometry: simplified,
4597
- type: type === "Polygon" || type === "MultiPolygon" ? 3 : type === "LineString" || type === "MultiLineString" ? 2 : 1,
4598
- tags
4599
- };
4600
- if (feature.id !== null) {
4601
- tileFeature.id = feature.id;
4602
- }
4603
- tile.features.push(tileFeature);
4604
- }
4605
- }
4606
- function addLine(result, geom, tile, tolerance, isPolygon, isOuter) {
4607
- const sqTolerance = tolerance * tolerance;
4608
- if (tolerance > 0 && geom.size < (isPolygon ? sqTolerance : tolerance)) {
4609
- tile.numPoints += geom.length / 3;
4610
- return;
4611
- }
4612
- const ring = [];
4613
- for (let i = 0; i < geom.length; i += 3) {
4614
- if (tolerance === 0 || geom[i + 2] > sqTolerance) {
4615
- tile.numSimplified++;
4616
- ring.push(geom[i], geom[i + 1]);
4835
+ // src/table-tile-source.ts
4836
+ var TableTileSource = {
4837
+ name: "TableTiler",
4838
+ id: "table-tiler",
4839
+ version: "0.0.0",
4840
+ extensions: ["mvt"],
4841
+ mimeTypes: ["application/octet-stream"],
4842
+ options: {
4843
+ table: {
4844
+ coordinates: "local",
4845
+ promoteId: void 0,
4846
+ maxZoom: 14,
4847
+ indexMaxZoom: 5,
4848
+ maxPointsPerTile: 1e4,
4849
+ tolerance: 3,
4850
+ extent: 4096,
4851
+ buffer: 64,
4852
+ generateId: void 0
4617
4853
  }
4618
- tile.numPoints++;
4619
- }
4620
- if (isPolygon)
4621
- rewind(ring, isOuter);
4622
- result.push(ring);
4623
- }
4624
- function rewind(ring, clockwise) {
4625
- let area2 = 0;
4626
- for (let i = 0, j = ring.length - 2; i < ring.length; j = i, i += 2) {
4627
- area2 += (ring[i] - ring[j]) * (ring[i + 1] + ring[j + 1]);
4854
+ },
4855
+ type: "table",
4856
+ testURL: (url) => url.endsWith(".geojson"),
4857
+ createDataSource(url, options) {
4858
+ const needsLoading = typeof url === "string" || url instanceof Blob;
4859
+ const loader = options?.table?.loaders?.[0];
4860
+ const tablePromise = needsLoading ? loadTable(url, loader) : url;
4861
+ return new DynamicVectorTileSource(tablePromise, options);
4628
4862
  }
4629
- if (area2 > 0 === clockwise) {
4630
- for (let i = 0, len = ring.length; i < len / 2; i += 2) {
4631
- const x = ring[i];
4632
- const y = ring[i + 1];
4633
- ring[i] = ring[len - 2 - i];
4634
- ring[i + 1] = ring[len - 1 - i];
4635
- ring[len - 2 - i] = x;
4636
- ring[len - 1 - i] = y;
4637
- }
4863
+ // @ts-expect-error
4864
+ };
4865
+ async function loadTable(url, loader) {
4866
+ if (typeof url === "string") {
4867
+ const response = await fetch(url);
4868
+ const data2 = await response.arrayBuffer();
4869
+ return await loader.parse(data2);
4638
4870
  }
4871
+ const data = await url.arrayBuffer();
4872
+ return await loader.parse(data);
4639
4873
  }
4640
-
4641
- // src/table-tile-source.ts
4642
- var _TableTileSource = class {
4643
- /** Stats for this TableTileSource */
4874
+ var _DynamicVectorTileSource = class {
4875
+ /** Stats for this DynamicVectorTileSource */
4644
4876
  stats = new Stats({
4645
4877
  id: "table-tile-source",
4646
4878
  stats: [new Stat("tiles", "count"), new Stat("features", "count")]
@@ -4649,6 +4881,7 @@ var __exports__ = (() => {
4649
4881
  mimeType = "application/vnd.mapbox-vector-tile";
4650
4882
  localCoordinates = true;
4651
4883
  /** The props that this tile source was created with */
4884
+ // @ts-expect-error
4652
4885
  props;
4653
4886
  /* Schema of the data */
4654
4887
  schema = null;
@@ -4661,7 +4894,7 @@ var __exports__ = (() => {
4661
4894
  /** Metadata for the tile source (generated TileJSON/tilestats */
4662
4895
  metadata;
4663
4896
  constructor(table, props) {
4664
- this.props = { ..._TableTileSource.defaultProps, ...props };
4897
+ this.props = { ...TableTileSource.options.table, ...props?.table };
4665
4898
  this.getTileData = this.getTileData.bind(this);
4666
4899
  this.ready = this.initializeTilesAsync(table);
4667
4900
  this.metadata = this.getMetadata();
@@ -4705,11 +4938,11 @@ var __exports__ = (() => {
4705
4938
  * @note Application must await `source.ready` before calling sync methods.
4706
4939
  */
4707
4940
  getTileSync(tileIndex) {
4708
- const rawTile = this.getRawTile(tileIndex);
4709
- if (!rawTile) {
4941
+ const protoTile = this.getProtoTile(tileIndex);
4942
+ if (!protoTile) {
4710
4943
  return null;
4711
4944
  }
4712
- return convertToGeoJSONTable(rawTile, {
4945
+ return convertTileToGeoJSON(protoTile, {
4713
4946
  coordinates: this.props.coordinates,
4714
4947
  tileIndex,
4715
4948
  extent: this.props.extent
@@ -4726,28 +4959,32 @@ var __exports__ = (() => {
4726
4959
  if (this.props.promoteId && this.props.generateId) {
4727
4960
  throw new Error("promoteId and generateId cannot be used together.");
4728
4961
  }
4729
- log.log(1, "TableTileSource creating root tiles", this.props)();
4962
+ log.log(1, "DynamicVectorTileSource creating root tiles", this.props)();
4730
4963
  log.time(1, "preprocess table")();
4731
- let features = convert(table, this.props);
4964
+ let features2 = convertFeaturesToProtoFeature(table, this.props);
4732
4965
  log.timeEnd(1, "preprocess table")();
4733
4966
  log.time(1, "generate tiles")();
4734
- features = wrap(features, this.props);
4735
- if (features.length === 0) {
4736
- log.log(1, "TableTileSource: no features generated")();
4967
+ features2 = wrapFeatures(features2, this.props);
4968
+ if (features2.length === 0) {
4969
+ log.log(1, "DynamicVectorTileSource: no features generated")();
4737
4970
  return;
4738
4971
  }
4739
- this.splitTile(features, 0, 0, 0);
4972
+ this.splitTile(features2, 0, 0, 0);
4740
4973
  const rootTile = this.tiles[0];
4741
4974
  log.log(1, `root tile features: ${rootTile.numFeatures}, points: ${rootTile.numPoints}`)();
4742
4975
  log.timeEnd(1, "generate tiles")();
4743
- log.log(1, `TableTileSource: tiles generated: ${this.stats.get("total").count}`, this.stats)();
4976
+ log.log(
4977
+ 1,
4978
+ `DynamicVectorTileSource: tiles generated: ${this.stats.get("total").count}`,
4979
+ this.stats
4980
+ )();
4744
4981
  }
4745
4982
  /**
4746
4983
  * Return geojsonvt-style "half formed" vector tile
4747
4984
  * @note Application must await `source.ready` before calling sync methods.
4748
4985
  */
4749
4986
  // eslint-disable-next-line complexity, max-statements
4750
- getRawTile(tileIndex) {
4987
+ getProtoTile(tileIndex) {
4751
4988
  const { z, y } = tileIndex;
4752
4989
  let { x } = tileIndex;
4753
4990
  const { extent } = this.props;
@@ -4771,12 +5008,12 @@ var __exports__ = (() => {
4771
5008
  y0 = y0 >> 1;
4772
5009
  parent = this.tiles[toID(z0, x0, y0)];
4773
5010
  }
4774
- if (!parent || !parent.source) {
5011
+ if (!parent || !parent.sourceFeatures) {
4775
5012
  return null;
4776
5013
  }
4777
5014
  log.log(1, "found parent tile z%d-%d-%d", z0, x0, y0)();
4778
5015
  log.time(1, "drilling down")();
4779
- this.splitTile(parent.source, z0, x0, y0, z, x, y);
5016
+ this.splitTile(parent.sourceFeatures, z0, x0, y0, z, x, y);
4780
5017
  log.timeEnd(1, "drilling down")();
4781
5018
  return this.tiles[id] ? transformTile(this.tiles[id], extent) : null;
4782
5019
  }
@@ -4789,28 +5026,28 @@ var __exports__ = (() => {
4789
5026
  * zoom or the number of points is low as specified in the props.
4790
5027
  */
4791
5028
  // eslint-disable-next-line max-params, max-statements, complexity
4792
- splitTile(features, z, x, y, cz, cx, cy) {
4793
- const stack = [features, z, x, y];
5029
+ splitTile(features2, z, x, y, cz, cx, cy) {
5030
+ const stack = [features2, z, x, y];
4794
5031
  while (stack.length) {
4795
5032
  y = stack.pop();
4796
5033
  x = stack.pop();
4797
5034
  z = stack.pop();
4798
- features = stack.pop();
5035
+ features2 = stack.pop();
4799
5036
  const z2 = 1 << z;
4800
5037
  const id = toID(z, x, y);
4801
5038
  let tile = this.tiles[id];
4802
5039
  if (!tile) {
4803
5040
  log.time(2, "tile creation")();
4804
- tile = this.tiles[id] = createTile(features, z, x, y, this.props);
5041
+ tile = this.tiles[id] = createProtoTile(features2, z, x, y, this.props);
4805
5042
  this.tileCoords.push({ z, x, y });
4806
5043
  const key = `z${z}`;
4807
5044
  let stat = this.stats.get(key, "count");
4808
5045
  stat.incrementCount();
4809
5046
  stat = this.stats.get("total");
4810
5047
  stat.incrementCount();
4811
- stat = _TableTileSource.stats.get(key, "count");
5048
+ stat = _DynamicVectorTileSource.stats.get(key, "count");
4812
5049
  stat.incrementCount();
4813
- stat = _TableTileSource.stats.get("total");
5050
+ stat = _DynamicVectorTileSource.stats.get("total");
4814
5051
  stat.incrementCount();
4815
5052
  log.log(
4816
5053
  2,
@@ -4824,7 +5061,7 @@ var __exports__ = (() => {
4824
5061
  )();
4825
5062
  log.timeEnd(2, "tile creation")();
4826
5063
  }
4827
- tile.source = features;
5064
+ tile.sourceFeatures = features2;
4828
5065
  if (cz === void 0) {
4829
5066
  if (z === this.props.indexMaxZoom || tile.numPoints <= this.props.maxPointsPerTile) {
4830
5067
  continue;
@@ -4837,8 +5074,8 @@ var __exports__ = (() => {
4837
5074
  continue;
4838
5075
  }
4839
5076
  }
4840
- tile.source = null;
4841
- if (features.length === 0)
5077
+ tile.sourceFeatures = null;
5078
+ if (features2.length === 0)
4842
5079
  continue;
4843
5080
  log.time(2, "clipping tile")();
4844
5081
  const k1 = 0.5 * this.props.buffer / this.props.extent;
@@ -4849,17 +5086,17 @@ var __exports__ = (() => {
4849
5086
  let bl = null;
4850
5087
  let tr = null;
4851
5088
  let br = null;
4852
- let left = clip(features, z2, x - k1, x + k3, 0, tile.minX, tile.maxX, this.props);
4853
- let right = clip(features, z2, x + k2, x + k4, 0, tile.minX, tile.maxX, this.props);
4854
- features = null;
5089
+ let left = clipFeatures(features2, z2, x - k1, x + k3, 0, tile.minX, tile.maxX, this.props);
5090
+ let right = clipFeatures(features2, z2, x + k2, x + k4, 0, tile.minX, tile.maxX, this.props);
5091
+ features2 = null;
4855
5092
  if (left) {
4856
- tl = clip(left, z2, y - k1, y + k3, 1, tile.minY, tile.maxY, this.props);
4857
- bl = clip(left, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, this.props);
5093
+ tl = clipFeatures(left, z2, y - k1, y + k3, 1, tile.minY, tile.maxY, this.props);
5094
+ bl = clipFeatures(left, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, this.props);
4858
5095
  left = null;
4859
5096
  }
4860
5097
  if (right) {
4861
- tr = clip(right, z2, y - k1, y + k3, 1, tile.minY, tile.maxY, this.props);
4862
- br = clip(right, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, this.props);
5098
+ tr = clipFeatures(right, z2, y - k1, y + k3, 1, tile.minY, tile.maxY, this.props);
5099
+ br = clipFeatures(right, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, this.props);
4863
5100
  right = null;
4864
5101
  }
4865
5102
  log.timeEnd(2, "clipping tile")();
@@ -4870,111 +5107,15 @@ var __exports__ = (() => {
4870
5107
  }
4871
5108
  }
4872
5109
  };
4873
- var TableTileSource = _TableTileSource;
4874
- __publicField(TableTileSource, "defaultProps", {
4875
- coordinates: "wgs84",
4876
- // coordinates in tile coordinates or lng/lat
4877
- maxZoom: 14,
4878
- // max zoom to preserve detail on
4879
- indexMaxZoom: 5,
4880
- // max zoom in the tile index
4881
- maxPointsPerTile: 1e5,
4882
- // max number of points per tile in the tile index
4883
- tolerance: 3,
4884
- // simplification tolerance (higher means simpler)
4885
- extent: 4096,
4886
- // tile extent
4887
- buffer: 64,
4888
- // tile buffer on each side
4889
- lineMetrics: false,
4890
- // whether to calculate line metrics
4891
- // @ts-expect-error
4892
- promoteId: void 0,
4893
- // name of a feature property to be promoted to feature.id
4894
- generateId: false,
4895
- // whether to generate feature ids. Cannot be used with promoteId
4896
- debug: 0
4897
- // logging level (0, 1 or 2)
4898
- });
4899
- /** Global stats for all TableTileSources */
4900
- __publicField(TableTileSource, "stats", new Stats({
5110
+ var DynamicVectorTileSource = _DynamicVectorTileSource;
5111
+ /** Global stats for all DynamicVectorTileSources */
5112
+ __publicField(DynamicVectorTileSource, "stats", new Stats({
4901
5113
  id: "table-tile-source-all",
4902
5114
  stats: [new Stat("count", "tiles"), new Stat("count", "features")]
4903
5115
  }));
4904
5116
  function toID(z, x, y) {
4905
5117
  return ((1 << z) * y + x) * 32 + z;
4906
5118
  }
4907
- function convertToGeoJSONTable(vtTile, props) {
4908
- const features = [];
4909
- for (const rawFeature of vtTile.features) {
4910
- if (!rawFeature || !rawFeature.geometry) {
4911
- continue;
4912
- }
4913
- let type;
4914
- let coordinates;
4915
- switch (rawFeature.type) {
4916
- case 1:
4917
- if (rawFeature.geometry.length === 1) {
4918
- type = "Point";
4919
- coordinates = rawFeature.geometry[0];
4920
- } else {
4921
- type = "MultiPoint";
4922
- coordinates = rawFeature.geometry;
4923
- }
4924
- break;
4925
- case 2:
4926
- if (rawFeature.geometry.length === 1) {
4927
- type = "LineString";
4928
- coordinates = rawFeature.geometry[0];
4929
- } else {
4930
- type = "MultiLineString";
4931
- coordinates = rawFeature.geometry;
4932
- }
4933
- break;
4934
- case 3:
4935
- if (rawFeature.geometry.length > 1) {
4936
- type = "MultiPolygon";
4937
- coordinates = [rawFeature.geometry];
4938
- } else {
4939
- type = "Polygon";
4940
- coordinates = rawFeature.geometry;
4941
- }
4942
- break;
4943
- default:
4944
- continue;
4945
- }
4946
- switch (props.coordinates) {
4947
- case "EPSG:4326":
4948
- case "wgs84":
4949
- projectToLngLat(coordinates, props.tileIndex, props.extent);
4950
- break;
4951
- case "local":
4952
- convertToLocalCoordinates(coordinates, props.extent);
4953
- break;
4954
- default:
4955
- throw new Error(`Unsupported CRS ${props.coordinates}`);
4956
- }
4957
- const feature = {
4958
- type: "Feature",
4959
- geometry: {
4960
- type,
4961
- coordinates
4962
- },
4963
- properties: rawFeature.tags || {},
4964
- id: rawFeature.id
4965
- };
4966
- features.push(feature);
4967
- }
4968
- if (features.length === 0) {
4969
- return null;
4970
- }
4971
- const table = {
4972
- shape: "geojson-table",
4973
- type: "FeatureCollection",
4974
- features
4975
- };
4976
- return table;
4977
- }
4978
5119
  return __toCommonJS(bundle_exports);
4979
5120
  })();
4980
5121
  /*! Bundled license information: