@carto/api-client 0.5.6-alpha.bundle.4 → 0.5.7-alpha-optional-spatial-filter.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/worker.js CHANGED
@@ -90,6 +90,14 @@ var SpatialIndexColumn = Object.freeze({
90
90
  ["h3" /* H3 */]: ["h3", "hex", "h3id", "hex_id", "h3hex"],
91
91
  ["quadbin" /* QUADBIN */]: ["quadbin"]
92
92
  });
93
+ var AggregationTypes = {
94
+ Count: "count",
95
+ Avg: "avg",
96
+ Min: "min",
97
+ Max: "max",
98
+ Sum: "sum",
99
+ Custom: "custom"
100
+ };
93
101
 
94
102
  // src/utils.ts
95
103
  var FILTER_TYPES = new Set(Object.values(FilterType));
@@ -1497,6 +1505,110 @@ function geojsonFeatures({
1497
1505
  return Array.from(map.values());
1498
1506
  }
1499
1507
 
1508
+ // node_modules/@math.gl/core/dist/lib/common.js
1509
+ var RADIANS_TO_DEGREES = 1 / Math.PI * 180;
1510
+ var DEGREES_TO_RADIANS = 1 / 180 * Math.PI;
1511
+ var DEFAULT_CONFIG = {
1512
+ EPSILON: 1e-12,
1513
+ debug: false,
1514
+ precision: 4,
1515
+ printTypes: false,
1516
+ printDegrees: false,
1517
+ printRowMajor: true,
1518
+ _cartographicRadians: false
1519
+ };
1520
+ globalThis.mathgl = globalThis.mathgl || { config: { ...DEFAULT_CONFIG } };
1521
+ var config = globalThis.mathgl.config;
1522
+ function isArray(value) {
1523
+ return Array.isArray(value) || ArrayBuffer.isView(value) && !(value instanceof DataView);
1524
+ }
1525
+ function lerp(a, b, t) {
1526
+ if (isArray(a)) {
1527
+ return a.map((ai, i) => lerp(ai, b[i], t));
1528
+ }
1529
+ return t * b + (1 - t) * a;
1530
+ }
1531
+
1532
+ // node_modules/@math.gl/web-mercator/dist/assert.js
1533
+ function assert2(condition, message) {
1534
+ if (!condition) {
1535
+ throw new Error(message || "@math.gl/web-mercator: assertion failed.");
1536
+ }
1537
+ }
1538
+
1539
+ // node_modules/@math.gl/web-mercator/dist/web-mercator-utils.js
1540
+ var PI = Math.PI;
1541
+ var PI_4 = PI / 4;
1542
+ var DEGREES_TO_RADIANS2 = PI / 180;
1543
+ var RADIANS_TO_DEGREES2 = 180 / PI;
1544
+ var TILE_SIZE = 512;
1545
+ function lngLatToWorld(lngLat) {
1546
+ const [lng, lat] = lngLat;
1547
+ assert2(Number.isFinite(lng));
1548
+ assert2(Number.isFinite(lat) && lat >= -90 && lat <= 90, "invalid latitude");
1549
+ const lambda2 = lng * DEGREES_TO_RADIANS2;
1550
+ const phi2 = lat * DEGREES_TO_RADIANS2;
1551
+ const x = TILE_SIZE * (lambda2 + PI) / (2 * PI);
1552
+ const y = TILE_SIZE * (PI + Math.log(Math.tan(PI_4 + phi2 * 0.5))) / (2 * PI);
1553
+ return [x, y];
1554
+ }
1555
+ function worldToLngLat(xy) {
1556
+ const [x, y] = xy;
1557
+ const lambda2 = x / TILE_SIZE * (2 * PI) - PI;
1558
+ const phi2 = 2 * (Math.atan(Math.exp(y / TILE_SIZE * (2 * PI) - PI)) - PI_4);
1559
+ return [lambda2 * RADIANS_TO_DEGREES2, phi2 * RADIANS_TO_DEGREES2];
1560
+ }
1561
+
1562
+ // node_modules/@math.gl/web-mercator/dist/get-bounds.js
1563
+ var DEGREES_TO_RADIANS3 = Math.PI / 180;
1564
+
1565
+ // src/utils/transformTileCoordsToWGS84.ts
1566
+ var TRANSFORM_FN = {
1567
+ Point: transformPoint,
1568
+ MultiPoint: transformMultiPoint,
1569
+ LineString: transformLineString,
1570
+ MultiLineString: transformMultiLineString,
1571
+ Polygon: transformPolygon,
1572
+ MultiPolygon: transformMultiPolygon
1573
+ };
1574
+ function transformTileCoordsToWGS84(geometry, bbox2) {
1575
+ const [west, south, east, north] = bbox2;
1576
+ const nw = lngLatToWorld([west, north]);
1577
+ const se = lngLatToWorld([east, south]);
1578
+ const projectedBbox = [nw, se];
1579
+ if (geometry.type === "GeometryCollection") {
1580
+ throw new Error("Unsupported geometry type GeometryCollection");
1581
+ }
1582
+ const transformFn = TRANSFORM_FN[geometry.type];
1583
+ const coordinates = transformFn(geometry.coordinates, projectedBbox);
1584
+ return { ...geometry, coordinates };
1585
+ }
1586
+ function transformPoint([pointX, pointY], [nw, se]) {
1587
+ const x = lerp(nw[0], se[0], pointX);
1588
+ const y = lerp(nw[1], se[1], pointY);
1589
+ return worldToLngLat([x, y]);
1590
+ }
1591
+ function getPoints(geometry, bbox2) {
1592
+ return geometry.map((g) => transformPoint(g, bbox2));
1593
+ }
1594
+ function transformMultiPoint(multiPoint, bbox2) {
1595
+ return getPoints(multiPoint, bbox2);
1596
+ }
1597
+ function transformLineString(line, bbox2) {
1598
+ return getPoints(line, bbox2);
1599
+ }
1600
+ function transformMultiLineString(multiLineString2, bbox2) {
1601
+ return multiLineString2.map(
1602
+ (lineString2) => transformLineString(lineString2, bbox2)
1603
+ );
1604
+ }
1605
+ function transformPolygon(polygon2, bbox2) {
1606
+ return polygon2.map((polygonRing) => getPoints(polygonRing, bbox2));
1607
+ }
1608
+ function transformMultiPolygon(multiPolygon2, bbox2) {
1609
+ return multiPolygon2.map((polygon2) => transformPolygon(polygon2, bbox2));
1610
+ }
1611
+
1500
1612
  // node_modules/@turf/bbox-polygon/dist/esm/index.js
1501
1613
  function bboxPolygon(bbox2, options = {}) {
1502
1614
  const west = Number(bbox2[0]);
@@ -1815,7 +1927,7 @@ var MAX_SAFE_INTEGER = 9007199254740991;
1815
1927
  var POWS_TEN = [1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13];
1816
1928
  var SQRT_BASE = 1e7;
1817
1929
  var MAX = 1e9;
1818
- function clone(configObject) {
1930
+ function clone2(configObject) {
1819
1931
  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 = {
1820
1932
  prefix: "",
1821
1933
  groupSize: 3,
@@ -1941,7 +2053,7 @@ function clone(configObject) {
1941
2053
  x.c = [x.e = 0];
1942
2054
  }
1943
2055
  }
1944
- BigNumber2.clone = clone;
2056
+ BigNumber2.clone = clone2;
1945
2057
  BigNumber2.ROUND_UP = 0;
1946
2058
  BigNumber2.ROUND_DOWN = 1;
1947
2059
  BigNumber2.ROUND_CEIL = 2;
@@ -3144,7 +3256,7 @@ function toFixedPoint(str, e, z) {
3144
3256
  }
3145
3257
  return str;
3146
3258
  }
3147
- var BigNumber = clone();
3259
+ var BigNumber = clone2();
3148
3260
  var bignumber_default = BigNumber;
3149
3261
 
3150
3262
  // node_modules/splaytree-ts/dist/esm/index.js
@@ -4713,117 +4825,7 @@ function intersect(features, options = {}) {
4713
4825
  }
4714
4826
  var turf_intersect_default = intersect;
4715
4827
 
4716
- // node_modules/@math.gl/core/dist/lib/common.js
4717
- var RADIANS_TO_DEGREES = 1 / Math.PI * 180;
4718
- var DEGREES_TO_RADIANS = 1 / 180 * Math.PI;
4719
- var DEFAULT_CONFIG = {
4720
- EPSILON: 1e-12,
4721
- debug: false,
4722
- precision: 4,
4723
- printTypes: false,
4724
- printDegrees: false,
4725
- printRowMajor: true,
4726
- _cartographicRadians: false
4727
- };
4728
- globalThis.mathgl = globalThis.mathgl || { config: { ...DEFAULT_CONFIG } };
4729
- var config = globalThis.mathgl.config;
4730
- function isArray(value) {
4731
- return Array.isArray(value) || ArrayBuffer.isView(value) && !(value instanceof DataView);
4732
- }
4733
- function lerp(a, b, t) {
4734
- if (isArray(a)) {
4735
- return a.map((ai, i) => lerp(ai, b[i], t));
4736
- }
4737
- return t * b + (1 - t) * a;
4738
- }
4739
-
4740
- // node_modules/@math.gl/web-mercator/dist/assert.js
4741
- function assert2(condition, message) {
4742
- if (!condition) {
4743
- throw new Error(message || "@math.gl/web-mercator: assertion failed.");
4744
- }
4745
- }
4746
-
4747
- // node_modules/@math.gl/web-mercator/dist/web-mercator-utils.js
4748
- var PI = Math.PI;
4749
- var PI_4 = PI / 4;
4750
- var DEGREES_TO_RADIANS2 = PI / 180;
4751
- var RADIANS_TO_DEGREES2 = 180 / PI;
4752
- var TILE_SIZE = 512;
4753
- function lngLatToWorld(lngLat) {
4754
- const [lng, lat] = lngLat;
4755
- assert2(Number.isFinite(lng));
4756
- assert2(Number.isFinite(lat) && lat >= -90 && lat <= 90, "invalid latitude");
4757
- const lambda2 = lng * DEGREES_TO_RADIANS2;
4758
- const phi2 = lat * DEGREES_TO_RADIANS2;
4759
- const x = TILE_SIZE * (lambda2 + PI) / (2 * PI);
4760
- const y = TILE_SIZE * (PI + Math.log(Math.tan(PI_4 + phi2 * 0.5))) / (2 * PI);
4761
- return [x, y];
4762
- }
4763
- function worldToLngLat(xy) {
4764
- const [x, y] = xy;
4765
- const lambda2 = x / TILE_SIZE * (2 * PI) - PI;
4766
- const phi2 = 2 * (Math.atan(Math.exp(y / TILE_SIZE * (2 * PI) - PI)) - PI_4);
4767
- return [lambda2 * RADIANS_TO_DEGREES2, phi2 * RADIANS_TO_DEGREES2];
4768
- }
4769
-
4770
- // node_modules/@math.gl/web-mercator/dist/get-bounds.js
4771
- var DEGREES_TO_RADIANS3 = Math.PI / 180;
4772
-
4773
4828
  // src/utils/transformToTileCoords.ts
4774
- var TRANSFORM_FN = {
4775
- Point: transformPoint,
4776
- MultiPoint: transformMultiPoint,
4777
- LineString: transformLineString,
4778
- MultiLineString: transformMultiLineString,
4779
- Polygon: transformPolygon,
4780
- MultiPolygon: transformMultiPolygon
4781
- };
4782
- function transformToTileCoords(geometry, bbox2) {
4783
- const [west, south, east, north] = bbox2;
4784
- const nw = projectFlat([west, north]);
4785
- const se = projectFlat([east, south]);
4786
- const projectedBbox = [nw, se];
4787
- if (geometry.type === "GeometryCollection") {
4788
- throw new Error("Unsupported geometry type GeometryCollection");
4789
- }
4790
- const transformFn = TRANSFORM_FN[geometry.type];
4791
- const coordinates = transformFn(geometry.coordinates, projectedBbox);
4792
- return { ...geometry, coordinates };
4793
- }
4794
- function transformPoint([pointX, pointY], [nw, se]) {
4795
- const x = inverseLerp(nw[0], se[0], pointX);
4796
- const y = inverseLerp(nw[1], se[1], pointY);
4797
- return [x, y];
4798
- }
4799
- function getPoints(geometry, bbox2) {
4800
- return geometry.map((g) => transformPoint(projectFlat(g), bbox2));
4801
- }
4802
- function transformMultiPoint(multiPoint, bbox2) {
4803
- return getPoints(multiPoint, bbox2);
4804
- }
4805
- function transformLineString(line, bbox2) {
4806
- return getPoints(line, bbox2);
4807
- }
4808
- function transformMultiLineString(multiLineString2, bbox2) {
4809
- return multiLineString2.map(
4810
- (lineString2) => transformLineString(lineString2, bbox2)
4811
- );
4812
- }
4813
- function transformPolygon(polygon2, bbox2) {
4814
- return polygon2.map((polygonRing) => getPoints(polygonRing, bbox2));
4815
- }
4816
- function transformMultiPolygon(multiPolygon2, bbox2) {
4817
- return multiPolygon2.map((polygon2) => transformPolygon(polygon2, bbox2));
4818
- }
4819
- function projectFlat(xyz) {
4820
- return lngLatToWorld(xyz);
4821
- }
4822
- function inverseLerp(a, b, x) {
4823
- return (x - a) / (b - a);
4824
- }
4825
-
4826
- // src/utils/transformTileCoordsToWGS84.ts
4827
4829
  var TRANSFORM_FN2 = {
4828
4830
  Point: transformPoint2,
4829
4831
  MultiPoint: transformMultiPoint2,
@@ -4832,10 +4834,10 @@ var TRANSFORM_FN2 = {
4832
4834
  Polygon: transformPolygon2,
4833
4835
  MultiPolygon: transformMultiPolygon2
4834
4836
  };
4835
- function transformTileCoordsToWGS84(geometry, bbox2) {
4837
+ function transformToTileCoords(geometry, bbox2) {
4836
4838
  const [west, south, east, north] = bbox2;
4837
- const nw = lngLatToWorld([west, north]);
4838
- const se = lngLatToWorld([east, south]);
4839
+ const nw = projectFlat([west, north]);
4840
+ const se = projectFlat([east, south]);
4839
4841
  const projectedBbox = [nw, se];
4840
4842
  if (geometry.type === "GeometryCollection") {
4841
4843
  throw new Error("Unsupported geometry type GeometryCollection");
@@ -4845,12 +4847,12 @@ function transformTileCoordsToWGS84(geometry, bbox2) {
4845
4847
  return { ...geometry, coordinates };
4846
4848
  }
4847
4849
  function transformPoint2([pointX, pointY], [nw, se]) {
4848
- const x = lerp(nw[0], se[0], pointX);
4849
- const y = lerp(nw[1], se[1], pointY);
4850
- return worldToLngLat([x, y]);
4850
+ const x = inverseLerp(nw[0], se[0], pointX);
4851
+ const y = inverseLerp(nw[1], se[1], pointY);
4852
+ return [x, y];
4851
4853
  }
4852
4854
  function getPoints2(geometry, bbox2) {
4853
- return geometry.map((g) => transformPoint2(g, bbox2));
4855
+ return geometry.map((g) => transformPoint2(projectFlat(g), bbox2));
4854
4856
  }
4855
4857
  function transformMultiPoint2(multiPoint, bbox2) {
4856
4858
  return getPoints2(multiPoint, bbox2);
@@ -4869,70 +4871,257 @@ function transformPolygon2(polygon2, bbox2) {
4869
4871
  function transformMultiPolygon2(multiPolygon2, bbox2) {
4870
4872
  return multiPolygon2.map((polygon2) => transformPolygon2(polygon2, bbox2));
4871
4873
  }
4874
+ function projectFlat(xyz) {
4875
+ return lngLatToWorld(xyz);
4876
+ }
4877
+ function inverseLerp(a, b, x) {
4878
+ return (x - a) / (b - a);
4879
+ }
4872
4880
 
4873
- // src/filters/tileFeaturesGeometries.ts
4874
- var FEATURE_GEOM_PROPERTY = "__geomValue";
4875
- function tileFeaturesGeometries({
4876
- tiles,
4877
- tileFormat,
4878
- spatialFilter,
4879
- uniqueIdProperty,
4880
- options
4881
- }) {
4882
- const map = /* @__PURE__ */ new Map();
4883
- for (const tile of tiles) {
4884
- if (tile.isVisible === false || !tile.data) {
4885
- continue;
4886
- }
4887
- const bbox2 = [
4888
- tile.bbox.west,
4889
- tile.bbox.south,
4890
- tile.bbox.east,
4891
- tile.bbox.north
4892
- ];
4893
- const bboxToGeom = turf_bbox_polygon_default(bbox2);
4894
- const tileIsFullyVisible = turf_boolean_within_default(bboxToGeom, spatialFilter);
4895
- const spatialFilterFeature = {
4896
- type: "Feature",
4897
- geometry: spatialFilter,
4898
- properties: {}
4899
- };
4900
- const clippedGeometryToIntersect = turf_intersect_default(
4901
- featureCollection([bboxToGeom, spatialFilterFeature])
4902
- );
4903
- if (!clippedGeometryToIntersect) {
4904
- continue;
4905
- }
4906
- const transformedGeometryToIntersect = tileFormat === "mvt" /* MVT */ ? transformToTileCoords(clippedGeometryToIntersect.geometry, bbox2) : clippedGeometryToIntersect.geometry;
4907
- calculateFeatures({
4908
- map,
4909
- tileIsFullyVisible,
4910
- geometryIntersection: transformedGeometryToIntersect,
4881
+ // src/filters/tileIntersection.ts
4882
+ import {
4883
+ cellToBoundary as quadbinCellToBoundary,
4884
+ geometryToCells as quadbinGeometryToCells
4885
+ } from "quadbin";
4886
+ import {
4887
+ cellToBoundary as h3CellToBoundary,
4888
+ polygonToCells as h3PolygonToCells
4889
+ } from "h3-js";
4890
+
4891
+ // node_modules/@turf/bbox-clip/dist/esm/index.js
4892
+ function lineclip(points, bbox2, result) {
4893
+ var len = points.length, codeA = bitCode(points[0], bbox2), part = [], i, codeB, lastCode;
4894
+ let a;
4895
+ let b;
4896
+ if (!result) result = [];
4897
+ for (i = 1; i < len; i++) {
4898
+ a = points[i - 1];
4899
+ b = points[i];
4900
+ codeB = lastCode = bitCode(b, bbox2);
4901
+ while (true) {
4902
+ if (!(codeA | codeB)) {
4903
+ part.push(a);
4904
+ if (codeB !== lastCode) {
4905
+ part.push(b);
4906
+ if (i < len - 1) {
4907
+ result.push(part);
4908
+ part = [];
4909
+ }
4910
+ } else if (i === len - 1) {
4911
+ part.push(b);
4912
+ }
4913
+ break;
4914
+ } else if (codeA & codeB) {
4915
+ break;
4916
+ } else if (codeA) {
4917
+ a = intersect2(a, b, codeA, bbox2);
4918
+ codeA = bitCode(a, bbox2);
4919
+ } else {
4920
+ b = intersect2(a, b, codeB, bbox2);
4921
+ codeB = bitCode(b, bbox2);
4922
+ }
4923
+ }
4924
+ codeA = lastCode;
4925
+ }
4926
+ if (part.length) result.push(part);
4927
+ return result;
4928
+ }
4929
+ function polygonclip(points, bbox2) {
4930
+ var result, edge, prev, prevInside, i, p, inside;
4931
+ for (edge = 1; edge <= 8; edge *= 2) {
4932
+ result = [];
4933
+ prev = points[points.length - 1];
4934
+ prevInside = !(bitCode(prev, bbox2) & edge);
4935
+ for (i = 0; i < points.length; i++) {
4936
+ p = points[i];
4937
+ inside = !(bitCode(p, bbox2) & edge);
4938
+ if (inside !== prevInside) result.push(intersect2(prev, p, edge, bbox2));
4939
+ if (inside) result.push(p);
4940
+ prev = p;
4941
+ prevInside = inside;
4942
+ }
4943
+ points = result;
4944
+ if (!points.length) break;
4945
+ }
4946
+ return result;
4947
+ }
4948
+ function intersect2(a, b, edge, bbox2) {
4949
+ 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;
4950
+ }
4951
+ function bitCode(p, bbox2) {
4952
+ var code = 0;
4953
+ if (p[0] < bbox2[0]) code |= 1;
4954
+ else if (p[0] > bbox2[2]) code |= 2;
4955
+ if (p[1] < bbox2[1]) code |= 4;
4956
+ else if (p[1] > bbox2[3]) code |= 8;
4957
+ return code;
4958
+ }
4959
+ function bboxClip(feature2, bbox2) {
4960
+ const geom = getGeom(feature2);
4961
+ const type = geom.type;
4962
+ const properties = feature2.type === "Feature" ? feature2.properties : {};
4963
+ let coords = geom.coordinates;
4964
+ switch (type) {
4965
+ case "LineString":
4966
+ case "MultiLineString": {
4967
+ const lines = [];
4968
+ if (type === "LineString") {
4969
+ coords = [coords];
4970
+ }
4971
+ coords.forEach((line) => {
4972
+ lineclip(line, bbox2, lines);
4973
+ });
4974
+ if (lines.length === 1) {
4975
+ return lineString(lines[0], properties);
4976
+ }
4977
+ return multiLineString(lines, properties);
4978
+ }
4979
+ case "Polygon":
4980
+ return polygon(clipPolygon(coords, bbox2), properties);
4981
+ case "MultiPolygon":
4982
+ return multiPolygon(
4983
+ coords.map((poly) => {
4984
+ return clipPolygon(poly, bbox2);
4985
+ }),
4986
+ properties
4987
+ );
4988
+ default:
4989
+ throw new Error("geometry " + type + " not supported");
4990
+ }
4991
+ }
4992
+ function clipPolygon(rings, bbox2) {
4993
+ const outRings = [];
4994
+ for (const ring of rings) {
4995
+ const clipped = polygonclip(ring, bbox2);
4996
+ if (clipped.length > 0) {
4997
+ if (clipped[0][0] !== clipped[clipped.length - 1][0] || clipped[0][1] !== clipped[clipped.length - 1][1]) {
4998
+ clipped.push(clipped[0]);
4999
+ }
5000
+ if (clipped.length >= 4) {
5001
+ outRings.push(clipped);
5002
+ }
5003
+ }
5004
+ }
5005
+ return outRings;
5006
+ }
5007
+ var turf_bbox_clip_default = bboxClip;
5008
+
5009
+ // src/filters/tileIntersection.ts
5010
+ function intersectTileGeometry(tileBbox, tileFormat, spatialFilter) {
5011
+ const tilePolygon = turf_bbox_polygon_default(tileBbox);
5012
+ if (!spatialFilter || turf_boolean_within_default(tilePolygon, spatialFilter)) {
5013
+ return true;
5014
+ }
5015
+ const clippedSpatialFilter = turf_intersect_default(
5016
+ featureCollection([tilePolygon, feature(spatialFilter)])
5017
+ );
5018
+ if (!clippedSpatialFilter) {
5019
+ return false;
5020
+ }
5021
+ return tileFormat === "mvt" /* MVT */ ? transformToTileCoords(clippedSpatialFilter.geometry, tileBbox) : clippedSpatialFilter.geometry;
5022
+ }
5023
+ function intersectTileRaster(parent, cellResolution, spatialFilter) {
5024
+ return intersectTileQuadbin(parent, cellResolution, spatialFilter);
5025
+ }
5026
+ function intersectTileQuadbin(parent, cellResolution, spatialFilter) {
5027
+ const tilePolygon = quadbinCellToBoundary(parent);
5028
+ if (!spatialFilter || turf_boolean_within_default(tilePolygon, spatialFilter)) {
5029
+ return true;
5030
+ }
5031
+ const clippedSpatialFilter = turf_intersect_default(
5032
+ featureCollection([feature(tilePolygon), feature(spatialFilter)])
5033
+ );
5034
+ if (!clippedSpatialFilter) {
5035
+ return false;
5036
+ }
5037
+ const cells = quadbinGeometryToCells(
5038
+ clippedSpatialFilter.geometry,
5039
+ cellResolution
5040
+ );
5041
+ return new Set(cells);
5042
+ }
5043
+ var BBOX_WEST = [-180, -90, 0, 90];
5044
+ var BBOX_EAST = [0, -90, 180, 90];
5045
+ function intersectTileH3(parent, cellResolution, spatialFilter) {
5046
+ const tilePolygon = {
5047
+ type: "Polygon",
5048
+ coordinates: [h3CellToBoundary(parent, true)]
5049
+ };
5050
+ if (!spatialFilter || turf_boolean_within_default(tilePolygon, spatialFilter)) {
5051
+ return true;
5052
+ }
5053
+ const clippedSpatialFilter = turf_intersect_default(
5054
+ featureCollection([feature(tilePolygon), feature(spatialFilter)])
5055
+ );
5056
+ if (!clippedSpatialFilter) {
5057
+ return false;
5058
+ }
5059
+ const cellsWest = h3PolygonToCells(
5060
+ turf_bbox_clip_default(clippedSpatialFilter, BBOX_WEST).geometry.coordinates,
5061
+ cellResolution,
5062
+ true
5063
+ );
5064
+ const cellsEast = h3PolygonToCells(
5065
+ turf_bbox_clip_default(clippedSpatialFilter, BBOX_EAST).geometry.coordinates,
5066
+ cellResolution,
5067
+ true
5068
+ );
5069
+ return new Set(cellsWest.concat(cellsEast));
5070
+ }
5071
+
5072
+ // src/filters/tileFeaturesGeometries.ts
5073
+ var FEATURE_GEOM_PROPERTY = "__geomValue";
5074
+ function tileFeaturesGeometries({
5075
+ tiles,
5076
+ tileFormat,
5077
+ spatialFilter,
5078
+ uniqueIdProperty,
5079
+ options
5080
+ }) {
5081
+ const map = /* @__PURE__ */ new Map();
5082
+ for (const tile of tiles) {
5083
+ if (tile.isVisible === false || !tile.data) {
5084
+ continue;
5085
+ }
5086
+ const tileBbox = [
5087
+ tile.bbox.west,
5088
+ tile.bbox.south,
5089
+ tile.bbox.east,
5090
+ tile.bbox.north
5091
+ ];
5092
+ const intersection3 = intersectTileGeometry(
5093
+ tileBbox,
5094
+ tileFormat,
5095
+ spatialFilter
5096
+ );
5097
+ if (intersection3 === false) continue;
5098
+ const transformedSpatialFilter = intersection3 === true ? void 0 : intersection3;
5099
+ calculateFeatures({
5100
+ map,
5101
+ spatialFilter: transformedSpatialFilter,
4911
5102
  data: tile.data.points,
4912
5103
  type: "Point",
4913
- bbox: bbox2,
5104
+ bbox: tileBbox,
4914
5105
  tileFormat,
4915
5106
  uniqueIdProperty,
4916
5107
  options
4917
5108
  });
4918
5109
  calculateFeatures({
4919
5110
  map,
4920
- tileIsFullyVisible,
4921
- geometryIntersection: transformedGeometryToIntersect,
5111
+ spatialFilter: transformedSpatialFilter,
4922
5112
  data: tile.data.lines,
4923
5113
  type: "LineString",
4924
- bbox: bbox2,
5114
+ bbox: tileBbox,
4925
5115
  tileFormat,
4926
5116
  uniqueIdProperty,
4927
5117
  options
4928
5118
  });
4929
5119
  calculateFeatures({
4930
5120
  map,
4931
- tileIsFullyVisible,
4932
- geometryIntersection: transformedGeometryToIntersect,
5121
+ spatialFilter: transformedSpatialFilter,
4933
5122
  data: tile.data.polygons,
4934
5123
  type: "Polygon",
4935
- bbox: bbox2,
5124
+ bbox: tileBbox,
4936
5125
  tileFormat,
4937
5126
  uniqueIdProperty,
4938
5127
  options
@@ -4950,7 +5139,7 @@ function processTileFeatureProperties({
4950
5139
  tileFormat,
4951
5140
  uniqueIdProperty,
4952
5141
  storeGeometry,
4953
- geometryIntersection
5142
+ spatialFilter
4954
5143
  }) {
4955
5144
  const tileProps = getPropertiesFromTile(data, startIndex);
4956
5145
  const uniquePropertyValue = getUniquePropertyValue(
@@ -4962,7 +5151,7 @@ function processTileFeatureProperties({
4962
5151
  return;
4963
5152
  }
4964
5153
  let geometry = null;
4965
- if (storeGeometry || geometryIntersection) {
5154
+ if (storeGeometry || spatialFilter) {
4966
5155
  const { positions } = data;
4967
5156
  const ringCoordinates = getRingCoordinatesFor(
4968
5157
  startIndex,
@@ -4971,7 +5160,7 @@ function processTileFeatureProperties({
4971
5160
  );
4972
5161
  geometry = getFeatureByType(ringCoordinates, type);
4973
5162
  }
4974
- if (geometry && geometryIntersection && !turf_boolean_intersects_default(geometry, geometryIntersection)) {
5163
+ if (geometry && spatialFilter && !turf_boolean_intersects_default(geometry, spatialFilter)) {
4975
5164
  return;
4976
5165
  }
4977
5166
  const properties = parseProperties(tileProps);
@@ -4983,7 +5172,7 @@ function processTileFeatureProperties({
4983
5172
  function addIntersectedFeaturesInTile({
4984
5173
  map,
4985
5174
  data,
4986
- geometryIntersection,
5175
+ spatialFilter,
4987
5176
  type,
4988
5177
  bbox: bbox2,
4989
5178
  tileFormat,
@@ -5005,7 +5194,7 @@ function addIntersectedFeaturesInTile({
5005
5194
  tileFormat,
5006
5195
  uniqueIdProperty,
5007
5196
  storeGeometry,
5008
- geometryIntersection
5197
+ spatialFilter
5009
5198
  });
5010
5199
  }
5011
5200
  }
@@ -5087,8 +5276,7 @@ function getRingCoordinatesFor(startIndex, endIndex, positions) {
5087
5276
  }
5088
5277
  function calculateFeatures({
5089
5278
  map,
5090
- tileIsFullyVisible,
5091
- geometryIntersection,
5279
+ spatialFilter,
5092
5280
  data,
5093
5281
  type,
5094
5282
  bbox: bbox2,
@@ -5099,7 +5287,7 @@ function calculateFeatures({
5099
5287
  if (!data?.properties.length) {
5100
5288
  return;
5101
5289
  }
5102
- if (tileIsFullyVisible) {
5290
+ if (!spatialFilter) {
5103
5291
  addAllFeaturesInTile({
5104
5292
  map,
5105
5293
  data,
@@ -5113,7 +5301,7 @@ function calculateFeatures({
5113
5301
  addIntersectedFeaturesInTile({
5114
5302
  map,
5115
5303
  data,
5116
- geometryIntersection,
5304
+ spatialFilter,
5117
5305
  type,
5118
5306
  bbox: bbox2,
5119
5307
  tileFormat,
@@ -5163,128 +5351,8 @@ function createIndicesForPoints(data) {
5163
5351
  }
5164
5352
 
5165
5353
  // src/filters/tileFeaturesSpatialIndex.ts
5166
- import { getResolution as quadbinGetResolution, geometryToCells } from "quadbin";
5167
-
5168
- // node_modules/@turf/bbox-clip/dist/esm/index.js
5169
- function lineclip(points, bbox2, result) {
5170
- var len = points.length, codeA = bitCode(points[0], bbox2), part = [], i, codeB, lastCode;
5171
- let a;
5172
- let b;
5173
- if (!result) result = [];
5174
- for (i = 1; i < len; i++) {
5175
- a = points[i - 1];
5176
- b = points[i];
5177
- codeB = lastCode = bitCode(b, bbox2);
5178
- while (true) {
5179
- if (!(codeA | codeB)) {
5180
- part.push(a);
5181
- if (codeB !== lastCode) {
5182
- part.push(b);
5183
- if (i < len - 1) {
5184
- result.push(part);
5185
- part = [];
5186
- }
5187
- } else if (i === len - 1) {
5188
- part.push(b);
5189
- }
5190
- break;
5191
- } else if (codeA & codeB) {
5192
- break;
5193
- } else if (codeA) {
5194
- a = intersect2(a, b, codeA, bbox2);
5195
- codeA = bitCode(a, bbox2);
5196
- } else {
5197
- b = intersect2(a, b, codeB, bbox2);
5198
- codeB = bitCode(b, bbox2);
5199
- }
5200
- }
5201
- codeA = lastCode;
5202
- }
5203
- if (part.length) result.push(part);
5204
- return result;
5205
- }
5206
- function polygonclip(points, bbox2) {
5207
- var result, edge, prev, prevInside, i, p, inside;
5208
- for (edge = 1; edge <= 8; edge *= 2) {
5209
- result = [];
5210
- prev = points[points.length - 1];
5211
- prevInside = !(bitCode(prev, bbox2) & edge);
5212
- for (i = 0; i < points.length; i++) {
5213
- p = points[i];
5214
- inside = !(bitCode(p, bbox2) & edge);
5215
- if (inside !== prevInside) result.push(intersect2(prev, p, edge, bbox2));
5216
- if (inside) result.push(p);
5217
- prev = p;
5218
- prevInside = inside;
5219
- }
5220
- points = result;
5221
- if (!points.length) break;
5222
- }
5223
- return result;
5224
- }
5225
- function intersect2(a, b, edge, bbox2) {
5226
- 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;
5227
- }
5228
- function bitCode(p, bbox2) {
5229
- var code = 0;
5230
- if (p[0] < bbox2[0]) code |= 1;
5231
- else if (p[0] > bbox2[2]) code |= 2;
5232
- if (p[1] < bbox2[1]) code |= 4;
5233
- else if (p[1] > bbox2[3]) code |= 8;
5234
- return code;
5235
- }
5236
- function bboxClip(feature2, bbox2) {
5237
- const geom = getGeom(feature2);
5238
- const type = geom.type;
5239
- const properties = feature2.type === "Feature" ? feature2.properties : {};
5240
- let coords = geom.coordinates;
5241
- switch (type) {
5242
- case "LineString":
5243
- case "MultiLineString": {
5244
- const lines = [];
5245
- if (type === "LineString") {
5246
- coords = [coords];
5247
- }
5248
- coords.forEach((line) => {
5249
- lineclip(line, bbox2, lines);
5250
- });
5251
- if (lines.length === 1) {
5252
- return lineString(lines[0], properties);
5253
- }
5254
- return multiLineString(lines, properties);
5255
- }
5256
- case "Polygon":
5257
- return polygon(clipPolygon(coords, bbox2), properties);
5258
- case "MultiPolygon":
5259
- return multiPolygon(
5260
- coords.map((poly) => {
5261
- return clipPolygon(poly, bbox2);
5262
- }),
5263
- properties
5264
- );
5265
- default:
5266
- throw new Error("geometry " + type + " not supported");
5267
- }
5268
- }
5269
- function clipPolygon(rings, bbox2) {
5270
- const outRings = [];
5271
- for (const ring of rings) {
5272
- const clipped = polygonclip(ring, bbox2);
5273
- if (clipped.length > 0) {
5274
- if (clipped[0][0] !== clipped[clipped.length - 1][0] || clipped[0][1] !== clipped[clipped.length - 1][1]) {
5275
- clipped.push(clipped[0]);
5276
- }
5277
- if (clipped.length >= 4) {
5278
- outRings.push(clipped);
5279
- }
5280
- }
5281
- }
5282
- return outRings;
5283
- }
5284
- var turf_bbox_clip_default = bboxClip;
5285
-
5286
- // src/filters/tileFeaturesSpatialIndex.ts
5287
- import { getResolution as h3GetResolution, polygonToCells } from "h3-js";
5354
+ import { getResolution as quadbinGetResolution } from "quadbin";
5355
+ import { getResolution as h3GetResolution } from "h3-js";
5288
5356
  function tileFeaturesSpatialIndex({
5289
5357
  tiles,
5290
5358
  spatialFilter,
@@ -5293,28 +5361,40 @@ function tileFeaturesSpatialIndex({
5293
5361
  }) {
5294
5362
  const map = /* @__PURE__ */ new Map();
5295
5363
  const spatialIndex = getSpatialIndex(spatialDataType);
5296
- const resolution = getResolution(tiles, spatialIndex);
5364
+ const cellResolution = getResolution(tiles, spatialIndex);
5297
5365
  const spatialIndexIDName = spatialDataColumn ? spatialDataColumn : spatialIndex;
5298
- if (!resolution) {
5366
+ if (!cellResolution) {
5299
5367
  return [];
5300
5368
  }
5301
- const cells = getCellsCoverGeometry(spatialFilter, spatialIndex, resolution);
5302
- if (!cells?.length) {
5303
- return [];
5304
- }
5305
- const cellsSet = new Set(cells);
5306
5369
  for (const tile of tiles) {
5307
5370
  if (tile.isVisible === false || !tile.data) {
5308
5371
  continue;
5309
5372
  }
5373
+ const parent = getTileIndex(tile, spatialIndex);
5374
+ const intersection3 = spatialIndex === "quadbin" /* QUADBIN */ ? intersectTileQuadbin(
5375
+ parent,
5376
+ cellResolution,
5377
+ spatialFilter
5378
+ ) : intersectTileH3(
5379
+ parent,
5380
+ cellResolution,
5381
+ spatialFilter
5382
+ );
5383
+ if (!intersection3) continue;
5310
5384
  tile.data.forEach((d) => {
5311
- if (cellsSet.has(d.id)) {
5385
+ if (intersection3 === true || intersection3.has(d.id)) {
5312
5386
  map.set(d.id, { ...d.properties, [spatialIndexIDName]: d.id });
5313
5387
  }
5314
5388
  });
5315
5389
  }
5316
5390
  return Array.from(map.values());
5317
5391
  }
5392
+ function getTileIndex(tile, spatialIndex) {
5393
+ if (spatialIndex === "quadbin" /* QUADBIN */) {
5394
+ return tile.index.q;
5395
+ }
5396
+ return tile.id;
5397
+ }
5318
5398
  function getResolution(tiles, spatialIndex) {
5319
5399
  const data = tiles.find((tile) => tile.data?.length)?.data;
5320
5400
  if (!data) {
@@ -5327,26 +5407,6 @@ function getResolution(tiles, spatialIndex) {
5327
5407
  return h3GetResolution(data[0].id);
5328
5408
  }
5329
5409
  }
5330
- var bboxWest = [-180, -90, 0, 90];
5331
- var bboxEast = [0, -90, 180, 90];
5332
- function getCellsCoverGeometry(geometry, spatialIndex, resolution) {
5333
- if (spatialIndex === "quadbin" /* QUADBIN */) {
5334
- return geometryToCells(geometry, resolution);
5335
- }
5336
- if (spatialIndex === "h3" /* H3 */) {
5337
- return polygonToCells(
5338
- turf_bbox_clip_default(geometry, bboxWest).geometry.coordinates,
5339
- resolution,
5340
- true
5341
- ).concat(
5342
- polygonToCells(
5343
- turf_bbox_clip_default(geometry, bboxEast).geometry.coordinates,
5344
- resolution,
5345
- true
5346
- )
5347
- );
5348
- }
5349
- }
5350
5410
  function getSpatialIndex(spatialDataType) {
5351
5411
  switch (spatialDataType) {
5352
5412
  case "h3":
@@ -5367,7 +5427,6 @@ var DEFAULT_AGGREGATION_EXP = `1 AS ${DEFAULT_AGGREGATION_EXP_ALIAS}`;
5367
5427
  import {
5368
5428
  cellToChildren as _cellToChildren,
5369
5429
  cellToTile,
5370
- geometryToCells as geometryToCells2,
5371
5430
  getResolution as getResolution2
5372
5431
  } from "quadbin";
5373
5432
  function tileFeaturesRaster({
@@ -5383,15 +5442,20 @@ function tileFeaturesRaster({
5383
5442
  const tileResolution = getResolution2(tiles[0].index.q);
5384
5443
  const tileBlockSize = tiles[0].data.blockSize;
5385
5444
  const cellResolution = tileResolution + BigInt(Math.log2(tileBlockSize));
5386
- const spatialFilterCells = new Set(
5387
- geometryToCells2(options.spatialFilter, cellResolution)
5388
- );
5389
5445
  const data = /* @__PURE__ */ new Map();
5390
5446
  for (const tile of tiles) {
5391
5447
  const parent = tile.index.q;
5392
- const children = cellToChildrenSorted(parent, cellResolution);
5393
- for (let i = 0; i < children.length; i++) {
5394
- if (!spatialFilterCells.has(children[i])) continue;
5448
+ const intersection3 = intersectTileRaster(
5449
+ parent,
5450
+ cellResolution,
5451
+ options.spatialFilter
5452
+ );
5453
+ if (intersection3 === false) continue;
5454
+ const tileSortedCells = cellToChildrenSorted(parent, cellResolution);
5455
+ for (let i = 0; i < tileSortedCells.length; i++) {
5456
+ if (intersection3 !== true && !intersection3.has(tileSortedCells[i])) {
5457
+ continue;
5458
+ }
5395
5459
  const cellData = {};
5396
5460
  let cellDataExists = false;
5397
5461
  for (const band in tile.data.cells.numericProps) {
@@ -5403,7 +5467,7 @@ function tileFeaturesRaster({
5403
5467
  }
5404
5468
  }
5405
5469
  if (cellDataExists) {
5406
- data.set(children[i], cellData);
5470
+ data.set(tileSortedCells[i], cellData);
5407
5471
  }
5408
5472
  }
5409
5473
  }
@@ -6184,7 +6248,7 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
6184
6248
  }
6185
6249
  _extractTileFeatures(spatialFilter) {
6186
6250
  const prevInputs = this._tileFeatureExtractPreviousInputs;
6187
- if (this._features.length && prevInputs.spatialFilter && booleanEqual(prevInputs.spatialFilter, spatialFilter)) {
6251
+ if (this._features.length && spatialFilterEquals(prevInputs.spatialFilter, spatialFilter)) {
6188
6252
  return;
6189
6253
  }
6190
6254
  this._features = tileFeatures({
@@ -6215,7 +6279,7 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
6215
6279
  }
6216
6280
  async getFormula({
6217
6281
  column = "*",
6218
- operation: operation2 = "count",
6282
+ operation: operation2 = AggregationTypes.Count,
6219
6283
  joinOperation,
6220
6284
  filters,
6221
6285
  filterOwner,
@@ -6226,13 +6290,13 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
6226
6290
  filters,
6227
6291
  filterOwner
6228
6292
  );
6229
- if (filteredFeatures.length === 0 && operation2 !== "count") {
6293
+ if (filteredFeatures.length === 0 && operation2 !== AggregationTypes.Count) {
6230
6294
  return { value: null };
6231
6295
  }
6232
- if (operation2 === "custom") {
6296
+ if (operation2 === AggregationTypes.Custom) {
6233
6297
  throw new Error("Custom aggregation not supported for tilesets");
6234
6298
  }
6235
- if (column && column !== "*" || operation2 !== "count") {
6299
+ if (column && column !== "*" || operation2 !== AggregationTypes.Count) {
6236
6300
  assertColumn(this._features, column);
6237
6301
  }
6238
6302
  const targetOperation = aggregationFunctions[operation2];
@@ -6241,7 +6305,7 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
6241
6305
  };
6242
6306
  }
6243
6307
  async getHistogram({
6244
- operation: operation2 = "count",
6308
+ operation: operation2 = AggregationTypes.Count,
6245
6309
  ticks,
6246
6310
  column,
6247
6311
  joinOperation,
@@ -6268,7 +6332,7 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
6268
6332
  }
6269
6333
  async getCategories({
6270
6334
  column,
6271
- operation: operation2 = "count",
6335
+ operation: operation2 = AggregationTypes.Count,
6272
6336
  operationColumn,
6273
6337
  joinOperation,
6274
6338
  filters,
@@ -6424,7 +6488,6 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
6424
6488
  * INTERNAL
6425
6489
  */
6426
6490
  _getFilteredFeatures(spatialFilter, filters, filterOwner) {
6427
- assert(spatialFilter, "spatialFilter required for tilesets");
6428
6491
  this._extractTileFeatures(spatialFilter);
6429
6492
  return applyFilters(
6430
6493
  this._features,
@@ -6448,6 +6511,11 @@ function assertColumn(features, ...columnArgs) {
6448
6511
  function normalizeColumns(columns) {
6449
6512
  return Array.isArray(columns) ? columns : typeof columns === "string" ? [columns] : [];
6450
6513
  }
6514
+ function spatialFilterEquals(a, b) {
6515
+ if (a === b) return true;
6516
+ if (!a || !b) return false;
6517
+ return booleanEqual(a, b);
6518
+ }
6451
6519
 
6452
6520
  // src/workers/widget-tileset-worker.ts
6453
6521
  var source;