@carto/api-client 0.5.0-alpha.13 → 0.5.0-alpha.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/CHANGELOG.md +30 -1
  2. package/build/api-client.cjs +9849 -2868
  3. package/build/api-client.cjs.map +1 -1
  4. package/build/api-client.d.cts +510 -171
  5. package/build/api-client.d.ts +510 -171
  6. package/build/api-client.js +9558 -2627
  7. package/build/api-client.js.map +1 -1
  8. package/build/worker.js +122 -469
  9. package/build/worker.js.map +1 -1
  10. package/package.json +36 -22
  11. package/src/api/query.ts +2 -1
  12. package/src/constants-internal.ts +10 -0
  13. package/src/constants.ts +5 -1
  14. package/src/fetch-map/basemap-styles.ts +159 -0
  15. package/src/fetch-map/basemap.ts +120 -0
  16. package/src/fetch-map/fetch-map.ts +331 -0
  17. package/src/fetch-map/index.ts +13 -0
  18. package/src/fetch-map/layer-map.ts +461 -0
  19. package/src/fetch-map/parse-map.ts +425 -0
  20. package/src/fetch-map/source.ts +233 -0
  21. package/src/fetch-map/types.ts +268 -0
  22. package/src/fetch-map/utils.ts +69 -0
  23. package/src/filters/tileFeatures.ts +26 -10
  24. package/src/filters/tileFeaturesRaster.ts +122 -0
  25. package/src/index.ts +1 -0
  26. package/src/models/model.ts +0 -7
  27. package/src/sources/base-source.ts +4 -2
  28. package/src/sources/h3-tileset-source.ts +1 -1
  29. package/src/sources/quadbin-tileset-source.ts +1 -1
  30. package/src/sources/raster-source.ts +18 -5
  31. package/src/sources/types.ts +14 -7
  32. package/src/sources/vector-tileset-source.ts +1 -1
  33. package/src/spatial-index.ts +3 -84
  34. package/src/types.ts +16 -2
  35. package/src/widget-sources/index.ts +1 -0
  36. package/src/widget-sources/types.ts +0 -2
  37. package/src/widget-sources/widget-raster-source.ts +14 -0
  38. package/src/widget-sources/widget-remote-source.ts +8 -76
  39. package/src/widget-sources/widget-source.ts +6 -24
  40. package/src/widget-sources/widget-tileset-source-impl.ts +13 -16
  41. package/src/widget-sources/widget-tileset-source.ts +20 -7
package/build/worker.js CHANGED
@@ -26,324 +26,6 @@ var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__
26
26
  ));
27
27
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
28
28
 
29
- // node_modules/tilebelt/index.js
30
- var require_tilebelt = __commonJS({
31
- "node_modules/tilebelt/index.js"(exports, module) {
32
- "use strict";
33
- var d2r = Math.PI / 180;
34
- var r2d = 180 / Math.PI;
35
- function tileToBBOX(tile) {
36
- var e = tile2lon(tile[0] + 1, tile[2]);
37
- var w = tile2lon(tile[0], tile[2]);
38
- var s = tile2lat(tile[1] + 1, tile[2]);
39
- var n = tile2lat(tile[1], tile[2]);
40
- return [w, s, e, n];
41
- }
42
- function tileToGeoJSON(tile) {
43
- var bbox = tileToBBOX(tile);
44
- var poly = {
45
- type: "Polygon",
46
- coordinates: [
47
- [
48
- [bbox[0], bbox[1]],
49
- [bbox[0], bbox[3]],
50
- [bbox[2], bbox[3]],
51
- [bbox[2], bbox[1]],
52
- [bbox[0], bbox[1]]
53
- ]
54
- ]
55
- };
56
- return poly;
57
- }
58
- function tile2lon(x, z) {
59
- return x / Math.pow(2, z) * 360 - 180;
60
- }
61
- function tile2lat(y, z) {
62
- var n = Math.PI - 2 * Math.PI * y / Math.pow(2, z);
63
- return r2d * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n)));
64
- }
65
- function pointToTile(lon, lat, z) {
66
- var tile = pointToTileFraction(lon, lat, z);
67
- tile[0] = Math.floor(tile[0]);
68
- tile[1] = Math.floor(tile[1]);
69
- return tile;
70
- }
71
- function getChildren(tile) {
72
- return [
73
- [tile[0] * 2, tile[1] * 2, tile[2] + 1],
74
- [tile[0] * 2 + 1, tile[1] * 2, tile[2] + 1],
75
- [tile[0] * 2 + 1, tile[1] * 2 + 1, tile[2] + 1],
76
- [tile[0] * 2, tile[1] * 2 + 1, tile[2] + 1]
77
- ];
78
- }
79
- function getParent(tile) {
80
- if (tile[0] % 2 === 0 && tile[1] % 2 === 0) {
81
- return [tile[0] / 2, tile[1] / 2, tile[2] - 1];
82
- } else if (tile[0] % 2 === 0 && !tile[1] % 2 === 0) {
83
- return [tile[0] / 2, (tile[1] - 1) / 2, tile[2] - 1];
84
- } else if (!tile[0] % 2 === 0 && tile[1] % 2 === 0) {
85
- return [(tile[0] - 1) / 2, tile[1] / 2, tile[2] - 1];
86
- } else {
87
- return [(tile[0] - 1) / 2, (tile[1] - 1) / 2, tile[2] - 1];
88
- }
89
- }
90
- function getSiblings(tile) {
91
- return getChildren(getParent(tile));
92
- }
93
- function hasSiblings(tile, tiles2) {
94
- var siblings = getSiblings(tile);
95
- for (var i = 0; i < siblings.length; i++) {
96
- if (!hasTile(tiles2, siblings[i])) return false;
97
- }
98
- return true;
99
- }
100
- function hasTile(tiles2, tile) {
101
- for (var i = 0; i < tiles2.length; i++) {
102
- if (tilesEqual(tiles2[i], tile)) return true;
103
- }
104
- return false;
105
- }
106
- function tilesEqual(tile1, tile2) {
107
- return tile1[0] === tile2[0] && tile1[1] === tile2[1] && tile1[2] === tile2[2];
108
- }
109
- function tileToQuadkey(tile) {
110
- var index = "";
111
- for (var z = tile[2]; z > 0; z--) {
112
- var b = 0;
113
- var mask = 1 << z - 1;
114
- if ((tile[0] & mask) !== 0) b++;
115
- if ((tile[1] & mask) !== 0) b += 2;
116
- index += b.toString();
117
- }
118
- return index;
119
- }
120
- function quadkeyToTile(quadkey) {
121
- var x = 0;
122
- var y = 0;
123
- var z = quadkey.length;
124
- for (var i = z; i > 0; i--) {
125
- var mask = 1 << i - 1;
126
- switch (quadkey[z - i]) {
127
- case "0":
128
- break;
129
- case "1":
130
- x |= mask;
131
- break;
132
- case "2":
133
- y |= mask;
134
- break;
135
- case "3":
136
- x |= mask;
137
- y |= mask;
138
- break;
139
- }
140
- }
141
- return [x, y, z];
142
- }
143
- function bboxToTile(bboxCoords) {
144
- var min2 = pointToTile(bboxCoords[0], bboxCoords[1], 32);
145
- var max2 = pointToTile(bboxCoords[2], bboxCoords[3], 32);
146
- var bbox = [min2[0], min2[1], max2[0], max2[1]];
147
- var z = getBboxZoom(bbox);
148
- if (z === 0) return [0, 0, 0];
149
- var x = bbox[0] >>> 32 - z;
150
- var y = bbox[1] >>> 32 - z;
151
- return [x, y, z];
152
- }
153
- function getBboxZoom(bbox) {
154
- var MAX_ZOOM = 28;
155
- for (var z = 0; z < MAX_ZOOM; z++) {
156
- var mask = 1 << 32 - (z + 1);
157
- if ((bbox[0] & mask) != (bbox[2] & mask) || (bbox[1] & mask) != (bbox[3] & mask)) {
158
- return z;
159
- }
160
- }
161
- return MAX_ZOOM;
162
- }
163
- function pointToTileFraction(lon, lat, z) {
164
- var sin2 = Math.sin(lat * d2r), z2 = Math.pow(2, z), x = z2 * (lon / 360 + 0.5), y = z2 * (0.5 - 0.25 * Math.log((1 + sin2) / (1 - sin2)) / Math.PI);
165
- return [x, y, z];
166
- }
167
- module.exports = {
168
- tileToGeoJSON,
169
- tileToBBOX,
170
- getChildren,
171
- getParent,
172
- getSiblings,
173
- hasTile,
174
- hasSiblings,
175
- tilesEqual,
176
- tileToQuadkey,
177
- quadkeyToTile,
178
- pointToTile,
179
- bboxToTile,
180
- pointToTileFraction
181
- };
182
- }
183
- });
184
-
185
- // node_modules/@mapbox/tile-cover/index.js
186
- var require_tile_cover = __commonJS({
187
- "node_modules/@mapbox/tile-cover/index.js"(exports) {
188
- "use strict";
189
- var tilebelt = require_tilebelt();
190
- exports.geojson = function(geom, limits) {
191
- return {
192
- type: "FeatureCollection",
193
- features: getTiles(geom, limits).map(tileToFeature)
194
- };
195
- };
196
- function tileToFeature(t) {
197
- return {
198
- type: "Feature",
199
- geometry: tilebelt.tileToGeoJSON(t),
200
- properties: {}
201
- };
202
- }
203
- exports.tiles = getTiles;
204
- exports.indexes = function(geom, limits) {
205
- return getTiles(geom, limits).map(tilebelt.tileToQuadkey);
206
- };
207
- function getTiles(geom, limits) {
208
- var i, tile, coords = geom.coordinates, maxZoom = limits.max_zoom, tileHash = {}, tiles2 = [];
209
- if (geom.type === "Point") {
210
- return [tilebelt.pointToTile(coords[0], coords[1], maxZoom)];
211
- } else if (geom.type === "MultiPoint") {
212
- for (i = 0; i < coords.length; i++) {
213
- tile = tilebelt.pointToTile(coords[i][0], coords[i][1], maxZoom);
214
- tileHash[toID(tile[0], tile[1], tile[2])] = true;
215
- }
216
- } else if (geom.type === "LineString") {
217
- lineCover(tileHash, coords, maxZoom);
218
- } else if (geom.type === "MultiLineString") {
219
- for (i = 0; i < coords.length; i++) {
220
- lineCover(tileHash, coords[i], maxZoom);
221
- }
222
- } else if (geom.type === "Polygon") {
223
- polygonCover(tileHash, tiles2, coords, maxZoom);
224
- } else if (geom.type === "MultiPolygon") {
225
- for (i = 0; i < coords.length; i++) {
226
- polygonCover(tileHash, tiles2, coords[i], maxZoom);
227
- }
228
- } else {
229
- throw new Error("Geometry type not implemented");
230
- }
231
- if (limits.min_zoom !== maxZoom) {
232
- var len = tiles2.length;
233
- appendHashTiles(tileHash, tiles2);
234
- for (i = 0; i < len; i++) {
235
- var t = tiles2[i];
236
- tileHash[toID(t[0], t[1], t[2])] = true;
237
- }
238
- return mergeTiles(tileHash, tiles2, limits);
239
- }
240
- appendHashTiles(tileHash, tiles2);
241
- return tiles2;
242
- }
243
- function mergeTiles(tileHash, tiles2, limits) {
244
- var mergedTiles = [];
245
- for (var z = limits.max_zoom; z > limits.min_zoom; z--) {
246
- var parentTileHash = {};
247
- var parentTiles = [];
248
- for (var i = 0; i < tiles2.length; i++) {
249
- var t = tiles2[i];
250
- if (t[0] % 2 === 0 && t[1] % 2 === 0) {
251
- var id2 = toID(t[0] + 1, t[1], z), id3 = toID(t[0], t[1] + 1, z), id4 = toID(t[0] + 1, t[1] + 1, z);
252
- if (tileHash[id2] && tileHash[id3] && tileHash[id4]) {
253
- tileHash[toID(t[0], t[1], t[2])] = false;
254
- tileHash[id2] = false;
255
- tileHash[id3] = false;
256
- tileHash[id4] = false;
257
- var parentTile = [t[0] / 2, t[1] / 2, z - 1];
258
- if (z - 1 === limits.min_zoom) mergedTiles.push(parentTile);
259
- else {
260
- parentTileHash[toID(t[0] / 2, t[1] / 2, z - 1)] = true;
261
- parentTiles.push(parentTile);
262
- }
263
- }
264
- }
265
- }
266
- for (i = 0; i < tiles2.length; i++) {
267
- t = tiles2[i];
268
- if (tileHash[toID(t[0], t[1], t[2])]) mergedTiles.push(t);
269
- }
270
- tileHash = parentTileHash;
271
- tiles2 = parentTiles;
272
- }
273
- return mergedTiles;
274
- }
275
- function polygonCover(tileHash, tileArray, geom, zoom) {
276
- var intersections = [];
277
- for (var i = 0; i < geom.length; i++) {
278
- var ring = [];
279
- lineCover(tileHash, geom[i], zoom, ring);
280
- for (var j = 0, len = ring.length, k = len - 1; j < len; k = j++) {
281
- var m = (j + 1) % len;
282
- var y = ring[j][1];
283
- if ((y > ring[k][1] || y > ring[m][1]) && // not local minimum
284
- (y < ring[k][1] || y < ring[m][1]) && // not local maximum
285
- y !== ring[m][1]) intersections.push(ring[j]);
286
- }
287
- }
288
- intersections.sort(compareTiles);
289
- for (i = 0; i < intersections.length; i += 2) {
290
- y = intersections[i][1];
291
- for (var x = intersections[i][0] + 1; x < intersections[i + 1][0]; x++) {
292
- var id = toID(x, y, zoom);
293
- if (!tileHash[id]) {
294
- tileArray.push([x, y, zoom]);
295
- }
296
- }
297
- }
298
- }
299
- function compareTiles(a, b) {
300
- return a[1] - b[1] || a[0] - b[0];
301
- }
302
- function lineCover(tileHash, coords, maxZoom, ring) {
303
- var prevX, prevY;
304
- for (var i = 0; i < coords.length - 1; i++) {
305
- 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;
306
- if (dy === 0 && dx === 0) continue;
307
- 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);
308
- if (x !== prevX || y !== prevY) {
309
- tileHash[toID(x, y, maxZoom)] = true;
310
- if (ring && y !== prevY) ring.push([x, y]);
311
- prevX = x;
312
- prevY = y;
313
- }
314
- while (tMaxX < 1 || tMaxY < 1) {
315
- if (tMaxX < tMaxY) {
316
- tMaxX += tdx;
317
- x += sx;
318
- } else {
319
- tMaxY += tdy;
320
- y += sy;
321
- }
322
- tileHash[toID(x, y, maxZoom)] = true;
323
- if (ring && y !== prevY) ring.push([x, y]);
324
- prevX = x;
325
- prevY = y;
326
- }
327
- }
328
- if (ring && y === ring[0][1]) ring.pop();
329
- }
330
- function appendHashTiles(hash, tiles2) {
331
- var keys = Object.keys(hash);
332
- for (var i = 0; i < keys.length; i++) {
333
- tiles2.push(fromID(+keys[i]));
334
- }
335
- }
336
- function toID(x, y, z) {
337
- var dim = 2 * (1 << z);
338
- return (dim * y + x) * 32 + z;
339
- }
340
- function fromID(id) {
341
- var z = id % 32, dim = 2 * (1 << z), xy = (id - z) / 32, x = xy % dim, y = (xy - x) / dim % dim;
342
- return [x, y, z];
343
- }
344
- }
345
- });
346
-
347
29
  // node_modules/thenby/thenBy.module.js
348
30
  var require_thenBy_module = __commonJS({
349
31
  "node_modules/thenby/thenBy.module.js"(exports, module) {
@@ -404,6 +86,10 @@ var FilterType = /* @__PURE__ */ ((FilterType2) => {
404
86
  return FilterType2;
405
87
  })(FilterType || {});
406
88
  var DEFAULT_API_BASE_URL = "https://gcp-us-east1.api.carto.com";
89
+ var SpatialIndexColumn = Object.freeze({
90
+ ["h3" /* H3 */]: ["h3", "hex", "h3id", "hex_id", "h3hex"],
91
+ ["quadbin" /* QUADBIN */]: ["quadbin"]
92
+ });
407
93
 
408
94
  // src/utils.ts
409
95
  var FILTER_TYPES = new Set(Object.values(FilterType));
@@ -755,14 +441,14 @@ function transformMultiPolygon2(multiPolygon, bbox) {
755
441
  import { featureCollection } from "@turf/helpers";
756
442
  var FEATURE_GEOM_PROPERTY = "__geomValue";
757
443
  function tileFeaturesGeometries({
758
- tiles: tiles2,
444
+ tiles,
759
445
  tileFormat,
760
446
  spatialFilter,
761
447
  uniqueIdProperty,
762
448
  options
763
449
  }) {
764
450
  const map = /* @__PURE__ */ new Map();
765
- for (const tile of tiles2) {
451
+ for (const tile of tiles) {
766
452
  if (tile.isVisible === false || !tile.data) {
767
453
  continue;
768
454
  }
@@ -1043,57 +729,19 @@ function createIndicesForPoints(data) {
1043
729
  data.pointIndices = pointIndices;
1044
730
  }
1045
731
 
1046
- // node_modules/quadbin/dist/esm/index.js
1047
- var import_tile_cover = __toESM(require_tile_cover(), 1);
1048
- var B = [
1049
- 0x5555555555555555n,
1050
- 0x3333333333333333n,
1051
- 0x0f0f0f0f0f0f0f0fn,
1052
- 0x00ff00ff00ff00ffn,
1053
- 0x0000ffff0000ffffn,
1054
- 0x00000000ffffffffn
1055
- ];
1056
- var S = [0n, 1n, 2n, 4n, 8n, 16n];
1057
- function tileToCell(tile) {
1058
- if (tile.z < 0 || tile.z > 26) {
1059
- throw new Error("Wrong zoom");
1060
- }
1061
- const z = BigInt(tile.z);
1062
- let x = BigInt(tile.x) << 32n - z;
1063
- let y = BigInt(tile.y) << 32n - z;
1064
- for (let i = 0; i < 5; i++) {
1065
- const s = S[5 - i];
1066
- const b = B[4 - i];
1067
- x = (x | x << s) & b;
1068
- y = (y | y << s) & b;
1069
- }
1070
- const quadbin = 0x4000000000000000n | 1n << 59n | // | (mode << 59) | (mode_dep << 57)
1071
- z << 52n | (x | y << 1n) >> 12n | 0xfffffffffffffn >> z * 2n;
1072
- return quadbin;
1073
- }
1074
- function getResolution(quadbin) {
1075
- return quadbin >> 52n & 0x1fn;
1076
- }
1077
- function geometryToCells(geometry, resolution) {
1078
- const zoom = Number(resolution);
1079
- return (0, import_tile_cover.tiles)(geometry, {
1080
- min_zoom: zoom,
1081
- max_zoom: zoom
1082
- }).map(([x, y, z]) => tileToCell({ x, y, z }));
1083
- }
1084
-
1085
732
  // src/filters/tileFeaturesSpatialIndex.ts
733
+ import { getResolution as quadbinGetResolution, geometryToCells } from "quadbin";
1086
734
  import bboxClip from "@turf/bbox-clip";
1087
735
  import { getResolution as h3GetResolution, polygonToCells } from "h3-js";
1088
736
  function tileFeaturesSpatialIndex({
1089
- tiles: tiles2,
737
+ tiles,
1090
738
  spatialFilter,
1091
739
  spatialDataColumn,
1092
740
  spatialDataType
1093
741
  }) {
1094
742
  const map = /* @__PURE__ */ new Map();
1095
743
  const spatialIndex = getSpatialIndex(spatialDataType);
1096
- const resolution = getResolution2(tiles2, spatialIndex);
744
+ const resolution = getResolution(tiles, spatialIndex);
1097
745
  const spatialIndexIDName = spatialDataColumn ? spatialDataColumn : spatialIndex;
1098
746
  if (!resolution) {
1099
747
  return [];
@@ -1103,7 +751,7 @@ function tileFeaturesSpatialIndex({
1103
751
  return [];
1104
752
  }
1105
753
  const cellsSet = new Set(cells);
1106
- for (const tile of tiles2) {
754
+ for (const tile of tiles) {
1107
755
  if (tile.isVisible === false || !tile.data) {
1108
756
  continue;
1109
757
  }
@@ -1115,13 +763,13 @@ function tileFeaturesSpatialIndex({
1115
763
  }
1116
764
  return Array.from(map.values());
1117
765
  }
1118
- function getResolution2(tiles2, spatialIndex) {
1119
- const data = tiles2.find((tile) => tile.data?.length)?.data;
766
+ function getResolution(tiles, spatialIndex) {
767
+ const data = tiles.find((tile) => tile.data?.length)?.data;
1120
768
  if (!data) {
1121
769
  return;
1122
770
  }
1123
771
  if (spatialIndex === "quadbin" /* QUADBIN */) {
1124
- return Number(getResolution(data[0].id));
772
+ return Number(quadbinGetResolution(data[0].id));
1125
773
  }
1126
774
  if (spatialIndex === "h3" /* H3 */) {
1127
775
  return h3GetResolution(data[0].id);
@@ -1160,33 +808,112 @@ function getSpatialIndex(spatialDataType) {
1160
808
 
1161
809
  // src/constants-internal.ts
1162
810
  var DEFAULT_GEO_COLUMN = "geom";
1163
- var DEFAULT_AGGREGATION_RES_LEVEL_H3 = 4;
1164
- var DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN = 6;
811
+ var DEFAULT_AGGREGATION_EXP_ALIAS = "__aggregationValue";
812
+ var DEFAULT_AGGREGATION_EXP = `1 AS ${DEFAULT_AGGREGATION_EXP_ALIAS}`;
813
+
814
+ // src/filters/tileFeaturesRaster.ts
815
+ import {
816
+ cellToChildren as _cellToChildren,
817
+ cellToTile,
818
+ geometryToCells as geometryToCells2,
819
+ getResolution as getResolution2
820
+ } from "quadbin";
821
+ function tileFeaturesRaster({
822
+ tiles,
823
+ ...options
824
+ }) {
825
+ const metadataByBand = {};
826
+ for (const band of options.rasterMetadata.bands) {
827
+ metadataByBand[band.name] = { ...band, nodata: Number(band.nodata) };
828
+ }
829
+ tiles = tiles.filter(isRasterTileVisible);
830
+ if (tiles.length === 0) return [];
831
+ const tileResolution = getResolution2(tiles[0].index.q);
832
+ const tileBlockSize = tiles[0].data.blockSize;
833
+ const cellResolution = tileResolution + BigInt(Math.log2(tileBlockSize));
834
+ const spatialFilterCells = new Set(
835
+ geometryToCells2(options.spatialFilter, cellResolution)
836
+ );
837
+ const data = /* @__PURE__ */ new Map();
838
+ for (const tile of tiles) {
839
+ const parent = tile.index.q;
840
+ const children = cellToChildrenSorted(parent, cellResolution);
841
+ for (let i = 0; i < children.length; i++) {
842
+ if (!spatialFilterCells.has(children[i])) continue;
843
+ const cellData = {};
844
+ let cellDataExists = false;
845
+ for (const band in tile.data.cells.numericProps) {
846
+ const value = tile.data.cells.numericProps[band].value[i];
847
+ const bandMetadata = metadataByBand[band];
848
+ if (isValidBandValue(value, bandMetadata.nodata)) {
849
+ cellData[band] = tile.data.cells.numericProps[band].value[i];
850
+ cellDataExists = true;
851
+ }
852
+ }
853
+ if (cellDataExists) {
854
+ data.set(children[i], cellData);
855
+ }
856
+ }
857
+ }
858
+ return Array.from(data.values());
859
+ }
860
+ function isRasterTile(tile) {
861
+ return !!tile.data?.cells;
862
+ }
863
+ function isRasterTileVisible(tile) {
864
+ return !!(tile.isVisible && tile.data?.cells?.numericProps);
865
+ }
866
+ function cellToChildrenSorted(parent, resolution) {
867
+ return _cellToChildren(parent, resolution).sort(
868
+ (cellA, cellB) => {
869
+ const tileA = cellToTile(cellA);
870
+ const tileB = cellToTile(cellB);
871
+ if (tileA.y !== tileB.y) {
872
+ return tileA.y > tileB.y ? 1 : -1;
873
+ }
874
+ return tileA.x > tileB.x ? 1 : -1;
875
+ }
876
+ );
877
+ }
878
+ function isValidBandValue(value, nodata) {
879
+ return Number.isNaN(value) ? false : nodata !== value;
880
+ }
1165
881
 
1166
882
  // src/filters/tileFeatures.ts
1167
883
  function tileFeatures({
1168
- tiles: tiles2,
884
+ tiles,
1169
885
  spatialFilter,
1170
886
  uniqueIdProperty,
1171
887
  tileFormat,
1172
888
  spatialDataColumn = DEFAULT_GEO_COLUMN,
1173
889
  spatialDataType,
890
+ rasterMetadata,
1174
891
  options = {}
1175
892
  }) {
1176
- if (spatialDataType !== "geo") {
1177
- return tileFeaturesSpatialIndex({
1178
- tiles: tiles2,
893
+ if (spatialDataType === "geo") {
894
+ return tileFeaturesGeometries({
895
+ tiles,
896
+ tileFormat,
897
+ spatialFilter,
898
+ uniqueIdProperty,
899
+ options
900
+ });
901
+ }
902
+ if (tiles.some(isRasterTile)) {
903
+ assert(rasterMetadata, "Missing raster metadata");
904
+ return tileFeaturesRaster({
905
+ tiles,
1179
906
  spatialFilter,
1180
907
  spatialDataColumn,
1181
- spatialDataType
908
+ spatialDataType,
909
+ rasterMetadata
1182
910
  });
1183
911
  }
1184
- return tileFeaturesGeometries({
1185
- tiles: tiles2,
1186
- tileFormat,
912
+ return tileFeaturesSpatialIndex({
913
+ tiles,
1187
914
  spatialFilter,
1188
- uniqueIdProperty,
1189
- options
915
+ spatialDataColumn,
916
+ spatialDataType
1190
917
  });
1191
918
  }
1192
919
 
@@ -1535,77 +1262,16 @@ function getClient() {
1535
1262
  return client;
1536
1263
  }
1537
1264
 
1538
- // src/spatial-index.ts
1539
- var DEFAULT_TILE_SIZE = 512;
1540
- var QUADBIN_ZOOM_MAX_OFFSET = 4;
1541
- function getSpatialFiltersResolution(source2, viewState) {
1542
- const dataResolution = source2.dataResolution ?? Number.MAX_VALUE;
1543
- const aggregationResLevel = source2.aggregationResLevel ?? (source2.spatialDataType === "h3" ? DEFAULT_AGGREGATION_RES_LEVEL_H3 : DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN);
1544
- const aggregationResLevelOffset = Math.max(
1545
- 0,
1546
- Math.floor(aggregationResLevel)
1547
- );
1548
- const currentZoomInt = Math.ceil(viewState.zoom);
1549
- if (source2.spatialDataType === "h3") {
1550
- const tileSize = DEFAULT_TILE_SIZE;
1551
- const maxResolutionForZoom = maxH3SpatialFiltersResolutions.find(
1552
- ([zoom]) => zoom === currentZoomInt
1553
- )?.[1] ?? Math.max(0, currentZoomInt - 3);
1554
- const maxSpatialFiltersResolution = maxResolutionForZoom ? Math.min(dataResolution, maxResolutionForZoom) : dataResolution;
1555
- const hexagonResolution = _getHexagonResolution(viewState, tileSize) + aggregationResLevelOffset;
1556
- return Math.min(hexagonResolution, maxSpatialFiltersResolution);
1557
- }
1558
- if (source2.spatialDataType === "quadbin") {
1559
- const maxResolutionForZoom = currentZoomInt + QUADBIN_ZOOM_MAX_OFFSET;
1560
- const maxSpatialFiltersResolution = Math.min(
1561
- dataResolution,
1562
- maxResolutionForZoom
1563
- );
1564
- const quadsResolution = Math.floor(viewState.zoom) + aggregationResLevelOffset;
1565
- return Math.min(quadsResolution, maxSpatialFiltersResolution);
1566
- }
1567
- return void 0;
1568
- }
1569
- var maxH3SpatialFiltersResolutions = [
1570
- [20, 14],
1571
- [19, 13],
1572
- [18, 12],
1573
- [17, 11],
1574
- [16, 10],
1575
- [15, 9],
1576
- [14, 8],
1577
- [13, 7],
1578
- [12, 7],
1579
- [11, 7],
1580
- [10, 6],
1581
- [9, 6],
1582
- [8, 5],
1583
- [7, 4],
1584
- [6, 4],
1585
- [5, 3],
1586
- [4, 2],
1587
- [3, 1],
1588
- [2, 1],
1589
- [1, 0]
1590
- ];
1591
- var BIAS = 2;
1592
- function _getHexagonResolution(viewport, tileSize) {
1593
- const zoomOffset = Math.log2(tileSize / DEFAULT_TILE_SIZE);
1594
- const hexagonScaleFactor = 2 / 3 * (viewport.zoom - zoomOffset);
1595
- const latitudeScaleFactor = Math.log(
1596
- 1 / Math.cos(Math.PI * viewport.latitude / 180)
1597
- );
1598
- return Math.max(
1599
- 0,
1600
- Math.floor(hexagonScaleFactor + latitudeScaleFactor - BIAS)
1601
- );
1602
- }
1603
-
1604
1265
  // src/widget-sources/widget-source.ts
1605
1266
  var _WidgetSource = class _WidgetSource {
1606
1267
  constructor(props) {
1607
1268
  __publicField(this, "props");
1608
- this.props = { ..._WidgetSource.defaultProps, ...props };
1269
+ this.props = {
1270
+ ..._WidgetSource.defaultProps,
1271
+ clientId: getClient(),
1272
+ // Refresh clientId, default may have changed.
1273
+ ...props
1274
+ };
1609
1275
  }
1610
1276
  /**
1611
1277
  * Destroys the widget source and releases allocated resources.
@@ -1616,17 +1282,6 @@ var _WidgetSource = class _WidgetSource {
1616
1282
  */
1617
1283
  destroy() {
1618
1284
  }
1619
- _getSpatialFiltersResolution(source2, spatialFilter, referenceViewState) {
1620
- if (!spatialFilter || source2.spatialDataType === "geo") {
1621
- return;
1622
- }
1623
- if (!referenceViewState) {
1624
- throw new Error(
1625
- 'Missing required option, "spatialIndexReferenceViewState".'
1626
- );
1627
- }
1628
- return getSpatialFiltersResolution(source2, referenceViewState);
1629
- }
1630
1285
  };
1631
1286
  __publicField(_WidgetSource, "defaultProps", {
1632
1287
  apiVersion: "v3" /* V3 */,
@@ -1652,8 +1307,8 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
1652
1307
  * After tiles are loaded, {@link extractTileFeatures} must be called
1653
1308
  * before computing statistics on the tiles.
1654
1309
  */
1655
- loadTiles(tiles2) {
1656
- this._tiles = tiles2;
1310
+ loadTiles(tiles) {
1311
+ this._tiles = tiles;
1657
1312
  this._features.length = 0;
1658
1313
  }
1659
1314
  /** Configures options used to extract features from tiles. */
@@ -1667,12 +1322,10 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
1667
1322
  return;
1668
1323
  }
1669
1324
  this._features = tileFeatures({
1670
- tiles: this._tiles,
1671
- tileFormat: this.props.tileFormat,
1325
+ ...this.props,
1672
1326
  ...this._tileFeatureExtractOptions,
1673
- spatialFilter,
1674
- spatialDataColumn: this.props.spatialDataColumn,
1675
- spatialDataType: this.props.spatialDataType
1327
+ tiles: this._tiles,
1328
+ spatialFilter
1676
1329
  });
1677
1330
  prevInputs.spatialFilter = spatialFilter;
1678
1331
  }
@@ -1703,12 +1356,6 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
1703
1356
  filterOwner,
1704
1357
  spatialFilter
1705
1358
  }) {
1706
- if (operation === "custom") {
1707
- throw new Error("Custom aggregation not supported for tilesets");
1708
- }
1709
- if (column && column !== "*" || operation !== "count") {
1710
- assertColumn(this._features, column);
1711
- }
1712
1359
  const filteredFeatures = this._getFilteredFeatures(
1713
1360
  spatialFilter,
1714
1361
  filters,
@@ -1717,6 +1364,12 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
1717
1364
  if (filteredFeatures.length === 0 && operation !== "count") {
1718
1365
  return { value: null };
1719
1366
  }
1367
+ if (operation === "custom") {
1368
+ throw new Error("Custom aggregation not supported for tilesets");
1369
+ }
1370
+ if (column && column !== "*" || operation !== "count") {
1371
+ assertColumn(this._features, column);
1372
+ }
1720
1373
  const targetOperation = aggregationFunctions[operation];
1721
1374
  return {
1722
1375
  value: targetOperation(filteredFeatures, column, joinOperation)
@@ -1881,7 +1534,6 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
1881
1534
  filterOwner,
1882
1535
  spatialFilter
1883
1536
  }) {
1884
- assertColumn(this._features, column);
1885
1537
  const filteredFeatures = this._getFilteredFeatures(
1886
1538
  spatialFilter,
1887
1539
  filters,
@@ -1890,6 +1542,7 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
1890
1542
  if (!this._features.length) {
1891
1543
  return null;
1892
1544
  }
1545
+ assertColumn(this._features, column);
1893
1546
  return {
1894
1547
  min: aggregationFunctions.min(filteredFeatures, column),
1895
1548
  max: aggregationFunctions.max(filteredFeatures, column)