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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/dist/dist.dev.js +1311 -767
  2. package/dist/dist.min.js +1 -1
  3. package/dist/geojson-tile-source.d.ts +79 -0
  4. package/dist/geojson-tile-source.d.ts.map +1 -0
  5. package/dist/{lib/geojson-tiler/geojson-tiler.js → geojson-tile-source.js} +137 -27
  6. package/dist/index.cjs +570 -560
  7. package/dist/index.cjs.map +4 -4
  8. package/dist/index.d.ts +2 -2
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +1 -1
  11. package/dist/lib/geojsonvt/clip.d.ts.map +1 -0
  12. package/dist/lib/geojsonvt/convert.d.ts +10 -0
  13. package/dist/lib/geojsonvt/convert.d.ts.map +1 -0
  14. package/dist/lib/geojsonvt/feature.d.ts.map +1 -0
  15. package/dist/lib/geojsonvt/simplify.d.ts.map +1 -0
  16. package/dist/lib/geojsonvt/tile.d.ts.map +1 -0
  17. package/dist/lib/geojsonvt/transform.d.ts.map +1 -0
  18. package/dist/lib/geojsonvt/wrap.d.ts.map +1 -0
  19. package/dist/lib/parse-mvt.d.ts +3 -2
  20. package/dist/lib/parse-mvt.d.ts.map +1 -1
  21. package/dist/lib/parse-mvt.js +13 -15
  22. package/dist/lib/types.d.ts +1 -39
  23. package/dist/lib/types.d.ts.map +1 -1
  24. package/dist/lib/utils/geometry-utils.d.ts +46 -0
  25. package/dist/lib/utils/geometry-utils.d.ts.map +1 -0
  26. package/dist/{helpers/binary-util-functions.js → lib/utils/geometry-utils.js} +79 -46
  27. package/dist/lib/{binary-vector-tile → vector-tile}/vector-tile-feature.d.ts +27 -15
  28. package/dist/lib/vector-tile/vector-tile-feature.d.ts.map +1 -0
  29. package/dist/lib/vector-tile/vector-tile-feature.js +345 -0
  30. package/dist/lib/{mapbox-vector-tile → vector-tile}/vector-tile-layer.d.ts +10 -1
  31. package/dist/lib/vector-tile/vector-tile-layer.d.ts.map +1 -0
  32. package/dist/lib/{mapbox-vector-tile → vector-tile}/vector-tile-layer.js +16 -1
  33. package/dist/lib/vector-tile/vector-tile.d.ts.map +1 -0
  34. package/dist/mvt-loader.d.ts +20 -9
  35. package/dist/mvt-loader.d.ts.map +1 -1
  36. package/dist/mvt-loader.js +3 -2
  37. package/dist/mvt-source.js +4 -4
  38. package/dist/mvt-worker.js +1172 -735
  39. package/dist/tilejson-loader.js +1 -1
  40. package/package.json +6 -6
  41. package/src/{lib/geojson-tiler/geojson-tiler.ts → geojson-tile-source.ts} +172 -33
  42. package/src/index.ts +3 -3
  43. package/src/lib/{geojson-tiler → geojsonvt}/convert.ts +2 -2
  44. package/src/lib/{geojson-tiler → geojsonvt}/tile.ts +2 -2
  45. package/src/lib/parse-mvt.ts +24 -33
  46. package/src/lib/types.ts +1 -39
  47. package/src/{helpers/binary-util-functions.ts → lib/utils/geometry-utils.ts} +92 -48
  48. package/src/lib/vector-tile/vector-tile-feature.ts +407 -0
  49. package/src/lib/{mapbox-vector-tile → vector-tile}/vector-tile-layer.ts +28 -2
  50. package/src/mvt-loader.ts +14 -6
  51. package/src/mvt-source.ts +4 -4
  52. package/dist/helpers/binary-util-functions.d.ts +0 -35
  53. package/dist/helpers/binary-util-functions.d.ts.map +0 -1
  54. package/dist/helpers/mapbox-util-functions.d.ts +0 -29
  55. package/dist/helpers/mapbox-util-functions.d.ts.map +0 -1
  56. package/dist/helpers/mapbox-util-functions.js +0 -78
  57. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +0 -1
  58. package/dist/lib/binary-vector-tile/vector-tile-feature.js +0 -163
  59. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts +0 -23
  60. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts.map +0 -1
  61. package/dist/lib/binary-vector-tile/vector-tile-layer.js +0 -96
  62. package/dist/lib/binary-vector-tile/vector-tile.d.ts +0 -9
  63. package/dist/lib/binary-vector-tile/vector-tile.d.ts.map +0 -1
  64. package/dist/lib/binary-vector-tile/vector-tile.js +0 -27
  65. package/dist/lib/geojson-tiler/clip.d.ts.map +0 -1
  66. package/dist/lib/geojson-tiler/convert.d.ts +0 -10
  67. package/dist/lib/geojson-tiler/convert.d.ts.map +0 -1
  68. package/dist/lib/geojson-tiler/feature.d.ts.map +0 -1
  69. package/dist/lib/geojson-tiler/geojson-tiler.d.ts +0 -44
  70. package/dist/lib/geojson-tiler/geojson-tiler.d.ts.map +0 -1
  71. package/dist/lib/geojson-tiler/simplify.d.ts.map +0 -1
  72. package/dist/lib/geojson-tiler/tile.d.ts.map +0 -1
  73. package/dist/lib/geojson-tiler/transform.d.ts.map +0 -1
  74. package/dist/lib/geojson-tiler/wrap.d.ts.map +0 -1
  75. package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts +0 -27
  76. package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts.map +0 -1
  77. package/dist/lib/mapbox-vector-tile/vector-tile-feature.js +0 -178
  78. package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts.map +0 -1
  79. package/dist/lib/mapbox-vector-tile/vector-tile.d.ts.map +0 -1
  80. package/src/helpers/mapbox-util-functions.ts +0 -82
  81. package/src/lib/binary-vector-tile/vector-tile-feature.ts +0 -203
  82. package/src/lib/binary-vector-tile/vector-tile-layer.ts +0 -113
  83. package/src/lib/binary-vector-tile/vector-tile.ts +0 -36
  84. package/src/lib/mapbox-vector-tile/LICENSE.txt +0 -31
  85. package/src/lib/mapbox-vector-tile/vector-tile-feature.ts +0 -207
  86. /package/dist/lib/{geojson-tiler → geojsonvt}/clip.d.ts +0 -0
  87. /package/dist/lib/{geojson-tiler → geojsonvt}/clip.js +0 -0
  88. /package/dist/lib/{geojson-tiler → geojsonvt}/convert.js +0 -0
  89. /package/dist/lib/{geojson-tiler → geojsonvt}/feature.d.ts +0 -0
  90. /package/dist/lib/{geojson-tiler → geojsonvt}/feature.js +0 -0
  91. /package/dist/lib/{geojson-tiler → geojsonvt}/simplify.d.ts +0 -0
  92. /package/dist/lib/{geojson-tiler → geojsonvt}/simplify.js +0 -0
  93. /package/dist/lib/{geojson-tiler → geojsonvt}/tile.d.ts +0 -0
  94. /package/dist/lib/{geojson-tiler → geojsonvt}/tile.js +0 -0
  95. /package/dist/lib/{geojson-tiler → geojsonvt}/transform.d.ts +0 -0
  96. /package/dist/lib/{geojson-tiler → geojsonvt}/transform.js +0 -0
  97. /package/dist/lib/{geojson-tiler → geojsonvt}/wrap.d.ts +0 -0
  98. /package/dist/lib/{geojson-tiler → geojsonvt}/wrap.js +0 -0
  99. /package/dist/lib/{mapbox-vector-tile → vector-tile}/vector-tile.d.ts +0 -0
  100. /package/dist/lib/{mapbox-vector-tile → vector-tile}/vector-tile.js +0 -0
  101. /package/src/lib/{geojson-tiler → geojsonvt}/LICENSE +0 -0
  102. /package/src/lib/{geojson-tiler → geojsonvt}/clip.ts +0 -0
  103. /package/src/lib/{geojson-tiler → geojsonvt}/feature.ts +0 -0
  104. /package/src/lib/{geojson-tiler → geojsonvt}/simplify.ts +0 -0
  105. /package/src/lib/{geojson-tiler → geojsonvt}/transform.ts +0 -0
  106. /package/src/lib/{geojson-tiler → geojsonvt}/wrap.ts +0 -0
  107. /package/src/lib/{binary-vector-tile → vector-tile}/LICENSE.txt +0 -0
  108. /package/src/lib/{mapbox-vector-tile → vector-tile}/vector-tile.ts +0 -0
@@ -6,6 +6,7 @@
6
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
7
  var __getProtoOf = Object.getPrototypeOf;
8
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
10
  var __commonJS = (cb, mod) => function __require() {
10
11
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
11
12
  };
@@ -25,6 +26,10 @@
25
26
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
27
  mod
27
28
  ));
29
+ var __publicField = (obj, key, value) => {
30
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
31
+ return value;
32
+ };
28
33
 
29
34
  // ../../node_modules/ieee754/index.js
30
35
  var require_ieee754 = __commonJS({
@@ -35,19 +40,19 @@
35
40
  var eMax = (1 << eLen) - 1;
36
41
  var eBias = eMax >> 1;
37
42
  var nBits = -7;
38
- var i2 = isLE ? nBytes - 1 : 0;
43
+ var i = isLE ? nBytes - 1 : 0;
39
44
  var d = isLE ? -1 : 1;
40
- var s = buffer[offset + i2];
41
- i2 += d;
45
+ var s = buffer[offset + i];
46
+ i += d;
42
47
  e = s & (1 << -nBits) - 1;
43
48
  s >>= -nBits;
44
49
  nBits += eLen;
45
- for (; nBits > 0; e = e * 256 + buffer[offset + i2], i2 += d, nBits -= 8) {
50
+ for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {
46
51
  }
47
52
  m = e & (1 << -nBits) - 1;
48
53
  e >>= -nBits;
49
54
  nBits += mLen;
50
- for (; nBits > 0; m = m * 256 + buffer[offset + i2], i2 += d, nBits -= 8) {
55
+ for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {
51
56
  }
52
57
  if (e === 0) {
53
58
  e = 1 - eBias;
@@ -65,7 +70,7 @@
65
70
  var eMax = (1 << eLen) - 1;
66
71
  var eBias = eMax >> 1;
67
72
  var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
68
- var i2 = isLE ? 0 : nBytes - 1;
73
+ var i = isLE ? 0 : nBytes - 1;
69
74
  var d = isLE ? 1 : -1;
70
75
  var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
71
76
  value = Math.abs(value);
@@ -98,13 +103,13 @@
98
103
  e = 0;
99
104
  }
100
105
  }
101
- for (; mLen >= 8; buffer[offset + i2] = m & 255, i2 += d, m /= 256, mLen -= 8) {
106
+ for (; mLen >= 8; buffer[offset + i] = m & 255, i += d, m /= 256, mLen -= 8) {
102
107
  }
103
108
  e = e << mLen | m;
104
109
  eLen += mLen;
105
- for (; eLen > 0; buffer[offset + i2] = e & 255, i2 += d, e /= 256, eLen -= 8) {
110
+ for (; eLen > 0; buffer[offset + i] = e & 255, i += d, e /= 256, eLen -= 8) {
106
111
  }
107
- buffer[offset + i2 - d] |= s * 128;
112
+ buffer[offset + i - d] |= s * 128;
108
113
  };
109
114
  }
110
115
  });
@@ -326,14 +331,14 @@
326
331
  this.writeVarint(tag << 3 | type);
327
332
  },
328
333
  realloc: function(min) {
329
- var length2 = this.length || 16;
330
- while (length2 < this.pos + min)
331
- length2 *= 2;
332
- if (length2 !== this.length) {
333
- var buf = new Uint8Array(length2);
334
+ var length = this.length || 16;
335
+ while (length < this.pos + min)
336
+ length *= 2;
337
+ if (length !== this.length) {
338
+ var buf = new Uint8Array(length);
334
339
  buf.set(this.buf);
335
340
  this.buf = buf;
336
- this.length = length2;
341
+ this.length = length;
337
342
  }
338
343
  },
339
344
  finish: function() {
@@ -414,8 +419,8 @@
414
419
  var len = buffer.length;
415
420
  this.writeVarint(len);
416
421
  this.realloc(len);
417
- for (var i2 = 0; i2 < len; i2++)
418
- this.buf[this.pos++] = buffer[i2];
422
+ for (var i = 0; i < len; i++)
423
+ this.buf[this.pos++] = buffer[i];
419
424
  },
420
425
  writeRawMessage: function(fn, obj) {
421
426
  this.pos++;
@@ -604,44 +609,44 @@
604
609
  function makeRoomForExtraLength(startPos, len, pbf) {
605
610
  var extraLen = len <= 16383 ? 1 : len <= 2097151 ? 2 : len <= 268435455 ? 3 : Math.floor(Math.log(len) / (Math.LN2 * 7));
606
611
  pbf.realloc(extraLen);
607
- for (var i2 = pbf.pos - 1; i2 >= startPos; i2--)
608
- pbf.buf[i2 + extraLen] = pbf.buf[i2];
612
+ for (var i = pbf.pos - 1; i >= startPos; i--)
613
+ pbf.buf[i + extraLen] = pbf.buf[i];
609
614
  }
610
615
  function writePackedVarint(arr, pbf) {
611
- for (var i2 = 0; i2 < arr.length; i2++)
612
- pbf.writeVarint(arr[i2]);
616
+ for (var i = 0; i < arr.length; i++)
617
+ pbf.writeVarint(arr[i]);
613
618
  }
614
619
  function writePackedSVarint(arr, pbf) {
615
- for (var i2 = 0; i2 < arr.length; i2++)
616
- pbf.writeSVarint(arr[i2]);
620
+ for (var i = 0; i < arr.length; i++)
621
+ pbf.writeSVarint(arr[i]);
617
622
  }
618
623
  function writePackedFloat(arr, pbf) {
619
- for (var i2 = 0; i2 < arr.length; i2++)
620
- pbf.writeFloat(arr[i2]);
624
+ for (var i = 0; i < arr.length; i++)
625
+ pbf.writeFloat(arr[i]);
621
626
  }
622
627
  function writePackedDouble(arr, pbf) {
623
- for (var i2 = 0; i2 < arr.length; i2++)
624
- pbf.writeDouble(arr[i2]);
628
+ for (var i = 0; i < arr.length; i++)
629
+ pbf.writeDouble(arr[i]);
625
630
  }
626
631
  function writePackedBoolean(arr, pbf) {
627
- for (var i2 = 0; i2 < arr.length; i2++)
628
- pbf.writeBoolean(arr[i2]);
632
+ for (var i = 0; i < arr.length; i++)
633
+ pbf.writeBoolean(arr[i]);
629
634
  }
630
635
  function writePackedFixed32(arr, pbf) {
631
- for (var i2 = 0; i2 < arr.length; i2++)
632
- pbf.writeFixed32(arr[i2]);
636
+ for (var i = 0; i < arr.length; i++)
637
+ pbf.writeFixed32(arr[i]);
633
638
  }
634
639
  function writePackedSFixed32(arr, pbf) {
635
- for (var i2 = 0; i2 < arr.length; i2++)
636
- pbf.writeSFixed32(arr[i2]);
640
+ for (var i = 0; i < arr.length; i++)
641
+ pbf.writeSFixed32(arr[i]);
637
642
  }
638
643
  function writePackedFixed64(arr, pbf) {
639
- for (var i2 = 0; i2 < arr.length; i2++)
640
- pbf.writeFixed64(arr[i2]);
644
+ for (var i = 0; i < arr.length; i++)
645
+ pbf.writeFixed64(arr[i]);
641
646
  }
642
647
  function writePackedSFixed64(arr, pbf) {
643
- for (var i2 = 0; i2 < arr.length; i2++)
644
- pbf.writeSFixed64(arr[i2]);
648
+ for (var i = 0; i < arr.length; i++)
649
+ pbf.writeSFixed64(arr[i]);
645
650
  }
646
651
  function readUInt32(buf, pos) {
647
652
  return (buf[pos] | buf[pos + 1] << 8 | buf[pos + 2] << 16) + buf[pos + 3] * 16777216;
@@ -657,12 +662,12 @@
657
662
  }
658
663
  function readUtf8(buf, pos, end) {
659
664
  var str = "";
660
- var i2 = pos;
661
- while (i2 < end) {
662
- var b0 = buf[i2];
665
+ var i = pos;
666
+ while (i < end) {
667
+ var b0 = buf[i];
663
668
  var c = null;
664
669
  var bytesPerSequence = b0 > 239 ? 4 : b0 > 223 ? 3 : b0 > 191 ? 2 : 1;
665
- if (i2 + bytesPerSequence > end)
670
+ if (i + bytesPerSequence > end)
666
671
  break;
667
672
  var b1, b2, b3;
668
673
  if (bytesPerSequence === 1) {
@@ -670,7 +675,7 @@
670
675
  c = b0;
671
676
  }
672
677
  } else if (bytesPerSequence === 2) {
673
- b1 = buf[i2 + 1];
678
+ b1 = buf[i + 1];
674
679
  if ((b1 & 192) === 128) {
675
680
  c = (b0 & 31) << 6 | b1 & 63;
676
681
  if (c <= 127) {
@@ -678,8 +683,8 @@
678
683
  }
679
684
  }
680
685
  } else if (bytesPerSequence === 3) {
681
- b1 = buf[i2 + 1];
682
- b2 = buf[i2 + 2];
686
+ b1 = buf[i + 1];
687
+ b2 = buf[i + 2];
683
688
  if ((b1 & 192) === 128 && (b2 & 192) === 128) {
684
689
  c = (b0 & 15) << 12 | (b1 & 63) << 6 | b2 & 63;
685
690
  if (c <= 2047 || c >= 55296 && c <= 57343) {
@@ -687,9 +692,9 @@
687
692
  }
688
693
  }
689
694
  } else if (bytesPerSequence === 4) {
690
- b1 = buf[i2 + 1];
691
- b2 = buf[i2 + 2];
692
- b3 = buf[i2 + 3];
695
+ b1 = buf[i + 1];
696
+ b2 = buf[i + 2];
697
+ b3 = buf[i + 3];
693
698
  if ((b1 & 192) === 128 && (b2 & 192) === 128 && (b3 & 192) === 128) {
694
699
  c = (b0 & 15) << 18 | (b1 & 63) << 12 | (b2 & 63) << 6 | b3 & 63;
695
700
  if (c <= 65535 || c >= 1114112) {
@@ -706,7 +711,7 @@
706
711
  c = 56320 | c & 1023;
707
712
  }
708
713
  str += String.fromCharCode(c);
709
- i2 += bytesPerSequence;
714
+ i += bytesPerSequence;
710
715
  }
711
716
  return str;
712
717
  }
@@ -714,8 +719,8 @@
714
719
  return utf8TextDecoder.decode(buf.subarray(pos, end));
715
720
  }
716
721
  function writeUtf8(buf, str, pos) {
717
- for (var i2 = 0, c, lead; i2 < str.length; i2++) {
718
- c = str.charCodeAt(i2);
722
+ for (var i = 0, c, lead; i < str.length; i++) {
723
+ c = str.charCodeAt(i);
719
724
  if (c > 55295 && c < 57344) {
720
725
  if (lead) {
721
726
  if (c < 56320) {
@@ -729,7 +734,7 @@
729
734
  lead = null;
730
735
  }
731
736
  } else {
732
- if (c > 56319 || i2 + 1 === str.length) {
737
+ if (c > 56319 || i + 1 === str.length) {
733
738
  buf[pos++] = 239;
734
739
  buf[pos++] = 191;
735
740
  buf[pos++] = 189;
@@ -828,9 +833,9 @@
828
833
  let area2 = 0;
829
834
  const i0 = DimIndex[plane[0]];
830
835
  const i1 = DimIndex[plane[1]];
831
- for (let i2 = start, j = end - dim; i2 < end; i2 += dim) {
832
- area2 += (points[i2 + i0] - points[j + i0]) * (points[i2 + i1] + points[j + i1]);
833
- j = i2;
836
+ for (let i = start, j = end - dim; i < end; i += dim) {
837
+ area2 += (points[i + i0] - points[j + i0]) * (points[i + i1] + points[j + i1]);
838
+ j = i;
834
839
  }
835
840
  return area2 / 2;
836
841
  }
@@ -848,24 +853,24 @@
848
853
  let maxY;
849
854
  let minX;
850
855
  let minY;
851
- let x2;
852
- let y2;
856
+ let x;
857
+ let y;
853
858
  if (hasHoles)
854
859
  outerNode = eliminateHoles(positions, holeIndices, outerNode, dim, areas, plane);
855
860
  if (positions.length > 80 * dim) {
856
861
  minX = maxX = positions[0];
857
862
  minY = maxY = positions[1];
858
- for (let i2 = dim; i2 < outerLen; i2 += dim) {
859
- x2 = positions[i2];
860
- y2 = positions[i2 + 1];
861
- if (x2 < minX)
862
- minX = x2;
863
- if (y2 < minY)
864
- minY = y2;
865
- if (x2 > maxX)
866
- maxX = x2;
867
- if (y2 > maxY)
868
- maxY = y2;
863
+ for (let i = dim; i < outerLen; i += dim) {
864
+ x = positions[i];
865
+ y = positions[i + 1];
866
+ if (x < minX)
867
+ minX = x;
868
+ if (y < minY)
869
+ minY = y;
870
+ if (x > maxX)
871
+ maxX = x;
872
+ if (y > maxY)
873
+ maxY = y;
869
874
  }
870
875
  invSize = Math.max(maxX - minX, maxY - minY);
871
876
  invSize = invSize !== 0 ? 32767 / invSize : 0;
@@ -874,7 +879,7 @@
874
879
  return triangles;
875
880
  }
876
881
  function linkedList(data, start, end, dim, clockwise, area2, plane) {
877
- let i2;
882
+ let i;
878
883
  let last;
879
884
  if (area2 === void 0) {
880
885
  area2 = getPolygonSignedArea(data, {
@@ -887,11 +892,11 @@
887
892
  let i0 = DimIndex[plane[0]];
888
893
  let i1 = DimIndex[plane[1]];
889
894
  if (clockwise === area2 < 0) {
890
- for (i2 = start; i2 < end; i2 += dim)
891
- last = insertNode(i2, data[i2 + i0], data[i2 + i1], last);
895
+ for (i = start; i < end; i += dim)
896
+ last = insertNode(i, data[i + i0], data[i + i1], last);
892
897
  } else {
893
- for (i2 = end - dim; i2 >= start; i2 -= dim)
894
- last = insertNode(i2, data[i2 + i0], data[i2 + i1], last);
898
+ for (i = end - dim; i >= start; i -= dim)
899
+ last = insertNode(i, data[i + i0], data[i + i1], last);
895
900
  }
896
901
  if (last && equals(last, last.next)) {
897
902
  removeNode(last);
@@ -1055,22 +1060,22 @@
1055
1060
  }
1056
1061
  function eliminateHoles(data, holeIndices, outerNode, dim, areas, plane) {
1057
1062
  const queue = [];
1058
- let i2;
1063
+ let i;
1059
1064
  let len;
1060
1065
  let start;
1061
1066
  let end;
1062
1067
  let list;
1063
- for (i2 = 0, len = holeIndices.length; i2 < len; i2++) {
1064
- start = holeIndices[i2] * dim;
1065
- end = i2 < len - 1 ? holeIndices[i2 + 1] * dim : data.length;
1066
- list = linkedList(data, start, end, dim, false, areas && areas[i2 + 1], plane);
1068
+ for (i = 0, len = holeIndices.length; i < len; i++) {
1069
+ start = holeIndices[i] * dim;
1070
+ end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
1071
+ list = linkedList(data, start, end, dim, false, areas && areas[i + 1], plane);
1067
1072
  if (list === list.next)
1068
1073
  list.steiner = true;
1069
1074
  queue.push(getLeftmost(list));
1070
1075
  }
1071
1076
  queue.sort(compareX);
1072
- for (i2 = 0; i2 < queue.length; i2++) {
1073
- outerNode = eliminateHole(queue[i2], outerNode);
1077
+ for (i = 0; i < queue.length; i++) {
1078
+ outerNode = eliminateHole(queue[i], outerNode);
1074
1079
  }
1075
1080
  return outerNode;
1076
1081
  }
@@ -1094,11 +1099,11 @@
1094
1099
  let m;
1095
1100
  do {
1096
1101
  if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
1097
- const x2 = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
1098
- if (x2 <= hx && x2 > qx) {
1099
- qx = x2;
1102
+ const x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
1103
+ if (x <= hx && x > qx) {
1104
+ qx = x;
1100
1105
  m = p.x < p.next.x ? p : p.next;
1101
- if (x2 === hx)
1106
+ if (x === hx)
1102
1107
  return m;
1103
1108
  }
1104
1109
  }
@@ -1142,7 +1147,7 @@
1142
1147
  }
1143
1148
  function sortLinked(list) {
1144
1149
  let e;
1145
- let i2;
1150
+ let i;
1146
1151
  let inSize = 1;
1147
1152
  let numMerges;
1148
1153
  let p;
@@ -1159,7 +1164,7 @@
1159
1164
  numMerges++;
1160
1165
  q = p;
1161
1166
  pSize = 0;
1162
- for (i2 = 0; i2 < inSize; i2++) {
1167
+ for (i = 0; i < inSize; i++) {
1163
1168
  pSize++;
1164
1169
  q = q.nextZ;
1165
1170
  if (!q)
@@ -1190,18 +1195,18 @@
1190
1195
  } while (numMerges > 1);
1191
1196
  return list;
1192
1197
  }
1193
- function zOrder(x2, y2, minX, minY, invSize) {
1194
- x2 = (x2 - minX) * invSize | 0;
1195
- y2 = (y2 - minY) * invSize | 0;
1196
- x2 = (x2 | x2 << 8) & 16711935;
1197
- x2 = (x2 | x2 << 4) & 252645135;
1198
- x2 = (x2 | x2 << 2) & 858993459;
1199
- x2 = (x2 | x2 << 1) & 1431655765;
1200
- y2 = (y2 | y2 << 8) & 16711935;
1201
- y2 = (y2 | y2 << 4) & 252645135;
1202
- y2 = (y2 | y2 << 2) & 858993459;
1203
- y2 = (y2 | y2 << 1) & 1431655765;
1204
- return x2 | y2 << 1;
1198
+ function zOrder(x, y, minX, minY, invSize) {
1199
+ x = (x - minX) * invSize | 0;
1200
+ y = (y - minY) * invSize | 0;
1201
+ x = (x | x << 8) & 16711935;
1202
+ x = (x | x << 4) & 252645135;
1203
+ x = (x | x << 2) & 858993459;
1204
+ x = (x | x << 1) & 1431655765;
1205
+ y = (y | y << 8) & 16711935;
1206
+ y = (y | y << 4) & 252645135;
1207
+ y = (y | y << 2) & 858993459;
1208
+ y = (y | y << 1) & 1431655765;
1209
+ return x | y << 1;
1205
1210
  }
1206
1211
  function getLeftmost(start) {
1207
1212
  let p = start;
@@ -1287,8 +1292,8 @@
1287
1292
  b2.prev = bp;
1288
1293
  return b2;
1289
1294
  }
1290
- function insertNode(i2, x2, y2, last) {
1291
- const p = new Vertex(i2, x2, y2);
1295
+ function insertNode(i, x, y, last) {
1296
+ const p = new Vertex(i, x, y);
1292
1297
  if (!last) {
1293
1298
  p.prev = p;
1294
1299
  p.next = p;
@@ -1309,7 +1314,7 @@
1309
1314
  p.nextZ.prevZ = p.prevZ;
1310
1315
  }
1311
1316
  var Vertex = class {
1312
- constructor(i2, x2, y2) {
1317
+ constructor(i, x, y) {
1313
1318
  _defineProperty(this, "i", void 0);
1314
1319
  _defineProperty(this, "x", void 0);
1315
1320
  _defineProperty(this, "y", void 0);
@@ -1319,9 +1324,9 @@
1319
1324
  _defineProperty(this, "prevZ", null);
1320
1325
  _defineProperty(this, "nextZ", null);
1321
1326
  _defineProperty(this, "steiner", false);
1322
- this.i = i2;
1323
- this.x = x2;
1324
- this.y = y2;
1327
+ this.i = i;
1328
+ this.x = x;
1329
+ this.y = y;
1325
1330
  }
1326
1331
  };
1327
1332
 
@@ -1490,9 +1495,9 @@
1490
1495
  indexMap.linePosition,
1491
1496
  indexMap.linePosition + nPositions
1492
1497
  );
1493
- for (let i2 = 0, il = geometry.indices.length; i2 < il; ++i2) {
1494
- const start = geometry.indices[i2];
1495
- const end = i2 === il - 1 ? geometry.data.length : geometry.indices[i2 + 1];
1498
+ for (let i = 0, il = geometry.indices.length; i < il; ++i) {
1499
+ const start = geometry.indices[i];
1500
+ const end = i === il - 1 ? geometry.data.length : geometry.indices[i + 1];
1496
1501
  lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
1497
1502
  indexMap.linePosition += (end - start) / coordLength;
1498
1503
  }
@@ -1517,12 +1522,12 @@
1517
1522
  const areas = geometry.areas[l];
1518
1523
  const indices = geometry.indices[l];
1519
1524
  const nextIndices = geometry.indices[l + 1];
1520
- for (let i2 = 0, il = indices.length; i2 < il; ++i2) {
1521
- const start = indices[i2];
1522
- const end = i2 === il - 1 ? (
1525
+ for (let i = 0, il = indices.length; i < il; ++i) {
1526
+ const start = indices[i];
1527
+ const end = i === il - 1 ? (
1523
1528
  // last line, so either read to:
1524
1529
  nextIndices === void 0 ? geometry.data.length : nextIndices[0]
1525
- ) : indices[i2 + 1];
1530
+ ) : indices[i + 1];
1526
1531
  polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
1527
1532
  indexMap.polygonPosition += (end - start) / coordLength;
1528
1533
  }
@@ -1589,11 +1594,11 @@
1589
1594
  }
1590
1595
  return binaryFeatures;
1591
1596
  }
1592
- function fillNumericProperties(object, properties, index, length2) {
1597
+ function fillNumericProperties(object, properties, index, length) {
1593
1598
  for (const numericPropName in object.numericProps) {
1594
1599
  if (numericPropName in properties) {
1595
1600
  const value = properties[numericPropName];
1596
- object.numericProps[numericPropName].fill(value, index, index + length2);
1601
+ object.numericProps[numericPropName].fill(value, index, index + length);
1597
1602
  }
1598
1603
  }
1599
1604
  }
@@ -1606,405 +1611,845 @@
1606
1611
  }
1607
1612
  return props;
1608
1613
  }
1609
- function deduceArrayType(x2, constructor) {
1610
- if (constructor === Array || !Number.isFinite(x2)) {
1614
+ function deduceArrayType(x, constructor) {
1615
+ if (constructor === Array || !Number.isFinite(x)) {
1611
1616
  return Array;
1612
1617
  }
1613
- return constructor === Float64Array || Math.fround(x2) !== x2 ? Float64Array : Float32Array;
1618
+ return constructor === Float64Array || Math.fround(x) !== x ? Float64Array : Float32Array;
1614
1619
  }
1615
1620
 
1616
- // src/lib/parse-mvt.ts
1617
- var import_pbf = __toESM(require_pbf(), 1);
1618
-
1619
- // src/helpers/mapbox-util-functions.ts
1620
- function classifyRings(rings) {
1621
- const len = rings.length;
1622
- if (len <= 1)
1623
- return [rings];
1624
- const polygons = [];
1625
- let polygon;
1626
- let ccw;
1627
- for (let i2 = 0; i2 < len; i2++) {
1628
- const area2 = signedArea(rings[i2]);
1629
- if (area2 === 0)
1630
- continue;
1631
- if (ccw === void 0)
1632
- ccw = area2 < 0;
1633
- if (ccw === area2 < 0) {
1634
- if (polygon)
1635
- polygons.push(polygon);
1636
- polygon = [rings[i2]];
1637
- } else if (polygon)
1638
- polygon.push(rings[i2]);
1621
+ // ../../node_modules/@probe.gl/log/node_modules/@probe.gl/env/dist/lib/is-electron.js
1622
+ function isElectron(mockUserAgent) {
1623
+ if (typeof window !== "undefined" && typeof window.process === "object" && window.process.type === "renderer") {
1624
+ return true;
1639
1625
  }
1640
- if (polygon)
1641
- polygons.push(polygon);
1642
- return polygons;
1643
- }
1644
- function signedArea(ring) {
1645
- let sum = 0;
1646
- for (let i2 = 0, j = ring.length - 1, p1, p2; i2 < ring.length; j = i2++) {
1647
- p1 = ring[i2];
1648
- p2 = ring[j];
1649
- sum += (p2[0] - p1[0]) * (p1[1] + p2[1]);
1626
+ if (typeof process !== "undefined" && typeof process.versions === "object" && Boolean(process.versions["electron"])) {
1627
+ return true;
1650
1628
  }
1651
- return sum;
1652
- }
1653
- function readFeature(tag, feature, pbf) {
1654
- if (feature && pbf) {
1655
- if (tag === 1)
1656
- feature.id = pbf.readVarint();
1657
- else if (tag === 2)
1658
- readTag(pbf, feature);
1659
- else if (tag === 3)
1660
- feature.type = pbf.readVarint();
1661
- else if (tag === 4)
1662
- feature._geometry = pbf.pos;
1629
+ const realUserAgent = typeof navigator === "object" && typeof navigator.userAgent === "string" && navigator.userAgent;
1630
+ const userAgent = mockUserAgent || realUserAgent;
1631
+ if (userAgent && userAgent.indexOf("Electron") >= 0) {
1632
+ return true;
1663
1633
  }
1634
+ return false;
1664
1635
  }
1665
- function readTag(pbf, feature) {
1666
- const end = pbf.readVarint() + pbf.pos;
1667
- while (pbf.pos < end) {
1668
- const key = feature._keys[pbf.readVarint()];
1669
- const value = feature._values[pbf.readVarint()];
1670
- feature.properties[key] = value;
1671
- }
1636
+
1637
+ // ../../node_modules/@probe.gl/log/node_modules/@probe.gl/env/dist/lib/is-browser.js
1638
+ function isBrowser() {
1639
+ const isNode = typeof process === "object" && String(process) === "[object process]" && !process.browser;
1640
+ return !isNode || isElectron();
1672
1641
  }
1673
1642
 
1674
- // src/lib/mapbox-vector-tile/vector-tile-feature.ts
1675
- var VectorTileFeature = class {
1676
- properties;
1677
- extent;
1678
- type;
1679
- id;
1680
- _pbf;
1681
- _geometry;
1682
- _keys;
1683
- _values;
1684
- static get types() {
1685
- return ["Unknown", "Point", "LineString", "Polygon"];
1686
- }
1687
- constructor(pbf, end, extent, keys, values) {
1688
- this.properties = {};
1689
- this.extent = extent;
1690
- this.type = 0;
1691
- this.id = null;
1692
- this._pbf = pbf;
1693
- this._geometry = -1;
1694
- this._keys = keys;
1695
- this._values = values;
1696
- pbf.readFields(readFeature, this, end);
1643
+ // ../../node_modules/@probe.gl/log/node_modules/@probe.gl/env/dist/lib/globals.js
1644
+ var self_ = globalThis.self || globalThis.window || globalThis.global;
1645
+ var window_ = globalThis.window || globalThis.self || globalThis.global;
1646
+ var document_ = globalThis.document || {};
1647
+ var process_ = globalThis.process || {};
1648
+ var console_ = globalThis.console;
1649
+ var navigator_ = globalThis.navigator || {};
1650
+
1651
+ // ../../node_modules/@probe.gl/log/node_modules/@probe.gl/env/dist/utils/globals.js
1652
+ var VERSION = true ? "4.2.0" : "untranspiled source";
1653
+ var isBrowser2 = isBrowser();
1654
+
1655
+ // ../../node_modules/@probe.gl/log/dist/utils/local-storage.js
1656
+ function getStorage(type) {
1657
+ try {
1658
+ const storage = window[type];
1659
+ const x = "__storage_test__";
1660
+ storage.setItem(x, x);
1661
+ storage.removeItem(x);
1662
+ return storage;
1663
+ } catch (e) {
1664
+ return null;
1697
1665
  }
1698
- // eslint-disable-next-line complexity, max-statements
1699
- loadGeometry() {
1700
- const pbf = this._pbf;
1701
- pbf.pos = this._geometry;
1702
- const end = pbf.readVarint() + pbf.pos;
1703
- let cmd2 = 1;
1704
- let length2 = 0;
1705
- let x2 = 0;
1706
- let y2 = 0;
1707
- const lines = [];
1708
- let line;
1709
- while (pbf.pos < end) {
1710
- if (length2 <= 0) {
1711
- const cmdLen2 = pbf.readVarint();
1712
- cmd2 = cmdLen2 & 7;
1713
- length2 = cmdLen2 >> 3;
1714
- }
1715
- length2--;
1716
- if (cmd2 === 1 || cmd2 === 2) {
1717
- x2 += pbf.readSVarint();
1718
- y2 += pbf.readSVarint();
1719
- if (cmd2 === 1) {
1720
- if (line)
1721
- lines.push(line);
1722
- line = [];
1723
- }
1724
- if (line)
1725
- line.push([x2, y2]);
1726
- } else if (cmd2 === 7) {
1727
- if (line) {
1728
- line.push(line[0].slice());
1729
- }
1730
- } else {
1731
- throw new Error(`unknown command ${cmd2}`);
1732
- }
1733
- }
1734
- if (line)
1735
- lines.push(line);
1736
- return lines;
1666
+ }
1667
+ var LocalStorage = class {
1668
+ constructor(id, defaultConfig) {
1669
+ let type = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "sessionStorage";
1670
+ _defineProperty(this, "storage", void 0);
1671
+ _defineProperty(this, "id", void 0);
1672
+ _defineProperty(this, "config", void 0);
1673
+ this.storage = getStorage(type);
1674
+ this.id = id;
1675
+ this.config = defaultConfig;
1676
+ this._loadConfiguration();
1737
1677
  }
1738
- // eslint-disable-next-line max-statements
1739
- bbox() {
1740
- const pbf = this._pbf;
1741
- pbf.pos = this._geometry;
1742
- const end = pbf.readVarint() + pbf.pos;
1743
- let cmd2 = 1;
1744
- let length2 = 0;
1745
- let x2 = 0;
1746
- let y2 = 0;
1747
- let x1 = Infinity;
1748
- let x22 = -Infinity;
1749
- let y1 = Infinity;
1750
- let y22 = -Infinity;
1751
- while (pbf.pos < end) {
1752
- if (length2 <= 0) {
1753
- const cmdLen2 = pbf.readVarint();
1754
- cmd2 = cmdLen2 & 7;
1755
- length2 = cmdLen2 >> 3;
1756
- }
1757
- length2--;
1758
- if (cmd2 === 1 || cmd2 === 2) {
1759
- x2 += pbf.readSVarint();
1760
- y2 += pbf.readSVarint();
1761
- if (x2 < x1)
1762
- x1 = x2;
1763
- if (x2 > x22)
1764
- x22 = x2;
1765
- if (y2 < y1)
1766
- y1 = y2;
1767
- if (y2 > y22)
1768
- y22 = y2;
1769
- } else if (cmd2 !== 7) {
1770
- throw new Error(`unknown command ${cmd2}`);
1771
- }
1772
- }
1773
- return [x1, y1, x22, y22];
1678
+ getConfiguration() {
1679
+ return this.config;
1774
1680
  }
1775
- _toGeoJSON(transform) {
1776
- let coords = this.loadGeometry();
1777
- let type = VectorTileFeature.types[this.type];
1778
- let i2;
1779
- let j;
1780
- switch (this.type) {
1781
- case 1:
1782
- const points = [];
1783
- for (i2 = 0; i2 < coords.length; i2++) {
1784
- points[i2] = coords[i2][0];
1785
- }
1786
- coords = points;
1787
- transform(coords, this);
1788
- break;
1789
- case 2:
1790
- for (i2 = 0; i2 < coords.length; i2++) {
1791
- transform(coords[i2], this);
1792
- }
1793
- break;
1794
- case 3:
1795
- coords = classifyRings(coords);
1796
- for (i2 = 0; i2 < coords.length; i2++) {
1797
- for (j = 0; j < coords[i2].length; j++) {
1798
- transform(coords[i2][j], this);
1799
- }
1800
- }
1801
- break;
1802
- }
1803
- if (coords.length === 1) {
1804
- coords = coords[0];
1805
- } else {
1806
- type = `Multi${type}`;
1807
- }
1808
- const result = {
1809
- type: "Feature",
1810
- geometry: {
1811
- type,
1812
- coordinates: coords
1813
- },
1814
- properties: this.properties
1815
- };
1816
- if (this.id !== null) {
1817
- result.id = this.id;
1681
+ setConfiguration(configuration) {
1682
+ Object.assign(this.config, configuration);
1683
+ if (this.storage) {
1684
+ const serialized = JSON.stringify(this.config);
1685
+ this.storage.setItem(this.id, serialized);
1818
1686
  }
1819
- return result;
1820
1687
  }
1821
- toGeoJSON(options) {
1822
- if (typeof options === "function") {
1823
- return this._toGeoJSON(options);
1824
- }
1825
- const { x: x2, y: y2, z } = options;
1826
- const size = this.extent * Math.pow(2, z);
1827
- const x0 = this.extent * x2;
1828
- const y0 = this.extent * y2;
1829
- function project2(line) {
1830
- for (let j = 0; j < line.length; j++) {
1831
- const p = line[j];
1832
- p[0] = (p[0] + x0) * 360 / size - 180;
1833
- const y22 = 180 - (p[1] + y0) * 360 / size;
1834
- p[1] = 360 / Math.PI * Math.atan(Math.exp(y22 * Math.PI / 180)) - 90;
1835
- }
1688
+ _loadConfiguration() {
1689
+ let configuration = {};
1690
+ if (this.storage) {
1691
+ const serializedConfiguration = this.storage.getItem(this.id);
1692
+ configuration = serializedConfiguration ? JSON.parse(serializedConfiguration) : {};
1836
1693
  }
1837
- return this._toGeoJSON(project2);
1694
+ Object.assign(this.config, configuration);
1695
+ return this;
1838
1696
  }
1839
1697
  };
1840
1698
 
1841
- // src/lib/mapbox-vector-tile/vector-tile-layer.ts
1842
- var VectorTileLayer = class {
1843
- version;
1844
- name;
1845
- extent;
1846
- length;
1847
- _pbf;
1848
- _keys;
1849
- _values;
1850
- _features;
1851
- constructor(pbf, end) {
1852
- this.version = 1;
1853
- this.name = "";
1854
- this.extent = 4096;
1855
- this.length = 0;
1856
- this._pbf = pbf;
1857
- this._keys = [];
1858
- this._values = [];
1859
- this._features = [];
1860
- pbf.readFields(readLayer, this, end);
1861
- this.length = this._features.length;
1862
- }
1863
- /**
1864
- * return feature `i` from this layer as a `VectorTileFeature`
1865
- * @param index
1866
- * @returns feature
1867
- */
1868
- feature(i2) {
1869
- if (i2 < 0 || i2 >= this._features.length) {
1870
- throw new Error("feature index out of bounds");
1871
- }
1872
- this._pbf.pos = this._features[i2];
1873
- const end = this._pbf.readVarint() + this._pbf.pos;
1874
- return new VectorTileFeature(this._pbf, end, this.extent, this._keys, this._values);
1875
- }
1876
- };
1877
- function readLayer(tag, layer, pbf) {
1878
- if (layer && pbf) {
1879
- if (tag === 15)
1880
- layer.version = pbf.readVarint();
1881
- else if (tag === 1)
1882
- layer.name = pbf.readString();
1883
- else if (tag === 5)
1884
- layer.extent = pbf.readVarint();
1885
- else if (tag === 2)
1886
- layer._features.push(pbf.pos);
1887
- else if (tag === 3)
1888
- layer._keys.push(pbf.readString());
1889
- else if (tag === 4)
1890
- layer._values.push(readValueMessage(pbf));
1699
+ // ../../node_modules/@probe.gl/log/dist/utils/formatters.js
1700
+ function formatTime(ms) {
1701
+ let formatted;
1702
+ if (ms < 10) {
1703
+ formatted = "".concat(ms.toFixed(2), "ms");
1704
+ } else if (ms < 100) {
1705
+ formatted = "".concat(ms.toFixed(1), "ms");
1706
+ } else if (ms < 1e3) {
1707
+ formatted = "".concat(ms.toFixed(0), "ms");
1708
+ } else {
1709
+ formatted = "".concat((ms / 1e3).toFixed(2), "s");
1891
1710
  }
1711
+ return formatted;
1892
1712
  }
1893
- function readValueMessage(pbf) {
1894
- let value = null;
1895
- const end = pbf.readVarint() + pbf.pos;
1896
- while (pbf.pos < end) {
1897
- const tag = pbf.readVarint() >> 3;
1898
- 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;
1713
+ function leftPad(string) {
1714
+ let length = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 8;
1715
+ const padLength = Math.max(length - string.length, 0);
1716
+ return "".concat(" ".repeat(padLength)).concat(string);
1717
+ }
1718
+ function formatImage(image, message, scale) {
1719
+ let maxWidth = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 600;
1720
+ const imageUrl = image.src.replace(/\(/g, "%28").replace(/\)/g, "%29");
1721
+ if (image.width > maxWidth) {
1722
+ scale = Math.min(scale, maxWidth / image.width);
1899
1723
  }
1900
- return value;
1724
+ const width = image.width * scale;
1725
+ const height = image.height * scale;
1726
+ 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("");
1727
+ return ["".concat(message, " %c+"), style];
1901
1728
  }
1902
1729
 
1903
- // src/lib/mapbox-vector-tile/vector-tile.ts
1904
- var VectorTile = class {
1905
- layers;
1906
- constructor(pbf, end) {
1907
- this.layers = pbf.readFields(readTile, {}, end);
1908
- }
1909
- };
1910
- function readTile(tag, layers, pbf) {
1911
- if (tag === 3) {
1912
- if (pbf) {
1913
- const layer = new VectorTileLayer(pbf, pbf.readVarint() + pbf.pos);
1914
- if (layer.length && layers) {
1915
- layers[layer.name] = layer;
1730
+ // ../../node_modules/@probe.gl/log/dist/utils/color.js
1731
+ var COLOR;
1732
+ (function(COLOR2) {
1733
+ COLOR2[COLOR2["BLACK"] = 30] = "BLACK";
1734
+ COLOR2[COLOR2["RED"] = 31] = "RED";
1735
+ COLOR2[COLOR2["GREEN"] = 32] = "GREEN";
1736
+ COLOR2[COLOR2["YELLOW"] = 33] = "YELLOW";
1737
+ COLOR2[COLOR2["BLUE"] = 34] = "BLUE";
1738
+ COLOR2[COLOR2["MAGENTA"] = 35] = "MAGENTA";
1739
+ COLOR2[COLOR2["CYAN"] = 36] = "CYAN";
1740
+ COLOR2[COLOR2["WHITE"] = 37] = "WHITE";
1741
+ COLOR2[COLOR2["BRIGHT_BLACK"] = 90] = "BRIGHT_BLACK";
1742
+ COLOR2[COLOR2["BRIGHT_RED"] = 91] = "BRIGHT_RED";
1743
+ COLOR2[COLOR2["BRIGHT_GREEN"] = 92] = "BRIGHT_GREEN";
1744
+ COLOR2[COLOR2["BRIGHT_YELLOW"] = 93] = "BRIGHT_YELLOW";
1745
+ COLOR2[COLOR2["BRIGHT_BLUE"] = 94] = "BRIGHT_BLUE";
1746
+ COLOR2[COLOR2["BRIGHT_MAGENTA"] = 95] = "BRIGHT_MAGENTA";
1747
+ COLOR2[COLOR2["BRIGHT_CYAN"] = 96] = "BRIGHT_CYAN";
1748
+ COLOR2[COLOR2["BRIGHT_WHITE"] = 97] = "BRIGHT_WHITE";
1749
+ })(COLOR || (COLOR = {}));
1750
+ var BACKGROUND_INCREMENT = 10;
1751
+ function getColor(color) {
1752
+ if (typeof color !== "string") {
1753
+ return color;
1754
+ }
1755
+ color = color.toUpperCase();
1756
+ return COLOR[color] || COLOR.WHITE;
1757
+ }
1758
+ function addColor(string, color, background) {
1759
+ if (!isBrowser && typeof string === "string") {
1760
+ if (color) {
1761
+ const colorCode = getColor(color);
1762
+ string = "\x1B[".concat(colorCode, "m").concat(string, "\x1B[39m");
1763
+ }
1764
+ if (background) {
1765
+ const colorCode = getColor(background);
1766
+ string = "\x1B[".concat(colorCode + BACKGROUND_INCREMENT, "m").concat(string, "\x1B[49m");
1767
+ }
1768
+ }
1769
+ return string;
1770
+ }
1771
+
1772
+ // ../../node_modules/@probe.gl/log/dist/utils/autobind.js
1773
+ function autobind(obj) {
1774
+ let predefined = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : ["constructor"];
1775
+ const proto = Object.getPrototypeOf(obj);
1776
+ const propNames = Object.getOwnPropertyNames(proto);
1777
+ const object = obj;
1778
+ for (const key of propNames) {
1779
+ const value = object[key];
1780
+ if (typeof value === "function") {
1781
+ if (!predefined.find((name) => key === name)) {
1782
+ object[key] = value.bind(obj);
1916
1783
  }
1917
1784
  }
1918
1785
  }
1919
1786
  }
1920
1787
 
1921
- // src/helpers/binary-util-functions.ts
1922
- function classifyRings2(geom) {
1923
- const len = geom.indices.length;
1924
- const type = "Polygon";
1925
- if (len <= 1) {
1926
- return {
1927
- type,
1928
- data: geom.data,
1929
- areas: [[getPolygonSignedArea(geom.data)]],
1930
- indices: [geom.indices]
1788
+ // ../../node_modules/@probe.gl/log/dist/utils/assert.js
1789
+ function assert(condition, message) {
1790
+ if (!condition) {
1791
+ throw new Error(message || "Assertion failed");
1792
+ }
1793
+ }
1794
+
1795
+ // ../../node_modules/@probe.gl/log/dist/utils/hi-res-timestamp.js
1796
+ function getHiResTimestamp() {
1797
+ let timestamp;
1798
+ if (isBrowser() && window_.performance) {
1799
+ var _window$performance, _window$performance$n;
1800
+ timestamp = window_ === null || window_ === void 0 ? void 0 : (_window$performance = window_.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);
1801
+ } else if ("hrtime" in process_) {
1802
+ var _process$hrtime;
1803
+ const timeParts = process_ === null || process_ === void 0 ? void 0 : (_process$hrtime = process_.hrtime) === null || _process$hrtime === void 0 ? void 0 : _process$hrtime.call(process_);
1804
+ timestamp = timeParts[0] * 1e3 + timeParts[1] / 1e6;
1805
+ } else {
1806
+ timestamp = Date.now();
1807
+ }
1808
+ return timestamp;
1809
+ }
1810
+
1811
+ // ../../node_modules/@probe.gl/log/dist/log.js
1812
+ var originalConsole = {
1813
+ debug: isBrowser() ? console.debug || console.log : console.log,
1814
+ log: console.log,
1815
+ info: console.info,
1816
+ warn: console.warn,
1817
+ error: console.error
1818
+ };
1819
+ var DEFAULT_LOG_CONFIGURATION = {
1820
+ enabled: true,
1821
+ level: 0
1822
+ };
1823
+ function noop() {
1824
+ }
1825
+ var cache = {};
1826
+ var ONCE = {
1827
+ once: true
1828
+ };
1829
+ var Log = class {
1830
+ constructor() {
1831
+ let {
1832
+ id
1833
+ } = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
1834
+ id: ""
1931
1835
  };
1836
+ _defineProperty(this, "id", void 0);
1837
+ _defineProperty(this, "VERSION", VERSION);
1838
+ _defineProperty(this, "_startTs", getHiResTimestamp());
1839
+ _defineProperty(this, "_deltaTs", getHiResTimestamp());
1840
+ _defineProperty(this, "_storage", void 0);
1841
+ _defineProperty(this, "userData", {});
1842
+ _defineProperty(this, "LOG_THROTTLE_TIMEOUT", 0);
1843
+ this.id = id;
1844
+ this.userData = {};
1845
+ this._storage = new LocalStorage("__probe-".concat(this.id, "__"), DEFAULT_LOG_CONFIGURATION);
1846
+ this.timeStamp("".concat(this.id, " started"));
1847
+ autobind(this);
1848
+ Object.seal(this);
1849
+ }
1850
+ set level(newLevel) {
1851
+ this.setLevel(newLevel);
1852
+ }
1853
+ get level() {
1854
+ return this.getLevel();
1855
+ }
1856
+ isEnabled() {
1857
+ return this._storage.config.enabled;
1858
+ }
1859
+ getLevel() {
1860
+ return this._storage.config.level;
1861
+ }
1862
+ getTotal() {
1863
+ return Number((getHiResTimestamp() - this._startTs).toPrecision(10));
1864
+ }
1865
+ getDelta() {
1866
+ return Number((getHiResTimestamp() - this._deltaTs).toPrecision(10));
1867
+ }
1868
+ set priority(newPriority) {
1869
+ this.level = newPriority;
1870
+ }
1871
+ get priority() {
1872
+ return this.level;
1873
+ }
1874
+ getPriority() {
1875
+ return this.level;
1876
+ }
1877
+ enable() {
1878
+ let enabled = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : true;
1879
+ this._storage.setConfiguration({
1880
+ enabled
1881
+ });
1882
+ return this;
1932
1883
  }
1933
- const areas = [];
1934
- const polygons = [];
1935
- let ringAreas = [];
1936
- let polygon = [];
1937
- let ccw;
1938
- let offset = 0;
1939
- for (let endIndex, i2 = 0, startIndex; i2 < len; i2++) {
1940
- startIndex = geom.indices[i2] - offset;
1941
- endIndex = geom.indices[i2 + 1] - offset || geom.data.length;
1942
- const shape = geom.data.slice(startIndex, endIndex);
1943
- const area2 = getPolygonSignedArea(shape);
1944
- if (area2 === 0) {
1945
- const before = geom.data.slice(0, startIndex);
1946
- const after = geom.data.slice(endIndex);
1947
- geom.data = before.concat(after);
1948
- offset += endIndex - startIndex;
1949
- continue;
1950
- }
1951
- if (ccw === void 0)
1952
- ccw = area2 < 0;
1953
- if (ccw === area2 < 0) {
1954
- if (polygon.length) {
1955
- areas.push(ringAreas);
1956
- polygons.push(polygon);
1957
- }
1958
- polygon = [startIndex];
1959
- ringAreas = [area2];
1884
+ setLevel(level) {
1885
+ this._storage.setConfiguration({
1886
+ level
1887
+ });
1888
+ return this;
1889
+ }
1890
+ get(setting) {
1891
+ return this._storage.config[setting];
1892
+ }
1893
+ set(setting, value) {
1894
+ this._storage.setConfiguration({
1895
+ [setting]: value
1896
+ });
1897
+ }
1898
+ settings() {
1899
+ if (console.table) {
1900
+ console.table(this._storage.config);
1960
1901
  } else {
1961
- ringAreas.push(area2);
1962
- polygon.push(startIndex);
1902
+ console.log(this._storage.config);
1963
1903
  }
1964
1904
  }
1965
- if (ringAreas)
1966
- areas.push(ringAreas);
1967
- if (polygon.length)
1968
- polygons.push(polygon);
1969
- return { type, areas, indices: polygons, data: geom.data };
1905
+ assert(condition, message) {
1906
+ assert(condition, message);
1907
+ }
1908
+ warn(message) {
1909
+ return this._getLogFunction(0, message, originalConsole.warn, arguments, ONCE);
1910
+ }
1911
+ error(message) {
1912
+ return this._getLogFunction(0, message, originalConsole.error, arguments);
1913
+ }
1914
+ deprecated(oldUsage, newUsage) {
1915
+ return this.warn("`".concat(oldUsage, "` is deprecated and will be removed in a later version. Use `").concat(newUsage, "` instead"));
1916
+ }
1917
+ removed(oldUsage, newUsage) {
1918
+ return this.error("`".concat(oldUsage, "` has been removed. Use `").concat(newUsage, "` instead"));
1919
+ }
1920
+ probe(logLevel, message) {
1921
+ return this._getLogFunction(logLevel, message, originalConsole.log, arguments, {
1922
+ time: true,
1923
+ once: true
1924
+ });
1925
+ }
1926
+ log(logLevel, message) {
1927
+ return this._getLogFunction(logLevel, message, originalConsole.debug, arguments);
1928
+ }
1929
+ info(logLevel, message) {
1930
+ return this._getLogFunction(logLevel, message, console.info, arguments);
1931
+ }
1932
+ once(logLevel, message) {
1933
+ return this._getLogFunction(logLevel, message, originalConsole.debug || originalConsole.info, arguments, ONCE);
1934
+ }
1935
+ table(logLevel, table, columns) {
1936
+ if (table) {
1937
+ return this._getLogFunction(logLevel, table, console.table || noop, columns && [columns], {
1938
+ tag: getTableHeader(table)
1939
+ });
1940
+ }
1941
+ return noop;
1942
+ }
1943
+ image(_ref) {
1944
+ let {
1945
+ logLevel,
1946
+ priority,
1947
+ image,
1948
+ message = "",
1949
+ scale = 1
1950
+ } = _ref;
1951
+ if (!this._shouldLog(logLevel || priority)) {
1952
+ return noop;
1953
+ }
1954
+ return isBrowser() ? logImageInBrowser({
1955
+ image,
1956
+ message,
1957
+ scale
1958
+ }) : logImageInNode({
1959
+ image,
1960
+ message,
1961
+ scale
1962
+ });
1963
+ }
1964
+ time(logLevel, message) {
1965
+ return this._getLogFunction(logLevel, message, console.time ? console.time : console.info);
1966
+ }
1967
+ timeEnd(logLevel, message) {
1968
+ return this._getLogFunction(logLevel, message, console.timeEnd ? console.timeEnd : console.info);
1969
+ }
1970
+ timeStamp(logLevel, message) {
1971
+ return this._getLogFunction(logLevel, message, console.timeStamp || noop);
1972
+ }
1973
+ group(logLevel, message) {
1974
+ let opts = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {
1975
+ collapsed: false
1976
+ };
1977
+ const options = normalizeArguments({
1978
+ logLevel,
1979
+ message,
1980
+ opts
1981
+ });
1982
+ const {
1983
+ collapsed
1984
+ } = opts;
1985
+ options.method = (collapsed ? console.groupCollapsed : console.group) || console.info;
1986
+ return this._getLogFunction(options);
1987
+ }
1988
+ groupCollapsed(logLevel, message) {
1989
+ let opts = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
1990
+ return this.group(logLevel, message, Object.assign({}, opts, {
1991
+ collapsed: true
1992
+ }));
1993
+ }
1994
+ groupEnd(logLevel) {
1995
+ return this._getLogFunction(logLevel, "", console.groupEnd || noop);
1996
+ }
1997
+ withGroup(logLevel, message, func) {
1998
+ this.group(logLevel, message)();
1999
+ try {
2000
+ func();
2001
+ } finally {
2002
+ this.groupEnd(logLevel)();
2003
+ }
2004
+ }
2005
+ trace() {
2006
+ if (console.trace) {
2007
+ console.trace();
2008
+ }
2009
+ }
2010
+ _shouldLog(logLevel) {
2011
+ return this.isEnabled() && this.getLevel() >= normalizeLogLevel(logLevel);
2012
+ }
2013
+ _getLogFunction(logLevel, message, method, args, opts) {
2014
+ if (this._shouldLog(logLevel)) {
2015
+ opts = normalizeArguments({
2016
+ logLevel,
2017
+ message,
2018
+ args,
2019
+ opts
2020
+ });
2021
+ method = method || opts.method;
2022
+ assert(method);
2023
+ opts.total = this.getTotal();
2024
+ opts.delta = this.getDelta();
2025
+ this._deltaTs = getHiResTimestamp();
2026
+ const tag = opts.tag || opts.message;
2027
+ if (opts.once && tag) {
2028
+ if (!cache[tag]) {
2029
+ cache[tag] = getHiResTimestamp();
2030
+ } else {
2031
+ return noop;
2032
+ }
2033
+ }
2034
+ message = decorateMessage(this.id, opts.message, opts);
2035
+ return method.bind(console, message, ...opts.args);
2036
+ }
2037
+ return noop;
2038
+ }
2039
+ };
2040
+ _defineProperty(Log, "VERSION", VERSION);
2041
+ function normalizeLogLevel(logLevel) {
2042
+ if (!logLevel) {
2043
+ return 0;
2044
+ }
2045
+ let resolvedLevel;
2046
+ switch (typeof logLevel) {
2047
+ case "number":
2048
+ resolvedLevel = logLevel;
2049
+ break;
2050
+ case "object":
2051
+ resolvedLevel = logLevel.logLevel || logLevel.priority || 0;
2052
+ break;
2053
+ default:
2054
+ return 0;
2055
+ }
2056
+ assert(Number.isFinite(resolvedLevel) && resolvedLevel >= 0);
2057
+ return resolvedLevel;
2058
+ }
2059
+ function normalizeArguments(opts) {
2060
+ const {
2061
+ logLevel,
2062
+ message
2063
+ } = opts;
2064
+ opts.logLevel = normalizeLogLevel(logLevel);
2065
+ const args = opts.args ? Array.from(opts.args) : [];
2066
+ while (args.length && args.shift() !== message) {
2067
+ }
2068
+ switch (typeof logLevel) {
2069
+ case "string":
2070
+ case "function":
2071
+ if (message !== void 0) {
2072
+ args.unshift(message);
2073
+ }
2074
+ opts.message = logLevel;
2075
+ break;
2076
+ case "object":
2077
+ Object.assign(opts, logLevel);
2078
+ break;
2079
+ default:
2080
+ }
2081
+ if (typeof opts.message === "function") {
2082
+ opts.message = opts.message();
2083
+ }
2084
+ const messageType = typeof opts.message;
2085
+ assert(messageType === "string" || messageType === "object");
2086
+ return Object.assign(opts, {
2087
+ args
2088
+ }, opts.opts);
2089
+ }
2090
+ function decorateMessage(id, message, opts) {
2091
+ if (typeof message === "string") {
2092
+ const time = opts.time ? leftPad(formatTime(opts.total)) : "";
2093
+ message = opts.time ? "".concat(id, ": ").concat(time, " ").concat(message) : "".concat(id, ": ").concat(message);
2094
+ message = addColor(message, opts.color, opts.background);
2095
+ }
2096
+ return message;
2097
+ }
2098
+ function logImageInNode(_ref2) {
2099
+ let {
2100
+ image,
2101
+ message = "",
2102
+ scale = 1
2103
+ } = _ref2;
2104
+ console.warn("removed");
2105
+ return noop;
2106
+ }
2107
+ function logImageInBrowser(_ref3) {
2108
+ let {
2109
+ image,
2110
+ message = "",
2111
+ scale = 1
2112
+ } = _ref3;
2113
+ if (typeof image === "string") {
2114
+ const img = new Image();
2115
+ img.onload = () => {
2116
+ const args = formatImage(img, message, scale);
2117
+ console.log(...args);
2118
+ };
2119
+ img.src = image;
2120
+ return noop;
2121
+ }
2122
+ const element = image.nodeName || "";
2123
+ if (element.toLowerCase() === "img") {
2124
+ console.log(...formatImage(image, message, scale));
2125
+ return noop;
2126
+ }
2127
+ if (element.toLowerCase() === "canvas") {
2128
+ const img = new Image();
2129
+ img.onload = () => console.log(...formatImage(img, message, scale));
2130
+ img.src = image.toDataURL();
2131
+ return noop;
2132
+ }
2133
+ return noop;
2134
+ }
2135
+ function getTableHeader(table) {
2136
+ for (const key in table) {
2137
+ for (const title in table[key]) {
2138
+ return title || "untitled";
2139
+ }
2140
+ }
2141
+ return "empty";
2142
+ }
2143
+
2144
+ // ../../node_modules/@probe.gl/log/dist/index.js
2145
+ var dist_default = new Log({
2146
+ id: "@probe.gl/log"
2147
+ });
2148
+
2149
+ // ../loader-utils/src/lib/log-utils/log.ts
2150
+ var VERSION2 = true ? "4.2.0" : "latest";
2151
+ var version = VERSION2[0] >= "0" && VERSION2[0] <= "9" ? `v${VERSION2}` : "";
2152
+ var log = new Log({ id: `loaders.gl ${version}` });
2153
+
2154
+ // ../worker-utils/src/lib/node/worker_threads-browser.ts
2155
+ var parentPort = null;
2156
+
2157
+ // ../worker-utils/src/lib/worker-utils/get-transfer-list.ts
2158
+ function getTransferList(object, recursive = true, transfers) {
2159
+ const transfersSet = transfers || /* @__PURE__ */ new Set();
2160
+ if (!object) {
2161
+ } else if (isTransferable(object)) {
2162
+ transfersSet.add(object);
2163
+ } else if (isTransferable(object.buffer)) {
2164
+ transfersSet.add(object.buffer);
2165
+ } else if (ArrayBuffer.isView(object)) {
2166
+ } else if (recursive && typeof object === "object") {
2167
+ for (const key in object) {
2168
+ getTransferList(object[key], recursive, transfersSet);
2169
+ }
2170
+ }
2171
+ return transfers === void 0 ? Array.from(transfersSet) : [];
2172
+ }
2173
+ function isTransferable(object) {
2174
+ if (!object) {
2175
+ return false;
2176
+ }
2177
+ if (object instanceof ArrayBuffer) {
2178
+ return true;
2179
+ }
2180
+ if (typeof MessagePort !== "undefined" && object instanceof MessagePort) {
2181
+ return true;
2182
+ }
2183
+ if (typeof ImageBitmap !== "undefined" && object instanceof ImageBitmap) {
2184
+ return true;
2185
+ }
2186
+ if (typeof OffscreenCanvas !== "undefined" && object instanceof OffscreenCanvas) {
2187
+ return true;
2188
+ }
2189
+ return false;
2190
+ }
2191
+
2192
+ // ../worker-utils/src/lib/worker-farm/worker-body.ts
2193
+ async function getParentPort() {
2194
+ return parentPort;
2195
+ }
2196
+ var onMessageWrapperMap = /* @__PURE__ */ new Map();
2197
+ var WorkerBody = class {
2198
+ /** Check that we are actually in a worker thread */
2199
+ static async inWorkerThread() {
2200
+ return typeof self !== "undefined" || Boolean(await getParentPort());
2201
+ }
2202
+ /*
2203
+ * (type: WorkerMessageType, payload: WorkerMessagePayload) => any
2204
+ */
2205
+ static set onmessage(onMessage) {
2206
+ async function handleMessage(message) {
2207
+ const parentPort2 = await getParentPort();
2208
+ const { type, payload } = parentPort2 ? message : message.data;
2209
+ onMessage(type, payload);
2210
+ }
2211
+ getParentPort().then((parentPort2) => {
2212
+ if (parentPort2) {
2213
+ parentPort2.on("message", (message) => {
2214
+ handleMessage(message);
2215
+ });
2216
+ parentPort2.on("exit", () => console.debug("Node worker closing"));
2217
+ } else {
2218
+ globalThis.onmessage = handleMessage;
2219
+ }
2220
+ });
2221
+ }
2222
+ static async addEventListener(onMessage) {
2223
+ let onMessageWrapper = onMessageWrapperMap.get(onMessage);
2224
+ if (!onMessageWrapper) {
2225
+ onMessageWrapper = async (message) => {
2226
+ if (!isKnownMessage(message)) {
2227
+ return;
2228
+ }
2229
+ const parentPort3 = await getParentPort();
2230
+ const { type, payload } = parentPort3 ? message : message.data;
2231
+ onMessage(type, payload);
2232
+ };
2233
+ }
2234
+ const parentPort2 = await getParentPort();
2235
+ if (parentPort2) {
2236
+ console.error("not implemented");
2237
+ } else {
2238
+ globalThis.addEventListener("message", onMessageWrapper);
2239
+ }
2240
+ }
2241
+ static async removeEventListener(onMessage) {
2242
+ const onMessageWrapper = onMessageWrapperMap.get(onMessage);
2243
+ onMessageWrapperMap.delete(onMessage);
2244
+ const parentPort2 = await getParentPort();
2245
+ if (parentPort2) {
2246
+ console.error("not implemented");
2247
+ } else {
2248
+ globalThis.removeEventListener("message", onMessageWrapper);
2249
+ }
2250
+ }
2251
+ /**
2252
+ * Send a message from a worker to creating thread (main thread)
2253
+ * @param type
2254
+ * @param payload
2255
+ */
2256
+ static async postMessage(type, payload) {
2257
+ const data = { source: "loaders.gl", type, payload };
2258
+ const transferList = getTransferList(payload);
2259
+ const parentPort2 = await getParentPort();
2260
+ if (parentPort2) {
2261
+ parentPort2.postMessage(data, transferList);
2262
+ } else {
2263
+ globalThis.postMessage(data, transferList);
2264
+ }
2265
+ }
2266
+ };
2267
+ function isKnownMessage(message) {
2268
+ const { type, data } = message;
2269
+ return type === "message" && data && typeof data.source === "string" && data.source.startsWith("loaders.gl");
2270
+ }
2271
+
2272
+ // ../loader-utils/src/lib/worker-loader-utils/create-loader-worker.ts
2273
+ var requestId = 0;
2274
+ async function createLoaderWorker(loader) {
2275
+ if (!await WorkerBody.inWorkerThread()) {
2276
+ return;
2277
+ }
2278
+ WorkerBody.onmessage = async (type, payload) => {
2279
+ switch (type) {
2280
+ case "process":
2281
+ try {
2282
+ const { input, options = {}, context = {} } = payload;
2283
+ const result = await parseData({
2284
+ loader,
2285
+ arrayBuffer: input,
2286
+ options,
2287
+ // @ts-expect-error fetch missing
2288
+ context: {
2289
+ ...context,
2290
+ _parse: parseOnMainThread
2291
+ }
2292
+ });
2293
+ WorkerBody.postMessage("done", { result });
2294
+ } catch (error) {
2295
+ const message = error instanceof Error ? error.message : "";
2296
+ WorkerBody.postMessage("error", { error: message });
2297
+ }
2298
+ break;
2299
+ default:
2300
+ }
2301
+ };
2302
+ }
2303
+ function parseOnMainThread(arrayBuffer, loader, options, context) {
2304
+ return new Promise((resolve, reject) => {
2305
+ const id = requestId++;
2306
+ const onMessage = (type, payload2) => {
2307
+ if (payload2.id !== id) {
2308
+ return;
2309
+ }
2310
+ switch (type) {
2311
+ case "done":
2312
+ WorkerBody.removeEventListener(onMessage);
2313
+ resolve(payload2.result);
2314
+ break;
2315
+ case "error":
2316
+ WorkerBody.removeEventListener(onMessage);
2317
+ reject(payload2.error);
2318
+ break;
2319
+ default:
2320
+ }
2321
+ };
2322
+ WorkerBody.addEventListener(onMessage);
2323
+ const payload = { id, input: arrayBuffer, options };
2324
+ WorkerBody.postMessage("process", payload);
2325
+ });
1970
2326
  }
1971
- function project(data, x0, y0, size) {
2327
+ async function parseData({
2328
+ loader,
2329
+ arrayBuffer,
2330
+ options,
2331
+ context
2332
+ }) {
2333
+ let data;
2334
+ let parser;
2335
+ if (loader.parseSync || loader.parse) {
2336
+ data = arrayBuffer;
2337
+ parser = loader.parseSync || loader.parse;
2338
+ } else if (loader.parseTextSync) {
2339
+ const textDecoder = new TextDecoder();
2340
+ data = textDecoder.decode(arrayBuffer);
2341
+ parser = loader.parseTextSync;
2342
+ } else {
2343
+ throw new Error(`Could not load data with ${loader.name} loader`);
2344
+ }
2345
+ options = {
2346
+ ...options,
2347
+ modules: loader && loader.options && loader.options.modules || {},
2348
+ worker: false
2349
+ };
2350
+ return await parser(data, { ...options }, context, loader);
2351
+ }
2352
+
2353
+ // src/lib/parse-mvt.ts
2354
+ var import_pbf = __toESM(require_pbf(), 1);
2355
+
2356
+ // src/lib/utils/geometry-utils.ts
2357
+ function signedArea(ring) {
2358
+ let sum = 0;
2359
+ for (let i = 0, j = ring.length - 1, p1, p2; i < ring.length; j = i++) {
2360
+ p1 = ring[i];
2361
+ p2 = ring[j];
2362
+ sum += (p2[0] - p1[0]) * (p1[1] + p2[1]);
2363
+ }
2364
+ return sum;
2365
+ }
2366
+ function projectToLngLatFlat(data, tileIndex, extent) {
2367
+ const { x, y, z } = tileIndex;
2368
+ const size = extent * Math.pow(2, z);
2369
+ const x0 = extent * x;
2370
+ const y0 = extent * y;
1972
2371
  for (let j = 0, jl = data.length; j < jl; j += 2) {
1973
2372
  data[j] = (data[j] + x0) * 360 / size - 180;
1974
2373
  const y2 = 180 - (data[j + 1] + y0) * 360 / size;
1975
2374
  data[j + 1] = 360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90;
1976
2375
  }
1977
2376
  }
1978
- function readFeature2(tag, feature, pbf) {
1979
- if (feature && pbf) {
1980
- if (tag === 1)
1981
- feature.id = pbf.readVarint();
1982
- else if (tag === 2)
1983
- readTag2(pbf, feature);
1984
- else if (tag === 3)
1985
- feature.type = pbf.readVarint();
1986
- else if (tag === 4)
1987
- feature._geometry = pbf.pos;
2377
+ function classifyRings(rings) {
2378
+ const len = rings.length;
2379
+ if (len <= 1)
2380
+ return [rings];
2381
+ const polygons = [];
2382
+ let polygon;
2383
+ let ccw;
2384
+ for (let i = 0; i < len; i++) {
2385
+ const area2 = signedArea(rings[i]);
2386
+ if (area2 === 0)
2387
+ continue;
2388
+ if (ccw === void 0)
2389
+ ccw = area2 < 0;
2390
+ if (ccw === area2 < 0) {
2391
+ if (polygon)
2392
+ polygons.push(polygon);
2393
+ polygon = [rings[i]];
2394
+ } else if (polygon)
2395
+ polygon.push(rings[i]);
1988
2396
  }
2397
+ if (polygon)
2398
+ polygons.push(polygon);
2399
+ return polygons;
1989
2400
  }
1990
- function readTag2(pbf, feature) {
1991
- const end = pbf.readVarint() + pbf.pos;
1992
- while (pbf.pos < end) {
1993
- const key = feature._keys[pbf.readVarint()];
1994
- const value = feature._values[pbf.readVarint()];
1995
- feature.properties[key] = value;
2401
+ function classifyRingsFlat(geom) {
2402
+ const len = geom.indices.length;
2403
+ const type = "Polygon";
2404
+ if (len <= 1) {
2405
+ return {
2406
+ type,
2407
+ data: geom.data,
2408
+ areas: [[getPolygonSignedArea(geom.data)]],
2409
+ indices: [geom.indices]
2410
+ };
2411
+ }
2412
+ const areas = [];
2413
+ const polygons = [];
2414
+ let ringAreas = [];
2415
+ let polygon = [];
2416
+ let ccw;
2417
+ let offset = 0;
2418
+ for (let endIndex, i = 0, startIndex; i < len; i++) {
2419
+ startIndex = geom.indices[i] - offset;
2420
+ endIndex = geom.indices[i + 1] - offset || geom.data.length;
2421
+ const shape = geom.data.slice(startIndex, endIndex);
2422
+ const area2 = getPolygonSignedArea(shape);
2423
+ if (area2 === 0) {
2424
+ const before = geom.data.slice(0, startIndex);
2425
+ const after = geom.data.slice(endIndex);
2426
+ geom.data = before.concat(after);
2427
+ offset += endIndex - startIndex;
2428
+ continue;
2429
+ }
2430
+ if (ccw === void 0)
2431
+ ccw = area2 < 0;
2432
+ if (ccw === area2 < 0) {
2433
+ if (polygon.length) {
2434
+ areas.push(ringAreas);
2435
+ polygons.push(polygon);
2436
+ }
2437
+ polygon = [startIndex];
2438
+ ringAreas = [area2];
2439
+ } else {
2440
+ ringAreas.push(area2);
2441
+ polygon.push(startIndex);
2442
+ }
1996
2443
  }
2444
+ if (ringAreas)
2445
+ areas.push(ringAreas);
2446
+ if (polygon.length)
2447
+ polygons.push(polygon);
2448
+ return { type, areas, indices: polygons, data: geom.data };
1997
2449
  }
1998
2450
 
1999
- // src/lib/binary-vector-tile/vector-tile-feature.ts
2000
- var endPos;
2001
- var cmd;
2002
- var cmdLen;
2003
- var length;
2004
- var x;
2005
- var y;
2006
- var i;
2007
- var BinaryVectorTileFeature = class {
2451
+ // src/lib/vector-tile/vector-tile-feature.ts
2452
+ var VectorTileFeature = class {
2008
2453
  properties;
2009
2454
  extent;
2010
2455
  type;
@@ -2025,23 +2470,57 @@
2025
2470
  this._keys = keys;
2026
2471
  this._values = values;
2027
2472
  this._geometryInfo = geometryInfo;
2028
- pbf.readFields(readFeature2, this, end);
2473
+ pbf.readFields(readFeature, this, end);
2029
2474
  }
2030
- // eslint-disable-next-line complexity, max-statements
2031
- loadGeometry() {
2475
+ toGeoJSON(options) {
2476
+ const coords = this.loadGeometry();
2477
+ if (typeof options === "function") {
2478
+ return _toGeoJSON(this, coords, options);
2479
+ }
2480
+ const { x, y, z } = options;
2481
+ const size = this.extent * Math.pow(2, z);
2482
+ const x0 = this.extent * x;
2483
+ const y0 = this.extent * y;
2484
+ function project(line) {
2485
+ for (let j = 0; j < line.length; j++) {
2486
+ const p = line[j];
2487
+ p[0] = (p[0] + x0) * 360 / size - 180;
2488
+ const y2 = 180 - (p[1] + y0) * 360 / size;
2489
+ p[1] = 360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90;
2490
+ }
2491
+ }
2492
+ return _toGeoJSON(this, coords, project);
2493
+ }
2494
+ /**
2495
+ *
2496
+ * @param options
2497
+ * @returns
2498
+ */
2499
+ toBinaryCoordinates(options) {
2500
+ if (typeof options === "function") {
2501
+ return this._toBinaryCoordinates(options);
2502
+ }
2503
+ const tileIndex = options;
2504
+ return this._toBinaryCoordinates(
2505
+ (data) => projectToLngLatFlat(data, tileIndex, this.extent)
2506
+ );
2507
+ }
2508
+ // eslint-disable-next-line max-statements
2509
+ bbox() {
2032
2510
  const pbf = this._pbf;
2033
2511
  pbf.pos = this._geometry;
2034
- endPos = pbf.readVarint() + pbf.pos;
2035
- cmd = 1;
2036
- length = 0;
2037
- x = 0;
2038
- y = 0;
2039
- i = 0;
2040
- const indices = [];
2041
- const data = [];
2042
- while (pbf.pos < endPos) {
2512
+ const end = pbf.readVarint() + pbf.pos;
2513
+ let cmd = 1;
2514
+ let length = 0;
2515
+ let x = 0;
2516
+ let y = 0;
2517
+ let x1 = Infinity;
2518
+ let x2 = -Infinity;
2519
+ let y1 = Infinity;
2520
+ let y2 = -Infinity;
2521
+ while (pbf.pos < end) {
2043
2522
  if (length <= 0) {
2044
- cmdLen = pbf.readVarint();
2523
+ const cmdLen = pbf.readVarint();
2045
2524
  cmd = cmdLen & 7;
2046
2525
  length = cmdLen >> 3;
2047
2526
  }
@@ -2049,30 +2528,28 @@
2049
2528
  if (cmd === 1 || cmd === 2) {
2050
2529
  x += pbf.readSVarint();
2051
2530
  y += pbf.readSVarint();
2052
- if (cmd === 1) {
2053
- indices.push(i);
2054
- }
2055
- data.push(x, y);
2056
- i += 2;
2057
- } else if (cmd === 7) {
2058
- if (i > 0) {
2059
- const start = indices[indices.length - 1];
2060
- data.push(data[start], data[start + 1]);
2061
- i += 2;
2062
- }
2063
- } else {
2531
+ if (x < x1)
2532
+ x1 = x;
2533
+ if (x > x2)
2534
+ x2 = x;
2535
+ if (y < y1)
2536
+ y1 = y;
2537
+ if (y > y2)
2538
+ y2 = y;
2539
+ } else if (cmd !== 7) {
2064
2540
  throw new Error(`unknown command ${cmd}`);
2065
2541
  }
2066
2542
  }
2067
- return { data, indices };
2543
+ return [x1, y1, x2, y2];
2068
2544
  }
2545
+ // BINARY HELPERS
2069
2546
  /**
2070
2547
  *
2071
2548
  * @param transform
2072
2549
  * @returns result
2073
2550
  */
2074
2551
  _toBinaryCoordinates(transform) {
2075
- const geom = this.loadGeometry();
2552
+ const geom = this.loadFlatGeometry();
2076
2553
  let geometry;
2077
2554
  transform(geom.data, this);
2078
2555
  const coordLength = 2;
@@ -2089,7 +2566,7 @@
2089
2566
  geometry = { type: "LineString", ...geom };
2090
2567
  break;
2091
2568
  case 3:
2092
- geometry = classifyRings2(geom);
2569
+ geometry = classifyRingsFlat(geom);
2093
2570
  this._geometryInfo.polygonFeaturesCount++;
2094
2571
  this._geometryInfo.polygonObjectsCount += geometry.indices.length;
2095
2572
  for (const indices of geometry.indices) {
@@ -2106,20 +2583,165 @@
2106
2583
  }
2107
2584
  return result;
2108
2585
  }
2109
- toBinaryCoordinates(options) {
2110
- if (typeof options === "function") {
2111
- return this._toBinaryCoordinates(options);
2586
+ // GEOJSON HELPER
2587
+ // eslint-disable-next-line complexity, max-statements
2588
+ loadGeometry() {
2589
+ const pbf = this._pbf;
2590
+ pbf.pos = this._geometry;
2591
+ const end = pbf.readVarint() + pbf.pos;
2592
+ let cmd = 1;
2593
+ let length = 0;
2594
+ let x = 0;
2595
+ let y = 0;
2596
+ const lines = [];
2597
+ let line;
2598
+ while (pbf.pos < end) {
2599
+ if (length <= 0) {
2600
+ const cmdLen = pbf.readVarint();
2601
+ cmd = cmdLen & 7;
2602
+ length = cmdLen >> 3;
2603
+ }
2604
+ length--;
2605
+ switch (cmd) {
2606
+ case 1:
2607
+ case 2:
2608
+ x += pbf.readSVarint();
2609
+ y += pbf.readSVarint();
2610
+ if (cmd === 1) {
2611
+ if (line)
2612
+ lines.push(line);
2613
+ line = [];
2614
+ }
2615
+ if (line)
2616
+ line.push([x, y]);
2617
+ break;
2618
+ case 7:
2619
+ if (line) {
2620
+ line.push(line[0].slice());
2621
+ }
2622
+ break;
2623
+ default:
2624
+ throw new Error(`unknown command ${cmd}`);
2625
+ }
2112
2626
  }
2113
- const { x: x2, y: y2, z } = options;
2114
- const size = this.extent * Math.pow(2, z);
2115
- const x0 = this.extent * x2;
2116
- const y0 = this.extent * y2;
2117
- return this._toBinaryCoordinates((data) => project(data, x0, y0, size));
2627
+ if (line)
2628
+ lines.push(line);
2629
+ return lines;
2630
+ }
2631
+ // eslint-disable-next-line complexity, max-statements
2632
+ loadFlatGeometry() {
2633
+ const pbf = this._pbf;
2634
+ pbf.pos = this._geometry;
2635
+ const endPos = pbf.readVarint() + pbf.pos;
2636
+ let cmd = 1;
2637
+ let cmdLen;
2638
+ let length = 0;
2639
+ let x = 0;
2640
+ let y = 0;
2641
+ let i = 0;
2642
+ const indices = [];
2643
+ const data = [];
2644
+ while (pbf.pos < endPos) {
2645
+ if (length <= 0) {
2646
+ cmdLen = pbf.readVarint();
2647
+ cmd = cmdLen & 7;
2648
+ length = cmdLen >> 3;
2649
+ }
2650
+ length--;
2651
+ if (cmd === 1 || cmd === 2) {
2652
+ x += pbf.readSVarint();
2653
+ y += pbf.readSVarint();
2654
+ if (cmd === 1) {
2655
+ indices.push(i);
2656
+ }
2657
+ data.push(x, y);
2658
+ i += 2;
2659
+ } else if (cmd === 7) {
2660
+ if (i > 0) {
2661
+ const start = indices[indices.length - 1];
2662
+ data.push(data[start], data[start + 1]);
2663
+ i += 2;
2664
+ }
2665
+ } else {
2666
+ throw new Error(`unknown command ${cmd}`);
2667
+ }
2668
+ }
2669
+ return { data, indices };
2118
2670
  }
2119
2671
  };
2672
+ __publicField(VectorTileFeature, "types", ["Unknown", "Point", "LineString", "Polygon"]);
2673
+ function _toGeoJSON(vtFeature, coords, transform) {
2674
+ let type = VectorTileFeature.types[vtFeature.type];
2675
+ let i;
2676
+ let j;
2677
+ let coordinates;
2678
+ switch (vtFeature.type) {
2679
+ case 1:
2680
+ const points = [];
2681
+ for (i = 0; i < coords.length; i++) {
2682
+ points[i] = coords[i][0];
2683
+ }
2684
+ coordinates = points;
2685
+ transform(coordinates, vtFeature);
2686
+ break;
2687
+ case 2:
2688
+ coordinates = coords;
2689
+ for (i = 0; i < coordinates.length; i++) {
2690
+ transform(coordinates[i], vtFeature);
2691
+ }
2692
+ break;
2693
+ case 3:
2694
+ coordinates = classifyRings(coords);
2695
+ for (i = 0; i < coordinates.length; i++) {
2696
+ for (j = 0; j < coordinates[i].length; j++) {
2697
+ transform(coordinates[i][j], vtFeature);
2698
+ }
2699
+ }
2700
+ break;
2701
+ default:
2702
+ throw new Error("illegal vector tile type");
2703
+ }
2704
+ if (coordinates.length === 1) {
2705
+ coordinates = coordinates[0];
2706
+ } else {
2707
+ type = `Multi${type}`;
2708
+ }
2709
+ const result = {
2710
+ type: "Feature",
2711
+ geometry: {
2712
+ type,
2713
+ coordinates
2714
+ },
2715
+ properties: vtFeature.properties
2716
+ };
2717
+ if (vtFeature.id !== null) {
2718
+ result.id = vtFeature.id;
2719
+ }
2720
+ return result;
2721
+ }
2722
+ function readFeature(tag, feature, pbf) {
2723
+ if (feature && pbf) {
2724
+ if (tag === 1)
2725
+ feature.id = pbf.readVarint();
2726
+ else if (tag === 2)
2727
+ readTag(pbf, feature);
2728
+ else if (tag === 3)
2729
+ feature.type = pbf.readVarint();
2730
+ else if (tag === 4)
2731
+ feature._geometry = pbf.pos;
2732
+ }
2733
+ }
2734
+ function readTag(pbf, feature) {
2735
+ const end = pbf.readVarint() + pbf.pos;
2736
+ while (pbf.pos < end) {
2737
+ const key = feature._keys[pbf.readVarint()];
2738
+ const value = feature._values[pbf.readVarint()];
2739
+ feature.properties[key] = value;
2740
+ }
2741
+ }
2120
2742
 
2121
- // src/lib/binary-vector-tile/vector-tile-layer.ts
2122
- var BinaryVectorTileLayer = class {
2743
+ // src/lib/vector-tile/vector-tile-layer.ts
2744
+ var VectorTileLayer = class {
2123
2745
  version;
2124
2746
  name;
2125
2747
  extent;
@@ -2137,23 +2759,36 @@
2137
2759
  this._keys = [];
2138
2760
  this._values = [];
2139
2761
  this._features = [];
2140
- pbf.readFields(readLayer2, this, end);
2762
+ pbf.readFields(readLayer, this, end);
2141
2763
  this.length = this._features.length;
2142
2764
  }
2143
2765
  /**
2144
- * return feature `i` from this layer as a `BinaryVectorTileFeature`
2766
+ * return feature `i` from this layer as a `VectorTileFeature`
2767
+ * @param index
2768
+ * @returns feature
2769
+ */
2770
+ getGeoJSONFeature(i) {
2771
+ if (i < 0 || i >= this._features.length) {
2772
+ throw new Error("feature index out of bounds");
2773
+ }
2774
+ this._pbf.pos = this._features[i];
2775
+ const end = this._pbf.readVarint() + this._pbf.pos;
2776
+ return new VectorTileFeature(this._pbf, end, this.extent, this._keys, this._values);
2777
+ }
2778
+ /**
2779
+ * return binary feature `i` from this layer as a `VectorTileFeature`
2145
2780
  *
2146
2781
  * @param index
2147
2782
  * @param geometryInfo
2148
- * @returns {BinaryVectorTileFeature}
2783
+ * @returns binary feature
2149
2784
  */
2150
- feature(i2, geometryInfo) {
2151
- if (i2 < 0 || i2 >= this._features.length) {
2785
+ getBinaryFeature(i, geometryInfo) {
2786
+ if (i < 0 || i >= this._features.length) {
2152
2787
  throw new Error("feature index out of bounds");
2153
2788
  }
2154
- this._pbf.pos = this._features[i2];
2789
+ this._pbf.pos = this._features[i];
2155
2790
  const end = this._pbf.readVarint() + this._pbf.pos;
2156
- return new BinaryVectorTileFeature(
2791
+ return new VectorTileFeature(
2157
2792
  this._pbf,
2158
2793
  end,
2159
2794
  this.extent,
@@ -2163,7 +2798,7 @@
2163
2798
  );
2164
2799
  }
2165
2800
  };
2166
- function readLayer2(tag, layer, pbf) {
2801
+ function readLayer(tag, layer, pbf) {
2167
2802
  if (layer && pbf) {
2168
2803
  if (tag === 15)
2169
2804
  layer.version = pbf.readVarint();
@@ -2176,10 +2811,10 @@
2176
2811
  else if (tag === 3)
2177
2812
  layer._keys.push(pbf.readString());
2178
2813
  else if (tag === 4)
2179
- layer._values.push(readValueMessage2(pbf));
2814
+ layer._values.push(readValueMessage(pbf));
2180
2815
  }
2181
2816
  }
2182
- function readValueMessage2(pbf) {
2817
+ function readValueMessage(pbf) {
2183
2818
  let value = null;
2184
2819
  const end = pbf.readVarint() + pbf.pos;
2185
2820
  while (pbf.pos < end) {
@@ -2189,17 +2824,17 @@
2189
2824
  return value;
2190
2825
  }
2191
2826
 
2192
- // src/lib/binary-vector-tile/vector-tile.ts
2193
- var BinaryVectorTile = class {
2827
+ // src/lib/vector-tile/vector-tile.ts
2828
+ var VectorTile = class {
2194
2829
  layers;
2195
2830
  constructor(pbf, end) {
2196
- this.layers = pbf.readFields(readTile2, {}, end);
2831
+ this.layers = pbf.readFields(readTile, {}, end);
2197
2832
  }
2198
2833
  };
2199
- function readTile2(tag, layers, pbf) {
2834
+ function readTile(tag, layers, pbf) {
2200
2835
  if (tag === 3) {
2201
2836
  if (pbf) {
2202
- const layer = new BinaryVectorTileLayer(pbf, pbf.readVarint() + pbf.pos);
2837
+ const layer = new VectorTileLayer(pbf, pbf.readVarint() + pbf.pos);
2203
2838
  if (layer.length && layers) {
2204
2839
  layers[layer.name] = layer;
2205
2840
  }
@@ -2209,7 +2844,7 @@
2209
2844
 
2210
2845
  // src/lib/parse-mvt.ts
2211
2846
  function parseMVT(arrayBuffer, options) {
2212
- const mvtOptions = normalizeOptions(options);
2847
+ const mvtOptions = checkOptions(options);
2213
2848
  const shape = options?.gis?.format || options?.mvt?.shape || options?.shape;
2214
2849
  switch (shape) {
2215
2850
  case "columnar-table":
@@ -2255,15 +2890,15 @@
2255
2890
  if (arrayBuffer.byteLength <= 0) {
2256
2891
  return [features, geometryInfo];
2257
2892
  }
2258
- const tile = new BinaryVectorTile(new import_pbf.default(arrayBuffer));
2893
+ const tile = new VectorTile(new import_pbf.default(arrayBuffer));
2259
2894
  const selectedLayers = options && Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);
2260
2895
  selectedLayers.forEach((layerName) => {
2261
2896
  const vectorTileLayer = tile.layers[layerName];
2262
2897
  if (!vectorTileLayer) {
2263
2898
  return;
2264
2899
  }
2265
- for (let i2 = 0; i2 < vectorTileLayer.length; i2++) {
2266
- const vectorTileFeature = vectorTileLayer.feature(i2, geometryInfo);
2900
+ for (let i = 0; i < vectorTileLayer.length; i++) {
2901
+ const vectorTileFeature = vectorTileLayer.getBinaryFeature(i, geometryInfo);
2267
2902
  const decodedFeature = getDecodedFeatureBinary(vectorTileFeature, options, layerName);
2268
2903
  features.push(decodedFeature);
2269
2904
  }
@@ -2282,24 +2917,24 @@
2282
2917
  if (!vectorTileLayer) {
2283
2918
  return;
2284
2919
  }
2285
- for (let i2 = 0; i2 < vectorTileLayer.length; i2++) {
2286
- const vectorTileFeature = vectorTileLayer.feature(i2);
2920
+ for (let i = 0; i < vectorTileLayer.length; i++) {
2921
+ const vectorTileFeature = vectorTileLayer.getGeoJSONFeature(i);
2287
2922
  const decodedFeature = getDecodedFeature(vectorTileFeature, options, layerName);
2288
2923
  features.push(decodedFeature);
2289
2924
  }
2290
2925
  });
2291
2926
  return features;
2292
2927
  }
2293
- function normalizeOptions(options) {
2928
+ function checkOptions(options) {
2294
2929
  if (!options?.mvt) {
2295
2930
  throw new Error("mvt options required");
2296
2931
  }
2297
- const wgs84Coordinates = options.mvt?.coordinates === "wgs84";
2298
- const { tileIndex } = options.mvt;
2299
- const hasTileIndex = tileIndex && Number.isFinite(tileIndex.x) && Number.isFinite(tileIndex.y) && Number.isFinite(tileIndex.z);
2300
- if (wgs84Coordinates && !hasTileIndex) {
2932
+ if (options.mvt?.coordinates === "wgs84" && !options.mvt.tileIndex) {
2301
2933
  throw new Error("MVT Loader: WGS84 coordinates need tileIndex property");
2302
2934
  }
2935
+ if (options.gis) {
2936
+ log.warn('MVTLoader: "options.gis" is deprecated, use "options.mvt.shape" instead')();
2937
+ }
2303
2938
  return options.mvt;
2304
2939
  }
2305
2940
  function getDecodedFeature(feature, options, layerName) {
@@ -2308,6 +2943,7 @@
2308
2943
  options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinates
2309
2944
  );
2310
2945
  if (options.layerProperty) {
2946
+ decodedFeature.properties ||= {};
2311
2947
  decodedFeature.properties[options.layerProperty] = layerName;
2312
2948
  }
2313
2949
  return decodedFeature;
@@ -2324,28 +2960,28 @@
2324
2960
  }
2325
2961
  function transformToLocalCoordinates(line, feature) {
2326
2962
  const { extent } = feature;
2327
- for (let i2 = 0; i2 < line.length; i2++) {
2328
- const p = line[i2];
2963
+ for (let i = 0; i < line.length; i++) {
2964
+ const p = line[i];
2329
2965
  p[0] /= extent;
2330
2966
  p[1] /= extent;
2331
2967
  }
2332
2968
  }
2333
2969
  function transformToLocalCoordinatesBinary(data, feature) {
2334
2970
  const { extent } = feature;
2335
- for (let i2 = 0, il = data.length; i2 < il; ++i2) {
2336
- data[i2] /= extent;
2971
+ for (let i = 0, il = data.length; i < il; ++i) {
2972
+ data[i] /= extent;
2337
2973
  }
2338
2974
  }
2339
2975
 
2340
2976
  // src/mvt-loader.ts
2341
- var VERSION = true ? "4.2.0-beta.2" : "latest";
2977
+ var VERSION3 = true ? "4.2.0" : "latest";
2342
2978
  var MVTWorkerLoader = {
2343
2979
  dataType: null,
2344
2980
  batchType: null,
2345
2981
  name: "Mapbox Vector Tile",
2346
2982
  id: "mvt",
2347
2983
  module: "mvt",
2348
- version: VERSION,
2984
+ version: VERSION3,
2349
2985
  // Note: ArcGIS uses '.pbf' extension and 'application/octet-stream'
2350
2986
  extensions: ["mvt", "pbf"],
2351
2987
  mimeTypes: [
@@ -2362,7 +2998,7 @@
2362
2998
  coordinates: "local",
2363
2999
  layerProperty: "layerName",
2364
3000
  layers: void 0,
2365
- tileIndex: null
3001
+ tileIndex: void 0
2366
3002
  }
2367
3003
  }
2368
3004
  };
@@ -2373,205 +3009,6 @@
2373
3009
  binary: true
2374
3010
  };
2375
3011
 
2376
- // ../worker-utils/src/lib/node/worker_threads-browser.ts
2377
- var parentPort = null;
2378
-
2379
- // ../worker-utils/src/lib/worker-utils/get-transfer-list.ts
2380
- function getTransferList(object, recursive = true, transfers) {
2381
- const transfersSet = transfers || /* @__PURE__ */ new Set();
2382
- if (!object) {
2383
- } else if (isTransferable(object)) {
2384
- transfersSet.add(object);
2385
- } else if (isTransferable(object.buffer)) {
2386
- transfersSet.add(object.buffer);
2387
- } else if (ArrayBuffer.isView(object)) {
2388
- } else if (recursive && typeof object === "object") {
2389
- for (const key in object) {
2390
- getTransferList(object[key], recursive, transfersSet);
2391
- }
2392
- }
2393
- return transfers === void 0 ? Array.from(transfersSet) : [];
2394
- }
2395
- function isTransferable(object) {
2396
- if (!object) {
2397
- return false;
2398
- }
2399
- if (object instanceof ArrayBuffer) {
2400
- return true;
2401
- }
2402
- if (typeof MessagePort !== "undefined" && object instanceof MessagePort) {
2403
- return true;
2404
- }
2405
- if (typeof ImageBitmap !== "undefined" && object instanceof ImageBitmap) {
2406
- return true;
2407
- }
2408
- if (typeof OffscreenCanvas !== "undefined" && object instanceof OffscreenCanvas) {
2409
- return true;
2410
- }
2411
- return false;
2412
- }
2413
-
2414
- // ../worker-utils/src/lib/worker-farm/worker-body.ts
2415
- async function getParentPort() {
2416
- return parentPort;
2417
- }
2418
- var onMessageWrapperMap = /* @__PURE__ */ new Map();
2419
- var WorkerBody = class {
2420
- /** Check that we are actually in a worker thread */
2421
- static async inWorkerThread() {
2422
- return typeof self !== "undefined" || Boolean(await getParentPort());
2423
- }
2424
- /*
2425
- * (type: WorkerMessageType, payload: WorkerMessagePayload) => any
2426
- */
2427
- static set onmessage(onMessage) {
2428
- async function handleMessage(message) {
2429
- const parentPort2 = await getParentPort();
2430
- const { type, payload } = parentPort2 ? message : message.data;
2431
- onMessage(type, payload);
2432
- }
2433
- getParentPort().then((parentPort2) => {
2434
- if (parentPort2) {
2435
- parentPort2.on("message", (message) => {
2436
- handleMessage(message);
2437
- });
2438
- parentPort2.on("exit", () => console.debug("Node worker closing"));
2439
- } else {
2440
- globalThis.onmessage = handleMessage;
2441
- }
2442
- });
2443
- }
2444
- static async addEventListener(onMessage) {
2445
- let onMessageWrapper = onMessageWrapperMap.get(onMessage);
2446
- if (!onMessageWrapper) {
2447
- onMessageWrapper = async (message) => {
2448
- if (!isKnownMessage(message)) {
2449
- return;
2450
- }
2451
- const parentPort3 = await getParentPort();
2452
- const { type, payload } = parentPort3 ? message : message.data;
2453
- onMessage(type, payload);
2454
- };
2455
- }
2456
- const parentPort2 = await getParentPort();
2457
- if (parentPort2) {
2458
- console.error("not implemented");
2459
- } else {
2460
- globalThis.addEventListener("message", onMessageWrapper);
2461
- }
2462
- }
2463
- static async removeEventListener(onMessage) {
2464
- const onMessageWrapper = onMessageWrapperMap.get(onMessage);
2465
- onMessageWrapperMap.delete(onMessage);
2466
- const parentPort2 = await getParentPort();
2467
- if (parentPort2) {
2468
- console.error("not implemented");
2469
- } else {
2470
- globalThis.removeEventListener("message", onMessageWrapper);
2471
- }
2472
- }
2473
- /**
2474
- * Send a message from a worker to creating thread (main thread)
2475
- * @param type
2476
- * @param payload
2477
- */
2478
- static async postMessage(type, payload) {
2479
- const data = { source: "loaders.gl", type, payload };
2480
- const transferList = getTransferList(payload);
2481
- const parentPort2 = await getParentPort();
2482
- if (parentPort2) {
2483
- parentPort2.postMessage(data, transferList);
2484
- } else {
2485
- globalThis.postMessage(data, transferList);
2486
- }
2487
- }
2488
- };
2489
- function isKnownMessage(message) {
2490
- const { type, data } = message;
2491
- return type === "message" && data && typeof data.source === "string" && data.source.startsWith("loaders.gl");
2492
- }
2493
-
2494
- // ../loader-utils/src/lib/worker-loader-utils/create-loader-worker.ts
2495
- var requestId = 0;
2496
- async function createLoaderWorker(loader) {
2497
- if (!await WorkerBody.inWorkerThread()) {
2498
- return;
2499
- }
2500
- WorkerBody.onmessage = async (type, payload) => {
2501
- switch (type) {
2502
- case "process":
2503
- try {
2504
- const { input, options = {}, context = {} } = payload;
2505
- const result = await parseData({
2506
- loader,
2507
- arrayBuffer: input,
2508
- options,
2509
- // @ts-expect-error fetch missing
2510
- context: {
2511
- ...context,
2512
- _parse: parseOnMainThread
2513
- }
2514
- });
2515
- WorkerBody.postMessage("done", { result });
2516
- } catch (error) {
2517
- const message = error instanceof Error ? error.message : "";
2518
- WorkerBody.postMessage("error", { error: message });
2519
- }
2520
- break;
2521
- default:
2522
- }
2523
- };
2524
- }
2525
- function parseOnMainThread(arrayBuffer, loader, options, context) {
2526
- return new Promise((resolve, reject) => {
2527
- const id = requestId++;
2528
- const onMessage = (type, payload2) => {
2529
- if (payload2.id !== id) {
2530
- return;
2531
- }
2532
- switch (type) {
2533
- case "done":
2534
- WorkerBody.removeEventListener(onMessage);
2535
- resolve(payload2.result);
2536
- break;
2537
- case "error":
2538
- WorkerBody.removeEventListener(onMessage);
2539
- reject(payload2.error);
2540
- break;
2541
- default:
2542
- }
2543
- };
2544
- WorkerBody.addEventListener(onMessage);
2545
- const payload = { id, input: arrayBuffer, options };
2546
- WorkerBody.postMessage("process", payload);
2547
- });
2548
- }
2549
- async function parseData({
2550
- loader,
2551
- arrayBuffer,
2552
- options,
2553
- context
2554
- }) {
2555
- let data;
2556
- let parser;
2557
- if (loader.parseSync || loader.parse) {
2558
- data = arrayBuffer;
2559
- parser = loader.parseSync || loader.parse;
2560
- } else if (loader.parseTextSync) {
2561
- const textDecoder = new TextDecoder();
2562
- data = textDecoder.decode(arrayBuffer);
2563
- parser = loader.parseTextSync;
2564
- } else {
2565
- throw new Error(`Could not load data with ${loader.name} loader`);
2566
- }
2567
- options = {
2568
- ...options,
2569
- modules: loader && loader.options && loader.options.modules || {},
2570
- worker: false
2571
- };
2572
- return await parser(data, { ...options }, context, loader);
2573
- }
2574
-
2575
3012
  // src/workers/mvt-worker.ts
2576
3013
  createLoaderWorker(MVTLoader);
2577
3014
  })();