@carto/api-client 0.5.7-alpha.5 → 0.5.7

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.
@@ -1727,6 +1727,143 @@ init_cjs_shims();
1727
1727
  // src/filters/tileFeaturesGeometries.ts
1728
1728
  init_cjs_shims();
1729
1729
 
1730
+ // src/utils/transformTileCoordsToWGS84.ts
1731
+ init_cjs_shims();
1732
+
1733
+ // node_modules/@math.gl/core/dist/index.js
1734
+ init_cjs_shims();
1735
+
1736
+ // node_modules/@math.gl/core/dist/lib/common.js
1737
+ init_cjs_shims();
1738
+ var RADIANS_TO_DEGREES = 1 / Math.PI * 180;
1739
+ var DEGREES_TO_RADIANS = 1 / 180 * Math.PI;
1740
+ var DEFAULT_CONFIG = {
1741
+ EPSILON: 1e-12,
1742
+ debug: false,
1743
+ precision: 4,
1744
+ printTypes: false,
1745
+ printDegrees: false,
1746
+ printRowMajor: true,
1747
+ _cartographicRadians: false
1748
+ };
1749
+ globalThis.mathgl = globalThis.mathgl || { config: { ...DEFAULT_CONFIG } };
1750
+ var config = globalThis.mathgl.config;
1751
+ function isArray(value) {
1752
+ return Array.isArray(value) || ArrayBuffer.isView(value) && !(value instanceof DataView);
1753
+ }
1754
+ function lerp(a, b, t) {
1755
+ if (isArray(a)) {
1756
+ return a.map((ai, i) => lerp(ai, b[i], t));
1757
+ }
1758
+ return t * b + (1 - t) * a;
1759
+ }
1760
+
1761
+ // node_modules/@math.gl/web-mercator/dist/index.js
1762
+ init_cjs_shims();
1763
+
1764
+ // node_modules/@math.gl/web-mercator/dist/web-mercator-viewport.js
1765
+ init_cjs_shims();
1766
+
1767
+ // node_modules/@math.gl/web-mercator/dist/math-utils.js
1768
+ init_cjs_shims();
1769
+
1770
+ // node_modules/@math.gl/web-mercator/dist/web-mercator-utils.js
1771
+ init_cjs_shims();
1772
+
1773
+ // node_modules/@math.gl/web-mercator/dist/assert.js
1774
+ init_cjs_shims();
1775
+ function assert(condition, message) {
1776
+ if (!condition) {
1777
+ throw new Error(message || "@math.gl/web-mercator: assertion failed.");
1778
+ }
1779
+ }
1780
+
1781
+ // node_modules/@math.gl/web-mercator/dist/web-mercator-utils.js
1782
+ var PI = Math.PI;
1783
+ var PI_4 = PI / 4;
1784
+ var DEGREES_TO_RADIANS2 = PI / 180;
1785
+ var RADIANS_TO_DEGREES2 = 180 / PI;
1786
+ var TILE_SIZE = 512;
1787
+ function lngLatToWorld(lngLat) {
1788
+ const [lng, lat] = lngLat;
1789
+ assert(Number.isFinite(lng));
1790
+ assert(Number.isFinite(lat) && lat >= -90 && lat <= 90, "invalid latitude");
1791
+ const lambda2 = lng * DEGREES_TO_RADIANS2;
1792
+ const phi2 = lat * DEGREES_TO_RADIANS2;
1793
+ const x = TILE_SIZE * (lambda2 + PI) / (2 * PI);
1794
+ const y = TILE_SIZE * (PI + Math.log(Math.tan(PI_4 + phi2 * 0.5))) / (2 * PI);
1795
+ return [x, y];
1796
+ }
1797
+ function worldToLngLat(xy) {
1798
+ const [x, y] = xy;
1799
+ const lambda2 = x / TILE_SIZE * (2 * PI) - PI;
1800
+ const phi2 = 2 * (Math.atan(Math.exp(y / TILE_SIZE * (2 * PI) - PI)) - PI_4);
1801
+ return [lambda2 * RADIANS_TO_DEGREES2, phi2 * RADIANS_TO_DEGREES2];
1802
+ }
1803
+
1804
+ // node_modules/@math.gl/web-mercator/dist/fit-bounds.js
1805
+ init_cjs_shims();
1806
+
1807
+ // node_modules/@math.gl/web-mercator/dist/get-bounds.js
1808
+ init_cjs_shims();
1809
+ var DEGREES_TO_RADIANS3 = Math.PI / 180;
1810
+
1811
+ // node_modules/@math.gl/web-mercator/dist/normalize-viewport-props.js
1812
+ init_cjs_shims();
1813
+
1814
+ // node_modules/@math.gl/web-mercator/dist/fly-to-viewport.js
1815
+ init_cjs_shims();
1816
+
1817
+ // src/utils/transformTileCoordsToWGS84.ts
1818
+ var TRANSFORM_FN = {
1819
+ Point: transformPoint,
1820
+ MultiPoint: transformMultiPoint,
1821
+ LineString: transformLineString,
1822
+ MultiLineString: transformMultiLineString,
1823
+ Polygon: transformPolygon,
1824
+ MultiPolygon: transformMultiPolygon
1825
+ };
1826
+ function transformTileCoordsToWGS84(geometry, bbox2) {
1827
+ const [west, south, east, north] = bbox2;
1828
+ const nw = lngLatToWorld([west, north]);
1829
+ const se = lngLatToWorld([east, south]);
1830
+ const projectedBbox = [nw, se];
1831
+ if (geometry.type === "GeometryCollection") {
1832
+ throw new Error("Unsupported geometry type GeometryCollection");
1833
+ }
1834
+ const transformFn = TRANSFORM_FN[geometry.type];
1835
+ const coordinates = transformFn(geometry.coordinates, projectedBbox);
1836
+ return { ...geometry, coordinates };
1837
+ }
1838
+ function transformPoint([pointX, pointY], [nw, se]) {
1839
+ const x = lerp(nw[0], se[0], pointX);
1840
+ const y = lerp(nw[1], se[1], pointY);
1841
+ return worldToLngLat([x, y]);
1842
+ }
1843
+ function getPoints(geometry, bbox2) {
1844
+ return geometry.map((g) => transformPoint(g, bbox2));
1845
+ }
1846
+ function transformMultiPoint(multiPoint, bbox2) {
1847
+ return getPoints(multiPoint, bbox2);
1848
+ }
1849
+ function transformLineString(line, bbox2) {
1850
+ return getPoints(line, bbox2);
1851
+ }
1852
+ function transformMultiLineString(multiLineString2, bbox2) {
1853
+ return multiLineString2.map(
1854
+ (lineString2) => transformLineString(lineString2, bbox2)
1855
+ );
1856
+ }
1857
+ function transformPolygon(polygon2, bbox2) {
1858
+ return polygon2.map((polygonRing) => getPoints(polygonRing, bbox2));
1859
+ }
1860
+ function transformMultiPolygon(multiPolygon2, bbox2) {
1861
+ return multiPolygon2.map((polygon2) => transformPolygon(polygon2, bbox2));
1862
+ }
1863
+
1864
+ // src/filters/tileIntersection.ts
1865
+ init_cjs_shims();
1866
+
1730
1867
  // node_modules/@turf/bbox-polygon/dist/esm/index.js
1731
1868
  init_cjs_shims();
1732
1869
  function bboxPolygon(bbox2, options = {}) {
@@ -2058,7 +2195,7 @@ var MAX_SAFE_INTEGER = 9007199254740991;
2058
2195
  var POWS_TEN = [1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13];
2059
2196
  var SQRT_BASE = 1e7;
2060
2197
  var MAX = 1e9;
2061
- function clone(configObject) {
2198
+ function clone2(configObject) {
2062
2199
  var div, convertBase, parseNumeric, P = BigNumber2.prototype = { constructor: BigNumber2, toString: null, valueOf: null }, ONE = new BigNumber2(1), DECIMAL_PLACES = 20, ROUNDING_MODE = 4, TO_EXP_NEG = -7, TO_EXP_POS = 21, MIN_EXP = -1e7, MAX_EXP = 1e7, CRYPTO = false, MODULO_MODE = 1, POW_PRECISION = 0, FORMAT = {
2063
2200
  prefix: "",
2064
2201
  groupSize: 3,
@@ -2184,7 +2321,7 @@ function clone(configObject) {
2184
2321
  x.c = [x.e = 0];
2185
2322
  }
2186
2323
  }
2187
- BigNumber2.clone = clone;
2324
+ BigNumber2.clone = clone2;
2188
2325
  BigNumber2.ROUND_UP = 0;
2189
2326
  BigNumber2.ROUND_DOWN = 1;
2190
2327
  BigNumber2.ROUND_CEIL = 2;
@@ -3387,7 +3524,7 @@ function toFixedPoint(str, e, z) {
3387
3524
  }
3388
3525
  return str;
3389
3526
  }
3390
- var BigNumber = clone();
3527
+ var BigNumber = clone2();
3391
3528
  var bignumber_default = BigNumber;
3392
3529
 
3393
3530
  // node_modules/splaytree-ts/dist/esm/index.js
@@ -4960,99 +5097,13 @@ var turf_intersect_default = intersect;
4960
5097
 
4961
5098
  // src/utils/transformToTileCoords.ts
4962
5099
  init_cjs_shims();
4963
-
4964
- // node_modules/@math.gl/web-mercator/dist/index.js
4965
- init_cjs_shims();
4966
-
4967
- // node_modules/@math.gl/web-mercator/dist/web-mercator-viewport.js
4968
- init_cjs_shims();
4969
-
4970
- // node_modules/@math.gl/web-mercator/dist/math-utils.js
4971
- init_cjs_shims();
4972
-
4973
- // node_modules/@math.gl/core/dist/index.js
4974
- init_cjs_shims();
4975
-
4976
- // node_modules/@math.gl/core/dist/lib/common.js
4977
- init_cjs_shims();
4978
- var RADIANS_TO_DEGREES = 1 / Math.PI * 180;
4979
- var DEGREES_TO_RADIANS = 1 / 180 * Math.PI;
4980
- var DEFAULT_CONFIG = {
4981
- EPSILON: 1e-12,
4982
- debug: false,
4983
- precision: 4,
4984
- printTypes: false,
4985
- printDegrees: false,
4986
- printRowMajor: true,
4987
- _cartographicRadians: false
4988
- };
4989
- globalThis.mathgl = globalThis.mathgl || { config: { ...DEFAULT_CONFIG } };
4990
- var config = globalThis.mathgl.config;
4991
- function isArray(value) {
4992
- return Array.isArray(value) || ArrayBuffer.isView(value) && !(value instanceof DataView);
4993
- }
4994
- function lerp(a, b, t) {
4995
- if (isArray(a)) {
4996
- return a.map((ai, i) => lerp(ai, b[i], t));
4997
- }
4998
- return t * b + (1 - t) * a;
4999
- }
5000
-
5001
- // node_modules/@math.gl/web-mercator/dist/web-mercator-utils.js
5002
- init_cjs_shims();
5003
-
5004
- // node_modules/@math.gl/web-mercator/dist/assert.js
5005
- init_cjs_shims();
5006
- function assert(condition, message) {
5007
- if (!condition) {
5008
- throw new Error(message || "@math.gl/web-mercator: assertion failed.");
5009
- }
5010
- }
5011
-
5012
- // node_modules/@math.gl/web-mercator/dist/web-mercator-utils.js
5013
- var PI = Math.PI;
5014
- var PI_4 = PI / 4;
5015
- var DEGREES_TO_RADIANS2 = PI / 180;
5016
- var RADIANS_TO_DEGREES2 = 180 / PI;
5017
- var TILE_SIZE = 512;
5018
- function lngLatToWorld(lngLat) {
5019
- const [lng, lat] = lngLat;
5020
- assert(Number.isFinite(lng));
5021
- assert(Number.isFinite(lat) && lat >= -90 && lat <= 90, "invalid latitude");
5022
- const lambda2 = lng * DEGREES_TO_RADIANS2;
5023
- const phi2 = lat * DEGREES_TO_RADIANS2;
5024
- const x = TILE_SIZE * (lambda2 + PI) / (2 * PI);
5025
- const y = TILE_SIZE * (PI + Math.log(Math.tan(PI_4 + phi2 * 0.5))) / (2 * PI);
5026
- return [x, y];
5027
- }
5028
- function worldToLngLat(xy) {
5029
- const [x, y] = xy;
5030
- const lambda2 = x / TILE_SIZE * (2 * PI) - PI;
5031
- const phi2 = 2 * (Math.atan(Math.exp(y / TILE_SIZE * (2 * PI) - PI)) - PI_4);
5032
- return [lambda2 * RADIANS_TO_DEGREES2, phi2 * RADIANS_TO_DEGREES2];
5033
- }
5034
-
5035
- // node_modules/@math.gl/web-mercator/dist/fit-bounds.js
5036
- init_cjs_shims();
5037
-
5038
- // node_modules/@math.gl/web-mercator/dist/get-bounds.js
5039
- init_cjs_shims();
5040
- var DEGREES_TO_RADIANS3 = Math.PI / 180;
5041
-
5042
- // node_modules/@math.gl/web-mercator/dist/normalize-viewport-props.js
5043
- init_cjs_shims();
5044
-
5045
- // node_modules/@math.gl/web-mercator/dist/fly-to-viewport.js
5046
- init_cjs_shims();
5047
-
5048
- // src/utils/transformToTileCoords.ts
5049
- var TRANSFORM_FN = {
5050
- Point: transformPoint,
5051
- MultiPoint: transformMultiPoint,
5052
- LineString: transformLineString,
5053
- MultiLineString: transformMultiLineString,
5054
- Polygon: transformPolygon,
5055
- MultiPolygon: transformMultiPolygon
5100
+ var TRANSFORM_FN2 = {
5101
+ Point: transformPoint2,
5102
+ MultiPoint: transformMultiPoint2,
5103
+ LineString: transformLineString2,
5104
+ MultiLineString: transformMultiLineString2,
5105
+ Polygon: transformPolygon2,
5106
+ MultiPolygon: transformMultiPolygon2
5056
5107
  };
5057
5108
  function transformToTileCoords(geometry, bbox2) {
5058
5109
  const [west, south, east, north] = bbox2;
@@ -5062,34 +5113,34 @@ function transformToTileCoords(geometry, bbox2) {
5062
5113
  if (geometry.type === "GeometryCollection") {
5063
5114
  throw new Error("Unsupported geometry type GeometryCollection");
5064
5115
  }
5065
- const transformFn = TRANSFORM_FN[geometry.type];
5116
+ const transformFn = TRANSFORM_FN2[geometry.type];
5066
5117
  const coordinates = transformFn(geometry.coordinates, projectedBbox);
5067
5118
  return { ...geometry, coordinates };
5068
5119
  }
5069
- function transformPoint([pointX, pointY], [nw, se]) {
5120
+ function transformPoint2([pointX, pointY], [nw, se]) {
5070
5121
  const x = inverseLerp(nw[0], se[0], pointX);
5071
5122
  const y = inverseLerp(nw[1], se[1], pointY);
5072
5123
  return [x, y];
5073
5124
  }
5074
- function getPoints(geometry, bbox2) {
5075
- return geometry.map((g) => transformPoint(projectFlat(g), bbox2));
5125
+ function getPoints2(geometry, bbox2) {
5126
+ return geometry.map((g) => transformPoint2(projectFlat(g), bbox2));
5076
5127
  }
5077
- function transformMultiPoint(multiPoint, bbox2) {
5078
- return getPoints(multiPoint, bbox2);
5128
+ function transformMultiPoint2(multiPoint, bbox2) {
5129
+ return getPoints2(multiPoint, bbox2);
5079
5130
  }
5080
- function transformLineString(line, bbox2) {
5081
- return getPoints(line, bbox2);
5131
+ function transformLineString2(line, bbox2) {
5132
+ return getPoints2(line, bbox2);
5082
5133
  }
5083
- function transformMultiLineString(multiLineString2, bbox2) {
5134
+ function transformMultiLineString2(multiLineString2, bbox2) {
5084
5135
  return multiLineString2.map(
5085
- (lineString2) => transformLineString(lineString2, bbox2)
5136
+ (lineString2) => transformLineString2(lineString2, bbox2)
5086
5137
  );
5087
5138
  }
5088
- function transformPolygon(polygon2, bbox2) {
5089
- return polygon2.map((polygonRing) => getPoints(polygonRing, bbox2));
5090
- }
5091
- function transformMultiPolygon(multiPolygon2, bbox2) {
5092
- return multiPolygon2.map((polygon2) => transformPolygon(polygon2, bbox2));
5139
+ function transformPolygon2(polygon2, bbox2) {
5140
+ return polygon2.map((polygonRing) => getPoints2(polygonRing, bbox2));
5141
+ }
5142
+ function transformMultiPolygon2(multiPolygon2, bbox2) {
5143
+ return multiPolygon2.map((polygon2) => transformPolygon2(polygon2, bbox2));
5093
5144
  }
5094
5145
  function projectFlat(xyz) {
5095
5146
  return lngLatToWorld(xyz);
@@ -5098,52 +5149,181 @@ function inverseLerp(a, b, x) {
5098
5149
  return (x - a) / (b - a);
5099
5150
  }
5100
5151
 
5101
- // src/utils/transformTileCoordsToWGS84.ts
5152
+ // src/filters/tileIntersection.ts
5153
+ var import_quadbin = require("quadbin");
5154
+ var import_h3_js = require("h3-js");
5155
+
5156
+ // node_modules/@turf/bbox-clip/dist/esm/index.js
5102
5157
  init_cjs_shims();
5103
- var TRANSFORM_FN2 = {
5104
- Point: transformPoint2,
5105
- MultiPoint: transformMultiPoint2,
5106
- LineString: transformLineString2,
5107
- MultiLineString: transformMultiLineString2,
5108
- Polygon: transformPolygon2,
5109
- MultiPolygon: transformMultiPolygon2
5110
- };
5111
- function transformTileCoordsToWGS84(geometry, bbox2) {
5112
- const [west, south, east, north] = bbox2;
5113
- const nw = lngLatToWorld([west, north]);
5114
- const se = lngLatToWorld([east, south]);
5115
- const projectedBbox = [nw, se];
5116
- if (geometry.type === "GeometryCollection") {
5117
- throw new Error("Unsupported geometry type GeometryCollection");
5158
+ function lineclip(points, bbox2, result) {
5159
+ var len = points.length, codeA = bitCode(points[0], bbox2), part = [], i, codeB, lastCode;
5160
+ let a;
5161
+ let b;
5162
+ if (!result) result = [];
5163
+ for (i = 1; i < len; i++) {
5164
+ a = points[i - 1];
5165
+ b = points[i];
5166
+ codeB = lastCode = bitCode(b, bbox2);
5167
+ while (true) {
5168
+ if (!(codeA | codeB)) {
5169
+ part.push(a);
5170
+ if (codeB !== lastCode) {
5171
+ part.push(b);
5172
+ if (i < len - 1) {
5173
+ result.push(part);
5174
+ part = [];
5175
+ }
5176
+ } else if (i === len - 1) {
5177
+ part.push(b);
5178
+ }
5179
+ break;
5180
+ } else if (codeA & codeB) {
5181
+ break;
5182
+ } else if (codeA) {
5183
+ a = intersect2(a, b, codeA, bbox2);
5184
+ codeA = bitCode(a, bbox2);
5185
+ } else {
5186
+ b = intersect2(a, b, codeB, bbox2);
5187
+ codeB = bitCode(b, bbox2);
5188
+ }
5189
+ }
5190
+ codeA = lastCode;
5118
5191
  }
5119
- const transformFn = TRANSFORM_FN2[geometry.type];
5120
- const coordinates = transformFn(geometry.coordinates, projectedBbox);
5121
- return { ...geometry, coordinates };
5192
+ if (part.length) result.push(part);
5193
+ return result;
5122
5194
  }
5123
- function transformPoint2([pointX, pointY], [nw, se]) {
5124
- const x = lerp(nw[0], se[0], pointX);
5125
- const y = lerp(nw[1], se[1], pointY);
5126
- return worldToLngLat([x, y]);
5195
+ function polygonclip(points, bbox2) {
5196
+ var result, edge, prev, prevInside, i, p, inside;
5197
+ for (edge = 1; edge <= 8; edge *= 2) {
5198
+ result = [];
5199
+ prev = points[points.length - 1];
5200
+ prevInside = !(bitCode(prev, bbox2) & edge);
5201
+ for (i = 0; i < points.length; i++) {
5202
+ p = points[i];
5203
+ inside = !(bitCode(p, bbox2) & edge);
5204
+ if (inside !== prevInside) result.push(intersect2(prev, p, edge, bbox2));
5205
+ if (inside) result.push(p);
5206
+ prev = p;
5207
+ prevInside = inside;
5208
+ }
5209
+ points = result;
5210
+ if (!points.length) break;
5211
+ }
5212
+ return result;
5127
5213
  }
5128
- function getPoints2(geometry, bbox2) {
5129
- return geometry.map((g) => transformPoint2(g, bbox2));
5214
+ function intersect2(a, b, edge, bbox2) {
5215
+ return edge & 8 ? [a[0] + (b[0] - a[0]) * (bbox2[3] - a[1]) / (b[1] - a[1]), bbox2[3]] : edge & 4 ? [a[0] + (b[0] - a[0]) * (bbox2[1] - a[1]) / (b[1] - a[1]), bbox2[1]] : edge & 2 ? [bbox2[2], a[1] + (b[1] - a[1]) * (bbox2[2] - a[0]) / (b[0] - a[0])] : edge & 1 ? [bbox2[0], a[1] + (b[1] - a[1]) * (bbox2[0] - a[0]) / (b[0] - a[0])] : null;
5130
5216
  }
5131
- function transformMultiPoint2(multiPoint, bbox2) {
5132
- return getPoints2(multiPoint, bbox2);
5217
+ function bitCode(p, bbox2) {
5218
+ var code = 0;
5219
+ if (p[0] < bbox2[0]) code |= 1;
5220
+ else if (p[0] > bbox2[2]) code |= 2;
5221
+ if (p[1] < bbox2[1]) code |= 4;
5222
+ else if (p[1] > bbox2[3]) code |= 8;
5223
+ return code;
5133
5224
  }
5134
- function transformLineString2(line, bbox2) {
5135
- return getPoints2(line, bbox2);
5225
+ function bboxClip(feature2, bbox2) {
5226
+ const geom = getGeom(feature2);
5227
+ const type = geom.type;
5228
+ const properties = feature2.type === "Feature" ? feature2.properties : {};
5229
+ let coords = geom.coordinates;
5230
+ switch (type) {
5231
+ case "LineString":
5232
+ case "MultiLineString": {
5233
+ const lines = [];
5234
+ if (type === "LineString") {
5235
+ coords = [coords];
5236
+ }
5237
+ coords.forEach((line) => {
5238
+ lineclip(line, bbox2, lines);
5239
+ });
5240
+ if (lines.length === 1) {
5241
+ return lineString(lines[0], properties);
5242
+ }
5243
+ return multiLineString(lines, properties);
5244
+ }
5245
+ case "Polygon":
5246
+ return polygon(clipPolygon(coords, bbox2), properties);
5247
+ case "MultiPolygon":
5248
+ return multiPolygon(
5249
+ coords.map((poly) => {
5250
+ return clipPolygon(poly, bbox2);
5251
+ }),
5252
+ properties
5253
+ );
5254
+ default:
5255
+ throw new Error("geometry " + type + " not supported");
5256
+ }
5136
5257
  }
5137
- function transformMultiLineString2(multiLineString2, bbox2) {
5138
- return multiLineString2.map(
5139
- (lineString2) => transformLineString2(lineString2, bbox2)
5258
+ function clipPolygon(rings, bbox2) {
5259
+ const outRings = [];
5260
+ for (const ring of rings) {
5261
+ const clipped = polygonclip(ring, bbox2);
5262
+ if (clipped.length > 0) {
5263
+ if (clipped[0][0] !== clipped[clipped.length - 1][0] || clipped[0][1] !== clipped[clipped.length - 1][1]) {
5264
+ clipped.push(clipped[0]);
5265
+ }
5266
+ if (clipped.length >= 4) {
5267
+ outRings.push(clipped);
5268
+ }
5269
+ }
5270
+ }
5271
+ return outRings;
5272
+ }
5273
+ var turf_bbox_clip_default = bboxClip;
5274
+
5275
+ // src/filters/tileIntersection.ts
5276
+ function intersectTileGeometry(tileBbox, tileFormat, spatialFilter) {
5277
+ const tilePolygon = turf_bbox_polygon_default(tileBbox);
5278
+ if (!spatialFilter || turf_boolean_within_default(tilePolygon, spatialFilter)) {
5279
+ return true;
5280
+ }
5281
+ const clippedSpatialFilter = turf_intersect_default(
5282
+ featureCollection([tilePolygon, feature(spatialFilter)])
5140
5283
  );
5284
+ if (!clippedSpatialFilter) {
5285
+ return false;
5286
+ }
5287
+ return tileFormat === "mvt" /* MVT */ ? transformToTileCoords(clippedSpatialFilter.geometry, tileBbox) : clippedSpatialFilter.geometry;
5141
5288
  }
5142
- function transformPolygon2(polygon2, bbox2) {
5143
- return polygon2.map((polygonRing) => getPoints2(polygonRing, bbox2));
5289
+ function intersectTileRaster(parent, cellResolution, spatialFilter) {
5290
+ return intersectTileQuadbin(parent, cellResolution, spatialFilter);
5144
5291
  }
5145
- function transformMultiPolygon2(multiPolygon2, bbox2) {
5146
- return multiPolygon2.map((polygon2) => transformPolygon2(polygon2, bbox2));
5292
+ function intersectTileQuadbin(parent, cellResolution, spatialFilter) {
5293
+ const tilePolygon = (0, import_quadbin.cellToBoundary)(parent);
5294
+ if (!spatialFilter || turf_boolean_within_default(tilePolygon, spatialFilter)) {
5295
+ return true;
5296
+ }
5297
+ const clippedSpatialFilter = turf_intersect_default(
5298
+ featureCollection([feature(tilePolygon), feature(spatialFilter)])
5299
+ );
5300
+ if (!clippedSpatialFilter) {
5301
+ return false;
5302
+ }
5303
+ const cells = (0, import_quadbin.geometryToCells)(
5304
+ clippedSpatialFilter.geometry,
5305
+ cellResolution
5306
+ );
5307
+ return new Set(cells);
5308
+ }
5309
+ var BBOX_WEST = [-180, -90, 0, 90];
5310
+ var BBOX_EAST = [0, -90, 180, 90];
5311
+ function intersectTileH3(cellResolution, spatialFilter) {
5312
+ if (!spatialFilter) {
5313
+ return true;
5314
+ }
5315
+ const spatialFilterFeature = feature(spatialFilter);
5316
+ const cellsWest = (0, import_h3_js.polygonToCells)(
5317
+ turf_bbox_clip_default(spatialFilterFeature, BBOX_WEST).geometry.coordinates,
5318
+ cellResolution,
5319
+ true
5320
+ );
5321
+ const cellsEast = (0, import_h3_js.polygonToCells)(
5322
+ turf_bbox_clip_default(spatialFilterFeature, BBOX_EAST).geometry.coordinates,
5323
+ cellResolution,
5324
+ true
5325
+ );
5326
+ return new Set(cellsWest.concat(cellsEast));
5147
5327
  }
5148
5328
 
5149
5329
  // src/filters/tileFeaturesGeometries.ts
@@ -5160,55 +5340,45 @@ function tileFeaturesGeometries({
5160
5340
  if (tile.isVisible === false || !tile.data) {
5161
5341
  continue;
5162
5342
  }
5163
- const bbox2 = [
5343
+ const tileBbox = [
5164
5344
  tile.bbox.west,
5165
5345
  tile.bbox.south,
5166
5346
  tile.bbox.east,
5167
5347
  tile.bbox.north
5168
5348
  ];
5169
- const bboxToGeom = turf_bbox_polygon_default(bbox2);
5170
- const tileIsFullyVisible = turf_boolean_within_default(bboxToGeom, spatialFilter);
5171
- const spatialFilterFeature = {
5172
- type: "Feature",
5173
- geometry: spatialFilter,
5174
- properties: {}
5175
- };
5176
- const clippedGeometryToIntersect = turf_intersect_default(
5177
- featureCollection([bboxToGeom, spatialFilterFeature])
5349
+ const intersection3 = intersectTileGeometry(
5350
+ tileBbox,
5351
+ tileFormat,
5352
+ spatialFilter
5178
5353
  );
5179
- if (!clippedGeometryToIntersect) {
5180
- continue;
5181
- }
5182
- const transformedGeometryToIntersect = tileFormat === "mvt" /* MVT */ ? transformToTileCoords(clippedGeometryToIntersect.geometry, bbox2) : clippedGeometryToIntersect.geometry;
5354
+ if (intersection3 === false) continue;
5355
+ const transformedSpatialFilter = intersection3 === true ? void 0 : intersection3;
5183
5356
  calculateFeatures({
5184
5357
  map,
5185
- tileIsFullyVisible,
5186
- geometryIntersection: transformedGeometryToIntersect,
5358
+ spatialFilter: transformedSpatialFilter,
5187
5359
  data: tile.data.points,
5188
5360
  type: "Point",
5189
- bbox: bbox2,
5361
+ bbox: tileBbox,
5190
5362
  tileFormat,
5191
5363
  uniqueIdProperty,
5192
5364
  options
5193
5365
  });
5194
5366
  calculateFeatures({
5195
5367
  map,
5196
- tileIsFullyVisible,
5197
- geometryIntersection: transformedGeometryToIntersect,
5368
+ spatialFilter: transformedSpatialFilter,
5198
5369
  data: tile.data.lines,
5199
5370
  type: "LineString",
5200
- bbox: bbox2,
5371
+ bbox: tileBbox,
5201
5372
  tileFormat,
5202
5373
  uniqueIdProperty,
5203
5374
  options
5204
5375
  });
5205
5376
  calculateFeatures({
5206
5377
  map,
5207
- tileIsFullyVisible,
5208
- geometryIntersection: transformedGeometryToIntersect,
5378
+ spatialFilter: transformedSpatialFilter,
5209
5379
  data: tile.data.polygons,
5210
5380
  type: "Polygon",
5211
- bbox: bbox2,
5381
+ bbox: tileBbox,
5212
5382
  tileFormat,
5213
5383
  uniqueIdProperty,
5214
5384
  options
@@ -5226,7 +5396,7 @@ function processTileFeatureProperties({
5226
5396
  tileFormat,
5227
5397
  uniqueIdProperty,
5228
5398
  storeGeometry,
5229
- geometryIntersection
5399
+ spatialFilter
5230
5400
  }) {
5231
5401
  const tileProps = getPropertiesFromTile(data, startIndex);
5232
5402
  const uniquePropertyValue = getUniquePropertyValue(
@@ -5238,7 +5408,7 @@ function processTileFeatureProperties({
5238
5408
  return;
5239
5409
  }
5240
5410
  let geometry = null;
5241
- if (storeGeometry || geometryIntersection) {
5411
+ if (storeGeometry || spatialFilter) {
5242
5412
  const { positions } = data;
5243
5413
  const ringCoordinates = getRingCoordinatesFor(
5244
5414
  startIndex,
@@ -5247,7 +5417,7 @@ function processTileFeatureProperties({
5247
5417
  );
5248
5418
  geometry = getFeatureByType(ringCoordinates, type);
5249
5419
  }
5250
- if (geometry && geometryIntersection && !turf_boolean_intersects_default(geometry, geometryIntersection)) {
5420
+ if (geometry && spatialFilter && !turf_boolean_intersects_default(geometry, spatialFilter)) {
5251
5421
  return;
5252
5422
  }
5253
5423
  const properties = parseProperties(tileProps);
@@ -5259,7 +5429,7 @@ function processTileFeatureProperties({
5259
5429
  function addIntersectedFeaturesInTile({
5260
5430
  map,
5261
5431
  data,
5262
- geometryIntersection,
5432
+ spatialFilter,
5263
5433
  type,
5264
5434
  bbox: bbox2,
5265
5435
  tileFormat,
@@ -5281,7 +5451,7 @@ function addIntersectedFeaturesInTile({
5281
5451
  tileFormat,
5282
5452
  uniqueIdProperty,
5283
5453
  storeGeometry,
5284
- geometryIntersection
5454
+ spatialFilter
5285
5455
  });
5286
5456
  }
5287
5457
  }
@@ -5337,232 +5507,110 @@ function getUniquePropertyValue(tileProps, uniqueIdProperty, map) {
5337
5507
  function getValueFromTileProps(tileProps, propertyName) {
5338
5508
  const { properties, numericProps } = tileProps;
5339
5509
  return numericProps[propertyName] || properties[propertyName];
5340
- }
5341
- function getFeatureByType(coordinates, type) {
5342
- switch (type) {
5343
- case "Polygon":
5344
- return { type: "Polygon", coordinates: [coordinates] };
5345
- case "LineString":
5346
- return { type: "LineString", coordinates };
5347
- case "Point":
5348
- return { type: "Point", coordinates: coordinates[0] };
5349
- default:
5350
- throw new Error("Invalid geometry type");
5351
- }
5352
- }
5353
- function getRingCoordinatesFor(startIndex, endIndex, positions) {
5354
- const ringCoordinates = [];
5355
- for (let j = startIndex; j < endIndex; j++) {
5356
- ringCoordinates.push(
5357
- Array.from(
5358
- positions.value.subarray(j * positions.size, (j + 1) * positions.size)
5359
- )
5360
- );
5361
- }
5362
- return ringCoordinates;
5363
- }
5364
- function calculateFeatures({
5365
- map,
5366
- tileIsFullyVisible,
5367
- geometryIntersection,
5368
- data,
5369
- type,
5370
- bbox: bbox2,
5371
- tileFormat,
5372
- uniqueIdProperty,
5373
- options
5374
- }) {
5375
- if (!data?.properties.length) {
5376
- return;
5377
- }
5378
- if (tileIsFullyVisible) {
5379
- addAllFeaturesInTile({
5380
- map,
5381
- data,
5382
- type,
5383
- bbox: bbox2,
5384
- tileFormat,
5385
- uniqueIdProperty,
5386
- options
5387
- });
5388
- } else {
5389
- addIntersectedFeaturesInTile({
5390
- map,
5391
- data,
5392
- geometryIntersection,
5393
- type,
5394
- bbox: bbox2,
5395
- tileFormat,
5396
- uniqueIdProperty,
5397
- options
5398
- });
5399
- }
5400
- }
5401
- function addAllFeaturesInTile({
5402
- map,
5403
- data,
5404
- type,
5405
- bbox: bbox2,
5406
- tileFormat,
5407
- uniqueIdProperty,
5408
- options
5409
- }) {
5410
- const indices = getIndices(data, type);
5411
- const storeGeometry = options?.storeGeometry || false;
5412
- for (let i = 0; i < indices.length - 1; i++) {
5413
- const startIndex = indices[i];
5414
- const endIndex = indices[i + 1];
5415
- processTileFeatureProperties({
5416
- map,
5417
- data,
5418
- startIndex,
5419
- endIndex,
5420
- type,
5421
- bbox: bbox2,
5422
- tileFormat,
5423
- uniqueIdProperty,
5424
- storeGeometry
5425
- });
5426
- }
5427
- }
5428
- function createIndicesForPoints(data) {
5429
- const featureIds = data.featureIds.value;
5430
- const lastFeatureId = featureIds[featureIds.length - 1];
5431
- const PointIndicesArray = featureIds.constructor;
5432
- const pointIndices = {
5433
- value: new PointIndicesArray(featureIds.length + 1),
5434
- size: 1
5435
- };
5436
- pointIndices.value.set(featureIds);
5437
- pointIndices.value.set([lastFeatureId + 1], featureIds.length);
5438
- return pointIndices;
5439
- }
5440
-
5441
- // src/filters/tileFeaturesSpatialIndex.ts
5442
- init_cjs_shims();
5443
- var import_quadbin = require("quadbin");
5444
-
5445
- // node_modules/@turf/bbox-clip/dist/esm/index.js
5446
- init_cjs_shims();
5447
- function lineclip(points, bbox2, result) {
5448
- var len = points.length, codeA = bitCode(points[0], bbox2), part = [], i, codeB, lastCode;
5449
- let a;
5450
- let b;
5451
- if (!result) result = [];
5452
- for (i = 1; i < len; i++) {
5453
- a = points[i - 1];
5454
- b = points[i];
5455
- codeB = lastCode = bitCode(b, bbox2);
5456
- while (true) {
5457
- if (!(codeA | codeB)) {
5458
- part.push(a);
5459
- if (codeB !== lastCode) {
5460
- part.push(b);
5461
- if (i < len - 1) {
5462
- result.push(part);
5463
- part = [];
5464
- }
5465
- } else if (i === len - 1) {
5466
- part.push(b);
5467
- }
5468
- break;
5469
- } else if (codeA & codeB) {
5470
- break;
5471
- } else if (codeA) {
5472
- a = intersect2(a, b, codeA, bbox2);
5473
- codeA = bitCode(a, bbox2);
5474
- } else {
5475
- b = intersect2(a, b, codeB, bbox2);
5476
- codeB = bitCode(b, bbox2);
5477
- }
5478
- }
5479
- codeA = lastCode;
5480
- }
5481
- if (part.length) result.push(part);
5482
- return result;
5483
- }
5484
- function polygonclip(points, bbox2) {
5485
- var result, edge, prev, prevInside, i, p, inside;
5486
- for (edge = 1; edge <= 8; edge *= 2) {
5487
- result = [];
5488
- prev = points[points.length - 1];
5489
- prevInside = !(bitCode(prev, bbox2) & edge);
5490
- for (i = 0; i < points.length; i++) {
5491
- p = points[i];
5492
- inside = !(bitCode(p, bbox2) & edge);
5493
- if (inside !== prevInside) result.push(intersect2(prev, p, edge, bbox2));
5494
- if (inside) result.push(p);
5495
- prev = p;
5496
- prevInside = inside;
5497
- }
5498
- points = result;
5499
- if (!points.length) break;
5500
- }
5501
- return result;
5502
- }
5503
- function intersect2(a, b, edge, bbox2) {
5504
- return edge & 8 ? [a[0] + (b[0] - a[0]) * (bbox2[3] - a[1]) / (b[1] - a[1]), bbox2[3]] : edge & 4 ? [a[0] + (b[0] - a[0]) * (bbox2[1] - a[1]) / (b[1] - a[1]), bbox2[1]] : edge & 2 ? [bbox2[2], a[1] + (b[1] - a[1]) * (bbox2[2] - a[0]) / (b[0] - a[0])] : edge & 1 ? [bbox2[0], a[1] + (b[1] - a[1]) * (bbox2[0] - a[0]) / (b[0] - a[0])] : null;
5505
- }
5506
- function bitCode(p, bbox2) {
5507
- var code = 0;
5508
- if (p[0] < bbox2[0]) code |= 1;
5509
- else if (p[0] > bbox2[2]) code |= 2;
5510
- if (p[1] < bbox2[1]) code |= 4;
5511
- else if (p[1] > bbox2[3]) code |= 8;
5512
- return code;
5513
- }
5514
- function bboxClip(feature2, bbox2) {
5515
- const geom = getGeom(feature2);
5516
- const type = geom.type;
5517
- const properties = feature2.type === "Feature" ? feature2.properties : {};
5518
- let coords = geom.coordinates;
5519
- switch (type) {
5520
- case "LineString":
5521
- case "MultiLineString": {
5522
- const lines = [];
5523
- if (type === "LineString") {
5524
- coords = [coords];
5525
- }
5526
- coords.forEach((line) => {
5527
- lineclip(line, bbox2, lines);
5528
- });
5529
- if (lines.length === 1) {
5530
- return lineString(lines[0], properties);
5531
- }
5532
- return multiLineString(lines, properties);
5533
- }
5510
+ }
5511
+ function getFeatureByType(coordinates, type) {
5512
+ switch (type) {
5534
5513
  case "Polygon":
5535
- return polygon(clipPolygon(coords, bbox2), properties);
5536
- case "MultiPolygon":
5537
- return multiPolygon(
5538
- coords.map((poly) => {
5539
- return clipPolygon(poly, bbox2);
5540
- }),
5541
- properties
5542
- );
5514
+ return { type: "Polygon", coordinates: [coordinates] };
5515
+ case "LineString":
5516
+ return { type: "LineString", coordinates };
5517
+ case "Point":
5518
+ return { type: "Point", coordinates: coordinates[0] };
5543
5519
  default:
5544
- throw new Error("geometry " + type + " not supported");
5520
+ throw new Error("Invalid geometry type");
5545
5521
  }
5546
5522
  }
5547
- function clipPolygon(rings, bbox2) {
5548
- const outRings = [];
5549
- for (const ring of rings) {
5550
- const clipped = polygonclip(ring, bbox2);
5551
- if (clipped.length > 0) {
5552
- if (clipped[0][0] !== clipped[clipped.length - 1][0] || clipped[0][1] !== clipped[clipped.length - 1][1]) {
5553
- clipped.push(clipped[0]);
5554
- }
5555
- if (clipped.length >= 4) {
5556
- outRings.push(clipped);
5557
- }
5558
- }
5523
+ function getRingCoordinatesFor(startIndex, endIndex, positions) {
5524
+ const ringCoordinates = [];
5525
+ for (let j = startIndex; j < endIndex; j++) {
5526
+ ringCoordinates.push(
5527
+ Array.from(
5528
+ positions.value.subarray(j * positions.size, (j + 1) * positions.size)
5529
+ )
5530
+ );
5559
5531
  }
5560
- return outRings;
5532
+ return ringCoordinates;
5533
+ }
5534
+ function calculateFeatures({
5535
+ map,
5536
+ spatialFilter,
5537
+ data,
5538
+ type,
5539
+ bbox: bbox2,
5540
+ tileFormat,
5541
+ uniqueIdProperty,
5542
+ options
5543
+ }) {
5544
+ if (!data?.properties.length) {
5545
+ return;
5546
+ }
5547
+ if (!spatialFilter) {
5548
+ addAllFeaturesInTile({
5549
+ map,
5550
+ data,
5551
+ type,
5552
+ bbox: bbox2,
5553
+ tileFormat,
5554
+ uniqueIdProperty,
5555
+ options
5556
+ });
5557
+ } else {
5558
+ addIntersectedFeaturesInTile({
5559
+ map,
5560
+ data,
5561
+ spatialFilter,
5562
+ type,
5563
+ bbox: bbox2,
5564
+ tileFormat,
5565
+ uniqueIdProperty,
5566
+ options
5567
+ });
5568
+ }
5569
+ }
5570
+ function addAllFeaturesInTile({
5571
+ map,
5572
+ data,
5573
+ type,
5574
+ bbox: bbox2,
5575
+ tileFormat,
5576
+ uniqueIdProperty,
5577
+ options
5578
+ }) {
5579
+ const indices = getIndices(data, type);
5580
+ const storeGeometry = options?.storeGeometry || false;
5581
+ for (let i = 0; i < indices.length - 1; i++) {
5582
+ const startIndex = indices[i];
5583
+ const endIndex = indices[i + 1];
5584
+ processTileFeatureProperties({
5585
+ map,
5586
+ data,
5587
+ startIndex,
5588
+ endIndex,
5589
+ type,
5590
+ bbox: bbox2,
5591
+ tileFormat,
5592
+ uniqueIdProperty,
5593
+ storeGeometry
5594
+ });
5595
+ }
5596
+ }
5597
+ function createIndicesForPoints(data) {
5598
+ const featureIds = data.featureIds.value;
5599
+ const lastFeatureId = featureIds[featureIds.length - 1];
5600
+ const PointIndicesArray = featureIds.constructor;
5601
+ const pointIndices = {
5602
+ value: new PointIndicesArray(featureIds.length + 1),
5603
+ size: 1
5604
+ };
5605
+ pointIndices.value.set(featureIds);
5606
+ pointIndices.value.set([lastFeatureId + 1], featureIds.length);
5607
+ return pointIndices;
5561
5608
  }
5562
- var turf_bbox_clip_default = bboxClip;
5563
5609
 
5564
5610
  // src/filters/tileFeaturesSpatialIndex.ts
5565
- var import_h3_js = require("h3-js");
5611
+ init_cjs_shims();
5612
+ var import_quadbin2 = require("quadbin");
5613
+ var import_h3_js2 = require("h3-js");
5566
5614
  function tileFeaturesSpatialIndex({
5567
5615
  tiles,
5568
5616
  spatialFilter,
@@ -5571,58 +5619,52 @@ function tileFeaturesSpatialIndex({
5571
5619
  }) {
5572
5620
  const map = /* @__PURE__ */ new Map();
5573
5621
  const spatialIndex = getSpatialIndex(spatialDataType);
5574
- const resolution = getResolution(tiles, spatialIndex);
5622
+ const cellResolution = getResolution(tiles, spatialIndex);
5575
5623
  const spatialIndexIDName = spatialDataColumn ? spatialDataColumn : spatialIndex;
5576
- if (!resolution) {
5624
+ if (!cellResolution) {
5577
5625
  return [];
5578
5626
  }
5579
- const cells = getCellsCoverGeometry(spatialFilter, spatialIndex, resolution);
5580
- if (!cells?.length) {
5581
- return [];
5627
+ let intersection3;
5628
+ if (spatialIndex === "h3" /* H3 */) {
5629
+ intersection3 = intersectTileH3(cellResolution, spatialFilter);
5582
5630
  }
5583
- const cellsSet = new Set(cells);
5584
5631
  for (const tile of tiles) {
5585
5632
  if (tile.isVisible === false || !tile.data) {
5586
5633
  continue;
5587
5634
  }
5635
+ if (spatialIndex === "quadbin" /* QUADBIN */) {
5636
+ const parent = getTileIndex(tile, spatialIndex);
5637
+ intersection3 = intersectTileQuadbin(
5638
+ parent,
5639
+ cellResolution,
5640
+ spatialFilter
5641
+ );
5642
+ }
5643
+ if (!intersection3) continue;
5588
5644
  tile.data.forEach((d) => {
5589
- if (cellsSet.has(d.id)) {
5645
+ if (intersection3 === true || intersection3.has(d.id)) {
5590
5646
  map.set(d.id, { ...d.properties, [spatialIndexIDName]: d.id });
5591
5647
  }
5592
5648
  });
5593
5649
  }
5594
5650
  return Array.from(map.values());
5595
5651
  }
5652
+ function getTileIndex(tile, spatialIndex) {
5653
+ if (spatialIndex === "quadbin" /* QUADBIN */) {
5654
+ return tile.index.q;
5655
+ }
5656
+ return tile.id;
5657
+ }
5596
5658
  function getResolution(tiles, spatialIndex) {
5597
5659
  const data = tiles.find((tile) => tile.data?.length)?.data;
5598
5660
  if (!data) {
5599
5661
  return;
5600
5662
  }
5601
5663
  if (spatialIndex === "quadbin" /* QUADBIN */) {
5602
- return Number((0, import_quadbin.getResolution)(data[0].id));
5603
- }
5604
- if (spatialIndex === "h3" /* H3 */) {
5605
- return (0, import_h3_js.getResolution)(data[0].id);
5606
- }
5607
- }
5608
- var bboxWest = [-180, -90, 0, 90];
5609
- var bboxEast = [0, -90, 180, 90];
5610
- function getCellsCoverGeometry(geometry, spatialIndex, resolution) {
5611
- if (spatialIndex === "quadbin" /* QUADBIN */) {
5612
- return (0, import_quadbin.geometryToCells)(geometry, resolution);
5664
+ return Number((0, import_quadbin2.getResolution)(data[0].id));
5613
5665
  }
5614
5666
  if (spatialIndex === "h3" /* H3 */) {
5615
- return (0, import_h3_js.polygonToCells)(
5616
- turf_bbox_clip_default(geometry, bboxWest).geometry.coordinates,
5617
- resolution,
5618
- true
5619
- ).concat(
5620
- (0, import_h3_js.polygonToCells)(
5621
- turf_bbox_clip_default(geometry, bboxEast).geometry.coordinates,
5622
- resolution,
5623
- true
5624
- )
5625
- );
5667
+ return (0, import_h3_js2.getResolution)(data[0].id);
5626
5668
  }
5627
5669
  }
5628
5670
  function getSpatialIndex(spatialDataType) {
@@ -5650,66 +5692,7 @@ var DEFAULT_AGGREGATION_EXP = `1 AS ${DEFAULT_AGGREGATION_EXP_ALIAS}`;
5650
5692
 
5651
5693
  // src/filters/tileFeaturesRaster.ts
5652
5694
  init_cjs_shims();
5653
- var import_quadbin2 = require("quadbin");
5654
-
5655
- // src/utils/CellSet.ts
5656
- init_cjs_shims();
5657
- var EMPTY_U32 = 2 ** 32 - 1;
5658
- var CellSet = class {
5659
- constructor(cells) {
5660
- /** List of cells stored by the set. Stored by reference, without copying. */
5661
- __publicField(this, "cells");
5662
- /** DataView representing a single cell ID. Pre-allocated to reduce memory during queries. */
5663
- __publicField(this, "cellView", new DataView(new ArrayBuffer(8)));
5664
- /** Hash table, mapping a hash index (computed) to an index in the 'cells' array. */
5665
- __publicField(this, "hashTable");
5666
- this.cells = cells;
5667
- this.hashTable = new Uint32Array(hashBuckets(cells.length)).fill(EMPTY_U32);
5668
- for (let cellIndex = 0; cellIndex < cells.length; cellIndex++) {
5669
- this.hashTable[this.hashLookup(cells[cellIndex])] = cellIndex;
5670
- }
5671
- }
5672
- has(cell) {
5673
- const hashIndex = this.hashLookup(cell);
5674
- return this.hashTable[hashIndex] !== EMPTY_U32;
5675
- }
5676
- hashLookup(cell) {
5677
- this.cellView.setBigUint64(0, cell);
5678
- const hashval = hash(this.cellView);
5679
- const hashmod = this.hashTable.length - 1;
5680
- let bucket = hashval & hashmod;
5681
- for (let probe = 0; probe <= hashmod; probe++) {
5682
- const cellIndex = this.hashTable[bucket];
5683
- if (cellIndex === EMPTY_U32 || cell === this.cells[cellIndex]) {
5684
- return bucket;
5685
- }
5686
- bucket = bucket + probe + 1 & hashmod;
5687
- }
5688
- throw new Error("Hash table full.");
5689
- }
5690
- };
5691
- function hash(view, h = 0) {
5692
- const m = 1540483477;
5693
- const r = 24;
5694
- for (let i = 0, il = view.byteLength / 4; i < il; i++) {
5695
- let k = view.getUint32(i * 4);
5696
- k = Math.imul(k, m) >>> 0;
5697
- k = (k ^ k >> r) >>> 0;
5698
- k = Math.imul(k, m) >>> 0;
5699
- h = Math.imul(h, m) >>> 0;
5700
- h = (h ^ k) >>> 0;
5701
- }
5702
- return h;
5703
- }
5704
- function hashBuckets(initialCount) {
5705
- let buckets = 1;
5706
- while (buckets < initialCount + initialCount / 4) {
5707
- buckets *= 2;
5708
- }
5709
- return buckets;
5710
- }
5711
-
5712
- // src/filters/tileFeaturesRaster.ts
5695
+ var import_quadbin3 = require("quadbin");
5713
5696
  function tileFeaturesRaster({
5714
5697
  tiles,
5715
5698
  ...options
@@ -5720,18 +5703,23 @@ function tileFeaturesRaster({
5720
5703
  }
5721
5704
  tiles = tiles.filter(isRasterTileVisible);
5722
5705
  if (tiles.length === 0) return [];
5723
- const tileResolution = (0, import_quadbin2.getResolution)(tiles[0].index.q);
5706
+ const tileResolution = (0, import_quadbin3.getResolution)(tiles[0].index.q);
5724
5707
  const tileBlockSize = tiles[0].data.blockSize;
5725
5708
  const cellResolution = tileResolution + BigInt(Math.log2(tileBlockSize));
5726
- const spatialFilterCells = new CellSet(
5727
- (0, import_quadbin2.geometryToCells)(options.spatialFilter, cellResolution)
5728
- );
5729
5709
  const data = /* @__PURE__ */ new Map();
5730
5710
  for (const tile of tiles) {
5731
5711
  const parent = tile.index.q;
5732
- const children = cellToChildrenSorted(parent, cellResolution);
5733
- for (let i = 0; i < children.length; i++) {
5734
- if (!spatialFilterCells.has(children[i])) continue;
5712
+ const intersection3 = intersectTileRaster(
5713
+ parent,
5714
+ cellResolution,
5715
+ options.spatialFilter
5716
+ );
5717
+ if (intersection3 === false) continue;
5718
+ const tileSortedCells = cellToChildrenSorted(parent, cellResolution);
5719
+ for (let i = 0; i < tileSortedCells.length; i++) {
5720
+ if (intersection3 !== true && !intersection3.has(tileSortedCells[i])) {
5721
+ continue;
5722
+ }
5735
5723
  const cellData = {};
5736
5724
  let cellDataExists = false;
5737
5725
  for (const band in tile.data.cells.numericProps) {
@@ -5743,7 +5731,7 @@ function tileFeaturesRaster({
5743
5731
  }
5744
5732
  }
5745
5733
  if (cellDataExists) {
5746
- data.set(children[i], cellData);
5734
+ data.set(tileSortedCells[i], cellData);
5747
5735
  }
5748
5736
  }
5749
5737
  }
@@ -5756,10 +5744,10 @@ function isRasterTileVisible(tile) {
5756
5744
  return !!(tile.isVisible && tile.data?.cells?.numericProps);
5757
5745
  }
5758
5746
  function cellToChildrenSorted(parent, resolution) {
5759
- return (0, import_quadbin2.cellToChildren)(parent, resolution).sort(
5747
+ return (0, import_quadbin3.cellToChildren)(parent, resolution).sort(
5760
5748
  (cellA, cellB) => {
5761
- const tileA = (0, import_quadbin2.cellToTile)(cellA);
5762
- const tileB = (0, import_quadbin2.cellToTile)(cellB);
5749
+ const tileA = (0, import_quadbin3.cellToTile)(cellA);
5750
+ const tileB = (0, import_quadbin3.cellToTile)(cellB);
5763
5751
  if (tileA.y !== tileB.y) {
5764
5752
  return tileA.y > tileB.y ? 1 : -1;
5765
5753
  }
@@ -7520,7 +7508,7 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
7520
7508
  }
7521
7509
  _extractTileFeatures(spatialFilter) {
7522
7510
  const prevInputs = this._tileFeatureExtractPreviousInputs;
7523
- if (this._features.length && prevInputs.spatialFilter && booleanEqual(prevInputs.spatialFilter, spatialFilter)) {
7511
+ if (this._features.length && spatialFilterEquals(prevInputs.spatialFilter, spatialFilter)) {
7524
7512
  return;
7525
7513
  }
7526
7514
  this._features = tileFeatures({
@@ -7760,7 +7748,6 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
7760
7748
  * INTERNAL
7761
7749
  */
7762
7750
  _getFilteredFeatures(spatialFilter, filters, filterOwner) {
7763
- assert2(spatialFilter, "spatialFilter required for tilesets");
7764
7751
  this._extractTileFeatures(spatialFilter);
7765
7752
  return applyFilters(
7766
7753
  this._features,
@@ -7784,6 +7771,11 @@ function assertColumn(features, ...columnArgs) {
7784
7771
  function normalizeColumns(columns) {
7785
7772
  return Array.isArray(columns) ? columns : typeof columns === "string" ? [columns] : [];
7786
7773
  }
7774
+ function spatialFilterEquals(a, b) {
7775
+ if (a === b) return true;
7776
+ if (!a || !b) return false;
7777
+ return booleanEqual(a, b);
7778
+ }
7787
7779
 
7788
7780
  // src/widget-sources/widget-tileset-source.ts
7789
7781
  var WidgetTilesetSource = class extends WidgetSource {
@@ -10348,6 +10340,63 @@ function _getHexagonResolution(viewport, tileSize) {
10348
10340
  Math.floor(hexagonScaleFactor + latitudeScaleFactor - BIAS)
10349
10341
  );
10350
10342
  }
10343
+
10344
+ // src/utils/CellSet.ts
10345
+ init_cjs_shims();
10346
+ var EMPTY_U32 = 2 ** 32 - 1;
10347
+ var CellSet = class {
10348
+ constructor(cells) {
10349
+ /** List of cells stored by the set. Stored by reference, without copying. */
10350
+ __publicField(this, "cells");
10351
+ /** DataView representing a single cell ID. Pre-allocated to reduce memory during queries. */
10352
+ __publicField(this, "cellView", new DataView(new ArrayBuffer(8)));
10353
+ /** Hash table, mapping a hash index (computed) to an index in the 'cells' array. */
10354
+ __publicField(this, "hashTable");
10355
+ this.cells = cells;
10356
+ this.hashTable = new Uint32Array(hashBuckets(cells.length)).fill(EMPTY_U32);
10357
+ for (let cellIndex = 0; cellIndex < cells.length; cellIndex++) {
10358
+ this.hashTable[this.hashLookup(cells[cellIndex])] = cellIndex;
10359
+ }
10360
+ }
10361
+ has(cell) {
10362
+ const hashIndex = this.hashLookup(cell);
10363
+ return this.hashTable[hashIndex] !== EMPTY_U32;
10364
+ }
10365
+ hashLookup(cell) {
10366
+ this.cellView.setBigUint64(0, cell);
10367
+ const hashval = hash(this.cellView);
10368
+ const hashmod = this.hashTable.length - 1;
10369
+ let bucket = hashval & hashmod;
10370
+ for (let probe = 0; probe <= hashmod; probe++) {
10371
+ const cellIndex = this.hashTable[bucket];
10372
+ if (cellIndex === EMPTY_U32 || cell === this.cells[cellIndex]) {
10373
+ return bucket;
10374
+ }
10375
+ bucket = bucket + probe + 1 & hashmod;
10376
+ }
10377
+ throw new Error("Hash table full.");
10378
+ }
10379
+ };
10380
+ function hash(view, h = 0) {
10381
+ const m = 1540483477;
10382
+ const r = 24;
10383
+ for (let i = 0, il = view.byteLength / 4; i < il; i++) {
10384
+ let k = view.getUint32(i * 4);
10385
+ k = Math.imul(k, m) >>> 0;
10386
+ k = (k ^ k >> r) >>> 0;
10387
+ k = Math.imul(k, m) >>> 0;
10388
+ h = Math.imul(h, m) >>> 0;
10389
+ h = (h ^ k) >>> 0;
10390
+ }
10391
+ return h;
10392
+ }
10393
+ function hashBuckets(initialCount) {
10394
+ let buckets = 1;
10395
+ while (buckets < initialCount + initialCount / 4) {
10396
+ buckets *= 2;
10397
+ }
10398
+ return buckets;
10399
+ }
10351
10400
  // Annotate the CommonJS export names for ESM import in node:
10352
10401
  0 && (module.exports = {
10353
10402
  AggregationTypes,