@loaders.gl/mvt 4.0.0-beta.2 → 4.0.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/dist/{dist.min.js → dist.dev.js} +2258 -1731
  2. package/dist/helpers/binary-util-functions.js.map +1 -0
  3. package/dist/helpers/mapbox-util-functions.js.map +1 -0
  4. package/dist/index.cjs +1800 -0
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +5 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/{esm/lib → lib}/binary-vector-tile/vector-tile-feature.js +12 -13
  10. package/dist/lib/binary-vector-tile/vector-tile-feature.js.map +1 -0
  11. package/dist/{esm/lib → lib}/binary-vector-tile/vector-tile-layer.js +9 -10
  12. package/dist/lib/binary-vector-tile/vector-tile-layer.js.map +1 -0
  13. package/dist/{esm/lib/mapbox-vector-tile → lib/binary-vector-tile}/vector-tile.js +2 -3
  14. package/dist/lib/binary-vector-tile/vector-tile.js.map +1 -0
  15. package/dist/{esm/lib → lib}/geojson-tiler/clip.js +4 -5
  16. package/dist/lib/geojson-tiler/clip.js.map +1 -0
  17. package/dist/{esm/lib → lib}/geojson-tiler/convert.js +2 -2
  18. package/dist/lib/geojson-tiler/convert.js.map +1 -0
  19. package/dist/lib/geojson-tiler/feature.js.map +1 -0
  20. package/dist/{esm/lib → lib}/geojson-tiler/geojson-tiler.js +11 -12
  21. package/dist/lib/geojson-tiler/geojson-tiler.js.map +1 -0
  22. package/dist/lib/geojson-tiler/simplify.js.map +1 -0
  23. package/dist/lib/geojson-tiler/tile.js.map +1 -0
  24. package/dist/lib/geojson-tiler/transform.js.map +1 -0
  25. package/dist/{esm/lib → lib}/geojson-tiler/wrap.js +5 -6
  26. package/dist/lib/geojson-tiler/wrap.js.map +1 -0
  27. package/dist/{esm/lib → lib}/mapbox-vector-tile/vector-tile-feature.js +12 -13
  28. package/dist/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -0
  29. package/dist/{esm/lib → lib}/mapbox-vector-tile/vector-tile-layer.js +9 -10
  30. package/dist/lib/mapbox-vector-tile/vector-tile-layer.js.map +1 -0
  31. package/dist/{esm/lib/binary-vector-tile → lib/mapbox-vector-tile}/vector-tile.js +2 -3
  32. package/dist/lib/mapbox-vector-tile/vector-tile.js.map +1 -0
  33. package/dist/{esm/lib → lib}/parse-mvt.js +2 -2
  34. package/dist/lib/parse-mvt.js.map +1 -0
  35. package/dist/lib/parse-tilejson.js.map +1 -0
  36. package/dist/lib/types.js.map +1 -0
  37. package/dist/{esm/mvt-loader.js → mvt-loader.js} +2 -2
  38. package/dist/mvt-loader.js.map +1 -0
  39. package/dist/mvt-source.d.ts +28 -0
  40. package/dist/mvt-source.d.ts.map +1 -0
  41. package/dist/mvt-source.js +100 -0
  42. package/dist/mvt-source.js.map +1 -0
  43. package/dist/mvt-worker.js +267 -103
  44. package/dist/{esm/tilejson-loader.js → tilejson-loader.js} +2 -2
  45. package/dist/tilejson-loader.js.map +1 -0
  46. package/dist/{esm/workers → workers}/mvt-worker.js +1 -1
  47. package/dist/workers/mvt-worker.js.map +1 -0
  48. package/package.json +19 -10
  49. package/src/index.ts +2 -0
  50. package/src/mvt-source.ts +110 -0
  51. package/dist/bundle.d.ts +0 -2
  52. package/dist/bundle.d.ts.map +0 -1
  53. package/dist/es5/bundle.js +0 -6
  54. package/dist/es5/bundle.js.map +0 -1
  55. package/dist/es5/helpers/binary-util-functions.js +0 -82
  56. package/dist/es5/helpers/binary-util-functions.js.map +0 -1
  57. package/dist/es5/helpers/mapbox-util-functions.js +0 -50
  58. package/dist/es5/helpers/mapbox-util-functions.js.map +0 -1
  59. package/dist/es5/index.js +0 -33
  60. package/dist/es5/index.js.map +0 -1
  61. package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js +0 -168
  62. package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js.map +0 -1
  63. package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js +0 -62
  64. package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js.map +0 -1
  65. package/dist/es5/lib/binary-vector-tile/vector-tile.js +0 -28
  66. package/dist/es5/lib/binary-vector-tile/vector-tile.js.map +0 -1
  67. package/dist/es5/lib/geojson-tiler/clip.js +0 -237
  68. package/dist/es5/lib/geojson-tiler/clip.js.map +0 -1
  69. package/dist/es5/lib/geojson-tiler/convert.js +0 -161
  70. package/dist/es5/lib/geojson-tiler/convert.js.map +0 -1
  71. package/dist/es5/lib/geojson-tiler/feature.js +0 -62
  72. package/dist/es5/lib/geojson-tiler/feature.js.map +0 -1
  73. package/dist/es5/lib/geojson-tiler/geojson-tiler.js +0 -186
  74. package/dist/es5/lib/geojson-tiler/geojson-tiler.js.map +0 -1
  75. package/dist/es5/lib/geojson-tiler/simplify.js +0 -52
  76. package/dist/es5/lib/geojson-tiler/simplify.js.map +0 -1
  77. package/dist/es5/lib/geojson-tiler/tile.js +0 -121
  78. package/dist/es5/lib/geojson-tiler/tile.js.map +0 -1
  79. package/dist/es5/lib/geojson-tiler/transform.js +0 -50
  80. package/dist/es5/lib/geojson-tiler/transform.js.map +0 -1
  81. package/dist/es5/lib/geojson-tiler/wrap.js +0 -122
  82. package/dist/es5/lib/geojson-tiler/wrap.js.map +0 -1
  83. package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js +0 -184
  84. package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js.map +0 -1
  85. package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js +0 -62
  86. package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js.map +0 -1
  87. package/dist/es5/lib/mapbox-vector-tile/vector-tile.js +0 -28
  88. package/dist/es5/lib/mapbox-vector-tile/vector-tile.js.map +0 -1
  89. package/dist/es5/lib/parse-mvt.js +0 -144
  90. package/dist/es5/lib/parse-mvt.js.map +0 -1
  91. package/dist/es5/lib/parse-tilejson.js +0 -186
  92. package/dist/es5/lib/parse-tilejson.js.map +0 -1
  93. package/dist/es5/lib/types.js +0 -2
  94. package/dist/es5/lib/types.js.map +0 -1
  95. package/dist/es5/mvt-loader.js +0 -57
  96. package/dist/es5/mvt-loader.js.map +0 -1
  97. package/dist/es5/tilejson-loader.js +0 -50
  98. package/dist/es5/tilejson-loader.js.map +0 -1
  99. package/dist/es5/workers/mvt-worker.js +0 -6
  100. package/dist/es5/workers/mvt-worker.js.map +0 -1
  101. package/dist/esm/bundle.js +0 -4
  102. package/dist/esm/bundle.js.map +0 -1
  103. package/dist/esm/helpers/binary-util-functions.js.map +0 -1
  104. package/dist/esm/helpers/mapbox-util-functions.js.map +0 -1
  105. package/dist/esm/index.js +0 -4
  106. package/dist/esm/index.js.map +0 -1
  107. package/dist/esm/lib/binary-vector-tile/LICENSE.txt +0 -31
  108. package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js.map +0 -1
  109. package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js.map +0 -1
  110. package/dist/esm/lib/binary-vector-tile/vector-tile.js.map +0 -1
  111. package/dist/esm/lib/geojson-tiler/LICENSE +0 -19
  112. package/dist/esm/lib/geojson-tiler/clip.js.map +0 -1
  113. package/dist/esm/lib/geojson-tiler/convert.js.map +0 -1
  114. package/dist/esm/lib/geojson-tiler/feature.js.map +0 -1
  115. package/dist/esm/lib/geojson-tiler/geojson-tiler.js.map +0 -1
  116. package/dist/esm/lib/geojson-tiler/simplify.js.map +0 -1
  117. package/dist/esm/lib/geojson-tiler/tile.js.map +0 -1
  118. package/dist/esm/lib/geojson-tiler/transform.js.map +0 -1
  119. package/dist/esm/lib/geojson-tiler/wrap.js.map +0 -1
  120. package/dist/esm/lib/mapbox-vector-tile/LICENSE.txt +0 -31
  121. package/dist/esm/lib/mapbox-vector-tile/vector-tile-feature.js.map +0 -1
  122. package/dist/esm/lib/mapbox-vector-tile/vector-tile-layer.js.map +0 -1
  123. package/dist/esm/lib/mapbox-vector-tile/vector-tile.js.map +0 -1
  124. package/dist/esm/lib/parse-mvt.js.map +0 -1
  125. package/dist/esm/lib/parse-tilejson.js.map +0 -1
  126. package/dist/esm/lib/types.js.map +0 -1
  127. package/dist/esm/mvt-loader.js.map +0 -1
  128. package/dist/esm/tilejson-loader.js.map +0 -1
  129. package/dist/esm/workers/mvt-worker.js.map +0 -1
  130. package/src/bundle.ts +0 -4
  131. /package/dist/{esm/helpers → helpers}/binary-util-functions.js +0 -0
  132. /package/dist/{esm/helpers → helpers}/mapbox-util-functions.js +0 -0
  133. /package/dist/{es5/lib → lib}/binary-vector-tile/LICENSE.txt +0 -0
  134. /package/dist/{es5/lib → lib}/geojson-tiler/LICENSE +0 -0
  135. /package/dist/{esm/lib → lib}/geojson-tiler/feature.js +0 -0
  136. /package/dist/{esm/lib → lib}/geojson-tiler/simplify.js +0 -0
  137. /package/dist/{esm/lib → lib}/geojson-tiler/tile.js +0 -0
  138. /package/dist/{esm/lib → lib}/geojson-tiler/transform.js +0 -0
  139. /package/dist/{es5/lib → lib}/mapbox-vector-tile/LICENSE.txt +0 -0
  140. /package/dist/{esm/lib → lib}/parse-tilejson.js +0 -0
  141. /package/dist/{esm/lib → lib}/types.js +0 -0
@@ -1,969 +1,136 @@
1
- (() => {
1
+ (function webpackUniversalModuleDefinition(root, factory) {
2
+ if (typeof exports === 'object' && typeof module === 'object')
3
+ module.exports = factory();
4
+ else if (typeof define === 'function' && define.amd) define([], factory);
5
+ else if (typeof exports === 'object') exports['loader'] = factory();
6
+ else root['loader'] = factory();})(globalThis, function () {
7
+ "use strict";
8
+ var __exports__ = (() => {
2
9
  var __create = Object.create;
3
10
  var __defProp = Object.defineProperty;
4
11
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
12
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
13
  var __getProtoOf = Object.getPrototypeOf;
7
14
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
9
- var __esm = (fn, res) => function __init() {
10
- return fn && (res = (0, fn[Object.keys(fn)[0]])(fn = 0)), res;
11
- };
12
15
  var __commonJS = (cb, mod) => function __require() {
13
- return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
16
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
14
17
  };
15
18
  var __export = (target, all) => {
16
- __markAsModule(target);
17
19
  for (var name in all)
18
20
  __defProp(target, name, { get: all[name], enumerable: true });
19
21
  };
20
- var __reExport = (target, module, desc) => {
21
- if (module && typeof module === "object" || typeof module === "function") {
22
- for (let key of __getOwnPropNames(module))
23
- if (!__hasOwnProp.call(target, key) && key !== "default")
24
- __defProp(target, key, { get: () => module[key], enumerable: !(desc = __getOwnPropDesc(module, key)) || desc.enumerable });
22
+ var __copyProps = (to, from, except, desc) => {
23
+ if (from && typeof from === "object" || typeof from === "function") {
24
+ for (let key of __getOwnPropNames(from))
25
+ if (!__hasOwnProp.call(to, key) && key !== except)
26
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
27
  }
26
- return target;
27
- };
28
- var __toModule = (module) => {
29
- return __reExport(__markAsModule(__defProp(module != null ? __create(__getProtoOf(module)) : {}, "default", module && module.__esModule && "default" in module ? { get: () => module.default, enumerable: true } : { value: module, enumerable: true })), module);
28
+ return to;
30
29
  };
30
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
31
+ // If the importer is in node compatibility mode or this is not an ESM
32
+ // file that has been converted to a CommonJS file using a Babel-
33
+ // compatible transform (i.e. "__esModule" has not been set), then set
34
+ // "default" to the CommonJS "module.exports" for node compatibility.
35
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
36
+ mod
37
+ ));
38
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
31
39
 
32
- // ../../node_modules/@babel/runtime/helpers/esm/typeof.js
33
- var init_typeof = __esm({
34
- "../../node_modules/@babel/runtime/helpers/esm/typeof.js"() {
35
- }
36
- });
37
-
38
- // ../../node_modules/@babel/runtime/helpers/esm/toPrimitive.js
39
- var init_toPrimitive = __esm({
40
- "../../node_modules/@babel/runtime/helpers/esm/toPrimitive.js"() {
41
- init_typeof();
42
- }
43
- });
44
-
45
- // ../../node_modules/@babel/runtime/helpers/esm/toPropertyKey.js
46
- var init_toPropertyKey = __esm({
47
- "../../node_modules/@babel/runtime/helpers/esm/toPropertyKey.js"() {
48
- init_typeof();
49
- init_toPrimitive();
50
- }
51
- });
52
-
53
- // ../../node_modules/@babel/runtime/helpers/esm/defineProperty.js
54
- var init_defineProperty = __esm({
55
- "../../node_modules/@babel/runtime/helpers/esm/defineProperty.js"() {
56
- init_toPropertyKey();
57
- }
58
- });
59
-
60
- // ../../node_modules/@math.gl/polygon/dist/esm/polygon-utils.js
61
- function getPolygonSignedArea(points, options = {}) {
62
- const {
63
- start = 0,
64
- end = points.length
65
- } = options;
66
- const dim = options.size || 2;
67
- let area2 = 0;
68
- for (let i2 = start, j = end - dim; i2 < end; i2 += dim) {
69
- area2 += (points[i2] - points[j]) * (points[i2 + 1] + points[j + 1]);
70
- j = i2;
71
- }
72
- return area2 / 2;
73
- }
74
- var init_polygon_utils = __esm({
75
- "../../node_modules/@math.gl/polygon/dist/esm/polygon-utils.js"() {
76
- }
77
- });
78
-
79
- // ../../node_modules/@math.gl/polygon/dist/esm/polygon.js
80
- var init_polygon = __esm({
81
- "../../node_modules/@math.gl/polygon/dist/esm/polygon.js"() {
82
- init_defineProperty();
83
- init_polygon_utils();
40
+ // ../../node_modules/ieee754/index.js
41
+ var require_ieee754 = __commonJS({
42
+ "../../node_modules/ieee754/index.js"(exports) {
43
+ exports.read = function(buffer, offset, isLE, mLen, nBytes) {
44
+ var e, m;
45
+ var eLen = nBytes * 8 - mLen - 1;
46
+ var eMax = (1 << eLen) - 1;
47
+ var eBias = eMax >> 1;
48
+ var nBits = -7;
49
+ var i2 = isLE ? nBytes - 1 : 0;
50
+ var d = isLE ? -1 : 1;
51
+ var s = buffer[offset + i2];
52
+ i2 += d;
53
+ e = s & (1 << -nBits) - 1;
54
+ s >>= -nBits;
55
+ nBits += eLen;
56
+ for (; nBits > 0; e = e * 256 + buffer[offset + i2], i2 += d, nBits -= 8) {
57
+ }
58
+ m = e & (1 << -nBits) - 1;
59
+ e >>= -nBits;
60
+ nBits += mLen;
61
+ for (; nBits > 0; m = m * 256 + buffer[offset + i2], i2 += d, nBits -= 8) {
62
+ }
63
+ if (e === 0) {
64
+ e = 1 - eBias;
65
+ } else if (e === eMax) {
66
+ return m ? NaN : (s ? -1 : 1) * Infinity;
67
+ } else {
68
+ m = m + Math.pow(2, mLen);
69
+ e = e - eBias;
70
+ }
71
+ return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
72
+ };
73
+ exports.write = function(buffer, value, offset, isLE, mLen, nBytes) {
74
+ var e, m, c;
75
+ var eLen = nBytes * 8 - mLen - 1;
76
+ var eMax = (1 << eLen) - 1;
77
+ var eBias = eMax >> 1;
78
+ var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
79
+ var i2 = isLE ? 0 : nBytes - 1;
80
+ var d = isLE ? 1 : -1;
81
+ var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
82
+ value = Math.abs(value);
83
+ if (isNaN(value) || value === Infinity) {
84
+ m = isNaN(value) ? 1 : 0;
85
+ e = eMax;
86
+ } else {
87
+ e = Math.floor(Math.log(value) / Math.LN2);
88
+ if (value * (c = Math.pow(2, -e)) < 1) {
89
+ e--;
90
+ c *= 2;
91
+ }
92
+ if (e + eBias >= 1) {
93
+ value += rt / c;
94
+ } else {
95
+ value += rt * Math.pow(2, 1 - eBias);
96
+ }
97
+ if (value * c >= 2) {
98
+ e++;
99
+ c /= 2;
100
+ }
101
+ if (e + eBias >= eMax) {
102
+ m = 0;
103
+ e = eMax;
104
+ } else if (e + eBias >= 1) {
105
+ m = (value * c - 1) * Math.pow(2, mLen);
106
+ e = e + eBias;
107
+ } else {
108
+ m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
109
+ e = 0;
110
+ }
111
+ }
112
+ for (; mLen >= 8; buffer[offset + i2] = m & 255, i2 += d, m /= 256, mLen -= 8) {
113
+ }
114
+ e = e << mLen | m;
115
+ eLen += mLen;
116
+ for (; eLen > 0; buffer[offset + i2] = e & 255, i2 += d, e /= 256, eLen -= 8) {
117
+ }
118
+ buffer[offset + i2 - d] |= s * 128;
119
+ };
84
120
  }
85
121
  });
86
122
 
87
- // ../../node_modules/@math.gl/polygon/dist/esm/earcut.js
88
- function earcut(positions, holeIndices, dim = 2, areas) {
89
- const hasHoles = holeIndices && holeIndices.length;
90
- const outerLen = hasHoles ? holeIndices[0] * dim : positions.length;
91
- let outerNode = linkedList(positions, 0, outerLen, dim, true, areas && areas[0]);
92
- const triangles = [];
93
- if (!outerNode || outerNode.next === outerNode.prev)
94
- return triangles;
95
- let invSize;
96
- let maxX;
97
- let maxY;
98
- let minX;
99
- let minY;
100
- let x2;
101
- let y2;
102
- if (hasHoles)
103
- outerNode = eliminateHoles(positions, holeIndices, outerNode, dim, areas);
104
- if (positions.length > 80 * dim) {
105
- minX = maxX = positions[0];
106
- minY = maxY = positions[1];
107
- for (let i2 = dim; i2 < outerLen; i2 += dim) {
108
- x2 = positions[i2];
109
- y2 = positions[i2 + 1];
110
- if (x2 < minX)
111
- minX = x2;
112
- if (y2 < minY)
113
- minY = y2;
114
- if (x2 > maxX)
115
- maxX = x2;
116
- if (y2 > maxY)
117
- maxY = y2;
118
- }
119
- invSize = Math.max(maxX - minX, maxY - minY);
120
- invSize = invSize !== 0 ? 1 / invSize : 0;
121
- }
122
- earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
123
- return triangles;
124
- }
125
- function linkedList(data, start, end, dim, clockwise, area2) {
126
- let i2;
127
- let last;
128
- if (area2 === void 0) {
129
- area2 = getPolygonSignedArea(data, {
130
- start,
131
- end,
132
- size: dim
133
- });
134
- }
135
- if (clockwise === area2 < 0) {
136
- for (i2 = start; i2 < end; i2 += dim)
137
- last = insertNode(i2, data[i2], data[i2 + 1], last);
138
- } else {
139
- for (i2 = end - dim; i2 >= start; i2 -= dim)
140
- last = insertNode(i2, data[i2], data[i2 + 1], last);
141
- }
142
- if (last && equals(last, last.next)) {
143
- removeNode(last);
144
- last = last.next;
145
- }
146
- return last;
147
- }
148
- function filterPoints(start, end) {
149
- if (!start)
150
- return start;
151
- if (!end)
152
- end = start;
153
- let p = start;
154
- let again;
155
- do {
156
- again = false;
157
- if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
158
- removeNode(p);
159
- p = end = p.prev;
160
- if (p === p.next)
161
- break;
162
- again = true;
163
- } else {
164
- p = p.next;
165
- }
166
- } while (again || p !== end);
167
- return end;
168
- }
169
- function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
170
- if (!ear)
171
- return;
172
- if (!pass && invSize)
173
- indexCurve(ear, minX, minY, invSize);
174
- let stop = ear;
175
- let prev;
176
- let next;
177
- while (ear.prev !== ear.next) {
178
- prev = ear.prev;
179
- next = ear.next;
180
- if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
181
- triangles.push(prev.i / dim);
182
- triangles.push(ear.i / dim);
183
- triangles.push(next.i / dim);
184
- removeNode(ear);
185
- ear = next.next;
186
- stop = next.next;
187
- continue;
188
- }
189
- ear = next;
190
- if (ear === stop) {
191
- if (!pass) {
192
- earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1);
193
- } else if (pass === 1) {
194
- ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
195
- earcutLinked(ear, triangles, dim, minX, minY, invSize, 2);
196
- } else if (pass === 2) {
197
- splitEarcut(ear, triangles, dim, minX, minY, invSize);
198
- }
199
- break;
200
- }
201
- }
202
- }
203
- function isEar(ear) {
204
- const a = ear.prev;
205
- const b = ear;
206
- const c = ear.next;
207
- if (area(a, b, c) >= 0)
208
- return false;
209
- let p = ear.next.next;
210
- while (p !== ear.prev) {
211
- if (pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0)
212
- return false;
213
- p = p.next;
214
- }
215
- return true;
216
- }
217
- function isEarHashed(ear, minX, minY, invSize) {
218
- const a = ear.prev;
219
- const b = ear;
220
- const c = ear.next;
221
- if (area(a, b, c) >= 0)
222
- return false;
223
- const minTX = a.x < b.x ? a.x < c.x ? a.x : c.x : b.x < c.x ? b.x : c.x;
224
- const minTY = a.y < b.y ? a.y < c.y ? a.y : c.y : b.y < c.y ? b.y : c.y;
225
- const maxTX = a.x > b.x ? a.x > c.x ? a.x : c.x : b.x > c.x ? b.x : c.x;
226
- const maxTY = a.y > b.y ? a.y > c.y ? a.y : c.y : b.y > c.y ? b.y : c.y;
227
- const minZ = zOrder(minTX, minTY, minX, minY, invSize);
228
- const maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
229
- let p = ear.prevZ;
230
- let n = ear.nextZ;
231
- while (p && p.z >= minZ && n && n.z <= maxZ) {
232
- if (p !== ear.prev && p !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0)
233
- return false;
234
- p = p.prevZ;
235
- if (n !== ear.prev && n !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y) && area(n.prev, n, n.next) >= 0)
236
- return false;
237
- n = n.nextZ;
238
- }
239
- while (p && p.z >= minZ) {
240
- if (p !== ear.prev && p !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0)
241
- return false;
242
- p = p.prevZ;
243
- }
244
- while (n && n.z <= maxZ) {
245
- if (n !== ear.prev && n !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y) && area(n.prev, n, n.next) >= 0)
246
- return false;
247
- n = n.nextZ;
248
- }
249
- return true;
250
- }
251
- function cureLocalIntersections(start, triangles, dim) {
252
- let p = start;
253
- do {
254
- const a = p.prev;
255
- const b = p.next.next;
256
- if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
257
- triangles.push(a.i / dim);
258
- triangles.push(p.i / dim);
259
- triangles.push(b.i / dim);
260
- removeNode(p);
261
- removeNode(p.next);
262
- p = start = b;
263
- }
264
- p = p.next;
265
- } while (p !== start);
266
- return filterPoints(p);
267
- }
268
- function splitEarcut(start, triangles, dim, minX, minY, invSize) {
269
- let a = start;
270
- do {
271
- let b = a.next.next;
272
- while (b !== a.prev) {
273
- if (a.i !== b.i && isValidDiagonal(a, b)) {
274
- let c = splitPolygon(a, b);
275
- a = filterPoints(a, a.next);
276
- c = filterPoints(c, c.next);
277
- earcutLinked(a, triangles, dim, minX, minY, invSize);
278
- earcutLinked(c, triangles, dim, minX, minY, invSize);
279
- return;
280
- }
281
- b = b.next;
282
- }
283
- a = a.next;
284
- } while (a !== start);
285
- }
286
- function eliminateHoles(data, holeIndices, outerNode, dim, areas) {
287
- const queue = [];
288
- let i2;
289
- let len;
290
- let start;
291
- let end;
292
- let list;
293
- for (i2 = 0, len = holeIndices.length; i2 < len; i2++) {
294
- start = holeIndices[i2] * dim;
295
- end = i2 < len - 1 ? holeIndices[i2 + 1] * dim : data.length;
296
- list = linkedList(data, start, end, dim, false, areas && areas[i2 + 1]);
297
- if (list === list.next)
298
- list.steiner = true;
299
- queue.push(getLeftmost(list));
300
- }
301
- queue.sort(compareX);
302
- for (i2 = 0; i2 < queue.length; i2++) {
303
- eliminateHole(queue[i2], outerNode);
304
- outerNode = filterPoints(outerNode, outerNode.next);
305
- }
306
- return outerNode;
307
- }
308
- function compareX(a, b) {
309
- return a.x - b.x;
310
- }
311
- function eliminateHole(hole, outerNode) {
312
- outerNode = findHoleBridge(hole, outerNode);
313
- if (outerNode) {
314
- const b = splitPolygon(outerNode, hole);
315
- filterPoints(outerNode, outerNode.next);
316
- filterPoints(b, b.next);
317
- }
318
- }
319
- function findHoleBridge(hole, outerNode) {
320
- let p = outerNode;
321
- const hx = hole.x;
322
- const hy = hole.y;
323
- let qx = -Infinity;
324
- let m;
325
- do {
326
- if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
327
- const x2 = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
328
- if (x2 <= hx && x2 > qx) {
329
- qx = x2;
330
- if (x2 === hx) {
331
- if (hy === p.y)
332
- return p;
333
- if (hy === p.next.y)
334
- return p.next;
335
- }
336
- m = p.x < p.next.x ? p : p.next;
337
- }
338
- }
339
- p = p.next;
340
- } while (p !== outerNode);
341
- if (!m)
342
- return null;
343
- if (hx === qx)
344
- return m;
345
- const stop = m;
346
- const mx = m.x;
347
- const my = m.y;
348
- let tanMin = Infinity;
349
- let tan;
350
- p = m;
351
- do {
352
- if (hx >= p.x && p.x >= mx && hx !== p.x && pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {
353
- tan = Math.abs(hy - p.y) / (hx - p.x);
354
- if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
355
- m = p;
356
- tanMin = tan;
357
- }
358
- }
359
- p = p.next;
360
- } while (p !== stop);
361
- return m;
362
- }
363
- function sectorContainsSector(m, p) {
364
- return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
365
- }
366
- function indexCurve(start, minX, minY, invSize) {
367
- let p = start;
368
- do {
369
- if (p.z === null)
370
- p.z = zOrder(p.x, p.y, minX, minY, invSize);
371
- p.prevZ = p.prev;
372
- p.nextZ = p.next;
373
- p = p.next;
374
- } while (p !== start);
375
- p.prevZ.nextZ = null;
376
- p.prevZ = null;
377
- sortLinked(p);
378
- }
379
- function sortLinked(list) {
380
- let e;
381
- let i2;
382
- let inSize = 1;
383
- let numMerges;
384
- let p;
385
- let pSize;
386
- let q;
387
- let qSize;
388
- let tail;
389
- do {
390
- p = list;
391
- list = null;
392
- tail = null;
393
- numMerges = 0;
394
- while (p) {
395
- numMerges++;
396
- q = p;
397
- pSize = 0;
398
- for (i2 = 0; i2 < inSize; i2++) {
399
- pSize++;
400
- q = q.nextZ;
401
- if (!q)
402
- break;
403
- }
404
- qSize = inSize;
405
- while (pSize > 0 || qSize > 0 && q) {
406
- if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
407
- e = p;
408
- p = p.nextZ;
409
- pSize--;
410
- } else {
411
- e = q;
412
- q = q.nextZ;
413
- qSize--;
414
- }
415
- if (tail)
416
- tail.nextZ = e;
417
- else
418
- list = e;
419
- e.prevZ = tail;
420
- tail = e;
421
- }
422
- p = q;
423
- }
424
- tail.nextZ = null;
425
- inSize *= 2;
426
- } while (numMerges > 1);
427
- return list;
428
- }
429
- function zOrder(x2, y2, minX, minY, invSize) {
430
- x2 = 32767 * (x2 - minX) * invSize;
431
- y2 = 32767 * (y2 - minY) * invSize;
432
- x2 = (x2 | x2 << 8) & 16711935;
433
- x2 = (x2 | x2 << 4) & 252645135;
434
- x2 = (x2 | x2 << 2) & 858993459;
435
- x2 = (x2 | x2 << 1) & 1431655765;
436
- y2 = (y2 | y2 << 8) & 16711935;
437
- y2 = (y2 | y2 << 4) & 252645135;
438
- y2 = (y2 | y2 << 2) & 858993459;
439
- y2 = (y2 | y2 << 1) & 1431655765;
440
- return x2 | y2 << 1;
441
- }
442
- function getLeftmost(start) {
443
- let p = start;
444
- let leftmost = start;
445
- do {
446
- if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y)
447
- leftmost = p;
448
- p = p.next;
449
- } while (p !== start);
450
- return leftmost;
451
- }
452
- function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
453
- return (cx - px) * (ay - py) - (ax - px) * (cy - py) >= 0 && (ax - px) * (by - py) - (bx - px) * (ay - py) >= 0 && (bx - px) * (cy - py) - (cx - px) * (by - py) >= 0;
454
- }
455
- function isValidDiagonal(a, b) {
456
- return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && (locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && (area(a.prev, a, b.prev) || area(a, b.prev, b)) || equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0);
457
- }
458
- function area(p, q, r) {
459
- return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
460
- }
461
- function equals(p1, p2) {
462
- return p1.x === p2.x && p1.y === p2.y;
463
- }
464
- function intersects(p1, q1, p2, q2) {
465
- const o1 = sign(area(p1, q1, p2));
466
- const o2 = sign(area(p1, q1, q2));
467
- const o3 = sign(area(p2, q2, p1));
468
- const o4 = sign(area(p2, q2, q1));
469
- if (o1 !== o2 && o3 !== o4)
470
- return true;
471
- if (o1 === 0 && onSegment(p1, p2, q1))
472
- return true;
473
- if (o2 === 0 && onSegment(p1, q2, q1))
474
- return true;
475
- if (o3 === 0 && onSegment(p2, p1, q2))
476
- return true;
477
- if (o4 === 0 && onSegment(p2, q1, q2))
478
- return true;
479
- return false;
480
- }
481
- function onSegment(p, q, r) {
482
- return q.x <= Math.max(p.x, r.x) && q.x >= Math.min(p.x, r.x) && q.y <= Math.max(p.y, r.y) && q.y >= Math.min(p.y, r.y);
483
- }
484
- function sign(num) {
485
- return num > 0 ? 1 : num < 0 ? -1 : 0;
486
- }
487
- function intersectsPolygon(a, b) {
488
- let p = a;
489
- do {
490
- if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i && intersects(p, p.next, a, b))
491
- return true;
492
- p = p.next;
493
- } while (p !== a);
494
- return false;
495
- }
496
- function locallyInside(a, b) {
497
- return area(a.prev, a, a.next) < 0 ? area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0 : area(a, b, a.prev) < 0 || area(a, a.next, b) < 0;
498
- }
499
- function middleInside(a, b) {
500
- let p = a;
501
- let inside = false;
502
- const px = (a.x + b.x) / 2;
503
- const py = (a.y + b.y) / 2;
504
- do {
505
- if (p.y > py !== p.next.y > py && p.next.y !== p.y && px < (p.next.x - p.x) * (py - p.y) / (p.next.y - p.y) + p.x)
506
- inside = !inside;
507
- p = p.next;
508
- } while (p !== a);
509
- return inside;
510
- }
511
- function splitPolygon(a, b) {
512
- const a2 = new Node(a.i, a.x, a.y);
513
- const b2 = new Node(b.i, b.x, b.y);
514
- const an = a.next;
515
- const bp = b.prev;
516
- a.next = b;
517
- b.prev = a;
518
- a2.next = an;
519
- an.prev = a2;
520
- b2.next = a2;
521
- a2.prev = b2;
522
- bp.next = b2;
523
- b2.prev = bp;
524
- return b2;
525
- }
526
- function insertNode(i2, x2, y2, last) {
527
- const p = new Node(i2, x2, y2);
528
- if (!last) {
529
- p.prev = p;
530
- p.next = p;
531
- } else {
532
- p.next = last.next;
533
- p.prev = last;
534
- last.next.prev = p;
535
- last.next = p;
536
- }
537
- return p;
538
- }
539
- function removeNode(p) {
540
- p.next.prev = p.prev;
541
- p.prev.next = p.next;
542
- if (p.prevZ)
543
- p.prevZ.nextZ = p.nextZ;
544
- if (p.nextZ)
545
- p.nextZ.prevZ = p.prevZ;
546
- }
547
- function Node(i2, x2, y2) {
548
- this.i = i2;
549
- this.x = x2;
550
- this.y = y2;
551
- this.prev = null;
552
- this.next = null;
553
- this.z = null;
554
- this.prevZ = null;
555
- this.nextZ = null;
556
- this.steiner = false;
557
- }
558
- var init_earcut = __esm({
559
- "../../node_modules/@math.gl/polygon/dist/esm/earcut.js"() {
560
- init_polygon_utils();
561
- }
562
- });
563
-
564
- // ../../node_modules/@math.gl/polygon/dist/esm/utils.js
565
- var init_utils = __esm({
566
- "../../node_modules/@math.gl/polygon/dist/esm/utils.js"() {
567
- }
568
- });
569
-
570
- // ../../node_modules/@math.gl/polygon/dist/esm/lineclip.js
571
- var init_lineclip = __esm({
572
- "../../node_modules/@math.gl/polygon/dist/esm/lineclip.js"() {
573
- init_utils();
574
- }
575
- });
576
-
577
- // ../../node_modules/@math.gl/polygon/dist/esm/cut-by-grid.js
578
- var init_cut_by_grid = __esm({
579
- "../../node_modules/@math.gl/polygon/dist/esm/cut-by-grid.js"() {
580
- init_lineclip();
581
- init_utils();
582
- }
583
- });
584
-
585
- // ../../node_modules/@math.gl/polygon/dist/esm/cut-by-mercator-bounds.js
586
- var init_cut_by_mercator_bounds = __esm({
587
- "../../node_modules/@math.gl/polygon/dist/esm/cut-by-mercator-bounds.js"() {
588
- init_cut_by_grid();
589
- init_utils();
590
- }
591
- });
592
-
593
- // ../../node_modules/@math.gl/polygon/dist/esm/index.js
594
- var init_esm = __esm({
595
- "../../node_modules/@math.gl/polygon/dist/esm/index.js"() {
596
- init_polygon();
597
- init_polygon_utils();
598
- init_earcut();
599
- init_lineclip();
600
- init_cut_by_grid();
601
- init_cut_by_mercator_bounds();
602
- init_polygon();
603
- }
604
- });
605
-
606
- // ../gis/src/lib/flat-geojson-to-binary.ts
607
- function flatGeojsonToBinary(features, geometryInfo, options) {
608
- const propArrayTypes = extractNumericPropTypes(features);
609
- const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
610
- return fillArrays(features, {
611
- propArrayTypes,
612
- ...geometryInfo
613
- }, {
614
- numericPropKeys: options && options.numericPropKeys || numericPropKeys,
615
- PositionDataType: options ? options.PositionDataType : Float32Array,
616
- triangulate: options ? options.triangulate : true
617
- });
618
- }
619
- function extractNumericPropTypes(features) {
620
- const propArrayTypes = {};
621
- for (const feature of features) {
622
- if (feature.properties) {
623
- for (const key in feature.properties) {
624
- const val = feature.properties[key];
625
- propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);
626
- }
627
- }
628
- }
629
- return propArrayTypes;
630
- }
631
- function fillArrays(features, geometryInfo, options) {
632
- const {
633
- pointPositionsCount,
634
- pointFeaturesCount,
635
- linePositionsCount,
636
- linePathsCount,
637
- lineFeaturesCount,
638
- polygonPositionsCount,
639
- polygonObjectsCount,
640
- polygonRingsCount,
641
- polygonFeaturesCount,
642
- propArrayTypes,
643
- coordLength
644
- } = geometryInfo;
645
- const { numericPropKeys = [], PositionDataType = Float32Array, triangulate = true } = options;
646
- const hasGlobalId = features[0] && "id" in features[0];
647
- const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
648
- const points = {
649
- type: "Point",
650
- positions: new PositionDataType(pointPositionsCount * coordLength),
651
- globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
652
- featureIds: pointFeaturesCount > 65535 ? new Uint32Array(pointPositionsCount) : new Uint16Array(pointPositionsCount),
653
- numericProps: {},
654
- properties: [],
655
- fields: []
656
- };
657
- const lines = {
658
- type: "LineString",
659
- pathIndices: linePositionsCount > 65535 ? new Uint32Array(linePathsCount + 1) : new Uint16Array(linePathsCount + 1),
660
- positions: new PositionDataType(linePositionsCount * coordLength),
661
- globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
662
- featureIds: lineFeaturesCount > 65535 ? new Uint32Array(linePositionsCount) : new Uint16Array(linePositionsCount),
663
- numericProps: {},
664
- properties: [],
665
- fields: []
666
- };
667
- const polygons = {
668
- type: "Polygon",
669
- polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
670
- primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
671
- positions: new PositionDataType(polygonPositionsCount * coordLength),
672
- globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),
673
- featureIds: polygonFeaturesCount > 65535 ? new Uint32Array(polygonPositionsCount) : new Uint16Array(polygonPositionsCount),
674
- numericProps: {},
675
- properties: [],
676
- fields: []
677
- };
678
- if (triangulate) {
679
- polygons.triangles = [];
680
- }
681
- for (const object of [points, lines, polygons]) {
682
- for (const propName of numericPropKeys) {
683
- const T = propArrayTypes[propName];
684
- object.numericProps[propName] = new T(object.positions.length / coordLength);
685
- }
686
- }
687
- lines.pathIndices[linePathsCount] = linePositionsCount;
688
- polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;
689
- polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;
690
- const indexMap = {
691
- pointPosition: 0,
692
- pointFeature: 0,
693
- linePosition: 0,
694
- linePath: 0,
695
- lineFeature: 0,
696
- polygonPosition: 0,
697
- polygonObject: 0,
698
- polygonRing: 0,
699
- polygonFeature: 0,
700
- feature: 0
701
- };
702
- for (const feature of features) {
703
- const geometry = feature.geometry;
704
- const properties = feature.properties || {};
705
- switch (geometry.type) {
706
- case "Point":
707
- handlePoint(geometry, points, indexMap, coordLength, properties);
708
- points.properties.push(keepStringProperties(properties, numericPropKeys));
709
- if (hasGlobalId) {
710
- points.fields.push({ id: feature.id });
711
- }
712
- indexMap.pointFeature++;
713
- break;
714
- case "LineString":
715
- handleLineString(geometry, lines, indexMap, coordLength, properties);
716
- lines.properties.push(keepStringProperties(properties, numericPropKeys));
717
- if (hasGlobalId) {
718
- lines.fields.push({ id: feature.id });
719
- }
720
- indexMap.lineFeature++;
721
- break;
722
- case "Polygon":
723
- handlePolygon(geometry, polygons, indexMap, coordLength, properties);
724
- polygons.properties.push(keepStringProperties(properties, numericPropKeys));
725
- if (hasGlobalId) {
726
- polygons.fields.push({ id: feature.id });
727
- }
728
- indexMap.polygonFeature++;
729
- break;
730
- default:
731
- throw new Error("Invalid geometry type");
732
- }
733
- indexMap.feature++;
734
- }
735
- return makeAccessorObjects(points, lines, polygons, coordLength);
736
- }
737
- function handlePoint(geometry, points, indexMap, coordLength, properties) {
738
- points.positions.set(geometry.data, indexMap.pointPosition * coordLength);
739
- const nPositions = geometry.data.length / coordLength;
740
- fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);
741
- points.globalFeatureIds.fill(indexMap.feature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
742
- points.featureIds.fill(indexMap.pointFeature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
743
- indexMap.pointPosition += nPositions;
744
- }
745
- function handleLineString(geometry, lines, indexMap, coordLength, properties) {
746
- lines.positions.set(geometry.data, indexMap.linePosition * coordLength);
747
- const nPositions = geometry.data.length / coordLength;
748
- fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
749
- lines.globalFeatureIds.fill(indexMap.feature, indexMap.linePosition, indexMap.linePosition + nPositions);
750
- lines.featureIds.fill(indexMap.lineFeature, indexMap.linePosition, indexMap.linePosition + nPositions);
751
- for (let i2 = 0, il = geometry.indices.length; i2 < il; ++i2) {
752
- const start = geometry.indices[i2];
753
- const end = i2 === il - 1 ? geometry.data.length : geometry.indices[i2 + 1];
754
- lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
755
- indexMap.linePosition += (end - start) / coordLength;
756
- }
757
- }
758
- function handlePolygon(geometry, polygons, indexMap, coordLength, properties) {
759
- polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);
760
- const nPositions = geometry.data.length / coordLength;
761
- fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
762
- polygons.globalFeatureIds.fill(indexMap.feature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
763
- polygons.featureIds.fill(indexMap.polygonFeature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
764
- for (let l = 0, ll = geometry.indices.length; l < ll; ++l) {
765
- const startPosition = indexMap.polygonPosition;
766
- polygons.polygonIndices[indexMap.polygonObject++] = startPosition;
767
- const areas = geometry.areas[l];
768
- const indices = geometry.indices[l];
769
- const nextIndices = geometry.indices[l + 1];
770
- for (let i2 = 0, il = indices.length; i2 < il; ++i2) {
771
- const start = indices[i2];
772
- const end = i2 === il - 1 ? nextIndices === void 0 ? geometry.data.length : nextIndices[0] : indices[i2 + 1];
773
- polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
774
- indexMap.polygonPosition += (end - start) / coordLength;
775
- }
776
- const endPosition = indexMap.polygonPosition;
777
- triangulatePolygon(polygons, areas, indices, { startPosition, endPosition, coordLength });
778
- }
779
- }
780
- function triangulatePolygon(polygons, areas, indices, {
781
- startPosition,
782
- endPosition,
783
- coordLength
784
- }) {
785
- if (!polygons.triangles) {
786
- return;
787
- }
788
- const start = startPosition * coordLength;
789
- const end = endPosition * coordLength;
790
- const polygonPositions = polygons.positions.subarray(start, end);
791
- const offset = indices[0];
792
- const holes = indices.slice(1).map((n) => (n - offset) / coordLength);
793
- const triangles = earcut(polygonPositions, holes, coordLength, areas);
794
- for (let t = 0, tl = triangles.length; t < tl; ++t) {
795
- polygons.triangles.push(startPosition + triangles[t]);
796
- }
797
- }
798
- function wrapProps(obj, size) {
799
- const returnObj = {};
800
- for (const key in obj) {
801
- returnObj[key] = { value: obj[key], size };
802
- }
803
- return returnObj;
804
- }
805
- function makeAccessorObjects(points, lines, polygons, coordLength) {
806
- const binaryFeatures = {
807
- points: {
808
- ...points,
809
- positions: { value: points.positions, size: coordLength },
810
- globalFeatureIds: { value: points.globalFeatureIds, size: 1 },
811
- featureIds: { value: points.featureIds, size: 1 },
812
- numericProps: wrapProps(points.numericProps, 1)
813
- },
814
- lines: {
815
- ...lines,
816
- positions: { value: lines.positions, size: coordLength },
817
- pathIndices: { value: lines.pathIndices, size: 1 },
818
- globalFeatureIds: { value: lines.globalFeatureIds, size: 1 },
819
- featureIds: { value: lines.featureIds, size: 1 },
820
- numericProps: wrapProps(lines.numericProps, 1)
821
- },
822
- polygons: {
823
- ...polygons,
824
- positions: { value: polygons.positions, size: coordLength },
825
- polygonIndices: { value: polygons.polygonIndices, size: 1 },
826
- primitivePolygonIndices: { value: polygons.primitivePolygonIndices, size: 1 },
827
- globalFeatureIds: { value: polygons.globalFeatureIds, size: 1 },
828
- featureIds: { value: polygons.featureIds, size: 1 },
829
- numericProps: wrapProps(polygons.numericProps, 1)
830
- }
831
- };
832
- if (binaryFeatures.polygons && polygons.triangles) {
833
- binaryFeatures.polygons.triangles = { value: new Uint32Array(polygons.triangles), size: 1 };
834
- }
835
- return binaryFeatures;
836
- }
837
- function fillNumericProperties(object, properties, index, length2) {
838
- for (const numericPropName in object.numericProps) {
839
- if (numericPropName in properties) {
840
- const value = properties[numericPropName];
841
- object.numericProps[numericPropName].fill(value, index, index + length2);
842
- }
843
- }
844
- }
845
- function keepStringProperties(properties, numericKeys) {
846
- const props = {};
847
- for (const key in properties) {
848
- if (!numericKeys.includes(key)) {
849
- props[key] = properties[key];
850
- }
851
- }
852
- return props;
853
- }
854
- function deduceArrayType(x2, constructor) {
855
- if (constructor === Array || !Number.isFinite(x2)) {
856
- return Array;
857
- }
858
- return constructor === Float64Array || Math.fround(x2) !== x2 ? Float64Array : Float32Array;
859
- }
860
- var init_flat_geojson_to_binary = __esm({
861
- "../gis/src/lib/flat-geojson-to-binary.ts"() {
862
- init_esm();
863
- }
864
- });
865
-
866
- // ../gis/src/index.ts
867
- var init_src = __esm({
868
- "../gis/src/index.ts"() {
869
- init_flat_geojson_to_binary();
870
- }
871
- });
872
-
873
- // ../../node_modules/ieee754/index.js
874
- var require_ieee754 = __commonJS({
875
- "../../node_modules/ieee754/index.js"(exports) {
876
- exports.read = function(buffer, offset, isLE, mLen, nBytes) {
877
- var e, m;
878
- var eLen = nBytes * 8 - mLen - 1;
879
- var eMax = (1 << eLen) - 1;
880
- var eBias = eMax >> 1;
881
- var nBits = -7;
882
- var i2 = isLE ? nBytes - 1 : 0;
883
- var d = isLE ? -1 : 1;
884
- var s = buffer[offset + i2];
885
- i2 += d;
886
- e = s & (1 << -nBits) - 1;
887
- s >>= -nBits;
888
- nBits += eLen;
889
- for (; nBits > 0; e = e * 256 + buffer[offset + i2], i2 += d, nBits -= 8) {
890
- }
891
- m = e & (1 << -nBits) - 1;
892
- e >>= -nBits;
893
- nBits += mLen;
894
- for (; nBits > 0; m = m * 256 + buffer[offset + i2], i2 += d, nBits -= 8) {
895
- }
896
- if (e === 0) {
897
- e = 1 - eBias;
898
- } else if (e === eMax) {
899
- return m ? NaN : (s ? -1 : 1) * Infinity;
900
- } else {
901
- m = m + Math.pow(2, mLen);
902
- e = e - eBias;
903
- }
904
- return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
905
- };
906
- exports.write = function(buffer, value, offset, isLE, mLen, nBytes) {
907
- var e, m, c;
908
- var eLen = nBytes * 8 - mLen - 1;
909
- var eMax = (1 << eLen) - 1;
910
- var eBias = eMax >> 1;
911
- var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
912
- var i2 = isLE ? 0 : nBytes - 1;
913
- var d = isLE ? 1 : -1;
914
- var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
915
- value = Math.abs(value);
916
- if (isNaN(value) || value === Infinity) {
917
- m = isNaN(value) ? 1 : 0;
918
- e = eMax;
919
- } else {
920
- e = Math.floor(Math.log(value) / Math.LN2);
921
- if (value * (c = Math.pow(2, -e)) < 1) {
922
- e--;
923
- c *= 2;
924
- }
925
- if (e + eBias >= 1) {
926
- value += rt / c;
927
- } else {
928
- value += rt * Math.pow(2, 1 - eBias);
929
- }
930
- if (value * c >= 2) {
931
- e++;
932
- c /= 2;
933
- }
934
- if (e + eBias >= eMax) {
935
- m = 0;
936
- e = eMax;
937
- } else if (e + eBias >= 1) {
938
- m = (value * c - 1) * Math.pow(2, mLen);
939
- e = e + eBias;
940
- } else {
941
- m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
942
- e = 0;
943
- }
944
- }
945
- for (; mLen >= 8; buffer[offset + i2] = m & 255, i2 += d, m /= 256, mLen -= 8) {
946
- }
947
- e = e << mLen | m;
948
- eLen += mLen;
949
- for (; eLen > 0; buffer[offset + i2] = e & 255, i2 += d, e /= 256, eLen -= 8) {
950
- }
951
- buffer[offset + i2 - d] |= s * 128;
952
- };
953
- }
954
- });
955
-
956
- // ../../node_modules/pbf/index.js
957
- var require_pbf = __commonJS({
958
- "../../node_modules/pbf/index.js"(exports, module) {
959
- "use strict";
960
- module.exports = Pbf;
961
- var ieee754 = require_ieee754();
962
- function Pbf(buf) {
963
- this.buf = ArrayBuffer.isView && ArrayBuffer.isView(buf) ? buf : new Uint8Array(buf || 0);
964
- this.pos = 0;
965
- this.type = 0;
966
- this.length = this.buf.length;
123
+ // ../../node_modules/pbf/index.js
124
+ var require_pbf = __commonJS({
125
+ "../../node_modules/pbf/index.js"(exports, module) {
126
+ "use strict";
127
+ module.exports = Pbf;
128
+ var ieee754 = require_ieee754();
129
+ function Pbf(buf) {
130
+ this.buf = ArrayBuffer.isView && ArrayBuffer.isView(buf) ? buf : new Uint8Array(buf || 0);
131
+ this.pos = 0;
132
+ this.type = 0;
133
+ this.length = this.buf.length;
967
134
  }
968
135
  Pbf.Varint = 0;
969
136
  Pbf.Fixed64 = 1;
@@ -977,6 +144,7 @@
977
144
  destroy: function() {
978
145
  this.buf = null;
979
146
  },
147
+ // === READING =================================================================
980
148
  readFields: function(readField, result, end) {
981
149
  end = end || this.length;
982
150
  while (this.pos < end) {
@@ -1001,6 +169,7 @@
1001
169
  this.pos += 4;
1002
170
  return val;
1003
171
  },
172
+ // 64-bit int handling is based on github.com/dpw/node-buffer-more-ints (MIT-licensed)
1004
173
  readFixed64: function() {
1005
174
  var val = readUInt32(this.buf, this.pos) + readUInt32(this.buf, this.pos + 4) * SHIFT_LEFT_32;
1006
175
  this.pos += 8;
@@ -1067,6 +236,7 @@
1067
236
  this.pos = end;
1068
237
  return buffer;
1069
238
  },
239
+ // verbose for performance reasons; doesn't affect gzipped size
1070
240
  readPackedVarint: function(arr, isSigned) {
1071
241
  if (this.type !== Pbf.Bytes)
1072
242
  return arr.push(this.readVarint(isSigned));
@@ -1162,6 +332,7 @@
1162
332
  else
1163
333
  throw new Error("Unimplemented type: " + type);
1164
334
  },
335
+ // === WRITING =================================================================
1165
336
  writeTag: function(tag, type) {
1166
337
  this.writeVarint(tag << 3 | type);
1167
338
  },
@@ -1479,132 +650,1015 @@
1479
650
  for (var i2 = 0; i2 < arr.length; i2++)
1480
651
  pbf.writeFixed64(arr[i2]);
1481
652
  }
1482
- function writePackedSFixed64(arr, pbf) {
1483
- for (var i2 = 0; i2 < arr.length; i2++)
1484
- pbf.writeSFixed64(arr[i2]);
653
+ function writePackedSFixed64(arr, pbf) {
654
+ for (var i2 = 0; i2 < arr.length; i2++)
655
+ pbf.writeSFixed64(arr[i2]);
656
+ }
657
+ function readUInt32(buf, pos) {
658
+ return (buf[pos] | buf[pos + 1] << 8 | buf[pos + 2] << 16) + buf[pos + 3] * 16777216;
659
+ }
660
+ function writeInt32(buf, val, pos) {
661
+ buf[pos] = val;
662
+ buf[pos + 1] = val >>> 8;
663
+ buf[pos + 2] = val >>> 16;
664
+ buf[pos + 3] = val >>> 24;
665
+ }
666
+ function readInt32(buf, pos) {
667
+ return (buf[pos] | buf[pos + 1] << 8 | buf[pos + 2] << 16) + (buf[pos + 3] << 24);
668
+ }
669
+ function readUtf8(buf, pos, end) {
670
+ var str = "";
671
+ var i2 = pos;
672
+ while (i2 < end) {
673
+ var b0 = buf[i2];
674
+ var c = null;
675
+ var bytesPerSequence = b0 > 239 ? 4 : b0 > 223 ? 3 : b0 > 191 ? 2 : 1;
676
+ if (i2 + bytesPerSequence > end)
677
+ break;
678
+ var b1, b2, b3;
679
+ if (bytesPerSequence === 1) {
680
+ if (b0 < 128) {
681
+ c = b0;
682
+ }
683
+ } else if (bytesPerSequence === 2) {
684
+ b1 = buf[i2 + 1];
685
+ if ((b1 & 192) === 128) {
686
+ c = (b0 & 31) << 6 | b1 & 63;
687
+ if (c <= 127) {
688
+ c = null;
689
+ }
690
+ }
691
+ } else if (bytesPerSequence === 3) {
692
+ b1 = buf[i2 + 1];
693
+ b2 = buf[i2 + 2];
694
+ if ((b1 & 192) === 128 && (b2 & 192) === 128) {
695
+ c = (b0 & 15) << 12 | (b1 & 63) << 6 | b2 & 63;
696
+ if (c <= 2047 || c >= 55296 && c <= 57343) {
697
+ c = null;
698
+ }
699
+ }
700
+ } else if (bytesPerSequence === 4) {
701
+ b1 = buf[i2 + 1];
702
+ b2 = buf[i2 + 2];
703
+ b3 = buf[i2 + 3];
704
+ if ((b1 & 192) === 128 && (b2 & 192) === 128 && (b3 & 192) === 128) {
705
+ c = (b0 & 15) << 18 | (b1 & 63) << 12 | (b2 & 63) << 6 | b3 & 63;
706
+ if (c <= 65535 || c >= 1114112) {
707
+ c = null;
708
+ }
709
+ }
710
+ }
711
+ if (c === null) {
712
+ c = 65533;
713
+ bytesPerSequence = 1;
714
+ } else if (c > 65535) {
715
+ c -= 65536;
716
+ str += String.fromCharCode(c >>> 10 & 1023 | 55296);
717
+ c = 56320 | c & 1023;
718
+ }
719
+ str += String.fromCharCode(c);
720
+ i2 += bytesPerSequence;
721
+ }
722
+ return str;
723
+ }
724
+ function readUtf8TextDecoder(buf, pos, end) {
725
+ return utf8TextDecoder.decode(buf.subarray(pos, end));
726
+ }
727
+ function writeUtf8(buf, str, pos) {
728
+ for (var i2 = 0, c, lead; i2 < str.length; i2++) {
729
+ c = str.charCodeAt(i2);
730
+ if (c > 55295 && c < 57344) {
731
+ if (lead) {
732
+ if (c < 56320) {
733
+ buf[pos++] = 239;
734
+ buf[pos++] = 191;
735
+ buf[pos++] = 189;
736
+ lead = c;
737
+ continue;
738
+ } else {
739
+ c = lead - 55296 << 10 | c - 56320 | 65536;
740
+ lead = null;
741
+ }
742
+ } else {
743
+ if (c > 56319 || i2 + 1 === str.length) {
744
+ buf[pos++] = 239;
745
+ buf[pos++] = 191;
746
+ buf[pos++] = 189;
747
+ } else {
748
+ lead = c;
749
+ }
750
+ continue;
751
+ }
752
+ } else if (lead) {
753
+ buf[pos++] = 239;
754
+ buf[pos++] = 191;
755
+ buf[pos++] = 189;
756
+ lead = null;
757
+ }
758
+ if (c < 128) {
759
+ buf[pos++] = c;
760
+ } else {
761
+ if (c < 2048) {
762
+ buf[pos++] = c >> 6 | 192;
763
+ } else {
764
+ if (c < 65536) {
765
+ buf[pos++] = c >> 12 | 224;
766
+ } else {
767
+ buf[pos++] = c >> 18 | 240;
768
+ buf[pos++] = c >> 12 & 63 | 128;
769
+ }
770
+ buf[pos++] = c >> 6 & 63 | 128;
771
+ }
772
+ buf[pos++] = c & 63 | 128;
773
+ }
774
+ }
775
+ return pos;
776
+ }
777
+ }
778
+ });
779
+
780
+ // src/index.ts
781
+ var src_exports = {};
782
+ __export(src_exports, {
783
+ GeoJSONTiler: () => GeoJSONTiler,
784
+ MVTLoader: () => MVTLoader,
785
+ MVTSource: () => MVTSource,
786
+ MVTWorkerLoader: () => MVTWorkerLoader,
787
+ TileJSONLoader: () => TileJSONLoader
788
+ });
789
+
790
+ // ../../node_modules/@babel/runtime/helpers/esm/typeof.js
791
+ function _typeof(obj) {
792
+ "@babel/helpers - typeof";
793
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) {
794
+ return typeof obj2;
795
+ } : function(obj2) {
796
+ return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
797
+ }, _typeof(obj);
798
+ }
799
+
800
+ // ../../node_modules/@babel/runtime/helpers/esm/toPrimitive.js
801
+ function _toPrimitive(input, hint) {
802
+ if (_typeof(input) !== "object" || input === null)
803
+ return input;
804
+ var prim = input[Symbol.toPrimitive];
805
+ if (prim !== void 0) {
806
+ var res = prim.call(input, hint || "default");
807
+ if (_typeof(res) !== "object")
808
+ return res;
809
+ throw new TypeError("@@toPrimitive must return a primitive value.");
810
+ }
811
+ return (hint === "string" ? String : Number)(input);
812
+ }
813
+
814
+ // ../../node_modules/@babel/runtime/helpers/esm/toPropertyKey.js
815
+ function _toPropertyKey(arg) {
816
+ var key = _toPrimitive(arg, "string");
817
+ return _typeof(key) === "symbol" ? key : String(key);
818
+ }
819
+
820
+ // ../../node_modules/@babel/runtime/helpers/esm/defineProperty.js
821
+ function _defineProperty(obj, key, value) {
822
+ key = _toPropertyKey(key);
823
+ if (key in obj) {
824
+ Object.defineProperty(obj, key, {
825
+ value,
826
+ enumerable: true,
827
+ configurable: true,
828
+ writable: true
829
+ });
830
+ } else {
831
+ obj[key] = value;
832
+ }
833
+ return obj;
834
+ }
835
+
836
+ // ../../node_modules/@math.gl/polygon/dist/polygon-utils.js
837
+ var DimIndex = {
838
+ x: 0,
839
+ y: 1,
840
+ z: 2
841
+ };
842
+ function getPolygonSignedArea(points, options = {}) {
843
+ const {
844
+ start = 0,
845
+ end = points.length,
846
+ plane = "xy"
847
+ } = options;
848
+ const dim = options.size || 2;
849
+ let area2 = 0;
850
+ const i0 = DimIndex[plane[0]];
851
+ const i1 = DimIndex[plane[1]];
852
+ for (let i2 = start, j = end - dim; i2 < end; i2 += dim) {
853
+ area2 += (points[i2 + i0] - points[j + i0]) * (points[i2 + i1] + points[j + i1]);
854
+ j = i2;
855
+ }
856
+ return area2 / 2;
857
+ }
858
+
859
+ // ../../node_modules/@math.gl/polygon/dist/earcut.js
860
+ function earcut(positions, holeIndices, dim = 2, areas, plane = "xy") {
861
+ const hasHoles = holeIndices && holeIndices.length;
862
+ const outerLen = hasHoles ? holeIndices[0] * dim : positions.length;
863
+ let outerNode = linkedList(positions, 0, outerLen, dim, true, areas && areas[0], plane);
864
+ const triangles = [];
865
+ if (!outerNode || outerNode.next === outerNode.prev)
866
+ return triangles;
867
+ let invSize;
868
+ let maxX;
869
+ let maxY;
870
+ let minX;
871
+ let minY;
872
+ let x2;
873
+ let y2;
874
+ if (hasHoles)
875
+ outerNode = eliminateHoles(positions, holeIndices, outerNode, dim, areas, plane);
876
+ if (positions.length > 80 * dim) {
877
+ minX = maxX = positions[0];
878
+ minY = maxY = positions[1];
879
+ for (let i2 = dim; i2 < outerLen; i2 += dim) {
880
+ x2 = positions[i2];
881
+ y2 = positions[i2 + 1];
882
+ if (x2 < minX)
883
+ minX = x2;
884
+ if (y2 < minY)
885
+ minY = y2;
886
+ if (x2 > maxX)
887
+ maxX = x2;
888
+ if (y2 > maxY)
889
+ maxY = y2;
890
+ }
891
+ invSize = Math.max(maxX - minX, maxY - minY);
892
+ invSize = invSize !== 0 ? 32767 / invSize : 0;
893
+ }
894
+ earcutLinked(outerNode, triangles, dim, minX, minY, invSize, 0);
895
+ return triangles;
896
+ }
897
+ function linkedList(data, start, end, dim, clockwise, area2, plane) {
898
+ let i2;
899
+ let last;
900
+ if (area2 === void 0) {
901
+ area2 = getPolygonSignedArea(data, {
902
+ start,
903
+ end,
904
+ size: dim,
905
+ plane
906
+ });
907
+ }
908
+ let i0 = DimIndex[plane[0]];
909
+ let i1 = DimIndex[plane[1]];
910
+ if (clockwise === area2 < 0) {
911
+ for (i2 = start; i2 < end; i2 += dim)
912
+ last = insertNode(i2, data[i2 + i0], data[i2 + i1], last);
913
+ } else {
914
+ for (i2 = end - dim; i2 >= start; i2 -= dim)
915
+ last = insertNode(i2, data[i2 + i0], data[i2 + i1], last);
916
+ }
917
+ if (last && equals(last, last.next)) {
918
+ removeNode(last);
919
+ last = last.next;
920
+ }
921
+ return last;
922
+ }
923
+ function filterPoints(start, end) {
924
+ if (!start)
925
+ return start;
926
+ if (!end)
927
+ end = start;
928
+ let p = start;
929
+ let again;
930
+ do {
931
+ again = false;
932
+ if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
933
+ removeNode(p);
934
+ p = end = p.prev;
935
+ if (p === p.next)
936
+ break;
937
+ again = true;
938
+ } else {
939
+ p = p.next;
940
+ }
941
+ } while (again || p !== end);
942
+ return end;
943
+ }
944
+ function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
945
+ if (!ear)
946
+ return;
947
+ if (!pass && invSize)
948
+ indexCurve(ear, minX, minY, invSize);
949
+ let stop = ear;
950
+ let prev;
951
+ let next;
952
+ while (ear.prev !== ear.next) {
953
+ prev = ear.prev;
954
+ next = ear.next;
955
+ if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
956
+ triangles.push(prev.i / dim | 0);
957
+ triangles.push(ear.i / dim | 0);
958
+ triangles.push(next.i / dim | 0);
959
+ removeNode(ear);
960
+ ear = next.next;
961
+ stop = next.next;
962
+ continue;
963
+ }
964
+ ear = next;
965
+ if (ear === stop) {
966
+ if (!pass) {
967
+ earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1);
968
+ } else if (pass === 1) {
969
+ ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
970
+ earcutLinked(ear, triangles, dim, minX, minY, invSize, 2);
971
+ } else if (pass === 2) {
972
+ splitEarcut(ear, triangles, dim, minX, minY, invSize);
973
+ }
974
+ break;
975
+ }
976
+ }
977
+ }
978
+ function isEar(ear) {
979
+ const a = ear.prev;
980
+ const b = ear;
981
+ const c = ear.next;
982
+ if (area(a, b, c) >= 0)
983
+ return false;
984
+ const ax = a.x;
985
+ const bx = b.x;
986
+ const cx = c.x;
987
+ const ay = a.y;
988
+ const by = b.y;
989
+ const cy = c.y;
990
+ const x0 = ax < bx ? ax < cx ? ax : cx : bx < cx ? bx : cx;
991
+ const y0 = ay < by ? ay < cy ? ay : cy : by < cy ? by : cy;
992
+ const x1 = ax > bx ? ax > cx ? ax : cx : bx > cx ? bx : cx;
993
+ const y1 = ay > by ? ay > cy ? ay : cy : by > cy ? by : cy;
994
+ let p = c.next;
995
+ while (p !== a) {
996
+ if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0)
997
+ return false;
998
+ p = p.next;
999
+ }
1000
+ return true;
1001
+ }
1002
+ function isEarHashed(ear, minX, minY, invSize) {
1003
+ const a = ear.prev;
1004
+ const b = ear;
1005
+ const c = ear.next;
1006
+ if (area(a, b, c) >= 0)
1007
+ return false;
1008
+ const ax = a.x;
1009
+ const bx = b.x;
1010
+ const cx = c.x;
1011
+ const ay = a.y;
1012
+ const by = b.y;
1013
+ const cy = c.y;
1014
+ const x0 = ax < bx ? ax < cx ? ax : cx : bx < cx ? bx : cx;
1015
+ const y0 = ay < by ? ay < cy ? ay : cy : by < cy ? by : cy;
1016
+ const x1 = ax > bx ? ax > cx ? ax : cx : bx > cx ? bx : cx;
1017
+ const y1 = ay > by ? ay > cy ? ay : cy : by > cy ? by : cy;
1018
+ const minZ = zOrder(x0, y0, minX, minY, invSize);
1019
+ const maxZ = zOrder(x1, y1, minX, minY, invSize);
1020
+ let p = ear.prevZ;
1021
+ let n = ear.nextZ;
1022
+ while (p && p.z >= minZ && n && n.z <= maxZ) {
1023
+ if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c && pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0)
1024
+ return false;
1025
+ p = p.prevZ;
1026
+ if (n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c && pointInTriangle(ax, ay, bx, by, cx, cy, n.x, n.y) && area(n.prev, n, n.next) >= 0)
1027
+ return false;
1028
+ n = n.nextZ;
1029
+ }
1030
+ while (p && p.z >= minZ) {
1031
+ if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c && pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0)
1032
+ return false;
1033
+ p = p.prevZ;
1034
+ }
1035
+ while (n && n.z <= maxZ) {
1036
+ if (n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c && pointInTriangle(ax, ay, bx, by, cx, cy, n.x, n.y) && area(n.prev, n, n.next) >= 0)
1037
+ return false;
1038
+ n = n.nextZ;
1039
+ }
1040
+ return true;
1041
+ }
1042
+ function cureLocalIntersections(start, triangles, dim) {
1043
+ let p = start;
1044
+ do {
1045
+ const a = p.prev;
1046
+ const b = p.next.next;
1047
+ if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
1048
+ triangles.push(a.i / dim | 0);
1049
+ triangles.push(p.i / dim | 0);
1050
+ triangles.push(b.i / dim | 0);
1051
+ removeNode(p);
1052
+ removeNode(p.next);
1053
+ p = start = b;
1485
1054
  }
1486
- function readUInt32(buf, pos) {
1487
- return (buf[pos] | buf[pos + 1] << 8 | buf[pos + 2] << 16) + buf[pos + 3] * 16777216;
1055
+ p = p.next;
1056
+ } while (p !== start);
1057
+ return filterPoints(p);
1058
+ }
1059
+ function splitEarcut(start, triangles, dim, minX, minY, invSize) {
1060
+ let a = start;
1061
+ do {
1062
+ let b = a.next.next;
1063
+ while (b !== a.prev) {
1064
+ if (a.i !== b.i && isValidDiagonal(a, b)) {
1065
+ let c = splitPolygon(a, b);
1066
+ a = filterPoints(a, a.next);
1067
+ c = filterPoints(c, c.next);
1068
+ earcutLinked(a, triangles, dim, minX, minY, invSize, 0);
1069
+ earcutLinked(c, triangles, dim, minX, minY, invSize, 0);
1070
+ return;
1071
+ }
1072
+ b = b.next;
1488
1073
  }
1489
- function writeInt32(buf, val, pos) {
1490
- buf[pos] = val;
1491
- buf[pos + 1] = val >>> 8;
1492
- buf[pos + 2] = val >>> 16;
1493
- buf[pos + 3] = val >>> 24;
1074
+ a = a.next;
1075
+ } while (a !== start);
1076
+ }
1077
+ function eliminateHoles(data, holeIndices, outerNode, dim, areas, plane) {
1078
+ const queue = [];
1079
+ let i2;
1080
+ let len;
1081
+ let start;
1082
+ let end;
1083
+ let list;
1084
+ for (i2 = 0, len = holeIndices.length; i2 < len; i2++) {
1085
+ start = holeIndices[i2] * dim;
1086
+ end = i2 < len - 1 ? holeIndices[i2 + 1] * dim : data.length;
1087
+ list = linkedList(data, start, end, dim, false, areas && areas[i2 + 1], plane);
1088
+ if (list === list.next)
1089
+ list.steiner = true;
1090
+ queue.push(getLeftmost(list));
1091
+ }
1092
+ queue.sort(compareX);
1093
+ for (i2 = 0; i2 < queue.length; i2++) {
1094
+ outerNode = eliminateHole(queue[i2], outerNode);
1095
+ }
1096
+ return outerNode;
1097
+ }
1098
+ function compareX(a, b) {
1099
+ return a.x - b.x;
1100
+ }
1101
+ function eliminateHole(hole, outerNode) {
1102
+ const bridge = findHoleBridge(hole, outerNode);
1103
+ if (!bridge) {
1104
+ return outerNode;
1105
+ }
1106
+ const bridgeReverse = splitPolygon(bridge, hole);
1107
+ filterPoints(bridgeReverse, bridgeReverse.next);
1108
+ return filterPoints(bridge, bridge.next);
1109
+ }
1110
+ function findHoleBridge(hole, outerNode) {
1111
+ let p = outerNode;
1112
+ const hx = hole.x;
1113
+ const hy = hole.y;
1114
+ let qx = -Infinity;
1115
+ let m;
1116
+ do {
1117
+ if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
1118
+ const x2 = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
1119
+ if (x2 <= hx && x2 > qx) {
1120
+ qx = x2;
1121
+ m = p.x < p.next.x ? p : p.next;
1122
+ if (x2 === hx)
1123
+ return m;
1124
+ }
1494
1125
  }
1495
- function readInt32(buf, pos) {
1496
- return (buf[pos] | buf[pos + 1] << 8 | buf[pos + 2] << 16) + (buf[pos + 3] << 24);
1126
+ p = p.next;
1127
+ } while (p !== outerNode);
1128
+ if (!m)
1129
+ return null;
1130
+ const stop = m;
1131
+ const mx = m.x;
1132
+ const my = m.y;
1133
+ let tanMin = Infinity;
1134
+ let tan;
1135
+ p = m;
1136
+ do {
1137
+ if (hx >= p.x && p.x >= mx && hx !== p.x && pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {
1138
+ tan = Math.abs(hy - p.y) / (hx - p.x);
1139
+ if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
1140
+ m = p;
1141
+ tanMin = tan;
1142
+ }
1497
1143
  }
1498
- function readUtf8(buf, pos, end) {
1499
- var str = "";
1500
- var i2 = pos;
1501
- while (i2 < end) {
1502
- var b0 = buf[i2];
1503
- var c = null;
1504
- var bytesPerSequence = b0 > 239 ? 4 : b0 > 223 ? 3 : b0 > 191 ? 2 : 1;
1505
- if (i2 + bytesPerSequence > end)
1144
+ p = p.next;
1145
+ } while (p !== stop);
1146
+ return m;
1147
+ }
1148
+ function sectorContainsSector(m, p) {
1149
+ return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
1150
+ }
1151
+ function indexCurve(start, minX, minY, invSize) {
1152
+ let p = start;
1153
+ do {
1154
+ if (p.z === 0)
1155
+ p.z = zOrder(p.x, p.y, minX, minY, invSize);
1156
+ p.prevZ = p.prev;
1157
+ p.nextZ = p.next;
1158
+ p = p.next;
1159
+ } while (p !== start);
1160
+ p.prevZ.nextZ = null;
1161
+ p.prevZ = null;
1162
+ sortLinked(p);
1163
+ }
1164
+ function sortLinked(list) {
1165
+ let e;
1166
+ let i2;
1167
+ let inSize = 1;
1168
+ let numMerges;
1169
+ let p;
1170
+ let pSize;
1171
+ let q;
1172
+ let qSize;
1173
+ let tail;
1174
+ do {
1175
+ p = list;
1176
+ list = null;
1177
+ tail = null;
1178
+ numMerges = 0;
1179
+ while (p) {
1180
+ numMerges++;
1181
+ q = p;
1182
+ pSize = 0;
1183
+ for (i2 = 0; i2 < inSize; i2++) {
1184
+ pSize++;
1185
+ q = q.nextZ;
1186
+ if (!q)
1506
1187
  break;
1507
- var b1, b2, b3;
1508
- if (bytesPerSequence === 1) {
1509
- if (b0 < 128) {
1510
- c = b0;
1511
- }
1512
- } else if (bytesPerSequence === 2) {
1513
- b1 = buf[i2 + 1];
1514
- if ((b1 & 192) === 128) {
1515
- c = (b0 & 31) << 6 | b1 & 63;
1516
- if (c <= 127) {
1517
- c = null;
1518
- }
1519
- }
1520
- } else if (bytesPerSequence === 3) {
1521
- b1 = buf[i2 + 1];
1522
- b2 = buf[i2 + 2];
1523
- if ((b1 & 192) === 128 && (b2 & 192) === 128) {
1524
- c = (b0 & 15) << 12 | (b1 & 63) << 6 | b2 & 63;
1525
- if (c <= 2047 || c >= 55296 && c <= 57343) {
1526
- c = null;
1527
- }
1528
- }
1529
- } else if (bytesPerSequence === 4) {
1530
- b1 = buf[i2 + 1];
1531
- b2 = buf[i2 + 2];
1532
- b3 = buf[i2 + 3];
1533
- if ((b1 & 192) === 128 && (b2 & 192) === 128 && (b3 & 192) === 128) {
1534
- c = (b0 & 15) << 18 | (b1 & 63) << 12 | (b2 & 63) << 6 | b3 & 63;
1535
- if (c <= 65535 || c >= 1114112) {
1536
- c = null;
1537
- }
1538
- }
1539
- }
1540
- if (c === null) {
1541
- c = 65533;
1542
- bytesPerSequence = 1;
1543
- } else if (c > 65535) {
1544
- c -= 65536;
1545
- str += String.fromCharCode(c >>> 10 & 1023 | 55296);
1546
- c = 56320 | c & 1023;
1188
+ }
1189
+ qSize = inSize;
1190
+ while (pSize > 0 || qSize > 0 && q) {
1191
+ if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
1192
+ e = p;
1193
+ p = p.nextZ;
1194
+ pSize--;
1195
+ } else {
1196
+ e = q;
1197
+ q = q.nextZ;
1198
+ qSize--;
1547
1199
  }
1548
- str += String.fromCharCode(c);
1549
- i2 += bytesPerSequence;
1200
+ if (tail)
1201
+ tail.nextZ = e;
1202
+ else
1203
+ list = e;
1204
+ e.prevZ = tail;
1205
+ tail = e;
1206
+ }
1207
+ p = q;
1208
+ }
1209
+ tail.nextZ = null;
1210
+ inSize *= 2;
1211
+ } while (numMerges > 1);
1212
+ return list;
1213
+ }
1214
+ function zOrder(x2, y2, minX, minY, invSize) {
1215
+ x2 = (x2 - minX) * invSize | 0;
1216
+ y2 = (y2 - minY) * invSize | 0;
1217
+ x2 = (x2 | x2 << 8) & 16711935;
1218
+ x2 = (x2 | x2 << 4) & 252645135;
1219
+ x2 = (x2 | x2 << 2) & 858993459;
1220
+ x2 = (x2 | x2 << 1) & 1431655765;
1221
+ y2 = (y2 | y2 << 8) & 16711935;
1222
+ y2 = (y2 | y2 << 4) & 252645135;
1223
+ y2 = (y2 | y2 << 2) & 858993459;
1224
+ y2 = (y2 | y2 << 1) & 1431655765;
1225
+ return x2 | y2 << 1;
1226
+ }
1227
+ function getLeftmost(start) {
1228
+ let p = start;
1229
+ let leftmost = start;
1230
+ do {
1231
+ if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y)
1232
+ leftmost = p;
1233
+ p = p.next;
1234
+ } while (p !== start);
1235
+ return leftmost;
1236
+ }
1237
+ function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
1238
+ return (cx - px) * (ay - py) >= (ax - px) * (cy - py) && (ax - px) * (by - py) >= (bx - px) * (ay - py) && (bx - px) * (cy - py) >= (cx - px) * (by - py);
1239
+ }
1240
+ function isValidDiagonal(a, b) {
1241
+ return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && (locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && (area(a.prev, a, b.prev) || area(a, b.prev, b)) || equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0);
1242
+ }
1243
+ function area(p, q, r) {
1244
+ return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
1245
+ }
1246
+ function equals(p1, p2) {
1247
+ return p1.x === p2.x && p1.y === p2.y;
1248
+ }
1249
+ function intersects(p1, q1, p2, q2) {
1250
+ const o1 = sign(area(p1, q1, p2));
1251
+ const o2 = sign(area(p1, q1, q2));
1252
+ const o3 = sign(area(p2, q2, p1));
1253
+ const o4 = sign(area(p2, q2, q1));
1254
+ if (o1 !== o2 && o3 !== o4)
1255
+ return true;
1256
+ if (o1 === 0 && onSegment(p1, p2, q1))
1257
+ return true;
1258
+ if (o2 === 0 && onSegment(p1, q2, q1))
1259
+ return true;
1260
+ if (o3 === 0 && onSegment(p2, p1, q2))
1261
+ return true;
1262
+ if (o4 === 0 && onSegment(p2, q1, q2))
1263
+ return true;
1264
+ return false;
1265
+ }
1266
+ function onSegment(p, q, r) {
1267
+ return q.x <= Math.max(p.x, r.x) && q.x >= Math.min(p.x, r.x) && q.y <= Math.max(p.y, r.y) && q.y >= Math.min(p.y, r.y);
1268
+ }
1269
+ function sign(num) {
1270
+ return num > 0 ? 1 : num < 0 ? -1 : 0;
1271
+ }
1272
+ function intersectsPolygon(a, b) {
1273
+ let p = a;
1274
+ do {
1275
+ if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i && intersects(p, p.next, a, b))
1276
+ return true;
1277
+ p = p.next;
1278
+ } while (p !== a);
1279
+ return false;
1280
+ }
1281
+ function locallyInside(a, b) {
1282
+ return area(a.prev, a, a.next) < 0 ? area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0 : area(a, b, a.prev) < 0 || area(a, a.next, b) < 0;
1283
+ }
1284
+ function middleInside(a, b) {
1285
+ let p = a;
1286
+ let inside = false;
1287
+ const px = (a.x + b.x) / 2;
1288
+ const py = (a.y + b.y) / 2;
1289
+ do {
1290
+ if (p.y > py !== p.next.y > py && p.next.y !== p.y && px < (p.next.x - p.x) * (py - p.y) / (p.next.y - p.y) + p.x)
1291
+ inside = !inside;
1292
+ p = p.next;
1293
+ } while (p !== a);
1294
+ return inside;
1295
+ }
1296
+ function splitPolygon(a, b) {
1297
+ const a2 = new Vertex(a.i, a.x, a.y);
1298
+ const b2 = new Vertex(b.i, b.x, b.y);
1299
+ const an = a.next;
1300
+ const bp = b.prev;
1301
+ a.next = b;
1302
+ b.prev = a;
1303
+ a2.next = an;
1304
+ an.prev = a2;
1305
+ b2.next = a2;
1306
+ a2.prev = b2;
1307
+ bp.next = b2;
1308
+ b2.prev = bp;
1309
+ return b2;
1310
+ }
1311
+ function insertNode(i2, x2, y2, last) {
1312
+ const p = new Vertex(i2, x2, y2);
1313
+ if (!last) {
1314
+ p.prev = p;
1315
+ p.next = p;
1316
+ } else {
1317
+ p.next = last.next;
1318
+ p.prev = last;
1319
+ last.next.prev = p;
1320
+ last.next = p;
1321
+ }
1322
+ return p;
1323
+ }
1324
+ function removeNode(p) {
1325
+ p.next.prev = p.prev;
1326
+ p.prev.next = p.next;
1327
+ if (p.prevZ)
1328
+ p.prevZ.nextZ = p.nextZ;
1329
+ if (p.nextZ)
1330
+ p.nextZ.prevZ = p.prevZ;
1331
+ }
1332
+ var Vertex = class {
1333
+ constructor(i2, x2, y2) {
1334
+ _defineProperty(this, "i", void 0);
1335
+ _defineProperty(this, "x", void 0);
1336
+ _defineProperty(this, "y", void 0);
1337
+ _defineProperty(this, "prev", null);
1338
+ _defineProperty(this, "next", null);
1339
+ _defineProperty(this, "z", 0);
1340
+ _defineProperty(this, "prevZ", null);
1341
+ _defineProperty(this, "nextZ", null);
1342
+ _defineProperty(this, "steiner", false);
1343
+ this.i = i2;
1344
+ this.x = x2;
1345
+ this.y = y2;
1346
+ }
1347
+ };
1348
+
1349
+ // ../gis/src/lib/flat-geojson-to-binary.ts
1350
+ function flatGeojsonToBinary(features, geometryInfo, options) {
1351
+ const propArrayTypes = extractNumericPropTypes(features);
1352
+ const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
1353
+ return fillArrays(features, {
1354
+ propArrayTypes,
1355
+ ...geometryInfo
1356
+ }, {
1357
+ numericPropKeys: options && options.numericPropKeys || numericPropKeys,
1358
+ PositionDataType: options ? options.PositionDataType : Float32Array,
1359
+ triangulate: options ? options.triangulate : true
1360
+ });
1361
+ }
1362
+ function extractNumericPropTypes(features) {
1363
+ const propArrayTypes = {};
1364
+ for (const feature of features) {
1365
+ if (feature.properties) {
1366
+ for (const key in feature.properties) {
1367
+ const val = feature.properties[key];
1368
+ propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);
1550
1369
  }
1551
- return str;
1552
1370
  }
1553
- function readUtf8TextDecoder(buf, pos, end) {
1554
- return utf8TextDecoder.decode(buf.subarray(pos, end));
1371
+ }
1372
+ return propArrayTypes;
1373
+ }
1374
+ function fillArrays(features, geometryInfo, options) {
1375
+ const {
1376
+ pointPositionsCount,
1377
+ pointFeaturesCount,
1378
+ linePositionsCount,
1379
+ linePathsCount,
1380
+ lineFeaturesCount,
1381
+ polygonPositionsCount,
1382
+ polygonObjectsCount,
1383
+ polygonRingsCount,
1384
+ polygonFeaturesCount,
1385
+ propArrayTypes,
1386
+ coordLength
1387
+ } = geometryInfo;
1388
+ const {
1389
+ numericPropKeys = [],
1390
+ PositionDataType = Float32Array,
1391
+ triangulate = true
1392
+ } = options;
1393
+ const hasGlobalId = features[0] && "id" in features[0];
1394
+ const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
1395
+ const points = {
1396
+ type: "Point",
1397
+ positions: new PositionDataType(pointPositionsCount * coordLength),
1398
+ globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
1399
+ featureIds: pointFeaturesCount > 65535 ? new Uint32Array(pointPositionsCount) : new Uint16Array(pointPositionsCount),
1400
+ numericProps: {},
1401
+ properties: [],
1402
+ fields: []
1403
+ };
1404
+ const lines = {
1405
+ type: "LineString",
1406
+ pathIndices: linePositionsCount > 65535 ? new Uint32Array(linePathsCount + 1) : new Uint16Array(linePathsCount + 1),
1407
+ positions: new PositionDataType(linePositionsCount * coordLength),
1408
+ globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
1409
+ featureIds: lineFeaturesCount > 65535 ? new Uint32Array(linePositionsCount) : new Uint16Array(linePositionsCount),
1410
+ numericProps: {},
1411
+ properties: [],
1412
+ fields: []
1413
+ };
1414
+ const polygons = {
1415
+ type: "Polygon",
1416
+ polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
1417
+ primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
1418
+ positions: new PositionDataType(polygonPositionsCount * coordLength),
1419
+ globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),
1420
+ featureIds: polygonFeaturesCount > 65535 ? new Uint32Array(polygonPositionsCount) : new Uint16Array(polygonPositionsCount),
1421
+ numericProps: {},
1422
+ properties: [],
1423
+ fields: []
1424
+ };
1425
+ if (triangulate) {
1426
+ polygons.triangles = [];
1427
+ }
1428
+ for (const object of [points, lines, polygons]) {
1429
+ for (const propName of numericPropKeys) {
1430
+ const T = propArrayTypes[propName];
1431
+ object.numericProps[propName] = new T(object.positions.length / coordLength);
1555
1432
  }
1556
- function writeUtf8(buf, str, pos) {
1557
- for (var i2 = 0, c, lead; i2 < str.length; i2++) {
1558
- c = str.charCodeAt(i2);
1559
- if (c > 55295 && c < 57344) {
1560
- if (lead) {
1561
- if (c < 56320) {
1562
- buf[pos++] = 239;
1563
- buf[pos++] = 191;
1564
- buf[pos++] = 189;
1565
- lead = c;
1566
- continue;
1567
- } else {
1568
- c = lead - 55296 << 10 | c - 56320 | 65536;
1569
- lead = null;
1570
- }
1571
- } else {
1572
- if (c > 56319 || i2 + 1 === str.length) {
1573
- buf[pos++] = 239;
1574
- buf[pos++] = 191;
1575
- buf[pos++] = 189;
1576
- } else {
1577
- lead = c;
1578
- }
1579
- continue;
1580
- }
1581
- } else if (lead) {
1582
- buf[pos++] = 239;
1583
- buf[pos++] = 191;
1584
- buf[pos++] = 189;
1585
- lead = null;
1433
+ }
1434
+ lines.pathIndices[linePathsCount] = linePositionsCount;
1435
+ polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;
1436
+ polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;
1437
+ const indexMap = {
1438
+ pointPosition: 0,
1439
+ pointFeature: 0,
1440
+ linePosition: 0,
1441
+ linePath: 0,
1442
+ lineFeature: 0,
1443
+ polygonPosition: 0,
1444
+ polygonObject: 0,
1445
+ polygonRing: 0,
1446
+ polygonFeature: 0,
1447
+ feature: 0
1448
+ };
1449
+ for (const feature of features) {
1450
+ const geometry = feature.geometry;
1451
+ const properties = feature.properties || {};
1452
+ switch (geometry.type) {
1453
+ case "Point":
1454
+ handlePoint(geometry, points, indexMap, coordLength, properties);
1455
+ points.properties.push(keepStringProperties(properties, numericPropKeys));
1456
+ if (hasGlobalId) {
1457
+ points.fields.push({
1458
+ id: feature.id
1459
+ });
1460
+ }
1461
+ indexMap.pointFeature++;
1462
+ break;
1463
+ case "LineString":
1464
+ handleLineString(geometry, lines, indexMap, coordLength, properties);
1465
+ lines.properties.push(keepStringProperties(properties, numericPropKeys));
1466
+ if (hasGlobalId) {
1467
+ lines.fields.push({
1468
+ id: feature.id
1469
+ });
1586
1470
  }
1587
- if (c < 128) {
1588
- buf[pos++] = c;
1589
- } else {
1590
- if (c < 2048) {
1591
- buf[pos++] = c >> 6 | 192;
1592
- } else {
1593
- if (c < 65536) {
1594
- buf[pos++] = c >> 12 | 224;
1595
- } else {
1596
- buf[pos++] = c >> 18 | 240;
1597
- buf[pos++] = c >> 12 & 63 | 128;
1598
- }
1599
- buf[pos++] = c >> 6 & 63 | 128;
1600
- }
1601
- buf[pos++] = c & 63 | 128;
1471
+ indexMap.lineFeature++;
1472
+ break;
1473
+ case "Polygon":
1474
+ handlePolygon(geometry, polygons, indexMap, coordLength, properties);
1475
+ polygons.properties.push(keepStringProperties(properties, numericPropKeys));
1476
+ if (hasGlobalId) {
1477
+ polygons.fields.push({
1478
+ id: feature.id
1479
+ });
1602
1480
  }
1603
- }
1604
- return pos;
1481
+ indexMap.polygonFeature++;
1482
+ break;
1483
+ default:
1484
+ throw new Error("Invalid geometry type");
1605
1485
  }
1486
+ indexMap.feature++;
1606
1487
  }
1607
- });
1488
+ return makeAccessorObjects(points, lines, polygons, coordLength);
1489
+ }
1490
+ function handlePoint(geometry, points, indexMap, coordLength, properties) {
1491
+ points.positions.set(geometry.data, indexMap.pointPosition * coordLength);
1492
+ const nPositions = geometry.data.length / coordLength;
1493
+ fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);
1494
+ points.globalFeatureIds.fill(indexMap.feature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
1495
+ points.featureIds.fill(indexMap.pointFeature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
1496
+ indexMap.pointPosition += nPositions;
1497
+ }
1498
+ function handleLineString(geometry, lines, indexMap, coordLength, properties) {
1499
+ lines.positions.set(geometry.data, indexMap.linePosition * coordLength);
1500
+ const nPositions = geometry.data.length / coordLength;
1501
+ fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
1502
+ lines.globalFeatureIds.fill(indexMap.feature, indexMap.linePosition, indexMap.linePosition + nPositions);
1503
+ lines.featureIds.fill(indexMap.lineFeature, indexMap.linePosition, indexMap.linePosition + nPositions);
1504
+ for (let i2 = 0, il = geometry.indices.length; i2 < il; ++i2) {
1505
+ const start = geometry.indices[i2];
1506
+ const end = i2 === il - 1 ? geometry.data.length : geometry.indices[i2 + 1];
1507
+ lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
1508
+ indexMap.linePosition += (end - start) / coordLength;
1509
+ }
1510
+ }
1511
+ function handlePolygon(geometry, polygons, indexMap, coordLength, properties) {
1512
+ polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);
1513
+ const nPositions = geometry.data.length / coordLength;
1514
+ fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
1515
+ polygons.globalFeatureIds.fill(indexMap.feature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
1516
+ polygons.featureIds.fill(indexMap.polygonFeature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
1517
+ for (let l = 0, ll = geometry.indices.length; l < ll; ++l) {
1518
+ const startPosition = indexMap.polygonPosition;
1519
+ polygons.polygonIndices[indexMap.polygonObject++] = startPosition;
1520
+ const areas = geometry.areas[l];
1521
+ const indices = geometry.indices[l];
1522
+ const nextIndices = geometry.indices[l + 1];
1523
+ for (let i2 = 0, il = indices.length; i2 < il; ++i2) {
1524
+ const start = indices[i2];
1525
+ const end = i2 === il - 1 ? nextIndices === void 0 ? geometry.data.length : nextIndices[0] : indices[i2 + 1];
1526
+ polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
1527
+ indexMap.polygonPosition += (end - start) / coordLength;
1528
+ }
1529
+ const endPosition = indexMap.polygonPosition;
1530
+ triangulatePolygon(polygons, areas, indices, {
1531
+ startPosition,
1532
+ endPosition,
1533
+ coordLength
1534
+ });
1535
+ }
1536
+ }
1537
+ function triangulatePolygon(polygons, areas, indices, {
1538
+ startPosition,
1539
+ endPosition,
1540
+ coordLength
1541
+ }) {
1542
+ if (!polygons.triangles) {
1543
+ return;
1544
+ }
1545
+ const start = startPosition * coordLength;
1546
+ const end = endPosition * coordLength;
1547
+ const polygonPositions = polygons.positions.subarray(start, end);
1548
+ const offset = indices[0];
1549
+ const holes = indices.slice(1).map((n) => (n - offset) / coordLength);
1550
+ const triangles = earcut(polygonPositions, holes, coordLength, areas);
1551
+ for (let t = 0, tl = triangles.length; t < tl; ++t) {
1552
+ polygons.triangles.push(startPosition + triangles[t]);
1553
+ }
1554
+ }
1555
+ function wrapProps(obj, size) {
1556
+ const returnObj = {};
1557
+ for (const key in obj) {
1558
+ returnObj[key] = {
1559
+ value: obj[key],
1560
+ size
1561
+ };
1562
+ }
1563
+ return returnObj;
1564
+ }
1565
+ function makeAccessorObjects(points, lines, polygons, coordLength) {
1566
+ const binaryFeatures = {
1567
+ points: {
1568
+ ...points,
1569
+ positions: {
1570
+ value: points.positions,
1571
+ size: coordLength
1572
+ },
1573
+ globalFeatureIds: {
1574
+ value: points.globalFeatureIds,
1575
+ size: 1
1576
+ },
1577
+ featureIds: {
1578
+ value: points.featureIds,
1579
+ size: 1
1580
+ },
1581
+ numericProps: wrapProps(points.numericProps, 1)
1582
+ },
1583
+ lines: {
1584
+ ...lines,
1585
+ positions: {
1586
+ value: lines.positions,
1587
+ size: coordLength
1588
+ },
1589
+ pathIndices: {
1590
+ value: lines.pathIndices,
1591
+ size: 1
1592
+ },
1593
+ globalFeatureIds: {
1594
+ value: lines.globalFeatureIds,
1595
+ size: 1
1596
+ },
1597
+ featureIds: {
1598
+ value: lines.featureIds,
1599
+ size: 1
1600
+ },
1601
+ numericProps: wrapProps(lines.numericProps, 1)
1602
+ },
1603
+ polygons: {
1604
+ ...polygons,
1605
+ positions: {
1606
+ value: polygons.positions,
1607
+ size: coordLength
1608
+ },
1609
+ polygonIndices: {
1610
+ value: polygons.polygonIndices,
1611
+ size: 1
1612
+ },
1613
+ primitivePolygonIndices: {
1614
+ value: polygons.primitivePolygonIndices,
1615
+ size: 1
1616
+ },
1617
+ globalFeatureIds: {
1618
+ value: polygons.globalFeatureIds,
1619
+ size: 1
1620
+ },
1621
+ featureIds: {
1622
+ value: polygons.featureIds,
1623
+ size: 1
1624
+ },
1625
+ numericProps: wrapProps(polygons.numericProps, 1)
1626
+ }
1627
+ };
1628
+ if (binaryFeatures.polygons && polygons.triangles) {
1629
+ binaryFeatures.polygons.triangles = {
1630
+ value: new Uint32Array(polygons.triangles),
1631
+ size: 1
1632
+ };
1633
+ }
1634
+ return binaryFeatures;
1635
+ }
1636
+ function fillNumericProperties(object, properties, index, length2) {
1637
+ for (const numericPropName in object.numericProps) {
1638
+ if (numericPropName in properties) {
1639
+ const value = properties[numericPropName];
1640
+ object.numericProps[numericPropName].fill(value, index, index + length2);
1641
+ }
1642
+ }
1643
+ }
1644
+ function keepStringProperties(properties, numericKeys) {
1645
+ const props = {};
1646
+ for (const key in properties) {
1647
+ if (!numericKeys.includes(key)) {
1648
+ props[key] = properties[key];
1649
+ }
1650
+ }
1651
+ return props;
1652
+ }
1653
+ function deduceArrayType(x2, constructor) {
1654
+ if (constructor === Array || !Number.isFinite(x2)) {
1655
+ return Array;
1656
+ }
1657
+ return constructor === Float64Array || Math.fround(x2) !== x2 ? Float64Array : Float32Array;
1658
+ }
1659
+
1660
+ // src/lib/parse-mvt.ts
1661
+ var import_pbf = __toESM(require_pbf(), 1);
1608
1662
 
1609
1663
  // src/helpers/mapbox-util-functions.ts
1610
1664
  function classifyRings(rings) {
@@ -1660,175 +1714,191 @@
1660
1714
  feature.properties[key] = value;
1661
1715
  }
1662
1716
  }
1663
- var init_mapbox_util_functions = __esm({
1664
- "src/helpers/mapbox-util-functions.ts"() {
1665
- }
1666
- });
1667
1717
 
1668
1718
  // src/lib/mapbox-vector-tile/vector-tile-feature.ts
1669
- var VectorTileFeature;
1670
- var init_vector_tile_feature = __esm({
1671
- "src/lib/mapbox-vector-tile/vector-tile-feature.ts"() {
1672
- init_mapbox_util_functions();
1673
- VectorTileFeature = class {
1674
- static get types() {
1675
- return ["Unknown", "Point", "LineString", "Polygon"];
1719
+ var VectorTileFeature = class {
1720
+ static get types() {
1721
+ return ["Unknown", "Point", "LineString", "Polygon"];
1722
+ }
1723
+ constructor(pbf, end, extent, keys, values) {
1724
+ this.properties = {};
1725
+ this.extent = extent;
1726
+ this.type = 0;
1727
+ this.id = null;
1728
+ this._pbf = pbf;
1729
+ this._geometry = -1;
1730
+ this._keys = keys;
1731
+ this._values = values;
1732
+ pbf.readFields(readFeature, this, end);
1733
+ }
1734
+ loadGeometry() {
1735
+ const pbf = this._pbf;
1736
+ pbf.pos = this._geometry;
1737
+ const end = pbf.readVarint() + pbf.pos;
1738
+ let cmd2 = 1;
1739
+ let length2 = 0;
1740
+ let x2 = 0;
1741
+ let y2 = 0;
1742
+ const lines = [];
1743
+ let line;
1744
+ while (pbf.pos < end) {
1745
+ if (length2 <= 0) {
1746
+ const cmdLen2 = pbf.readVarint();
1747
+ cmd2 = cmdLen2 & 7;
1748
+ length2 = cmdLen2 >> 3;
1676
1749
  }
1677
- constructor(pbf, end, extent, keys, values) {
1678
- this.properties = {};
1679
- this.extent = extent;
1680
- this.type = 0;
1681
- this.id = null;
1682
- this._pbf = pbf;
1683
- this._geometry = -1;
1684
- this._keys = keys;
1685
- this._values = values;
1686
- pbf.readFields(readFeature, this, end);
1687
- }
1688
- loadGeometry() {
1689
- const pbf = this._pbf;
1690
- pbf.pos = this._geometry;
1691
- const end = pbf.readVarint() + pbf.pos;
1692
- let cmd2 = 1;
1693
- let length2 = 0;
1694
- let x2 = 0;
1695
- let y2 = 0;
1696
- const lines = [];
1697
- let line;
1698
- while (pbf.pos < end) {
1699
- if (length2 <= 0) {
1700
- const cmdLen2 = pbf.readVarint();
1701
- cmd2 = cmdLen2 & 7;
1702
- length2 = cmdLen2 >> 3;
1703
- }
1704
- length2--;
1705
- if (cmd2 === 1 || cmd2 === 2) {
1706
- x2 += pbf.readSVarint();
1707
- y2 += pbf.readSVarint();
1708
- if (cmd2 === 1) {
1709
- if (line)
1710
- lines.push(line);
1711
- line = [];
1712
- }
1713
- if (line)
1714
- line.push([x2, y2]);
1715
- } else if (cmd2 === 7) {
1716
- if (line) {
1717
- line.push(line[0].slice());
1718
- }
1719
- } else {
1720
- throw new Error(`unknown command ${cmd2}`);
1721
- }
1750
+ length2--;
1751
+ if (cmd2 === 1 || cmd2 === 2) {
1752
+ x2 += pbf.readSVarint();
1753
+ y2 += pbf.readSVarint();
1754
+ if (cmd2 === 1) {
1755
+ if (line)
1756
+ lines.push(line);
1757
+ line = [];
1722
1758
  }
1723
1759
  if (line)
1724
- lines.push(line);
1725
- return lines;
1726
- }
1727
- bbox() {
1728
- const pbf = this._pbf;
1729
- pbf.pos = this._geometry;
1730
- const end = pbf.readVarint() + pbf.pos;
1731
- let cmd2 = 1;
1732
- let length2 = 0;
1733
- let x2 = 0;
1734
- let y2 = 0;
1735
- let x1 = Infinity;
1736
- let x22 = -Infinity;
1737
- let y1 = Infinity;
1738
- let y22 = -Infinity;
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 (x2 < x1)
1750
- x1 = x2;
1751
- if (x2 > x22)
1752
- x22 = x2;
1753
- if (y2 < y1)
1754
- y1 = y2;
1755
- if (y2 > y22)
1756
- y22 = y2;
1757
- } else if (cmd2 !== 7) {
1758
- throw new Error(`unknown command ${cmd2}`);
1759
- }
1760
+ line.push([x2, y2]);
1761
+ } else if (cmd2 === 7) {
1762
+ if (line) {
1763
+ line.push(line[0].slice());
1760
1764
  }
1761
- return [x1, y1, x22, y22];
1765
+ } else {
1766
+ throw new Error(`unknown command ${cmd2}`);
1762
1767
  }
1763
- _toGeoJSON(transform) {
1764
- let coords = this.loadGeometry();
1765
- let type = VectorTileFeature.types[this.type];
1766
- let i2;
1767
- let j;
1768
- switch (this.type) {
1769
- case 1:
1770
- const points = [];
1771
- for (i2 = 0; i2 < coords.length; i2++) {
1772
- points[i2] = coords[i2][0];
1773
- }
1774
- coords = points;
1775
- transform(coords, this);
1776
- break;
1777
- case 2:
1778
- for (i2 = 0; i2 < coords.length; i2++) {
1779
- transform(coords[i2], this);
1780
- }
1781
- break;
1782
- case 3:
1783
- coords = classifyRings(coords);
1784
- for (i2 = 0; i2 < coords.length; i2++) {
1785
- for (j = 0; j < coords[i2].length; j++) {
1786
- transform(coords[i2][j], this);
1787
- }
1788
- }
1789
- break;
1790
- }
1791
- if (coords.length === 1) {
1792
- coords = coords[0];
1793
- } else {
1794
- type = `Multi${type}`;
1795
- }
1796
- const result = {
1797
- type: "Feature",
1798
- geometry: {
1799
- type,
1800
- coordinates: coords
1801
- },
1802
- properties: this.properties
1803
- };
1804
- if (this.id !== null) {
1805
- result.id = this.id;
1806
- }
1807
- return result;
1768
+ }
1769
+ if (line)
1770
+ lines.push(line);
1771
+ return lines;
1772
+ }
1773
+ bbox() {
1774
+ const pbf = this._pbf;
1775
+ pbf.pos = this._geometry;
1776
+ const end = pbf.readVarint() + pbf.pos;
1777
+ let cmd2 = 1;
1778
+ let length2 = 0;
1779
+ let x2 = 0;
1780
+ let y2 = 0;
1781
+ let x1 = Infinity;
1782
+ let x22 = -Infinity;
1783
+ let y1 = Infinity;
1784
+ let y22 = -Infinity;
1785
+ while (pbf.pos < end) {
1786
+ if (length2 <= 0) {
1787
+ const cmdLen2 = pbf.readVarint();
1788
+ cmd2 = cmdLen2 & 7;
1789
+ length2 = cmdLen2 >> 3;
1808
1790
  }
1809
- toGeoJSON(options) {
1810
- if (typeof options === "function") {
1811
- return this._toGeoJSON(options);
1791
+ length2--;
1792
+ if (cmd2 === 1 || cmd2 === 2) {
1793
+ x2 += pbf.readSVarint();
1794
+ y2 += pbf.readSVarint();
1795
+ if (x2 < x1)
1796
+ x1 = x2;
1797
+ if (x2 > x22)
1798
+ x22 = x2;
1799
+ if (y2 < y1)
1800
+ y1 = y2;
1801
+ if (y2 > y22)
1802
+ y22 = y2;
1803
+ } else if (cmd2 !== 7) {
1804
+ throw new Error(`unknown command ${cmd2}`);
1805
+ }
1806
+ }
1807
+ return [x1, y1, x22, y22];
1808
+ }
1809
+ _toGeoJSON(transform) {
1810
+ let coords = this.loadGeometry();
1811
+ let type = VectorTileFeature.types[this.type];
1812
+ let i2;
1813
+ let j;
1814
+ switch (this.type) {
1815
+ case 1:
1816
+ const points = [];
1817
+ for (i2 = 0; i2 < coords.length; i2++) {
1818
+ points[i2] = coords[i2][0];
1812
1819
  }
1813
- const { x: x2, y: y2, z } = options;
1814
- const size = this.extent * Math.pow(2, z);
1815
- const x0 = this.extent * x2;
1816
- const y0 = this.extent * y2;
1817
- function project2(line) {
1818
- for (let j = 0; j < line.length; j++) {
1819
- const p = line[j];
1820
- p[0] = (p[0] + x0) * 360 / size - 180;
1821
- const y22 = 180 - (p[1] + y0) * 360 / size;
1822
- p[1] = 360 / Math.PI * Math.atan(Math.exp(y22 * Math.PI / 180)) - 90;
1820
+ coords = points;
1821
+ transform(coords, this);
1822
+ break;
1823
+ case 2:
1824
+ for (i2 = 0; i2 < coords.length; i2++) {
1825
+ transform(coords[i2], this);
1826
+ }
1827
+ break;
1828
+ case 3:
1829
+ coords = classifyRings(coords);
1830
+ for (i2 = 0; i2 < coords.length; i2++) {
1831
+ for (j = 0; j < coords[i2].length; j++) {
1832
+ transform(coords[i2][j], this);
1823
1833
  }
1824
1834
  }
1825
- return this._toGeoJSON(project2);
1826
- }
1835
+ break;
1836
+ }
1837
+ if (coords.length === 1) {
1838
+ coords = coords[0];
1839
+ } else {
1840
+ type = `Multi${type}`;
1841
+ }
1842
+ const result = {
1843
+ type: "Feature",
1844
+ geometry: {
1845
+ type,
1846
+ coordinates: coords
1847
+ },
1848
+ properties: this.properties
1827
1849
  };
1850
+ if (this.id !== null) {
1851
+ result.id = this.id;
1852
+ }
1853
+ return result;
1828
1854
  }
1829
- });
1855
+ toGeoJSON(options) {
1856
+ if (typeof options === "function") {
1857
+ return this._toGeoJSON(options);
1858
+ }
1859
+ const {
1860
+ x: x2,
1861
+ y: y2,
1862
+ z
1863
+ } = options;
1864
+ const size = this.extent * Math.pow(2, z);
1865
+ const x0 = this.extent * x2;
1866
+ const y0 = this.extent * y2;
1867
+ function project2(line) {
1868
+ for (let j = 0; j < line.length; j++) {
1869
+ const p = line[j];
1870
+ p[0] = (p[0] + x0) * 360 / size - 180;
1871
+ const y22 = 180 - (p[1] + y0) * 360 / size;
1872
+ p[1] = 360 / Math.PI * Math.atan(Math.exp(y22 * Math.PI / 180)) - 90;
1873
+ }
1874
+ }
1875
+ return this._toGeoJSON(project2);
1876
+ }
1877
+ };
1830
1878
 
1831
1879
  // src/lib/mapbox-vector-tile/vector-tile-layer.ts
1880
+ var VectorTileLayer = class {
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;
1892
+ }
1893
+ feature(i2) {
1894
+ if (i2 < 0 || i2 >= this._features.length) {
1895
+ throw new Error("feature index out of bounds");
1896
+ }
1897
+ this._pbf.pos = this._features[i2];
1898
+ const end = this._pbf.readVarint() + this._pbf.pos;
1899
+ return new VectorTileFeature(this._pbf, end, this.extent, this._keys, this._values);
1900
+ }
1901
+ };
1832
1902
  function readLayer(tag, layer, pbf) {
1833
1903
  if (layer && pbf) {
1834
1904
  if (tag === 15)
@@ -1854,36 +1924,13 @@
1854
1924
  }
1855
1925
  return value;
1856
1926
  }
1857
- var VectorTileLayer;
1858
- var init_vector_tile_layer = __esm({
1859
- "src/lib/mapbox-vector-tile/vector-tile-layer.ts"() {
1860
- init_vector_tile_feature();
1861
- VectorTileLayer = class {
1862
- constructor(pbf, end) {
1863
- this.version = 1;
1864
- this.name = "";
1865
- this.extent = 4096;
1866
- this.length = 0;
1867
- this._pbf = pbf;
1868
- this._keys = [];
1869
- this._values = [];
1870
- this._features = [];
1871
- pbf.readFields(readLayer, this, end);
1872
- this.length = this._features.length;
1873
- }
1874
- feature(i2) {
1875
- if (i2 < 0 || i2 >= this._features.length) {
1876
- throw new Error("feature index out of bounds");
1877
- }
1878
- this._pbf.pos = this._features[i2];
1879
- const end = this._pbf.readVarint() + this._pbf.pos;
1880
- return new VectorTileFeature(this._pbf, end, this.extent, this._keys, this._values);
1881
- }
1882
- };
1883
- }
1884
- });
1885
1927
 
1886
1928
  // src/lib/mapbox-vector-tile/vector-tile.ts
1929
+ var VectorTile = class {
1930
+ constructor(pbf, end) {
1931
+ this.layers = pbf.readFields(readTile, {}, end);
1932
+ }
1933
+ };
1887
1934
  function readTile(tag, layers, pbf) {
1888
1935
  if (tag === 3) {
1889
1936
  if (pbf) {
@@ -1894,17 +1941,6 @@
1894
1941
  }
1895
1942
  }
1896
1943
  }
1897
- var VectorTile;
1898
- var init_vector_tile = __esm({
1899
- "src/lib/mapbox-vector-tile/vector-tile.ts"() {
1900
- init_vector_tile_layer();
1901
- VectorTile = class {
1902
- constructor(pbf, end) {
1903
- this.layers = pbf.readFields(readTile, {}, end);
1904
- }
1905
- };
1906
- }
1907
- });
1908
1944
 
1909
1945
  // src/helpers/binary-util-functions.ts
1910
1946
  function classifyRings2(geom) {
@@ -1954,7 +1990,12 @@
1954
1990
  areas.push(ringAreas);
1955
1991
  if (polygon.length)
1956
1992
  polygons.push(polygon);
1957
- return { type, areas, indices: polygons, data: geom.data };
1993
+ return {
1994
+ type,
1995
+ areas,
1996
+ indices: polygons,
1997
+ data: geom.data
1998
+ };
1958
1999
  }
1959
2000
  function project(data, x0, y0, size) {
1960
2001
  for (let j = 0, jl = data.length; j < jl; j += 2) {
@@ -1983,118 +2024,153 @@
1983
2024
  feature.properties[key] = value;
1984
2025
  }
1985
2026
  }
1986
- var init_binary_util_functions = __esm({
1987
- "src/helpers/binary-util-functions.ts"() {
1988
- init_esm();
1989
- }
1990
- });
1991
2027
 
1992
2028
  // src/lib/binary-vector-tile/vector-tile-feature.ts
1993
- var endPos, cmd, cmdLen, length, x, y, i, VectorTileFeature2;
1994
- var init_vector_tile_feature2 = __esm({
1995
- "src/lib/binary-vector-tile/vector-tile-feature.ts"() {
1996
- init_binary_util_functions();
1997
- VectorTileFeature2 = class {
1998
- constructor(pbf, end, extent, keys, values, geometryInfo) {
1999
- this.properties = {};
2000
- this.extent = extent;
2001
- this.type = 0;
2002
- this.id = null;
2003
- this._pbf = pbf;
2004
- this._geometry = -1;
2005
- this._keys = keys;
2006
- this._values = values;
2007
- this._geometryInfo = geometryInfo;
2008
- pbf.readFields(readFeature2, this, end);
2009
- }
2010
- loadGeometry() {
2011
- const pbf = this._pbf;
2012
- pbf.pos = this._geometry;
2013
- endPos = pbf.readVarint() + pbf.pos;
2014
- cmd = 1;
2015
- length = 0;
2016
- x = 0;
2017
- y = 0;
2018
- i = 0;
2019
- const indices = [];
2020
- const data = [];
2021
- while (pbf.pos < endPos) {
2022
- if (length <= 0) {
2023
- cmdLen = pbf.readVarint();
2024
- cmd = cmdLen & 7;
2025
- length = cmdLen >> 3;
2026
- }
2027
- length--;
2028
- if (cmd === 1 || cmd === 2) {
2029
- x += pbf.readSVarint();
2030
- y += pbf.readSVarint();
2031
- if (cmd === 1) {
2032
- indices.push(i);
2033
- }
2034
- data.push(x, y);
2035
- i += 2;
2036
- } else if (cmd === 7) {
2037
- if (i > 0) {
2038
- const start = indices[indices.length - 1];
2039
- data.push(data[start], data[start + 1]);
2040
- i += 2;
2041
- }
2042
- } else {
2043
- throw new Error(`unknown command ${cmd}`);
2044
- }
2045
- }
2046
- return { data, indices };
2029
+ var endPos;
2030
+ var cmd;
2031
+ var cmdLen;
2032
+ var length;
2033
+ var x;
2034
+ var y;
2035
+ var i;
2036
+ var VectorTileFeature2 = class {
2037
+ constructor(pbf, end, extent, keys, values, geometryInfo) {
2038
+ this.properties = {};
2039
+ this.extent = extent;
2040
+ this.type = 0;
2041
+ this.id = null;
2042
+ this._pbf = pbf;
2043
+ this._geometry = -1;
2044
+ this._keys = keys;
2045
+ this._values = values;
2046
+ this._geometryInfo = geometryInfo;
2047
+ pbf.readFields(readFeature2, this, end);
2048
+ }
2049
+ loadGeometry() {
2050
+ const pbf = this._pbf;
2051
+ pbf.pos = this._geometry;
2052
+ endPos = pbf.readVarint() + pbf.pos;
2053
+ cmd = 1;
2054
+ length = 0;
2055
+ x = 0;
2056
+ y = 0;
2057
+ i = 0;
2058
+ const indices = [];
2059
+ const data = [];
2060
+ while (pbf.pos < endPos) {
2061
+ if (length <= 0) {
2062
+ cmdLen = pbf.readVarint();
2063
+ cmd = cmdLen & 7;
2064
+ length = cmdLen >> 3;
2047
2065
  }
2048
- _toBinaryCoordinates(transform) {
2049
- const geom = this.loadGeometry();
2050
- let geometry;
2051
- transform(geom.data, this);
2052
- const coordLength = 2;
2053
- switch (this.type) {
2054
- case 1:
2055
- this._geometryInfo.pointFeaturesCount++;
2056
- this._geometryInfo.pointPositionsCount += geom.indices.length;
2057
- geometry = { type: "Point", ...geom };
2058
- break;
2059
- case 2:
2060
- this._geometryInfo.lineFeaturesCount++;
2061
- this._geometryInfo.linePathsCount += geom.indices.length;
2062
- this._geometryInfo.linePositionsCount += geom.data.length / coordLength;
2063
- geometry = { type: "LineString", ...geom };
2064
- break;
2065
- case 3:
2066
- geometry = classifyRings2(geom);
2067
- this._geometryInfo.polygonFeaturesCount++;
2068
- this._geometryInfo.polygonObjectsCount += geometry.indices.length;
2069
- for (const indices of geometry.indices) {
2070
- this._geometryInfo.polygonRingsCount += indices.length;
2071
- }
2072
- this._geometryInfo.polygonPositionsCount += geometry.data.length / coordLength;
2073
- break;
2074
- default:
2075
- throw new Error(`Invalid geometry type: ${this.type}`);
2066
+ length--;
2067
+ if (cmd === 1 || cmd === 2) {
2068
+ x += pbf.readSVarint();
2069
+ y += pbf.readSVarint();
2070
+ if (cmd === 1) {
2071
+ indices.push(i);
2076
2072
  }
2077
- const result = { type: "Feature", geometry, properties: this.properties };
2078
- if (this.id !== null) {
2079
- result.id = this.id;
2073
+ data.push(x, y);
2074
+ i += 2;
2075
+ } else if (cmd === 7) {
2076
+ if (i > 0) {
2077
+ const start = indices[indices.length - 1];
2078
+ data.push(data[start], data[start + 1]);
2079
+ i += 2;
2080
2080
  }
2081
- return result;
2081
+ } else {
2082
+ throw new Error(`unknown command ${cmd}`);
2082
2083
  }
2083
- toBinaryCoordinates(options) {
2084
- if (typeof options === "function") {
2085
- return this._toBinaryCoordinates(options);
2084
+ }
2085
+ return {
2086
+ data,
2087
+ indices
2088
+ };
2089
+ }
2090
+ _toBinaryCoordinates(transform) {
2091
+ const geom = this.loadGeometry();
2092
+ let geometry;
2093
+ transform(geom.data, this);
2094
+ const coordLength = 2;
2095
+ switch (this.type) {
2096
+ case 1:
2097
+ this._geometryInfo.pointFeaturesCount++;
2098
+ this._geometryInfo.pointPositionsCount += geom.indices.length;
2099
+ geometry = {
2100
+ type: "Point",
2101
+ ...geom
2102
+ };
2103
+ break;
2104
+ case 2:
2105
+ this._geometryInfo.lineFeaturesCount++;
2106
+ this._geometryInfo.linePathsCount += geom.indices.length;
2107
+ this._geometryInfo.linePositionsCount += geom.data.length / coordLength;
2108
+ geometry = {
2109
+ type: "LineString",
2110
+ ...geom
2111
+ };
2112
+ break;
2113
+ case 3:
2114
+ geometry = classifyRings2(geom);
2115
+ this._geometryInfo.polygonFeaturesCount++;
2116
+ this._geometryInfo.polygonObjectsCount += geometry.indices.length;
2117
+ for (const indices of geometry.indices) {
2118
+ this._geometryInfo.polygonRingsCount += indices.length;
2086
2119
  }
2087
- const { x: x2, y: y2, z } = options;
2088
- const size = this.extent * Math.pow(2, z);
2089
- const x0 = this.extent * x2;
2090
- const y0 = this.extent * y2;
2091
- return this._toBinaryCoordinates((data) => project(data, x0, y0, size));
2092
- }
2120
+ this._geometryInfo.polygonPositionsCount += geometry.data.length / coordLength;
2121
+ break;
2122
+ default:
2123
+ throw new Error(`Invalid geometry type: ${this.type}`);
2124
+ }
2125
+ const result = {
2126
+ type: "Feature",
2127
+ geometry,
2128
+ properties: this.properties
2093
2129
  };
2130
+ if (this.id !== null) {
2131
+ result.id = this.id;
2132
+ }
2133
+ return result;
2094
2134
  }
2095
- });
2135
+ toBinaryCoordinates(options) {
2136
+ if (typeof options === "function") {
2137
+ return this._toBinaryCoordinates(options);
2138
+ }
2139
+ const {
2140
+ x: x2,
2141
+ y: y2,
2142
+ z
2143
+ } = 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));
2148
+ }
2149
+ };
2096
2150
 
2097
2151
  // src/lib/binary-vector-tile/vector-tile-layer.ts
2152
+ var VectorTileLayer2 = class {
2153
+ constructor(pbf, end) {
2154
+ this.version = 1;
2155
+ this.name = "";
2156
+ this.extent = 4096;
2157
+ this.length = 0;
2158
+ this._pbf = pbf;
2159
+ this._keys = [];
2160
+ this._values = [];
2161
+ this._features = [];
2162
+ pbf.readFields(readLayer2, this, end);
2163
+ this.length = this._features.length;
2164
+ }
2165
+ feature(i2, geometryInfo) {
2166
+ if (i2 < 0 || i2 >= this._features.length) {
2167
+ throw new Error("feature index out of bounds");
2168
+ }
2169
+ this._pbf.pos = this._features[i2];
2170
+ const end = this._pbf.readVarint() + this._pbf.pos;
2171
+ return new VectorTileFeature2(this._pbf, end, this.extent, this._keys, this._values, geometryInfo);
2172
+ }
2173
+ };
2098
2174
  function readLayer2(tag, layer, pbf) {
2099
2175
  if (layer && pbf) {
2100
2176
  if (tag === 15)
@@ -2118,38 +2194,15 @@
2118
2194
  const tag = pbf.readVarint() >> 3;
2119
2195
  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;
2120
2196
  }
2121
- return value;
2122
- }
2123
- var VectorTileLayer2;
2124
- var init_vector_tile_layer2 = __esm({
2125
- "src/lib/binary-vector-tile/vector-tile-layer.ts"() {
2126
- init_vector_tile_feature2();
2127
- VectorTileLayer2 = class {
2128
- constructor(pbf, end) {
2129
- this.version = 1;
2130
- this.name = "";
2131
- this.extent = 4096;
2132
- this.length = 0;
2133
- this._pbf = pbf;
2134
- this._keys = [];
2135
- this._values = [];
2136
- this._features = [];
2137
- pbf.readFields(readLayer2, this, end);
2138
- this.length = this._features.length;
2139
- }
2140
- feature(i2, geometryInfo) {
2141
- if (i2 < 0 || i2 >= this._features.length) {
2142
- throw new Error("feature index out of bounds");
2143
- }
2144
- this._pbf.pos = this._features[i2];
2145
- const end = this._pbf.readVarint() + this._pbf.pos;
2146
- return new VectorTileFeature2(this._pbf, end, this.extent, this._keys, this._values, geometryInfo);
2147
- }
2148
- };
2149
- }
2150
- });
2197
+ return value;
2198
+ }
2151
2199
 
2152
2200
  // src/lib/binary-vector-tile/vector-tile.ts
2201
+ var VectorTile2 = class {
2202
+ constructor(pbf, end) {
2203
+ this.layers = pbf.readFields(readTile2, {}, end);
2204
+ }
2205
+ };
2153
2206
  function readTile2(tag, layers, pbf) {
2154
2207
  if (tag === 3) {
2155
2208
  if (pbf) {
@@ -2160,17 +2213,6 @@
2160
2213
  }
2161
2214
  }
2162
2215
  }
2163
- var VectorTile2;
2164
- var init_vector_tile2 = __esm({
2165
- "src/lib/binary-vector-tile/vector-tile.ts"() {
2166
- init_vector_tile_layer2();
2167
- VectorTile2 = class {
2168
- constructor(pbf, end) {
2169
- this.layers = pbf.readFields(readTile2, {}, end);
2170
- }
2171
- };
2172
- }
2173
- });
2174
2216
 
2175
2217
  // src/lib/parse-mvt.ts
2176
2218
  function parseMVT(arrayBuffer, options) {
@@ -2178,7 +2220,10 @@
2178
2220
  const shape = options?.gis?.format || options?.mvt?.shape || options?.shape;
2179
2221
  switch (shape) {
2180
2222
  case "columnar-table":
2181
- return { shape: "columnar-table", data: parseToBinary(arrayBuffer, mvtOptions) };
2223
+ return {
2224
+ shape: "columnar-table",
2225
+ data: parseToBinary(arrayBuffer, mvtOptions)
2226
+ };
2182
2227
  case "geojson-table": {
2183
2228
  const table = {
2184
2229
  shape: "geojson-table",
@@ -2260,7 +2305,9 @@
2260
2305
  throw new Error("mvt options required");
2261
2306
  }
2262
2307
  const wgs84Coordinates = options.mvt?.coordinates === "wgs84";
2263
- const { tileIndex } = options.mvt;
2308
+ const {
2309
+ tileIndex
2310
+ } = options.mvt;
2264
2311
  const hasTileIndex = tileIndex && Number.isFinite(tileIndex.x) && Number.isFinite(tileIndex.y) && Number.isFinite(tileIndex.z);
2265
2312
  if (wgs84Coordinates && !hasTileIndex) {
2266
2313
  throw new Error("MVT Loader: WGS84 coordinates need tileIndex property");
@@ -2282,7 +2329,9 @@
2282
2329
  return decodedFeature;
2283
2330
  }
2284
2331
  function transformToLocalCoordinates(line, feature) {
2285
- const { extent } = feature;
2332
+ const {
2333
+ extent
2334
+ } = feature;
2286
2335
  for (let i2 = 0; i2 < line.length; i2++) {
2287
2336
  const p = line[i2];
2288
2337
  p[0] /= extent;
@@ -2290,59 +2339,44 @@
2290
2339
  }
2291
2340
  }
2292
2341
  function transformToLocalCoordinatesBinary(data, feature) {
2293
- const { extent } = feature;
2342
+ const {
2343
+ extent
2344
+ } = feature;
2294
2345
  for (let i2 = 0, il = data.length; i2 < il; ++i2) {
2295
2346
  data[i2] /= extent;
2296
2347
  }
2297
2348
  }
2298
- var import_pbf;
2299
- var init_parse_mvt = __esm({
2300
- "src/lib/parse-mvt.ts"() {
2301
- init_src();
2302
- import_pbf = __toModule(require_pbf());
2303
- init_vector_tile();
2304
- init_vector_tile2();
2305
- }
2306
- });
2307
2349
 
2308
2350
  // src/mvt-loader.ts
2309
- var VERSION, MVTWorkerLoader, MVTLoader;
2310
- var init_mvt_loader = __esm({
2311
- "src/mvt-loader.ts"() {
2312
- init_parse_mvt();
2313
- VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
2314
- MVTWorkerLoader = {
2315
- name: "Mapbox Vector Tile",
2316
- id: "mvt",
2317
- module: "mvt",
2318
- version: VERSION,
2319
- extensions: ["mvt", "pbf"],
2320
- mimeTypes: [
2321
- "application/vnd.mapbox-vector-tile",
2322
- "application/x-protobuf"
2323
- ],
2324
- worker: true,
2325
- category: "geometry",
2326
- options: {
2327
- mvt: {
2328
- shape: "geojson",
2329
- coordinates: "local",
2330
- layerProperty: "layerName",
2331
- layers: void 0,
2332
- tileIndex: null
2333
- }
2334
- }
2335
- };
2336
- MVTLoader = {
2337
- ...MVTWorkerLoader,
2338
- parse: async (arrayBuffer, options) => parseMVT(arrayBuffer, options),
2339
- parseSync: parseMVT,
2340
- binary: true
2341
- };
2351
+ var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
2352
+ var MVTWorkerLoader = {
2353
+ name: "Mapbox Vector Tile",
2354
+ id: "mvt",
2355
+ module: "mvt",
2356
+ version: VERSION,
2357
+ extensions: ["mvt", "pbf"],
2358
+ mimeTypes: ["application/vnd.mapbox-vector-tile", "application/x-protobuf"],
2359
+ worker: true,
2360
+ category: "geometry",
2361
+ options: {
2362
+ mvt: {
2363
+ shape: "geojson",
2364
+ coordinates: "local",
2365
+ layerProperty: "layerName",
2366
+ layers: void 0,
2367
+ tileIndex: null
2368
+ }
2342
2369
  }
2343
- });
2370
+ };
2371
+ var MVTLoader = {
2372
+ ...MVTWorkerLoader,
2373
+ parse: async (arrayBuffer, options) => parseMVT(arrayBuffer, options),
2374
+ parseSync: parseMVT,
2375
+ binary: true
2376
+ };
2344
2377
 
2345
2378
  // src/lib/parse-tilejson.ts
2379
+ var isObject = (x2) => x2 !== null && typeof x2 === "object";
2346
2380
  function parseTileJSON(jsonMetadata) {
2347
2381
  if (!jsonMetadata || !isObject(jsonMetadata)) {
2348
2382
  return null;
@@ -2420,10 +2454,7 @@
2420
2454
  function parseBounds(bounds) {
2421
2455
  const result = fromArrayOrString(bounds);
2422
2456
  if (Array.isArray(result) && result.length === 4 && [result[0], result[2]].every(isLng) && [result[1], result[3]].every(isLat)) {
2423
- return [
2424
- [result[0], result[1]],
2425
- [result[2], result[3]]
2426
- ];
2457
+ return [[result[0], result[1]], [result[2], result[3]]];
2427
2458
  }
2428
2459
  return void 0;
2429
2460
  }
@@ -2455,6 +2486,35 @@
2455
2486
  }
2456
2487
  return null;
2457
2488
  }
2489
+ var attrTypeMap = {
2490
+ number: {
2491
+ type: "float32"
2492
+ },
2493
+ numeric: {
2494
+ type: "float32"
2495
+ },
2496
+ string: {
2497
+ type: "utf8"
2498
+ },
2499
+ vachar: {
2500
+ type: "utf8"
2501
+ },
2502
+ float: {
2503
+ type: "float32"
2504
+ },
2505
+ int: {
2506
+ type: "int32"
2507
+ },
2508
+ int4: {
2509
+ type: "int32"
2510
+ },
2511
+ boolean: {
2512
+ type: "boolean"
2513
+ },
2514
+ bool: {
2515
+ type: "boolean"
2516
+ }
2517
+ };
2458
2518
  function attributeToField(attribute = {}) {
2459
2519
  const fieldTypes = attributeTypeToFieldType(attribute.type);
2460
2520
  return {
@@ -2466,74 +2526,591 @@
2466
2526
  const type = aType.toLowerCase();
2467
2527
  if (!type || !attrTypeMap[type]) {
2468
2528
  }
2469
- return attrTypeMap[type] || { type: "string" };
2529
+ return attrTypeMap[type] || {
2530
+ type: "string"
2531
+ };
2470
2532
  }
2471
- var isObject, attrTypeMap;
2472
- var init_parse_tilejson = __esm({
2473
- "src/lib/parse-tilejson.ts"() {
2474
- isObject = (x2) => x2 !== null && typeof x2 === "object";
2475
- attrTypeMap = {
2476
- number: {
2477
- type: "float32"
2478
- },
2479
- numeric: {
2480
- type: "float32"
2481
- },
2482
- string: {
2483
- type: "utf8"
2484
- },
2485
- vachar: {
2486
- type: "utf8"
2487
- },
2488
- float: {
2489
- type: "float32"
2490
- },
2491
- int: {
2492
- type: "int32"
2493
- },
2494
- int4: {
2495
- type: "int32"
2496
- },
2497
- boolean: {
2498
- type: "boolean"
2499
- },
2500
- bool: {
2501
- type: "boolean"
2502
- }
2533
+
2534
+ // src/tilejson-loader.ts
2535
+ var VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
2536
+ var TileJSONLoader = {
2537
+ name: "TileJSON",
2538
+ id: "tilejson",
2539
+ module: "pmtiles",
2540
+ version: VERSION2,
2541
+ worker: true,
2542
+ extensions: ["json"],
2543
+ mimeTypes: ["application/json"],
2544
+ text: true,
2545
+ options: {
2546
+ tilejson: {}
2547
+ },
2548
+ parse: async (arrayBuffer, options) => {
2549
+ const jsonString = new TextDecoder().decode(arrayBuffer);
2550
+ const json = JSON.parse(jsonString);
2551
+ return parseTileJSON(json);
2552
+ },
2553
+ parseTextSync: (text, options) => {
2554
+ const json = JSON.parse(text);
2555
+ return parseTileJSON(json);
2556
+ }
2557
+ };
2558
+
2559
+ // ../loader-utils/src/lib/env-utils/assert.ts
2560
+ function assert(condition, message) {
2561
+ if (!condition) {
2562
+ throw new Error(message || "loader assertion failed.");
2563
+ }
2564
+ }
2565
+
2566
+ // ../loader-utils/src/lib/env-utils/globals.ts
2567
+ var globals = {
2568
+ self: typeof self !== "undefined" && self,
2569
+ window: typeof window !== "undefined" && window,
2570
+ global: typeof global !== "undefined" && global,
2571
+ document: typeof document !== "undefined" && document
2572
+ };
2573
+ var self_ = globals.self || globals.window || globals.global || {};
2574
+ var window_ = globals.window || globals.self || globals.global || {};
2575
+ var global_ = globals.global || globals.self || globals.window || {};
2576
+ var document_ = globals.document || {};
2577
+ var isBrowser = Boolean(typeof process !== "object" || String(process) !== "[object process]" || process.browser);
2578
+ var matches = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
2579
+ var nodeVersion = matches && parseFloat(matches[1]) || 0;
2580
+
2581
+ // ../loader-utils/src/lib/path-utils/file-aliases.ts
2582
+ var pathPrefix = "";
2583
+ var fileAliases = {};
2584
+ function resolvePath(filename) {
2585
+ for (const alias in fileAliases) {
2586
+ if (filename.startsWith(alias)) {
2587
+ const replacement = fileAliases[alias];
2588
+ filename = filename.replace(alias, replacement);
2589
+ }
2590
+ }
2591
+ if (!filename.startsWith("http://") && !filename.startsWith("https://")) {
2592
+ filename = `${pathPrefix}${filename}`;
2593
+ }
2594
+ return filename;
2595
+ }
2596
+
2597
+ // ../loader-utils/src/lib/sources/data-source.ts
2598
+ var DataSource = class {
2599
+ _needsRefresh = true;
2600
+ constructor(props) {
2601
+ this.props = {
2602
+ ...props
2503
2603
  };
2604
+ this.loadOptions = {
2605
+ ...props.loadOptions
2606
+ };
2607
+ this.fetch = getFetchFunction(this.loadOptions);
2504
2608
  }
2505
- });
2609
+ setProps(props) {
2610
+ this.props = Object.assign(this.props, props);
2611
+ this.setNeedsRefresh();
2612
+ }
2613
+ setNeedsRefresh() {
2614
+ this._needsRefresh = true;
2615
+ }
2616
+ getNeedsRefresh(clear = true) {
2617
+ const needsRefresh = this._needsRefresh;
2618
+ if (clear) {
2619
+ this._needsRefresh = false;
2620
+ }
2621
+ return needsRefresh;
2622
+ }
2623
+ };
2624
+ function getFetchFunction(options) {
2625
+ const fetchFunction = options?.fetch;
2626
+ if (fetchFunction && typeof fetchFunction === "function") {
2627
+ return (url, fetchOptions2) => fetchFunction(url, fetchOptions2);
2628
+ }
2629
+ const fetchOptions = options?.fetch;
2630
+ if (fetchOptions && typeof fetchOptions !== "function") {
2631
+ return (url) => fetch(url, fetchOptions);
2632
+ }
2633
+ return (url) => fetch(url);
2634
+ }
2506
2635
 
2507
- // src/tilejson-loader.ts
2508
- var VERSION2, TileJSONLoader;
2509
- var init_tilejson_loader = __esm({
2510
- "src/tilejson-loader.ts"() {
2511
- init_parse_tilejson();
2512
- VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
2513
- TileJSONLoader = {
2514
- name: "TileJSON",
2515
- id: "tilejson",
2516
- module: "pmtiles",
2517
- version: VERSION2,
2518
- worker: true,
2519
- extensions: ["json"],
2520
- mimeTypes: ["application/json"],
2521
- text: true,
2522
- options: {
2523
- tilejson: {}
2524
- },
2525
- parse: async (arrayBuffer, options) => {
2526
- const jsonString = new TextDecoder().decode(arrayBuffer);
2527
- const json = JSON.parse(jsonString);
2528
- return parseTileJSON(json);
2529
- },
2530
- parseTextSync: (text, options) => {
2531
- const json = JSON.parse(text);
2532
- return parseTileJSON(json);
2636
+ // ../images/src/lib/utils/version.ts
2637
+ var VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
2638
+
2639
+ // ../images/src/lib/category-api/image-type.ts
2640
+ var parseImageNode = globalThis.loaders?.parseImageNode;
2641
+ var IMAGE_SUPPORTED = typeof Image !== "undefined";
2642
+ var IMAGE_BITMAP_SUPPORTED = typeof ImageBitmap !== "undefined";
2643
+ var NODE_IMAGE_SUPPORTED = Boolean(parseImageNode);
2644
+ var DATA_SUPPORTED = isBrowser ? true : NODE_IMAGE_SUPPORTED;
2645
+ function isImageTypeSupported(type) {
2646
+ switch (type) {
2647
+ case "auto":
2648
+ return IMAGE_BITMAP_SUPPORTED || IMAGE_SUPPORTED || DATA_SUPPORTED;
2649
+ case "imagebitmap":
2650
+ return IMAGE_BITMAP_SUPPORTED;
2651
+ case "image":
2652
+ return IMAGE_SUPPORTED;
2653
+ case "data":
2654
+ return DATA_SUPPORTED;
2655
+ default:
2656
+ throw new Error(`@loaders.gl/images: image ${type} not supported in this environment`);
2657
+ }
2658
+ }
2659
+ function getDefaultImageType() {
2660
+ if (IMAGE_BITMAP_SUPPORTED) {
2661
+ return "imagebitmap";
2662
+ }
2663
+ if (IMAGE_SUPPORTED) {
2664
+ return "image";
2665
+ }
2666
+ if (DATA_SUPPORTED) {
2667
+ return "data";
2668
+ }
2669
+ throw new Error("Install '@loaders.gl/polyfills' to parse images under Node.js");
2670
+ }
2671
+
2672
+ // ../images/src/lib/category-api/parsed-image-api.ts
2673
+ function getImageType(image) {
2674
+ const format = getImageTypeOrNull(image);
2675
+ if (!format) {
2676
+ throw new Error("Not an image");
2677
+ }
2678
+ return format;
2679
+ }
2680
+ function getImageData(image) {
2681
+ switch (getImageType(image)) {
2682
+ case "data":
2683
+ return image;
2684
+ case "image":
2685
+ case "imagebitmap":
2686
+ const canvas = document.createElement("canvas");
2687
+ const context = canvas.getContext("2d");
2688
+ if (!context) {
2689
+ throw new Error("getImageData");
2690
+ }
2691
+ canvas.width = image.width;
2692
+ canvas.height = image.height;
2693
+ context.drawImage(image, 0, 0);
2694
+ return context.getImageData(0, 0, image.width, image.height);
2695
+ default:
2696
+ throw new Error("getImageData");
2697
+ }
2698
+ }
2699
+ function getImageTypeOrNull(image) {
2700
+ if (typeof ImageBitmap !== "undefined" && image instanceof ImageBitmap) {
2701
+ return "imagebitmap";
2702
+ }
2703
+ if (typeof Image !== "undefined" && image instanceof Image) {
2704
+ return "image";
2705
+ }
2706
+ if (image && typeof image === "object" && image.data && image.width && image.height) {
2707
+ return "data";
2708
+ }
2709
+ return null;
2710
+ }
2711
+
2712
+ // ../images/src/lib/parsers/svg-utils.ts
2713
+ var SVG_DATA_URL_PATTERN = /^data:image\/svg\+xml/;
2714
+ var SVG_URL_PATTERN = /\.svg((\?|#).*)?$/;
2715
+ function isSVG(url) {
2716
+ return url && (SVG_DATA_URL_PATTERN.test(url) || SVG_URL_PATTERN.test(url));
2717
+ }
2718
+ function getBlobOrSVGDataUrl(arrayBuffer, url) {
2719
+ if (isSVG(url)) {
2720
+ const textDecoder = new TextDecoder();
2721
+ let xmlText = textDecoder.decode(arrayBuffer);
2722
+ try {
2723
+ if (typeof unescape === "function" && typeof encodeURIComponent === "function") {
2724
+ xmlText = unescape(encodeURIComponent(xmlText));
2533
2725
  }
2726
+ } catch (error) {
2727
+ throw new Error(error.message);
2728
+ }
2729
+ const src = `data:image/svg+xml;base64,${btoa(xmlText)}`;
2730
+ return src;
2731
+ }
2732
+ return getBlob(arrayBuffer, url);
2733
+ }
2734
+ function getBlob(arrayBuffer, url) {
2735
+ if (isSVG(url)) {
2736
+ throw new Error("SVG cannot be parsed directly to imagebitmap");
2737
+ }
2738
+ return new Blob([new Uint8Array(arrayBuffer)]);
2739
+ }
2740
+
2741
+ // ../images/src/lib/parsers/parse-to-image.ts
2742
+ async function parseToImage(arrayBuffer, options, url) {
2743
+ const blobOrDataUrl = getBlobOrSVGDataUrl(arrayBuffer, url);
2744
+ const URL = self.URL || self.webkitURL;
2745
+ const objectUrl = typeof blobOrDataUrl !== "string" && URL.createObjectURL(blobOrDataUrl);
2746
+ try {
2747
+ return await loadToImage(objectUrl || blobOrDataUrl, options);
2748
+ } finally {
2749
+ if (objectUrl) {
2750
+ URL.revokeObjectURL(objectUrl);
2751
+ }
2752
+ }
2753
+ }
2754
+ async function loadToImage(url, options) {
2755
+ const image = new Image();
2756
+ image.src = url;
2757
+ if (options.image && options.image.decode && image.decode) {
2758
+ await image.decode();
2759
+ return image;
2760
+ }
2761
+ return await new Promise((resolve, reject) => {
2762
+ try {
2763
+ image.onload = () => resolve(image);
2764
+ image.onerror = (err) => reject(new Error(`Could not load image ${url}: ${err}`));
2765
+ } catch (error) {
2766
+ reject(error);
2767
+ }
2768
+ });
2769
+ }
2770
+
2771
+ // ../images/src/lib/parsers/parse-to-image-bitmap.ts
2772
+ var EMPTY_OBJECT = {};
2773
+ var imagebitmapOptionsSupported = true;
2774
+ async function parseToImageBitmap(arrayBuffer, options, url) {
2775
+ let blob;
2776
+ if (isSVG(url)) {
2777
+ const image = await parseToImage(arrayBuffer, options, url);
2778
+ blob = image;
2779
+ } else {
2780
+ blob = getBlob(arrayBuffer, url);
2781
+ }
2782
+ const imagebitmapOptions = options && options.imagebitmap;
2783
+ return await safeCreateImageBitmap(blob, imagebitmapOptions);
2784
+ }
2785
+ async function safeCreateImageBitmap(blob, imagebitmapOptions = null) {
2786
+ if (isEmptyObject(imagebitmapOptions) || !imagebitmapOptionsSupported) {
2787
+ imagebitmapOptions = null;
2788
+ }
2789
+ if (imagebitmapOptions) {
2790
+ try {
2791
+ return await createImageBitmap(blob, imagebitmapOptions);
2792
+ } catch (error) {
2793
+ console.warn(error);
2794
+ imagebitmapOptionsSupported = false;
2795
+ }
2796
+ }
2797
+ return await createImageBitmap(blob);
2798
+ }
2799
+ function isEmptyObject(object) {
2800
+ for (const key in object || EMPTY_OBJECT) {
2801
+ return false;
2802
+ }
2803
+ return true;
2804
+ }
2805
+
2806
+ // ../images/src/lib/category-api/parse-isobmff-binary.ts
2807
+ function getISOBMFFMediaType(buffer) {
2808
+ if (!checkString(buffer, "ftyp", 4)) {
2809
+ return null;
2810
+ }
2811
+ if ((buffer[8] & 96) === 0) {
2812
+ return null;
2813
+ }
2814
+ return decodeMajorBrand(buffer);
2815
+ }
2816
+ function decodeMajorBrand(buffer) {
2817
+ const brandMajor = getUTF8String(buffer, 8, 12).replace("\0", " ").trim();
2818
+ switch (brandMajor) {
2819
+ case "avif":
2820
+ case "avis":
2821
+ return {
2822
+ extension: "avif",
2823
+ mimeType: "image/avif"
2824
+ };
2825
+ default:
2826
+ return null;
2827
+ }
2828
+ }
2829
+ function getUTF8String(array, start, end) {
2830
+ return String.fromCharCode(...array.slice(start, end));
2831
+ }
2832
+ function stringToBytes(string) {
2833
+ return [...string].map((character) => character.charCodeAt(0));
2834
+ }
2835
+ function checkString(buffer, header, offset = 0) {
2836
+ const headerBytes = stringToBytes(header);
2837
+ for (let i2 = 0; i2 < headerBytes.length; ++i2) {
2838
+ if (headerBytes[i2] !== buffer[i2 + offset]) {
2839
+ return false;
2840
+ }
2841
+ }
2842
+ return true;
2843
+ }
2844
+
2845
+ // ../images/src/lib/category-api/binary-image-api.ts
2846
+ var BIG_ENDIAN = false;
2847
+ var LITTLE_ENDIAN = true;
2848
+ function getBinaryImageMetadata(binaryData) {
2849
+ const dataView = toDataView(binaryData);
2850
+ return getPngMetadata(dataView) || getJpegMetadata(dataView) || getGifMetadata(dataView) || getBmpMetadata(dataView) || getISOBMFFMetadata(dataView);
2851
+ }
2852
+ function getISOBMFFMetadata(binaryData) {
2853
+ const buffer = new Uint8Array(binaryData instanceof DataView ? binaryData.buffer : binaryData);
2854
+ const mediaType = getISOBMFFMediaType(buffer);
2855
+ if (!mediaType) {
2856
+ return null;
2857
+ }
2858
+ return {
2859
+ mimeType: mediaType.mimeType,
2860
+ width: 0,
2861
+ height: 0
2862
+ };
2863
+ }
2864
+ function getPngMetadata(binaryData) {
2865
+ const dataView = toDataView(binaryData);
2866
+ const isPng = dataView.byteLength >= 24 && dataView.getUint32(0, BIG_ENDIAN) === 2303741511;
2867
+ if (!isPng) {
2868
+ return null;
2869
+ }
2870
+ return {
2871
+ mimeType: "image/png",
2872
+ width: dataView.getUint32(16, BIG_ENDIAN),
2873
+ height: dataView.getUint32(20, BIG_ENDIAN)
2874
+ };
2875
+ }
2876
+ function getGifMetadata(binaryData) {
2877
+ const dataView = toDataView(binaryData);
2878
+ const isGif = dataView.byteLength >= 10 && dataView.getUint32(0, BIG_ENDIAN) === 1195984440;
2879
+ if (!isGif) {
2880
+ return null;
2881
+ }
2882
+ return {
2883
+ mimeType: "image/gif",
2884
+ width: dataView.getUint16(6, LITTLE_ENDIAN),
2885
+ height: dataView.getUint16(8, LITTLE_ENDIAN)
2886
+ };
2887
+ }
2888
+ function getBmpMetadata(binaryData) {
2889
+ const dataView = toDataView(binaryData);
2890
+ const isBmp = dataView.byteLength >= 14 && dataView.getUint16(0, BIG_ENDIAN) === 16973 && dataView.getUint32(2, LITTLE_ENDIAN) === dataView.byteLength;
2891
+ if (!isBmp) {
2892
+ return null;
2893
+ }
2894
+ return {
2895
+ mimeType: "image/bmp",
2896
+ width: dataView.getUint32(18, LITTLE_ENDIAN),
2897
+ height: dataView.getUint32(22, LITTLE_ENDIAN)
2898
+ };
2899
+ }
2900
+ function getJpegMetadata(binaryData) {
2901
+ const dataView = toDataView(binaryData);
2902
+ const isJpeg = dataView.byteLength >= 3 && dataView.getUint16(0, BIG_ENDIAN) === 65496 && dataView.getUint8(2) === 255;
2903
+ if (!isJpeg) {
2904
+ return null;
2905
+ }
2906
+ const {
2907
+ tableMarkers,
2908
+ sofMarkers
2909
+ } = getJpegMarkers();
2910
+ let i2 = 2;
2911
+ while (i2 + 9 < dataView.byteLength) {
2912
+ const marker = dataView.getUint16(i2, BIG_ENDIAN);
2913
+ if (sofMarkers.has(marker)) {
2914
+ return {
2915
+ mimeType: "image/jpeg",
2916
+ height: dataView.getUint16(i2 + 5, BIG_ENDIAN),
2917
+ width: dataView.getUint16(i2 + 7, BIG_ENDIAN)
2918
+ };
2919
+ }
2920
+ if (!tableMarkers.has(marker)) {
2921
+ return null;
2922
+ }
2923
+ i2 += 2;
2924
+ i2 += dataView.getUint16(i2, BIG_ENDIAN);
2925
+ }
2926
+ return null;
2927
+ }
2928
+ function getJpegMarkers() {
2929
+ const tableMarkers = /* @__PURE__ */ new Set([65499, 65476, 65484, 65501, 65534]);
2930
+ for (let i2 = 65504; i2 < 65520; ++i2) {
2931
+ tableMarkers.add(i2);
2932
+ }
2933
+ const sofMarkers = /* @__PURE__ */ new Set([65472, 65473, 65474, 65475, 65477, 65478, 65479, 65481, 65482, 65483, 65485, 65486, 65487, 65502]);
2934
+ return {
2935
+ tableMarkers,
2936
+ sofMarkers
2937
+ };
2938
+ }
2939
+ function toDataView(data) {
2940
+ if (data instanceof DataView) {
2941
+ return data;
2942
+ }
2943
+ if (ArrayBuffer.isView(data)) {
2944
+ return new DataView(data.buffer);
2945
+ }
2946
+ if (data instanceof ArrayBuffer) {
2947
+ return new DataView(data);
2948
+ }
2949
+ throw new Error("toDataView");
2950
+ }
2951
+
2952
+ // ../images/src/lib/parsers/parse-to-node-image.ts
2953
+ async function parseToNodeImage(arrayBuffer, options) {
2954
+ const {
2955
+ mimeType
2956
+ } = getBinaryImageMetadata(arrayBuffer) || {};
2957
+ const parseImageNode2 = globalThis.loaders?.parseImageNode;
2958
+ assert(parseImageNode2);
2959
+ return await parseImageNode2(arrayBuffer, mimeType);
2960
+ }
2961
+
2962
+ // ../images/src/lib/parsers/parse-image.ts
2963
+ async function parseImage(arrayBuffer, options, context) {
2964
+ options = options || {};
2965
+ const imageOptions = options.image || {};
2966
+ const imageType = imageOptions.type || "auto";
2967
+ const {
2968
+ url
2969
+ } = context || {};
2970
+ const loadType = getLoadableImageType(imageType);
2971
+ let image;
2972
+ switch (loadType) {
2973
+ case "imagebitmap":
2974
+ image = await parseToImageBitmap(arrayBuffer, options, url);
2975
+ break;
2976
+ case "image":
2977
+ image = await parseToImage(arrayBuffer, options, url);
2978
+ break;
2979
+ case "data":
2980
+ image = await parseToNodeImage(arrayBuffer, options);
2981
+ break;
2982
+ default:
2983
+ assert(false);
2984
+ }
2985
+ if (imageType === "data") {
2986
+ image = getImageData(image);
2987
+ }
2988
+ return image;
2989
+ }
2990
+ function getLoadableImageType(type) {
2991
+ switch (type) {
2992
+ case "auto":
2993
+ case "data":
2994
+ return getDefaultImageType();
2995
+ default:
2996
+ isImageTypeSupported(type);
2997
+ return type;
2998
+ }
2999
+ }
3000
+
3001
+ // ../images/src/image-loader.ts
3002
+ var EXTENSIONS = ["png", "jpg", "jpeg", "gif", "webp", "bmp", "ico", "svg", "avif"];
3003
+ var MIME_TYPES = ["image/png", "image/jpeg", "image/gif", "image/webp", "image/avif", "image/bmp", "image/vnd.microsoft.icon", "image/svg+xml"];
3004
+ var DEFAULT_IMAGE_LOADER_OPTIONS = {
3005
+ image: {
3006
+ type: "auto",
3007
+ decode: true
3008
+ }
3009
+ };
3010
+ var ImageLoader = {
3011
+ id: "image",
3012
+ module: "images",
3013
+ name: "Images",
3014
+ version: VERSION3,
3015
+ mimeTypes: MIME_TYPES,
3016
+ extensions: EXTENSIONS,
3017
+ parse: parseImage,
3018
+ tests: [(arrayBuffer) => Boolean(getBinaryImageMetadata(new DataView(arrayBuffer)))],
3019
+ options: DEFAULT_IMAGE_LOADER_OPTIONS
3020
+ };
3021
+
3022
+ // src/mvt-source.ts
3023
+ var MVTSource = class extends DataSource {
3024
+ schema = "tms";
3025
+ constructor(props) {
3026
+ super(props);
3027
+ this.props = props;
3028
+ this.url = resolvePath(props.url);
3029
+ this.getTileData = this.getTileData.bind(this);
3030
+ this.metadata = this.getMetadata();
3031
+ }
3032
+ async getMetadata() {
3033
+ const metadataUrl = this.getMetadataUrl();
3034
+ const response = await this.fetch(metadataUrl);
3035
+ if (!response.ok) {
3036
+ return null;
3037
+ }
3038
+ const tileJSON = await response.text();
3039
+ const metadata = TileJSONLoader.parseTextSync?.(JSON.stringify(tileJSON)) || null;
3040
+ return metadata;
3041
+ }
3042
+ async getTile(tileParams) {
3043
+ const {
3044
+ x: x2,
3045
+ y: y2,
3046
+ zoom: z
3047
+ } = tileParams;
3048
+ const tileUrl = this.getTileURL(x2, y2, z);
3049
+ const response = await this.fetch(tileUrl);
3050
+ if (!response.ok) {
3051
+ return null;
3052
+ }
3053
+ const arrayBuffer = await response.arrayBuffer();
3054
+ return arrayBuffer;
3055
+ }
3056
+ async getTileData(tileParams) {
3057
+ const {
3058
+ x: x2,
3059
+ y: y2,
3060
+ z
3061
+ } = tileParams.index;
3062
+ const metadata = await this.metadata;
3063
+ switch (metadata.mimeType || "application/vnd.mapbox-vector-tile") {
3064
+ case "application/vnd.mapbox-vector-tile":
3065
+ return await this.getVectorTile({
3066
+ x: x2,
3067
+ y: y2,
3068
+ zoom: z,
3069
+ layers: []
3070
+ });
3071
+ default:
3072
+ return await this.getImageTile({
3073
+ x: x2,
3074
+ y: y2,
3075
+ zoom: z,
3076
+ layers: []
3077
+ });
3078
+ }
3079
+ }
3080
+ async getImageTile(tileParams) {
3081
+ const arrayBuffer = await this.getTile(tileParams);
3082
+ return arrayBuffer ? await ImageLoader.parse(arrayBuffer, this.loadOptions) : null;
3083
+ }
3084
+ async getVectorTile(tileParams) {
3085
+ const arrayBuffer = await this.getTile(tileParams);
3086
+ const loadOptions = {
3087
+ shape: "geojson-table",
3088
+ mvt: {
3089
+ coordinates: "wgs84",
3090
+ tileIndex: {
3091
+ x: tileParams.x,
3092
+ y: tileParams.y,
3093
+ z: tileParams.zoom
3094
+ },
3095
+ ...this.loadOptions?.mvt
3096
+ },
3097
+ ...this.loadOptions
2534
3098
  };
3099
+ return arrayBuffer ? await MVTLoader.parse(arrayBuffer, loadOptions) : null;
2535
3100
  }
2536
- });
3101
+ getMetadataUrl() {
3102
+ return `${this.url}/tilejson.json`;
3103
+ }
3104
+ getTileURL(x2, y2, z) {
3105
+ switch (this.schema) {
3106
+ case "xyz":
3107
+ return `${this.url}/${x2}/${y2}/${z}`;
3108
+ case "tms":
3109
+ default:
3110
+ return `${this.url}/${z}/${x2}/${y2}`;
3111
+ }
3112
+ }
3113
+ };
2537
3114
 
2538
3115
  // src/lib/geojson-tiler/simplify.ts
2539
3116
  function simplify(coords, first, last, sqTolerance) {
@@ -2583,10 +3160,6 @@
2583
3160
  dy = py - y2;
2584
3161
  return dx * dx + dy * dy;
2585
3162
  }
2586
- var init_simplify = __esm({
2587
- "src/lib/geojson-tiler/simplify.ts"() {
2588
- }
2589
- });
2590
3163
 
2591
3164
  // src/lib/geojson-tiler/feature.ts
2592
3165
  function createFeature(id, type, geom, tags) {
@@ -2623,10 +3196,6 @@
2623
3196
  feature.maxY = Math.max(feature.maxY, geom[i2 + 1]);
2624
3197
  }
2625
3198
  }
2626
- var init_feature = __esm({
2627
- "src/lib/geojson-tiler/feature.ts"() {
2628
- }
2629
- });
2630
3199
 
2631
3200
  // src/lib/geojson-tiler/convert.ts
2632
3201
  function convert(data, options) {
@@ -2638,7 +3207,9 @@
2638
3207
  } else if (data.type === "Feature") {
2639
3208
  convertFeature(features, data, options);
2640
3209
  } else {
2641
- convertFeature(features, { geometry: data }, options);
3210
+ convertFeature(features, {
3211
+ geometry: data
3212
+ }, options);
2642
3213
  }
2643
3214
  return features;
2644
3215
  }
@@ -2740,12 +3311,6 @@
2740
3311
  const y22 = 0.5 - 0.25 * Math.log((1 + sin) / (1 - sin)) / Math.PI;
2741
3312
  return y22 < 0 ? 0 : y22 > 1 ? 1 : y22;
2742
3313
  }
2743
- var init_convert = __esm({
2744
- "src/lib/geojson-tiler/convert.ts"() {
2745
- init_simplify();
2746
- init_feature();
2747
- }
2748
- });
2749
3314
 
2750
3315
  // src/lib/geojson-tiler/clip.ts
2751
3316
  function clip(features, scale, k1, k2, axis, minAll, maxAll, options) {
@@ -2911,11 +3476,6 @@
2911
3476
  addPoint(out, ax + (bx - ax) * t, y2, 1);
2912
3477
  return t;
2913
3478
  }
2914
- var init_clip = __esm({
2915
- "src/lib/geojson-tiler/clip.ts"() {
2916
- init_feature();
2917
- }
2918
- });
2919
3479
 
2920
3480
  // src/lib/geojson-tiler/wrap.ts
2921
3481
  function wrap(features, options) {
@@ -2973,12 +3533,6 @@
2973
3533
  }
2974
3534
  return newPoints;
2975
3535
  }
2976
- var init_wrap = __esm({
2977
- "src/lib/geojson-tiler/wrap.ts"() {
2978
- init_clip();
2979
- init_feature();
2980
- }
2981
- });
2982
3536
 
2983
3537
  // src/lib/geojson-tiler/transform.ts
2984
3538
  function transformTile(tile, extent) {
@@ -3012,10 +3566,6 @@
3012
3566
  function transformPoint(x2, y2, extent, z2, tx, ty) {
3013
3567
  return [Math.round(extent * (x2 * z2 - tx)), Math.round(extent * (y2 * z2 - ty))];
3014
3568
  }
3015
- var init_transform = __esm({
3016
- "src/lib/geojson-tiler/transform.ts"() {
3017
- }
3018
- });
3019
3569
 
3020
3570
  // src/lib/geojson-tiler/tile.ts
3021
3571
  function createTile(features, z, tx, ty, options) {
@@ -3122,207 +3672,184 @@
3122
3672
  }
3123
3673
  }
3124
3674
  }
3125
- var init_tile = __esm({
3126
- "src/lib/geojson-tiler/tile.ts"() {
3127
- }
3128
- });
3129
3675
 
3130
3676
  // src/lib/geojson-tiler/geojson-tiler.ts
3131
- function toID(z, x2, y2) {
3132
- return ((1 << z) * y2 + x2) * 32 + z;
3133
- }
3134
- var DEFAULT_OPTIONS, GeoJSONTiler;
3135
- var init_geojson_tiler = __esm({
3136
- "src/lib/geojson-tiler/geojson-tiler.ts"() {
3137
- init_convert();
3138
- init_clip();
3139
- init_wrap();
3140
- init_transform();
3141
- init_tile();
3142
- DEFAULT_OPTIONS = {
3143
- maxZoom: 14,
3144
- indexMaxZoom: 5,
3145
- indexMaxPoints: 1e5,
3146
- tolerance: 3,
3147
- extent: 4096,
3148
- buffer: 64,
3149
- lineMetrics: false,
3150
- promoteId: void 0,
3151
- generateId: false,
3152
- debug: 0
3677
+ var DEFAULT_OPTIONS = {
3678
+ maxZoom: 14,
3679
+ indexMaxZoom: 5,
3680
+ indexMaxPoints: 1e5,
3681
+ tolerance: 3,
3682
+ extent: 4096,
3683
+ buffer: 64,
3684
+ lineMetrics: false,
3685
+ promoteId: void 0,
3686
+ generateId: false,
3687
+ debug: 0
3688
+ };
3689
+ var GeoJSONTiler = class {
3690
+ tiles = {};
3691
+ tileCoords = [];
3692
+ stats = {};
3693
+ total = 0;
3694
+ constructor(data, options) {
3695
+ this.options = {
3696
+ ...DEFAULT_OPTIONS,
3697
+ ...options
3153
3698
  };
3154
- GeoJSONTiler = class {
3155
- constructor(data, options) {
3156
- this.tiles = {};
3157
- this.tileCoords = [];
3158
- this.stats = {};
3159
- this.total = 0;
3160
- this.options = { ...DEFAULT_OPTIONS, ...options };
3161
- options = this.options;
3162
- const debug = options.debug;
3163
- if (debug)
3164
- console.time("preprocess data");
3165
- if (this.options.maxZoom < 0 || this.options.maxZoom > 24) {
3166
- throw new Error("maxZoom should be in the 0-24 range");
3167
- }
3168
- if (options.promoteId && this.options.generateId) {
3169
- throw new Error("promoteId and generateId cannot be used together.");
3170
- }
3171
- let features = convert(data, options);
3172
- if (debug) {
3173
- console.timeEnd("preprocess data");
3174
- console.log("index: maxZoom: %d, maxPoints: %d", options.indexMaxZoom, options.indexMaxPoints);
3175
- console.time("generate tiles");
3176
- }
3177
- features = wrap(features, this.options);
3178
- if (features.length) {
3179
- this.splitTile(features, 0, 0, 0);
3699
+ options = this.options;
3700
+ const debug = options.debug;
3701
+ if (debug)
3702
+ console.time("preprocess data");
3703
+ if (this.options.maxZoom < 0 || this.options.maxZoom > 24) {
3704
+ throw new Error("maxZoom should be in the 0-24 range");
3705
+ }
3706
+ if (options.promoteId && this.options.generateId) {
3707
+ throw new Error("promoteId and generateId cannot be used together.");
3708
+ }
3709
+ let features = convert(data, options);
3710
+ if (debug) {
3711
+ console.timeEnd("preprocess data");
3712
+ console.log("index: maxZoom: %d, maxPoints: %d", options.indexMaxZoom, options.indexMaxPoints);
3713
+ console.time("generate tiles");
3714
+ }
3715
+ features = wrap(features, this.options);
3716
+ if (features.length) {
3717
+ this.splitTile(features, 0, 0, 0);
3718
+ }
3719
+ if (debug) {
3720
+ if (features.length) {
3721
+ console.log("features: %d, points: %d", this.tiles[0].numFeatures, this.tiles[0].numPoints);
3722
+ }
3723
+ console.timeEnd("generate tiles");
3724
+ console.log("tiles generated:", this.total, JSON.stringify(this.stats));
3725
+ }
3726
+ }
3727
+ getTile(z, x2, y2) {
3728
+ const {
3729
+ extent,
3730
+ debug
3731
+ } = this.options;
3732
+ if (z < 0 || z > 24) {
3733
+ return null;
3734
+ }
3735
+ const z2 = 1 << z;
3736
+ x2 = x2 + z2 & z2 - 1;
3737
+ const id = toID(z, x2, y2);
3738
+ if (this.tiles[id]) {
3739
+ return transformTile(this.tiles[id], extent);
3740
+ }
3741
+ if (debug > 1)
3742
+ console.log("drilling down to z%d-%d-%d", z, x2, y2);
3743
+ let z0 = z;
3744
+ let x0 = x2;
3745
+ let y0 = y2;
3746
+ let parent;
3747
+ while (!parent && z0 > 0) {
3748
+ z0--;
3749
+ x0 = x0 >> 1;
3750
+ y0 = y0 >> 1;
3751
+ parent = this.tiles[toID(z0, x0, y0)];
3752
+ }
3753
+ if (!parent || !parent.source) {
3754
+ return null;
3755
+ }
3756
+ if (debug > 1) {
3757
+ console.log("found parent tile z%d-%d-%d", z0, x0, y0);
3758
+ console.time("drilling down");
3759
+ }
3760
+ this.splitTile(parent.source, z0, x0, y0, z, x2, y2);
3761
+ if (debug > 1) {
3762
+ console.timeEnd("drilling down");
3763
+ }
3764
+ return this.tiles[id] ? transformTile(this.tiles[id], extent) : null;
3765
+ }
3766
+ splitTile(features, z, x2, y2, cz, cx, cy) {
3767
+ const stack = [features, z, x2, y2];
3768
+ const options = this.options;
3769
+ const debug = options.debug;
3770
+ while (stack.length) {
3771
+ y2 = stack.pop();
3772
+ x2 = stack.pop();
3773
+ z = stack.pop();
3774
+ features = stack.pop();
3775
+ const z2 = 1 << z;
3776
+ const id = toID(z, x2, y2);
3777
+ let tile = this.tiles[id];
3778
+ if (!tile) {
3779
+ if (debug > 1) {
3780
+ console.time("creation");
3180
3781
  }
3782
+ tile = this.tiles[id] = createTile(features, z, x2, y2, options);
3783
+ this.tileCoords.push({
3784
+ z,
3785
+ x: x2,
3786
+ y: y2
3787
+ });
3181
3788
  if (debug) {
3182
- if (features.length) {
3183
- console.log("features: %d, points: %d", this.tiles[0].numFeatures, this.tiles[0].numPoints);
3789
+ if (debug > 1) {
3790
+ console.log("tile z%d-%d-%d (features: %d, points: %d, simplified: %d)", z, x2, y2, tile.numFeatures, tile.numPoints, tile.numSimplified);
3791
+ console.timeEnd("creation");
3184
3792
  }
3185
- console.timeEnd("generate tiles");
3186
- console.log("tiles generated:", this.total, JSON.stringify(this.stats));
3793
+ const key = `z${z}`;
3794
+ this.stats[key] = (this.stats[key] || 0) + 1;
3795
+ this.total++;
3187
3796
  }
3188
3797
  }
3189
- getTile(z, x2, y2) {
3190
- const { extent, debug } = this.options;
3191
- if (z < 0 || z > 24) {
3192
- return null;
3193
- }
3194
- const z2 = 1 << z;
3195
- x2 = x2 + z2 & z2 - 1;
3196
- const id = toID(z, x2, y2);
3197
- if (this.tiles[id]) {
3198
- return transformTile(this.tiles[id], extent);
3199
- }
3200
- if (debug > 1)
3201
- console.log("drilling down to z%d-%d-%d", z, x2, y2);
3202
- let z0 = z;
3203
- let x0 = x2;
3204
- let y0 = y2;
3205
- let parent;
3206
- while (!parent && z0 > 0) {
3207
- z0--;
3208
- x0 = x0 >> 1;
3209
- y0 = y0 >> 1;
3210
- parent = this.tiles[toID(z0, x0, y0)];
3211
- }
3212
- if (!parent || !parent.source) {
3213
- return null;
3214
- }
3215
- if (debug > 1) {
3216
- console.log("found parent tile z%d-%d-%d", z0, x0, y0);
3217
- console.time("drilling down");
3218
- }
3219
- this.splitTile(parent.source, z0, x0, y0, z, x2, y2);
3220
- if (debug > 1) {
3221
- console.timeEnd("drilling down");
3222
- }
3223
- return this.tiles[id] ? transformTile(this.tiles[id], extent) : null;
3798
+ tile.source = features;
3799
+ if (cz === void 0) {
3800
+ if (z === options.indexMaxZoom || tile.numPoints <= options.indexMaxPoints)
3801
+ continue;
3802
+ } else if (z === options.maxZoom || z === cz) {
3803
+ continue;
3804
+ } else if (cz !== void 0) {
3805
+ const zoomSteps = cz - z;
3806
+ if (x2 !== cx >> zoomSteps || y2 !== cy >> zoomSteps)
3807
+ continue;
3224
3808
  }
3225
- splitTile(features, z, x2, y2, cz, cx, cy) {
3226
- const stack = [features, z, x2, y2];
3227
- const options = this.options;
3228
- const debug = options.debug;
3229
- while (stack.length) {
3230
- y2 = stack.pop();
3231
- x2 = stack.pop();
3232
- z = stack.pop();
3233
- features = stack.pop();
3234
- const z2 = 1 << z;
3235
- const id = toID(z, x2, y2);
3236
- let tile = this.tiles[id];
3237
- if (!tile) {
3238
- if (debug > 1) {
3239
- console.time("creation");
3240
- }
3241
- tile = this.tiles[id] = createTile(features, z, x2, y2, options);
3242
- this.tileCoords.push({ z, x: x2, y: y2 });
3243
- if (debug) {
3244
- if (debug > 1) {
3245
- console.log("tile z%d-%d-%d (features: %d, points: %d, simplified: %d)", z, x2, y2, tile.numFeatures, tile.numPoints, tile.numSimplified);
3246
- console.timeEnd("creation");
3247
- }
3248
- const key = `z${z}`;
3249
- this.stats[key] = (this.stats[key] || 0) + 1;
3250
- this.total++;
3251
- }
3252
- }
3253
- tile.source = features;
3254
- if (cz === void 0) {
3255
- if (z === options.indexMaxZoom || tile.numPoints <= options.indexMaxPoints)
3256
- continue;
3257
- } else if (z === options.maxZoom || z === cz) {
3258
- continue;
3259
- } else if (cz !== void 0) {
3260
- const zoomSteps = cz - z;
3261
- if (x2 !== cx >> zoomSteps || y2 !== cy >> zoomSteps)
3262
- continue;
3263
- }
3264
- tile.source = null;
3265
- if (features.length === 0)
3266
- continue;
3267
- if (debug > 1)
3268
- console.time("clipping");
3269
- const k1 = 0.5 * options.buffer / options.extent;
3270
- const k2 = 0.5 - k1;
3271
- const k3 = 0.5 + k1;
3272
- const k4 = 1 + k1;
3273
- let tl = null;
3274
- let bl = null;
3275
- let tr = null;
3276
- let br = null;
3277
- let left = clip(features, z2, x2 - k1, x2 + k3, 0, tile.minX, tile.maxX, options);
3278
- let right = clip(features, z2, x2 + k2, x2 + k4, 0, tile.minX, tile.maxX, options);
3279
- features = null;
3280
- if (left) {
3281
- tl = clip(left, z2, y2 - k1, y2 + k3, 1, tile.minY, tile.maxY, options);
3282
- bl = clip(left, z2, y2 + k2, y2 + k4, 1, tile.minY, tile.maxY, options);
3283
- left = null;
3284
- }
3285
- if (right) {
3286
- tr = clip(right, z2, y2 - k1, y2 + k3, 1, tile.minY, tile.maxY, options);
3287
- br = clip(right, z2, y2 + k2, y2 + k4, 1, tile.minY, tile.maxY, options);
3288
- right = null;
3289
- }
3290
- if (debug > 1)
3291
- console.timeEnd("clipping");
3292
- stack.push(tl || [], z + 1, x2 * 2, y2 * 2);
3293
- stack.push(bl || [], z + 1, x2 * 2, y2 * 2 + 1);
3294
- stack.push(tr || [], z + 1, x2 * 2 + 1, y2 * 2);
3295
- stack.push(br || [], z + 1, x2 * 2 + 1, y2 * 2 + 1);
3296
- }
3809
+ tile.source = null;
3810
+ if (features.length === 0)
3811
+ continue;
3812
+ if (debug > 1)
3813
+ console.time("clipping");
3814
+ const k1 = 0.5 * options.buffer / options.extent;
3815
+ const k2 = 0.5 - k1;
3816
+ const k3 = 0.5 + k1;
3817
+ const k4 = 1 + k1;
3818
+ let tl = null;
3819
+ let bl = null;
3820
+ let tr = null;
3821
+ let br = null;
3822
+ let left = clip(features, z2, x2 - k1, x2 + k3, 0, tile.minX, tile.maxX, options);
3823
+ let right = clip(features, z2, x2 + k2, x2 + k4, 0, tile.minX, tile.maxX, options);
3824
+ features = null;
3825
+ if (left) {
3826
+ tl = clip(left, z2, y2 - k1, y2 + k3, 1, tile.minY, tile.maxY, options);
3827
+ bl = clip(left, z2, y2 + k2, y2 + k4, 1, tile.minY, tile.maxY, options);
3828
+ left = null;
3297
3829
  }
3298
- };
3299
- }
3300
- });
3301
-
3302
- // src/index.ts
3303
- var src_exports = {};
3304
- __export(src_exports, {
3305
- GeoJSONTiler: () => GeoJSONTiler,
3306
- MVTLoader: () => MVTLoader,
3307
- MVTWorkerLoader: () => MVTWorkerLoader,
3308
- TileJSONLoader: () => TileJSONLoader
3309
- });
3310
- var init_src2 = __esm({
3311
- "src/index.ts"() {
3312
- init_mvt_loader();
3313
- init_tilejson_loader();
3314
- init_geojson_tiler();
3315
- }
3316
- });
3317
-
3318
- // src/bundle.ts
3319
- var require_bundle = __commonJS({
3320
- "src/bundle.ts"(exports, module) {
3321
- var moduleExports = (init_src2(), src_exports);
3322
- globalThis.loaders = globalThis.loaders || {};
3323
- module.exports = Object.assign(globalThis.loaders, moduleExports);
3830
+ if (right) {
3831
+ tr = clip(right, z2, y2 - k1, y2 + k3, 1, tile.minY, tile.maxY, options);
3832
+ br = clip(right, z2, y2 + k2, y2 + k4, 1, tile.minY, tile.maxY, options);
3833
+ right = null;
3834
+ }
3835
+ if (debug > 1)
3836
+ console.timeEnd("clipping");
3837
+ stack.push(tl || [], z + 1, x2 * 2, y2 * 2);
3838
+ stack.push(bl || [], z + 1, x2 * 2, y2 * 2 + 1);
3839
+ stack.push(tr || [], z + 1, x2 * 2 + 1, y2 * 2);
3840
+ stack.push(br || [], z + 1, x2 * 2 + 1, y2 * 2 + 1);
3841
+ }
3324
3842
  }
3325
- });
3326
- require_bundle();
3843
+ };
3844
+ function toID(z, x2, y2) {
3845
+ return ((1 << z) * y2 + x2) * 32 + z;
3846
+ }
3847
+ return __toCommonJS(src_exports);
3327
3848
  })();
3328
- /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
3849
+ /*! Bundled license information:
3850
+
3851
+ ieee754/index.js:
3852
+ (*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> *)
3853
+ */
3854
+ return __exports__;
3855
+ });