@deck.gl/carto 9.3.0-beta.1 → 9.3.0

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.
package/dist/dist.dev.js CHANGED
@@ -66,334 +66,6 @@ var __exports__ = (() => {
66
66
  }
67
67
  });
68
68
 
69
- // ../../node_modules/tilebelt/index.js
70
- var require_tilebelt = __commonJS({
71
- "../../node_modules/tilebelt/index.js"(exports, module) {
72
- var d2r2 = Math.PI / 180;
73
- var r2d2 = 180 / Math.PI;
74
- function tileToBBOX2(tile) {
75
- var e = tile2lon2(tile[0] + 1, tile[2]);
76
- var w = tile2lon2(tile[0], tile[2]);
77
- var s = tile2lat2(tile[1] + 1, tile[2]);
78
- var n = tile2lat2(tile[1], tile[2]);
79
- return [w, s, e, n];
80
- }
81
- function tileToGeoJSON2(tile) {
82
- var bbox2 = tileToBBOX2(tile);
83
- var poly = {
84
- type: "Polygon",
85
- coordinates: [
86
- [
87
- [bbox2[0], bbox2[1]],
88
- [bbox2[0], bbox2[3]],
89
- [bbox2[2], bbox2[3]],
90
- [bbox2[2], bbox2[1]],
91
- [bbox2[0], bbox2[1]]
92
- ]
93
- ]
94
- };
95
- return poly;
96
- }
97
- function tile2lon2(x, z) {
98
- return x / Math.pow(2, z) * 360 - 180;
99
- }
100
- function tile2lat2(y, z) {
101
- var n = Math.PI - 2 * Math.PI * y / Math.pow(2, z);
102
- return r2d2 * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n)));
103
- }
104
- function pointToTile2(lon, lat, z) {
105
- var tile = pointToTileFraction2(lon, lat, z);
106
- tile[0] = Math.floor(tile[0]);
107
- tile[1] = Math.floor(tile[1]);
108
- return tile;
109
- }
110
- function getChildren2(tile) {
111
- return [
112
- [tile[0] * 2, tile[1] * 2, tile[2] + 1],
113
- [tile[0] * 2 + 1, tile[1] * 2, tile[2] + 1],
114
- [tile[0] * 2 + 1, tile[1] * 2 + 1, tile[2] + 1],
115
- [tile[0] * 2, tile[1] * 2 + 1, tile[2] + 1]
116
- ];
117
- }
118
- function getParent2(tile) {
119
- if (tile[0] % 2 === 0 && tile[1] % 2 === 0) {
120
- return [tile[0] / 2, tile[1] / 2, tile[2] - 1];
121
- } else if (tile[0] % 2 === 0 && !tile[1] % 2 === 0) {
122
- return [tile[0] / 2, (tile[1] - 1) / 2, tile[2] - 1];
123
- } else if (!tile[0] % 2 === 0 && tile[1] % 2 === 0) {
124
- return [(tile[0] - 1) / 2, tile[1] / 2, tile[2] - 1];
125
- } else {
126
- return [(tile[0] - 1) / 2, (tile[1] - 1) / 2, tile[2] - 1];
127
- }
128
- }
129
- function getSiblings2(tile) {
130
- return getChildren2(getParent2(tile));
131
- }
132
- function hasSiblings2(tile, tiles3) {
133
- var siblings = getSiblings2(tile);
134
- for (var i = 0; i < siblings.length; i++) {
135
- if (!hasTile2(tiles3, siblings[i]))
136
- return false;
137
- }
138
- return true;
139
- }
140
- function hasTile2(tiles3, tile) {
141
- for (var i = 0; i < tiles3.length; i++) {
142
- if (tilesEqual2(tiles3[i], tile))
143
- return true;
144
- }
145
- return false;
146
- }
147
- function tilesEqual2(tile1, tile2) {
148
- return tile1[0] === tile2[0] && tile1[1] === tile2[1] && tile1[2] === tile2[2];
149
- }
150
- function tileToQuadkey2(tile) {
151
- var index2 = "";
152
- for (var z = tile[2]; z > 0; z--) {
153
- var b = 0;
154
- var mask = 1 << z - 1;
155
- if ((tile[0] & mask) !== 0)
156
- b++;
157
- if ((tile[1] & mask) !== 0)
158
- b += 2;
159
- index2 += b.toString();
160
- }
161
- return index2;
162
- }
163
- function quadkeyToTile2(quadkey) {
164
- var x = 0;
165
- var y = 0;
166
- var z = quadkey.length;
167
- for (var i = z; i > 0; i--) {
168
- var mask = 1 << i - 1;
169
- switch (quadkey[z - i]) {
170
- case "0":
171
- break;
172
- case "1":
173
- x |= mask;
174
- break;
175
- case "2":
176
- y |= mask;
177
- break;
178
- case "3":
179
- x |= mask;
180
- y |= mask;
181
- break;
182
- }
183
- }
184
- return [x, y, z];
185
- }
186
- function bboxToTile2(bboxCoords) {
187
- var min2 = pointToTile2(bboxCoords[0], bboxCoords[1], 32);
188
- var max2 = pointToTile2(bboxCoords[2], bboxCoords[3], 32);
189
- var bbox2 = [min2[0], min2[1], max2[0], max2[1]];
190
- var z = getBboxZoom2(bbox2);
191
- if (z === 0)
192
- return [0, 0, 0];
193
- var x = bbox2[0] >>> 32 - z;
194
- var y = bbox2[1] >>> 32 - z;
195
- return [x, y, z];
196
- }
197
- function getBboxZoom2(bbox2) {
198
- var MAX_ZOOM = 28;
199
- for (var z = 0; z < MAX_ZOOM; z++) {
200
- var mask = 1 << 32 - (z + 1);
201
- if ((bbox2[0] & mask) != (bbox2[2] & mask) || (bbox2[1] & mask) != (bbox2[3] & mask)) {
202
- return z;
203
- }
204
- }
205
- return MAX_ZOOM;
206
- }
207
- function pointToTileFraction2(lon, lat, z) {
208
- var sin = Math.sin(lat * d2r2), z2 = Math.pow(2, z), x = z2 * (lon / 360 + 0.5), y = z2 * (0.5 - 0.25 * Math.log((1 + sin) / (1 - sin)) / Math.PI);
209
- return [x, y, z];
210
- }
211
- module.exports = {
212
- tileToGeoJSON: tileToGeoJSON2,
213
- tileToBBOX: tileToBBOX2,
214
- getChildren: getChildren2,
215
- getParent: getParent2,
216
- getSiblings: getSiblings2,
217
- hasTile: hasTile2,
218
- hasSiblings: hasSiblings2,
219
- tilesEqual: tilesEqual2,
220
- tileToQuadkey: tileToQuadkey2,
221
- quadkeyToTile: quadkeyToTile2,
222
- pointToTile: pointToTile2,
223
- bboxToTile: bboxToTile2,
224
- pointToTileFraction: pointToTileFraction2
225
- };
226
- }
227
- });
228
-
229
- // ../../node_modules/@mapbox/tile-cover/index.js
230
- var require_tile_cover = __commonJS({
231
- "../../node_modules/@mapbox/tile-cover/index.js"(exports) {
232
- var tilebelt2 = require_tilebelt();
233
- exports.geojson = function(geom, limits) {
234
- return {
235
- type: "FeatureCollection",
236
- features: getTiles2(geom, limits).map(tileToFeature)
237
- };
238
- };
239
- function tileToFeature(t) {
240
- return {
241
- type: "Feature",
242
- geometry: tilebelt2.tileToGeoJSON(t),
243
- properties: {}
244
- };
245
- }
246
- exports.tiles = getTiles2;
247
- exports.indexes = function(geom, limits) {
248
- return getTiles2(geom, limits).map(tilebelt2.tileToQuadkey);
249
- };
250
- function getTiles2(geom, limits) {
251
- var i, tile, coords = geom.coordinates, maxZoom = limits.max_zoom, tileHash = {}, tiles3 = [];
252
- if (geom.type === "Point") {
253
- return [tilebelt2.pointToTile(coords[0], coords[1], maxZoom)];
254
- } else if (geom.type === "MultiPoint") {
255
- for (i = 0; i < coords.length; i++) {
256
- tile = tilebelt2.pointToTile(coords[i][0], coords[i][1], maxZoom);
257
- tileHash[toID2(tile[0], tile[1], tile[2])] = true;
258
- }
259
- } else if (geom.type === "LineString") {
260
- lineCover2(tileHash, coords, maxZoom);
261
- } else if (geom.type === "MultiLineString") {
262
- for (i = 0; i < coords.length; i++) {
263
- lineCover2(tileHash, coords[i], maxZoom);
264
- }
265
- } else if (geom.type === "Polygon") {
266
- polygonCover2(tileHash, tiles3, coords, maxZoom);
267
- } else if (geom.type === "MultiPolygon") {
268
- for (i = 0; i < coords.length; i++) {
269
- polygonCover2(tileHash, tiles3, coords[i], maxZoom);
270
- }
271
- } else {
272
- throw new Error("Geometry type not implemented");
273
- }
274
- if (limits.min_zoom !== maxZoom) {
275
- var len = tiles3.length;
276
- appendHashTiles2(tileHash, tiles3);
277
- for (i = 0; i < len; i++) {
278
- var t = tiles3[i];
279
- tileHash[toID2(t[0], t[1], t[2])] = true;
280
- }
281
- return mergeTiles2(tileHash, tiles3, limits);
282
- }
283
- appendHashTiles2(tileHash, tiles3);
284
- return tiles3;
285
- }
286
- function mergeTiles2(tileHash, tiles3, limits) {
287
- var mergedTiles = [];
288
- for (var z = limits.max_zoom; z > limits.min_zoom; z--) {
289
- var parentTileHash = {};
290
- var parentTiles = [];
291
- for (var i = 0; i < tiles3.length; i++) {
292
- var t = tiles3[i];
293
- if (t[0] % 2 === 0 && t[1] % 2 === 0) {
294
- var id22 = toID2(t[0] + 1, t[1], z), id32 = toID2(t[0], t[1] + 1, z), id42 = toID2(t[0] + 1, t[1] + 1, z);
295
- if (tileHash[id22] && tileHash[id32] && tileHash[id42]) {
296
- tileHash[toID2(t[0], t[1], t[2])] = false;
297
- tileHash[id22] = false;
298
- tileHash[id32] = false;
299
- tileHash[id42] = false;
300
- var parentTile = [t[0] / 2, t[1] / 2, z - 1];
301
- if (z - 1 === limits.min_zoom)
302
- mergedTiles.push(parentTile);
303
- else {
304
- parentTileHash[toID2(t[0] / 2, t[1] / 2, z - 1)] = true;
305
- parentTiles.push(parentTile);
306
- }
307
- }
308
- }
309
- }
310
- for (i = 0; i < tiles3.length; i++) {
311
- t = tiles3[i];
312
- if (tileHash[toID2(t[0], t[1], t[2])])
313
- mergedTiles.push(t);
314
- }
315
- tileHash = parentTileHash;
316
- tiles3 = parentTiles;
317
- }
318
- return mergedTiles;
319
- }
320
- function polygonCover2(tileHash, tileArray, geom, zoom) {
321
- var intersections = [];
322
- for (var i = 0; i < geom.length; i++) {
323
- var ring = [];
324
- lineCover2(tileHash, geom[i], zoom, ring);
325
- for (var j = 0, len = ring.length, k = len - 1; j < len; k = j++) {
326
- var m = (j + 1) % len;
327
- var y = ring[j][1];
328
- if ((y > ring[k][1] || y > ring[m][1]) && // not local minimum
329
- (y < ring[k][1] || y < ring[m][1]) && // not local maximum
330
- y !== ring[m][1])
331
- intersections.push(ring[j]);
332
- }
333
- }
334
- intersections.sort(compareTiles2);
335
- for (i = 0; i < intersections.length; i += 2) {
336
- y = intersections[i][1];
337
- for (var x = intersections[i][0] + 1; x < intersections[i + 1][0]; x++) {
338
- var id5 = toID2(x, y, zoom);
339
- if (!tileHash[id5]) {
340
- tileArray.push([x, y, zoom]);
341
- }
342
- }
343
- }
344
- }
345
- function compareTiles2(a, b) {
346
- return a[1] - b[1] || a[0] - b[0];
347
- }
348
- function lineCover2(tileHash, coords, maxZoom, ring) {
349
- var prevX, prevY;
350
- for (var i = 0; i < coords.length - 1; i++) {
351
- var start = tilebelt2.pointToTileFraction(coords[i][0], coords[i][1], maxZoom), stop = tilebelt2.pointToTileFraction(coords[i + 1][0], coords[i + 1][1], maxZoom), x0 = start[0], y0 = start[1], x1 = stop[0], y1 = stop[1], dx = x1 - x0, dy = y1 - y0;
352
- if (dy === 0 && dx === 0)
353
- continue;
354
- var sx = dx > 0 ? 1 : -1, sy = dy > 0 ? 1 : -1, x = Math.floor(x0), y = Math.floor(y0), tMaxX = dx === 0 ? Infinity : Math.abs(((dx > 0 ? 1 : 0) + x - x0) / dx), tMaxY = dy === 0 ? Infinity : Math.abs(((dy > 0 ? 1 : 0) + y - y0) / dy), tdx = Math.abs(sx / dx), tdy = Math.abs(sy / dy);
355
- if (x !== prevX || y !== prevY) {
356
- tileHash[toID2(x, y, maxZoom)] = true;
357
- if (ring && y !== prevY)
358
- ring.push([x, y]);
359
- prevX = x;
360
- prevY = y;
361
- }
362
- while (tMaxX < 1 || tMaxY < 1) {
363
- if (tMaxX < tMaxY) {
364
- tMaxX += tdx;
365
- x += sx;
366
- } else {
367
- tMaxY += tdy;
368
- y += sy;
369
- }
370
- tileHash[toID2(x, y, maxZoom)] = true;
371
- if (ring && y !== prevY)
372
- ring.push([x, y]);
373
- prevX = x;
374
- prevY = y;
375
- }
376
- }
377
- if (ring && y === ring[0][1])
378
- ring.pop();
379
- }
380
- function appendHashTiles2(hash, tiles3) {
381
- var keys = Object.keys(hash);
382
- for (var i = 0; i < keys.length; i++) {
383
- tiles3.push(fromID2(+keys[i]));
384
- }
385
- }
386
- function toID2(x, y, z) {
387
- var dim = 2 * (1 << z);
388
- return (dim * y + x) * 32 + z;
389
- }
390
- function fromID2(id5) {
391
- var z = id5 % 32, dim = 2 * (1 << z), xy = (id5 - z) / 32, x = xy % dim, y = (xy - x) / dim % dim;
392
- return [x, y, z];
393
- }
394
- }
395
- });
396
-
397
69
  // external-global-plugin:h3-js
398
70
  var require_h3_js = __commonJS({
399
71
  "external-global-plugin:h3-js"(exports, module) {
@@ -6044,9 +5716,6 @@ var __exports__ = (() => {
6044
5716
  // src/layers/cluster-tile-layer.ts
6045
5717
  var import_core6 = __toESM(require_core2(), 1);
6046
5718
 
6047
- // ../../node_modules/quadbin/dist/index.esm.js
6048
- var import_tile_cover = __toESM(require_tile_cover(), 1);
6049
-
6050
5719
  // ../../node_modules/@math.gl/web-mercator/dist/web-mercator-utils.js
6051
5720
  var PI = Math.PI;
6052
5721
  var PI_4 = PI / 4;
@@ -6064,811 +5733,1149 @@ var __exports__ = (() => {
6064
5733
  var DEGREES_TO_RADIANS2 = Math.PI / 180;
6065
5734
 
6066
5735
  // ../../node_modules/quadbin/dist/index.esm.js
6067
- var B = [0x5555555555555555n, 0x3333333333333333n, 0x0f0f0f0f0f0f0f0fn, 0x00ff00ff00ff00ffn, 0x0000ffff0000ffffn, 0x00000000ffffffffn];
6068
- var S = [0n, 1n, 2n, 4n, 8n, 16n];
6069
- function hexToBigInt(hex3) {
6070
- return BigInt(`0x${hex3}`);
5736
+ var d2r = Math.PI / 180;
5737
+ var r2d = 180 / Math.PI;
5738
+ function tileToBBOX(tile) {
5739
+ var e = tile2lon(tile[0] + 1, tile[2]);
5740
+ var w = tile2lon(tile[0], tile[2]);
5741
+ var s = tile2lat(tile[1] + 1, tile[2]);
5742
+ var n = tile2lat(tile[1], tile[2]);
5743
+ return [w, s, e, n];
6071
5744
  }
6072
- function bigIntToHex(index2) {
6073
- return index2.toString(16);
5745
+ function tileToGeoJSON(tile) {
5746
+ var bbox2 = tileToBBOX(tile);
5747
+ var poly = {
5748
+ type: "Polygon",
5749
+ coordinates: [
5750
+ [
5751
+ [bbox2[0], bbox2[1]],
5752
+ [bbox2[0], bbox2[3]],
5753
+ [bbox2[2], bbox2[3]],
5754
+ [bbox2[2], bbox2[1]],
5755
+ [bbox2[0], bbox2[1]]
5756
+ ]
5757
+ ]
5758
+ };
5759
+ return poly;
6074
5760
  }
6075
- function tileToCell(tile) {
6076
- if (tile.z < 0 || tile.z > 26) {
6077
- throw new Error("Wrong zoom");
6078
- }
6079
- const z = BigInt(tile.z);
6080
- let x = BigInt(tile.x) << 32n - z;
6081
- let y = BigInt(tile.y) << 32n - z;
6082
- for (let i = 0; i < 5; i++) {
6083
- const s = S[5 - i];
6084
- const b = B[4 - i];
6085
- x = (x | x << s) & b;
6086
- y = (y | y << s) & b;
6087
- }
6088
- const quadbin = 0x4000000000000000n | 1n << 59n | // | (mode << 59) | (mode_dep << 57)
6089
- z << 52n | (x | y << 1n) >> 12n | 0xfffffffffffffn >> z * 2n;
6090
- return quadbin;
5761
+ function tile2lon(x, z) {
5762
+ return x / Math.pow(2, z) * 360 - 180;
6091
5763
  }
6092
- function cellToTile(quadbin) {
6093
- const mode = quadbin >> 59n & 7n;
6094
- const modeDep = quadbin >> 57n & 3n;
6095
- const z = quadbin >> 52n & 0x1fn;
6096
- const q = (quadbin & 0xfffffffffffffn) << 12n;
6097
- if (mode !== 1n && modeDep !== 0n) {
6098
- throw new Error("Wrong mode");
6099
- }
6100
- let x = q;
6101
- let y = q >> 1n;
6102
- for (let i = 0; i < 6; i++) {
6103
- const s = S[i];
6104
- const b = B[i];
6105
- x = (x | x >> s) & b;
6106
- y = (y | y >> s) & b;
6107
- }
6108
- x = x >> 32n - z;
6109
- y = y >> 32n - z;
6110
- return {
6111
- z: Number(z),
6112
- x: Number(x),
6113
- y: Number(y)
6114
- };
5764
+ function tile2lat(y, z) {
5765
+ var n = Math.PI - 2 * Math.PI * y / Math.pow(2, z);
5766
+ return r2d * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n)));
6115
5767
  }
6116
- function getResolution(quadbin) {
6117
- return quadbin >> 52n & 0x1fn;
5768
+ function pointToTile(lon, lat, z) {
5769
+ var tile = pointToTileFraction(lon, lat, z);
5770
+ tile[0] = Math.floor(tile[0]);
5771
+ tile[1] = Math.floor(tile[1]);
5772
+ return tile;
6118
5773
  }
6119
- function cellToParent(quadbin) {
6120
- const zparent = getResolution(quadbin) - 1n;
6121
- const parent = quadbin & ~(0x1fn << 52n) | zparent << 52n | 0xfffffffffffffn >> zparent * 2n;
6122
- return parent;
5774
+ function getChildren(tile) {
5775
+ return [
5776
+ [tile[0] * 2, tile[1] * 2, tile[2] + 1],
5777
+ [tile[0] * 2 + 1, tile[1] * 2, tile[2] + 1],
5778
+ [tile[0] * 2 + 1, tile[1] * 2 + 1, tile[2] + 1],
5779
+ [tile[0] * 2, tile[1] * 2 + 1, tile[2] + 1]
5780
+ ];
6123
5781
  }
6124
-
6125
- // src/layers/cluster-utils.ts
6126
- var import_h3_js = __toESM(require_h3_js(), 1);
6127
- var import_core2 = __toESM(require_core2(), 1);
6128
-
6129
- // src/utils.ts
6130
- var import_core = __toESM(require_core2(), 1);
6131
- function assert2(condition, message) {
6132
- import_core.log.assert(condition, message);
5782
+ function getParent(tile) {
5783
+ if (tile[0] % 2 === 0 && tile[1] % 2 === 0) {
5784
+ return [tile[0] / 2, tile[1] / 2, tile[2] - 1];
5785
+ } else if (tile[0] % 2 === 0 && !tile[1] % 2 === 0) {
5786
+ return [tile[0] / 2, (tile[1] - 1) / 2, tile[2] - 1];
5787
+ } else if (!tile[0] % 2 === 0 && tile[1] % 2 === 0) {
5788
+ return [(tile[0] - 1) / 2, tile[1] / 2, tile[2] - 1];
5789
+ } else {
5790
+ return [(tile[0] - 1) / 2, (tile[1] - 1) / 2, tile[2] - 1];
5791
+ }
6133
5792
  }
6134
- function createBinaryProxy(data, index2) {
6135
- const { properties, numericProps } = data;
6136
- return new Proxy(properties[index2] || {}, {
6137
- get(target, property) {
6138
- if (property in numericProps) {
6139
- return numericProps[property].value[index2];
6140
- }
6141
- return target[property];
6142
- },
6143
- has(target, property) {
6144
- return property in numericProps || property in target;
6145
- },
6146
- ownKeys(target) {
6147
- return [...Object.keys(numericProps), ...Reflect.ownKeys(target)];
6148
- },
6149
- getOwnPropertyDescriptor(target, prop) {
6150
- return { enumerable: true, configurable: true };
6151
- }
6152
- });
5793
+ function getSiblings(tile) {
5794
+ return getChildren(getParent(tile));
6153
5795
  }
6154
- function getWorkerUrl(id5, version) {
6155
- return `https://unpkg.com/@deck.gl/carto@${version}/dist/${id5}-worker.js`;
5796
+ function hasSiblings(tile, tiles2) {
5797
+ var siblings = getSiblings(tile);
5798
+ for (var i = 0; i < siblings.length; i++) {
5799
+ if (!hasTile(tiles2, siblings[i]))
5800
+ return false;
5801
+ }
5802
+ return true;
6156
5803
  }
6157
- var EMPTY_UINT16ARRAY = new Uint16Array();
6158
- var EMPTY_BINARY_PROPS = {
6159
- positions: { value: new Float32Array(), size: 2 },
6160
- properties: [],
6161
- numericProps: {},
6162
- featureIds: { value: EMPTY_UINT16ARRAY, size: 1 },
6163
- globalFeatureIds: { value: EMPTY_UINT16ARRAY, size: 1 }
6164
- };
6165
- function createEmptyBinary() {
6166
- return {
6167
- shape: "binary-feature-collection",
6168
- points: {
6169
- type: "Point",
6170
- ...EMPTY_BINARY_PROPS
6171
- },
6172
- lines: {
6173
- type: "LineString",
6174
- pathIndices: { value: EMPTY_UINT16ARRAY, size: 1 },
6175
- ...EMPTY_BINARY_PROPS
6176
- },
6177
- polygons: {
6178
- type: "Polygon",
6179
- polygonIndices: { value: EMPTY_UINT16ARRAY, size: 1 },
6180
- primitivePolygonIndices: { value: EMPTY_UINT16ARRAY, size: 1 },
6181
- ...EMPTY_BINARY_PROPS
6182
- }
6183
- };
5804
+ function hasTile(tiles2, tile) {
5805
+ for (var i = 0; i < tiles2.length; i++) {
5806
+ if (tilesEqual(tiles2[i], tile))
5807
+ return true;
5808
+ }
5809
+ return false;
6184
5810
  }
6185
- function createBinaryPointFeature(positions, featureIds, globalFeatureIds, numericProps, properties, size = 2) {
6186
- return {
6187
- type: "Point",
6188
- positions: { value: new Float32Array(positions), size },
6189
- featureIds: { value: new Uint16Array(featureIds), size: 1 },
6190
- globalFeatureIds: { value: new Uint32Array(globalFeatureIds), size: 1 },
6191
- numericProps,
6192
- properties
6193
- };
5811
+ function tilesEqual(tile1, tile2) {
5812
+ return tile1[0] === tile2[0] && tile1[1] === tile2[1] && tile1[2] === tile2[2];
6194
5813
  }
6195
- function initializeNumericProps(numPoints, sourceProps) {
6196
- const numericProps = {};
6197
- if (sourceProps) {
6198
- Object.keys(sourceProps).forEach((prop) => {
6199
- numericProps[prop] = { value: new Float32Array(numPoints), size: 1 };
6200
- });
5814
+ function tileToQuadkey(tile) {
5815
+ var index2 = "";
5816
+ for (var z = tile[2]; z > 0; z--) {
5817
+ var b = 0;
5818
+ var mask = 1 << z - 1;
5819
+ if ((tile[0] & mask) !== 0)
5820
+ b++;
5821
+ if ((tile[1] & mask) !== 0)
5822
+ b += 2;
5823
+ index2 += b.toString();
6201
5824
  }
6202
- return numericProps;
5825
+ return index2;
6203
5826
  }
6204
- function copyNumericProps(sourceProps, targetProps, sourceIndex, targetIndex) {
6205
- Object.keys(sourceProps).forEach((prop) => {
6206
- targetProps[prop].value[targetIndex] = sourceProps[prop].value[sourceIndex];
6207
- });
5827
+ function quadkeyToTile(quadkey) {
5828
+ var x = 0;
5829
+ var y = 0;
5830
+ var z = quadkey.length;
5831
+ for (var i = z; i > 0; i--) {
5832
+ var mask = 1 << i - 1;
5833
+ switch (quadkey[z - i]) {
5834
+ case "0":
5835
+ break;
5836
+ case "1":
5837
+ x |= mask;
5838
+ break;
5839
+ case "2":
5840
+ y |= mask;
5841
+ break;
5842
+ case "3":
5843
+ x |= mask;
5844
+ y |= mask;
5845
+ break;
5846
+ }
5847
+ }
5848
+ return [x, y, z];
6208
5849
  }
6209
-
6210
- // src/layers/cluster-utils.ts
6211
- function aggregateTile(tile, tileAggregationCache, aggregationLevels, properties = [], getPosition, getWeight, scheme = "quadbin") {
6212
- if (!tile.content)
6213
- return false;
6214
- if (!tile.userData)
6215
- tile.userData = {};
6216
- const cell0 = tileAggregationCache.get(aggregationLevels)?.[0];
6217
- if (cell0) {
6218
- if (properties.every((property) => property.name in cell0)) {
6219
- return false;
5850
+ function bboxToTile(bboxCoords) {
5851
+ var min2 = pointToTile(bboxCoords[0], bboxCoords[1], 32);
5852
+ var max2 = pointToTile(bboxCoords[2], bboxCoords[3], 32);
5853
+ var bbox2 = [min2[0], min2[1], max2[0], max2[1]];
5854
+ var z = getBboxZoom(bbox2);
5855
+ if (z === 0)
5856
+ return [0, 0, 0];
5857
+ var x = bbox2[0] >>> 32 - z;
5858
+ var y = bbox2[1] >>> 32 - z;
5859
+ return [x, y, z];
5860
+ }
5861
+ function getBboxZoom(bbox2) {
5862
+ var MAX_ZOOM = 28;
5863
+ for (var z = 0; z < MAX_ZOOM; z++) {
5864
+ var mask = 1 << 32 - (z + 1);
5865
+ if ((bbox2[0] & mask) != (bbox2[2] & mask) || (bbox2[1] & mask) != (bbox2[3] & mask)) {
5866
+ return z;
6220
5867
  }
6221
- tileAggregationCache.clear();
6222
5868
  }
6223
- const out = {};
6224
- for (const cell of tile.content) {
6225
- let id5 = cell.id;
6226
- const position = typeof getPosition === "function" ? getPosition(cell, {}) : getPosition;
6227
- for (let i = 0; i < aggregationLevels - 1; i++) {
6228
- if (scheme === "h3") {
6229
- const currentResolution = (0, import_h3_js.getResolution)(id5);
6230
- id5 = (0, import_h3_js.cellToParent)(id5, Math.max(0, currentResolution - 1));
6231
- } else {
6232
- id5 = cellToParent(id5);
6233
- }
5869
+ return MAX_ZOOM;
5870
+ }
5871
+ function pointToTileFraction(lon, lat, z) {
5872
+ var sin = Math.sin(lat * d2r), z2 = Math.pow(2, z), x = z2 * (lon / 360 + 0.5), y = z2 * (0.5 - 0.25 * Math.log((1 + sin) / (1 - sin)) / Math.PI);
5873
+ return [x, y, z];
5874
+ }
5875
+ var tilebelt = {
5876
+ tileToGeoJSON,
5877
+ tileToBBOX,
5878
+ getChildren,
5879
+ getParent,
5880
+ getSiblings,
5881
+ hasTile,
5882
+ hasSiblings,
5883
+ tilesEqual,
5884
+ tileToQuadkey,
5885
+ quadkeyToTile,
5886
+ pointToTile,
5887
+ bboxToTile,
5888
+ pointToTileFraction
5889
+ };
5890
+ var tiles = getTiles;
5891
+ function getTiles(geom, limits) {
5892
+ var i, tile, coords = geom.coordinates, maxZoom = limits.max_zoom, tileHash = {}, tiles2 = [];
5893
+ if (geom.type === "Point") {
5894
+ return [tilebelt.pointToTile(coords[0], coords[1], maxZoom)];
5895
+ } else if (geom.type === "MultiPoint") {
5896
+ for (i = 0; i < coords.length; i++) {
5897
+ tile = tilebelt.pointToTile(coords[i][0], coords[i][1], maxZoom);
5898
+ tileHash[toID(tile[0], tile[1], tile[2])] = true;
6234
5899
  }
6235
- const parentId = String(id5);
6236
- if (!(parentId in out)) {
6237
- out[parentId] = { id: id5, count: 0, position: [0, 0] };
6238
- for (const { name, aggregation } of properties) {
6239
- if (aggregation === "any") {
6240
- out[parentId][name] = cell.properties[name];
6241
- } else {
6242
- out[parentId][name] = 0;
5900
+ } else if (geom.type === "LineString") {
5901
+ lineCover(tileHash, coords, maxZoom);
5902
+ } else if (geom.type === "MultiLineString") {
5903
+ for (i = 0; i < coords.length; i++) {
5904
+ lineCover(tileHash, coords[i], maxZoom);
5905
+ }
5906
+ } else if (geom.type === "Polygon") {
5907
+ polygonCover(tileHash, tiles2, coords, maxZoom);
5908
+ } else if (geom.type === "MultiPolygon") {
5909
+ for (i = 0; i < coords.length; i++) {
5910
+ polygonCover(tileHash, tiles2, coords[i], maxZoom);
5911
+ }
5912
+ } else {
5913
+ throw new Error("Geometry type not implemented");
5914
+ }
5915
+ if (limits.min_zoom !== maxZoom) {
5916
+ var len = tiles2.length;
5917
+ appendHashTiles(tileHash, tiles2);
5918
+ for (i = 0; i < len; i++) {
5919
+ var t = tiles2[i];
5920
+ tileHash[toID(t[0], t[1], t[2])] = true;
5921
+ }
5922
+ return mergeTiles(tileHash, tiles2, limits);
5923
+ }
5924
+ appendHashTiles(tileHash, tiles2);
5925
+ return tiles2;
5926
+ }
5927
+ function mergeTiles(tileHash, tiles2, limits) {
5928
+ var mergedTiles = [];
5929
+ for (var z = limits.max_zoom; z > limits.min_zoom; z--) {
5930
+ var parentTileHash = {};
5931
+ var parentTiles = [];
5932
+ for (var i = 0; i < tiles2.length; i++) {
5933
+ var t = tiles2[i];
5934
+ if (t[0] % 2 === 0 && t[1] % 2 === 0) {
5935
+ var id22 = toID(t[0] + 1, t[1], z), id32 = toID(t[0], t[1] + 1, z), id42 = toID(t[0] + 1, t[1] + 1, z);
5936
+ if (tileHash[id22] && tileHash[id32] && tileHash[id42]) {
5937
+ tileHash[toID(t[0], t[1], t[2])] = false;
5938
+ tileHash[id22] = false;
5939
+ tileHash[id32] = false;
5940
+ tileHash[id42] = false;
5941
+ var parentTile = [t[0] / 2, t[1] / 2, z - 1];
5942
+ if (z - 1 === limits.min_zoom)
5943
+ mergedTiles.push(parentTile);
5944
+ else {
5945
+ parentTileHash[toID(t[0] / 2, t[1] / 2, z - 1)] = true;
5946
+ parentTiles.push(parentTile);
5947
+ }
6243
5948
  }
6244
5949
  }
6245
5950
  }
6246
- const prevTotalW = out[parentId].count;
6247
- out[parentId].count += typeof getWeight === "function" ? getWeight(cell, {}) : getWeight;
6248
- const totalW = out[parentId].count;
6249
- const W = totalW - prevTotalW;
6250
- out[parentId].position[0] = (prevTotalW * out[parentId].position[0] + W * position[0]) / totalW;
6251
- out[parentId].position[1] = (prevTotalW * out[parentId].position[1] + W * position[1]) / totalW;
6252
- for (const { name, aggregation } of properties) {
6253
- const prevValue = out[parentId][name];
6254
- const value = cell.properties[name];
6255
- if (aggregation === "average") {
6256
- out[parentId][name] = (prevTotalW * prevValue + W * value) / totalW;
6257
- } else if (aggregation === "count" || aggregation === "sum") {
6258
- out[parentId][name] = prevValue + value;
6259
- } else if (aggregation === "max") {
6260
- out[parentId][name] = Math.max(prevValue, value);
6261
- } else if (aggregation === "min") {
6262
- out[parentId][name] = Math.min(prevValue, value);
6263
- }
5951
+ for (i = 0; i < tiles2.length; i++) {
5952
+ t = tiles2[i];
5953
+ if (tileHash[toID(t[0], t[1], t[2])])
5954
+ mergedTiles.push(t);
6264
5955
  }
5956
+ tileHash = parentTileHash;
5957
+ tiles2 = parentTiles;
6265
5958
  }
6266
- tileAggregationCache.set(aggregationLevels, Object.values(out));
6267
- return true;
5959
+ return mergedTiles;
6268
5960
  }
6269
- function extractAggregationProperties(tile) {
6270
- const properties = [];
6271
- const validAggregations = ["any", "average", "count", "min", "max", "sum"];
6272
- for (const name of Object.keys(tile.content[0].properties)) {
6273
- let aggregation = name.split("_").pop().toLowerCase();
6274
- if (!validAggregations.includes(aggregation)) {
6275
- import_core2.log.warn(`No valid aggregation present in ${name} property`)();
6276
- aggregation = "any";
5961
+ function polygonCover(tileHash, tileArray, geom, zoom) {
5962
+ var intersections = [];
5963
+ for (var i = 0; i < geom.length; i++) {
5964
+ var ring = [];
5965
+ lineCover(tileHash, geom[i], zoom, ring);
5966
+ for (var j = 0, len = ring.length, k = len - 1; j < len; k = j++) {
5967
+ var m = (j + 1) % len;
5968
+ var y = ring[j][1];
5969
+ if ((y > ring[k][1] || y > ring[m][1]) && // not local minimum
5970
+ (y < ring[k][1] || y < ring[m][1]) && // not local maximum
5971
+ y !== ring[m][1])
5972
+ intersections.push(ring[j]);
6277
5973
  }
6278
- properties.push({ name, aggregation });
6279
5974
  }
6280
- return properties;
6281
- }
6282
- function computeAggregationStats(data, properties) {
6283
- const stats = {};
6284
- for (const { name, aggregation } of properties) {
6285
- stats[name] = { min: Infinity, max: -Infinity };
6286
- if (aggregation !== "any") {
6287
- for (const d of data) {
6288
- stats[name].min = Math.min(stats[name].min, d[name]);
6289
- stats[name].max = Math.max(stats[name].max, d[name]);
5975
+ intersections.sort(compareTiles);
5976
+ for (i = 0; i < intersections.length; i += 2) {
5977
+ y = intersections[i][1];
5978
+ for (var x = intersections[i][0] + 1; x < intersections[i + 1][0]; x++) {
5979
+ var id5 = toID(x, y, zoom);
5980
+ if (!tileHash[id5]) {
5981
+ tileArray.push([x, y, zoom]);
6290
5982
  }
6291
5983
  }
6292
5984
  }
6293
- return stats;
6294
5985
  }
6295
- function clustersToBinary(data) {
6296
- const positions = new Float32Array(data.length * 2);
6297
- const featureIds = new Uint16Array(data.length);
6298
- for (let i = 0; i < data.length; i++) {
6299
- positions.set(data[i].position, 2 * i);
6300
- featureIds[i] = i;
6301
- }
6302
- return {
6303
- ...createEmptyBinary(),
6304
- points: createBinaryPointFeature(positions, featureIds, featureIds, {}, data)
6305
- };
5986
+ function compareTiles(a, b) {
5987
+ return a[1] - b[1] || a[0] - b[0];
6306
5988
  }
6307
-
6308
- // src/constants.ts
6309
- var DEFAULT_TILE_SIZE = 512;
6310
-
6311
- // src/layers/quadbin-tileset-2d.ts
6312
- var import_geo_layers = __toESM(require_geo_layers(), 1);
6313
- var QuadbinTileset2D = class extends import_geo_layers._Tileset2D {
6314
- // @ts-expect-error for spatial indices, TileSet2d should be parametrized by TileIndexT
6315
- getTileIndices(opts) {
6316
- return super.getTileIndices(opts).map(tileToCell).map((q) => ({ q, i: bigIntToHex(q) }));
6317
- }
6318
- // @ts-expect-error TileIndex must be generic
6319
- getTileId({ q, i }) {
6320
- return i || bigIntToHex(q);
6321
- }
6322
- // @ts-expect-error TileIndex must be generic
6323
- getTileMetadata({ q }) {
6324
- return super.getTileMetadata(cellToTile(q));
6325
- }
6326
- // @ts-expect-error TileIndex must be generic
6327
- getTileZoom({ q }) {
6328
- return Number(getResolution(q));
6329
- }
6330
- // @ts-expect-error TileIndex must be generic
6331
- getParentIndex({ q }) {
6332
- return { q: cellToParent(q) };
5989
+ function lineCover(tileHash, coords, maxZoom, ring) {
5990
+ var prevX, prevY;
5991
+ for (var i = 0; i < coords.length - 1; i++) {
5992
+ var start = tilebelt.pointToTileFraction(coords[i][0], coords[i][1], maxZoom), stop = tilebelt.pointToTileFraction(coords[i + 1][0], coords[i + 1][1], maxZoom), x0 = start[0], y0 = start[1], x1 = stop[0], y1 = stop[1], dx = x1 - x0, dy = y1 - y0;
5993
+ if (dy === 0 && dx === 0)
5994
+ continue;
5995
+ var sx = dx > 0 ? 1 : -1, sy = dy > 0 ? 1 : -1, x = Math.floor(x0), y = Math.floor(y0), tMaxX = dx === 0 ? Infinity : Math.abs(((dx > 0 ? 1 : 0) + x - x0) / dx), tMaxY = dy === 0 ? Infinity : Math.abs(((dy > 0 ? 1 : 0) + y - y0) / dy), tdx = Math.abs(sx / dx), tdy = Math.abs(sy / dy);
5996
+ if (x !== prevX || y !== prevY) {
5997
+ tileHash[toID(x, y, maxZoom)] = true;
5998
+ if (ring && y !== prevY)
5999
+ ring.push([x, y]);
6000
+ prevX = x;
6001
+ prevY = y;
6002
+ }
6003
+ while (tMaxX < 1 || tMaxY < 1) {
6004
+ if (tMaxX < tMaxY) {
6005
+ tMaxX += tdx;
6006
+ x += sx;
6007
+ } else {
6008
+ tMaxY += tdy;
6009
+ y += sy;
6010
+ }
6011
+ tileHash[toID(x, y, maxZoom)] = true;
6012
+ if (ring && y !== prevY)
6013
+ ring.push([x, y]);
6014
+ prevX = x;
6015
+ prevY = y;
6016
+ }
6333
6017
  }
6334
- };
6335
-
6336
- // src/layers/h3-tileset-2d.ts
6337
- var import_geo_layers2 = __toESM(require_geo_layers(), 1);
6338
- var import_h3_js2 = __toESM(require_h3_js(), 1);
6339
- var MAX_LATITUDE2 = 85.051128;
6340
- function padBoundingBox({ west, north, east, south }, resolution, scale = 1) {
6341
- const corners = [
6342
- [north, east],
6343
- [south, east],
6344
- [south, west],
6345
- [north, west]
6346
- ];
6347
- const cornerCells = corners.map((c) => (0, import_h3_js2.latLngToCell)(c[0], c[1], resolution));
6348
- const cornerEdgeLengths = cornerCells.map(
6349
- (c) => Math.max(...(0, import_h3_js2.originToDirectedEdges)(c).map((e) => (0, import_h3_js2.edgeLength)(e, import_h3_js2.UNITS.rads))) * 180 / Math.PI
6350
- );
6351
- const bufferLat = Math.max(...cornerEdgeLengths) * scale;
6352
- const bufferLon = Math.min(180, bufferLat / Math.cos((north + south) / 2 * Math.PI / 180));
6353
- return {
6354
- north: Math.min(north + bufferLat, MAX_LATITUDE2),
6355
- east: east + bufferLon,
6356
- south: Math.max(south - bufferLat, -MAX_LATITUDE2),
6357
- west: west - bufferLon
6358
- };
6018
+ if (ring && y === ring[0][1])
6019
+ ring.pop();
6359
6020
  }
6360
- function getHexagonsInBoundingBox({ west, north, east, south }, resolution) {
6361
- const longitudeSpan = Math.abs(east - west);
6362
- if (longitudeSpan > 180) {
6363
- const nSegments = Math.ceil(longitudeSpan / 180);
6364
- let h3Indices = [];
6365
- for (let s = 0; s < nSegments; s++) {
6366
- const segmentWest = west + s * 180;
6367
- const segmentEast = Math.min(segmentWest + 179.9999999, east);
6368
- h3Indices = h3Indices.concat(
6369
- getHexagonsInBoundingBox({ west: segmentWest, north, east: segmentEast, south }, resolution)
6370
- );
6371
- }
6372
- return [...new Set(h3Indices)];
6021
+ function appendHashTiles(hash, tiles2) {
6022
+ var keys = Object.keys(hash);
6023
+ for (var i = 0; i < keys.length; i++) {
6024
+ tiles2.push(fromID(+keys[i]));
6373
6025
  }
6374
- const polygon2 = [
6375
- [north, east],
6376
- [south, east],
6377
- [south, west],
6378
- [north, west],
6379
- [north, east]
6380
- ];
6381
- return (0, import_h3_js2.polygonToCells)(polygon2, resolution);
6382
6026
  }
6383
- function tileToBoundingBox(index2) {
6384
- const coordinates = (0, import_h3_js2.cellToBoundary)(index2);
6385
- const latitudes = coordinates.map((c) => c[0]);
6386
- const longitudes = coordinates.map((c) => c[1]);
6387
- const west = Math.min(...longitudes);
6388
- const south = Math.min(...latitudes);
6389
- const east = Math.max(...longitudes);
6390
- const north = Math.max(...latitudes);
6391
- const bbox2 = { west, south, east, north };
6392
- return padBoundingBox(bbox2, (0, import_h3_js2.getResolution)(index2), 0.12);
6027
+ function toID(x, y, z) {
6028
+ var dim = 2 * (1 << z);
6029
+ return (dim * y + x) * 32 + z;
6393
6030
  }
6394
- var BIAS = 2;
6395
- function getHexagonResolution(viewport, tileSize) {
6396
- const zoomOffset = Math.log2(tileSize / 512);
6397
- const hexagonScaleFactor = 2 / 3 * (viewport.zoom - zoomOffset);
6398
- const latitudeScaleFactor = Math.log(1 / Math.cos(Math.PI * viewport.latitude / 180));
6399
- return Math.max(0, Math.floor(hexagonScaleFactor + latitudeScaleFactor - BIAS));
6031
+ function fromID(id5) {
6032
+ var z = id5 % 32, dim = 2 * (1 << z), xy = (id5 - z) / 32, x = xy % dim, y = (xy - x) / dim % dim;
6033
+ return [x, y, z];
6400
6034
  }
6401
- var H3Tileset2D = class extends import_geo_layers2._Tileset2D {
6402
- /**
6403
- * Returns all tile indices in the current viewport. If the current zoom level is smaller
6404
- * than minZoom, return an empty array. If the current zoom level is greater than maxZoom,
6405
- * return tiles that are on maxZoom.
6406
- */
6407
- // @ts-expect-error Tileset2D should be generic over TileIndex
6408
- getTileIndices({ viewport, minZoom, maxZoom }) {
6409
- if (viewport.latitude === void 0)
6410
- return [];
6411
- const [west, south, east, north] = viewport.getBounds();
6412
- const { tileSize } = this.opts;
6413
- let z = getHexagonResolution(viewport, tileSize);
6414
- let indices;
6415
- if (typeof minZoom === "number" && Number.isFinite(minZoom) && z < minZoom) {
6416
- return [];
6417
- }
6418
- if (typeof maxZoom === "number" && Number.isFinite(maxZoom) && z > maxZoom) {
6419
- z = maxZoom;
6420
- const center = (0, import_h3_js2.latLngToCell)(viewport.latitude, viewport.longitude, maxZoom);
6421
- indices = (0, import_h3_js2.gridDisk)(center, 1);
6422
- } else {
6423
- const paddedBounds = padBoundingBox({ west, north, east, south }, z);
6424
- indices = getHexagonsInBoundingBox(paddedBounds, z);
6425
- }
6426
- return indices.map((i) => ({ i }));
6427
- }
6428
- // @ts-expect-error Tileset2D should be generic over TileIndex
6429
- getTileId({ i }) {
6430
- return i;
6431
- }
6432
- // @ts-expect-error Tileset2D should be generic over TileIndex
6433
- getTileMetadata({ i }) {
6434
- return { bbox: tileToBoundingBox(i) };
6435
- }
6436
- // @ts-expect-error Tileset2D should be generic over TileIndex
6437
- getTileZoom({ i }) {
6438
- return (0, import_h3_js2.getResolution)(i);
6439
- }
6440
- // @ts-expect-error Tileset2D should be generic over TileIndex
6441
- getParentIndex(index2) {
6442
- const resolution = (0, import_h3_js2.getResolution)(index2.i);
6443
- const i = (0, import_h3_js2.cellToParent)(index2.i, resolution - 1);
6444
- return { i };
6445
- }
6446
- };
6447
-
6448
- // src/layers/quadbin-utils.ts
6035
+ var B = [0x5555555555555555n, 0x3333333333333333n, 0x0f0f0f0f0f0f0f0fn, 0x00ff00ff00ff00ffn, 0x0000ffff0000ffffn, 0x00000000ffffffffn];
6036
+ var S = [0n, 1n, 2n, 4n, 8n, 16n];
6449
6037
  var TILE_SIZE2 = 512;
6450
- function quadbinToOffset(quadbin) {
6451
- const { x, y, z } = cellToTile(quadbin);
6038
+ function cellToOffset(quadbin) {
6039
+ const {
6040
+ x,
6041
+ y,
6042
+ z
6043
+ } = cellToTile(quadbin);
6452
6044
  const scale = TILE_SIZE2 / (1 << z);
6453
6045
  return [x * scale, TILE_SIZE2 - y * scale, scale];
6454
6046
  }
6455
- function quadbinToWorldBounds(quadbin, coverage) {
6456
- const [xOffset, yOffset, scale] = quadbinToOffset(quadbin);
6457
- return [
6458
- [xOffset, yOffset],
6459
- [xOffset + coverage * scale, yOffset - coverage * scale]
6460
- ];
6047
+ function cellToWorldBounds(quadbin, coverage) {
6048
+ const [xOffset, yOffset, scale] = cellToOffset(quadbin);
6049
+ return [[xOffset, yOffset], [xOffset + coverage * scale, yOffset - coverage * scale]];
6461
6050
  }
6462
- function getQuadbinPolygon(quadbin, coverage = 1) {
6463
- const [topLeft, bottomRight] = quadbinToWorldBounds(quadbin, coverage);
6051
+ function getCellPolygon(quadbin, coverage = 1) {
6052
+ const [topLeft, bottomRight] = cellToWorldBounds(quadbin, coverage);
6464
6053
  const [w, n] = worldToLngLat(topLeft);
6465
6054
  const [e, s] = worldToLngLat(bottomRight);
6466
6055
  return [e, n, e, s, w, s, w, n, e, n];
6467
6056
  }
6468
-
6469
- // src/layers/cluster-tile-layer.ts
6470
- var import_h3_js3 = __toESM(require_h3_js(), 1);
6471
-
6472
- // ../../node_modules/@loaders.gl/loader-utils/dist/lib/env-utils/globals.js
6473
- var globals = {
6474
- self: typeof self !== "undefined" && self,
6475
- window: typeof window !== "undefined" && window,
6476
- global: typeof global !== "undefined" && global,
6477
- document: typeof document !== "undefined" && document
6478
- };
6479
- var self_ = globals.self || globals.window || globals.global || {};
6480
- var window_ = globals.window || globals.self || globals.global || {};
6481
- var global_ = globals.global || globals.self || globals.window || {};
6482
- var document_ = globals.document || {};
6483
- var isBrowser = (
6484
- // @ts-ignore process does not exist on browser
6485
- Boolean(typeof process !== "object" || String(process) !== "[object process]" || process.browser)
6486
- );
6487
- var matches = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
6488
- var nodeVersion = matches && parseFloat(matches[1]) || 0;
6489
-
6490
- // ../../node_modules/@loaders.gl/loader-utils/dist/lib/javascript-utils/is-type.js
6491
- var isSharedArrayBuffer = (value) => typeof SharedArrayBuffer !== "undefined" && value instanceof SharedArrayBuffer;
6492
-
6493
- // ../../node_modules/@loaders.gl/loader-utils/dist/lib/module-utils/js-module-utils.js
6494
- function registerJSModules(modules) {
6495
- globalThis.loaders ||= {};
6496
- globalThis.loaders.modules ||= {};
6497
- Object.assign(globalThis.loaders.modules, modules);
6057
+ function hexToBigInt(hex3) {
6058
+ return BigInt(`0x${hex3}`);
6498
6059
  }
6499
-
6500
- // ../../node_modules/@loaders.gl/loader-utils/dist/lib/binary-utils/array-buffer-utils.js
6501
- function concatenateArrayBuffers(...sources) {
6502
- return concatenateArrayBuffersFromArray(sources);
6060
+ function bigIntToHex(index2) {
6061
+ return index2.toString(16);
6503
6062
  }
6504
- function concatenateArrayBuffersFromArray(sources) {
6505
- const sourceArrays = sources.map((source2) => source2 instanceof ArrayBuffer ? new Uint8Array(source2) : source2);
6506
- const byteLength = sourceArrays.reduce((length2, typedArray) => length2 + typedArray.byteLength, 0);
6507
- const result = new Uint8Array(byteLength);
6508
- let offset = 0;
6509
- for (const sourceArray of sourceArrays) {
6510
- result.set(sourceArray, offset);
6511
- offset += sourceArray.byteLength;
6063
+ function tileToCell(tile) {
6064
+ if (tile.z < 0 || tile.z > 26) {
6065
+ throw new Error("Wrong zoom");
6512
6066
  }
6513
- return result.buffer;
6514
- }
6515
-
6516
- // ../../node_modules/@loaders.gl/loader-utils/dist/lib/iterators/async-iteration.js
6517
- async function concatenateArrayBuffersAsync(asyncIterator) {
6518
- const arrayBuffers = [];
6519
- for await (const chunk of asyncIterator) {
6520
- arrayBuffers.push(copyToArrayBuffer(chunk));
6067
+ const z = BigInt(tile.z);
6068
+ let x = BigInt(tile.x) << 32n - z;
6069
+ let y = BigInt(tile.y) << 32n - z;
6070
+ for (let i = 0; i < 5; i++) {
6071
+ const s = S[5 - i];
6072
+ const b = B[4 - i];
6073
+ x = (x | x << s) & b;
6074
+ y = (y | y << s) & b;
6521
6075
  }
6522
- return concatenateArrayBuffers(...arrayBuffers);
6076
+ const quadbin = 0x4000000000000000n | 1n << 59n | // | (mode << 59) | (mode_dep << 57)
6077
+ z << 52n | (x | y << 1n) >> 12n | 0xfffffffffffffn >> z * 2n;
6078
+ return quadbin;
6523
6079
  }
6524
- function copyToArrayBuffer(chunk) {
6525
- if (chunk instanceof ArrayBuffer) {
6526
- return chunk;
6527
- }
6528
- if (ArrayBuffer.isView(chunk)) {
6529
- const { buffer, byteOffset, byteLength } = chunk;
6530
- return copyFromBuffer(buffer, byteOffset, byteLength);
6080
+ function cellToTile(quadbin) {
6081
+ const mode = quadbin >> 59n & 7n;
6082
+ const modeDep = quadbin >> 57n & 3n;
6083
+ const z = quadbin >> 52n & 0x1fn;
6084
+ const q = (quadbin & 0xfffffffffffffn) << 12n;
6085
+ if (mode !== 1n && modeDep !== 0n) {
6086
+ throw new Error("Wrong mode");
6531
6087
  }
6532
- return copyFromBuffer(chunk);
6088
+ let x = q;
6089
+ let y = q >> 1n;
6090
+ for (let i = 0; i < 6; i++) {
6091
+ const s = S[i];
6092
+ const b = B[i];
6093
+ x = (x | x >> s) & b;
6094
+ y = (y | y >> s) & b;
6095
+ }
6096
+ x = x >> 32n - z;
6097
+ y = y >> 32n - z;
6098
+ return {
6099
+ z: Number(z),
6100
+ x: Number(x),
6101
+ y: Number(y)
6102
+ };
6533
6103
  }
6534
- function copyFromBuffer(buffer, byteOffset = 0, byteLength = buffer.byteLength - byteOffset) {
6535
- const view = new Uint8Array(buffer, byteOffset, byteLength);
6536
- const copy3 = new Uint8Array(view.length);
6537
- copy3.set(view);
6538
- return copy3.buffer;
6104
+ function getResolution(quadbin) {
6105
+ return quadbin >> 52n & 0x1fn;
6539
6106
  }
6540
-
6541
- // ../../node_modules/@loaders.gl/loader-utils/dist/lib/node/buffer.browser.js
6542
- function toArrayBuffer(buffer) {
6543
- return buffer;
6107
+ function cellToParent(quadbin) {
6108
+ const zparent = getResolution(quadbin) - 1n;
6109
+ const parent = quadbin & ~(0x1fn << 52n) | zparent << 52n | 0xfffffffffffffn >> zparent * 2n;
6110
+ return parent;
6111
+ }
6112
+ function geometryToCells(geometry, resolution) {
6113
+ const zoom = Number(resolution);
6114
+ return tiles(geometry, {
6115
+ min_zoom: zoom,
6116
+ max_zoom: zoom
6117
+ }).map(([x, y, z]) => tileToCell({
6118
+ x,
6119
+ y,
6120
+ z
6121
+ }));
6122
+ }
6123
+ function cellToBoundary(cell) {
6124
+ const bbox2 = getCellPolygon(cell);
6125
+ const boundary = [[bbox2[0], bbox2[1]], [bbox2[2], bbox2[3]], [bbox2[4], bbox2[5]], [bbox2[6], bbox2[7]], [bbox2[0], bbox2[1]]];
6126
+ return {
6127
+ type: "Polygon",
6128
+ coordinates: [boundary]
6129
+ };
6544
6130
  }
6545
6131
 
6546
- // ../../node_modules/@loaders.gl/loader-utils/dist/lib/binary-utils/memory-conversion-utils.js
6547
- function isBuffer(value) {
6548
- return value && typeof value === "object" && value.isBuffer;
6132
+ // src/layers/cluster-utils.ts
6133
+ var import_h3_js = __toESM(require_h3_js(), 1);
6134
+ var import_core2 = __toESM(require_core2(), 1);
6135
+
6136
+ // src/utils.ts
6137
+ var import_core = __toESM(require_core2(), 1);
6138
+ function assert2(condition, message) {
6139
+ import_core.log.assert(condition, message);
6549
6140
  }
6550
- function toArrayBuffer2(data) {
6551
- if (isBuffer(data)) {
6552
- return toArrayBuffer(data);
6553
- }
6554
- if (data instanceof ArrayBuffer) {
6555
- return data;
6141
+ function createBinaryProxy(data, index2) {
6142
+ const { properties, numericProps } = data;
6143
+ return new Proxy(properties[index2] || {}, {
6144
+ get(target, property) {
6145
+ if (property in numericProps) {
6146
+ return numericProps[property].value[index2];
6147
+ }
6148
+ return target[property];
6149
+ },
6150
+ has(target, property) {
6151
+ return property in numericProps || property in target;
6152
+ },
6153
+ ownKeys(target) {
6154
+ return [...Object.keys(numericProps), ...Reflect.ownKeys(target)];
6155
+ },
6156
+ getOwnPropertyDescriptor(target, prop) {
6157
+ return { enumerable: true, configurable: true };
6158
+ }
6159
+ });
6160
+ }
6161
+ function getWorkerUrl(id5, version) {
6162
+ return `https://unpkg.com/@deck.gl/carto@${version}/dist/${id5}-worker.js`;
6163
+ }
6164
+ var EMPTY_UINT16ARRAY = new Uint16Array();
6165
+ var EMPTY_BINARY_PROPS = {
6166
+ positions: { value: new Float32Array(), size: 2 },
6167
+ properties: [],
6168
+ numericProps: {},
6169
+ featureIds: { value: EMPTY_UINT16ARRAY, size: 1 },
6170
+ globalFeatureIds: { value: EMPTY_UINT16ARRAY, size: 1 }
6171
+ };
6172
+ function createEmptyBinary() {
6173
+ return {
6174
+ shape: "binary-feature-collection",
6175
+ points: {
6176
+ type: "Point",
6177
+ ...EMPTY_BINARY_PROPS
6178
+ },
6179
+ lines: {
6180
+ type: "LineString",
6181
+ pathIndices: { value: EMPTY_UINT16ARRAY, size: 1 },
6182
+ ...EMPTY_BINARY_PROPS
6183
+ },
6184
+ polygons: {
6185
+ type: "Polygon",
6186
+ polygonIndices: { value: EMPTY_UINT16ARRAY, size: 1 },
6187
+ primitivePolygonIndices: { value: EMPTY_UINT16ARRAY, size: 1 },
6188
+ ...EMPTY_BINARY_PROPS
6189
+ }
6190
+ };
6191
+ }
6192
+ function createBinaryPointFeature(positions, featureIds, globalFeatureIds, numericProps, properties, size = 2) {
6193
+ return {
6194
+ type: "Point",
6195
+ positions: { value: new Float32Array(positions), size },
6196
+ featureIds: { value: new Uint16Array(featureIds), size: 1 },
6197
+ globalFeatureIds: { value: new Uint32Array(globalFeatureIds), size: 1 },
6198
+ numericProps,
6199
+ properties
6200
+ };
6201
+ }
6202
+ function initializeNumericProps(numPoints, sourceProps) {
6203
+ const numericProps = {};
6204
+ if (sourceProps) {
6205
+ Object.keys(sourceProps).forEach((prop) => {
6206
+ numericProps[prop] = { value: new Float32Array(numPoints), size: 1 };
6207
+ });
6556
6208
  }
6557
- if (isSharedArrayBuffer(data)) {
6558
- return copyToArrayBuffer2(data);
6209
+ return numericProps;
6210
+ }
6211
+ function copyNumericProps(sourceProps, targetProps, sourceIndex, targetIndex) {
6212
+ Object.keys(sourceProps).forEach((prop) => {
6213
+ targetProps[prop].value[targetIndex] = sourceProps[prop].value[sourceIndex];
6214
+ });
6215
+ }
6216
+
6217
+ // src/layers/cluster-utils.ts
6218
+ function aggregateTile(tile, tileAggregationCache, aggregationLevels, properties = [], getPosition, getWeight, scheme = "quadbin") {
6219
+ if (!tile.content)
6220
+ return false;
6221
+ if (!tile.userData)
6222
+ tile.userData = {};
6223
+ const cell0 = tileAggregationCache.get(aggregationLevels)?.[0];
6224
+ if (cell0) {
6225
+ if (properties.every((property) => property.name in cell0)) {
6226
+ return false;
6227
+ }
6228
+ tileAggregationCache.clear();
6559
6229
  }
6560
- if (ArrayBuffer.isView(data)) {
6561
- const buffer = data.buffer;
6562
- if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) {
6563
- return buffer;
6230
+ const out = {};
6231
+ for (const cell of tile.content) {
6232
+ let id5 = cell.id;
6233
+ const position = typeof getPosition === "function" ? getPosition(cell, {}) : getPosition;
6234
+ for (let i = 0; i < aggregationLevels - 1; i++) {
6235
+ if (scheme === "h3") {
6236
+ const currentResolution = (0, import_h3_js.getResolution)(id5);
6237
+ id5 = (0, import_h3_js.cellToParent)(id5, Math.max(0, currentResolution - 1));
6238
+ } else {
6239
+ id5 = cellToParent(id5);
6240
+ }
6241
+ }
6242
+ const parentId = String(id5);
6243
+ if (!(parentId in out)) {
6244
+ out[parentId] = { id: id5, count: 0, position: [0, 0] };
6245
+ for (const { name, aggregation } of properties) {
6246
+ if (aggregation === "any") {
6247
+ out[parentId][name] = cell.properties[name];
6248
+ } else {
6249
+ out[parentId][name] = 0;
6250
+ }
6251
+ }
6252
+ }
6253
+ const prevTotalW = out[parentId].count;
6254
+ out[parentId].count += typeof getWeight === "function" ? getWeight(cell, {}) : getWeight;
6255
+ const totalW = out[parentId].count;
6256
+ const W = totalW - prevTotalW;
6257
+ out[parentId].position[0] = (prevTotalW * out[parentId].position[0] + W * position[0]) / totalW;
6258
+ out[parentId].position[1] = (prevTotalW * out[parentId].position[1] + W * position[1]) / totalW;
6259
+ for (const { name, aggregation } of properties) {
6260
+ const prevValue = out[parentId][name];
6261
+ const value = cell.properties[name];
6262
+ if (aggregation === "average") {
6263
+ out[parentId][name] = (prevTotalW * prevValue + W * value) / totalW;
6264
+ } else if (aggregation === "count" || aggregation === "sum") {
6265
+ out[parentId][name] = prevValue + value;
6266
+ } else if (aggregation === "max") {
6267
+ out[parentId][name] = Math.max(prevValue, value);
6268
+ } else if (aggregation === "min") {
6269
+ out[parentId][name] = Math.min(prevValue, value);
6270
+ }
6564
6271
  }
6565
- return buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
6566
6272
  }
6567
- if (typeof data === "string") {
6568
- const text = data;
6569
- const uint8Array = new TextEncoder().encode(text);
6570
- return uint8Array.buffer;
6273
+ tileAggregationCache.set(aggregationLevels, Object.values(out));
6274
+ return true;
6275
+ }
6276
+ function extractAggregationProperties(tile) {
6277
+ const properties = [];
6278
+ const validAggregations = ["any", "average", "count", "min", "max", "sum"];
6279
+ for (const name of Object.keys(tile.content[0].properties)) {
6280
+ let aggregation = name.split("_").pop().toLowerCase();
6281
+ if (!validAggregations.includes(aggregation)) {
6282
+ import_core2.log.warn(`No valid aggregation present in ${name} property`)();
6283
+ aggregation = "any";
6284
+ }
6285
+ properties.push({ name, aggregation });
6571
6286
  }
6572
- if (data && typeof data === "object" && data._toArrayBuffer) {
6573
- return data._toArrayBuffer();
6287
+ return properties;
6288
+ }
6289
+ function computeAggregationStats(data, properties) {
6290
+ const stats = {};
6291
+ for (const { name, aggregation } of properties) {
6292
+ stats[name] = { min: Infinity, max: -Infinity };
6293
+ if (aggregation !== "any") {
6294
+ for (const d of data) {
6295
+ stats[name].min = Math.min(stats[name].min, d[name]);
6296
+ stats[name].max = Math.max(stats[name].max, d[name]);
6297
+ }
6298
+ }
6574
6299
  }
6575
- throw new Error("toArrayBuffer");
6300
+ return stats;
6576
6301
  }
6577
- function copyToArrayBuffer2(buffer, byteOffset = 0, byteLength = buffer.byteLength - byteOffset) {
6578
- const view = new Uint8Array(buffer, byteOffset, byteLength);
6579
- const copy3 = new Uint8Array(view.length);
6580
- copy3.set(view);
6581
- return copy3.buffer;
6302
+ function clustersToBinary(data) {
6303
+ const positions = new Float32Array(data.length * 2);
6304
+ const featureIds = new Uint16Array(data.length);
6305
+ for (let i = 0; i < data.length; i++) {
6306
+ positions.set(data[i].position, 2 * i);
6307
+ featureIds[i] = i;
6308
+ }
6309
+ return {
6310
+ ...createEmptyBinary(),
6311
+ points: createBinaryPointFeature(positions, featureIds, featureIds, {}, data)
6312
+ };
6582
6313
  }
6583
6314
 
6584
- // ../../node_modules/@loaders.gl/loader-utils/dist/lib/node/promisify.js
6585
- function promisify1(fn) {
6586
- return (args) => new Promise((resolve, reject) => fn(args, (error, callbackArgs) => error ? reject(error) : resolve(callbackArgs)));
6587
- }
6315
+ // src/constants.ts
6316
+ var DEFAULT_TILE_SIZE = 512;
6588
6317
 
6589
- // ../../node_modules/@loaders.gl/compression/dist/lib/compression.js
6590
- var Compression = class {
6591
- constructor(options) {
6592
- this.compressBatches = this.compressBatches.bind(this);
6593
- this.decompressBatches = this.decompressBatches.bind(this);
6594
- }
6595
- /** Preloads any dynamic libraries. May enable sync functions */
6596
- async preload(modules = {}) {
6597
- registerJSModules(modules);
6598
- return;
6599
- }
6600
- /** Asynchronously compress data */
6601
- async compress(input) {
6602
- await this.preload();
6603
- return this.compressSync(input);
6604
- }
6605
- /** Asynchronously decompress data */
6606
- async decompress(input, size) {
6607
- await this.preload();
6608
- return this.decompressSync(input, size);
6609
- }
6610
- /** Synchronously compress data */
6611
- compressSync(input) {
6612
- throw new Error(`${this.name}: sync compression not supported`);
6613
- }
6614
- /** Synchronously compress data */
6615
- decompressSync(input, size) {
6616
- throw new Error(`${this.name}: sync decompression not supported`);
6318
+ // src/layers/quadbin-tileset-2d.ts
6319
+ var import_geo_layers = __toESM(require_geo_layers(), 1);
6320
+ var QuadbinTileset2D = class extends import_geo_layers._Tileset2D {
6321
+ // @ts-expect-error for spatial indices, TileSet2d should be parametrized by TileIndexT
6322
+ getTileIndices(opts) {
6323
+ return super.getTileIndices(opts).map(tileToCell).map((q) => ({ q, i: bigIntToHex(q) }));
6617
6324
  }
6618
- /** Compress batches */
6619
- async *compressBatches(asyncIterator) {
6620
- const input = await this.concatenate(asyncIterator);
6621
- yield this.compress(input);
6325
+ // @ts-expect-error TileIndex must be generic
6326
+ getTileId({ q, i }) {
6327
+ return i || bigIntToHex(q);
6622
6328
  }
6623
- /** Decompress batches */
6624
- async *decompressBatches(asyncIterator) {
6625
- const input = await this.concatenate(asyncIterator);
6626
- yield this.decompress(input);
6329
+ // @ts-expect-error TileIndex must be generic
6330
+ getTileMetadata({ q }) {
6331
+ return super.getTileMetadata(cellToTile(q));
6627
6332
  }
6628
- // HELPERS
6629
- concatenate(asyncIterator) {
6630
- return concatenateArrayBuffersAsync(asyncIterator);
6333
+ // @ts-expect-error TileIndex must be generic
6334
+ getTileZoom({ q }) {
6335
+ return Number(getResolution(q));
6631
6336
  }
6632
- improveError(error) {
6633
- if (!error.message.includes(this.name)) {
6634
- error.message = `${this.name} ${error.message}`;
6635
- }
6636
- return error;
6337
+ // @ts-expect-error TileIndex must be generic
6338
+ getParentIndex({ q }) {
6339
+ return { q: cellToParent(q) };
6637
6340
  }
6638
6341
  };
6639
6342
 
6640
- // ../../node_modules/@loaders.gl/compression/dist/lib/deflate-compression.js
6641
- var import_pako = __toESM(require_pako(), 1);
6642
- var import_zlib = __toESM(require_zlib(), 1);
6643
- var DeflateCompression = class extends Compression {
6644
- name = "deflate";
6645
- extensions = [];
6646
- contentEncodings = ["deflate"];
6647
- isSupported = true;
6648
- options;
6649
- _chunks = [];
6650
- constructor(options = {}) {
6651
- super(options);
6652
- this.options = options;
6653
- }
6654
- async compress(input) {
6655
- if (!isBrowser && this.options.deflate?.useZlib) {
6656
- const buffer = this.options.deflate?.gzip ? await promisify1(import_zlib.default.gzip)(input) : await promisify1(import_zlib.default.deflate)(input);
6657
- return toArrayBuffer2(buffer);
6658
- }
6659
- return this.compressSync(input);
6660
- }
6661
- async decompress(input) {
6662
- if (!isBrowser && this.options.deflate?.useZlib) {
6663
- const buffer = this.options.deflate?.gzip ? await promisify1(import_zlib.default.gunzip)(input) : await promisify1(import_zlib.default.inflate)(input);
6664
- return toArrayBuffer2(buffer);
6343
+ // src/layers/h3-tileset-2d.ts
6344
+ var import_geo_layers2 = __toESM(require_geo_layers(), 1);
6345
+ var import_h3_js2 = __toESM(require_h3_js(), 1);
6346
+ var MAX_LATITUDE2 = 85.051128;
6347
+ function padBoundingBox({ west, north, east, south }, resolution, scale = 1) {
6348
+ const corners = [
6349
+ [north, east],
6350
+ [south, east],
6351
+ [south, west],
6352
+ [north, west]
6353
+ ];
6354
+ const cornerCells = corners.map((c) => (0, import_h3_js2.latLngToCell)(c[0], c[1], resolution));
6355
+ const cornerEdgeLengths = cornerCells.map(
6356
+ (c) => Math.max(...(0, import_h3_js2.originToDirectedEdges)(c).map((e) => (0, import_h3_js2.edgeLength)(e, import_h3_js2.UNITS.rads))) * 180 / Math.PI
6357
+ );
6358
+ const bufferLat = Math.max(...cornerEdgeLengths) * scale;
6359
+ const bufferLon = Math.min(180, bufferLat / Math.cos((north + south) / 2 * Math.PI / 180));
6360
+ return {
6361
+ north: Math.min(north + bufferLat, MAX_LATITUDE2),
6362
+ east: east + bufferLon,
6363
+ south: Math.max(south - bufferLat, -MAX_LATITUDE2),
6364
+ west: west - bufferLon
6365
+ };
6366
+ }
6367
+ function getHexagonsInBoundingBox({ west, north, east, south }, resolution) {
6368
+ const longitudeSpan = Math.abs(east - west);
6369
+ if (longitudeSpan > 180) {
6370
+ const nSegments = Math.ceil(longitudeSpan / 180);
6371
+ let h3Indices = [];
6372
+ for (let s = 0; s < nSegments; s++) {
6373
+ const segmentWest = west + s * 180;
6374
+ const segmentEast = Math.min(segmentWest + 179.9999999, east);
6375
+ h3Indices = h3Indices.concat(
6376
+ getHexagonsInBoundingBox({ west: segmentWest, north, east: segmentEast, south }, resolution)
6377
+ );
6665
6378
  }
6666
- return this.decompressSync(input);
6379
+ return [...new Set(h3Indices)];
6667
6380
  }
6668
- compressSync(input) {
6669
- if (!isBrowser && this.options.deflate?.useZlib) {
6670
- const buffer = this.options.deflate?.gzip ? import_zlib.default.gzipSync(input) : import_zlib.default.deflateSync(input);
6671
- return toArrayBuffer2(buffer);
6381
+ const polygon2 = [
6382
+ [north, east],
6383
+ [south, east],
6384
+ [south, west],
6385
+ [north, west],
6386
+ [north, east]
6387
+ ];
6388
+ return (0, import_h3_js2.polygonToCells)(polygon2, resolution);
6389
+ }
6390
+ function tileToBoundingBox(index2) {
6391
+ const coordinates = (0, import_h3_js2.cellToBoundary)(index2);
6392
+ const latitudes = coordinates.map((c) => c[0]);
6393
+ const longitudes = coordinates.map((c) => c[1]);
6394
+ const west = Math.min(...longitudes);
6395
+ const south = Math.min(...latitudes);
6396
+ const east = Math.max(...longitudes);
6397
+ const north = Math.max(...latitudes);
6398
+ const bbox2 = { west, south, east, north };
6399
+ return padBoundingBox(bbox2, (0, import_h3_js2.getResolution)(index2), 0.12);
6400
+ }
6401
+ var BIAS = 2;
6402
+ function getHexagonResolution(viewport, tileSize) {
6403
+ const zoomOffset = Math.log2(tileSize / 512);
6404
+ const hexagonScaleFactor = 2 / 3 * (viewport.zoom - zoomOffset);
6405
+ const latitudeScaleFactor = Math.log(1 / Math.cos(Math.PI * viewport.latitude / 180));
6406
+ return Math.max(0, Math.floor(hexagonScaleFactor + latitudeScaleFactor - BIAS));
6407
+ }
6408
+ var H3Tileset2D = class extends import_geo_layers2._Tileset2D {
6409
+ /**
6410
+ * Returns all tile indices in the current viewport. If the current zoom level is smaller
6411
+ * than minZoom, return an empty array. If the current zoom level is greater than maxZoom,
6412
+ * return tiles that are on maxZoom.
6413
+ */
6414
+ // @ts-expect-error Tileset2D should be generic over TileIndex
6415
+ getTileIndices({ viewport, minZoom, maxZoom }) {
6416
+ if (viewport.latitude === void 0)
6417
+ return [];
6418
+ const [west, south, east, north] = viewport.getBounds();
6419
+ const { tileSize } = this.opts;
6420
+ let z = getHexagonResolution(viewport, tileSize);
6421
+ let indices;
6422
+ if (typeof minZoom === "number" && Number.isFinite(minZoom) && z < minZoom) {
6423
+ return [];
6672
6424
  }
6673
- const pakoOptions = this.options?.deflate || {};
6674
- const inputArray = new Uint8Array(input);
6675
- const deflate = this.options?.raw ? import_pako.default.deflateRaw : import_pako.default.deflate;
6676
- return toArrayBuffer2(deflate(inputArray, pakoOptions).buffer);
6677
- }
6678
- decompressSync(input) {
6679
- if (!isBrowser && this.options.deflate?.useZlib) {
6680
- const buffer = this.options.deflate?.gzip ? import_zlib.default.gunzipSync(input) : import_zlib.default.inflateSync(input);
6681
- return toArrayBuffer2(buffer);
6425
+ if (typeof maxZoom === "number" && Number.isFinite(maxZoom) && z > maxZoom) {
6426
+ z = maxZoom;
6427
+ const center = (0, import_h3_js2.latLngToCell)(viewport.latitude, viewport.longitude, maxZoom);
6428
+ indices = (0, import_h3_js2.gridDisk)(center, 1);
6429
+ } else {
6430
+ const paddedBounds = padBoundingBox({ west, north, east, south }, z);
6431
+ indices = getHexagonsInBoundingBox(paddedBounds, z);
6682
6432
  }
6683
- const pakoOptions = this.options?.deflate || {};
6684
- const inputArray = new Uint8Array(input);
6685
- const inflate = this.options?.raw ? import_pako.default.inflateRaw : import_pako.default.inflate;
6686
- return toArrayBuffer2(inflate(inputArray, pakoOptions).buffer);
6687
- }
6688
- async *compressBatches(asyncIterator) {
6689
- const pakoOptions = this.options?.deflate || {};
6690
- const pakoProcessor = new import_pako.default.Deflate(pakoOptions);
6691
- yield* this.transformBatches(pakoProcessor, asyncIterator);
6692
- }
6693
- async *decompressBatches(asyncIterator) {
6694
- const pakoOptions = this.options?.deflate || {};
6695
- const pakoProcessor = new import_pako.default.Inflate(pakoOptions);
6696
- yield* this.transformBatches(pakoProcessor, asyncIterator);
6433
+ return indices.map((i) => ({ i }));
6697
6434
  }
6698
- async *transformBatches(pakoProcessor, asyncIterator) {
6699
- pakoProcessor.onData = this._onData.bind(this);
6700
- pakoProcessor.onEnd = this._onEnd.bind(this);
6701
- for await (const chunk of asyncIterator) {
6702
- const uint8Array = new Uint8Array(chunk);
6703
- const ok2 = pakoProcessor.push(uint8Array, false);
6704
- if (!ok2) {
6705
- throw new Error(`${this._getError()}write`);
6706
- }
6707
- const chunks2 = this._getChunks();
6708
- yield* chunks2;
6709
- }
6710
- const emptyChunk = new Uint8Array(0);
6711
- const ok = pakoProcessor.push(emptyChunk, true);
6712
- if (!ok) {
6713
- }
6714
- const chunks = this._getChunks();
6715
- yield* chunks;
6435
+ // @ts-expect-error Tileset2D should be generic over TileIndex
6436
+ getTileId({ i }) {
6437
+ return i;
6716
6438
  }
6717
- _onData(chunk) {
6718
- this._chunks.push(chunk);
6439
+ // @ts-expect-error Tileset2D should be generic over TileIndex
6440
+ getTileMetadata({ i }) {
6441
+ return { bbox: tileToBoundingBox(i) };
6719
6442
  }
6720
- _onEnd(status) {
6721
- if (status !== 0) {
6722
- throw new Error(this._getError(status) + this._chunks.length);
6723
- }
6443
+ // @ts-expect-error Tileset2D should be generic over TileIndex
6444
+ getTileZoom({ i }) {
6445
+ return (0, import_h3_js2.getResolution)(i);
6724
6446
  }
6725
- _getChunks() {
6726
- const chunks = this._chunks;
6727
- this._chunks = [];
6728
- return chunks;
6729
- }
6730
- // TODO - For some reason we don't get the error message from pako in _onEnd?
6731
- _getError(code = 0) {
6732
- const MESSAGES = {
6733
- /* Z_NEED_DICT 2 */
6734
- 2: "need dictionary",
6735
- /* Z_STREAM_END 1 */
6736
- 1: "stream end",
6737
- /* Z_OK 0 */
6738
- 0: "",
6739
- /* Z_ERRNO (-1) */
6740
- "-1": "file error",
6741
- /* Z_STREAM_ERROR (-2) */
6742
- "-2": "stream error",
6743
- /* Z_DATA_ERROR (-3) */
6744
- "-3": "data error",
6745
- /* Z_MEM_ERROR (-4) */
6746
- "-4": "insufficient memory",
6747
- /* Z_BUF_ERROR (-5) */
6748
- "-5": "buffer error",
6749
- /* Z_VERSION_ERROR (-6) */
6750
- "-6": "incompatible version"
6751
- };
6752
- return `${this.name}: ${MESSAGES[code]}`;
6447
+ // @ts-expect-error Tileset2D should be generic over TileIndex
6448
+ getParentIndex(index2) {
6449
+ const resolution = (0, import_h3_js2.getResolution)(index2.i);
6450
+ const i = (0, import_h3_js2.cellToParent)(index2.i, resolution - 1);
6451
+ return { i };
6753
6452
  }
6754
6453
  };
6755
6454
 
6756
- // ../../node_modules/@loaders.gl/compression/dist/lib/gzip-compression.js
6757
- var GZipCompression = class extends DeflateCompression {
6758
- name = "gzip";
6759
- extensions = ["gz", "gzip"];
6760
- contentEncodings = ["gzip", "x-gzip"];
6761
- isSupported = true;
6762
- constructor(options) {
6763
- super({ ...options, deflate: { ...options?.gzip, gzip: true } });
6764
- }
6455
+ // src/layers/quadbin-utils.ts
6456
+ var TILE_SIZE3 = 512;
6457
+ function quadbinToOffset(quadbin) {
6458
+ const { x, y, z } = cellToTile(quadbin);
6459
+ const scale = TILE_SIZE3 / (1 << z);
6460
+ return [x * scale, TILE_SIZE3 - y * scale, scale];
6461
+ }
6462
+ function quadbinToWorldBounds(quadbin, coverage) {
6463
+ const [xOffset, yOffset, scale] = quadbinToOffset(quadbin);
6464
+ return [
6465
+ [xOffset, yOffset],
6466
+ [xOffset + coverage * scale, yOffset - coverage * scale]
6467
+ ];
6468
+ }
6469
+ function getQuadbinPolygon(quadbin, coverage = 1) {
6470
+ const [topLeft, bottomRight] = quadbinToWorldBounds(quadbin, coverage);
6471
+ const [w, n] = worldToLngLat(topLeft);
6472
+ const [e, s] = worldToLngLat(bottomRight);
6473
+ return [e, n, e, s, w, s, w, n, e, n];
6474
+ }
6475
+
6476
+ // src/layers/cluster-tile-layer.ts
6477
+ var import_h3_js3 = __toESM(require_h3_js(), 1);
6478
+
6479
+ // ../../node_modules/@loaders.gl/loader-utils/dist/lib/env-utils/globals.js
6480
+ var globals = {
6481
+ self: typeof self !== "undefined" && self,
6482
+ window: typeof window !== "undefined" && window,
6483
+ global: typeof global !== "undefined" && global,
6484
+ document: typeof document !== "undefined" && document
6765
6485
  };
6486
+ var self_ = globals.self || globals.window || globals.global || {};
6487
+ var window_ = globals.window || globals.self || globals.global || {};
6488
+ var global_ = globals.global || globals.self || globals.window || {};
6489
+ var document_ = globals.document || {};
6490
+ var isBrowser = (
6491
+ // @ts-ignore process does not exist on browser
6492
+ Boolean(typeof process !== "object" || String(process) !== "[object process]" || process.browser)
6493
+ );
6494
+ var matches = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
6495
+ var nodeVersion = matches && parseFloat(matches[1]) || 0;
6766
6496
 
6767
- // src/layers/schema/fast-pbf.ts
6768
- function readPackedTypedArray(TypedArray, pbf, obj, options) {
6769
- const end = pbf.type === 2 ? pbf.readVarint() + pbf.pos : pbf.pos + 1;
6770
- const data = pbf.buf.buffer.slice(pbf.pos, end);
6771
- if (options?.compression === "gzip") {
6772
- const compression = new GZipCompression();
6773
- const decompressedData = compression.decompressSync(data);
6774
- obj.value = new TypedArray(decompressedData);
6775
- } else {
6776
- obj.value = new TypedArray(data);
6497
+ // ../../node_modules/@loaders.gl/loader-utils/dist/lib/javascript-utils/is-type.js
6498
+ var isSharedArrayBuffer = (value) => typeof SharedArrayBuffer !== "undefined" && value instanceof SharedArrayBuffer;
6499
+
6500
+ // ../../node_modules/@loaders.gl/loader-utils/dist/lib/module-utils/js-module-utils.js
6501
+ function registerJSModules(modules) {
6502
+ globalThis.loaders ||= {};
6503
+ globalThis.loaders.modules ||= {};
6504
+ Object.assign(globalThis.loaders.modules, modules);
6505
+ }
6506
+
6507
+ // ../../node_modules/@loaders.gl/loader-utils/dist/lib/binary-utils/array-buffer-utils.js
6508
+ function concatenateArrayBuffers(...sources) {
6509
+ return concatenateArrayBuffersFromArray(sources);
6510
+ }
6511
+ function concatenateArrayBuffersFromArray(sources) {
6512
+ const sourceArrays = sources.map((source2) => source2 instanceof ArrayBuffer ? new Uint8Array(source2) : source2);
6513
+ const byteLength = sourceArrays.reduce((length2, typedArray) => length2 + typedArray.byteLength, 0);
6514
+ const result = new Uint8Array(byteLength);
6515
+ let offset = 0;
6516
+ for (const sourceArray of sourceArrays) {
6517
+ result.set(sourceArray, offset);
6518
+ offset += sourceArray.byteLength;
6777
6519
  }
6778
- pbf.pos = end;
6779
- return obj.value;
6520
+ return result.buffer;
6780
6521
  }
6781
6522
 
6782
- // src/layers/schema/carto-tile.ts
6783
- var KeyValueObjectReader = class {
6784
- static read(pbf, end) {
6785
- return pbf.readFields(KeyValueObjectReader._readField, { key: "", value: null }, end);
6523
+ // ../../node_modules/@loaders.gl/loader-utils/dist/lib/iterators/async-iteration.js
6524
+ async function concatenateArrayBuffersAsync(asyncIterator) {
6525
+ const arrayBuffers = [];
6526
+ for await (const chunk of asyncIterator) {
6527
+ arrayBuffers.push(copyToArrayBuffer(chunk));
6786
6528
  }
6787
- static _readField(tag, obj, pbf) {
6788
- if (tag === 1)
6789
- obj.key = pbf.readString();
6790
- else if (tag === 2)
6791
- obj.value = pbf.readString();
6529
+ return concatenateArrayBuffers(...arrayBuffers);
6530
+ }
6531
+ function copyToArrayBuffer(chunk) {
6532
+ if (chunk instanceof ArrayBuffer) {
6533
+ return chunk;
6792
6534
  }
6793
- };
6794
- var PropertiesReader = class {
6795
- static read(pbf, end) {
6796
- return pbf.readFields(PropertiesReader._readField, {}, end);
6535
+ if (ArrayBuffer.isView(chunk)) {
6536
+ const { buffer, byteOffset, byteLength } = chunk;
6537
+ return copyFromBuffer(buffer, byteOffset, byteLength);
6797
6538
  }
6798
- static _readField(tag, obj, pbf) {
6799
- if (tag === 1) {
6800
- const { key, value } = KeyValueObjectReader.read(pbf, pbf.readVarint() + pbf.pos);
6801
- obj[key] = value;
6802
- }
6539
+ return copyFromBuffer(chunk);
6540
+ }
6541
+ function copyFromBuffer(buffer, byteOffset = 0, byteLength = buffer.byteLength - byteOffset) {
6542
+ const view = new Uint8Array(buffer, byteOffset, byteLength);
6543
+ const copy3 = new Uint8Array(view.length);
6544
+ copy3.set(view);
6545
+ return copy3.buffer;
6546
+ }
6547
+
6548
+ // ../../node_modules/@loaders.gl/loader-utils/dist/lib/node/buffer.browser.js
6549
+ function toArrayBuffer(buffer) {
6550
+ return buffer;
6551
+ }
6552
+
6553
+ // ../../node_modules/@loaders.gl/loader-utils/dist/lib/binary-utils/memory-conversion-utils.js
6554
+ function isBuffer(value) {
6555
+ return value && typeof value === "object" && value.isBuffer;
6556
+ }
6557
+ function toArrayBuffer2(data) {
6558
+ if (isBuffer(data)) {
6559
+ return toArrayBuffer(data);
6803
6560
  }
6804
- };
6805
- var DoublesReader = class {
6806
- static read(pbf, end) {
6807
- const { value, size } = pbf.readFields(DoublesReader._readField, { value: [], size: 0 }, end);
6808
- return { value, size };
6561
+ if (data instanceof ArrayBuffer) {
6562
+ return data;
6809
6563
  }
6810
- static _readField(tag, obj, pbf) {
6811
- if (tag === 1)
6812
- readPackedTypedArray(Float64Array, pbf, obj);
6813
- else if (tag === 2)
6814
- obj.size = pbf.readVarint(true);
6564
+ if (isSharedArrayBuffer(data)) {
6565
+ return copyToArrayBuffer2(data);
6815
6566
  }
6816
- };
6817
- var IntsReader = class {
6818
- static read(pbf, end) {
6819
- const { value, size } = pbf.readFields(IntsReader._readField, { value: [], size: 0 }, end);
6820
- return { value: new Uint32Array(value), size };
6567
+ if (ArrayBuffer.isView(data)) {
6568
+ const buffer = data.buffer;
6569
+ if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) {
6570
+ return buffer;
6571
+ }
6572
+ return buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
6821
6573
  }
6822
- static _readField(tag, obj, pbf) {
6823
- if (tag === 1)
6824
- pbf.readPackedVarint(obj.value);
6825
- else if (tag === 2)
6826
- obj.size = pbf.readVarint(true);
6574
+ if (typeof data === "string") {
6575
+ const text = data;
6576
+ const uint8Array = new TextEncoder().encode(text);
6577
+ return uint8Array.buffer;
6827
6578
  }
6828
- };
6829
- var FieldsReader = class {
6830
- static read(pbf, end) {
6831
- return pbf.readFields(FieldsReader._readField, { id: 0 }, end);
6579
+ if (data && typeof data === "object" && data._toArrayBuffer) {
6580
+ return data._toArrayBuffer();
6832
6581
  }
6833
- static _readField(tag, obj, pbf) {
6834
- if (tag === 1)
6835
- obj.id = pbf.readVarint();
6582
+ throw new Error("toArrayBuffer");
6583
+ }
6584
+ function copyToArrayBuffer2(buffer, byteOffset = 0, byteLength = buffer.byteLength - byteOffset) {
6585
+ const view = new Uint8Array(buffer, byteOffset, byteLength);
6586
+ const copy3 = new Uint8Array(view.length);
6587
+ copy3.set(view);
6588
+ return copy3.buffer;
6589
+ }
6590
+
6591
+ // ../../node_modules/@loaders.gl/loader-utils/dist/lib/node/promisify.js
6592
+ function promisify1(fn) {
6593
+ return (args) => new Promise((resolve, reject) => fn(args, (error, callbackArgs) => error ? reject(error) : resolve(callbackArgs)));
6594
+ }
6595
+
6596
+ // ../../node_modules/@loaders.gl/compression/dist/lib/compression.js
6597
+ var Compression = class {
6598
+ constructor(options) {
6599
+ this.compressBatches = this.compressBatches.bind(this);
6600
+ this.decompressBatches = this.decompressBatches.bind(this);
6836
6601
  }
6837
- };
6838
- var NumericPropReader = class {
6839
- static read(pbf, end) {
6840
- return pbf.readFields(NumericPropReader._readField, { value: [] }, end);
6602
+ /** Preloads any dynamic libraries. May enable sync functions */
6603
+ async preload(modules = {}) {
6604
+ registerJSModules(modules);
6605
+ return;
6841
6606
  }
6842
- static _readField(tag, obj, pbf) {
6843
- if (tag === 1)
6844
- readPackedTypedArray(Float64Array, pbf, obj);
6607
+ /** Asynchronously compress data */
6608
+ async compress(input) {
6609
+ await this.preload();
6610
+ return this.compressSync(input);
6845
6611
  }
6846
- };
6847
- var NumericPropKeyValueReader = class {
6848
- static read(pbf, end) {
6849
- return pbf.readFields(NumericPropKeyValueReader._readField, { key: "", value: null }, end);
6612
+ /** Asynchronously decompress data */
6613
+ async decompress(input, size) {
6614
+ await this.preload();
6615
+ return this.decompressSync(input, size);
6850
6616
  }
6851
- static _readField(tag, obj, pbf) {
6852
- if (tag === 1)
6853
- obj.key = pbf.readString();
6854
- else if (tag === 2)
6855
- obj.value = NumericPropReader.read(pbf, pbf.readVarint() + pbf.pos);
6617
+ /** Synchronously compress data */
6618
+ compressSync(input) {
6619
+ throw new Error(`${this.name}: sync compression not supported`);
6856
6620
  }
6857
- };
6858
- var PointsReader = class {
6859
- static read(pbf, end) {
6860
- return pbf.readFields(
6861
- PointsReader._readField,
6862
- {
6863
- positions: null,
6864
- globalFeatureIds: null,
6865
- featureIds: null,
6866
- properties: [],
6867
- numericProps: {},
6868
- fields: []
6869
- },
6870
- end
6871
- );
6621
+ /** Synchronously compress data */
6622
+ decompressSync(input, size) {
6623
+ throw new Error(`${this.name}: sync decompression not supported`);
6624
+ }
6625
+ /** Compress batches */
6626
+ async *compressBatches(asyncIterator) {
6627
+ const input = await this.concatenate(asyncIterator);
6628
+ yield this.compress(input);
6629
+ }
6630
+ /** Decompress batches */
6631
+ async *decompressBatches(asyncIterator) {
6632
+ const input = await this.concatenate(asyncIterator);
6633
+ yield this.decompress(input);
6634
+ }
6635
+ // HELPERS
6636
+ concatenate(asyncIterator) {
6637
+ return concatenateArrayBuffersAsync(asyncIterator);
6638
+ }
6639
+ improveError(error) {
6640
+ if (!error.message.includes(this.name)) {
6641
+ error.message = `${this.name} ${error.message}`;
6642
+ }
6643
+ return error;
6644
+ }
6645
+ };
6646
+
6647
+ // ../../node_modules/@loaders.gl/compression/dist/lib/deflate-compression.js
6648
+ var import_pako = __toESM(require_pako(), 1);
6649
+ var import_zlib = __toESM(require_zlib(), 1);
6650
+ var DeflateCompression = class extends Compression {
6651
+ name = "deflate";
6652
+ extensions = [];
6653
+ contentEncodings = ["deflate"];
6654
+ isSupported = true;
6655
+ options;
6656
+ _chunks = [];
6657
+ constructor(options = {}) {
6658
+ super(options);
6659
+ this.options = options;
6660
+ }
6661
+ async compress(input) {
6662
+ if (!isBrowser && this.options.deflate?.useZlib) {
6663
+ const buffer = this.options.deflate?.gzip ? await promisify1(import_zlib.default.gzip)(input) : await promisify1(import_zlib.default.deflate)(input);
6664
+ return toArrayBuffer2(buffer);
6665
+ }
6666
+ return this.compressSync(input);
6667
+ }
6668
+ async decompress(input) {
6669
+ if (!isBrowser && this.options.deflate?.useZlib) {
6670
+ const buffer = this.options.deflate?.gzip ? await promisify1(import_zlib.default.gunzip)(input) : await promisify1(import_zlib.default.inflate)(input);
6671
+ return toArrayBuffer2(buffer);
6672
+ }
6673
+ return this.decompressSync(input);
6674
+ }
6675
+ compressSync(input) {
6676
+ if (!isBrowser && this.options.deflate?.useZlib) {
6677
+ const buffer = this.options.deflate?.gzip ? import_zlib.default.gzipSync(input) : import_zlib.default.deflateSync(input);
6678
+ return toArrayBuffer2(buffer);
6679
+ }
6680
+ const pakoOptions = this.options?.deflate || {};
6681
+ const inputArray = new Uint8Array(input);
6682
+ const deflate = this.options?.raw ? import_pako.default.deflateRaw : import_pako.default.deflate;
6683
+ return toArrayBuffer2(deflate(inputArray, pakoOptions).buffer);
6684
+ }
6685
+ decompressSync(input) {
6686
+ if (!isBrowser && this.options.deflate?.useZlib) {
6687
+ const buffer = this.options.deflate?.gzip ? import_zlib.default.gunzipSync(input) : import_zlib.default.inflateSync(input);
6688
+ return toArrayBuffer2(buffer);
6689
+ }
6690
+ const pakoOptions = this.options?.deflate || {};
6691
+ const inputArray = new Uint8Array(input);
6692
+ const inflate = this.options?.raw ? import_pako.default.inflateRaw : import_pako.default.inflate;
6693
+ return toArrayBuffer2(inflate(inputArray, pakoOptions).buffer);
6694
+ }
6695
+ async *compressBatches(asyncIterator) {
6696
+ const pakoOptions = this.options?.deflate || {};
6697
+ const pakoProcessor = new import_pako.default.Deflate(pakoOptions);
6698
+ yield* this.transformBatches(pakoProcessor, asyncIterator);
6699
+ }
6700
+ async *decompressBatches(asyncIterator) {
6701
+ const pakoOptions = this.options?.deflate || {};
6702
+ const pakoProcessor = new import_pako.default.Inflate(pakoOptions);
6703
+ yield* this.transformBatches(pakoProcessor, asyncIterator);
6704
+ }
6705
+ async *transformBatches(pakoProcessor, asyncIterator) {
6706
+ pakoProcessor.onData = this._onData.bind(this);
6707
+ pakoProcessor.onEnd = this._onEnd.bind(this);
6708
+ for await (const chunk of asyncIterator) {
6709
+ const uint8Array = new Uint8Array(chunk);
6710
+ const ok2 = pakoProcessor.push(uint8Array, false);
6711
+ if (!ok2) {
6712
+ throw new Error(`${this._getError()}write`);
6713
+ }
6714
+ const chunks2 = this._getChunks();
6715
+ yield* chunks2;
6716
+ }
6717
+ const emptyChunk = new Uint8Array(0);
6718
+ const ok = pakoProcessor.push(emptyChunk, true);
6719
+ if (!ok) {
6720
+ }
6721
+ const chunks = this._getChunks();
6722
+ yield* chunks;
6723
+ }
6724
+ _onData(chunk) {
6725
+ this._chunks.push(chunk);
6726
+ }
6727
+ _onEnd(status) {
6728
+ if (status !== 0) {
6729
+ throw new Error(this._getError(status) + this._chunks.length);
6730
+ }
6731
+ }
6732
+ _getChunks() {
6733
+ const chunks = this._chunks;
6734
+ this._chunks = [];
6735
+ return chunks;
6736
+ }
6737
+ // TODO - For some reason we don't get the error message from pako in _onEnd?
6738
+ _getError(code = 0) {
6739
+ const MESSAGES = {
6740
+ /* Z_NEED_DICT 2 */
6741
+ 2: "need dictionary",
6742
+ /* Z_STREAM_END 1 */
6743
+ 1: "stream end",
6744
+ /* Z_OK 0 */
6745
+ 0: "",
6746
+ /* Z_ERRNO (-1) */
6747
+ "-1": "file error",
6748
+ /* Z_STREAM_ERROR (-2) */
6749
+ "-2": "stream error",
6750
+ /* Z_DATA_ERROR (-3) */
6751
+ "-3": "data error",
6752
+ /* Z_MEM_ERROR (-4) */
6753
+ "-4": "insufficient memory",
6754
+ /* Z_BUF_ERROR (-5) */
6755
+ "-5": "buffer error",
6756
+ /* Z_VERSION_ERROR (-6) */
6757
+ "-6": "incompatible version"
6758
+ };
6759
+ return `${this.name}: ${MESSAGES[code]}`;
6760
+ }
6761
+ };
6762
+
6763
+ // ../../node_modules/@loaders.gl/compression/dist/lib/gzip-compression.js
6764
+ var GZipCompression = class extends DeflateCompression {
6765
+ name = "gzip";
6766
+ extensions = ["gz", "gzip"];
6767
+ contentEncodings = ["gzip", "x-gzip"];
6768
+ isSupported = true;
6769
+ constructor(options) {
6770
+ super({ ...options, deflate: { ...options?.gzip, gzip: true } });
6771
+ }
6772
+ };
6773
+
6774
+ // src/layers/schema/fast-pbf.ts
6775
+ function readPackedTypedArray(TypedArray, pbf, obj, options) {
6776
+ const end = pbf.type === 2 ? pbf.readVarint() + pbf.pos : pbf.pos + 1;
6777
+ const data = pbf.buf.buffer.slice(pbf.pos, end);
6778
+ if (options?.compression === "gzip") {
6779
+ const compression = new GZipCompression();
6780
+ const decompressedData = compression.decompressSync(data);
6781
+ obj.value = new TypedArray(decompressedData);
6782
+ } else {
6783
+ obj.value = new TypedArray(data);
6784
+ }
6785
+ pbf.pos = end;
6786
+ return obj.value;
6787
+ }
6788
+
6789
+ // src/layers/schema/carto-tile.ts
6790
+ var KeyValueObjectReader = class {
6791
+ static read(pbf, end) {
6792
+ return pbf.readFields(KeyValueObjectReader._readField, { key: "", value: null }, end);
6793
+ }
6794
+ static _readField(tag, obj, pbf) {
6795
+ if (tag === 1)
6796
+ obj.key = pbf.readString();
6797
+ else if (tag === 2)
6798
+ obj.value = pbf.readString();
6799
+ }
6800
+ };
6801
+ var PropertiesReader = class {
6802
+ static read(pbf, end) {
6803
+ return pbf.readFields(PropertiesReader._readField, {}, end);
6804
+ }
6805
+ static _readField(tag, obj, pbf) {
6806
+ if (tag === 1) {
6807
+ const { key, value } = KeyValueObjectReader.read(pbf, pbf.readVarint() + pbf.pos);
6808
+ obj[key] = value;
6809
+ }
6810
+ }
6811
+ };
6812
+ var DoublesReader = class {
6813
+ static read(pbf, end) {
6814
+ const { value, size } = pbf.readFields(DoublesReader._readField, { value: [], size: 0 }, end);
6815
+ return { value, size };
6816
+ }
6817
+ static _readField(tag, obj, pbf) {
6818
+ if (tag === 1)
6819
+ readPackedTypedArray(Float64Array, pbf, obj);
6820
+ else if (tag === 2)
6821
+ obj.size = pbf.readVarint(true);
6822
+ }
6823
+ };
6824
+ var IntsReader = class {
6825
+ static read(pbf, end) {
6826
+ const { value, size } = pbf.readFields(IntsReader._readField, { value: [], size: 0 }, end);
6827
+ return { value: new Uint32Array(value), size };
6828
+ }
6829
+ static _readField(tag, obj, pbf) {
6830
+ if (tag === 1)
6831
+ pbf.readPackedVarint(obj.value);
6832
+ else if (tag === 2)
6833
+ obj.size = pbf.readVarint(true);
6834
+ }
6835
+ };
6836
+ var FieldsReader = class {
6837
+ static read(pbf, end) {
6838
+ return pbf.readFields(FieldsReader._readField, { id: 0 }, end);
6839
+ }
6840
+ static _readField(tag, obj, pbf) {
6841
+ if (tag === 1)
6842
+ obj.id = pbf.readVarint();
6843
+ }
6844
+ };
6845
+ var NumericPropReader = class {
6846
+ static read(pbf, end) {
6847
+ return pbf.readFields(NumericPropReader._readField, { value: [] }, end);
6848
+ }
6849
+ static _readField(tag, obj, pbf) {
6850
+ if (tag === 1)
6851
+ readPackedTypedArray(Float64Array, pbf, obj);
6852
+ }
6853
+ };
6854
+ var NumericPropKeyValueReader = class {
6855
+ static read(pbf, end) {
6856
+ return pbf.readFields(NumericPropKeyValueReader._readField, { key: "", value: null }, end);
6857
+ }
6858
+ static _readField(tag, obj, pbf) {
6859
+ if (tag === 1)
6860
+ obj.key = pbf.readString();
6861
+ else if (tag === 2)
6862
+ obj.value = NumericPropReader.read(pbf, pbf.readVarint() + pbf.pos);
6863
+ }
6864
+ };
6865
+ var PointsReader = class {
6866
+ static read(pbf, end) {
6867
+ return pbf.readFields(
6868
+ PointsReader._readField,
6869
+ {
6870
+ positions: null,
6871
+ globalFeatureIds: null,
6872
+ featureIds: null,
6873
+ properties: [],
6874
+ numericProps: {},
6875
+ fields: []
6876
+ },
6877
+ end
6878
+ );
6872
6879
  }
6873
6880
  static _readField(tag, obj, pbf) {
6874
6881
  if (tag === 1)
@@ -7953,8 +7960,8 @@ vec4 heatmap_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
7953
7960
  let maxDensity = 0;
7954
7961
  const loadedTiles = [...this.state.tiles].filter((t) => t.content);
7955
7962
  const visibleTiles = loadedTiles.filter((t) => t.isVisible);
7956
- const tiles3 = visibleTiles.length ? visibleTiles : loadedTiles;
7957
- for (const tile of tiles3) {
7963
+ const tiles2 = visibleTiles.length ? visibleTiles : loadedTiles;
7964
+ for (const tile of tiles2) {
7958
7965
  const cell = tile.content[0];
7959
7966
  const unitDensity = isH3 ? unitDensityForH3Cell(cell.id) : unitDensityForQuadbinCell(cell.id);
7960
7967
  maxDensity = Math.max(tile.userData.maxWeight * unitDensity, maxDensity);
@@ -7998,10 +8005,10 @@ vec4 heatmap_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
7998
8005
  getElevation: updateTriggers.getWeight
7999
8006
  },
8000
8007
  // Tile stats
8001
- onViewportLoad: (tiles4) => {
8008
+ onViewportLoad: (tiles3) => {
8002
8009
  this.setState({ isLoaded: true });
8003
8010
  if (typeof onViewportLoad === "function") {
8004
- onViewportLoad(tiles4);
8011
+ onViewportLoad(tiles3);
8005
8012
  }
8006
8013
  },
8007
8014
  onTileLoad: (tile) => {
@@ -8891,628 +8898,242 @@ void main(void) {
8891
8898
  function isPointInTriangle(p, v1, v2, v3) {
8892
8899
  const area = Math.abs((v2[0] - v1[0]) * (v3[1] - v1[1]) - (v3[0] - v1[0]) * (v2[1] - v1[1])) / 2;
8893
8900
  const area1 = Math.abs((v1[0] - p[0]) * (v2[1] - p[1]) - (v2[0] - p[0]) * (v1[1] - p[1])) / 2;
8894
- const area2 = Math.abs((v2[0] - p[0]) * (v3[1] - p[1]) - (v3[0] - p[0]) * (v2[1] - p[1])) / 2;
8895
- const area3 = Math.abs((v3[0] - p[0]) * (v1[1] - p[1]) - (v1[0] - p[0]) * (v3[1] - p[1])) / 2;
8896
- return Math.abs(area - (area1 + area2 + area3)) < 1e-10;
8897
- }
8898
- function getTriangleArea([x1, y1], [x2, y2], [x3, y3]) {
8899
- return Math.abs((x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2);
8900
- }
8901
- function getPolygonCentroid(polygons, index2) {
8902
- const {
8903
- positions: { value: positions, size }
8904
- } = polygons;
8905
- const startIndex = size * polygons.polygonIndices.value[index2];
8906
- const endIndex = size * polygons.polygonIndices.value[index2 + 1];
8907
- let minX = Infinity;
8908
- let minY = Infinity;
8909
- let maxX = -Infinity;
8910
- let maxY = -Infinity;
8911
- for (let i = startIndex; i < endIndex; i += size) {
8912
- const [x, y] = positions.subarray(i, i + 2);
8913
- minX = Math.min(minX, x);
8914
- minY = Math.min(minY, y);
8915
- maxX = Math.max(maxX, x);
8916
- maxY = Math.max(maxY, y);
8917
- }
8918
- return [(minX + maxX) / 2, (minY + maxY) / 2];
8919
- }
8920
- function getSegmentLength(lines, index2) {
8921
- const {
8922
- positions: { value }
8923
- } = lines;
8924
- const [x1, y1, x2, y2] = value.subarray(index2, index2 + 4);
8925
- return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
8926
- }
8927
- function getLineLength(lines, index2) {
8928
- const {
8929
- positions: { size }
8930
- } = lines;
8931
- const startIndex = size * lines.pathIndices.value[index2];
8932
- const endIndex = size * lines.pathIndices.value[index2 + 1];
8933
- let length2 = 0;
8934
- for (let j = startIndex; j < endIndex; j += size) {
8935
- length2 += getSegmentLength(lines, j);
8936
- }
8937
- return length2;
8938
- }
8939
- function getLineMidpoint(lines, index2) {
8940
- const {
8941
- positions: { value: positions },
8942
- pathIndices: { value: pathIndices }
8943
- } = lines;
8944
- const startIndex = pathIndices[index2] * 2;
8945
- const endIndex = pathIndices[index2 + 1] * 2;
8946
- const numPoints = (endIndex - startIndex) / 2;
8947
- if (numPoints === 2) {
8948
- const [x1, y1, x2, y2] = positions.subarray(startIndex, startIndex + 4);
8949
- return [(x1 + x2) / 2, (y1 + y2) / 2];
8950
- }
8951
- const midPointIndex = startIndex + Math.floor(numPoints / 2) * 2;
8952
- return [positions[midPointIndex], positions[midPointIndex + 1]];
8953
- }
8954
-
8955
- // src/layers/vector-tile-layer.ts
8956
- (0, import_core16.registerLoaders)([carto_properties_tile_loader_default, carto_vector_tile_loader_default]);
8957
- var MVT_BBOX = { west: 0, east: 1, south: 0, north: 1 };
8958
- var defaultProps10 = {
8959
- ...import_geo_layers8.MVTLayer.defaultProps,
8960
- autoLabels: false,
8961
- data: TilejsonPropType,
8962
- dataComparator: TilejsonPropType.equal,
8963
- tileSize: DEFAULT_TILE_SIZE
8964
- };
8965
- var VectorTileLayer = class extends import_geo_layers8.MVTLayer {
8966
- constructor(...propObjects) {
8967
- super(...propObjects);
8968
- }
8969
- initializeState() {
8970
- super.initializeState();
8971
- this.setState({ binary: true });
8972
- }
8973
- updateState(parameters) {
8974
- const { props } = parameters;
8975
- if (props.data) {
8976
- super.updateState(parameters);
8977
- const formatTiles = new URL(props.data.tiles[0]).searchParams.get("formatTiles");
8978
- const mvt = formatTiles === "mvt";
8979
- this.setState({ mvt });
8980
- }
8981
- }
8982
- getLoadOptions() {
8983
- const tileJSON = this.props.data;
8984
- return mergeLoadOptions(super.getLoadOptions(), {
8985
- fetch: { headers: { Authorization: `Bearer ${tileJSON.accessToken}` } },
8986
- gis: { format: "binary" }
8987
- // Use binary for MVT loading
8988
- });
8989
- }
8990
- /* eslint-disable camelcase */
8991
- async getTileData(tile) {
8992
- const tileJSON = this.props.data;
8993
- const { tiles: tiles3, properties_tiles } = tileJSON;
8994
- const url = (0, import_geo_layers8._getURLFromTemplate)(tiles3, tile);
8995
- if (!url) {
8996
- return Promise.reject("Invalid URL");
8997
- }
8998
- const loadOptions = this.getLoadOptions();
8999
- const { fetch: fetch2 } = this.props;
9000
- const { signal } = tile;
9001
- const geometryFetch = fetch2(url, { propName: "data", layer: this, loadOptions, signal });
9002
- if (!properties_tiles) {
9003
- return await geometryFetch;
9004
- }
9005
- const propertiesUrl = (0, import_geo_layers8._getURLFromTemplate)(properties_tiles, tile);
9006
- if (!propertiesUrl) {
9007
- return Promise.reject("Invalid properties URL");
9008
- }
9009
- const attributesFetch = fetch2(propertiesUrl, {
9010
- propName: "data",
9011
- layer: this,
9012
- loadOptions,
9013
- signal
9014
- });
9015
- const [geometry, attributes] = await Promise.all([geometryFetch, attributesFetch]);
9016
- if (!geometry)
9017
- return null;
9018
- return attributes ? mergeBoundaryData(geometry, attributes) : geometry;
9019
- }
9020
- /* eslint-enable camelcase */
9021
- renderSubLayers(props) {
9022
- if (props.data === null) {
9023
- return null;
9024
- }
9025
- const tileBbox = props.tile.bbox;
9026
- const subLayers = [];
9027
- const defaultToPointLabelLayer = {
9028
- "points-text": {
9029
- type: PointLabelLayer,
9030
- ...props?._subLayerProps?.["points-text"],
9031
- extensions: [
9032
- new import_extensions.CollisionFilterExtension(),
9033
- ...props.extensions || [],
9034
- ...props?._subLayerProps?.["points-text"]?.extensions || []
9035
- ]
9036
- }
9037
- };
9038
- if (this.state.mvt) {
9039
- const subLayerProps = {
9040
- ...props,
9041
- _subLayerProps: {
9042
- ...props._subLayerProps,
9043
- ...defaultToPointLabelLayer
9044
- }
9045
- };
9046
- subLayers.push(super.renderSubLayers(subLayerProps));
9047
- } else {
9048
- const { west, south, east, north } = tileBbox;
9049
- const extensions = [new import_extensions.ClipExtension(), ...props.extensions || []];
9050
- const clipProps = {
9051
- clipBounds: [west, south, east, north]
9052
- };
9053
- const applyClipExtensionToSublayerProps = (subLayerId) => {
9054
- return {
9055
- [subLayerId]: {
9056
- ...clipProps,
9057
- ...props?._subLayerProps?.[subLayerId],
9058
- extensions: [...extensions, ...props?._subLayerProps?.[subLayerId]?.extensions || []]
9059
- }
9060
- };
9061
- };
9062
- const subLayerProps = {
9063
- ...props,
9064
- data: { ...props.data, tileBbox },
9065
- autoHighlight: false,
9066
- // Do not perform clipping on points (#9059)
9067
- _subLayerProps: {
9068
- ...props._subLayerProps,
9069
- ...defaultToPointLabelLayer,
9070
- ...applyClipExtensionToSublayerProps("polygons-fill"),
9071
- ...applyClipExtensionToSublayerProps("polygons-stroke"),
9072
- ...applyClipExtensionToSublayerProps("linestrings")
9073
- }
9074
- };
9075
- subLayers.push(new import_layers5.GeoJsonLayer(subLayerProps));
9076
- }
9077
- if (subLayers[0] && props.autoLabels) {
9078
- const labelData = createEmptyBinary();
9079
- if (props.data.lines && props.data.lines.positions.value.length > 0) {
9080
- labelData.points = createPointsFromLines(
9081
- props.data.lines,
9082
- typeof props.autoLabels === "object" ? props.autoLabels.uniqueIdProperty : void 0
9083
- );
9084
- }
9085
- if (props.data.polygons && props.data.polygons.positions.value.length > 0) {
9086
- labelData.points = createPointsFromPolygons(
9087
- props.data.polygons,
9088
- this.state.mvt ? MVT_BBOX : tileBbox,
9089
- props
9090
- );
9091
- }
9092
- subLayers.push(
9093
- subLayers[0].clone({
9094
- id: `${props.id}-labels`,
9095
- data: labelData,
9096
- pickable: false,
9097
- autoHighlight: false
9098
- })
9099
- );
9100
- }
9101
- return subLayers;
9102
- }
9103
- renderLayers() {
9104
- const layers = super.renderLayers();
9105
- if (!this.props.autoLabels) {
9106
- return layers;
9107
- }
9108
- const validLayers = (layers || []).flat().filter(Boolean);
9109
- validLayers.sort((a, b) => {
9110
- const aHasLabel = a.id.includes("labels");
9111
- const bHasLabel = b.id.includes("labels");
9112
- if (aHasLabel && !bHasLabel)
9113
- return 1;
9114
- if (!aHasLabel && bHasLabel)
9115
- return -1;
9116
- return 0;
9117
- });
9118
- return validLayers.map(
9119
- (l) => l.id.includes("labels") ? l.clone({ highlightedObjectIndex: -1 }) : l
9120
- );
9121
- }
9122
- _isWGS84() {
9123
- if (this.state.mvt)
9124
- return super._isWGS84();
9125
- return true;
9126
- }
9127
- };
9128
- VectorTileLayer.layerName = "VectorTileLayer";
9129
- VectorTileLayer.defaultProps = defaultProps10;
9130
-
9131
- // ../../node_modules/@carto/api-client/node_modules/quadbin/dist/index.esm.js
9132
- var d2r = Math.PI / 180;
9133
- var r2d = 180 / Math.PI;
9134
- function tileToBBOX(tile) {
9135
- var e = tile2lon(tile[0] + 1, tile[2]);
9136
- var w = tile2lon(tile[0], tile[2]);
9137
- var s = tile2lat(tile[1] + 1, tile[2]);
9138
- var n = tile2lat(tile[1], tile[2]);
9139
- return [w, s, e, n];
9140
- }
9141
- function tileToGeoJSON(tile) {
9142
- var bbox2 = tileToBBOX(tile);
9143
- var poly = {
9144
- type: "Polygon",
9145
- coordinates: [
9146
- [
9147
- [bbox2[0], bbox2[1]],
9148
- [bbox2[0], bbox2[3]],
9149
- [bbox2[2], bbox2[3]],
9150
- [bbox2[2], bbox2[1]],
9151
- [bbox2[0], bbox2[1]]
9152
- ]
9153
- ]
9154
- };
9155
- return poly;
9156
- }
9157
- function tile2lon(x, z) {
9158
- return x / Math.pow(2, z) * 360 - 180;
9159
- }
9160
- function tile2lat(y, z) {
9161
- var n = Math.PI - 2 * Math.PI * y / Math.pow(2, z);
9162
- return r2d * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n)));
9163
- }
9164
- function pointToTile(lon, lat, z) {
9165
- var tile = pointToTileFraction(lon, lat, z);
9166
- tile[0] = Math.floor(tile[0]);
9167
- tile[1] = Math.floor(tile[1]);
9168
- return tile;
9169
- }
9170
- function getChildren(tile) {
9171
- return [
9172
- [tile[0] * 2, tile[1] * 2, tile[2] + 1],
9173
- [tile[0] * 2 + 1, tile[1] * 2, tile[2] + 1],
9174
- [tile[0] * 2 + 1, tile[1] * 2 + 1, tile[2] + 1],
9175
- [tile[0] * 2, tile[1] * 2 + 1, tile[2] + 1]
9176
- ];
9177
- }
9178
- function getParent(tile) {
9179
- if (tile[0] % 2 === 0 && tile[1] % 2 === 0) {
9180
- return [tile[0] / 2, tile[1] / 2, tile[2] - 1];
9181
- } else if (tile[0] % 2 === 0 && !tile[1] % 2 === 0) {
9182
- return [tile[0] / 2, (tile[1] - 1) / 2, tile[2] - 1];
9183
- } else if (!tile[0] % 2 === 0 && tile[1] % 2 === 0) {
9184
- return [(tile[0] - 1) / 2, tile[1] / 2, tile[2] - 1];
9185
- } else {
9186
- return [(tile[0] - 1) / 2, (tile[1] - 1) / 2, tile[2] - 1];
9187
- }
9188
- }
9189
- function getSiblings(tile) {
9190
- return getChildren(getParent(tile));
8901
+ const area2 = Math.abs((v2[0] - p[0]) * (v3[1] - p[1]) - (v3[0] - p[0]) * (v2[1] - p[1])) / 2;
8902
+ const area3 = Math.abs((v3[0] - p[0]) * (v1[1] - p[1]) - (v1[0] - p[0]) * (v3[1] - p[1])) / 2;
8903
+ return Math.abs(area - (area1 + area2 + area3)) < 1e-10;
9191
8904
  }
9192
- function hasSiblings(tile, tiles3) {
9193
- var siblings = getSiblings(tile);
9194
- for (var i = 0; i < siblings.length; i++) {
9195
- if (!hasTile(tiles3, siblings[i]))
9196
- return false;
9197
- }
9198
- return true;
8905
+ function getTriangleArea([x1, y1], [x2, y2], [x3, y3]) {
8906
+ return Math.abs((x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2);
9199
8907
  }
9200
- function hasTile(tiles3, tile) {
9201
- for (var i = 0; i < tiles3.length; i++) {
9202
- if (tilesEqual(tiles3[i], tile))
9203
- return true;
8908
+ function getPolygonCentroid(polygons, index2) {
8909
+ const {
8910
+ positions: { value: positions, size }
8911
+ } = polygons;
8912
+ const startIndex = size * polygons.polygonIndices.value[index2];
8913
+ const endIndex = size * polygons.polygonIndices.value[index2 + 1];
8914
+ let minX = Infinity;
8915
+ let minY = Infinity;
8916
+ let maxX = -Infinity;
8917
+ let maxY = -Infinity;
8918
+ for (let i = startIndex; i < endIndex; i += size) {
8919
+ const [x, y] = positions.subarray(i, i + 2);
8920
+ minX = Math.min(minX, x);
8921
+ minY = Math.min(minY, y);
8922
+ maxX = Math.max(maxX, x);
8923
+ maxY = Math.max(maxY, y);
9204
8924
  }
9205
- return false;
8925
+ return [(minX + maxX) / 2, (minY + maxY) / 2];
9206
8926
  }
9207
- function tilesEqual(tile1, tile2) {
9208
- return tile1[0] === tile2[0] && tile1[1] === tile2[1] && tile1[2] === tile2[2];
8927
+ function getSegmentLength(lines, index2) {
8928
+ const {
8929
+ positions: { value }
8930
+ } = lines;
8931
+ const [x1, y1, x2, y2] = value.subarray(index2, index2 + 4);
8932
+ return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
9209
8933
  }
9210
- function tileToQuadkey(tile) {
9211
- var index2 = "";
9212
- for (var z = tile[2]; z > 0; z--) {
9213
- var b = 0;
9214
- var mask = 1 << z - 1;
9215
- if ((tile[0] & mask) !== 0)
9216
- b++;
9217
- if ((tile[1] & mask) !== 0)
9218
- b += 2;
9219
- index2 += b.toString();
8934
+ function getLineLength(lines, index2) {
8935
+ const {
8936
+ positions: { size }
8937
+ } = lines;
8938
+ const startIndex = size * lines.pathIndices.value[index2];
8939
+ const endIndex = size * lines.pathIndices.value[index2 + 1];
8940
+ let length2 = 0;
8941
+ for (let j = startIndex; j < endIndex; j += size) {
8942
+ length2 += getSegmentLength(lines, j);
9220
8943
  }
9221
- return index2;
8944
+ return length2;
9222
8945
  }
9223
- function quadkeyToTile(quadkey) {
9224
- var x = 0;
9225
- var y = 0;
9226
- var z = quadkey.length;
9227
- for (var i = z; i > 0; i--) {
9228
- var mask = 1 << i - 1;
9229
- switch (quadkey[z - i]) {
9230
- case "0":
9231
- break;
9232
- case "1":
9233
- x |= mask;
9234
- break;
9235
- case "2":
9236
- y |= mask;
9237
- break;
9238
- case "3":
9239
- x |= mask;
9240
- y |= mask;
9241
- break;
9242
- }
8946
+ function getLineMidpoint(lines, index2) {
8947
+ const {
8948
+ positions: { value: positions },
8949
+ pathIndices: { value: pathIndices }
8950
+ } = lines;
8951
+ const startIndex = pathIndices[index2] * 2;
8952
+ const endIndex = pathIndices[index2 + 1] * 2;
8953
+ const numPoints = (endIndex - startIndex) / 2;
8954
+ if (numPoints === 2) {
8955
+ const [x1, y1, x2, y2] = positions.subarray(startIndex, startIndex + 4);
8956
+ return [(x1 + x2) / 2, (y1 + y2) / 2];
9243
8957
  }
9244
- return [x, y, z];
9245
- }
9246
- function bboxToTile(bboxCoords) {
9247
- var min2 = pointToTile(bboxCoords[0], bboxCoords[1], 32);
9248
- var max2 = pointToTile(bboxCoords[2], bboxCoords[3], 32);
9249
- var bbox2 = [min2[0], min2[1], max2[0], max2[1]];
9250
- var z = getBboxZoom(bbox2);
9251
- if (z === 0)
9252
- return [0, 0, 0];
9253
- var x = bbox2[0] >>> 32 - z;
9254
- var y = bbox2[1] >>> 32 - z;
9255
- return [x, y, z];
8958
+ const midPointIndex = startIndex + Math.floor(numPoints / 2) * 2;
8959
+ return [positions[midPointIndex], positions[midPointIndex + 1]];
9256
8960
  }
9257
- function getBboxZoom(bbox2) {
9258
- var MAX_ZOOM = 28;
9259
- for (var z = 0; z < MAX_ZOOM; z++) {
9260
- var mask = 1 << 32 - (z + 1);
9261
- if ((bbox2[0] & mask) != (bbox2[2] & mask) || (bbox2[1] & mask) != (bbox2[3] & mask)) {
9262
- return z;
8961
+
8962
+ // src/layers/vector-tile-layer.ts
8963
+ (0, import_core16.registerLoaders)([carto_properties_tile_loader_default, carto_vector_tile_loader_default]);
8964
+ var MVT_BBOX = { west: 0, east: 1, south: 0, north: 1 };
8965
+ var defaultProps10 = {
8966
+ ...import_geo_layers8.MVTLayer.defaultProps,
8967
+ autoLabels: false,
8968
+ data: TilejsonPropType,
8969
+ dataComparator: TilejsonPropType.equal,
8970
+ tileSize: DEFAULT_TILE_SIZE
8971
+ };
8972
+ var VectorTileLayer = class extends import_geo_layers8.MVTLayer {
8973
+ constructor(...propObjects) {
8974
+ super(...propObjects);
8975
+ }
8976
+ initializeState() {
8977
+ super.initializeState();
8978
+ this.setState({ binary: true });
8979
+ }
8980
+ updateState(parameters) {
8981
+ const { props } = parameters;
8982
+ if (props.data) {
8983
+ super.updateState(parameters);
8984
+ const formatTiles = new URL(props.data.tiles[0]).searchParams.get("formatTiles");
8985
+ const mvt = formatTiles === "mvt";
8986
+ this.setState({ mvt });
9263
8987
  }
9264
8988
  }
9265
- return MAX_ZOOM;
9266
- }
9267
- function pointToTileFraction(lon, lat, z) {
9268
- var sin = Math.sin(lat * d2r), z2 = Math.pow(2, z), x = z2 * (lon / 360 + 0.5), y = z2 * (0.5 - 0.25 * Math.log((1 + sin) / (1 - sin)) / Math.PI);
9269
- return [x, y, z];
9270
- }
9271
- var tilebelt = {
9272
- tileToGeoJSON,
9273
- tileToBBOX,
9274
- getChildren,
9275
- getParent,
9276
- getSiblings,
9277
- hasTile,
9278
- hasSiblings,
9279
- tilesEqual,
9280
- tileToQuadkey,
9281
- quadkeyToTile,
9282
- pointToTile,
9283
- bboxToTile,
9284
- pointToTileFraction
9285
- };
9286
- var tiles2 = getTiles;
9287
- function getTiles(geom, limits) {
9288
- var i, tile, coords = geom.coordinates, maxZoom = limits.max_zoom, tileHash = {}, tiles3 = [];
9289
- if (geom.type === "Point") {
9290
- return [tilebelt.pointToTile(coords[0], coords[1], maxZoom)];
9291
- } else if (geom.type === "MultiPoint") {
9292
- for (i = 0; i < coords.length; i++) {
9293
- tile = tilebelt.pointToTile(coords[i][0], coords[i][1], maxZoom);
9294
- tileHash[toID(tile[0], tile[1], tile[2])] = true;
8989
+ getLoadOptions() {
8990
+ const tileJSON = this.props.data;
8991
+ return mergeLoadOptions(super.getLoadOptions(), {
8992
+ fetch: { headers: { Authorization: `Bearer ${tileJSON.accessToken}` } },
8993
+ gis: { format: "binary" }
8994
+ // Use binary for MVT loading
8995
+ });
8996
+ }
8997
+ /* eslint-disable camelcase */
8998
+ async getTileData(tile) {
8999
+ const tileJSON = this.props.data;
9000
+ const { tiles: tiles2, properties_tiles } = tileJSON;
9001
+ const url = (0, import_geo_layers8._getURLFromTemplate)(tiles2, tile);
9002
+ if (!url) {
9003
+ return Promise.reject("Invalid URL");
9295
9004
  }
9296
- } else if (geom.type === "LineString") {
9297
- lineCover(tileHash, coords, maxZoom);
9298
- } else if (geom.type === "MultiLineString") {
9299
- for (i = 0; i < coords.length; i++) {
9300
- lineCover(tileHash, coords[i], maxZoom);
9005
+ const loadOptions = this.getLoadOptions();
9006
+ const { fetch: fetch2 } = this.props;
9007
+ const { signal } = tile;
9008
+ const geometryFetch = fetch2(url, { propName: "data", layer: this, loadOptions, signal });
9009
+ if (!properties_tiles) {
9010
+ return await geometryFetch;
9301
9011
  }
9302
- } else if (geom.type === "Polygon") {
9303
- polygonCover(tileHash, tiles3, coords, maxZoom);
9304
- } else if (geom.type === "MultiPolygon") {
9305
- for (i = 0; i < coords.length; i++) {
9306
- polygonCover(tileHash, tiles3, coords[i], maxZoom);
9012
+ const propertiesUrl = (0, import_geo_layers8._getURLFromTemplate)(properties_tiles, tile);
9013
+ if (!propertiesUrl) {
9014
+ return Promise.reject("Invalid properties URL");
9307
9015
  }
9308
- } else {
9309
- throw new Error("Geometry type not implemented");
9016
+ const attributesFetch = fetch2(propertiesUrl, {
9017
+ propName: "data",
9018
+ layer: this,
9019
+ loadOptions,
9020
+ signal
9021
+ });
9022
+ const [geometry, attributes] = await Promise.all([geometryFetch, attributesFetch]);
9023
+ if (!geometry)
9024
+ return null;
9025
+ return attributes ? mergeBoundaryData(geometry, attributes) : geometry;
9310
9026
  }
9311
- if (limits.min_zoom !== maxZoom) {
9312
- var len = tiles3.length;
9313
- appendHashTiles(tileHash, tiles3);
9314
- for (i = 0; i < len; i++) {
9315
- var t = tiles3[i];
9316
- tileHash[toID(t[0], t[1], t[2])] = true;
9027
+ /* eslint-enable camelcase */
9028
+ renderSubLayers(props) {
9029
+ if (props.data === null) {
9030
+ return null;
9317
9031
  }
9318
- return mergeTiles(tileHash, tiles3, limits);
9319
- }
9320
- appendHashTiles(tileHash, tiles3);
9321
- return tiles3;
9322
- }
9323
- function mergeTiles(tileHash, tiles3, limits) {
9324
- var mergedTiles = [];
9325
- for (var z = limits.max_zoom; z > limits.min_zoom; z--) {
9326
- var parentTileHash = {};
9327
- var parentTiles = [];
9328
- for (var i = 0; i < tiles3.length; i++) {
9329
- var t = tiles3[i];
9330
- if (t[0] % 2 === 0 && t[1] % 2 === 0) {
9331
- var id22 = toID(t[0] + 1, t[1], z), id32 = toID(t[0], t[1] + 1, z), id42 = toID(t[0] + 1, t[1] + 1, z);
9332
- if (tileHash[id22] && tileHash[id32] && tileHash[id42]) {
9333
- tileHash[toID(t[0], t[1], t[2])] = false;
9334
- tileHash[id22] = false;
9335
- tileHash[id32] = false;
9336
- tileHash[id42] = false;
9337
- var parentTile = [t[0] / 2, t[1] / 2, z - 1];
9338
- if (z - 1 === limits.min_zoom)
9339
- mergedTiles.push(parentTile);
9340
- else {
9341
- parentTileHash[toID(t[0] / 2, t[1] / 2, z - 1)] = true;
9342
- parentTiles.push(parentTile);
9032
+ const tileBbox = props.tile.bbox;
9033
+ const subLayers = [];
9034
+ const defaultToPointLabelLayer = {
9035
+ "points-text": {
9036
+ type: PointLabelLayer,
9037
+ ...props?._subLayerProps?.["points-text"],
9038
+ extensions: [
9039
+ new import_extensions.CollisionFilterExtension(),
9040
+ ...props.extensions || [],
9041
+ ...props?._subLayerProps?.["points-text"]?.extensions || []
9042
+ ]
9043
+ }
9044
+ };
9045
+ if (this.state.mvt) {
9046
+ const subLayerProps = {
9047
+ ...props,
9048
+ _subLayerProps: {
9049
+ ...props._subLayerProps,
9050
+ ...defaultToPointLabelLayer
9051
+ }
9052
+ };
9053
+ subLayers.push(super.renderSubLayers(subLayerProps));
9054
+ } else {
9055
+ const { west, south, east, north } = tileBbox;
9056
+ const extensions = [new import_extensions.ClipExtension(), ...props.extensions || []];
9057
+ const clipProps = {
9058
+ clipBounds: [west, south, east, north]
9059
+ };
9060
+ const applyClipExtensionToSublayerProps = (subLayerId) => {
9061
+ return {
9062
+ [subLayerId]: {
9063
+ ...clipProps,
9064
+ ...props?._subLayerProps?.[subLayerId],
9065
+ extensions: [...extensions, ...props?._subLayerProps?.[subLayerId]?.extensions || []]
9343
9066
  }
9067
+ };
9068
+ };
9069
+ const subLayerProps = {
9070
+ ...props,
9071
+ data: { ...props.data, tileBbox },
9072
+ autoHighlight: false,
9073
+ // Do not perform clipping on points (#9059)
9074
+ _subLayerProps: {
9075
+ ...props._subLayerProps,
9076
+ ...defaultToPointLabelLayer,
9077
+ ...applyClipExtensionToSublayerProps("polygons-fill"),
9078
+ ...applyClipExtensionToSublayerProps("polygons-stroke"),
9079
+ ...applyClipExtensionToSublayerProps("linestrings")
9344
9080
  }
9345
- }
9346
- }
9347
- for (i = 0; i < tiles3.length; i++) {
9348
- t = tiles3[i];
9349
- if (tileHash[toID(t[0], t[1], t[2])])
9350
- mergedTiles.push(t);
9351
- }
9352
- tileHash = parentTileHash;
9353
- tiles3 = parentTiles;
9354
- }
9355
- return mergedTiles;
9356
- }
9357
- function polygonCover(tileHash, tileArray, geom, zoom) {
9358
- var intersections = [];
9359
- for (var i = 0; i < geom.length; i++) {
9360
- var ring = [];
9361
- lineCover(tileHash, geom[i], zoom, ring);
9362
- for (var j = 0, len = ring.length, k = len - 1; j < len; k = j++) {
9363
- var m = (j + 1) % len;
9364
- var y = ring[j][1];
9365
- if ((y > ring[k][1] || y > ring[m][1]) && // not local minimum
9366
- (y < ring[k][1] || y < ring[m][1]) && // not local maximum
9367
- y !== ring[m][1])
9368
- intersections.push(ring[j]);
9081
+ };
9082
+ subLayers.push(new import_layers5.GeoJsonLayer(subLayerProps));
9369
9083
  }
9370
- }
9371
- intersections.sort(compareTiles);
9372
- for (i = 0; i < intersections.length; i += 2) {
9373
- y = intersections[i][1];
9374
- for (var x = intersections[i][0] + 1; x < intersections[i + 1][0]; x++) {
9375
- var id5 = toID(x, y, zoom);
9376
- if (!tileHash[id5]) {
9377
- tileArray.push([x, y, zoom]);
9084
+ if (subLayers[0] && props.autoLabels) {
9085
+ const labelData = createEmptyBinary();
9086
+ if (props.data.lines && props.data.lines.positions.value.length > 0) {
9087
+ labelData.points = createPointsFromLines(
9088
+ props.data.lines,
9089
+ typeof props.autoLabels === "object" ? props.autoLabels.uniqueIdProperty : void 0
9090
+ );
9378
9091
  }
9379
- }
9380
- }
9381
- }
9382
- function compareTiles(a, b) {
9383
- return a[1] - b[1] || a[0] - b[0];
9384
- }
9385
- function lineCover(tileHash, coords, maxZoom, ring) {
9386
- var prevX, prevY;
9387
- for (var i = 0; i < coords.length - 1; i++) {
9388
- var start = tilebelt.pointToTileFraction(coords[i][0], coords[i][1], maxZoom), stop = tilebelt.pointToTileFraction(coords[i + 1][0], coords[i + 1][1], maxZoom), x0 = start[0], y0 = start[1], x1 = stop[0], y1 = stop[1], dx = x1 - x0, dy = y1 - y0;
9389
- if (dy === 0 && dx === 0)
9390
- continue;
9391
- var sx = dx > 0 ? 1 : -1, sy = dy > 0 ? 1 : -1, x = Math.floor(x0), y = Math.floor(y0), tMaxX = dx === 0 ? Infinity : Math.abs(((dx > 0 ? 1 : 0) + x - x0) / dx), tMaxY = dy === 0 ? Infinity : Math.abs(((dy > 0 ? 1 : 0) + y - y0) / dy), tdx = Math.abs(sx / dx), tdy = Math.abs(sy / dy);
9392
- if (x !== prevX || y !== prevY) {
9393
- tileHash[toID(x, y, maxZoom)] = true;
9394
- if (ring && y !== prevY)
9395
- ring.push([x, y]);
9396
- prevX = x;
9397
- prevY = y;
9398
- }
9399
- while (tMaxX < 1 || tMaxY < 1) {
9400
- if (tMaxX < tMaxY) {
9401
- tMaxX += tdx;
9402
- x += sx;
9403
- } else {
9404
- tMaxY += tdy;
9405
- y += sy;
9092
+ if (props.data.polygons && props.data.polygons.positions.value.length > 0) {
9093
+ labelData.points = createPointsFromPolygons(
9094
+ props.data.polygons,
9095
+ this.state.mvt ? MVT_BBOX : tileBbox,
9096
+ props
9097
+ );
9406
9098
  }
9407
- tileHash[toID(x, y, maxZoom)] = true;
9408
- if (ring && y !== prevY)
9409
- ring.push([x, y]);
9410
- prevX = x;
9411
- prevY = y;
9099
+ subLayers.push(
9100
+ subLayers[0].clone({
9101
+ id: `${props.id}-labels`,
9102
+ data: labelData,
9103
+ pickable: false,
9104
+ autoHighlight: false
9105
+ })
9106
+ );
9412
9107
  }
9108
+ return subLayers;
9413
9109
  }
9414
- if (ring && y === ring[0][1])
9415
- ring.pop();
9416
- }
9417
- function appendHashTiles(hash, tiles3) {
9418
- var keys = Object.keys(hash);
9419
- for (var i = 0; i < keys.length; i++) {
9420
- tiles3.push(fromID(+keys[i]));
9421
- }
9422
- }
9423
- function toID(x, y, z) {
9424
- var dim = 2 * (1 << z);
9425
- return (dim * y + x) * 32 + z;
9426
- }
9427
- function fromID(id5) {
9428
- var z = id5 % 32, dim = 2 * (1 << z), xy = (id5 - z) / 32, x = xy % dim, y = (xy - x) / dim % dim;
9429
- return [x, y, z];
9430
- }
9431
- var B2 = [0x5555555555555555n, 0x3333333333333333n, 0x0f0f0f0f0f0f0f0fn, 0x00ff00ff00ff00ffn, 0x0000ffff0000ffffn, 0x00000000ffffffffn];
9432
- var S2 = [0n, 1n, 2n, 4n, 8n, 16n];
9433
- var TILE_SIZE3 = 512;
9434
- function cellToOffset(quadbin) {
9435
- const {
9436
- x,
9437
- y,
9438
- z
9439
- } = cellToTile2(quadbin);
9440
- const scale = TILE_SIZE3 / (1 << z);
9441
- return [x * scale, TILE_SIZE3 - y * scale, scale];
9442
- }
9443
- function cellToWorldBounds(quadbin, coverage) {
9444
- const [xOffset, yOffset, scale] = cellToOffset(quadbin);
9445
- return [[xOffset, yOffset], [xOffset + coverage * scale, yOffset - coverage * scale]];
9446
- }
9447
- function getCellPolygon(quadbin, coverage = 1) {
9448
- const [topLeft, bottomRight] = cellToWorldBounds(quadbin, coverage);
9449
- const [w, n] = worldToLngLat(topLeft);
9450
- const [e, s] = worldToLngLat(bottomRight);
9451
- return [e, n, e, s, w, s, w, n, e, n];
9452
- }
9453
- function tileToCell2(tile) {
9454
- if (tile.z < 0 || tile.z > 26) {
9455
- throw new Error("Wrong zoom");
9456
- }
9457
- const z = BigInt(tile.z);
9458
- let x = BigInt(tile.x) << 32n - z;
9459
- let y = BigInt(tile.y) << 32n - z;
9460
- for (let i = 0; i < 5; i++) {
9461
- const s = S2[5 - i];
9462
- const b = B2[4 - i];
9463
- x = (x | x << s) & b;
9464
- y = (y | y << s) & b;
9465
- }
9466
- const quadbin = 0x4000000000000000n | 1n << 59n | // | (mode << 59) | (mode_dep << 57)
9467
- z << 52n | (x | y << 1n) >> 12n | 0xfffffffffffffn >> z * 2n;
9468
- return quadbin;
9469
- }
9470
- function cellToTile2(quadbin) {
9471
- const mode = quadbin >> 59n & 7n;
9472
- const modeDep = quadbin >> 57n & 3n;
9473
- const z = quadbin >> 52n & 0x1fn;
9474
- const q = (quadbin & 0xfffffffffffffn) << 12n;
9475
- if (mode !== 1n && modeDep !== 0n) {
9476
- throw new Error("Wrong mode");
9110
+ renderLayers() {
9111
+ const layers = super.renderLayers();
9112
+ if (!this.props.autoLabels) {
9113
+ return layers;
9114
+ }
9115
+ const validLayers = (layers || []).flat().filter(Boolean);
9116
+ validLayers.sort((a, b) => {
9117
+ const aHasLabel = a.id.includes("labels");
9118
+ const bHasLabel = b.id.includes("labels");
9119
+ if (aHasLabel && !bHasLabel)
9120
+ return 1;
9121
+ if (!aHasLabel && bHasLabel)
9122
+ return -1;
9123
+ return 0;
9124
+ });
9125
+ return validLayers.map(
9126
+ (l) => l.id.includes("labels") ? l.clone({ highlightedObjectIndex: -1 }) : l
9127
+ );
9477
9128
  }
9478
- let x = q;
9479
- let y = q >> 1n;
9480
- for (let i = 0; i < 6; i++) {
9481
- const s = S2[i];
9482
- const b = B2[i];
9483
- x = (x | x >> s) & b;
9484
- y = (y | y >> s) & b;
9129
+ _isWGS84() {
9130
+ if (this.state.mvt)
9131
+ return super._isWGS84();
9132
+ return true;
9485
9133
  }
9486
- x = x >> 32n - z;
9487
- y = y >> 32n - z;
9488
- return {
9489
- z: Number(z),
9490
- x: Number(x),
9491
- y: Number(y)
9492
- };
9493
- }
9494
- function getResolution4(quadbin) {
9495
- return quadbin >> 52n & 0x1fn;
9496
- }
9497
- function geometryToCells(geometry, resolution) {
9498
- const zoom = Number(resolution);
9499
- return tiles2(geometry, {
9500
- min_zoom: zoom,
9501
- max_zoom: zoom
9502
- }).map(([x, y, z]) => tileToCell2({
9503
- x,
9504
- y,
9505
- z
9506
- }));
9507
- }
9508
- function cellToBoundary2(cell) {
9509
- const bbox2 = getCellPolygon(cell);
9510
- const boundary = [[bbox2[0], bbox2[1]], [bbox2[2], bbox2[3]], [bbox2[4], bbox2[5]], [bbox2[6], bbox2[7]], [bbox2[0], bbox2[1]]];
9511
- return {
9512
- type: "Polygon",
9513
- coordinates: [boundary]
9514
- };
9515
- }
9134
+ };
9135
+ VectorTileLayer.layerName = "VectorTileLayer";
9136
+ VectorTileLayer.defaultProps = defaultProps10;
9516
9137
 
9517
9138
  // ../../node_modules/@carto/api-client/build/api-client.js
9518
9139
  var import_h3_js5 = __toESM(require_h3_js(), 1);
@@ -12181,6 +11802,9 @@ void main(void) {
12181
11802
  return ApiVersion2;
12182
11803
  })(ApiVersion || {});
12183
11804
  var DEFAULT_API_BASE_URL = "https://gcp-us-east1.api.carto.com";
11805
+ var AUDIT_TAGS = {
11806
+ mapId: "tag-mapId"
11807
+ };
12184
11808
  var SpatialIndex = /* @__PURE__ */ ((SpatialIndex2) => {
12185
11809
  SpatialIndex2["H3"] = "h3";
12186
11810
  SpatialIndex2["QUADBIN"] = "quadbin";
@@ -12427,7 +12051,7 @@ void main(void) {
12427
12051
  var ccwerrboundA = (3 + 16 * epsilon) * epsilon;
12428
12052
  var ccwerrboundB = (2 + 12 * epsilon) * epsilon;
12429
12053
  var ccwerrboundC = (9 + 64 * epsilon) * epsilon * epsilon;
12430
- var B3 = vec(4);
12054
+ var B2 = vec(4);
12431
12055
  var C1 = vec(8);
12432
12056
  var C2 = vec(12);
12433
12057
  var D = vec(16);
@@ -12457,18 +12081,18 @@ void main(void) {
12457
12081
  t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
12458
12082
  _i = s0 - t0;
12459
12083
  bvirt = s0 - _i;
12460
- B3[0] = s0 - (_i + bvirt) + (bvirt - t0);
12084
+ B2[0] = s0 - (_i + bvirt) + (bvirt - t0);
12461
12085
  _j = s1 + _i;
12462
12086
  bvirt = _j - s1;
12463
12087
  _0 = s1 - (_j - bvirt) + (_i - bvirt);
12464
12088
  _i = _0 - t1;
12465
12089
  bvirt = _0 - _i;
12466
- B3[1] = _0 - (_i + bvirt) + (bvirt - t1);
12090
+ B2[1] = _0 - (_i + bvirt) + (bvirt - t1);
12467
12091
  u32 = _j + _i;
12468
12092
  bvirt = u32 - _j;
12469
- B3[2] = _j - (u32 - bvirt) + (_i - bvirt);
12470
- B3[3] = u32;
12471
- let det = estimate(4, B3);
12093
+ B2[2] = _j - (u32 - bvirt) + (_i - bvirt);
12094
+ B2[3] = u32;
12095
+ let det = estimate(4, B2);
12472
12096
  let errbound = ccwerrboundB * detsum;
12473
12097
  if (det >= errbound || -det >= errbound) {
12474
12098
  return det;
@@ -12517,7 +12141,7 @@ void main(void) {
12517
12141
  bvirt = u32 - _j;
12518
12142
  u[2] = _j - (u32 - bvirt) + (_i - bvirt);
12519
12143
  u[3] = u32;
12520
- const C1len = sum(4, B3, 4, u, C1);
12144
+ const C1len = sum(4, B2, 4, u, C1);
12521
12145
  s1 = acx * bcytail;
12522
12146
  c = splitter * acx;
12523
12147
  ahi = c - (c - acx);
@@ -17369,7 +16993,7 @@ void main(void) {
17369
16993
  return intersectTileQuadbin(parent, cellResolution, spatialFilter);
17370
16994
  }
17371
16995
  function intersectTileQuadbin(parent, cellResolution, spatialFilter) {
17372
- const tilePolygon = cellToBoundary2(parent);
16996
+ const tilePolygon = cellToBoundary(parent);
17373
16997
  if (!spatialFilter || turf_boolean_within_default(tilePolygon, spatialFilter)) {
17374
16998
  return true;
17375
16999
  }
@@ -17406,14 +17030,14 @@ void main(void) {
17406
17030
  }
17407
17031
  var FEATURE_GEOM_PROPERTY = "__geomValue";
17408
17032
  function tileFeaturesGeometries({
17409
- tiles: tiles3,
17033
+ tiles: tiles2,
17410
17034
  tileFormat,
17411
17035
  spatialFilter,
17412
17036
  uniqueIdProperty,
17413
17037
  options
17414
17038
  }) {
17415
17039
  const map2 = /* @__PURE__ */ new Map();
17416
- for (const tile of tiles3) {
17040
+ for (const tile of tiles2) {
17417
17041
  if (tile.isVisible === false || !tile.data) {
17418
17042
  continue;
17419
17043
  }
@@ -17685,14 +17309,14 @@ void main(void) {
17685
17309
  return pointIndices;
17686
17310
  }
17687
17311
  function tileFeaturesSpatialIndex({
17688
- tiles: tiles3,
17312
+ tiles: tiles2,
17689
17313
  spatialFilter,
17690
17314
  spatialDataColumn,
17691
17315
  spatialDataType
17692
17316
  }) {
17693
17317
  const map2 = /* @__PURE__ */ new Map();
17694
17318
  const spatialIndex = getSpatialIndex(spatialDataType);
17695
- const cellResolution = getResolution5(tiles3, spatialIndex);
17319
+ const cellResolution = getResolution4(tiles2, spatialIndex);
17696
17320
  const spatialIndexIDName = spatialDataColumn ? spatialDataColumn : spatialIndex;
17697
17321
  if (!cellResolution) {
17698
17322
  return [];
@@ -17701,7 +17325,7 @@ void main(void) {
17701
17325
  if (spatialIndex === "h3") {
17702
17326
  intersection3 = intersectTileH3(cellResolution, spatialFilter);
17703
17327
  }
17704
- for (const tile of tiles3) {
17328
+ for (const tile of tiles2) {
17705
17329
  if (tile.isVisible === false || !tile.data) {
17706
17330
  continue;
17707
17331
  }
@@ -17729,13 +17353,13 @@ void main(void) {
17729
17353
  }
17730
17354
  return tile.id;
17731
17355
  }
17732
- function getResolution5(tiles3, spatialIndex) {
17733
- const data = tiles3.find((tile) => tile.data?.length)?.data;
17356
+ function getResolution4(tiles2, spatialIndex) {
17357
+ const data = tiles2.find((tile) => tile.data?.length)?.data;
17734
17358
  if (!data) {
17735
17359
  return;
17736
17360
  }
17737
17361
  if (spatialIndex === "quadbin") {
17738
- return Number(getResolution4(data[0].id));
17362
+ return Number(getResolution(data[0].id));
17739
17363
  }
17740
17364
  if (spatialIndex === "h3") {
17741
17365
  return (0, import_h3_js6.getResolution)(data[0].id);
@@ -17761,21 +17385,21 @@ void main(void) {
17761
17385
  var DEFAULT_AGGREGATION_EXP_ALIAS = "__aggregationValue";
17762
17386
  var DEFAULT_AGGREGATION_EXP = `1 AS ${DEFAULT_AGGREGATION_EXP_ALIAS}`;
17763
17387
  function tileFeaturesRaster({
17764
- tiles: tiles3,
17388
+ tiles: tiles2,
17765
17389
  ...options
17766
17390
  }) {
17767
17391
  const metadataByBand = {};
17768
17392
  for (const band2 of options.rasterMetadata.bands) {
17769
17393
  metadataByBand[band2.name] = { ...band2, nodata: Number(band2.nodata) };
17770
17394
  }
17771
- tiles3 = tiles3.filter(isRasterTileVisible);
17772
- if (tiles3.length === 0)
17395
+ tiles2 = tiles2.filter(isRasterTileVisible);
17396
+ if (tiles2.length === 0)
17773
17397
  return [];
17774
- const tileResolution = getResolution4(tiles3[0].index.q);
17775
- const tileBlockSize = tiles3[0].data.blockSize;
17398
+ const tileResolution = getResolution(tiles2[0].index.q);
17399
+ const tileBlockSize = tiles2[0].data.blockSize;
17776
17400
  const cellResolution = tileResolution + BigInt(Math.log2(tileBlockSize));
17777
17401
  const data = /* @__PURE__ */ new Map();
17778
- for (const tile of tiles3) {
17402
+ for (const tile of tiles2) {
17779
17403
  const parent = tile.index.q;
17780
17404
  const intersection3 = intersectTileRaster(
17781
17405
  parent,
@@ -17813,7 +17437,7 @@ void main(void) {
17813
17437
  return !!(tile.isVisible && tile.data?.cells?.numericProps);
17814
17438
  }
17815
17439
  function cellToChildrenRaster(parent, resolution) {
17816
- const parentTile = cellToTile2(parent);
17440
+ const parentTile = cellToTile(parent);
17817
17441
  const childZ = Number(resolution);
17818
17442
  const blockSize = 2 ** (childZ - parentTile.z);
17819
17443
  const childBaseX = parentTile.x * blockSize;
@@ -17822,7 +17446,7 @@ void main(void) {
17822
17446
  for (let i = 0, il = blockSize ** 2; i < il; i++) {
17823
17447
  const x = childBaseX + i % blockSize;
17824
17448
  const y = childBaseY + Math.floor(i / blockSize);
17825
- cells.push(tileToCell2({ x, y, z: childZ }));
17449
+ cells.push(tileToCell({ x, y, z: childZ }));
17826
17450
  }
17827
17451
  return cells;
17828
17452
  }
@@ -17886,7 +17510,7 @@ void main(void) {
17886
17510
  return spatialDataType;
17887
17511
  }
17888
17512
  function tileFeatures({
17889
- tiles: tiles3,
17513
+ tiles: tiles2,
17890
17514
  spatialFilter,
17891
17515
  uniqueIdProperty,
17892
17516
  tileFormat,
@@ -17897,17 +17521,17 @@ void main(void) {
17897
17521
  }) {
17898
17522
  if (spatialDataType === "geo") {
17899
17523
  return tileFeaturesGeometries({
17900
- tiles: tiles3,
17524
+ tiles: tiles2,
17901
17525
  tileFormat,
17902
17526
  spatialFilter,
17903
17527
  uniqueIdProperty,
17904
17528
  options: { storeGeometry }
17905
17529
  });
17906
17530
  }
17907
- if (tiles3.some(isRasterTile)) {
17531
+ if (tiles2.some(isRasterTile)) {
17908
17532
  assert22(rasterMetadata, "Missing raster metadata");
17909
17533
  return tileFeaturesRaster({
17910
- tiles: tiles3,
17534
+ tiles: tiles2,
17911
17535
  spatialFilter,
17912
17536
  spatialDataColumn,
17913
17537
  spatialDataType,
@@ -17915,7 +17539,7 @@ void main(void) {
17915
17539
  });
17916
17540
  }
17917
17541
  return tileFeaturesSpatialIndex({
17918
- tiles: tiles3,
17542
+ tiles: tiles2,
17919
17543
  spatialFilter,
17920
17544
  spatialDataColumn,
17921
17545
  spatialDataType
@@ -18481,7 +18105,7 @@ ${formatErrorKey(key)}: ${errorContext[key]}`;
18481
18105
  spatialFiltersMode,
18482
18106
  ...params
18483
18107
  } = options;
18484
- const { columns, dataType, featureIds, z, limit, tileResolution } = params;
18108
+ const { columns, dataType, featureIds, z, limit, tileResolution, offset } = params;
18485
18109
  return executeModel({
18486
18110
  model: "pick",
18487
18111
  source: {
@@ -18494,12 +18118,13 @@ ${formatErrorKey(key)}: ${errorContext[key]}`;
18494
18118
  dataType,
18495
18119
  featureIds,
18496
18120
  z,
18121
+ offset,
18497
18122
  limit: limit || 1e3,
18498
18123
  tileResolution: tileResolution || DEFAULT_TILE_RESOLUTION
18499
18124
  },
18500
18125
  opts: { signal, headers: this.props.headers }
18501
18126
  // Avoid `normalizeObjectKeys()`, which changes column names.
18502
- }).then(({ rows }) => ({ rows }));
18127
+ }).then(({ rows, metadata }) => ({ rows, metadata }));
18503
18128
  }
18504
18129
  async getFormula(options) {
18505
18130
  const {
@@ -19430,8 +19055,8 @@ ${formatErrorKey(key)}: ${errorContext[key]}`;
19430
19055
  * After tiles are loaded, {@link extractTileFeatures} must be called
19431
19056
  * before computing statistics on the tiles.
19432
19057
  */
19433
- loadTiles(tiles3) {
19434
- this._tiles = tiles3;
19058
+ loadTiles(tiles2) {
19059
+ this._tiles = tiles2;
19435
19060
  this._features.length = 0;
19436
19061
  }
19437
19062
  /** Configures options used to extract features from tiles. */
@@ -19862,12 +19487,12 @@ ${formatErrorKey(key)}: ${errorContext[key]}`;
19862
19487
  * After tiles are loaded, {@link extractTileFeatures} must be called
19863
19488
  * before computing statistics on the tiles.
19864
19489
  */
19865
- loadTiles(tiles3) {
19490
+ loadTiles(tiles2) {
19866
19491
  if (!this._workerEnabled) {
19867
- return this._localImpl.loadTiles(tiles3);
19492
+ return this._localImpl.loadTiles(tiles2);
19868
19493
  }
19869
19494
  const worker = this._getWorker();
19870
- tiles3 = tiles3.map(
19495
+ tiles2 = tiles2.map(
19871
19496
  ({ id: id5, index: index2, bbox: bbox2, isVisible, data }) => {
19872
19497
  const tile = {
19873
19498
  id: id5,
@@ -19881,7 +19506,7 @@ ${formatErrorKey(key)}: ${errorContext[key]}`;
19881
19506
  );
19882
19507
  worker.postMessage({
19883
19508
  method: "loadTiles",
19884
- params: [tiles3]
19509
+ params: [tiles2]
19885
19510
  });
19886
19511
  }
19887
19512
  /** Configures options used to extract features from tiles. */
@@ -20418,7 +20043,7 @@ ${formatErrorKey(key)}: ${errorContext[key]}`;
20418
20043
  } = options;
20419
20044
  const urlParameters = { q: sqlQuery };
20420
20045
  if (queryParameters) {
20421
- urlParameters.queryParameters = JSON.stringify(queryParameters);
20046
+ urlParameters.queryParameters = queryParameters;
20422
20047
  }
20423
20048
  const baseUrl = buildQueryUrl({ apiBaseUrl, connectionName });
20424
20049
  const headers = {
@@ -21320,10 +20945,16 @@ ${formatErrorKey(key)}: ${errorContext[key]}`;
21320
20945
  if (!attribute.categories) {
21321
20946
  return [0, 1];
21322
20947
  }
21323
- return attribute.categories.map((c) => c.category).filter((c) => c !== void 0 && c !== null);
20948
+ return attribute.categories.map((c) => c.category).filter((c) => c !== void 0 && c !== null).slice(0, scaleLength);
21324
20949
  }
21325
20950
  if (scaleType === "quantile" && attribute.quantiles) {
21326
- return "global" in attribute.quantiles ? attribute.quantiles.global[scaleLength] : attribute.quantiles[scaleLength];
20951
+ const quantiles = "global" in attribute.quantiles ? attribute.quantiles.global : attribute.quantiles;
20952
+ if (scaleLength === 2 && !quantiles[2] && quantiles[4]?.length === 5) {
20953
+ return [quantiles[4][0], quantiles[4][2], quantiles[4][4]];
20954
+ }
20955
+ if (quantiles[scaleLength]) {
20956
+ return quantiles[scaleLength];
20957
+ }
21327
20958
  }
21328
20959
  let { min: min2 } = attribute;
21329
20960
  if (scaleType === "log" && min2 === 0) {
@@ -21825,19 +21456,8 @@ ${formatErrorKey(key)}: ${errorContext[key]}`;
21825
21456
  if (scaleType === "ordinal") {
21826
21457
  return colorRange.colorMap?.map(([value]) => value) || [];
21827
21458
  }
21828
- if (scaleType === "custom") {
21829
- if (colorRange.uiCustomScaleType === "logarithmic") {
21830
- return getLog10ScaleSteps({
21831
- min: band2.stats.min,
21832
- max: band2.stats.max,
21833
- steps: colorRange.colors.length
21834
- });
21835
- } else {
21836
- return colorRange.colorMap?.map(([value]) => value) || [];
21837
- }
21838
- }
21839
- const scaleLength = colorRange.colors.length;
21840
21459
  if (scaleType === "quantile") {
21460
+ const scaleLength = colorRange.colors.length;
21841
21461
  const quantiles = band2.stats.quantiles?.[scaleLength];
21842
21462
  if (!quantiles) {
21843
21463
  return [0, 1];
@@ -21863,9 +21483,21 @@ ${formatErrorKey(key)}: ${errorContext[key]}`;
21863
21483
  return {};
21864
21484
  }
21865
21485
  const domain = domainFromRasterMetadataBand(bandInfo, scaleType, colorRange);
21486
+ let scaleDomain = domain;
21487
+ if (scaleType === "custom") {
21488
+ if (colorRange.uiCustomScaleType === "logarithmic") {
21489
+ scaleDomain = getLog10ScaleSteps({
21490
+ min: bandInfo.stats.min,
21491
+ max: bandInfo.stats.max,
21492
+ steps: colorRange.colors.length
21493
+ });
21494
+ } else {
21495
+ scaleDomain = colorRange.colorMap?.map(([value]) => value) || [];
21496
+ }
21497
+ }
21866
21498
  const scaleFun = createColorScale(
21867
21499
  scaleType,
21868
- domain,
21500
+ scaleDomain,
21869
21501
  colorRange.colors.map(hexToRGB2),
21870
21502
  UNKNOWN_COLOR2
21871
21503
  );
@@ -21880,7 +21512,12 @@ ${formatErrorKey(key)}: ${errorContext[key]}`;
21880
21512
  updateTriggers: getRasterTileLayerUpdateTriggers({
21881
21513
  layerConfig,
21882
21514
  visualChannels
21883
- })
21515
+ }),
21516
+ domain,
21517
+ scaleDomain: scaleFun.domain(),
21518
+ range: colorRange.colors,
21519
+ type: scaleType,
21520
+ field: colorField
21884
21521
  };
21885
21522
  }
21886
21523
  function getRasterTileLayerUpdateTriggers({
@@ -22069,18 +21706,27 @@ ${formatErrorKey(key)}: ${errorContext[key]}`;
22069
21706
  rasterMetadata,
22070
21707
  visualChannels
22071
21708
  }),
22072
- scales: {}
22073
- // TODO
21709
+ scales: {
21710
+ fillColor: {
21711
+ type: "identity"
21712
+ }
21713
+ }
22074
21714
  };
22075
21715
  } else {
21716
+ const { dataTransform, updateTriggers: updateTriggers2, ...scaleProps } = getRasterTileLayerStylePropsScaledBand({
21717
+ layerConfig: config2,
21718
+ visualChannels,
21719
+ rasterMetadata
21720
+ });
22076
21721
  return {
22077
- channelProps: getRasterTileLayerStylePropsScaledBand({
22078
- layerConfig: config2,
22079
- visualChannels,
22080
- rasterMetadata
22081
- }),
21722
+ channelProps: {
21723
+ dataTransform,
21724
+ updateTriggers: updateTriggers2
21725
+ },
22082
21726
  scales: {
22083
- // TODO
21727
+ ...scaleProps.type && {
21728
+ fillColor: scaleProps
21729
+ }
22084
21730
  }
22085
21731
  };
22086
21732
  }
@@ -22547,7 +22193,8 @@ ${formatErrorKey(key)}: ${errorContext[key]}`;
22547
22193
  apiBaseUrl,
22548
22194
  connection,
22549
22195
  headers,
22550
- maxLengthURL
22196
+ maxLengthURL,
22197
+ tags
22551
22198
  }) {
22552
22199
  return {
22553
22200
  accessToken,
@@ -22559,7 +22206,8 @@ ${formatErrorKey(key)}: ${errorContext[key]}`;
22559
22206
  localCache: {
22560
22207
  cacheControl: ["no-cache"]
22561
22208
  }
22562
- }
22209
+ },
22210
+ tags
22563
22211
  };
22564
22212
  }
22565
22213
  function getDynamicTileResolution(spatialIndex) {
@@ -22594,14 +22242,19 @@ ${formatErrorKey(key)}: ${errorContext[key]}`;
22594
22242
  const cache = {};
22595
22243
  const configuredSource = configureSource({
22596
22244
  dataset,
22597
- filters: isRemoteCalculationSupported(dataset) ? filters : void 0,
22245
+ filters: !isEmptyObject(filters) && isRemoteCalculationSupported(dataset) ? filters : void 0,
22598
22246
  options: {
22599
22247
  ...context,
22600
22248
  connection: connectionName,
22601
22249
  headers: context.headers,
22602
22250
  accessToken: context.accessToken,
22603
22251
  apiBaseUrl: context.apiBaseUrl,
22604
- maxLengthURL: context.maxLengthURL
22252
+ maxLengthURL: context.maxLengthURL,
22253
+ ...context.mapId && {
22254
+ tags: {
22255
+ [AUDIT_TAGS.mapId]: context.mapId
22256
+ }
22257
+ }
22605
22258
  }
22606
22259
  });
22607
22260
  dataset.data = await configuredSource;
@@ -22634,10 +22287,13 @@ ${formatErrorKey(key)}: ${errorContext[key]}`;
22634
22287
  if (client2) {
22635
22288
  parameters.client = client2;
22636
22289
  }
22290
+ if (context.mapId) {
22291
+ parameters[AUDIT_TAGS.mapId] = context.mapId;
22292
+ }
22637
22293
  if (type === "query") {
22638
22294
  parameters.q = source;
22639
22295
  if (queryParameters) {
22640
- parameters.queryParameters = JSON.stringify(queryParameters);
22296
+ parameters.queryParameters = queryParameters;
22641
22297
  }
22642
22298
  }
22643
22299
  const stats = await requestWithParameters({
@@ -22723,6 +22379,7 @@ ${formatErrorKey(key)}: ${errorContext[key]}`;
22723
22379
  maxLengthURL
22724
22380
  });
22725
22381
  const context = {
22382
+ mapId: cartoMapId,
22726
22383
  accessToken: map2.token || accessToken,
22727
22384
  apiBaseUrl,
22728
22385
  clientId,
@@ -22775,7 +22432,7 @@ ${formatErrorKey(key)}: ${errorContext[key]}`;
22775
22432
  const pointType = layer.props?.pointType || "";
22776
22433
  return pointType.includes("text");
22777
22434
  });
22778
- if (textLayers.length && window.FontFace && !document.fonts.check("12px Inter")) {
22435
+ if (textLayers.length && typeof window !== "undefined" && typeof document !== "undefined" && window.FontFace && document.fonts && !document.fonts.check("12px Inter")) {
22779
22436
  const font = new FontFace(
22780
22437
  "Inter",
22781
22438
  "url(https://fonts.gstatic.com/s/inter/v12/UcC73FwrK3iLTeHuS_fvQtMwCp50KnMa1ZL7W0Q5nw.woff2)"