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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/dist/dist.dev.js +1784 -847
  2. package/dist/dist.min.js +1 -1
  3. package/dist/index.cjs +713 -640
  4. package/dist/index.cjs.map +4 -4
  5. package/dist/index.d.ts +2 -2
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +1 -1
  8. package/dist/lib/parse-mvt.d.ts +2 -1
  9. package/dist/lib/parse-mvt.d.ts.map +1 -1
  10. package/dist/lib/parse-mvt.js +15 -45
  11. package/dist/lib/parse-tilejson.d.ts +4 -4
  12. package/dist/lib/parse-tilejson.d.ts.map +1 -1
  13. package/dist/lib/types.d.ts +1 -39
  14. package/dist/lib/types.d.ts.map +1 -1
  15. package/dist/lib/utils/geometry-utils.d.ts +83 -0
  16. package/dist/lib/utils/geometry-utils.d.ts.map +1 -0
  17. package/dist/lib/utils/geometry-utils.js +206 -0
  18. package/dist/lib/vector-tile/vector-tile-feature.d.ts +72 -0
  19. package/dist/lib/vector-tile/vector-tile-feature.d.ts.map +1 -0
  20. package/dist/lib/vector-tile/vector-tile-feature.js +342 -0
  21. package/dist/lib/{mapbox-vector-tile → vector-tile}/vector-tile-layer.d.ts +10 -1
  22. package/dist/lib/vector-tile/vector-tile-layer.d.ts.map +1 -0
  23. package/dist/lib/{mapbox-vector-tile → vector-tile}/vector-tile-layer.js +16 -1
  24. package/dist/lib/vector-tile/vector-tile.d.ts.map +1 -0
  25. package/dist/lib/{geojson-tiler → vector-tiler}/clip.d.ts +3 -3
  26. package/dist/lib/vector-tiler/clip.d.ts.map +1 -0
  27. package/dist/lib/vector-tiler/convert.d.ts +18 -0
  28. package/dist/lib/vector-tiler/convert.d.ts.map +1 -0
  29. package/dist/lib/{geojson-tiler → vector-tiler}/convert.js +8 -1
  30. package/dist/lib/vector-tiler/feature.d.ts +3 -0
  31. package/dist/lib/vector-tiler/feature.d.ts.map +1 -0
  32. package/dist/lib/vector-tiler/simplify.d.ts.map +1 -0
  33. package/dist/lib/{geojson-tiler → vector-tiler}/tile.d.ts +4 -4
  34. package/dist/lib/vector-tiler/tile.d.ts.map +1 -0
  35. package/dist/lib/vector-tiler/transform.d.ts +7 -0
  36. package/dist/lib/vector-tiler/transform.d.ts.map +1 -0
  37. package/dist/lib/{geojson-tiler → vector-tiler}/wrap.d.ts +2 -2
  38. package/dist/lib/vector-tiler/wrap.d.ts.map +1 -0
  39. package/dist/mvt-loader.d.ts +19 -8
  40. package/dist/mvt-loader.d.ts.map +1 -1
  41. package/dist/mvt-loader.js +3 -2
  42. package/dist/mvt-source.d.ts +4 -4
  43. package/dist/mvt-source.d.ts.map +1 -1
  44. package/dist/mvt-source.js +7 -7
  45. package/dist/mvt-worker.js +1244 -762
  46. package/dist/table-tile-source.d.ts +118 -0
  47. package/dist/table-tile-source.d.ts.map +1 -0
  48. package/dist/table-tile-source.js +370 -0
  49. package/dist/tilejson-loader.js +1 -1
  50. package/package.json +7 -6
  51. package/src/index.ts +3 -3
  52. package/src/lib/parse-mvt.ts +28 -66
  53. package/src/lib/parse-tilejson.ts +5 -5
  54. package/src/lib/types.ts +1 -39
  55. package/src/lib/utils/geometry-utils.ts +234 -0
  56. package/src/lib/vector-tile/vector-tile-feature.ts +416 -0
  57. package/src/lib/{mapbox-vector-tile → vector-tile}/vector-tile-layer.ts +28 -2
  58. package/src/lib/{geojson-tiler → vector-tiler}/clip.ts +4 -4
  59. package/src/lib/{geojson-tiler → vector-tiler}/convert.ts +19 -9
  60. package/src/lib/{geojson-tiler → vector-tiler}/feature.ts +3 -3
  61. package/src/lib/{geojson-tiler → vector-tiler}/tile.ts +10 -10
  62. package/src/lib/{geojson-tiler → vector-tiler}/transform.ts +2 -2
  63. package/src/lib/{geojson-tiler → vector-tiler}/wrap.ts +5 -5
  64. package/src/mvt-loader.ts +14 -6
  65. package/src/mvt-source.ts +9 -10
  66. package/src/table-tile-source.ts +508 -0
  67. package/dist/helpers/binary-util-functions.d.ts +0 -35
  68. package/dist/helpers/binary-util-functions.d.ts.map +0 -1
  69. package/dist/helpers/binary-util-functions.js +0 -114
  70. package/dist/helpers/mapbox-util-functions.d.ts +0 -29
  71. package/dist/helpers/mapbox-util-functions.d.ts.map +0 -1
  72. package/dist/helpers/mapbox-util-functions.js +0 -78
  73. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts +0 -41
  74. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +0 -1
  75. package/dist/lib/binary-vector-tile/vector-tile-feature.js +0 -163
  76. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts +0 -23
  77. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts.map +0 -1
  78. package/dist/lib/binary-vector-tile/vector-tile-layer.js +0 -96
  79. package/dist/lib/binary-vector-tile/vector-tile.d.ts +0 -9
  80. package/dist/lib/binary-vector-tile/vector-tile.d.ts.map +0 -1
  81. package/dist/lib/binary-vector-tile/vector-tile.js +0 -27
  82. package/dist/lib/geojson-tiler/clip.d.ts.map +0 -1
  83. package/dist/lib/geojson-tiler/convert.d.ts +0 -10
  84. package/dist/lib/geojson-tiler/convert.d.ts.map +0 -1
  85. package/dist/lib/geojson-tiler/feature.d.ts +0 -3
  86. package/dist/lib/geojson-tiler/feature.d.ts.map +0 -1
  87. package/dist/lib/geojson-tiler/geojson-tiler.d.ts +0 -44
  88. package/dist/lib/geojson-tiler/geojson-tiler.d.ts.map +0 -1
  89. package/dist/lib/geojson-tiler/geojson-tiler.js +0 -209
  90. package/dist/lib/geojson-tiler/simplify.d.ts.map +0 -1
  91. package/dist/lib/geojson-tiler/tile.d.ts.map +0 -1
  92. package/dist/lib/geojson-tiler/transform.d.ts +0 -7
  93. package/dist/lib/geojson-tiler/transform.d.ts.map +0 -1
  94. package/dist/lib/geojson-tiler/wrap.d.ts.map +0 -1
  95. package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts +0 -27
  96. package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts.map +0 -1
  97. package/dist/lib/mapbox-vector-tile/vector-tile-feature.js +0 -178
  98. package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts.map +0 -1
  99. package/dist/lib/mapbox-vector-tile/vector-tile.d.ts.map +0 -1
  100. package/src/helpers/binary-util-functions.ts +0 -125
  101. package/src/helpers/mapbox-util-functions.ts +0 -82
  102. package/src/lib/binary-vector-tile/vector-tile-feature.ts +0 -203
  103. package/src/lib/binary-vector-tile/vector-tile-layer.ts +0 -113
  104. package/src/lib/binary-vector-tile/vector-tile.ts +0 -36
  105. package/src/lib/geojson-tiler/geojson-tiler.ts +0 -283
  106. package/src/lib/mapbox-vector-tile/LICENSE.txt +0 -31
  107. package/src/lib/mapbox-vector-tile/vector-tile-feature.ts +0 -207
  108. /package/dist/lib/{mapbox-vector-tile → vector-tile}/vector-tile.d.ts +0 -0
  109. /package/dist/lib/{mapbox-vector-tile → vector-tile}/vector-tile.js +0 -0
  110. /package/dist/lib/{geojson-tiler → vector-tiler}/clip.js +0 -0
  111. /package/dist/lib/{geojson-tiler → vector-tiler}/feature.js +0 -0
  112. /package/dist/lib/{geojson-tiler → vector-tiler}/simplify.d.ts +0 -0
  113. /package/dist/lib/{geojson-tiler → vector-tiler}/simplify.js +0 -0
  114. /package/dist/lib/{geojson-tiler → vector-tiler}/tile.js +0 -0
  115. /package/dist/lib/{geojson-tiler → vector-tiler}/transform.js +0 -0
  116. /package/dist/lib/{geojson-tiler → vector-tiler}/wrap.js +0 -0
  117. /package/src/lib/{binary-vector-tile → vector-tile}/LICENSE.txt +0 -0
  118. /package/src/lib/{mapbox-vector-tile → vector-tile}/vector-tile.ts +0 -0
  119. /package/src/lib/{geojson-tiler → vector-tiler}/LICENSE +0 -0
  120. /package/src/lib/{geojson-tiler → vector-tiler}/simplify.ts +0 -0
package/dist/dist.dev.js CHANGED
@@ -12,6 +12,7 @@ var __exports__ = (() => {
12
12
  var __getOwnPropNames = Object.getOwnPropertyNames;
13
13
  var __getProtoOf = Object.getPrototypeOf;
14
14
  var __hasOwnProp = Object.prototype.hasOwnProperty;
15
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
15
16
  var __commonJS = (cb, mod) => function __require() {
16
17
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
17
18
  };
@@ -37,6 +38,10 @@ var __exports__ = (() => {
37
38
  mod
38
39
  ));
39
40
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
41
+ var __publicField = (obj, key, value) => {
42
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
43
+ return value;
44
+ };
40
45
 
41
46
  // external-global-plugin:@loaders.gl/core
42
47
  var require_core = __commonJS({
@@ -54,19 +59,19 @@ var __exports__ = (() => {
54
59
  var eMax = (1 << eLen) - 1;
55
60
  var eBias = eMax >> 1;
56
61
  var nBits = -7;
57
- var i2 = isLE ? nBytes - 1 : 0;
62
+ var i = isLE ? nBytes - 1 : 0;
58
63
  var d = isLE ? -1 : 1;
59
- var s = buffer[offset + i2];
60
- i2 += d;
64
+ var s = buffer[offset + i];
65
+ i += d;
61
66
  e = s & (1 << -nBits) - 1;
62
67
  s >>= -nBits;
63
68
  nBits += eLen;
64
- for (; nBits > 0; e = e * 256 + buffer[offset + i2], i2 += d, nBits -= 8) {
69
+ for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {
65
70
  }
66
71
  m = e & (1 << -nBits) - 1;
67
72
  e >>= -nBits;
68
73
  nBits += mLen;
69
- for (; nBits > 0; m = m * 256 + buffer[offset + i2], i2 += d, nBits -= 8) {
74
+ for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {
70
75
  }
71
76
  if (e === 0) {
72
77
  e = 1 - eBias;
@@ -84,7 +89,7 @@ var __exports__ = (() => {
84
89
  var eMax = (1 << eLen) - 1;
85
90
  var eBias = eMax >> 1;
86
91
  var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
87
- var i2 = isLE ? 0 : nBytes - 1;
92
+ var i = isLE ? 0 : nBytes - 1;
88
93
  var d = isLE ? 1 : -1;
89
94
  var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
90
95
  value = Math.abs(value);
@@ -117,13 +122,13 @@ var __exports__ = (() => {
117
122
  e = 0;
118
123
  }
119
124
  }
120
- for (; mLen >= 8; buffer[offset + i2] = m & 255, i2 += d, m /= 256, mLen -= 8) {
125
+ for (; mLen >= 8; buffer[offset + i] = m & 255, i += d, m /= 256, mLen -= 8) {
121
126
  }
122
127
  e = e << mLen | m;
123
128
  eLen += mLen;
124
- for (; eLen > 0; buffer[offset + i2] = e & 255, i2 += d, e /= 256, eLen -= 8) {
129
+ for (; eLen > 0; buffer[offset + i] = e & 255, i += d, e /= 256, eLen -= 8) {
125
130
  }
126
- buffer[offset + i2 - d] |= s * 128;
131
+ buffer[offset + i - d] |= s * 128;
127
132
  };
128
133
  }
129
134
  });
@@ -345,14 +350,14 @@ var __exports__ = (() => {
345
350
  this.writeVarint(tag << 3 | type);
346
351
  },
347
352
  realloc: function(min) {
348
- var length2 = this.length || 16;
349
- while (length2 < this.pos + min)
350
- length2 *= 2;
351
- if (length2 !== this.length) {
352
- var buf = new Uint8Array(length2);
353
+ var length = this.length || 16;
354
+ while (length < this.pos + min)
355
+ length *= 2;
356
+ if (length !== this.length) {
357
+ var buf = new Uint8Array(length);
353
358
  buf.set(this.buf);
354
359
  this.buf = buf;
355
- this.length = length2;
360
+ this.length = length;
356
361
  }
357
362
  },
358
363
  finish: function() {
@@ -433,8 +438,8 @@ var __exports__ = (() => {
433
438
  var len = buffer.length;
434
439
  this.writeVarint(len);
435
440
  this.realloc(len);
436
- for (var i2 = 0; i2 < len; i2++)
437
- this.buf[this.pos++] = buffer[i2];
441
+ for (var i = 0; i < len; i++)
442
+ this.buf[this.pos++] = buffer[i];
438
443
  },
439
444
  writeRawMessage: function(fn, obj) {
440
445
  this.pos++;
@@ -623,44 +628,44 @@ var __exports__ = (() => {
623
628
  function makeRoomForExtraLength(startPos, len, pbf) {
624
629
  var extraLen = len <= 16383 ? 1 : len <= 2097151 ? 2 : len <= 268435455 ? 3 : Math.floor(Math.log(len) / (Math.LN2 * 7));
625
630
  pbf.realloc(extraLen);
626
- for (var i2 = pbf.pos - 1; i2 >= startPos; i2--)
627
- pbf.buf[i2 + extraLen] = pbf.buf[i2];
631
+ for (var i = pbf.pos - 1; i >= startPos; i--)
632
+ pbf.buf[i + extraLen] = pbf.buf[i];
628
633
  }
629
634
  function writePackedVarint(arr, pbf) {
630
- for (var i2 = 0; i2 < arr.length; i2++)
631
- pbf.writeVarint(arr[i2]);
635
+ for (var i = 0; i < arr.length; i++)
636
+ pbf.writeVarint(arr[i]);
632
637
  }
633
638
  function writePackedSVarint(arr, pbf) {
634
- for (var i2 = 0; i2 < arr.length; i2++)
635
- pbf.writeSVarint(arr[i2]);
639
+ for (var i = 0; i < arr.length; i++)
640
+ pbf.writeSVarint(arr[i]);
636
641
  }
637
642
  function writePackedFloat(arr, pbf) {
638
- for (var i2 = 0; i2 < arr.length; i2++)
639
- pbf.writeFloat(arr[i2]);
643
+ for (var i = 0; i < arr.length; i++)
644
+ pbf.writeFloat(arr[i]);
640
645
  }
641
646
  function writePackedDouble(arr, pbf) {
642
- for (var i2 = 0; i2 < arr.length; i2++)
643
- pbf.writeDouble(arr[i2]);
647
+ for (var i = 0; i < arr.length; i++)
648
+ pbf.writeDouble(arr[i]);
644
649
  }
645
650
  function writePackedBoolean(arr, pbf) {
646
- for (var i2 = 0; i2 < arr.length; i2++)
647
- pbf.writeBoolean(arr[i2]);
651
+ for (var i = 0; i < arr.length; i++)
652
+ pbf.writeBoolean(arr[i]);
648
653
  }
649
654
  function writePackedFixed32(arr, pbf) {
650
- for (var i2 = 0; i2 < arr.length; i2++)
651
- pbf.writeFixed32(arr[i2]);
655
+ for (var i = 0; i < arr.length; i++)
656
+ pbf.writeFixed32(arr[i]);
652
657
  }
653
658
  function writePackedSFixed32(arr, pbf) {
654
- for (var i2 = 0; i2 < arr.length; i2++)
655
- pbf.writeSFixed32(arr[i2]);
659
+ for (var i = 0; i < arr.length; i++)
660
+ pbf.writeSFixed32(arr[i]);
656
661
  }
657
662
  function writePackedFixed64(arr, pbf) {
658
- for (var i2 = 0; i2 < arr.length; i2++)
659
- pbf.writeFixed64(arr[i2]);
663
+ for (var i = 0; i < arr.length; i++)
664
+ pbf.writeFixed64(arr[i]);
660
665
  }
661
666
  function writePackedSFixed64(arr, pbf) {
662
- for (var i2 = 0; i2 < arr.length; i2++)
663
- pbf.writeSFixed64(arr[i2]);
667
+ for (var i = 0; i < arr.length; i++)
668
+ pbf.writeSFixed64(arr[i]);
664
669
  }
665
670
  function readUInt32(buf, pos) {
666
671
  return (buf[pos] | buf[pos + 1] << 8 | buf[pos + 2] << 16) + buf[pos + 3] * 16777216;
@@ -676,12 +681,12 @@ var __exports__ = (() => {
676
681
  }
677
682
  function readUtf8(buf, pos, end) {
678
683
  var str = "";
679
- var i2 = pos;
680
- while (i2 < end) {
681
- var b0 = buf[i2];
684
+ var i = pos;
685
+ while (i < end) {
686
+ var b0 = buf[i];
682
687
  var c = null;
683
688
  var bytesPerSequence = b0 > 239 ? 4 : b0 > 223 ? 3 : b0 > 191 ? 2 : 1;
684
- if (i2 + bytesPerSequence > end)
689
+ if (i + bytesPerSequence > end)
685
690
  break;
686
691
  var b1, b2, b3;
687
692
  if (bytesPerSequence === 1) {
@@ -689,7 +694,7 @@ var __exports__ = (() => {
689
694
  c = b0;
690
695
  }
691
696
  } else if (bytesPerSequence === 2) {
692
- b1 = buf[i2 + 1];
697
+ b1 = buf[i + 1];
693
698
  if ((b1 & 192) === 128) {
694
699
  c = (b0 & 31) << 6 | b1 & 63;
695
700
  if (c <= 127) {
@@ -697,8 +702,8 @@ var __exports__ = (() => {
697
702
  }
698
703
  }
699
704
  } else if (bytesPerSequence === 3) {
700
- b1 = buf[i2 + 1];
701
- b2 = buf[i2 + 2];
705
+ b1 = buf[i + 1];
706
+ b2 = buf[i + 2];
702
707
  if ((b1 & 192) === 128 && (b2 & 192) === 128) {
703
708
  c = (b0 & 15) << 12 | (b1 & 63) << 6 | b2 & 63;
704
709
  if (c <= 2047 || c >= 55296 && c <= 57343) {
@@ -706,9 +711,9 @@ var __exports__ = (() => {
706
711
  }
707
712
  }
708
713
  } else if (bytesPerSequence === 4) {
709
- b1 = buf[i2 + 1];
710
- b2 = buf[i2 + 2];
711
- b3 = buf[i2 + 3];
714
+ b1 = buf[i + 1];
715
+ b2 = buf[i + 2];
716
+ b3 = buf[i + 3];
712
717
  if ((b1 & 192) === 128 && (b2 & 192) === 128 && (b3 & 192) === 128) {
713
718
  c = (b0 & 15) << 18 | (b1 & 63) << 12 | (b2 & 63) << 6 | b3 & 63;
714
719
  if (c <= 65535 || c >= 1114112) {
@@ -725,7 +730,7 @@ var __exports__ = (() => {
725
730
  c = 56320 | c & 1023;
726
731
  }
727
732
  str += String.fromCharCode(c);
728
- i2 += bytesPerSequence;
733
+ i += bytesPerSequence;
729
734
  }
730
735
  return str;
731
736
  }
@@ -733,8 +738,8 @@ var __exports__ = (() => {
733
738
  return utf8TextDecoder.decode(buf.subarray(pos, end));
734
739
  }
735
740
  function writeUtf8(buf, str, pos) {
736
- for (var i2 = 0, c, lead; i2 < str.length; i2++) {
737
- c = str.charCodeAt(i2);
741
+ for (var i = 0, c, lead; i < str.length; i++) {
742
+ c = str.charCodeAt(i);
738
743
  if (c > 55295 && c < 57344) {
739
744
  if (lead) {
740
745
  if (c < 56320) {
@@ -748,7 +753,7 @@ var __exports__ = (() => {
748
753
  lead = null;
749
754
  }
750
755
  } else {
751
- if (c > 56319 || i2 + 1 === str.length) {
756
+ if (c > 56319 || i + 1 === str.length) {
752
757
  buf[pos++] = 239;
753
758
  buf[pos++] = 191;
754
759
  buf[pos++] = 189;
@@ -788,14 +793,142 @@ var __exports__ = (() => {
788
793
  // bundle.ts
789
794
  var bundle_exports = {};
790
795
  __export(bundle_exports, {
791
- GeoJSONTiler: () => GeoJSONTiler,
792
796
  MVTLoader: () => MVTLoader,
793
797
  MVTSource: () => MVTSource,
794
798
  MVTWorkerLoader: () => MVTWorkerLoader,
799
+ TableTileSource: () => TableTileSource,
795
800
  TileJSONLoader: () => TileJSONLoader
796
801
  });
797
802
  __reExport(bundle_exports, __toESM(require_core(), 1));
798
803
 
804
+ // ../schema/src/lib/table/simple-table/data-type.ts
805
+ function getDataTypeFromValue(value, defaultNumberType = "float32") {
806
+ if (value instanceof Date) {
807
+ return "date-millisecond";
808
+ }
809
+ if (value instanceof Number) {
810
+ return defaultNumberType;
811
+ }
812
+ if (typeof value === "string") {
813
+ return "utf8";
814
+ }
815
+ if (value === null || value === "undefined") {
816
+ return "null";
817
+ }
818
+ return "null";
819
+ }
820
+ function getDataTypeFromArray(array) {
821
+ let type = getDataTypeFromTypedArray(array);
822
+ if (type !== "null") {
823
+ return { type, nullable: false };
824
+ }
825
+ if (array.length > 0) {
826
+ type = getDataTypeFromValue(array[0]);
827
+ return { type, nullable: true };
828
+ }
829
+ return { type: "null", nullable: true };
830
+ }
831
+ function getDataTypeFromTypedArray(array) {
832
+ switch (array.constructor) {
833
+ case Int8Array:
834
+ return "int8";
835
+ case Uint8Array:
836
+ case Uint8ClampedArray:
837
+ return "uint8";
838
+ case Int16Array:
839
+ return "int16";
840
+ case Uint16Array:
841
+ return "uint16";
842
+ case Int32Array:
843
+ return "int32";
844
+ case Uint32Array:
845
+ return "uint32";
846
+ case Float32Array:
847
+ return "float32";
848
+ case Float64Array:
849
+ return "float64";
850
+ default:
851
+ return "null";
852
+ }
853
+ }
854
+
855
+ // ../schema/src/lib/table/simple-table/table-schema.ts
856
+ function deduceTableSchema(table) {
857
+ switch (table.shape) {
858
+ case "array-row-table":
859
+ case "object-row-table":
860
+ return deduceSchemaFromRows(table.data);
861
+ case "geojson-table":
862
+ return deduceSchemaFromGeoJSON(table.features);
863
+ case "columnar-table":
864
+ return deduceSchemaFromColumns(table.data);
865
+ case "arrow-table":
866
+ default:
867
+ throw new Error("Deduce schema");
868
+ }
869
+ }
870
+ function deduceSchemaFromColumns(columnarTable) {
871
+ const fields = [];
872
+ for (const [columnName, column] of Object.entries(columnarTable)) {
873
+ const field = deduceFieldFromColumn(column, columnName);
874
+ fields.push(field);
875
+ }
876
+ return { fields, metadata: {} };
877
+ }
878
+ function deduceSchemaFromRows(rowTable) {
879
+ if (!rowTable.length) {
880
+ throw new Error("deduce from empty table");
881
+ }
882
+ const fields = [];
883
+ const row0 = rowTable[0];
884
+ for (const [columnName, value] of Object.entries(row0)) {
885
+ fields.push(deduceFieldFromValue(value, columnName));
886
+ }
887
+ return { fields, metadata: {} };
888
+ }
889
+ function deduceSchemaFromGeoJSON(features) {
890
+ if (!features.length) {
891
+ throw new Error("deduce from empty table");
892
+ }
893
+ const fields = [];
894
+ const row0 = features[0].properties || {};
895
+ for (const [columnName, value] of Object.entries(row0)) {
896
+ fields.push(deduceFieldFromValue(value, columnName));
897
+ }
898
+ return { fields, metadata: {} };
899
+ }
900
+ function deduceFieldFromColumn(column, name) {
901
+ if (ArrayBuffer.isView(column)) {
902
+ const type = getDataTypeFromArray(column);
903
+ return {
904
+ name,
905
+ type: type.type || "null",
906
+ nullable: type.nullable
907
+ // metadata: {}
908
+ };
909
+ }
910
+ if (Array.isArray(column) && column.length > 0) {
911
+ const value = column[0];
912
+ const type = getDataTypeFromValue(value);
913
+ return {
914
+ name,
915
+ type,
916
+ nullable: true
917
+ // metadata: {},
918
+ };
919
+ }
920
+ throw new Error("empty table");
921
+ }
922
+ function deduceFieldFromValue(value, name) {
923
+ const type = getDataTypeFromValue(value);
924
+ return {
925
+ name,
926
+ type,
927
+ nullable: true
928
+ // metadata: {}
929
+ };
930
+ }
931
+
799
932
  // ../../node_modules/@babel/runtime/helpers/esm/typeof.js
800
933
  function _typeof(obj) {
801
934
  "@babel/helpers - typeof";
@@ -858,9 +991,9 @@ var __exports__ = (() => {
858
991
  let area2 = 0;
859
992
  const i0 = DimIndex[plane[0]];
860
993
  const i1 = DimIndex[plane[1]];
861
- for (let i2 = start, j = end - dim; i2 < end; i2 += dim) {
862
- area2 += (points[i2 + i0] - points[j + i0]) * (points[i2 + i1] + points[j + i1]);
863
- j = i2;
994
+ for (let i = start, j = end - dim; i < end; i += dim) {
995
+ area2 += (points[i + i0] - points[j + i0]) * (points[i + i1] + points[j + i1]);
996
+ j = i;
864
997
  }
865
998
  return area2 / 2;
866
999
  }
@@ -878,24 +1011,24 @@ var __exports__ = (() => {
878
1011
  let maxY;
879
1012
  let minX;
880
1013
  let minY;
881
- let x2;
882
- let y2;
1014
+ let x;
1015
+ let y;
883
1016
  if (hasHoles)
884
1017
  outerNode = eliminateHoles(positions, holeIndices, outerNode, dim, areas, plane);
885
1018
  if (positions.length > 80 * dim) {
886
1019
  minX = maxX = positions[0];
887
1020
  minY = maxY = positions[1];
888
- for (let i2 = dim; i2 < outerLen; i2 += dim) {
889
- x2 = positions[i2];
890
- y2 = positions[i2 + 1];
891
- if (x2 < minX)
892
- minX = x2;
893
- if (y2 < minY)
894
- minY = y2;
895
- if (x2 > maxX)
896
- maxX = x2;
897
- if (y2 > maxY)
898
- maxY = y2;
1021
+ for (let i = dim; i < outerLen; i += dim) {
1022
+ x = positions[i];
1023
+ y = positions[i + 1];
1024
+ if (x < minX)
1025
+ minX = x;
1026
+ if (y < minY)
1027
+ minY = y;
1028
+ if (x > maxX)
1029
+ maxX = x;
1030
+ if (y > maxY)
1031
+ maxY = y;
899
1032
  }
900
1033
  invSize = Math.max(maxX - minX, maxY - minY);
901
1034
  invSize = invSize !== 0 ? 32767 / invSize : 0;
@@ -904,7 +1037,7 @@ var __exports__ = (() => {
904
1037
  return triangles;
905
1038
  }
906
1039
  function linkedList(data, start, end, dim, clockwise, area2, plane) {
907
- let i2;
1040
+ let i;
908
1041
  let last;
909
1042
  if (area2 === void 0) {
910
1043
  area2 = getPolygonSignedArea(data, {
@@ -917,11 +1050,11 @@ var __exports__ = (() => {
917
1050
  let i0 = DimIndex[plane[0]];
918
1051
  let i1 = DimIndex[plane[1]];
919
1052
  if (clockwise === area2 < 0) {
920
- for (i2 = start; i2 < end; i2 += dim)
921
- last = insertNode(i2, data[i2 + i0], data[i2 + i1], last);
1053
+ for (i = start; i < end; i += dim)
1054
+ last = insertNode(i, data[i + i0], data[i + i1], last);
922
1055
  } else {
923
- for (i2 = end - dim; i2 >= start; i2 -= dim)
924
- last = insertNode(i2, data[i2 + i0], data[i2 + i1], last);
1056
+ for (i = end - dim; i >= start; i -= dim)
1057
+ last = insertNode(i, data[i + i0], data[i + i1], last);
925
1058
  }
926
1059
  if (last && equals(last, last.next)) {
927
1060
  removeNode(last);
@@ -1085,22 +1218,22 @@ var __exports__ = (() => {
1085
1218
  }
1086
1219
  function eliminateHoles(data, holeIndices, outerNode, dim, areas, plane) {
1087
1220
  const queue = [];
1088
- let i2;
1221
+ let i;
1089
1222
  let len;
1090
1223
  let start;
1091
1224
  let end;
1092
1225
  let list;
1093
- for (i2 = 0, len = holeIndices.length; i2 < len; i2++) {
1094
- start = holeIndices[i2] * dim;
1095
- end = i2 < len - 1 ? holeIndices[i2 + 1] * dim : data.length;
1096
- list = linkedList(data, start, end, dim, false, areas && areas[i2 + 1], plane);
1226
+ for (i = 0, len = holeIndices.length; i < len; i++) {
1227
+ start = holeIndices[i] * dim;
1228
+ end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
1229
+ list = linkedList(data, start, end, dim, false, areas && areas[i + 1], plane);
1097
1230
  if (list === list.next)
1098
1231
  list.steiner = true;
1099
1232
  queue.push(getLeftmost(list));
1100
1233
  }
1101
1234
  queue.sort(compareX);
1102
- for (i2 = 0; i2 < queue.length; i2++) {
1103
- outerNode = eliminateHole(queue[i2], outerNode);
1235
+ for (i = 0; i < queue.length; i++) {
1236
+ outerNode = eliminateHole(queue[i], outerNode);
1104
1237
  }
1105
1238
  return outerNode;
1106
1239
  }
@@ -1124,11 +1257,11 @@ var __exports__ = (() => {
1124
1257
  let m;
1125
1258
  do {
1126
1259
  if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
1127
- const x2 = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
1128
- if (x2 <= hx && x2 > qx) {
1129
- qx = x2;
1260
+ const x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
1261
+ if (x <= hx && x > qx) {
1262
+ qx = x;
1130
1263
  m = p.x < p.next.x ? p : p.next;
1131
- if (x2 === hx)
1264
+ if (x === hx)
1132
1265
  return m;
1133
1266
  }
1134
1267
  }
@@ -1172,7 +1305,7 @@ var __exports__ = (() => {
1172
1305
  }
1173
1306
  function sortLinked(list) {
1174
1307
  let e;
1175
- let i2;
1308
+ let i;
1176
1309
  let inSize = 1;
1177
1310
  let numMerges;
1178
1311
  let p;
@@ -1189,7 +1322,7 @@ var __exports__ = (() => {
1189
1322
  numMerges++;
1190
1323
  q = p;
1191
1324
  pSize = 0;
1192
- for (i2 = 0; i2 < inSize; i2++) {
1325
+ for (i = 0; i < inSize; i++) {
1193
1326
  pSize++;
1194
1327
  q = q.nextZ;
1195
1328
  if (!q)
@@ -1220,18 +1353,18 @@ var __exports__ = (() => {
1220
1353
  } while (numMerges > 1);
1221
1354
  return list;
1222
1355
  }
1223
- function zOrder(x2, y2, minX, minY, invSize) {
1224
- x2 = (x2 - minX) * invSize | 0;
1225
- y2 = (y2 - minY) * invSize | 0;
1226
- x2 = (x2 | x2 << 8) & 16711935;
1227
- x2 = (x2 | x2 << 4) & 252645135;
1228
- x2 = (x2 | x2 << 2) & 858993459;
1229
- x2 = (x2 | x2 << 1) & 1431655765;
1230
- y2 = (y2 | y2 << 8) & 16711935;
1231
- y2 = (y2 | y2 << 4) & 252645135;
1232
- y2 = (y2 | y2 << 2) & 858993459;
1233
- y2 = (y2 | y2 << 1) & 1431655765;
1234
- return x2 | y2 << 1;
1356
+ function zOrder(x, y, minX, minY, invSize) {
1357
+ x = (x - minX) * invSize | 0;
1358
+ y = (y - minY) * invSize | 0;
1359
+ x = (x | x << 8) & 16711935;
1360
+ x = (x | x << 4) & 252645135;
1361
+ x = (x | x << 2) & 858993459;
1362
+ x = (x | x << 1) & 1431655765;
1363
+ y = (y | y << 8) & 16711935;
1364
+ y = (y | y << 4) & 252645135;
1365
+ y = (y | y << 2) & 858993459;
1366
+ y = (y | y << 1) & 1431655765;
1367
+ return x | y << 1;
1235
1368
  }
1236
1369
  function getLeftmost(start) {
1237
1370
  let p = start;
@@ -1317,8 +1450,8 @@ var __exports__ = (() => {
1317
1450
  b2.prev = bp;
1318
1451
  return b2;
1319
1452
  }
1320
- function insertNode(i2, x2, y2, last) {
1321
- const p = new Vertex(i2, x2, y2);
1453
+ function insertNode(i, x, y, last) {
1454
+ const p = new Vertex(i, x, y);
1322
1455
  if (!last) {
1323
1456
  p.prev = p;
1324
1457
  p.next = p;
@@ -1339,7 +1472,7 @@ var __exports__ = (() => {
1339
1472
  p.nextZ.prevZ = p.prevZ;
1340
1473
  }
1341
1474
  var Vertex = class {
1342
- constructor(i2, x2, y2) {
1475
+ constructor(i, x, y) {
1343
1476
  _defineProperty(this, "i", void 0);
1344
1477
  _defineProperty(this, "x", void 0);
1345
1478
  _defineProperty(this, "y", void 0);
@@ -1349,9 +1482,9 @@ var __exports__ = (() => {
1349
1482
  _defineProperty(this, "prevZ", null);
1350
1483
  _defineProperty(this, "nextZ", null);
1351
1484
  _defineProperty(this, "steiner", false);
1352
- this.i = i2;
1353
- this.x = x2;
1354
- this.y = y2;
1485
+ this.i = i;
1486
+ this.x = x;
1487
+ this.y = y;
1355
1488
  }
1356
1489
  };
1357
1490
 
@@ -1520,9 +1653,9 @@ var __exports__ = (() => {
1520
1653
  indexMap.linePosition,
1521
1654
  indexMap.linePosition + nPositions
1522
1655
  );
1523
- for (let i2 = 0, il = geometry.indices.length; i2 < il; ++i2) {
1524
- const start = geometry.indices[i2];
1525
- const end = i2 === il - 1 ? geometry.data.length : geometry.indices[i2 + 1];
1656
+ for (let i = 0, il = geometry.indices.length; i < il; ++i) {
1657
+ const start = geometry.indices[i];
1658
+ const end = i === il - 1 ? geometry.data.length : geometry.indices[i + 1];
1526
1659
  lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
1527
1660
  indexMap.linePosition += (end - start) / coordLength;
1528
1661
  }
@@ -1547,12 +1680,12 @@ var __exports__ = (() => {
1547
1680
  const areas = geometry.areas[l];
1548
1681
  const indices = geometry.indices[l];
1549
1682
  const nextIndices = geometry.indices[l + 1];
1550
- for (let i2 = 0, il = indices.length; i2 < il; ++i2) {
1551
- const start = indices[i2];
1552
- const end = i2 === il - 1 ? (
1683
+ for (let i = 0, il = indices.length; i < il; ++i) {
1684
+ const start = indices[i];
1685
+ const end = i === il - 1 ? (
1553
1686
  // last line, so either read to:
1554
1687
  nextIndices === void 0 ? geometry.data.length : nextIndices[0]
1555
- ) : indices[i2 + 1];
1688
+ ) : indices[i + 1];
1556
1689
  polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
1557
1690
  indexMap.polygonPosition += (end - start) / coordLength;
1558
1691
  }
@@ -1619,11 +1752,11 @@ var __exports__ = (() => {
1619
1752
  }
1620
1753
  return binaryFeatures;
1621
1754
  }
1622
- function fillNumericProperties(object, properties, index, length2) {
1755
+ function fillNumericProperties(object, properties, index, length) {
1623
1756
  for (const numericPropName in object.numericProps) {
1624
1757
  if (numericPropName in properties) {
1625
1758
  const value = properties[numericPropName];
1626
- object.numericProps[numericPropName].fill(value, index, index + length2);
1759
+ object.numericProps[numericPropName].fill(value, index, index + length);
1627
1760
  }
1628
1761
  }
1629
1762
  }
@@ -1636,320 +1769,723 @@ var __exports__ = (() => {
1636
1769
  }
1637
1770
  return props;
1638
1771
  }
1639
- function deduceArrayType(x2, constructor) {
1640
- if (constructor === Array || !Number.isFinite(x2)) {
1772
+ function deduceArrayType(x, constructor) {
1773
+ if (constructor === Array || !Number.isFinite(x)) {
1641
1774
  return Array;
1642
1775
  }
1643
- return constructor === Float64Array || Math.fround(x2) !== x2 ? Float64Array : Float32Array;
1776
+ return constructor === Float64Array || Math.fround(x) !== x ? Float64Array : Float32Array;
1644
1777
  }
1645
1778
 
1646
- // src/lib/parse-mvt.ts
1647
- var import_pbf = __toESM(require_pbf(), 1);
1779
+ // ../loader-utils/src/lib/env-utils/assert.ts
1780
+ function assert(condition, message) {
1781
+ if (!condition) {
1782
+ throw new Error(message || "loader assertion failed.");
1783
+ }
1784
+ }
1648
1785
 
1649
- // src/helpers/mapbox-util-functions.ts
1650
- function classifyRings(rings) {
1651
- const len = rings.length;
1652
- if (len <= 1)
1653
- return [rings];
1654
- const polygons = [];
1655
- let polygon;
1656
- let ccw;
1657
- for (let i2 = 0; i2 < len; i2++) {
1658
- const area2 = signedArea(rings[i2]);
1659
- if (area2 === 0)
1660
- continue;
1661
- if (ccw === void 0)
1662
- ccw = area2 < 0;
1663
- if (ccw === area2 < 0) {
1664
- if (polygon)
1665
- polygons.push(polygon);
1666
- polygon = [rings[i2]];
1667
- } else if (polygon)
1668
- polygon.push(rings[i2]);
1786
+ // ../loader-utils/src/lib/env-utils/globals.ts
1787
+ var globals = {
1788
+ self: typeof self !== "undefined" && self,
1789
+ window: typeof window !== "undefined" && window,
1790
+ global: typeof global !== "undefined" && global,
1791
+ document: typeof document !== "undefined" && document
1792
+ };
1793
+ var self_ = globals.self || globals.window || globals.global || {};
1794
+ var window_ = globals.window || globals.self || globals.global || {};
1795
+ var global_ = globals.global || globals.self || globals.window || {};
1796
+ var document_ = globals.document || {};
1797
+ var isBrowser = (
1798
+ // @ts-ignore process does not exist on browser
1799
+ Boolean(typeof process !== "object" || String(process) !== "[object process]" || process.browser)
1800
+ );
1801
+ var matches = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
1802
+ var nodeVersion = matches && parseFloat(matches[1]) || 0;
1803
+
1804
+ // ../../node_modules/@probe.gl/log/node_modules/@probe.gl/env/dist/lib/is-electron.js
1805
+ function isElectron(mockUserAgent) {
1806
+ if (typeof window !== "undefined" && typeof window.process === "object" && window.process.type === "renderer") {
1807
+ return true;
1669
1808
  }
1670
- if (polygon)
1671
- polygons.push(polygon);
1672
- return polygons;
1809
+ if (typeof process !== "undefined" && typeof process.versions === "object" && Boolean(process.versions["electron"])) {
1810
+ return true;
1811
+ }
1812
+ const realUserAgent = typeof navigator === "object" && typeof navigator.userAgent === "string" && navigator.userAgent;
1813
+ const userAgent = mockUserAgent || realUserAgent;
1814
+ if (userAgent && userAgent.indexOf("Electron") >= 0) {
1815
+ return true;
1816
+ }
1817
+ return false;
1673
1818
  }
1674
- function signedArea(ring) {
1675
- let sum = 0;
1676
- for (let i2 = 0, j = ring.length - 1, p1, p2; i2 < ring.length; j = i2++) {
1677
- p1 = ring[i2];
1678
- p2 = ring[j];
1679
- sum += (p2[0] - p1[0]) * (p1[1] + p2[1]);
1819
+
1820
+ // ../../node_modules/@probe.gl/log/node_modules/@probe.gl/env/dist/lib/is-browser.js
1821
+ function isBrowser2() {
1822
+ const isNode = typeof process === "object" && String(process) === "[object process]" && !process.browser;
1823
+ return !isNode || isElectron();
1824
+ }
1825
+
1826
+ // ../../node_modules/@probe.gl/log/node_modules/@probe.gl/env/dist/lib/globals.js
1827
+ var self_2 = globalThis.self || globalThis.window || globalThis.global;
1828
+ var window_2 = globalThis.window || globalThis.self || globalThis.global;
1829
+ var document_2 = globalThis.document || {};
1830
+ var process_ = globalThis.process || {};
1831
+ var console_ = globalThis.console;
1832
+ var navigator_ = globalThis.navigator || {};
1833
+
1834
+ // ../../node_modules/@probe.gl/log/node_modules/@probe.gl/env/dist/utils/globals.js
1835
+ var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "untranspiled source";
1836
+ var isBrowser3 = isBrowser2();
1837
+
1838
+ // ../../node_modules/@probe.gl/log/dist/utils/local-storage.js
1839
+ function getStorage(type) {
1840
+ try {
1841
+ const storage = window[type];
1842
+ const x = "__storage_test__";
1843
+ storage.setItem(x, x);
1844
+ storage.removeItem(x);
1845
+ return storage;
1846
+ } catch (e) {
1847
+ return null;
1680
1848
  }
1681
- return sum;
1682
1849
  }
1683
- function readFeature(tag, feature, pbf) {
1684
- if (feature && pbf) {
1685
- if (tag === 1)
1686
- feature.id = pbf.readVarint();
1687
- else if (tag === 2)
1688
- readTag(pbf, feature);
1689
- else if (tag === 3)
1690
- feature.type = pbf.readVarint();
1691
- else if (tag === 4)
1692
- feature._geometry = pbf.pos;
1850
+ var LocalStorage = class {
1851
+ constructor(id, defaultConfig) {
1852
+ let type = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "sessionStorage";
1853
+ _defineProperty(this, "storage", void 0);
1854
+ _defineProperty(this, "id", void 0);
1855
+ _defineProperty(this, "config", void 0);
1856
+ this.storage = getStorage(type);
1857
+ this.id = id;
1858
+ this.config = defaultConfig;
1859
+ this._loadConfiguration();
1860
+ }
1861
+ getConfiguration() {
1862
+ return this.config;
1863
+ }
1864
+ setConfiguration(configuration) {
1865
+ Object.assign(this.config, configuration);
1866
+ if (this.storage) {
1867
+ const serialized = JSON.stringify(this.config);
1868
+ this.storage.setItem(this.id, serialized);
1869
+ }
1870
+ }
1871
+ _loadConfiguration() {
1872
+ let configuration = {};
1873
+ if (this.storage) {
1874
+ const serializedConfiguration = this.storage.getItem(this.id);
1875
+ configuration = serializedConfiguration ? JSON.parse(serializedConfiguration) : {};
1876
+ }
1877
+ Object.assign(this.config, configuration);
1878
+ return this;
1879
+ }
1880
+ };
1881
+
1882
+ // ../../node_modules/@probe.gl/log/dist/utils/formatters.js
1883
+ function formatTime(ms) {
1884
+ let formatted;
1885
+ if (ms < 10) {
1886
+ formatted = "".concat(ms.toFixed(2), "ms");
1887
+ } else if (ms < 100) {
1888
+ formatted = "".concat(ms.toFixed(1), "ms");
1889
+ } else if (ms < 1e3) {
1890
+ formatted = "".concat(ms.toFixed(0), "ms");
1891
+ } else {
1892
+ formatted = "".concat((ms / 1e3).toFixed(2), "s");
1693
1893
  }
1894
+ return formatted;
1694
1895
  }
1695
- function readTag(pbf, feature) {
1696
- const end = pbf.readVarint() + pbf.pos;
1697
- while (pbf.pos < end) {
1698
- const key = feature._keys[pbf.readVarint()];
1699
- const value = feature._values[pbf.readVarint()];
1700
- feature.properties[key] = value;
1896
+ function leftPad(string) {
1897
+ let length = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 8;
1898
+ const padLength = Math.max(length - string.length, 0);
1899
+ return "".concat(" ".repeat(padLength)).concat(string);
1900
+ }
1901
+ function formatImage(image, message, scale) {
1902
+ let maxWidth = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 600;
1903
+ const imageUrl = image.src.replace(/\(/g, "%28").replace(/\)/g, "%29");
1904
+ if (image.width > maxWidth) {
1905
+ scale = Math.min(scale, maxWidth / image.width);
1701
1906
  }
1907
+ const width = image.width * scale;
1908
+ const height = image.height * scale;
1909
+ const style = ["font-size:1px;", "padding:".concat(Math.floor(height / 2), "px ").concat(Math.floor(width / 2), "px;"), "line-height:".concat(height, "px;"), "background:url(".concat(imageUrl, ");"), "background-size:".concat(width, "px ").concat(height, "px;"), "color:transparent;"].join("");
1910
+ return ["".concat(message, " %c+"), style];
1702
1911
  }
1703
1912
 
1704
- // src/lib/mapbox-vector-tile/vector-tile-feature.ts
1705
- var VectorTileFeature = class {
1706
- properties;
1707
- extent;
1708
- type;
1709
- id;
1710
- _pbf;
1711
- _geometry;
1712
- _keys;
1713
- _values;
1714
- static get types() {
1715
- return ["Unknown", "Point", "LineString", "Polygon"];
1716
- }
1717
- constructor(pbf, end, extent, keys, values) {
1718
- this.properties = {};
1719
- this.extent = extent;
1720
- this.type = 0;
1721
- this.id = null;
1722
- this._pbf = pbf;
1723
- this._geometry = -1;
1724
- this._keys = keys;
1725
- this._values = values;
1726
- pbf.readFields(readFeature, this, end);
1913
+ // ../../node_modules/@probe.gl/log/dist/utils/color.js
1914
+ var COLOR;
1915
+ (function(COLOR2) {
1916
+ COLOR2[COLOR2["BLACK"] = 30] = "BLACK";
1917
+ COLOR2[COLOR2["RED"] = 31] = "RED";
1918
+ COLOR2[COLOR2["GREEN"] = 32] = "GREEN";
1919
+ COLOR2[COLOR2["YELLOW"] = 33] = "YELLOW";
1920
+ COLOR2[COLOR2["BLUE"] = 34] = "BLUE";
1921
+ COLOR2[COLOR2["MAGENTA"] = 35] = "MAGENTA";
1922
+ COLOR2[COLOR2["CYAN"] = 36] = "CYAN";
1923
+ COLOR2[COLOR2["WHITE"] = 37] = "WHITE";
1924
+ COLOR2[COLOR2["BRIGHT_BLACK"] = 90] = "BRIGHT_BLACK";
1925
+ COLOR2[COLOR2["BRIGHT_RED"] = 91] = "BRIGHT_RED";
1926
+ COLOR2[COLOR2["BRIGHT_GREEN"] = 92] = "BRIGHT_GREEN";
1927
+ COLOR2[COLOR2["BRIGHT_YELLOW"] = 93] = "BRIGHT_YELLOW";
1928
+ COLOR2[COLOR2["BRIGHT_BLUE"] = 94] = "BRIGHT_BLUE";
1929
+ COLOR2[COLOR2["BRIGHT_MAGENTA"] = 95] = "BRIGHT_MAGENTA";
1930
+ COLOR2[COLOR2["BRIGHT_CYAN"] = 96] = "BRIGHT_CYAN";
1931
+ COLOR2[COLOR2["BRIGHT_WHITE"] = 97] = "BRIGHT_WHITE";
1932
+ })(COLOR || (COLOR = {}));
1933
+ var BACKGROUND_INCREMENT = 10;
1934
+ function getColor(color) {
1935
+ if (typeof color !== "string") {
1936
+ return color;
1937
+ }
1938
+ color = color.toUpperCase();
1939
+ return COLOR[color] || COLOR.WHITE;
1940
+ }
1941
+ function addColor(string, color, background) {
1942
+ if (!isBrowser2 && typeof string === "string") {
1943
+ if (color) {
1944
+ const colorCode = getColor(color);
1945
+ string = "\x1B[".concat(colorCode, "m").concat(string, "\x1B[39m");
1946
+ }
1947
+ if (background) {
1948
+ const colorCode = getColor(background);
1949
+ string = "\x1B[".concat(colorCode + BACKGROUND_INCREMENT, "m").concat(string, "\x1B[49m");
1950
+ }
1727
1951
  }
1728
- // eslint-disable-next-line complexity, max-statements
1729
- loadGeometry() {
1730
- const pbf = this._pbf;
1731
- pbf.pos = this._geometry;
1732
- const end = pbf.readVarint() + pbf.pos;
1733
- let cmd2 = 1;
1734
- let length2 = 0;
1735
- let x2 = 0;
1736
- let y2 = 0;
1737
- const lines = [];
1738
- let line;
1739
- while (pbf.pos < end) {
1740
- if (length2 <= 0) {
1741
- const cmdLen2 = pbf.readVarint();
1742
- cmd2 = cmdLen2 & 7;
1743
- length2 = cmdLen2 >> 3;
1744
- }
1745
- length2--;
1746
- if (cmd2 === 1 || cmd2 === 2) {
1747
- x2 += pbf.readSVarint();
1748
- y2 += pbf.readSVarint();
1749
- if (cmd2 === 1) {
1750
- if (line)
1751
- lines.push(line);
1752
- line = [];
1753
- }
1754
- if (line)
1755
- line.push([x2, y2]);
1756
- } else if (cmd2 === 7) {
1757
- if (line) {
1758
- line.push(line[0].slice());
1759
- }
1760
- } else {
1761
- throw new Error(`unknown command ${cmd2}`);
1952
+ return string;
1953
+ }
1954
+
1955
+ // ../../node_modules/@probe.gl/log/dist/utils/autobind.js
1956
+ function autobind(obj) {
1957
+ let predefined = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : ["constructor"];
1958
+ const proto = Object.getPrototypeOf(obj);
1959
+ const propNames = Object.getOwnPropertyNames(proto);
1960
+ const object = obj;
1961
+ for (const key of propNames) {
1962
+ const value = object[key];
1963
+ if (typeof value === "function") {
1964
+ if (!predefined.find((name) => key === name)) {
1965
+ object[key] = value.bind(obj);
1762
1966
  }
1763
1967
  }
1764
- if (line)
1765
- lines.push(line);
1766
- return lines;
1767
1968
  }
1768
- // eslint-disable-next-line max-statements
1769
- bbox() {
1770
- const pbf = this._pbf;
1771
- pbf.pos = this._geometry;
1772
- const end = pbf.readVarint() + pbf.pos;
1773
- let cmd2 = 1;
1774
- let length2 = 0;
1775
- let x2 = 0;
1776
- let y2 = 0;
1777
- let x1 = Infinity;
1778
- let x22 = -Infinity;
1779
- let y1 = Infinity;
1780
- let y22 = -Infinity;
1781
- while (pbf.pos < end) {
1782
- if (length2 <= 0) {
1783
- const cmdLen2 = pbf.readVarint();
1784
- cmd2 = cmdLen2 & 7;
1785
- length2 = cmdLen2 >> 3;
1786
- }
1787
- length2--;
1788
- if (cmd2 === 1 || cmd2 === 2) {
1789
- x2 += pbf.readSVarint();
1790
- y2 += pbf.readSVarint();
1791
- if (x2 < x1)
1792
- x1 = x2;
1793
- if (x2 > x22)
1794
- x22 = x2;
1795
- if (y2 < y1)
1796
- y1 = y2;
1797
- if (y2 > y22)
1798
- y22 = y2;
1799
- } else if (cmd2 !== 7) {
1800
- throw new Error(`unknown command ${cmd2}`);
1801
- }
1969
+ }
1970
+
1971
+ // ../../node_modules/@probe.gl/log/dist/utils/assert.js
1972
+ function assert2(condition, message) {
1973
+ if (!condition) {
1974
+ throw new Error(message || "Assertion failed");
1975
+ }
1976
+ }
1977
+
1978
+ // ../../node_modules/@probe.gl/log/dist/utils/hi-res-timestamp.js
1979
+ function getHiResTimestamp() {
1980
+ let timestamp;
1981
+ if (isBrowser2() && window_2.performance) {
1982
+ var _window$performance, _window$performance$n;
1983
+ timestamp = window_2 === null || window_2 === void 0 ? void 0 : (_window$performance = window_2.performance) === null || _window$performance === void 0 ? void 0 : (_window$performance$n = _window$performance.now) === null || _window$performance$n === void 0 ? void 0 : _window$performance$n.call(_window$performance);
1984
+ } else if ("hrtime" in process_) {
1985
+ var _process$hrtime;
1986
+ const timeParts = process_ === null || process_ === void 0 ? void 0 : (_process$hrtime = process_.hrtime) === null || _process$hrtime === void 0 ? void 0 : _process$hrtime.call(process_);
1987
+ timestamp = timeParts[0] * 1e3 + timeParts[1] / 1e6;
1988
+ } else {
1989
+ timestamp = Date.now();
1990
+ }
1991
+ return timestamp;
1992
+ }
1993
+
1994
+ // ../../node_modules/@probe.gl/log/dist/log.js
1995
+ var originalConsole = {
1996
+ debug: isBrowser2() ? console.debug || console.log : console.log,
1997
+ log: console.log,
1998
+ info: console.info,
1999
+ warn: console.warn,
2000
+ error: console.error
2001
+ };
2002
+ var DEFAULT_LOG_CONFIGURATION = {
2003
+ enabled: true,
2004
+ level: 0
2005
+ };
2006
+ function noop() {
2007
+ }
2008
+ var cache = {};
2009
+ var ONCE = {
2010
+ once: true
2011
+ };
2012
+ var Log = class {
2013
+ constructor() {
2014
+ let {
2015
+ id
2016
+ } = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
2017
+ id: ""
2018
+ };
2019
+ _defineProperty(this, "id", void 0);
2020
+ _defineProperty(this, "VERSION", VERSION);
2021
+ _defineProperty(this, "_startTs", getHiResTimestamp());
2022
+ _defineProperty(this, "_deltaTs", getHiResTimestamp());
2023
+ _defineProperty(this, "_storage", void 0);
2024
+ _defineProperty(this, "userData", {});
2025
+ _defineProperty(this, "LOG_THROTTLE_TIMEOUT", 0);
2026
+ this.id = id;
2027
+ this.userData = {};
2028
+ this._storage = new LocalStorage("__probe-".concat(this.id, "__"), DEFAULT_LOG_CONFIGURATION);
2029
+ this.timeStamp("".concat(this.id, " started"));
2030
+ autobind(this);
2031
+ Object.seal(this);
2032
+ }
2033
+ set level(newLevel) {
2034
+ this.setLevel(newLevel);
2035
+ }
2036
+ get level() {
2037
+ return this.getLevel();
2038
+ }
2039
+ isEnabled() {
2040
+ return this._storage.config.enabled;
2041
+ }
2042
+ getLevel() {
2043
+ return this._storage.config.level;
2044
+ }
2045
+ getTotal() {
2046
+ return Number((getHiResTimestamp() - this._startTs).toPrecision(10));
2047
+ }
2048
+ getDelta() {
2049
+ return Number((getHiResTimestamp() - this._deltaTs).toPrecision(10));
2050
+ }
2051
+ set priority(newPriority) {
2052
+ this.level = newPriority;
2053
+ }
2054
+ get priority() {
2055
+ return this.level;
2056
+ }
2057
+ getPriority() {
2058
+ return this.level;
2059
+ }
2060
+ enable() {
2061
+ let enabled = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : true;
2062
+ this._storage.setConfiguration({
2063
+ enabled
2064
+ });
2065
+ return this;
2066
+ }
2067
+ setLevel(level) {
2068
+ this._storage.setConfiguration({
2069
+ level
2070
+ });
2071
+ return this;
2072
+ }
2073
+ get(setting) {
2074
+ return this._storage.config[setting];
2075
+ }
2076
+ set(setting, value) {
2077
+ this._storage.setConfiguration({
2078
+ [setting]: value
2079
+ });
2080
+ }
2081
+ settings() {
2082
+ if (console.table) {
2083
+ console.table(this._storage.config);
2084
+ } else {
2085
+ console.log(this._storage.config);
1802
2086
  }
1803
- return [x1, y1, x22, y22];
1804
2087
  }
1805
- _toGeoJSON(transform) {
1806
- let coords = this.loadGeometry();
1807
- let type = VectorTileFeature.types[this.type];
1808
- let i2;
1809
- let j;
1810
- switch (this.type) {
1811
- case 1:
1812
- const points = [];
1813
- for (i2 = 0; i2 < coords.length; i2++) {
1814
- points[i2] = coords[i2][0];
1815
- }
1816
- coords = points;
1817
- transform(coords, this);
1818
- break;
1819
- case 2:
1820
- for (i2 = 0; i2 < coords.length; i2++) {
1821
- transform(coords[i2], this);
1822
- }
1823
- break;
1824
- case 3:
1825
- coords = classifyRings(coords);
1826
- for (i2 = 0; i2 < coords.length; i2++) {
1827
- for (j = 0; j < coords[i2].length; j++) {
1828
- transform(coords[i2][j], this);
1829
- }
1830
- }
1831
- break;
2088
+ assert(condition, message) {
2089
+ assert2(condition, message);
2090
+ }
2091
+ warn(message) {
2092
+ return this._getLogFunction(0, message, originalConsole.warn, arguments, ONCE);
2093
+ }
2094
+ error(message) {
2095
+ return this._getLogFunction(0, message, originalConsole.error, arguments);
2096
+ }
2097
+ deprecated(oldUsage, newUsage) {
2098
+ return this.warn("`".concat(oldUsage, "` is deprecated and will be removed in a later version. Use `").concat(newUsage, "` instead"));
2099
+ }
2100
+ removed(oldUsage, newUsage) {
2101
+ return this.error("`".concat(oldUsage, "` has been removed. Use `").concat(newUsage, "` instead"));
2102
+ }
2103
+ probe(logLevel, message) {
2104
+ return this._getLogFunction(logLevel, message, originalConsole.log, arguments, {
2105
+ time: true,
2106
+ once: true
2107
+ });
2108
+ }
2109
+ log(logLevel, message) {
2110
+ return this._getLogFunction(logLevel, message, originalConsole.debug, arguments);
2111
+ }
2112
+ info(logLevel, message) {
2113
+ return this._getLogFunction(logLevel, message, console.info, arguments);
2114
+ }
2115
+ once(logLevel, message) {
2116
+ return this._getLogFunction(logLevel, message, originalConsole.debug || originalConsole.info, arguments, ONCE);
2117
+ }
2118
+ table(logLevel, table, columns) {
2119
+ if (table) {
2120
+ return this._getLogFunction(logLevel, table, console.table || noop, columns && [columns], {
2121
+ tag: getTableHeader(table)
2122
+ });
1832
2123
  }
1833
- if (coords.length === 1) {
1834
- coords = coords[0];
1835
- } else {
1836
- type = `Multi${type}`;
2124
+ return noop;
2125
+ }
2126
+ image(_ref) {
2127
+ let {
2128
+ logLevel,
2129
+ priority,
2130
+ image,
2131
+ message = "",
2132
+ scale = 1
2133
+ } = _ref;
2134
+ if (!this._shouldLog(logLevel || priority)) {
2135
+ return noop;
1837
2136
  }
1838
- const result = {
1839
- type: "Feature",
1840
- geometry: {
1841
- type,
1842
- coordinates: coords
1843
- },
1844
- properties: this.properties
2137
+ return isBrowser2() ? logImageInBrowser({
2138
+ image,
2139
+ message,
2140
+ scale
2141
+ }) : logImageInNode({
2142
+ image,
2143
+ message,
2144
+ scale
2145
+ });
2146
+ }
2147
+ time(logLevel, message) {
2148
+ return this._getLogFunction(logLevel, message, console.time ? console.time : console.info);
2149
+ }
2150
+ timeEnd(logLevel, message) {
2151
+ return this._getLogFunction(logLevel, message, console.timeEnd ? console.timeEnd : console.info);
2152
+ }
2153
+ timeStamp(logLevel, message) {
2154
+ return this._getLogFunction(logLevel, message, console.timeStamp || noop);
2155
+ }
2156
+ group(logLevel, message) {
2157
+ let opts = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {
2158
+ collapsed: false
1845
2159
  };
1846
- if (this.id !== null) {
1847
- result.id = this.id;
2160
+ const options = normalizeArguments({
2161
+ logLevel,
2162
+ message,
2163
+ opts
2164
+ });
2165
+ const {
2166
+ collapsed
2167
+ } = opts;
2168
+ options.method = (collapsed ? console.groupCollapsed : console.group) || console.info;
2169
+ return this._getLogFunction(options);
2170
+ }
2171
+ groupCollapsed(logLevel, message) {
2172
+ let opts = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
2173
+ return this.group(logLevel, message, Object.assign({}, opts, {
2174
+ collapsed: true
2175
+ }));
2176
+ }
2177
+ groupEnd(logLevel) {
2178
+ return this._getLogFunction(logLevel, "", console.groupEnd || noop);
2179
+ }
2180
+ withGroup(logLevel, message, func) {
2181
+ this.group(logLevel, message)();
2182
+ try {
2183
+ func();
2184
+ } finally {
2185
+ this.groupEnd(logLevel)();
1848
2186
  }
1849
- return result;
1850
2187
  }
1851
- toGeoJSON(options) {
1852
- if (typeof options === "function") {
1853
- return this._toGeoJSON(options);
1854
- }
1855
- const { x: x2, y: y2, z } = options;
1856
- const size = this.extent * Math.pow(2, z);
1857
- const x0 = this.extent * x2;
1858
- const y0 = this.extent * y2;
1859
- function project2(line) {
1860
- for (let j = 0; j < line.length; j++) {
1861
- const p = line[j];
1862
- p[0] = (p[0] + x0) * 360 / size - 180;
1863
- const y22 = 180 - (p[1] + y0) * 360 / size;
1864
- p[1] = 360 / Math.PI * Math.atan(Math.exp(y22 * Math.PI / 180)) - 90;
2188
+ trace() {
2189
+ if (console.trace) {
2190
+ console.trace();
2191
+ }
2192
+ }
2193
+ _shouldLog(logLevel) {
2194
+ return this.isEnabled() && this.getLevel() >= normalizeLogLevel(logLevel);
2195
+ }
2196
+ _getLogFunction(logLevel, message, method, args, opts) {
2197
+ if (this._shouldLog(logLevel)) {
2198
+ opts = normalizeArguments({
2199
+ logLevel,
2200
+ message,
2201
+ args,
2202
+ opts
2203
+ });
2204
+ method = method || opts.method;
2205
+ assert2(method);
2206
+ opts.total = this.getTotal();
2207
+ opts.delta = this.getDelta();
2208
+ this._deltaTs = getHiResTimestamp();
2209
+ const tag = opts.tag || opts.message;
2210
+ if (opts.once && tag) {
2211
+ if (!cache[tag]) {
2212
+ cache[tag] = getHiResTimestamp();
2213
+ } else {
2214
+ return noop;
2215
+ }
1865
2216
  }
2217
+ message = decorateMessage(this.id, opts.message, opts);
2218
+ return method.bind(console, message, ...opts.args);
1866
2219
  }
1867
- return this._toGeoJSON(project2);
2220
+ return noop;
1868
2221
  }
1869
2222
  };
1870
-
1871
- // src/lib/mapbox-vector-tile/vector-tile-layer.ts
1872
- var VectorTileLayer = class {
1873
- version;
1874
- name;
1875
- extent;
1876
- length;
1877
- _pbf;
1878
- _keys;
1879
- _values;
1880
- _features;
1881
- constructor(pbf, end) {
1882
- this.version = 1;
1883
- this.name = "";
1884
- this.extent = 4096;
1885
- this.length = 0;
1886
- this._pbf = pbf;
1887
- this._keys = [];
1888
- this._values = [];
1889
- this._features = [];
1890
- pbf.readFields(readLayer, this, end);
1891
- this.length = this._features.length;
2223
+ _defineProperty(Log, "VERSION", VERSION);
2224
+ function normalizeLogLevel(logLevel) {
2225
+ if (!logLevel) {
2226
+ return 0;
2227
+ }
2228
+ let resolvedLevel;
2229
+ switch (typeof logLevel) {
2230
+ case "number":
2231
+ resolvedLevel = logLevel;
2232
+ break;
2233
+ case "object":
2234
+ resolvedLevel = logLevel.logLevel || logLevel.priority || 0;
2235
+ break;
2236
+ default:
2237
+ return 0;
2238
+ }
2239
+ assert2(Number.isFinite(resolvedLevel) && resolvedLevel >= 0);
2240
+ return resolvedLevel;
2241
+ }
2242
+ function normalizeArguments(opts) {
2243
+ const {
2244
+ logLevel,
2245
+ message
2246
+ } = opts;
2247
+ opts.logLevel = normalizeLogLevel(logLevel);
2248
+ const args = opts.args ? Array.from(opts.args) : [];
2249
+ while (args.length && args.shift() !== message) {
2250
+ }
2251
+ switch (typeof logLevel) {
2252
+ case "string":
2253
+ case "function":
2254
+ if (message !== void 0) {
2255
+ args.unshift(message);
2256
+ }
2257
+ opts.message = logLevel;
2258
+ break;
2259
+ case "object":
2260
+ Object.assign(opts, logLevel);
2261
+ break;
2262
+ default:
2263
+ }
2264
+ if (typeof opts.message === "function") {
2265
+ opts.message = opts.message();
2266
+ }
2267
+ const messageType = typeof opts.message;
2268
+ assert2(messageType === "string" || messageType === "object");
2269
+ return Object.assign(opts, {
2270
+ args
2271
+ }, opts.opts);
2272
+ }
2273
+ function decorateMessage(id, message, opts) {
2274
+ if (typeof message === "string") {
2275
+ const time = opts.time ? leftPad(formatTime(opts.total)) : "";
2276
+ message = opts.time ? "".concat(id, ": ").concat(time, " ").concat(message) : "".concat(id, ": ").concat(message);
2277
+ message = addColor(message, opts.color, opts.background);
2278
+ }
2279
+ return message;
2280
+ }
2281
+ function logImageInNode(_ref2) {
2282
+ let {
2283
+ image,
2284
+ message = "",
2285
+ scale = 1
2286
+ } = _ref2;
2287
+ console.warn("removed");
2288
+ return noop;
2289
+ }
2290
+ function logImageInBrowser(_ref3) {
2291
+ let {
2292
+ image,
2293
+ message = "",
2294
+ scale = 1
2295
+ } = _ref3;
2296
+ if (typeof image === "string") {
2297
+ const img = new Image();
2298
+ img.onload = () => {
2299
+ const args = formatImage(img, message, scale);
2300
+ console.log(...args);
2301
+ };
2302
+ img.src = image;
2303
+ return noop;
2304
+ }
2305
+ const element = image.nodeName || "";
2306
+ if (element.toLowerCase() === "img") {
2307
+ console.log(...formatImage(image, message, scale));
2308
+ return noop;
2309
+ }
2310
+ if (element.toLowerCase() === "canvas") {
2311
+ const img = new Image();
2312
+ img.onload = () => console.log(...formatImage(img, message, scale));
2313
+ img.src = image.toDataURL();
2314
+ return noop;
2315
+ }
2316
+ return noop;
2317
+ }
2318
+ function getTableHeader(table) {
2319
+ for (const key in table) {
2320
+ for (const title in table[key]) {
2321
+ return title || "untitled";
2322
+ }
2323
+ }
2324
+ return "empty";
2325
+ }
2326
+
2327
+ // ../../node_modules/@probe.gl/log/dist/index.js
2328
+ var dist_default = new Log({
2329
+ id: "@probe.gl/log"
2330
+ });
2331
+
2332
+ // ../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}` : "";
2335
+ function createLog() {
2336
+ const log2 = new Log({ id: "loaders.gl" });
2337
+ globalThis.loaders = globalThis.loaders || {};
2338
+ globalThis.loaders.log = log2;
2339
+ globalThis.loaders.version = version;
2340
+ globalThis.probe = globalThis.probe || {};
2341
+ globalThis.probe.loaders = log2;
2342
+ return log2;
2343
+ }
2344
+ var log = createLog();
2345
+
2346
+ // ../loader-utils/src/lib/path-utils/file-aliases.ts
2347
+ var pathPrefix = "";
2348
+ var fileAliases = {};
2349
+ function resolvePath(filename) {
2350
+ for (const alias in fileAliases) {
2351
+ if (filename.startsWith(alias)) {
2352
+ const replacement = fileAliases[alias];
2353
+ filename = filename.replace(alias, replacement);
2354
+ }
2355
+ }
2356
+ if (!filename.startsWith("http://") && !filename.startsWith("https://")) {
2357
+ filename = `${pathPrefix}${filename}`;
2358
+ }
2359
+ return filename;
2360
+ }
2361
+
2362
+ // ../loader-utils/src/lib/sources/data-source.ts
2363
+ var DataSource = class {
2364
+ /** A resolved fetch function extracted from loadOptions prop */
2365
+ fetch;
2366
+ /** The actual load options, if calling a loaders.gl loader */
2367
+ loadOptions;
2368
+ _needsRefresh = true;
2369
+ props;
2370
+ constructor(props) {
2371
+ this.props = { ...props };
2372
+ this.loadOptions = { ...props.loadOptions };
2373
+ this.fetch = getFetchFunction(this.loadOptions);
2374
+ }
2375
+ setProps(props) {
2376
+ this.props = Object.assign(this.props, props);
2377
+ this.setNeedsRefresh();
2378
+ }
2379
+ /** Mark this data source as needing a refresh (redraw) */
2380
+ setNeedsRefresh() {
2381
+ this._needsRefresh = true;
1892
2382
  }
1893
2383
  /**
1894
- * return feature `i` from this layer as a `VectorTileFeature`
1895
- * @param index
1896
- * @returns feature
2384
+ * Does this data source need refreshing?
2385
+ * @note The specifics of the refresh mechanism depends on type of data source
1897
2386
  */
1898
- feature(i2) {
1899
- if (i2 < 0 || i2 >= this._features.length) {
1900
- throw new Error("feature index out of bounds");
2387
+ getNeedsRefresh(clear = true) {
2388
+ const needsRefresh = this._needsRefresh;
2389
+ if (clear) {
2390
+ this._needsRefresh = false;
1901
2391
  }
1902
- this._pbf.pos = this._features[i2];
1903
- const end = this._pbf.readVarint() + this._pbf.pos;
1904
- return new VectorTileFeature(this._pbf, end, this.extent, this._keys, this._values);
2392
+ return needsRefresh;
1905
2393
  }
1906
2394
  };
1907
- function readLayer(tag, layer, pbf) {
1908
- if (layer && pbf) {
1909
- if (tag === 15)
1910
- layer.version = pbf.readVarint();
1911
- else if (tag === 1)
1912
- layer.name = pbf.readString();
1913
- else if (tag === 5)
1914
- layer.extent = pbf.readVarint();
1915
- else if (tag === 2)
1916
- layer._features.push(pbf.pos);
1917
- else if (tag === 3)
1918
- layer._keys.push(pbf.readString());
1919
- else if (tag === 4)
1920
- layer._values.push(readValueMessage(pbf));
2395
+ function getFetchFunction(options) {
2396
+ const fetchFunction = options?.fetch;
2397
+ if (fetchFunction && typeof fetchFunction === "function") {
2398
+ return (url, fetchOptions2) => fetchFunction(url, fetchOptions2);
1921
2399
  }
1922
- }
1923
- function readValueMessage(pbf) {
1924
- let value = null;
1925
- const end = pbf.readVarint() + pbf.pos;
1926
- while (pbf.pos < end) {
1927
- const tag = pbf.readVarint() >> 3;
1928
- value = tag === 1 ? pbf.readString() : tag === 2 ? pbf.readFloat() : tag === 3 ? pbf.readDouble() : tag === 4 ? pbf.readVarint64() : tag === 5 ? pbf.readVarint() : tag === 6 ? pbf.readSVarint() : tag === 7 ? pbf.readBoolean() : null;
2400
+ const fetchOptions = options?.fetch;
2401
+ if (fetchOptions && typeof fetchOptions !== "function") {
2402
+ return (url) => fetch(url, fetchOptions);
1929
2403
  }
1930
- return value;
2404
+ return (url) => fetch(url);
1931
2405
  }
1932
2406
 
1933
- // src/lib/mapbox-vector-tile/vector-tile.ts
1934
- var VectorTile = class {
1935
- layers;
1936
- constructor(pbf, end) {
1937
- this.layers = pbf.readFields(readTile, {}, end);
2407
+ // src/lib/parse-mvt.ts
2408
+ var import_pbf = __toESM(require_pbf(), 1);
2409
+
2410
+ // src/lib/utils/geometry-utils.ts
2411
+ function signedArea(ring) {
2412
+ let sum = 0;
2413
+ for (let i = 0, j = ring.length - 1, p1, p2; i < ring.length; j = i++) {
2414
+ p1 = ring[i];
2415
+ p2 = ring[j];
2416
+ sum += (p2[0] - p1[0]) * (p1[1] + p2[1]);
1938
2417
  }
1939
- };
1940
- function readTile(tag, layers, pbf) {
1941
- if (tag === 3) {
1942
- if (pbf) {
1943
- const layer = new VectorTileLayer(pbf, pbf.readVarint() + pbf.pos);
1944
- if (layer.length && layers) {
1945
- layers[layer.name] = layer;
1946
- }
2418
+ return sum;
2419
+ }
2420
+ function convertToLocalCoordinates(coordinates, extent) {
2421
+ if (Array.isArray(coordinates[0])) {
2422
+ for (const subcoords of coordinates) {
2423
+ convertToLocalCoordinates(subcoords, extent);
1947
2424
  }
2425
+ return;
1948
2426
  }
2427
+ const p = coordinates;
2428
+ p[0] /= extent;
2429
+ p[1] /= extent;
1949
2430
  }
1950
-
1951
- // src/helpers/binary-util-functions.ts
1952
- function classifyRings2(geom) {
2431
+ function convertToLocalCoordinatesFlat(data, extent) {
2432
+ for (let i = 0, il = data.length; i < il; ++i) {
2433
+ data[i] /= extent;
2434
+ }
2435
+ }
2436
+ function projectToLngLat(line, tileIndex, extent) {
2437
+ if (typeof line[0][0] !== "number") {
2438
+ for (const point of line) {
2439
+ projectToLngLat(point, tileIndex, extent);
2440
+ }
2441
+ return;
2442
+ }
2443
+ const size = extent * Math.pow(2, tileIndex.z);
2444
+ const x0 = extent * tileIndex.x;
2445
+ const y0 = extent * tileIndex.y;
2446
+ for (let j = 0; j < line.length; j++) {
2447
+ const p = line[j];
2448
+ p[0] = (p[0] + x0) * 360 / size - 180;
2449
+ const y2 = 180 - (p[1] + y0) * 360 / size;
2450
+ p[1] = 360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90;
2451
+ }
2452
+ }
2453
+ function projectToLngLatFlat(data, tileIndex, extent) {
2454
+ const { x, y, z } = tileIndex;
2455
+ const size = extent * Math.pow(2, z);
2456
+ const x0 = extent * x;
2457
+ const y0 = extent * y;
2458
+ for (let j = 0, jl = data.length; j < jl; j += 2) {
2459
+ data[j] = (data[j] + x0) * 360 / size - 180;
2460
+ const y2 = 180 - (data[j + 1] + y0) * 360 / size;
2461
+ data[j + 1] = 360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90;
2462
+ }
2463
+ }
2464
+ function classifyRings(rings) {
2465
+ const len = rings.length;
2466
+ if (len <= 1)
2467
+ return [rings];
2468
+ const polygons = [];
2469
+ let polygon;
2470
+ let ccw;
2471
+ for (let i = 0; i < len; i++) {
2472
+ const area2 = signedArea(rings[i]);
2473
+ if (area2 === 0)
2474
+ continue;
2475
+ if (ccw === void 0)
2476
+ ccw = area2 < 0;
2477
+ if (ccw === area2 < 0) {
2478
+ if (polygon)
2479
+ polygons.push(polygon);
2480
+ polygon = [rings[i]];
2481
+ } else if (polygon)
2482
+ polygon.push(rings[i]);
2483
+ }
2484
+ if (polygon)
2485
+ polygons.push(polygon);
2486
+ return polygons;
2487
+ }
2488
+ function classifyRingsFlat(geom) {
1953
2489
  const len = geom.indices.length;
1954
2490
  const type = "Polygon";
1955
2491
  if (len <= 1) {
@@ -1966,9 +2502,9 @@ var __exports__ = (() => {
1966
2502
  let polygon = [];
1967
2503
  let ccw;
1968
2504
  let offset = 0;
1969
- for (let endIndex, i2 = 0, startIndex; i2 < len; i2++) {
1970
- startIndex = geom.indices[i2] - offset;
1971
- endIndex = geom.indices[i2 + 1] - offset || geom.data.length;
2505
+ for (let endIndex, i = 0, startIndex; i < len; i++) {
2506
+ startIndex = geom.indices[i] - offset;
2507
+ endIndex = geom.indices[i + 1] - offset || geom.data.length;
1972
2508
  const shape = geom.data.slice(startIndex, endIndex);
1973
2509
  const area2 = getPolygonSignedArea(shape);
1974
2510
  if (area2 === 0) {
@@ -1998,43 +2534,9 @@ var __exports__ = (() => {
1998
2534
  polygons.push(polygon);
1999
2535
  return { type, areas, indices: polygons, data: geom.data };
2000
2536
  }
2001
- function project(data, x0, y0, size) {
2002
- for (let j = 0, jl = data.length; j < jl; j += 2) {
2003
- data[j] = (data[j] + x0) * 360 / size - 180;
2004
- const y2 = 180 - (data[j + 1] + y0) * 360 / size;
2005
- data[j + 1] = 360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90;
2006
- }
2007
- }
2008
- function readFeature2(tag, feature, pbf) {
2009
- if (feature && pbf) {
2010
- if (tag === 1)
2011
- feature.id = pbf.readVarint();
2012
- else if (tag === 2)
2013
- readTag2(pbf, feature);
2014
- else if (tag === 3)
2015
- feature.type = pbf.readVarint();
2016
- else if (tag === 4)
2017
- feature._geometry = pbf.pos;
2018
- }
2019
- }
2020
- function readTag2(pbf, feature) {
2021
- const end = pbf.readVarint() + pbf.pos;
2022
- while (pbf.pos < end) {
2023
- const key = feature._keys[pbf.readVarint()];
2024
- const value = feature._values[pbf.readVarint()];
2025
- feature.properties[key] = value;
2026
- }
2027
- }
2028
2537
 
2029
- // src/lib/binary-vector-tile/vector-tile-feature.ts
2030
- var endPos;
2031
- var cmd;
2032
- var cmdLen;
2033
- var length;
2034
- var x;
2035
- var y;
2036
- var i;
2037
- var BinaryVectorTileFeature = class {
2538
+ // src/lib/vector-tile/vector-tile-feature.ts
2539
+ var VectorTileFeature = class {
2038
2540
  properties;
2039
2541
  extent;
2040
2542
  type;
@@ -2055,23 +2557,55 @@ var __exports__ = (() => {
2055
2557
  this._keys = keys;
2056
2558
  this._values = values;
2057
2559
  this._geometryInfo = geometryInfo;
2058
- pbf.readFields(readFeature2, this, end);
2560
+ pbf.readFields(readFeature, this, end);
2059
2561
  }
2060
- // eslint-disable-next-line complexity, max-statements
2061
- loadGeometry() {
2562
+ toGeoJSONFeature(coordinates, tileIndex) {
2563
+ const coords = this.loadGeometry();
2564
+ switch (coordinates) {
2565
+ case "wgs84":
2566
+ return _toGeoJSONFeature(
2567
+ this,
2568
+ coords,
2569
+ (line) => projectToLngLat(line, tileIndex, this.extent)
2570
+ );
2571
+ default:
2572
+ return _toGeoJSONFeature(this, coords, convertToLocalCoordinates);
2573
+ }
2574
+ }
2575
+ /**
2576
+ *
2577
+ * @param options
2578
+ * @returns
2579
+ */
2580
+ toBinaryFeature(coordinates, tileIndex) {
2581
+ const geom = this.loadFlatGeometry();
2582
+ switch (coordinates) {
2583
+ case "wgs84":
2584
+ return this._toBinaryCoordinates(
2585
+ geom,
2586
+ (coords) => projectToLngLatFlat(coords, tileIndex, this.extent)
2587
+ );
2588
+ default:
2589
+ return this._toBinaryCoordinates(geom, convertToLocalCoordinatesFlat);
2590
+ }
2591
+ }
2592
+ /** Read a bounding box from the feature */
2593
+ // eslint-disable-next-line max-statements
2594
+ bbox() {
2062
2595
  const pbf = this._pbf;
2063
2596
  pbf.pos = this._geometry;
2064
- endPos = pbf.readVarint() + pbf.pos;
2065
- cmd = 1;
2066
- length = 0;
2067
- x = 0;
2068
- y = 0;
2069
- i = 0;
2070
- const indices = [];
2071
- const data = [];
2072
- while (pbf.pos < endPos) {
2597
+ const end = pbf.readVarint() + pbf.pos;
2598
+ let cmd = 1;
2599
+ let length = 0;
2600
+ let x = 0;
2601
+ let y = 0;
2602
+ let x1 = Infinity;
2603
+ let x2 = -Infinity;
2604
+ let y1 = Infinity;
2605
+ let y2 = -Infinity;
2606
+ while (pbf.pos < end) {
2073
2607
  if (length <= 0) {
2074
- cmdLen = pbf.readVarint();
2608
+ const cmdLen = pbf.readVarint();
2075
2609
  cmd = cmdLen & 7;
2076
2610
  length = cmdLen >> 3;
2077
2611
  }
@@ -2079,32 +2613,29 @@ var __exports__ = (() => {
2079
2613
  if (cmd === 1 || cmd === 2) {
2080
2614
  x += pbf.readSVarint();
2081
2615
  y += pbf.readSVarint();
2082
- if (cmd === 1) {
2083
- indices.push(i);
2084
- }
2085
- data.push(x, y);
2086
- i += 2;
2087
- } else if (cmd === 7) {
2088
- if (i > 0) {
2089
- const start = indices[indices.length - 1];
2090
- data.push(data[start], data[start + 1]);
2091
- i += 2;
2092
- }
2093
- } else {
2616
+ if (x < x1)
2617
+ x1 = x;
2618
+ if (x > x2)
2619
+ x2 = x;
2620
+ if (y < y1)
2621
+ y1 = y;
2622
+ if (y > y2)
2623
+ y2 = y;
2624
+ } else if (cmd !== 7) {
2094
2625
  throw new Error(`unknown command ${cmd}`);
2095
2626
  }
2096
2627
  }
2097
- return { data, indices };
2628
+ return [x1, y1, x2, y2];
2098
2629
  }
2630
+ // BINARY HELPERS
2099
2631
  /**
2100
2632
  *
2101
2633
  * @param transform
2102
2634
  * @returns result
2103
2635
  */
2104
- _toBinaryCoordinates(transform) {
2105
- const geom = this.loadGeometry();
2636
+ _toBinaryCoordinates(geom, transform) {
2106
2637
  let geometry;
2107
- transform(geom.data, this);
2638
+ transform(geom.data, this.extent);
2108
2639
  const coordLength = 2;
2109
2640
  switch (this.type) {
2110
2641
  case 1:
@@ -2119,7 +2650,7 @@ var __exports__ = (() => {
2119
2650
  geometry = { type: "LineString", ...geom };
2120
2651
  break;
2121
2652
  case 3:
2122
- geometry = classifyRings2(geom);
2653
+ geometry = classifyRingsFlat(geom);
2123
2654
  this._geometryInfo.polygonFeaturesCount++;
2124
2655
  this._geometryInfo.polygonObjectsCount += geometry.indices.length;
2125
2656
  for (const indices of geometry.indices) {
@@ -2136,20 +2667,188 @@ var __exports__ = (() => {
2136
2667
  }
2137
2668
  return result;
2138
2669
  }
2139
- toBinaryCoordinates(options) {
2140
- if (typeof options === "function") {
2141
- return this._toBinaryCoordinates(options);
2670
+ // GEOJSON HELPER
2671
+ // eslint-disable-next-line complexity, max-statements
2672
+ loadGeometry() {
2673
+ const pbf = this._pbf;
2674
+ pbf.pos = this._geometry;
2675
+ const end = pbf.readVarint() + pbf.pos;
2676
+ let cmd = 1;
2677
+ let length = 0;
2678
+ let x = 0;
2679
+ let y = 0;
2680
+ const lines = [];
2681
+ let line;
2682
+ while (pbf.pos < end) {
2683
+ if (length <= 0) {
2684
+ const cmdLen = pbf.readVarint();
2685
+ cmd = cmdLen & 7;
2686
+ length = cmdLen >> 3;
2687
+ }
2688
+ length--;
2689
+ switch (cmd) {
2690
+ case 1:
2691
+ case 2:
2692
+ x += pbf.readSVarint();
2693
+ y += pbf.readSVarint();
2694
+ if (cmd === 1) {
2695
+ if (line)
2696
+ lines.push(line);
2697
+ line = [];
2698
+ }
2699
+ if (line)
2700
+ line.push([x, y]);
2701
+ break;
2702
+ case 7:
2703
+ if (line) {
2704
+ line.push(line[0].slice());
2705
+ }
2706
+ break;
2707
+ default:
2708
+ throw new Error(`unknown command ${cmd}`);
2709
+ }
2142
2710
  }
2143
- const { x: x2, y: y2, z } = options;
2144
- const size = this.extent * Math.pow(2, z);
2145
- const x0 = this.extent * x2;
2146
- const y0 = this.extent * y2;
2147
- return this._toBinaryCoordinates((data) => project(data, x0, y0, size));
2711
+ if (line)
2712
+ lines.push(line);
2713
+ return lines;
2714
+ }
2715
+ /**
2716
+ * Expands the protobuf data to an intermediate Flat GeoJSON
2717
+ * data format, which maps closely to the binary data buffers.
2718
+ * It is similar to GeoJSON, but rather than storing the coordinates
2719
+ * in multidimensional arrays, we have a 1D `data` with all the
2720
+ * coordinates, and then index into this using the `indices`
2721
+ * parameter, e.g.
2722
+ *
2723
+ * geometry: {
2724
+ * type: 'Point', data: [1,2], indices: [0]
2725
+ * }
2726
+ * geometry: {
2727
+ * type: 'LineString', data: [1,2,3,4,...], indices: [0]
2728
+ * }
2729
+ * geometry: {
2730
+ * type: 'Polygon', data: [1,2,3,4,...], indices: [[0, 2]]
2731
+ * }
2732
+ * Thus the indices member lets us look up the relevant range
2733
+ * from the data array.
2734
+ * The Multi* versions of the above types share the same data
2735
+ * structure, just with multiple elements in the indices array
2736
+ */
2737
+ // eslint-disable-next-line complexity, max-statements
2738
+ loadFlatGeometry() {
2739
+ const pbf = this._pbf;
2740
+ pbf.pos = this._geometry;
2741
+ const endPos = pbf.readVarint() + pbf.pos;
2742
+ let cmd = 1;
2743
+ let cmdLen;
2744
+ let length = 0;
2745
+ let x = 0;
2746
+ let y = 0;
2747
+ let i = 0;
2748
+ const indices = [];
2749
+ const data = [];
2750
+ while (pbf.pos < endPos) {
2751
+ if (length <= 0) {
2752
+ cmdLen = pbf.readVarint();
2753
+ cmd = cmdLen & 7;
2754
+ length = cmdLen >> 3;
2755
+ }
2756
+ length--;
2757
+ if (cmd === 1 || cmd === 2) {
2758
+ x += pbf.readSVarint();
2759
+ y += pbf.readSVarint();
2760
+ if (cmd === 1) {
2761
+ indices.push(i);
2762
+ }
2763
+ data.push(x, y);
2764
+ i += 2;
2765
+ } else if (cmd === 7) {
2766
+ if (i > 0) {
2767
+ const start = indices[indices.length - 1];
2768
+ data.push(data[start], data[start + 1]);
2769
+ i += 2;
2770
+ }
2771
+ } else {
2772
+ throw new Error(`unknown command ${cmd}`);
2773
+ }
2774
+ }
2775
+ return { data, indices };
2148
2776
  }
2149
2777
  };
2778
+ __publicField(VectorTileFeature, "types", ["Unknown", "Point", "LineString", "Polygon"]);
2779
+ function _toGeoJSONFeature(vtFeature, coords, transform) {
2780
+ let type = VectorTileFeature.types[vtFeature.type];
2781
+ let i;
2782
+ let j;
2783
+ let coordinates;
2784
+ switch (vtFeature.type) {
2785
+ case 1:
2786
+ const points = [];
2787
+ for (i = 0; i < coords.length; i++) {
2788
+ points[i] = coords[i][0];
2789
+ }
2790
+ coordinates = points;
2791
+ transform(coordinates, vtFeature.extent);
2792
+ break;
2793
+ case 2:
2794
+ coordinates = coords;
2795
+ for (i = 0; i < coordinates.length; i++) {
2796
+ transform(coordinates[i], vtFeature.extent);
2797
+ }
2798
+ break;
2799
+ case 3:
2800
+ coordinates = classifyRings(coords);
2801
+ for (i = 0; i < coordinates.length; i++) {
2802
+ for (j = 0; j < coordinates[i].length; j++) {
2803
+ transform(coordinates[i][j], vtFeature.extent);
2804
+ }
2805
+ }
2806
+ break;
2807
+ default:
2808
+ throw new Error("illegal vector tile type");
2809
+ }
2810
+ if (coordinates.length === 1) {
2811
+ coordinates = coordinates[0];
2812
+ } else {
2813
+ type = `Multi${type}`;
2814
+ }
2815
+ const result = {
2816
+ type: "Feature",
2817
+ geometry: {
2818
+ type,
2819
+ coordinates
2820
+ },
2821
+ properties: vtFeature.properties
2822
+ };
2823
+ if (vtFeature.id !== null) {
2824
+ result.properties ||= {};
2825
+ result.properties.id = vtFeature.id;
2826
+ }
2827
+ return result;
2828
+ }
2829
+ function readFeature(tag, feature, pbf) {
2830
+ if (feature && pbf) {
2831
+ if (tag === 1)
2832
+ feature.id = pbf.readVarint();
2833
+ else if (tag === 2)
2834
+ readTag(pbf, feature);
2835
+ else if (tag === 3)
2836
+ feature.type = pbf.readVarint();
2837
+ else if (tag === 4)
2838
+ feature._geometry = pbf.pos;
2839
+ }
2840
+ }
2841
+ function readTag(pbf, feature) {
2842
+ const end = pbf.readVarint() + pbf.pos;
2843
+ while (pbf.pos < end) {
2844
+ const key = feature._keys[pbf.readVarint()];
2845
+ const value = feature._values[pbf.readVarint()];
2846
+ feature.properties[key] = value;
2847
+ }
2848
+ }
2150
2849
 
2151
- // src/lib/binary-vector-tile/vector-tile-layer.ts
2152
- var BinaryVectorTileLayer = class {
2850
+ // src/lib/vector-tile/vector-tile-layer.ts
2851
+ var VectorTileLayer = class {
2153
2852
  version;
2154
2853
  name;
2155
2854
  extent;
@@ -2167,23 +2866,36 @@ var __exports__ = (() => {
2167
2866
  this._keys = [];
2168
2867
  this._values = [];
2169
2868
  this._features = [];
2170
- pbf.readFields(readLayer2, this, end);
2869
+ pbf.readFields(readLayer, this, end);
2171
2870
  this.length = this._features.length;
2172
2871
  }
2173
2872
  /**
2174
- * return feature `i` from this layer as a `BinaryVectorTileFeature`
2873
+ * return feature `i` from this layer as a `VectorTileFeature`
2874
+ * @param index
2875
+ * @returns feature
2876
+ */
2877
+ getGeoJSONFeature(i) {
2878
+ if (i < 0 || i >= this._features.length) {
2879
+ throw new Error("feature index out of bounds");
2880
+ }
2881
+ this._pbf.pos = this._features[i];
2882
+ const end = this._pbf.readVarint() + this._pbf.pos;
2883
+ return new VectorTileFeature(this._pbf, end, this.extent, this._keys, this._values);
2884
+ }
2885
+ /**
2886
+ * return binary feature `i` from this layer as a `VectorTileFeature`
2175
2887
  *
2176
2888
  * @param index
2177
2889
  * @param geometryInfo
2178
- * @returns {BinaryVectorTileFeature}
2890
+ * @returns binary feature
2179
2891
  */
2180
- feature(i2, geometryInfo) {
2181
- if (i2 < 0 || i2 >= this._features.length) {
2892
+ getBinaryFeature(i, geometryInfo) {
2893
+ if (i < 0 || i >= this._features.length) {
2182
2894
  throw new Error("feature index out of bounds");
2183
2895
  }
2184
- this._pbf.pos = this._features[i2];
2896
+ this._pbf.pos = this._features[i];
2185
2897
  const end = this._pbf.readVarint() + this._pbf.pos;
2186
- return new BinaryVectorTileFeature(
2898
+ return new VectorTileFeature(
2187
2899
  this._pbf,
2188
2900
  end,
2189
2901
  this.extent,
@@ -2193,7 +2905,7 @@ var __exports__ = (() => {
2193
2905
  );
2194
2906
  }
2195
2907
  };
2196
- function readLayer2(tag, layer, pbf) {
2908
+ function readLayer(tag, layer, pbf) {
2197
2909
  if (layer && pbf) {
2198
2910
  if (tag === 15)
2199
2911
  layer.version = pbf.readVarint();
@@ -2206,10 +2918,10 @@ var __exports__ = (() => {
2206
2918
  else if (tag === 3)
2207
2919
  layer._keys.push(pbf.readString());
2208
2920
  else if (tag === 4)
2209
- layer._values.push(readValueMessage2(pbf));
2921
+ layer._values.push(readValueMessage(pbf));
2210
2922
  }
2211
2923
  }
2212
- function readValueMessage2(pbf) {
2924
+ function readValueMessage(pbf) {
2213
2925
  let value = null;
2214
2926
  const end = pbf.readVarint() + pbf.pos;
2215
2927
  while (pbf.pos < end) {
@@ -2219,17 +2931,17 @@ var __exports__ = (() => {
2219
2931
  return value;
2220
2932
  }
2221
2933
 
2222
- // src/lib/binary-vector-tile/vector-tile.ts
2223
- var BinaryVectorTile = class {
2934
+ // src/lib/vector-tile/vector-tile.ts
2935
+ var VectorTile = class {
2224
2936
  layers;
2225
2937
  constructor(pbf, end) {
2226
- this.layers = pbf.readFields(readTile2, {}, end);
2938
+ this.layers = pbf.readFields(readTile, {}, end);
2227
2939
  }
2228
2940
  };
2229
- function readTile2(tag, layers, pbf) {
2941
+ function readTile(tag, layers, pbf) {
2230
2942
  if (tag === 3) {
2231
2943
  if (pbf) {
2232
- const layer = new BinaryVectorTileLayer(pbf, pbf.readVarint() + pbf.pos);
2944
+ const layer = new VectorTileLayer(pbf, pbf.readVarint() + pbf.pos);
2233
2945
  if (layer.length && layers) {
2234
2946
  layers[layer.name] = layer;
2235
2947
  }
@@ -2239,7 +2951,7 @@ var __exports__ = (() => {
2239
2951
 
2240
2952
  // src/lib/parse-mvt.ts
2241
2953
  function parseMVT(arrayBuffer, options) {
2242
- const mvtOptions = normalizeOptions(options);
2954
+ const mvtOptions = checkOptions(options);
2243
2955
  const shape = options?.gis?.format || options?.mvt?.shape || options?.shape;
2244
2956
  switch (shape) {
2245
2957
  case "columnar-table":
@@ -2285,15 +2997,15 @@ var __exports__ = (() => {
2285
2997
  if (arrayBuffer.byteLength <= 0) {
2286
2998
  return [features, geometryInfo];
2287
2999
  }
2288
- const tile = new BinaryVectorTile(new import_pbf.default(arrayBuffer));
3000
+ const tile = new VectorTile(new import_pbf.default(arrayBuffer));
2289
3001
  const selectedLayers = options && Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);
2290
3002
  selectedLayers.forEach((layerName) => {
2291
3003
  const vectorTileLayer = tile.layers[layerName];
2292
3004
  if (!vectorTileLayer) {
2293
3005
  return;
2294
3006
  }
2295
- for (let i2 = 0; i2 < vectorTileLayer.length; i2++) {
2296
- const vectorTileFeature = vectorTileLayer.feature(i2, geometryInfo);
3007
+ for (let i = 0; i < vectorTileLayer.length; i++) {
3008
+ const vectorTileFeature = vectorTileLayer.getBinaryFeature(i, geometryInfo);
2297
3009
  const decodedFeature = getDecodedFeatureBinary(vectorTileFeature, options, layerName);
2298
3010
  features.push(decodedFeature);
2299
3011
  }
@@ -2312,70 +3024,54 @@ var __exports__ = (() => {
2312
3024
  if (!vectorTileLayer) {
2313
3025
  return;
2314
3026
  }
2315
- for (let i2 = 0; i2 < vectorTileLayer.length; i2++) {
2316
- const vectorTileFeature = vectorTileLayer.feature(i2);
3027
+ for (let i = 0; i < vectorTileLayer.length; i++) {
3028
+ const vectorTileFeature = vectorTileLayer.getGeoJSONFeature(i);
2317
3029
  const decodedFeature = getDecodedFeature(vectorTileFeature, options, layerName);
2318
3030
  features.push(decodedFeature);
2319
3031
  }
2320
3032
  });
2321
3033
  return features;
2322
3034
  }
2323
- function normalizeOptions(options) {
3035
+ function checkOptions(options) {
2324
3036
  if (!options?.mvt) {
2325
3037
  throw new Error("mvt options required");
2326
3038
  }
2327
- const wgs84Coordinates = options.mvt?.coordinates === "wgs84";
2328
- const { tileIndex } = options.mvt;
2329
- const hasTileIndex = tileIndex && Number.isFinite(tileIndex.x) && Number.isFinite(tileIndex.y) && Number.isFinite(tileIndex.z);
2330
- if (wgs84Coordinates && !hasTileIndex) {
3039
+ if (options.mvt?.coordinates === "wgs84" && !options.mvt.tileIndex) {
2331
3040
  throw new Error("MVT Loader: WGS84 coordinates need tileIndex property");
2332
3041
  }
3042
+ if (options.gis) {
3043
+ log.warn('MVTLoader: "options.gis" is deprecated, use "options.mvt.shape" instead')();
3044
+ }
2333
3045
  return options.mvt;
2334
3046
  }
2335
3047
  function getDecodedFeature(feature, options, layerName) {
2336
- const decodedFeature = feature.toGeoJSON(
2337
- // @ts-expect-error What is going on here?
2338
- options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinates
3048
+ const decodedFeature = feature.toGeoJSONFeature(
3049
+ options.coordinates || "local",
3050
+ options.tileIndex
2339
3051
  );
2340
3052
  if (options.layerProperty) {
3053
+ decodedFeature.properties ||= {};
2341
3054
  decodedFeature.properties[options.layerProperty] = layerName;
2342
3055
  }
2343
3056
  return decodedFeature;
2344
3057
  }
2345
3058
  function getDecodedFeatureBinary(feature, options, layerName) {
2346
- const decodedFeature = feature.toBinaryCoordinates(
2347
- // @ts-expect-error
2348
- options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinatesBinary
2349
- );
3059
+ const decodedFeature = feature.toBinaryFeature(options.coordinates || "local", options.tileIndex);
2350
3060
  if (options.layerProperty && decodedFeature.properties) {
2351
3061
  decodedFeature.properties[options.layerProperty] = layerName;
2352
3062
  }
2353
3063
  return decodedFeature;
2354
3064
  }
2355
- function transformToLocalCoordinates(line, feature) {
2356
- const { extent } = feature;
2357
- for (let i2 = 0; i2 < line.length; i2++) {
2358
- const p = line[i2];
2359
- p[0] /= extent;
2360
- p[1] /= extent;
2361
- }
2362
- }
2363
- function transformToLocalCoordinatesBinary(data, feature) {
2364
- const { extent } = feature;
2365
- for (let i2 = 0, il = data.length; i2 < il; ++i2) {
2366
- data[i2] /= extent;
2367
- }
2368
- }
2369
3065
 
2370
3066
  // src/mvt-loader.ts
2371
- var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
3067
+ var VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
2372
3068
  var MVTWorkerLoader = {
2373
3069
  dataType: null,
2374
3070
  batchType: null,
2375
3071
  name: "Mapbox Vector Tile",
2376
3072
  id: "mvt",
2377
3073
  module: "mvt",
2378
- version: VERSION,
3074
+ version: VERSION3,
2379
3075
  // Note: ArcGIS uses '.pbf' extension and 'application/octet-stream'
2380
3076
  extensions: ["mvt", "pbf"],
2381
3077
  mimeTypes: [
@@ -2392,7 +3088,7 @@ var __exports__ = (() => {
2392
3088
  coordinates: "local",
2393
3089
  layerProperty: "layerName",
2394
3090
  layers: void 0,
2395
- tileIndex: null
3091
+ tileIndex: void 0
2396
3092
  }
2397
3093
  }
2398
3094
  };
@@ -2404,7 +3100,7 @@ var __exports__ = (() => {
2404
3100
  };
2405
3101
 
2406
3102
  // src/lib/parse-tilejson.ts
2407
- var isObject = (x2) => x2 !== null && typeof x2 === "object";
3103
+ var isObject = (x) => x !== null && typeof x === "object";
2408
3104
  function parseTileJSON(jsonMetadata, options) {
2409
3105
  if (!jsonMetadata || !isObject(jsonMetadata)) {
2410
3106
  return null;
@@ -2608,14 +3304,14 @@ var __exports__ = (() => {
2608
3304
  }
2609
3305
 
2610
3306
  // src/tilejson-loader.ts
2611
- var VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
3307
+ var VERSION4 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
2612
3308
  var TileJSONLoader = {
2613
3309
  dataType: null,
2614
3310
  batchType: null,
2615
3311
  name: "TileJSON",
2616
3312
  id: "tilejson",
2617
3313
  module: "pmtiles",
2618
- version: VERSION2,
3314
+ version: VERSION4,
2619
3315
  worker: true,
2620
3316
  extensions: ["json"],
2621
3317
  mimeTypes: ["application/json"],
@@ -2638,94 +3334,8 @@ var __exports__ = (() => {
2638
3334
  }
2639
3335
  };
2640
3336
 
2641
- // ../loader-utils/src/lib/env-utils/assert.ts
2642
- function assert(condition, message) {
2643
- if (!condition) {
2644
- throw new Error(message || "loader assertion failed.");
2645
- }
2646
- }
2647
-
2648
- // ../loader-utils/src/lib/env-utils/globals.ts
2649
- var globals = {
2650
- self: typeof self !== "undefined" && self,
2651
- window: typeof window !== "undefined" && window,
2652
- global: typeof global !== "undefined" && global,
2653
- document: typeof document !== "undefined" && document
2654
- };
2655
- var self_ = globals.self || globals.window || globals.global || {};
2656
- var window_ = globals.window || globals.self || globals.global || {};
2657
- var global_ = globals.global || globals.self || globals.window || {};
2658
- var document_ = globals.document || {};
2659
- var isBrowser = (
2660
- // @ts-ignore process does not exist on browser
2661
- Boolean(typeof process !== "object" || String(process) !== "[object process]" || process.browser)
2662
- );
2663
- var matches = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
2664
- var nodeVersion = matches && parseFloat(matches[1]) || 0;
2665
-
2666
- // ../loader-utils/src/lib/path-utils/file-aliases.ts
2667
- var pathPrefix = "";
2668
- var fileAliases = {};
2669
- function resolvePath(filename) {
2670
- for (const alias in fileAliases) {
2671
- if (filename.startsWith(alias)) {
2672
- const replacement = fileAliases[alias];
2673
- filename = filename.replace(alias, replacement);
2674
- }
2675
- }
2676
- if (!filename.startsWith("http://") && !filename.startsWith("https://")) {
2677
- filename = `${pathPrefix}${filename}`;
2678
- }
2679
- return filename;
2680
- }
2681
-
2682
- // ../loader-utils/src/lib/sources/data-source.ts
2683
- var DataSource = class {
2684
- /** A resolved fetch function extracted from loadOptions prop */
2685
- fetch;
2686
- /** The actual load options, if calling a loaders.gl loader */
2687
- loadOptions;
2688
- _needsRefresh = true;
2689
- props;
2690
- constructor(props) {
2691
- this.props = { ...props };
2692
- this.loadOptions = { ...props.loadOptions };
2693
- this.fetch = getFetchFunction(this.loadOptions);
2694
- }
2695
- setProps(props) {
2696
- this.props = Object.assign(this.props, props);
2697
- this.setNeedsRefresh();
2698
- }
2699
- /** Mark this data source as needing a refresh (redraw) */
2700
- setNeedsRefresh() {
2701
- this._needsRefresh = true;
2702
- }
2703
- /**
2704
- * Does this data source need refreshing?
2705
- * @note The specifics of the refresh mechanism depends on type of data source
2706
- */
2707
- getNeedsRefresh(clear = true) {
2708
- const needsRefresh = this._needsRefresh;
2709
- if (clear) {
2710
- this._needsRefresh = false;
2711
- }
2712
- return needsRefresh;
2713
- }
2714
- };
2715
- function getFetchFunction(options) {
2716
- const fetchFunction = options?.fetch;
2717
- if (fetchFunction && typeof fetchFunction === "function") {
2718
- return (url, fetchOptions2) => fetchFunction(url, fetchOptions2);
2719
- }
2720
- const fetchOptions = options?.fetch;
2721
- if (fetchOptions && typeof fetchOptions !== "function") {
2722
- return (url) => fetch(url, fetchOptions);
2723
- }
2724
- return (url) => fetch(url);
2725
- }
2726
-
2727
3337
  // ../images/src/lib/utils/version.ts
2728
- var VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
3338
+ var VERSION5 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
2729
3339
 
2730
3340
  // ../images/src/lib/category-api/image-type.ts
2731
3341
  var parseImageNode = globalThis.loaders?.parseImageNode;
@@ -2925,8 +3535,8 @@ var __exports__ = (() => {
2925
3535
  }
2926
3536
  function checkString(buffer, header, offset = 0) {
2927
3537
  const headerBytes = stringToBytes(header);
2928
- for (let i2 = 0; i2 < headerBytes.length; ++i2) {
2929
- if (headerBytes[i2] !== buffer[i2 + offset]) {
3538
+ for (let i = 0; i < headerBytes.length; ++i) {
3539
+ if (headerBytes[i] !== buffer[i + offset]) {
2930
3540
  return false;
2931
3541
  }
2932
3542
  }
@@ -2996,30 +3606,30 @@ var __exports__ = (() => {
2996
3606
  return null;
2997
3607
  }
2998
3608
  const { tableMarkers, sofMarkers } = getJpegMarkers();
2999
- let i2 = 2;
3000
- while (i2 + 9 < dataView.byteLength) {
3001
- const marker = dataView.getUint16(i2, BIG_ENDIAN);
3609
+ let i = 2;
3610
+ while (i + 9 < dataView.byteLength) {
3611
+ const marker = dataView.getUint16(i, BIG_ENDIAN);
3002
3612
  if (sofMarkers.has(marker)) {
3003
3613
  return {
3004
3614
  mimeType: "image/jpeg",
3005
- height: dataView.getUint16(i2 + 5, BIG_ENDIAN),
3615
+ height: dataView.getUint16(i + 5, BIG_ENDIAN),
3006
3616
  // Number of lines
3007
- width: dataView.getUint16(i2 + 7, BIG_ENDIAN)
3617
+ width: dataView.getUint16(i + 7, BIG_ENDIAN)
3008
3618
  // Number of pixels per line
3009
3619
  };
3010
3620
  }
3011
3621
  if (!tableMarkers.has(marker)) {
3012
3622
  return null;
3013
3623
  }
3014
- i2 += 2;
3015
- i2 += dataView.getUint16(i2, BIG_ENDIAN);
3624
+ i += 2;
3625
+ i += dataView.getUint16(i, BIG_ENDIAN);
3016
3626
  }
3017
3627
  return null;
3018
3628
  }
3019
3629
  function getJpegMarkers() {
3020
3630
  const tableMarkers = /* @__PURE__ */ new Set([65499, 65476, 65484, 65501, 65534]);
3021
- for (let i2 = 65504; i2 < 65520; ++i2) {
3022
- tableMarkers.add(i2);
3631
+ for (let i = 65504; i < 65520; ++i) {
3632
+ tableMarkers.add(i);
3023
3633
  }
3024
3634
  const sofMarkers = /* @__PURE__ */ new Set([
3025
3635
  65472,
@@ -3123,7 +3733,7 @@ var __exports__ = (() => {
3123
3733
  id: "image",
3124
3734
  module: "images",
3125
3735
  name: "Images",
3126
- version: VERSION3,
3736
+ version: VERSION5,
3127
3737
  mimeTypes: MIME_TYPES,
3128
3738
  extensions: EXTENSIONS,
3129
3739
  parse: parseImage,
@@ -3178,9 +3788,9 @@ var __exports__ = (() => {
3178
3788
  getTileMIMEType() {
3179
3789
  return this.mimeType;
3180
3790
  }
3181
- async getTile(tileParams) {
3182
- const { x: x2, y: y2, zoom: z } = tileParams;
3183
- const tileUrl = this.getTileURL(x2, y2, z);
3791
+ async getTile(parameters) {
3792
+ const { x, y, z } = parameters;
3793
+ const tileUrl = this.getTileURL(x, y, z);
3184
3794
  const response = await this.fetch(tileUrl);
3185
3795
  if (!response.ok) {
3186
3796
  return null;
@@ -3190,9 +3800,9 @@ var __exports__ = (() => {
3190
3800
  }
3191
3801
  // Tile Source interface implementation: deck.gl compatible API
3192
3802
  // TODO - currently only handles image tiles, not vector tiles
3193
- async getTileData(tileParams) {
3194
- const { x: x2, y: y2, z } = tileParams.index;
3195
- const arrayBuffer = await this.getTile({ x: x2, y: y2, zoom: z, layers: [] });
3803
+ async getTileData(parameters) {
3804
+ const { x, y, z } = parameters.index;
3805
+ const arrayBuffer = await this.getTile({ x, y, z, layers: [] });
3196
3806
  if (arrayBuffer === null) {
3197
3807
  return null;
3198
3808
  }
@@ -3200,7 +3810,7 @@ var __exports__ = (() => {
3200
3810
  this.mimeType = this.mimeType || imageMetadata?.mimeType || "application/vnd.mapbox-vector-tile";
3201
3811
  switch (this.mimeType) {
3202
3812
  case "application/vnd.mapbox-vector-tile":
3203
- return await this._parseVectorTile(arrayBuffer, { x: x2, y: y2, zoom: z, layers: [] });
3813
+ return await this._parseVectorTile(arrayBuffer, { x, y, z, layers: [] });
3204
3814
  default:
3205
3815
  return await this._parseImageTile(arrayBuffer);
3206
3816
  }
@@ -3223,7 +3833,7 @@ var __exports__ = (() => {
3223
3833
  shape: "geojson-table",
3224
3834
  mvt: {
3225
3835
  coordinates: "wgs84",
3226
- tileIndex: { x: tileParams.x, y: tileParams.y, z: tileParams.zoom },
3836
+ tileIndex: { x: tileParams.x, y: tileParams.y, z: tileParams.z },
3227
3837
  ...this.loadOptions?.mvt
3228
3838
  },
3229
3839
  ...this.loadOptions
@@ -3233,14 +3843,14 @@ var __exports__ = (() => {
3233
3843
  getMetadataUrl() {
3234
3844
  return this.metadataUrl;
3235
3845
  }
3236
- getTileURL(x2, y2, z) {
3846
+ getTileURL(x, y, z) {
3237
3847
  switch (this.schema) {
3238
3848
  case "xyz":
3239
- return `${this.url}/${x2}/${y2}/${z}${this.extension}`;
3849
+ return `${this.url}/${x}/${y}/${z}${this.extension}`;
3240
3850
  case "tms":
3241
- return `${this.url}/${z}/${x2}/${y2}${this.extension}`;
3851
+ return `${this.url}/${z}/${x}/${y}${this.extension}`;
3242
3852
  case "template":
3243
- return getURLFromTemplate(this.url, x2, y2, z, "0");
3853
+ return getURLFromTemplate(this.url, x, y, z, "0");
3244
3854
  default:
3245
3855
  throw new Error(this.schema);
3246
3856
  }
@@ -3252,17 +3862,17 @@ var __exports__ = (() => {
3252
3862
  var xRegex = new RegExp("{x}", "g");
3253
3863
  var yRegex = new RegExp("{y}", "g");
3254
3864
  var zRegex = new RegExp("{z}", "g");
3255
- function getURLFromTemplate(template, x2, y2, z, id = "0") {
3865
+ function getURLFromTemplate(template, x, y, z, id = "0") {
3256
3866
  if (Array.isArray(template)) {
3257
- const i2 = stringHash(id) % template.length;
3258
- template = template[i2];
3867
+ const i = stringHash(id) % template.length;
3868
+ template = template[i];
3259
3869
  }
3260
3870
  let url = template;
3261
- url = url.replace(xRegex, String(x2));
3262
- url = url.replace(yRegex, String(y2));
3871
+ url = url.replace(xRegex, String(x));
3872
+ url = url.replace(yRegex, String(y));
3263
3873
  url = url.replace(zRegex, String(z));
3264
- if (Number.isInteger(y2) && Number.isInteger(z)) {
3265
- url = url.replace(/\{-y\}/g, String(Math.pow(2, z) - y2 - 1));
3874
+ if (Number.isInteger(y) && Number.isInteger(z)) {
3875
+ url = url.replace(/\{-y\}/g, String(Math.pow(2, z) - y - 1));
3266
3876
  }
3267
3877
  return url;
3268
3878
  }
@@ -3270,7 +3880,200 @@ var __exports__ = (() => {
3270
3880
  return Math.abs(s.split("").reduce((a, b) => (a << 5) - a + b.charCodeAt(0) | 0, 0));
3271
3881
  }
3272
3882
 
3273
- // src/lib/geojson-tiler/simplify.ts
3883
+ // node_modules/@probe.gl/stats/dist/utils/hi-res-timestamp.js
3884
+ function getHiResTimestamp2() {
3885
+ let timestamp;
3886
+ if (typeof window !== "undefined" && window.performance) {
3887
+ timestamp = window.performance.now();
3888
+ } else if (typeof process !== "undefined" && process.hrtime) {
3889
+ const timeParts = process.hrtime();
3890
+ timestamp = timeParts[0] * 1e3 + timeParts[1] / 1e6;
3891
+ } else {
3892
+ timestamp = Date.now();
3893
+ }
3894
+ return timestamp;
3895
+ }
3896
+
3897
+ // node_modules/@probe.gl/stats/dist/lib/stat.js
3898
+ var Stat = class {
3899
+ constructor(name, type) {
3900
+ this.sampleSize = 1;
3901
+ this.time = 0;
3902
+ this.count = 0;
3903
+ this.samples = 0;
3904
+ this.lastTiming = 0;
3905
+ this.lastSampleTime = 0;
3906
+ this.lastSampleCount = 0;
3907
+ this._count = 0;
3908
+ this._time = 0;
3909
+ this._samples = 0;
3910
+ this._startTime = 0;
3911
+ this._timerPending = false;
3912
+ this.name = name;
3913
+ this.type = type;
3914
+ this.reset();
3915
+ }
3916
+ reset() {
3917
+ this.time = 0;
3918
+ this.count = 0;
3919
+ this.samples = 0;
3920
+ this.lastTiming = 0;
3921
+ this.lastSampleTime = 0;
3922
+ this.lastSampleCount = 0;
3923
+ this._count = 0;
3924
+ this._time = 0;
3925
+ this._samples = 0;
3926
+ this._startTime = 0;
3927
+ this._timerPending = false;
3928
+ return this;
3929
+ }
3930
+ setSampleSize(samples) {
3931
+ this.sampleSize = samples;
3932
+ return this;
3933
+ }
3934
+ /** Call to increment count (+1) */
3935
+ incrementCount() {
3936
+ this.addCount(1);
3937
+ return this;
3938
+ }
3939
+ /** Call to decrement count (-1) */
3940
+ decrementCount() {
3941
+ this.subtractCount(1);
3942
+ return this;
3943
+ }
3944
+ /** Increase count */
3945
+ addCount(value) {
3946
+ this._count += value;
3947
+ this._samples++;
3948
+ this._checkSampling();
3949
+ return this;
3950
+ }
3951
+ /** Decrease count */
3952
+ subtractCount(value) {
3953
+ this._count -= value;
3954
+ this._samples++;
3955
+ this._checkSampling();
3956
+ return this;
3957
+ }
3958
+ /** Add an arbitrary timing and bump the count */
3959
+ addTime(time) {
3960
+ this._time += time;
3961
+ this.lastTiming = time;
3962
+ this._samples++;
3963
+ this._checkSampling();
3964
+ return this;
3965
+ }
3966
+ /** Start a timer */
3967
+ timeStart() {
3968
+ this._startTime = getHiResTimestamp2();
3969
+ this._timerPending = true;
3970
+ return this;
3971
+ }
3972
+ /** End a timer. Adds to time and bumps the timing count. */
3973
+ timeEnd() {
3974
+ if (!this._timerPending) {
3975
+ return this;
3976
+ }
3977
+ this.addTime(getHiResTimestamp2() - this._startTime);
3978
+ this._timerPending = false;
3979
+ this._checkSampling();
3980
+ return this;
3981
+ }
3982
+ getSampleAverageCount() {
3983
+ return this.sampleSize > 0 ? this.lastSampleCount / this.sampleSize : 0;
3984
+ }
3985
+ /** Calculate average time / count for the previous window */
3986
+ getSampleAverageTime() {
3987
+ return this.sampleSize > 0 ? this.lastSampleTime / this.sampleSize : 0;
3988
+ }
3989
+ /** Calculate counts per second for the previous window */
3990
+ getSampleHz() {
3991
+ return this.lastSampleTime > 0 ? this.sampleSize / (this.lastSampleTime / 1e3) : 0;
3992
+ }
3993
+ getAverageCount() {
3994
+ return this.samples > 0 ? this.count / this.samples : 0;
3995
+ }
3996
+ /** Calculate average time / count */
3997
+ getAverageTime() {
3998
+ return this.samples > 0 ? this.time / this.samples : 0;
3999
+ }
4000
+ /** Calculate counts per second */
4001
+ getHz() {
4002
+ return this.time > 0 ? this.samples / (this.time / 1e3) : 0;
4003
+ }
4004
+ _checkSampling() {
4005
+ if (this._samples === this.sampleSize) {
4006
+ this.lastSampleTime = this._time;
4007
+ this.lastSampleCount = this._count;
4008
+ this.count += this._count;
4009
+ this.time += this._time;
4010
+ this.samples += this._samples;
4011
+ this._time = 0;
4012
+ this._count = 0;
4013
+ this._samples = 0;
4014
+ }
4015
+ }
4016
+ };
4017
+
4018
+ // node_modules/@probe.gl/stats/dist/lib/stats.js
4019
+ var Stats = class {
4020
+ constructor(options) {
4021
+ this.stats = {};
4022
+ this.id = options.id;
4023
+ this.stats = {};
4024
+ this._initializeStats(options.stats);
4025
+ Object.seal(this);
4026
+ }
4027
+ /** Acquire a stat. Create if it doesn't exist. */
4028
+ get(name, type = "count") {
4029
+ return this._getOrCreate({ name, type });
4030
+ }
4031
+ get size() {
4032
+ return Object.keys(this.stats).length;
4033
+ }
4034
+ /** Reset all stats */
4035
+ reset() {
4036
+ for (const stat of Object.values(this.stats)) {
4037
+ stat.reset();
4038
+ }
4039
+ return this;
4040
+ }
4041
+ forEach(fn) {
4042
+ for (const stat of Object.values(this.stats)) {
4043
+ fn(stat);
4044
+ }
4045
+ }
4046
+ getTable() {
4047
+ const table = {};
4048
+ this.forEach((stat) => {
4049
+ table[stat.name] = {
4050
+ time: stat.time || 0,
4051
+ count: stat.count || 0,
4052
+ average: stat.getAverageTime() || 0,
4053
+ hz: stat.getHz() || 0
4054
+ };
4055
+ });
4056
+ return table;
4057
+ }
4058
+ _initializeStats(stats = []) {
4059
+ stats.forEach((stat) => this._getOrCreate(stat));
4060
+ }
4061
+ _getOrCreate(stat) {
4062
+ const { name, type } = stat;
4063
+ let result = this.stats[name];
4064
+ if (!result) {
4065
+ if (stat instanceof Stat) {
4066
+ result = stat;
4067
+ } else {
4068
+ result = new Stat(name, type);
4069
+ }
4070
+ this.stats[name] = result;
4071
+ }
4072
+ return result;
4073
+ }
4074
+ };
4075
+
4076
+ // src/lib/vector-tiler/simplify.ts
3274
4077
  function simplify(coords, first, last, sqTolerance) {
3275
4078
  let maxSqDist = sqTolerance;
3276
4079
  const mid = last - first >> 1;
@@ -3280,15 +4083,15 @@ var __exports__ = (() => {
3280
4083
  const ay = coords[first + 1];
3281
4084
  const bx = coords[last];
3282
4085
  const by = coords[last + 1];
3283
- for (let i2 = first + 3; i2 < last; i2 += 3) {
3284
- const d = getSqSegDist(coords[i2], coords[i2 + 1], ax, ay, bx, by);
4086
+ for (let i = first + 3; i < last; i += 3) {
4087
+ const d = getSqSegDist(coords[i], coords[i + 1], ax, ay, bx, by);
3285
4088
  if (d > maxSqDist) {
3286
- index = i2;
4089
+ index = i;
3287
4090
  maxSqDist = d;
3288
4091
  } else if (d === maxSqDist) {
3289
- const posToMid = Math.abs(i2 - mid);
4092
+ const posToMid = Math.abs(i - mid);
3290
4093
  if (posToMid < minPosToMid) {
3291
- index = i2;
4094
+ index = i;
3292
4095
  minPosToMid = posToMid;
3293
4096
  }
3294
4097
  }
@@ -3301,25 +4104,25 @@ var __exports__ = (() => {
3301
4104
  simplify(coords, index, last, sqTolerance);
3302
4105
  }
3303
4106
  }
3304
- function getSqSegDist(px, py, x2, y2, bx, by) {
3305
- let dx = bx - x2;
3306
- let dy = by - y2;
4107
+ function getSqSegDist(px, py, x, y, bx, by) {
4108
+ let dx = bx - x;
4109
+ let dy = by - y;
3307
4110
  if (dx !== 0 || dy !== 0) {
3308
- const t = ((px - x2) * dx + (py - y2) * dy) / (dx * dx + dy * dy);
4111
+ const t = ((px - x) * dx + (py - y) * dy) / (dx * dx + dy * dy);
3309
4112
  if (t > 1) {
3310
- x2 = bx;
3311
- y2 = by;
4113
+ x = bx;
4114
+ y = by;
3312
4115
  } else if (t > 0) {
3313
- x2 += dx * t;
3314
- y2 += dy * t;
4116
+ x += dx * t;
4117
+ y += dy * t;
3315
4118
  }
3316
4119
  }
3317
- dx = px - x2;
3318
- dy = py - y2;
4120
+ dx = px - x;
4121
+ dy = py - y;
3319
4122
  return dx * dx + dy * dy;
3320
4123
  }
3321
4124
 
3322
- // src/lib/geojson-tiler/feature.ts
4125
+ // src/lib/vector-tiler/feature.ts
3323
4126
  function createFeature(id, type, geom, tags) {
3324
4127
  const feature = {
3325
4128
  // eslint-disable-next-line
@@ -3348,20 +4151,20 @@ var __exports__ = (() => {
3348
4151
  return feature;
3349
4152
  }
3350
4153
  function calcLineBBox(feature, geom) {
3351
- for (let i2 = 0; i2 < geom.length; i2 += 3) {
3352
- feature.minX = Math.min(feature.minX, geom[i2]);
3353
- feature.minY = Math.min(feature.minY, geom[i2 + 1]);
3354
- feature.maxX = Math.max(feature.maxX, geom[i2]);
3355
- feature.maxY = Math.max(feature.maxY, geom[i2 + 1]);
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]);
3356
4159
  }
3357
4160
  }
3358
4161
 
3359
- // src/lib/geojson-tiler/convert.ts
4162
+ // src/lib/vector-tiler/convert.ts
3360
4163
  function convert(data, options) {
3361
4164
  const features = [];
3362
4165
  if (data.type === "FeatureCollection") {
3363
- for (let i2 = 0; i2 < data.features.length; i2++) {
3364
- convertFeature(features, data.features[i2], options, i2);
4166
+ for (let i = 0; i < data.features.length; i++) {
4167
+ convertFeature(features, data.features[i], options, i);
3365
4168
  }
3366
4169
  } else if (data.type === "Feature") {
3367
4170
  convertFeature(features, data, options);
@@ -3437,18 +4240,18 @@ var __exports__ = (() => {
3437
4240
  let x0, y0;
3438
4241
  let size = 0;
3439
4242
  for (let j = 0; j < ring.length; j++) {
3440
- const x2 = projectX(ring[j][0]);
3441
- const y2 = projectY(ring[j][1]);
3442
- out.push(x2, y2, 0);
4243
+ const x = projectX(ring[j][0]);
4244
+ const y = projectY(ring[j][1]);
4245
+ out.push(x, y, 0);
3443
4246
  if (j > 0) {
3444
4247
  if (isPolygon) {
3445
- size += (x0 * y2 - x2 * y0) / 2;
4248
+ size += (x0 * y - x * y0) / 2;
3446
4249
  } else {
3447
- size += Math.sqrt(Math.pow(x2 - x0, 2) + Math.pow(y2 - y0, 2));
4250
+ size += Math.sqrt(Math.pow(x - x0, 2) + Math.pow(y - y0, 2));
3448
4251
  }
3449
4252
  }
3450
- x0 = x2;
3451
- y0 = y2;
4253
+ x0 = x;
4254
+ y0 = y;
3452
4255
  }
3453
4256
  const last = out.length - 3;
3454
4257
  out[2] = 1;
@@ -3459,22 +4262,22 @@ var __exports__ = (() => {
3459
4262
  out.end = out.size;
3460
4263
  }
3461
4264
  function convertLines(rings, out, tolerance, isPolygon) {
3462
- for (let i2 = 0; i2 < rings.length; i2++) {
4265
+ for (let i = 0; i < rings.length; i++) {
3463
4266
  const geom = [];
3464
- convertLine(rings[i2], geom, tolerance, isPolygon);
4267
+ convertLine(rings[i], geom, tolerance, isPolygon);
3465
4268
  out.push(geom);
3466
4269
  }
3467
4270
  }
3468
- function projectX(x2) {
3469
- return x2 / 360 + 0.5;
4271
+ function projectX(x) {
4272
+ return x / 360 + 0.5;
3470
4273
  }
3471
- function projectY(y2) {
3472
- const sin = Math.sin(y2 * Math.PI / 180);
3473
- const y22 = 0.5 - 0.25 * Math.log((1 + sin) / (1 - sin)) / Math.PI;
3474
- return y22 < 0 ? 0 : y22 > 1 ? 1 : y22;
4274
+ function projectY(y) {
4275
+ const sin = Math.sin(y * Math.PI / 180);
4276
+ const y2 = 0.5 - 0.25 * Math.log((1 + sin) / (1 - sin)) / Math.PI;
4277
+ return y2 < 0 ? 0 : y2 > 1 ? 1 : y2;
3475
4278
  }
3476
4279
 
3477
- // src/lib/geojson-tiler/clip.ts
4280
+ // src/lib/vector-tiler/clip.ts
3478
4281
  function clip(features, scale, k1, k2, axis, minAll, maxAll, options) {
3479
4282
  k1 /= scale;
3480
4283
  k2 /= scale;
@@ -3537,10 +4340,10 @@ var __exports__ = (() => {
3537
4340
  return clipped.length ? clipped : null;
3538
4341
  }
3539
4342
  function clipPoints(geom, newGeom, k1, k2, axis) {
3540
- for (let i2 = 0; i2 < geom.length; i2 += 3) {
3541
- const a = geom[i2 + axis];
4343
+ for (let i = 0; i < geom.length; i += 3) {
4344
+ const a = geom[i + axis];
3542
4345
  if (a >= k1 && a <= k2) {
3543
- addPoint(newGeom, geom[i2], geom[i2 + 1], geom[i2 + 2]);
4346
+ addPoint(newGeom, geom[i], geom[i + 1], geom[i + 2]);
3544
4347
  }
3545
4348
  }
3546
4349
  }
@@ -3550,12 +4353,12 @@ var __exports__ = (() => {
3550
4353
  let len = geom.start;
3551
4354
  let segLen;
3552
4355
  let t;
3553
- for (let i2 = 0; i2 < geom.length - 3; i2 += 3) {
3554
- const ax2 = geom[i2];
3555
- const ay2 = geom[i2 + 1];
3556
- const az2 = geom[i2 + 2];
3557
- const bx = geom[i2 + 3];
3558
- const by = geom[i2 + 4];
4356
+ for (let i = 0; i < geom.length - 3; i += 3) {
4357
+ const ax2 = geom[i];
4358
+ const ay2 = geom[i + 1];
4359
+ const az2 = geom[i + 2];
4360
+ const bx = geom[i + 3];
4361
+ const by = geom[i + 4];
3559
4362
  const a2 = axis === 0 ? ax2 : ay2;
3560
4363
  const b = axis === 0 ? bx : by;
3561
4364
  let exited = false;
@@ -3625,21 +4428,21 @@ var __exports__ = (() => {
3625
4428
  clipLine(line, newGeom, k1, k2, axis, isPolygon, false);
3626
4429
  }
3627
4430
  }
3628
- function addPoint(out, x2, y2, z) {
3629
- out.push(x2, y2, z);
4431
+ function addPoint(out, x, y, z) {
4432
+ out.push(x, y, z);
3630
4433
  }
3631
- function intersectX(out, ax, ay, bx, by, x2) {
3632
- const t = (x2 - ax) / (bx - ax);
3633
- addPoint(out, x2, ay + (by - ay) * t, 1);
4434
+ function intersectX(out, ax, ay, bx, by, x) {
4435
+ const t = (x - ax) / (bx - ax);
4436
+ addPoint(out, x, ay + (by - ay) * t, 1);
3634
4437
  return t;
3635
4438
  }
3636
- function intersectY(out, ax, ay, bx, by, y2) {
3637
- const t = (y2 - ay) / (by - ay);
3638
- addPoint(out, ax + (bx - ax) * t, y2, 1);
4439
+ function intersectY(out, ax, ay, bx, by, y) {
4440
+ const t = (y - ay) / (by - ay);
4441
+ addPoint(out, ax + (bx - ax) * t, y, 1);
3639
4442
  return t;
3640
4443
  }
3641
4444
 
3642
- // src/lib/geojson-tiler/wrap.ts
4445
+ // src/lib/vector-tiler/wrap.ts
3643
4446
  function wrap(features, options) {
3644
4447
  const buffer = options.buffer / options.extent;
3645
4448
  let merged = features;
@@ -3658,8 +4461,8 @@ var __exports__ = (() => {
3658
4461
  }
3659
4462
  function shiftFeatureCoords(features, offset) {
3660
4463
  const newFeatures = [];
3661
- for (let i2 = 0; i2 < features.length; i2++) {
3662
- const feature = features[i2];
4464
+ for (let i = 0; i < features.length; i++) {
4465
+ const feature = features[i];
3663
4466
  const type = feature.type;
3664
4467
  let newGeometry;
3665
4468
  if (type === "Point" || type === "MultiPoint" || type === "LineString") {
@@ -3690,13 +4493,13 @@ var __exports__ = (() => {
3690
4493
  newPoints.start = points.start;
3691
4494
  newPoints.end = points.end;
3692
4495
  }
3693
- for (let i2 = 0; i2 < points.length; i2 += 3) {
3694
- newPoints.push(points[i2] + offset, points[i2 + 1], points[i2 + 2]);
4496
+ for (let i = 0; i < points.length; i += 3) {
4497
+ newPoints.push(points[i] + offset, points[i + 1], points[i + 2]);
3695
4498
  }
3696
4499
  return newPoints;
3697
4500
  }
3698
4501
 
3699
- // src/lib/geojson-tiler/transform.ts
4502
+ // src/lib/vector-tiler/transform.ts
3700
4503
  function transformTile(tile, extent) {
3701
4504
  if (tile.transformed) {
3702
4505
  return tile;
@@ -3725,11 +4528,11 @@ var __exports__ = (() => {
3725
4528
  tile.transformed = true;
3726
4529
  return tile;
3727
4530
  }
3728
- function transformPoint(x2, y2, extent, z2, tx, ty) {
3729
- return [Math.round(extent * (x2 * z2 - tx)), Math.round(extent * (y2 * z2 - ty))];
4531
+ function transformPoint(x, y, extent, z2, tx, ty) {
4532
+ return [Math.round(extent * (x * z2 - tx)), Math.round(extent * (y * z2 - ty))];
3730
4533
  }
3731
4534
 
3732
- // src/lib/geojson-tiler/tile.ts
4535
+ // src/lib/vector-tiler/tile.ts
3733
4536
  function createTile(features, z, tx, ty, options) {
3734
4537
  const tolerance = z === options.maxZoom ? 0 : options.tolerance / ((1 << z) * options.extent);
3735
4538
  const tile = {
@@ -3761,22 +4564,22 @@ var __exports__ = (() => {
3761
4564
  tile.maxX = Math.max(tile.maxX, feature.maxX);
3762
4565
  tile.maxY = Math.max(tile.maxY, feature.maxY);
3763
4566
  if (type === "Point" || type === "MultiPoint") {
3764
- for (let i2 = 0; i2 < geom.length; i2 += 3) {
3765
- simplified.push(geom[i2], geom[i2 + 1]);
4567
+ for (let i = 0; i < geom.length; i += 3) {
4568
+ simplified.push(geom[i], geom[i + 1]);
3766
4569
  tile.numPoints++;
3767
4570
  tile.numSimplified++;
3768
4571
  }
3769
4572
  } else if (type === "LineString") {
3770
4573
  addLine(simplified, geom, tile, tolerance, false, false);
3771
4574
  } else if (type === "MultiLineString" || type === "Polygon") {
3772
- for (let i2 = 0; i2 < geom.length; i2++) {
3773
- addLine(simplified, geom[i2], tile, tolerance, type === "Polygon", i2 === 0);
4575
+ for (let i = 0; i < geom.length; i++) {
4576
+ addLine(simplified, geom[i], tile, tolerance, type === "Polygon", i === 0);
3774
4577
  }
3775
4578
  } else if (type === "MultiPolygon") {
3776
4579
  for (let k = 0; k < geom.length; k++) {
3777
4580
  const polygon = geom[k];
3778
- for (let i2 = 0; i2 < polygon.length; i2++) {
3779
- addLine(simplified, polygon[i2], tile, tolerance, true, i2 === 0);
4581
+ for (let i = 0; i < polygon.length; i++) {
4582
+ addLine(simplified, polygon[i], tile, tolerance, true, i === 0);
3780
4583
  }
3781
4584
  }
3782
4585
  }
@@ -3807,10 +4610,10 @@ var __exports__ = (() => {
3807
4610
  return;
3808
4611
  }
3809
4612
  const ring = [];
3810
- for (let i2 = 0; i2 < geom.length; i2 += 3) {
3811
- if (tolerance === 0 || geom[i2 + 2] > sqTolerance) {
4613
+ for (let i = 0; i < geom.length; i += 3) {
4614
+ if (tolerance === 0 || geom[i + 2] > sqTolerance) {
3812
4615
  tile.numSimplified++;
3813
- ring.push(geom[i2], geom[i2 + 1]);
4616
+ ring.push(geom[i], geom[i + 1]);
3814
4617
  }
3815
4618
  tile.numPoints++;
3816
4619
  }
@@ -3820,110 +4623,147 @@ var __exports__ = (() => {
3820
4623
  }
3821
4624
  function rewind(ring, clockwise) {
3822
4625
  let area2 = 0;
3823
- for (let i2 = 0, j = ring.length - 2; i2 < ring.length; j = i2, i2 += 2) {
3824
- area2 += (ring[i2] - ring[j]) * (ring[i2 + 1] + ring[j + 1]);
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]);
3825
4628
  }
3826
4629
  if (area2 > 0 === clockwise) {
3827
- for (let i2 = 0, len = ring.length; i2 < len / 2; i2 += 2) {
3828
- const x2 = ring[i2];
3829
- const y2 = ring[i2 + 1];
3830
- ring[i2] = ring[len - 2 - i2];
3831
- ring[i2 + 1] = ring[len - 1 - i2];
3832
- ring[len - 2 - i2] = x2;
3833
- ring[len - 1 - i2] = y2;
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;
3834
4637
  }
3835
4638
  }
3836
4639
  }
3837
4640
 
3838
- // src/lib/geojson-tiler/geojson-tiler.ts
3839
- var DEFAULT_OPTIONS = {
3840
- maxZoom: 14,
3841
- // max zoom to preserve detail on
3842
- indexMaxZoom: 5,
3843
- // max zoom in the tile index
3844
- indexMaxPoints: 1e5,
3845
- // max number of points per tile in the tile index
3846
- tolerance: 3,
3847
- // simplification tolerance (higher means simpler)
3848
- extent: 4096,
3849
- // tile extent
3850
- buffer: 64,
3851
- // tile buffer on each side
3852
- lineMetrics: false,
3853
- // whether to calculate line metrics
3854
- // @ts-expect-error Ensures all these required params have defaults
3855
- promoteId: void 0,
3856
- // name of a feature property to be promoted to feature.id
3857
- generateId: false,
3858
- // whether to generate feature ids. Cannot be used with promoteId
3859
- debug: 0
3860
- // logging level (0, 1 or 2)
3861
- };
3862
- var GeoJSONTiler = class {
3863
- options;
3864
- // tiles and tileCoords are part of the public API
4641
+ // src/table-tile-source.ts
4642
+ var _TableTileSource = class {
4643
+ /** Stats for this TableTileSource */
4644
+ stats = new Stats({
4645
+ id: "table-tile-source",
4646
+ stats: [new Stat("tiles", "count"), new Stat("features", "count")]
4647
+ });
4648
+ /** MIME type of the tiles emitted by this tile source */
4649
+ mimeType = "application/vnd.mapbox-vector-tile";
4650
+ localCoordinates = true;
4651
+ /** The props that this tile source was created with */
4652
+ props;
4653
+ /* Schema of the data */
4654
+ schema = null;
4655
+ /** Map of generated tiles, indexed by stringified tile coordinates */
3865
4656
  tiles = {};
4657
+ /** Array of tile coordinates */
3866
4658
  tileCoords = [];
3867
- stats = {};
3868
- total = 0;
3869
- constructor(data, options) {
3870
- this.options = { ...DEFAULT_OPTIONS, ...options };
3871
- options = this.options;
3872
- const debug = options.debug;
3873
- if (debug)
3874
- console.time("preprocess data");
3875
- if (this.options.maxZoom < 0 || this.options.maxZoom > 24) {
4659
+ /** Input data has loaded, initial top-level tiling is done, sync methods can now be called */
4660
+ ready;
4661
+ /** Metadata for the tile source (generated TileJSON/tilestats */
4662
+ metadata;
4663
+ constructor(table, props) {
4664
+ this.props = { ..._TableTileSource.defaultProps, ...props };
4665
+ this.getTileData = this.getTileData.bind(this);
4666
+ this.ready = this.initializeTilesAsync(table);
4667
+ this.metadata = this.getMetadata();
4668
+ }
4669
+ async initializeTilesAsync(tablePromise) {
4670
+ const table = await tablePromise;
4671
+ this.schema = deduceTableSchema(table);
4672
+ this.createRootTiles(table);
4673
+ }
4674
+ async getMetadata() {
4675
+ await this.ready;
4676
+ return { schema: this.schema, minZoom: 0, maxZoom: this.props.maxZoom };
4677
+ }
4678
+ async getSchema() {
4679
+ await this.ready;
4680
+ return this.schema;
4681
+ }
4682
+ /**
4683
+ * Get a tile at the specified index
4684
+ * @param tileIndex z, x, y of tile
4685
+ * @returns
4686
+ */
4687
+ async getVectorTile(tileIndex) {
4688
+ await this.ready;
4689
+ const table = this.getTileSync(tileIndex);
4690
+ log.info(2, "getVectorTile", tileIndex, table)();
4691
+ return table;
4692
+ }
4693
+ async getTile(tileIndex) {
4694
+ await this.ready;
4695
+ return this.getTileSync(tileIndex);
4696
+ }
4697
+ async getTileData(tileParams) {
4698
+ const { x, y, z } = tileParams.index;
4699
+ const tile = await this.getVectorTile({ x, y, z });
4700
+ return tile?.features || [];
4701
+ }
4702
+ // Implementation
4703
+ /**
4704
+ * Synchronously request a tile
4705
+ * @note Application must await `source.ready` before calling sync methods.
4706
+ */
4707
+ getTileSync(tileIndex) {
4708
+ const rawTile = this.getRawTile(tileIndex);
4709
+ if (!rawTile) {
4710
+ return null;
4711
+ }
4712
+ return convertToGeoJSONTable(rawTile, {
4713
+ coordinates: this.props.coordinates,
4714
+ tileIndex,
4715
+ extent: this.props.extent
4716
+ });
4717
+ }
4718
+ /**
4719
+ * Create the initial tiles
4720
+ * @note the tiles stores all the features together with additional data
4721
+ */
4722
+ createRootTiles(table) {
4723
+ if (this.props.maxZoom < 0 || this.props.maxZoom > 24) {
3876
4724
  throw new Error("maxZoom should be in the 0-24 range");
3877
4725
  }
3878
- if (options.promoteId && this.options.generateId) {
4726
+ if (this.props.promoteId && this.props.generateId) {
3879
4727
  throw new Error("promoteId and generateId cannot be used together.");
3880
4728
  }
3881
- let features = convert(data, options);
3882
- if (debug) {
3883
- console.timeEnd("preprocess data");
3884
- console.log(
3885
- "index: maxZoom: %d, maxPoints: %d",
3886
- options.indexMaxZoom,
3887
- options.indexMaxPoints
3888
- );
3889
- console.time("generate tiles");
3890
- }
3891
- features = wrap(features, this.options);
3892
- if (features.length) {
3893
- this.splitTile(features, 0, 0, 0);
3894
- }
3895
- if (debug) {
3896
- if (features.length) {
3897
- console.log("features: %d, points: %d", this.tiles[0].numFeatures, this.tiles[0].numPoints);
3898
- }
3899
- console.timeEnd("generate tiles");
3900
- console.log("tiles generated:", this.total, JSON.stringify(this.stats));
4729
+ log.log(1, "TableTileSource creating root tiles", this.props)();
4730
+ log.time(1, "preprocess table")();
4731
+ let features = convert(table, this.props);
4732
+ log.timeEnd(1, "preprocess table")();
4733
+ log.time(1, "generate tiles")();
4734
+ features = wrap(features, this.props);
4735
+ if (features.length === 0) {
4736
+ log.log(1, "TableTileSource: no features generated")();
4737
+ return;
3901
4738
  }
4739
+ this.splitTile(features, 0, 0, 0);
4740
+ const rootTile = this.tiles[0];
4741
+ log.log(1, `root tile features: ${rootTile.numFeatures}, points: ${rootTile.numPoints}`)();
4742
+ log.timeEnd(1, "generate tiles")();
4743
+ log.log(1, `TableTileSource: tiles generated: ${this.stats.get("total").count}`, this.stats)();
3902
4744
  }
3903
4745
  /**
3904
- * Get a tile at the specified index
3905
- * @param z
3906
- * @param x
3907
- * @param y
3908
- * @returns
4746
+ * Return geojsonvt-style "half formed" vector tile
4747
+ * @note Application must await `source.ready` before calling sync methods.
3909
4748
  */
3910
4749
  // eslint-disable-next-line complexity, max-statements
3911
- getTile(z, x2, y2) {
3912
- const { extent, debug } = this.options;
4750
+ getRawTile(tileIndex) {
4751
+ const { z, y } = tileIndex;
4752
+ let { x } = tileIndex;
4753
+ const { extent } = this.props;
3913
4754
  if (z < 0 || z > 24) {
3914
4755
  return null;
3915
4756
  }
3916
4757
  const z2 = 1 << z;
3917
- x2 = x2 + z2 & z2 - 1;
3918
- const id = toID(z, x2, y2);
4758
+ x = x + z2 & z2 - 1;
4759
+ const id = toID(z, x, y);
3919
4760
  if (this.tiles[id]) {
3920
4761
  return transformTile(this.tiles[id], extent);
3921
4762
  }
3922
- if (debug > 1)
3923
- console.log("drilling down to z%d-%d-%d", z, x2, y2);
4763
+ log.log(log, "drilling down to z%d-%d-%d", z, x, y)();
3924
4764
  let z0 = z;
3925
- let x0 = x2;
3926
- let y0 = y2;
4765
+ let x0 = x;
4766
+ let y0 = y;
3927
4767
  let parent;
3928
4768
  while (!parent && z0 > 0) {
3929
4769
  z0--;
@@ -3934,14 +4774,10 @@ var __exports__ = (() => {
3934
4774
  if (!parent || !parent.source) {
3935
4775
  return null;
3936
4776
  }
3937
- if (debug > 1) {
3938
- console.log("found parent tile z%d-%d-%d", z0, x0, y0);
3939
- console.time("drilling down");
3940
- }
3941
- this.splitTile(parent.source, z0, x0, y0, z, x2, y2);
3942
- if (debug > 1) {
3943
- console.timeEnd("drilling down");
3944
- }
4777
+ log.log(1, "found parent tile z%d-%d-%d", z0, x0, y0)();
4778
+ log.time(1, "drilling down")();
4779
+ this.splitTile(parent.source, z0, x0, y0, z, x, y);
4780
+ log.timeEnd(1, "drilling down")();
3945
4781
  return this.tiles[id] ? transformTile(this.tiles[id], extent) : null;
3946
4782
  }
3947
4783
  /**
@@ -3950,62 +4786,62 @@ var __exports__ = (() => {
3950
4786
  * @param cz, cx, and cy are the coordinates of the target tile
3951
4787
  *
3952
4788
  * If no target tile is specified, splitting stops when we reach the maximum
3953
- * zoom or the number of points is low as specified in the options.
4789
+ * zoom or the number of points is low as specified in the props.
3954
4790
  */
3955
4791
  // eslint-disable-next-line max-params, max-statements, complexity
3956
- splitTile(features, z, x2, y2, cz, cx, cy) {
3957
- const stack = [features, z, x2, y2];
3958
- const options = this.options;
3959
- const debug = options.debug;
4792
+ splitTile(features, z, x, y, cz, cx, cy) {
4793
+ const stack = [features, z, x, y];
3960
4794
  while (stack.length) {
3961
- y2 = stack.pop();
3962
- x2 = stack.pop();
4795
+ y = stack.pop();
4796
+ x = stack.pop();
3963
4797
  z = stack.pop();
3964
4798
  features = stack.pop();
3965
4799
  const z2 = 1 << z;
3966
- const id = toID(z, x2, y2);
4800
+ const id = toID(z, x, y);
3967
4801
  let tile = this.tiles[id];
3968
4802
  if (!tile) {
3969
- if (debug > 1) {
3970
- console.time("creation");
3971
- }
3972
- tile = this.tiles[id] = createTile(features, z, x2, y2, options);
3973
- this.tileCoords.push({ z, x: x2, y: y2 });
3974
- if (debug) {
3975
- if (debug > 1) {
3976
- console.log(
3977
- "tile z%d-%d-%d (features: %d, points: %d, simplified: %d)",
3978
- z,
3979
- x2,
3980
- y2,
3981
- tile.numFeatures,
3982
- tile.numPoints,
3983
- tile.numSimplified
3984
- );
3985
- console.timeEnd("creation");
3986
- }
3987
- const key = `z${z}`;
3988
- this.stats[key] = (this.stats[key] || 0) + 1;
3989
- this.total++;
3990
- }
4803
+ log.time(2, "tile creation")();
4804
+ tile = this.tiles[id] = createTile(features, z, x, y, this.props);
4805
+ this.tileCoords.push({ z, x, y });
4806
+ const key = `z${z}`;
4807
+ let stat = this.stats.get(key, "count");
4808
+ stat.incrementCount();
4809
+ stat = this.stats.get("total");
4810
+ stat.incrementCount();
4811
+ stat = _TableTileSource.stats.get(key, "count");
4812
+ stat.incrementCount();
4813
+ stat = _TableTileSource.stats.get("total");
4814
+ stat.incrementCount();
4815
+ log.log(
4816
+ 2,
4817
+ "tile z%d-%d-%d (features: %d, points: %d, simplified: %d)",
4818
+ z,
4819
+ x,
4820
+ y,
4821
+ tile.numFeatures,
4822
+ tile.numPoints,
4823
+ tile.numSimplified
4824
+ )();
4825
+ log.timeEnd(2, "tile creation")();
3991
4826
  }
3992
4827
  tile.source = features;
3993
4828
  if (cz === void 0) {
3994
- if (z === options.indexMaxZoom || tile.numPoints <= options.indexMaxPoints)
4829
+ if (z === this.props.indexMaxZoom || tile.numPoints <= this.props.maxPointsPerTile) {
3995
4830
  continue;
3996
- } else if (z === options.maxZoom || z === cz) {
4831
+ }
4832
+ } else if (z === this.props.maxZoom || z === cz) {
3997
4833
  continue;
3998
4834
  } else if (cz !== void 0) {
3999
4835
  const zoomSteps = cz - z;
4000
- if (x2 !== cx >> zoomSteps || y2 !== cy >> zoomSteps)
4836
+ if (x !== cx >> zoomSteps || y !== cy >> zoomSteps) {
4001
4837
  continue;
4838
+ }
4002
4839
  }
4003
4840
  tile.source = null;
4004
4841
  if (features.length === 0)
4005
4842
  continue;
4006
- if (debug > 1)
4007
- console.time("clipping");
4008
- const k1 = 0.5 * options.buffer / options.extent;
4843
+ log.time(2, "clipping tile")();
4844
+ const k1 = 0.5 * this.props.buffer / this.props.extent;
4009
4845
  const k2 = 0.5 - k1;
4010
4846
  const k3 = 0.5 + k1;
4011
4847
  const k4 = 1 + k1;
@@ -4013,30 +4849,131 @@ var __exports__ = (() => {
4013
4849
  let bl = null;
4014
4850
  let tr = null;
4015
4851
  let br = null;
4016
- let left = clip(features, z2, x2 - k1, x2 + k3, 0, tile.minX, tile.maxX, options);
4017
- let right = clip(features, z2, x2 + k2, x2 + k4, 0, tile.minX, tile.maxX, options);
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);
4018
4854
  features = null;
4019
4855
  if (left) {
4020
- tl = clip(left, z2, y2 - k1, y2 + k3, 1, tile.minY, tile.maxY, options);
4021
- bl = clip(left, z2, y2 + k2, y2 + k4, 1, tile.minY, tile.maxY, options);
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);
4022
4858
  left = null;
4023
4859
  }
4024
4860
  if (right) {
4025
- tr = clip(right, z2, y2 - k1, y2 + k3, 1, tile.minY, tile.maxY, options);
4026
- br = clip(right, z2, y2 + k2, y2 + k4, 1, tile.minY, tile.maxY, options);
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);
4027
4863
  right = null;
4028
4864
  }
4029
- if (debug > 1)
4030
- console.timeEnd("clipping");
4031
- stack.push(tl || [], z + 1, x2 * 2, y2 * 2);
4032
- stack.push(bl || [], z + 1, x2 * 2, y2 * 2 + 1);
4033
- stack.push(tr || [], z + 1, x2 * 2 + 1, y2 * 2);
4034
- stack.push(br || [], z + 1, x2 * 2 + 1, y2 * 2 + 1);
4865
+ log.timeEnd(2, "clipping tile")();
4866
+ stack.push(tl || [], z + 1, x * 2, y * 2);
4867
+ stack.push(bl || [], z + 1, x * 2, y * 2 + 1);
4868
+ stack.push(tr || [], z + 1, x * 2 + 1, y * 2);
4869
+ stack.push(br || [], z + 1, x * 2 + 1, y * 2 + 1);
4035
4870
  }
4036
4871
  }
4037
4872
  };
4038
- function toID(z, x2, y2) {
4039
- return ((1 << z) * y2 + x2) * 32 + z;
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({
4901
+ id: "table-tile-source-all",
4902
+ stats: [new Stat("count", "tiles"), new Stat("count", "features")]
4903
+ }));
4904
+ function toID(z, x, y) {
4905
+ return ((1 << z) * y + x) * 32 + z;
4906
+ }
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;
4040
4977
  }
4041
4978
  return __toCommonJS(bundle_exports);
4042
4979
  })();