@carto/api-client 0.5.0-alpha.11 → 0.5.0-alpha.14

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.
@@ -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) {
@@ -802,14 +484,14 @@ function transformMultiPolygon2(multiPolygon2, bbox) {
802
484
  import { featureCollection } from "@turf/helpers";
803
485
  var FEATURE_GEOM_PROPERTY = "__geomValue";
804
486
  function tileFeaturesGeometries({
805
- tiles: tiles2,
487
+ tiles,
806
488
  tileFormat,
807
489
  spatialFilter,
808
490
  uniqueIdProperty,
809
491
  options
810
492
  }) {
811
493
  const map = /* @__PURE__ */ new Map();
812
- for (const tile of tiles2) {
494
+ for (const tile of tiles) {
813
495
  if (tile.isVisible === false || !tile.data) {
814
496
  continue;
815
497
  }
@@ -1090,57 +772,19 @@ function createIndicesForPoints(data) {
1090
772
  data.pointIndices = pointIndices;
1091
773
  }
1092
774
 
1093
- // node_modules/quadbin/dist/esm/index.js
1094
- var import_tile_cover = __toESM(require_tile_cover(), 1);
1095
- var B = [
1096
- 0x5555555555555555n,
1097
- 0x3333333333333333n,
1098
- 0x0f0f0f0f0f0f0f0fn,
1099
- 0x00ff00ff00ff00ffn,
1100
- 0x0000ffff0000ffffn,
1101
- 0x00000000ffffffffn
1102
- ];
1103
- var S = [0n, 1n, 2n, 4n, 8n, 16n];
1104
- function tileToCell(tile) {
1105
- if (tile.z < 0 || tile.z > 26) {
1106
- throw new Error("Wrong zoom");
1107
- }
1108
- const z = BigInt(tile.z);
1109
- let x = BigInt(tile.x) << 32n - z;
1110
- let y = BigInt(tile.y) << 32n - z;
1111
- for (let i = 0; i < 5; i++) {
1112
- const s = S[5 - i];
1113
- const b = B[4 - i];
1114
- x = (x | x << s) & b;
1115
- y = (y | y << s) & b;
1116
- }
1117
- const quadbin = 0x4000000000000000n | 1n << 59n | // | (mode << 59) | (mode_dep << 57)
1118
- z << 52n | (x | y << 1n) >> 12n | 0xfffffffffffffn >> z * 2n;
1119
- return quadbin;
1120
- }
1121
- function getResolution(quadbin) {
1122
- return quadbin >> 52n & 0x1fn;
1123
- }
1124
- function geometryToCells(geometry, resolution) {
1125
- const zoom = Number(resolution);
1126
- return (0, import_tile_cover.tiles)(geometry, {
1127
- min_zoom: zoom,
1128
- max_zoom: zoom
1129
- }).map(([x, y, z]) => tileToCell({ x, y, z }));
1130
- }
1131
-
1132
775
  // src/filters/tileFeaturesSpatialIndex.ts
776
+ import { getResolution as quadbinGetResolution, geometryToCells } from "quadbin";
1133
777
  import bboxClip from "@turf/bbox-clip";
1134
778
  import { getResolution as h3GetResolution, polygonToCells } from "h3-js";
1135
779
  function tileFeaturesSpatialIndex({
1136
- tiles: tiles2,
780
+ tiles,
1137
781
  spatialFilter,
1138
782
  spatialDataColumn,
1139
783
  spatialDataType
1140
784
  }) {
1141
785
  const map = /* @__PURE__ */ new Map();
1142
786
  const spatialIndex = getSpatialIndex(spatialDataType);
1143
- const resolution = getResolution2(tiles2, spatialIndex);
787
+ const resolution = getResolution(tiles, spatialIndex);
1144
788
  const spatialIndexIDName = spatialDataColumn ? spatialDataColumn : spatialIndex;
1145
789
  if (!resolution) {
1146
790
  return [];
@@ -1150,7 +794,7 @@ function tileFeaturesSpatialIndex({
1150
794
  return [];
1151
795
  }
1152
796
  const cellsSet = new Set(cells);
1153
- for (const tile of tiles2) {
797
+ for (const tile of tiles) {
1154
798
  if (tile.isVisible === false || !tile.data) {
1155
799
  continue;
1156
800
  }
@@ -1162,13 +806,13 @@ function tileFeaturesSpatialIndex({
1162
806
  }
1163
807
  return Array.from(map.values());
1164
808
  }
1165
- function getResolution2(tiles2, spatialIndex) {
1166
- const data = tiles2.find((tile) => tile.data?.length)?.data;
809
+ function getResolution(tiles, spatialIndex) {
810
+ const data = tiles.find((tile) => tile.data?.length)?.data;
1167
811
  if (!data) {
1168
812
  return;
1169
813
  }
1170
814
  if (spatialIndex === "quadbin" /* QUADBIN */) {
1171
- return Number(getResolution(data[0].id));
815
+ return Number(quadbinGetResolution(data[0].id));
1172
816
  }
1173
817
  if (spatialIndex === "h3" /* H3 */) {
1174
818
  return h3GetResolution(data[0].id);
@@ -1213,39 +857,176 @@ var DEFAULT_TILE_RESOLUTION = 0.5;
1213
857
  var DEFAULT_AGGREGATION_RES_LEVEL_H3 = 4;
1214
858
  var DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN = 6;
1215
859
 
860
+ // src/filters/tileFeaturesRaster.ts
861
+ import {
862
+ cellToChildren as _cellToChildren,
863
+ cellToTile,
864
+ geometryToCells as geometryToCells2,
865
+ getResolution as getResolution2
866
+ } from "quadbin";
867
+ function tileFeaturesRaster({
868
+ tiles,
869
+ ...options
870
+ }) {
871
+ const metadataByBand = {};
872
+ for (const band of options.rasterMetadata.bands) {
873
+ metadataByBand[band.name] = { ...band, nodata: Number(band.nodata) };
874
+ }
875
+ tiles = tiles.filter(isRasterTileVisible);
876
+ if (tiles.length === 0) return [];
877
+ const tileResolution = getResolution2(tiles[0].index.q);
878
+ const tileBlockSize = tiles[0].data.blockSize;
879
+ const cellResolution = tileResolution + BigInt(Math.log2(tileBlockSize));
880
+ const spatialFilterCells = new Set(
881
+ geometryToCells2(options.spatialFilter, cellResolution)
882
+ );
883
+ const data = /* @__PURE__ */ new Map();
884
+ for (const tile of tiles) {
885
+ const parent = tile.index.q;
886
+ const children = cellToChildrenSorted(parent, cellResolution);
887
+ for (let i = 0; i < children.length; i++) {
888
+ if (!spatialFilterCells.has(children[i])) continue;
889
+ const cellData = {};
890
+ let cellDataExists = false;
891
+ for (const band in tile.data.cells.numericProps) {
892
+ const value = tile.data.cells.numericProps[band].value[i];
893
+ const bandMetadata = metadataByBand[band];
894
+ if (isValidBandValue(value, bandMetadata.nodata)) {
895
+ cellData[band] = tile.data.cells.numericProps[band].value[i];
896
+ cellDataExists = true;
897
+ }
898
+ }
899
+ if (cellDataExists) {
900
+ data.set(children[i], cellData);
901
+ }
902
+ }
903
+ }
904
+ return Array.from(data.values());
905
+ }
906
+ function isRasterTile(tile) {
907
+ return !!tile.data?.cells;
908
+ }
909
+ function isRasterTileVisible(tile) {
910
+ return !!(tile.isVisible && tile.data?.cells?.numericProps);
911
+ }
912
+ function cellToChildrenSorted(parent, resolution) {
913
+ return _cellToChildren(parent, resolution).sort(
914
+ (cellA, cellB) => {
915
+ const tileA = cellToTile(cellA);
916
+ const tileB = cellToTile(cellB);
917
+ if (tileA.y !== tileB.y) {
918
+ return tileA.y > tileB.y ? 1 : -1;
919
+ }
920
+ return tileA.x > tileB.x ? 1 : -1;
921
+ }
922
+ );
923
+ }
924
+ function isValidBandValue(value, nodata) {
925
+ return Number.isNaN(value) ? false : nodata !== value;
926
+ }
927
+
928
+ // src/utils.ts
929
+ var FILTER_TYPES = new Set(Object.values(FilterType));
930
+ var isFilterType = (type) => FILTER_TYPES.has(type);
931
+ function getApplicableFilters(owner, filters) {
932
+ if (!filters) return {};
933
+ const applicableFilters = {};
934
+ for (const column in filters) {
935
+ for (const type in filters[column]) {
936
+ if (!isFilterType(type)) continue;
937
+ const filter = filters[column][type];
938
+ const isApplicable = !owner || !filter?.owner || filter?.owner !== owner;
939
+ if (filter && isApplicable) {
940
+ applicableFilters[column] || (applicableFilters[column] = {});
941
+ applicableFilters[column][type] = filter;
942
+ }
943
+ }
944
+ }
945
+ return applicableFilters;
946
+ }
947
+ function normalizeObjectKeys(el) {
948
+ if (Array.isArray(el)) {
949
+ return el.map((value) => normalizeObjectKeys(value));
950
+ } else if (typeof el !== "object") {
951
+ return el;
952
+ }
953
+ return Object.entries(el).reduce(
954
+ (acc, [key, value]) => {
955
+ acc[key.toLowerCase()] = typeof value === "object" && value ? normalizeObjectKeys(value) : value;
956
+ return acc;
957
+ },
958
+ {}
959
+ );
960
+ }
961
+ function assert2(condition, message) {
962
+ if (!condition) {
963
+ throw new Error(message);
964
+ }
965
+ }
966
+ var _InvalidColumnError = class _InvalidColumnError extends Error {
967
+ constructor(message) {
968
+ super(`${_InvalidColumnError.NAME}: ${message}`);
969
+ this.name = _InvalidColumnError.NAME;
970
+ }
971
+ static is(error) {
972
+ return error instanceof _InvalidColumnError || error.message?.includes(_InvalidColumnError.NAME);
973
+ }
974
+ };
975
+ __publicField(_InvalidColumnError, "NAME", "InvalidColumnError");
976
+ var InvalidColumnError = _InvalidColumnError;
977
+ function isEmptyObject(object) {
978
+ for (const _ in object) {
979
+ return false;
980
+ }
981
+ return true;
982
+ }
983
+ var isObject = (x) => x !== null && typeof x === "object";
984
+ var isPureObject = (x) => isObject(x) && x.constructor === {}.constructor;
985
+
1216
986
  // src/filters/tileFeatures.ts
1217
987
  function tileFeatures({
1218
- tiles: tiles2,
988
+ tiles,
1219
989
  spatialFilter,
1220
990
  uniqueIdProperty,
1221
991
  tileFormat,
1222
992
  spatialDataColumn = DEFAULT_GEO_COLUMN,
1223
993
  spatialDataType,
994
+ rasterMetadata,
1224
995
  options = {}
1225
996
  }) {
1226
- if (spatialDataType !== "geo") {
1227
- return tileFeaturesSpatialIndex({
1228
- tiles: tiles2,
997
+ if (spatialDataType === "geo") {
998
+ return tileFeaturesGeometries({
999
+ tiles,
1000
+ tileFormat,
1001
+ spatialFilter,
1002
+ uniqueIdProperty,
1003
+ options
1004
+ });
1005
+ }
1006
+ if (tiles.some(isRasterTile)) {
1007
+ assert2(rasterMetadata, "Missing raster metadata");
1008
+ return tileFeaturesRaster({
1009
+ tiles,
1229
1010
  spatialFilter,
1230
1011
  spatialDataColumn,
1231
- spatialDataType
1012
+ spatialDataType,
1013
+ rasterMetadata
1232
1014
  });
1233
1015
  }
1234
- return tileFeaturesGeometries({
1235
- tiles: tiles2,
1236
- tileFormat,
1016
+ return tileFeaturesSpatialIndex({
1017
+ tiles,
1237
1018
  spatialFilter,
1238
- uniqueIdProperty,
1239
- options
1019
+ spatialDataColumn,
1020
+ spatialDataType
1240
1021
  });
1241
1022
  }
1242
1023
 
1243
1024
  // src/deck/get-data-filter-extension-props.ts
1244
- function getDataFilterExtensionProps(filters, filtersLogicalOperator, filterSize) {
1245
- filterSize ?? (filterSize = 4);
1025
+ var DEFAULT_FILTER_SIZE = 4;
1026
+ function getDataFilterExtensionProps(filters, filtersLogicalOperator) {
1246
1027
  const { filtersWithoutTimeType, timeColumn, timeFilter } = getFiltersByType(filters);
1247
1028
  return {
1248
- filterRange: getFilterRange(timeFilter, filterSize),
1029
+ filterRange: getFilterRange(timeFilter, DEFAULT_FILTER_SIZE),
1249
1030
  updateTriggers: getUpdateTriggers(
1250
1031
  filtersWithoutTimeType,
1251
1032
  timeColumn,
@@ -1255,7 +1036,7 @@ function getDataFilterExtensionProps(filters, filtersLogicalOperator, filterSize
1255
1036
  filtersWithoutTimeType,
1256
1037
  timeColumn,
1257
1038
  timeFilter,
1258
- filterSize,
1039
+ DEFAULT_FILTER_SIZE,
1259
1040
  filtersLogicalOperator
1260
1041
  )
1261
1042
  };
@@ -1321,64 +1102,6 @@ function getFilterValue(filtersWithoutTimeType, timeColumn, timeFilter, filterSi
1321
1102
  };
1322
1103
  }
1323
1104
 
1324
- // src/utils.ts
1325
- var FILTER_TYPES = new Set(Object.values(FilterType));
1326
- var isFilterType = (type) => FILTER_TYPES.has(type);
1327
- function getApplicableFilters(owner, filters) {
1328
- if (!filters) return {};
1329
- const applicableFilters = {};
1330
- for (const column in filters) {
1331
- for (const type in filters[column]) {
1332
- if (!isFilterType(type)) continue;
1333
- const filter = filters[column][type];
1334
- const isApplicable = !owner || !filter?.owner || filter?.owner !== owner;
1335
- if (filter && isApplicable) {
1336
- applicableFilters[column] || (applicableFilters[column] = {});
1337
- applicableFilters[column][type] = filter;
1338
- }
1339
- }
1340
- }
1341
- return applicableFilters;
1342
- }
1343
- function normalizeObjectKeys(el) {
1344
- if (Array.isArray(el)) {
1345
- return el.map((value) => normalizeObjectKeys(value));
1346
- } else if (typeof el !== "object") {
1347
- return el;
1348
- }
1349
- return Object.entries(el).reduce(
1350
- (acc, [key, value]) => {
1351
- acc[key.toLowerCase()] = typeof value === "object" && value ? normalizeObjectKeys(value) : value;
1352
- return acc;
1353
- },
1354
- {}
1355
- );
1356
- }
1357
- function assert2(condition, message) {
1358
- if (!condition) {
1359
- throw new Error(message);
1360
- }
1361
- }
1362
- var _InvalidColumnError = class _InvalidColumnError extends Error {
1363
- constructor(message) {
1364
- super(`${_InvalidColumnError.NAME}: ${message}`);
1365
- this.name = _InvalidColumnError.NAME;
1366
- }
1367
- static is(error) {
1368
- return error instanceof _InvalidColumnError || error.message?.includes(_InvalidColumnError.NAME);
1369
- }
1370
- };
1371
- __publicField(_InvalidColumnError, "NAME", "InvalidColumnError");
1372
- var InvalidColumnError = _InvalidColumnError;
1373
- function isEmptyObject(object) {
1374
- for (const _ in object) {
1375
- return false;
1376
- }
1377
- return true;
1378
- }
1379
- var isObject = (x) => x !== null && typeof x === "object";
1380
- var isPureObject = (x) => isObject(x) && x.constructor === {}.constructor;
1381
-
1382
1105
  // src/filters.ts
1383
1106
  function addFilter(filters, { column, type, values, owner }) {
1384
1107
  if (!filters[column]) {
@@ -2446,17 +2169,6 @@ var WidgetQuerySource = class extends WidgetRemoteSource {
2446
2169
  }
2447
2170
  };
2448
2171
 
2449
- // src/widget-sources/widget-table-source.ts
2450
- var WidgetTableSource = class extends WidgetRemoteSource {
2451
- getModelSource(filters, filterOwner) {
2452
- return {
2453
- ...super._getModelSource(filters, filterOwner),
2454
- type: "table",
2455
- data: this.props.tableName
2456
- };
2457
- }
2458
- };
2459
-
2460
2172
  // src/operations/aggregation.ts
2461
2173
  var aggregationFunctions = {
2462
2174
  count: (values) => values.length,
@@ -2811,8 +2523,8 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
2811
2523
  * After tiles are loaded, {@link extractTileFeatures} must be called
2812
2524
  * before computing statistics on the tiles.
2813
2525
  */
2814
- loadTiles(tiles2) {
2815
- this._tiles = tiles2;
2526
+ loadTiles(tiles) {
2527
+ this._tiles = tiles;
2816
2528
  this._features.length = 0;
2817
2529
  }
2818
2530
  /** Configures options used to extract features from tiles. */
@@ -2826,12 +2538,10 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
2826
2538
  return;
2827
2539
  }
2828
2540
  this._features = tileFeatures({
2829
- tiles: this._tiles,
2830
- tileFormat: this.props.tileFormat,
2541
+ ...this.props,
2831
2542
  ...this._tileFeatureExtractOptions,
2832
- spatialFilter,
2833
- spatialDataColumn: this.props.spatialDataColumn,
2834
- spatialDataType: this.props.spatialDataType
2543
+ tiles: this._tiles,
2544
+ spatialFilter
2835
2545
  });
2836
2546
  prevInputs.spatialFilter = spatialFilter;
2837
2547
  }
@@ -2862,12 +2572,6 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
2862
2572
  filterOwner,
2863
2573
  spatialFilter
2864
2574
  }) {
2865
- if (operation === "custom") {
2866
- throw new Error("Custom aggregation not supported for tilesets");
2867
- }
2868
- if (column && column !== "*" || operation !== "count") {
2869
- assertColumn(this._features, column);
2870
- }
2871
2575
  const filteredFeatures = this._getFilteredFeatures(
2872
2576
  spatialFilter,
2873
2577
  filters,
@@ -2876,6 +2580,12 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
2876
2580
  if (filteredFeatures.length === 0 && operation !== "count") {
2877
2581
  return { value: null };
2878
2582
  }
2583
+ if (operation === "custom") {
2584
+ throw new Error("Custom aggregation not supported for tilesets");
2585
+ }
2586
+ if (column && column !== "*" || operation !== "count") {
2587
+ assertColumn(this._features, column);
2588
+ }
2879
2589
  const targetOperation = aggregationFunctions[operation];
2880
2590
  return {
2881
2591
  value: targetOperation(filteredFeatures, column, joinOperation)
@@ -3040,7 +2750,6 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
3040
2750
  filterOwner,
3041
2751
  spatialFilter
3042
2752
  }) {
3043
- assertColumn(this._features, column);
3044
2753
  const filteredFeatures = this._getFilteredFeatures(
3045
2754
  spatialFilter,
3046
2755
  filters,
@@ -3049,6 +2758,7 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
3049
2758
  if (!this._features.length) {
3050
2759
  return null;
3051
2760
  }
2761
+ assertColumn(this._features, column);
3052
2762
  return {
3053
2763
  min: aggregationFunctions.min(filteredFeatures, column),
3054
2764
  max: aggregationFunctions.max(filteredFeatures, column)
@@ -3143,9 +2853,8 @@ var WidgetTilesetSource = class extends WidgetSource {
3143
2853
  function onMessage(e) {
3144
2854
  const response = e.data;
3145
2855
  if (response.requestId !== requestId) return;
3146
- if (signal?.aborted) {
3147
- reject(new Error(signal.reason));
3148
- } else if (response.ok) {
2856
+ if (signal?.aborted) return;
2857
+ if (response.ok) {
3149
2858
  resolve(response.result);
3150
2859
  } else {
3151
2860
  reject(new Error(response.error));
@@ -3178,19 +2887,26 @@ var WidgetTilesetSource = class extends WidgetSource {
3178
2887
  * After tiles are loaded, {@link extractTileFeatures} must be called
3179
2888
  * before computing statistics on the tiles.
3180
2889
  */
3181
- loadTiles(tiles2) {
2890
+ loadTiles(tiles) {
3182
2891
  if (!this._workerEnabled) {
3183
- return this._localImpl.loadTiles(tiles2);
2892
+ return this._localImpl.loadTiles(tiles);
3184
2893
  }
3185
2894
  const worker = this._getWorker();
3186
- tiles2 = tiles2.map(({ id, bbox, data }) => ({
3187
- id,
3188
- bbox,
3189
- data
3190
- }));
2895
+ tiles = tiles.map(
2896
+ ({ id, index, bbox, isVisible, data }) => {
2897
+ const tile = {
2898
+ id,
2899
+ index,
2900
+ isVisible,
2901
+ data,
2902
+ bbox
2903
+ };
2904
+ return tile;
2905
+ }
2906
+ );
3191
2907
  worker.postMessage({
3192
2908
  method: "loadTiles" /* LOAD_TILES */,
3193
- params: [tiles2]
2909
+ params: [tiles]
3194
2910
  });
3195
2911
  }
3196
2912
  /** Configures options used to extract features from tiles. */
@@ -3272,6 +2988,21 @@ var WidgetTilesetSource = class extends WidgetSource {
3272
2988
  }
3273
2989
  };
3274
2990
 
2991
+ // src/widget-sources/widget-raster-source.ts
2992
+ var WidgetRasterSource = class extends WidgetTilesetSource {
2993
+ };
2994
+
2995
+ // src/widget-sources/widget-table-source.ts
2996
+ var WidgetTableSource = class extends WidgetRemoteSource {
2997
+ getModelSource(filters, filterOwner) {
2998
+ return {
2999
+ ...super._getModelSource(filters, filterOwner),
3000
+ type: "table",
3001
+ data: this.props.tableName
3002
+ };
3003
+ }
3004
+ };
3005
+
3275
3006
  // src/sources/h3-query-source.ts
3276
3007
  var h3QuerySource = async function(options) {
3277
3008
  const {
@@ -3376,10 +3107,17 @@ var rasterSource = async function(options) {
3376
3107
  if (filters) {
3377
3108
  urlParameters.filters = filters;
3378
3109
  }
3379
- return baseSource(
3380
- "raster",
3381
- options,
3382
- urlParameters
3110
+ return baseSource("raster", options, urlParameters).then(
3111
+ (result) => ({
3112
+ ...result,
3113
+ widgetSource: new WidgetRasterSource({
3114
+ ...options,
3115
+ tileFormat: getTileFormat(result),
3116
+ spatialDataColumn: "quadbin",
3117
+ spatialDataType: "quadbin",
3118
+ rasterMetadata: result.raster_metadata
3119
+ })
3120
+ })
3383
3121
  );
3384
3122
  };
3385
3123
 
@@ -3622,6 +3360,7 @@ export {
3622
3360
  SpatialIndex,
3623
3361
  TileFormat,
3624
3362
  WidgetQuerySource,
3363
+ WidgetRasterSource,
3625
3364
  WidgetRemoteSource,
3626
3365
  WidgetSource,
3627
3366
  WidgetTableSource,