@carto/api-client 0.5.7-alpha.6 → 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.
@@ -1558,6 +1558,110 @@ function geojsonFeatures({
1558
1558
  return Array.from(map.values());
1559
1559
  }
1560
1560
 
1561
+ // node_modules/@math.gl/core/dist/lib/common.js
1562
+ var RADIANS_TO_DEGREES = 1 / Math.PI * 180;
1563
+ var DEGREES_TO_RADIANS = 1 / 180 * Math.PI;
1564
+ var DEFAULT_CONFIG = {
1565
+ EPSILON: 1e-12,
1566
+ debug: false,
1567
+ precision: 4,
1568
+ printTypes: false,
1569
+ printDegrees: false,
1570
+ printRowMajor: true,
1571
+ _cartographicRadians: false
1572
+ };
1573
+ globalThis.mathgl = globalThis.mathgl || { config: { ...DEFAULT_CONFIG } };
1574
+ var config = globalThis.mathgl.config;
1575
+ function isArray(value) {
1576
+ return Array.isArray(value) || ArrayBuffer.isView(value) && !(value instanceof DataView);
1577
+ }
1578
+ function lerp(a, b, t) {
1579
+ if (isArray(a)) {
1580
+ return a.map((ai, i) => lerp(ai, b[i], t));
1581
+ }
1582
+ return t * b + (1 - t) * a;
1583
+ }
1584
+
1585
+ // node_modules/@math.gl/web-mercator/dist/assert.js
1586
+ function assert(condition, message) {
1587
+ if (!condition) {
1588
+ throw new Error(message || "@math.gl/web-mercator: assertion failed.");
1589
+ }
1590
+ }
1591
+
1592
+ // node_modules/@math.gl/web-mercator/dist/web-mercator-utils.js
1593
+ var PI = Math.PI;
1594
+ var PI_4 = PI / 4;
1595
+ var DEGREES_TO_RADIANS2 = PI / 180;
1596
+ var RADIANS_TO_DEGREES2 = 180 / PI;
1597
+ var TILE_SIZE = 512;
1598
+ function lngLatToWorld(lngLat) {
1599
+ const [lng, lat] = lngLat;
1600
+ assert(Number.isFinite(lng));
1601
+ assert(Number.isFinite(lat) && lat >= -90 && lat <= 90, "invalid latitude");
1602
+ const lambda2 = lng * DEGREES_TO_RADIANS2;
1603
+ const phi2 = lat * DEGREES_TO_RADIANS2;
1604
+ const x = TILE_SIZE * (lambda2 + PI) / (2 * PI);
1605
+ const y = TILE_SIZE * (PI + Math.log(Math.tan(PI_4 + phi2 * 0.5))) / (2 * PI);
1606
+ return [x, y];
1607
+ }
1608
+ function worldToLngLat(xy) {
1609
+ const [x, y] = xy;
1610
+ const lambda2 = x / TILE_SIZE * (2 * PI) - PI;
1611
+ const phi2 = 2 * (Math.atan(Math.exp(y / TILE_SIZE * (2 * PI) - PI)) - PI_4);
1612
+ return [lambda2 * RADIANS_TO_DEGREES2, phi2 * RADIANS_TO_DEGREES2];
1613
+ }
1614
+
1615
+ // node_modules/@math.gl/web-mercator/dist/get-bounds.js
1616
+ var DEGREES_TO_RADIANS3 = Math.PI / 180;
1617
+
1618
+ // src/utils/transformTileCoordsToWGS84.ts
1619
+ var TRANSFORM_FN = {
1620
+ Point: transformPoint,
1621
+ MultiPoint: transformMultiPoint,
1622
+ LineString: transformLineString,
1623
+ MultiLineString: transformMultiLineString,
1624
+ Polygon: transformPolygon,
1625
+ MultiPolygon: transformMultiPolygon
1626
+ };
1627
+ function transformTileCoordsToWGS84(geometry, bbox2) {
1628
+ const [west, south, east, north] = bbox2;
1629
+ const nw = lngLatToWorld([west, north]);
1630
+ const se = lngLatToWorld([east, south]);
1631
+ const projectedBbox = [nw, se];
1632
+ if (geometry.type === "GeometryCollection") {
1633
+ throw new Error("Unsupported geometry type GeometryCollection");
1634
+ }
1635
+ const transformFn = TRANSFORM_FN[geometry.type];
1636
+ const coordinates = transformFn(geometry.coordinates, projectedBbox);
1637
+ return { ...geometry, coordinates };
1638
+ }
1639
+ function transformPoint([pointX, pointY], [nw, se]) {
1640
+ const x = lerp(nw[0], se[0], pointX);
1641
+ const y = lerp(nw[1], se[1], pointY);
1642
+ return worldToLngLat([x, y]);
1643
+ }
1644
+ function getPoints(geometry, bbox2) {
1645
+ return geometry.map((g) => transformPoint(g, bbox2));
1646
+ }
1647
+ function transformMultiPoint(multiPoint, bbox2) {
1648
+ return getPoints(multiPoint, bbox2);
1649
+ }
1650
+ function transformLineString(line, bbox2) {
1651
+ return getPoints(line, bbox2);
1652
+ }
1653
+ function transformMultiLineString(multiLineString2, bbox2) {
1654
+ return multiLineString2.map(
1655
+ (lineString2) => transformLineString(lineString2, bbox2)
1656
+ );
1657
+ }
1658
+ function transformPolygon(polygon2, bbox2) {
1659
+ return polygon2.map((polygonRing) => getPoints(polygonRing, bbox2));
1660
+ }
1661
+ function transformMultiPolygon(multiPolygon2, bbox2) {
1662
+ return multiPolygon2.map((polygon2) => transformPolygon(polygon2, bbox2));
1663
+ }
1664
+
1561
1665
  // node_modules/@turf/bbox-polygon/dist/esm/index.js
1562
1666
  function bboxPolygon(bbox2, options = {}) {
1563
1667
  const west = Number(bbox2[0]);
@@ -1876,7 +1980,7 @@ var MAX_SAFE_INTEGER = 9007199254740991;
1876
1980
  var POWS_TEN = [1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13];
1877
1981
  var SQRT_BASE = 1e7;
1878
1982
  var MAX = 1e9;
1879
- function clone(configObject) {
1983
+ function clone2(configObject) {
1880
1984
  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 = {
1881
1985
  prefix: "",
1882
1986
  groupSize: 3,
@@ -2002,7 +2106,7 @@ function clone(configObject) {
2002
2106
  x.c = [x.e = 0];
2003
2107
  }
2004
2108
  }
2005
- BigNumber2.clone = clone;
2109
+ BigNumber2.clone = clone2;
2006
2110
  BigNumber2.ROUND_UP = 0;
2007
2111
  BigNumber2.ROUND_DOWN = 1;
2008
2112
  BigNumber2.ROUND_CEIL = 2;
@@ -3205,7 +3309,7 @@ function toFixedPoint(str, e, z) {
3205
3309
  }
3206
3310
  return str;
3207
3311
  }
3208
- var BigNumber = clone();
3312
+ var BigNumber = clone2();
3209
3313
  var bignumber_default = BigNumber;
3210
3314
 
3211
3315
  // node_modules/splaytree-ts/dist/esm/index.js
@@ -4775,117 +4879,7 @@ function intersect(features, options = {}) {
4775
4879
  }
4776
4880
  var turf_intersect_default = intersect;
4777
4881
 
4778
- // node_modules/@math.gl/core/dist/lib/common.js
4779
- var RADIANS_TO_DEGREES = 1 / Math.PI * 180;
4780
- var DEGREES_TO_RADIANS = 1 / 180 * Math.PI;
4781
- var DEFAULT_CONFIG = {
4782
- EPSILON: 1e-12,
4783
- debug: false,
4784
- precision: 4,
4785
- printTypes: false,
4786
- printDegrees: false,
4787
- printRowMajor: true,
4788
- _cartographicRadians: false
4789
- };
4790
- globalThis.mathgl = globalThis.mathgl || { config: { ...DEFAULT_CONFIG } };
4791
- var config = globalThis.mathgl.config;
4792
- function isArray(value) {
4793
- return Array.isArray(value) || ArrayBuffer.isView(value) && !(value instanceof DataView);
4794
- }
4795
- function lerp(a, b, t) {
4796
- if (isArray(a)) {
4797
- return a.map((ai, i) => lerp(ai, b[i], t));
4798
- }
4799
- return t * b + (1 - t) * a;
4800
- }
4801
-
4802
- // node_modules/@math.gl/web-mercator/dist/assert.js
4803
- function assert(condition, message) {
4804
- if (!condition) {
4805
- throw new Error(message || "@math.gl/web-mercator: assertion failed.");
4806
- }
4807
- }
4808
-
4809
- // node_modules/@math.gl/web-mercator/dist/web-mercator-utils.js
4810
- var PI = Math.PI;
4811
- var PI_4 = PI / 4;
4812
- var DEGREES_TO_RADIANS2 = PI / 180;
4813
- var RADIANS_TO_DEGREES2 = 180 / PI;
4814
- var TILE_SIZE = 512;
4815
- function lngLatToWorld(lngLat) {
4816
- const [lng, lat] = lngLat;
4817
- assert(Number.isFinite(lng));
4818
- assert(Number.isFinite(lat) && lat >= -90 && lat <= 90, "invalid latitude");
4819
- const lambda2 = lng * DEGREES_TO_RADIANS2;
4820
- const phi2 = lat * DEGREES_TO_RADIANS2;
4821
- const x = TILE_SIZE * (lambda2 + PI) / (2 * PI);
4822
- const y = TILE_SIZE * (PI + Math.log(Math.tan(PI_4 + phi2 * 0.5))) / (2 * PI);
4823
- return [x, y];
4824
- }
4825
- function worldToLngLat(xy) {
4826
- const [x, y] = xy;
4827
- const lambda2 = x / TILE_SIZE * (2 * PI) - PI;
4828
- const phi2 = 2 * (Math.atan(Math.exp(y / TILE_SIZE * (2 * PI) - PI)) - PI_4);
4829
- return [lambda2 * RADIANS_TO_DEGREES2, phi2 * RADIANS_TO_DEGREES2];
4830
- }
4831
-
4832
- // node_modules/@math.gl/web-mercator/dist/get-bounds.js
4833
- var DEGREES_TO_RADIANS3 = Math.PI / 180;
4834
-
4835
4882
  // src/utils/transformToTileCoords.ts
4836
- var TRANSFORM_FN = {
4837
- Point: transformPoint,
4838
- MultiPoint: transformMultiPoint,
4839
- LineString: transformLineString,
4840
- MultiLineString: transformMultiLineString,
4841
- Polygon: transformPolygon,
4842
- MultiPolygon: transformMultiPolygon
4843
- };
4844
- function transformToTileCoords(geometry, bbox2) {
4845
- const [west, south, east, north] = bbox2;
4846
- const nw = projectFlat([west, north]);
4847
- const se = projectFlat([east, south]);
4848
- const projectedBbox = [nw, se];
4849
- if (geometry.type === "GeometryCollection") {
4850
- throw new Error("Unsupported geometry type GeometryCollection");
4851
- }
4852
- const transformFn = TRANSFORM_FN[geometry.type];
4853
- const coordinates = transformFn(geometry.coordinates, projectedBbox);
4854
- return { ...geometry, coordinates };
4855
- }
4856
- function transformPoint([pointX, pointY], [nw, se]) {
4857
- const x = inverseLerp(nw[0], se[0], pointX);
4858
- const y = inverseLerp(nw[1], se[1], pointY);
4859
- return [x, y];
4860
- }
4861
- function getPoints(geometry, bbox2) {
4862
- return geometry.map((g) => transformPoint(projectFlat(g), bbox2));
4863
- }
4864
- function transformMultiPoint(multiPoint, bbox2) {
4865
- return getPoints(multiPoint, bbox2);
4866
- }
4867
- function transformLineString(line, bbox2) {
4868
- return getPoints(line, bbox2);
4869
- }
4870
- function transformMultiLineString(multiLineString2, bbox2) {
4871
- return multiLineString2.map(
4872
- (lineString2) => transformLineString(lineString2, bbox2)
4873
- );
4874
- }
4875
- function transformPolygon(polygon2, bbox2) {
4876
- return polygon2.map((polygonRing) => getPoints(polygonRing, bbox2));
4877
- }
4878
- function transformMultiPolygon(multiPolygon2, bbox2) {
4879
- return multiPolygon2.map((polygon2) => transformPolygon(polygon2, bbox2));
4880
- }
4881
- function projectFlat(xyz) {
4882
- return lngLatToWorld(xyz);
4883
- }
4884
- function inverseLerp(a, b, x) {
4885
- return (x - a) / (b - a);
4886
- }
4887
-
4888
- // src/utils/transformTileCoordsToWGS84.ts
4889
4883
  var TRANSFORM_FN2 = {
4890
4884
  Point: transformPoint2,
4891
4885
  MultiPoint: transformMultiPoint2,
@@ -4894,10 +4888,10 @@ var TRANSFORM_FN2 = {
4894
4888
  Polygon: transformPolygon2,
4895
4889
  MultiPolygon: transformMultiPolygon2
4896
4890
  };
4897
- function transformTileCoordsToWGS84(geometry, bbox2) {
4891
+ function transformToTileCoords(geometry, bbox2) {
4898
4892
  const [west, south, east, north] = bbox2;
4899
- const nw = lngLatToWorld([west, north]);
4900
- const se = lngLatToWorld([east, south]);
4893
+ const nw = projectFlat([west, north]);
4894
+ const se = projectFlat([east, south]);
4901
4895
  const projectedBbox = [nw, se];
4902
4896
  if (geometry.type === "GeometryCollection") {
4903
4897
  throw new Error("Unsupported geometry type GeometryCollection");
@@ -4907,12 +4901,12 @@ function transformTileCoordsToWGS84(geometry, bbox2) {
4907
4901
  return { ...geometry, coordinates };
4908
4902
  }
4909
4903
  function transformPoint2([pointX, pointY], [nw, se]) {
4910
- const x = lerp(nw[0], se[0], pointX);
4911
- const y = lerp(nw[1], se[1], pointY);
4912
- return worldToLngLat([x, y]);
4904
+ const x = inverseLerp(nw[0], se[0], pointX);
4905
+ const y = inverseLerp(nw[1], se[1], pointY);
4906
+ return [x, y];
4913
4907
  }
4914
4908
  function getPoints2(geometry, bbox2) {
4915
- return geometry.map((g) => transformPoint2(g, bbox2));
4909
+ return geometry.map((g) => transformPoint2(projectFlat(g), bbox2));
4916
4910
  }
4917
4911
  function transformMultiPoint2(multiPoint, bbox2) {
4918
4912
  return getPoints2(multiPoint, bbox2);
@@ -4931,70 +4925,245 @@ function transformPolygon2(polygon2, bbox2) {
4931
4925
  function transformMultiPolygon2(multiPolygon2, bbox2) {
4932
4926
  return multiPolygon2.map((polygon2) => transformPolygon2(polygon2, bbox2));
4933
4927
  }
4928
+ function projectFlat(xyz) {
4929
+ return lngLatToWorld(xyz);
4930
+ }
4931
+ function inverseLerp(a, b, x) {
4932
+ return (x - a) / (b - a);
4933
+ }
4934
4934
 
4935
- // src/filters/tileFeaturesGeometries.ts
4936
- var FEATURE_GEOM_PROPERTY = "__geomValue";
4937
- function tileFeaturesGeometries({
4938
- tiles,
4939
- tileFormat,
4940
- spatialFilter,
4941
- uniqueIdProperty,
4942
- options
4943
- }) {
4944
- const map = /* @__PURE__ */ new Map();
4945
- for (const tile of tiles) {
4946
- if (tile.isVisible === false || !tile.data) {
4947
- continue;
4948
- }
4949
- const bbox2 = [
4950
- tile.bbox.west,
4951
- tile.bbox.south,
4952
- tile.bbox.east,
4953
- tile.bbox.north
4954
- ];
4955
- const bboxToGeom = turf_bbox_polygon_default(bbox2);
4956
- const tileIsFullyVisible = turf_boolean_within_default(bboxToGeom, spatialFilter);
4957
- const spatialFilterFeature = {
4958
- type: "Feature",
4959
- geometry: spatialFilter,
4960
- properties: {}
4961
- };
4962
- const clippedGeometryToIntersect = turf_intersect_default(
4963
- featureCollection([bboxToGeom, spatialFilterFeature])
4964
- );
4965
- if (!clippedGeometryToIntersect) {
4966
- continue;
4967
- }
4968
- const transformedGeometryToIntersect = tileFormat === "mvt" /* MVT */ ? transformToTileCoords(clippedGeometryToIntersect.geometry, bbox2) : clippedGeometryToIntersect.geometry;
4969
- calculateFeatures({
4970
- map,
4971
- tileIsFullyVisible,
4972
- geometryIntersection: transformedGeometryToIntersect,
4973
- data: tile.data.points,
4935
+ // src/filters/tileIntersection.ts
4936
+ import {
4937
+ cellToBoundary as quadbinCellToBoundary,
4938
+ geometryToCells as quadbinGeometryToCells
4939
+ } from "quadbin";
4940
+ import { polygonToCells as h3PolygonToCells } from "h3-js";
4941
+
4942
+ // node_modules/@turf/bbox-clip/dist/esm/index.js
4943
+ function lineclip(points, bbox2, result) {
4944
+ var len = points.length, codeA = bitCode(points[0], bbox2), part = [], i, codeB, lastCode;
4945
+ let a;
4946
+ let b;
4947
+ if (!result) result = [];
4948
+ for (i = 1; i < len; i++) {
4949
+ a = points[i - 1];
4950
+ b = points[i];
4951
+ codeB = lastCode = bitCode(b, bbox2);
4952
+ while (true) {
4953
+ if (!(codeA | codeB)) {
4954
+ part.push(a);
4955
+ if (codeB !== lastCode) {
4956
+ part.push(b);
4957
+ if (i < len - 1) {
4958
+ result.push(part);
4959
+ part = [];
4960
+ }
4961
+ } else if (i === len - 1) {
4962
+ part.push(b);
4963
+ }
4964
+ break;
4965
+ } else if (codeA & codeB) {
4966
+ break;
4967
+ } else if (codeA) {
4968
+ a = intersect2(a, b, codeA, bbox2);
4969
+ codeA = bitCode(a, bbox2);
4970
+ } else {
4971
+ b = intersect2(a, b, codeB, bbox2);
4972
+ codeB = bitCode(b, bbox2);
4973
+ }
4974
+ }
4975
+ codeA = lastCode;
4976
+ }
4977
+ if (part.length) result.push(part);
4978
+ return result;
4979
+ }
4980
+ function polygonclip(points, bbox2) {
4981
+ var result, edge, prev, prevInside, i, p, inside;
4982
+ for (edge = 1; edge <= 8; edge *= 2) {
4983
+ result = [];
4984
+ prev = points[points.length - 1];
4985
+ prevInside = !(bitCode(prev, bbox2) & edge);
4986
+ for (i = 0; i < points.length; i++) {
4987
+ p = points[i];
4988
+ inside = !(bitCode(p, bbox2) & edge);
4989
+ if (inside !== prevInside) result.push(intersect2(prev, p, edge, bbox2));
4990
+ if (inside) result.push(p);
4991
+ prev = p;
4992
+ prevInside = inside;
4993
+ }
4994
+ points = result;
4995
+ if (!points.length) break;
4996
+ }
4997
+ return result;
4998
+ }
4999
+ function intersect2(a, b, edge, bbox2) {
5000
+ 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;
5001
+ }
5002
+ function bitCode(p, bbox2) {
5003
+ var code = 0;
5004
+ if (p[0] < bbox2[0]) code |= 1;
5005
+ else if (p[0] > bbox2[2]) code |= 2;
5006
+ if (p[1] < bbox2[1]) code |= 4;
5007
+ else if (p[1] > bbox2[3]) code |= 8;
5008
+ return code;
5009
+ }
5010
+ function bboxClip(feature2, bbox2) {
5011
+ const geom = getGeom(feature2);
5012
+ const type = geom.type;
5013
+ const properties = feature2.type === "Feature" ? feature2.properties : {};
5014
+ let coords = geom.coordinates;
5015
+ switch (type) {
5016
+ case "LineString":
5017
+ case "MultiLineString": {
5018
+ const lines = [];
5019
+ if (type === "LineString") {
5020
+ coords = [coords];
5021
+ }
5022
+ coords.forEach((line) => {
5023
+ lineclip(line, bbox2, lines);
5024
+ });
5025
+ if (lines.length === 1) {
5026
+ return lineString(lines[0], properties);
5027
+ }
5028
+ return multiLineString(lines, properties);
5029
+ }
5030
+ case "Polygon":
5031
+ return polygon(clipPolygon(coords, bbox2), properties);
5032
+ case "MultiPolygon":
5033
+ return multiPolygon(
5034
+ coords.map((poly) => {
5035
+ return clipPolygon(poly, bbox2);
5036
+ }),
5037
+ properties
5038
+ );
5039
+ default:
5040
+ throw new Error("geometry " + type + " not supported");
5041
+ }
5042
+ }
5043
+ function clipPolygon(rings, bbox2) {
5044
+ const outRings = [];
5045
+ for (const ring of rings) {
5046
+ const clipped = polygonclip(ring, bbox2);
5047
+ if (clipped.length > 0) {
5048
+ if (clipped[0][0] !== clipped[clipped.length - 1][0] || clipped[0][1] !== clipped[clipped.length - 1][1]) {
5049
+ clipped.push(clipped[0]);
5050
+ }
5051
+ if (clipped.length >= 4) {
5052
+ outRings.push(clipped);
5053
+ }
5054
+ }
5055
+ }
5056
+ return outRings;
5057
+ }
5058
+ var turf_bbox_clip_default = bboxClip;
5059
+
5060
+ // src/filters/tileIntersection.ts
5061
+ function intersectTileGeometry(tileBbox, tileFormat, spatialFilter) {
5062
+ const tilePolygon = turf_bbox_polygon_default(tileBbox);
5063
+ if (!spatialFilter || turf_boolean_within_default(tilePolygon, spatialFilter)) {
5064
+ return true;
5065
+ }
5066
+ const clippedSpatialFilter = turf_intersect_default(
5067
+ featureCollection([tilePolygon, feature(spatialFilter)])
5068
+ );
5069
+ if (!clippedSpatialFilter) {
5070
+ return false;
5071
+ }
5072
+ return tileFormat === "mvt" /* MVT */ ? transformToTileCoords(clippedSpatialFilter.geometry, tileBbox) : clippedSpatialFilter.geometry;
5073
+ }
5074
+ function intersectTileRaster(parent, cellResolution, spatialFilter) {
5075
+ return intersectTileQuadbin(parent, cellResolution, spatialFilter);
5076
+ }
5077
+ function intersectTileQuadbin(parent, cellResolution, spatialFilter) {
5078
+ const tilePolygon = quadbinCellToBoundary(parent);
5079
+ if (!spatialFilter || turf_boolean_within_default(tilePolygon, spatialFilter)) {
5080
+ return true;
5081
+ }
5082
+ const clippedSpatialFilter = turf_intersect_default(
5083
+ featureCollection([feature(tilePolygon), feature(spatialFilter)])
5084
+ );
5085
+ if (!clippedSpatialFilter) {
5086
+ return false;
5087
+ }
5088
+ const cells = quadbinGeometryToCells(
5089
+ clippedSpatialFilter.geometry,
5090
+ cellResolution
5091
+ );
5092
+ return new Set(cells);
5093
+ }
5094
+ var BBOX_WEST = [-180, -90, 0, 90];
5095
+ var BBOX_EAST = [0, -90, 180, 90];
5096
+ function intersectTileH3(cellResolution, spatialFilter) {
5097
+ if (!spatialFilter) {
5098
+ return true;
5099
+ }
5100
+ const spatialFilterFeature = feature(spatialFilter);
5101
+ const cellsWest = h3PolygonToCells(
5102
+ turf_bbox_clip_default(spatialFilterFeature, BBOX_WEST).geometry.coordinates,
5103
+ cellResolution,
5104
+ true
5105
+ );
5106
+ const cellsEast = h3PolygonToCells(
5107
+ turf_bbox_clip_default(spatialFilterFeature, BBOX_EAST).geometry.coordinates,
5108
+ cellResolution,
5109
+ true
5110
+ );
5111
+ return new Set(cellsWest.concat(cellsEast));
5112
+ }
5113
+
5114
+ // src/filters/tileFeaturesGeometries.ts
5115
+ var FEATURE_GEOM_PROPERTY = "__geomValue";
5116
+ function tileFeaturesGeometries({
5117
+ tiles,
5118
+ tileFormat,
5119
+ spatialFilter,
5120
+ uniqueIdProperty,
5121
+ options
5122
+ }) {
5123
+ const map = /* @__PURE__ */ new Map();
5124
+ for (const tile of tiles) {
5125
+ if (tile.isVisible === false || !tile.data) {
5126
+ continue;
5127
+ }
5128
+ const tileBbox = [
5129
+ tile.bbox.west,
5130
+ tile.bbox.south,
5131
+ tile.bbox.east,
5132
+ tile.bbox.north
5133
+ ];
5134
+ const intersection3 = intersectTileGeometry(
5135
+ tileBbox,
5136
+ tileFormat,
5137
+ spatialFilter
5138
+ );
5139
+ if (intersection3 === false) continue;
5140
+ const transformedSpatialFilter = intersection3 === true ? void 0 : intersection3;
5141
+ calculateFeatures({
5142
+ map,
5143
+ spatialFilter: transformedSpatialFilter,
5144
+ data: tile.data.points,
4974
5145
  type: "Point",
4975
- bbox: bbox2,
5146
+ bbox: tileBbox,
4976
5147
  tileFormat,
4977
5148
  uniqueIdProperty,
4978
5149
  options
4979
5150
  });
4980
5151
  calculateFeatures({
4981
5152
  map,
4982
- tileIsFullyVisible,
4983
- geometryIntersection: transformedGeometryToIntersect,
5153
+ spatialFilter: transformedSpatialFilter,
4984
5154
  data: tile.data.lines,
4985
5155
  type: "LineString",
4986
- bbox: bbox2,
5156
+ bbox: tileBbox,
4987
5157
  tileFormat,
4988
5158
  uniqueIdProperty,
4989
5159
  options
4990
5160
  });
4991
5161
  calculateFeatures({
4992
5162
  map,
4993
- tileIsFullyVisible,
4994
- geometryIntersection: transformedGeometryToIntersect,
5163
+ spatialFilter: transformedSpatialFilter,
4995
5164
  data: tile.data.polygons,
4996
5165
  type: "Polygon",
4997
- bbox: bbox2,
5166
+ bbox: tileBbox,
4998
5167
  tileFormat,
4999
5168
  uniqueIdProperty,
5000
5169
  options
@@ -5012,7 +5181,7 @@ function processTileFeatureProperties({
5012
5181
  tileFormat,
5013
5182
  uniqueIdProperty,
5014
5183
  storeGeometry,
5015
- geometryIntersection
5184
+ spatialFilter
5016
5185
  }) {
5017
5186
  const tileProps = getPropertiesFromTile(data, startIndex);
5018
5187
  const uniquePropertyValue = getUniquePropertyValue(
@@ -5024,7 +5193,7 @@ function processTileFeatureProperties({
5024
5193
  return;
5025
5194
  }
5026
5195
  let geometry = null;
5027
- if (storeGeometry || geometryIntersection) {
5196
+ if (storeGeometry || spatialFilter) {
5028
5197
  const { positions } = data;
5029
5198
  const ringCoordinates = getRingCoordinatesFor(
5030
5199
  startIndex,
@@ -5033,7 +5202,7 @@ function processTileFeatureProperties({
5033
5202
  );
5034
5203
  geometry = getFeatureByType(ringCoordinates, type);
5035
5204
  }
5036
- if (geometry && geometryIntersection && !turf_boolean_intersects_default(geometry, geometryIntersection)) {
5205
+ if (geometry && spatialFilter && !turf_boolean_intersects_default(geometry, spatialFilter)) {
5037
5206
  return;
5038
5207
  }
5039
5208
  const properties = parseProperties(tileProps);
@@ -5045,7 +5214,7 @@ function processTileFeatureProperties({
5045
5214
  function addIntersectedFeaturesInTile({
5046
5215
  map,
5047
5216
  data,
5048
- geometryIntersection,
5217
+ spatialFilter,
5049
5218
  type,
5050
5219
  bbox: bbox2,
5051
5220
  tileFormat,
@@ -5067,7 +5236,7 @@ function addIntersectedFeaturesInTile({
5067
5236
  tileFormat,
5068
5237
  uniqueIdProperty,
5069
5238
  storeGeometry,
5070
- geometryIntersection
5239
+ spatialFilter
5071
5240
  });
5072
5241
  }
5073
5242
  }
@@ -5149,8 +5318,7 @@ function getRingCoordinatesFor(startIndex, endIndex, positions) {
5149
5318
  }
5150
5319
  function calculateFeatures({
5151
5320
  map,
5152
- tileIsFullyVisible,
5153
- geometryIntersection,
5321
+ spatialFilter,
5154
5322
  data,
5155
5323
  type,
5156
5324
  bbox: bbox2,
@@ -5161,7 +5329,7 @@ function calculateFeatures({
5161
5329
  if (!data?.properties.length) {
5162
5330
  return;
5163
5331
  }
5164
- if (tileIsFullyVisible) {
5332
+ if (!spatialFilter) {
5165
5333
  addAllFeaturesInTile({
5166
5334
  map,
5167
5335
  data,
@@ -5175,7 +5343,7 @@ function calculateFeatures({
5175
5343
  addIntersectedFeaturesInTile({
5176
5344
  map,
5177
5345
  data,
5178
- geometryIntersection,
5346
+ spatialFilter,
5179
5347
  type,
5180
5348
  bbox: bbox2,
5181
5349
  tileFormat,
@@ -5225,128 +5393,8 @@ function createIndicesForPoints(data) {
5225
5393
  }
5226
5394
 
5227
5395
  // src/filters/tileFeaturesSpatialIndex.ts
5228
- import { getResolution as quadbinGetResolution, geometryToCells } from "quadbin";
5229
-
5230
- // node_modules/@turf/bbox-clip/dist/esm/index.js
5231
- function lineclip(points, bbox2, result) {
5232
- var len = points.length, codeA = bitCode(points[0], bbox2), part = [], i, codeB, lastCode;
5233
- let a;
5234
- let b;
5235
- if (!result) result = [];
5236
- for (i = 1; i < len; i++) {
5237
- a = points[i - 1];
5238
- b = points[i];
5239
- codeB = lastCode = bitCode(b, bbox2);
5240
- while (true) {
5241
- if (!(codeA | codeB)) {
5242
- part.push(a);
5243
- if (codeB !== lastCode) {
5244
- part.push(b);
5245
- if (i < len - 1) {
5246
- result.push(part);
5247
- part = [];
5248
- }
5249
- } else if (i === len - 1) {
5250
- part.push(b);
5251
- }
5252
- break;
5253
- } else if (codeA & codeB) {
5254
- break;
5255
- } else if (codeA) {
5256
- a = intersect2(a, b, codeA, bbox2);
5257
- codeA = bitCode(a, bbox2);
5258
- } else {
5259
- b = intersect2(a, b, codeB, bbox2);
5260
- codeB = bitCode(b, bbox2);
5261
- }
5262
- }
5263
- codeA = lastCode;
5264
- }
5265
- if (part.length) result.push(part);
5266
- return result;
5267
- }
5268
- function polygonclip(points, bbox2) {
5269
- var result, edge, prev, prevInside, i, p, inside;
5270
- for (edge = 1; edge <= 8; edge *= 2) {
5271
- result = [];
5272
- prev = points[points.length - 1];
5273
- prevInside = !(bitCode(prev, bbox2) & edge);
5274
- for (i = 0; i < points.length; i++) {
5275
- p = points[i];
5276
- inside = !(bitCode(p, bbox2) & edge);
5277
- if (inside !== prevInside) result.push(intersect2(prev, p, edge, bbox2));
5278
- if (inside) result.push(p);
5279
- prev = p;
5280
- prevInside = inside;
5281
- }
5282
- points = result;
5283
- if (!points.length) break;
5284
- }
5285
- return result;
5286
- }
5287
- function intersect2(a, b, edge, bbox2) {
5288
- 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;
5289
- }
5290
- function bitCode(p, bbox2) {
5291
- var code = 0;
5292
- if (p[0] < bbox2[0]) code |= 1;
5293
- else if (p[0] > bbox2[2]) code |= 2;
5294
- if (p[1] < bbox2[1]) code |= 4;
5295
- else if (p[1] > bbox2[3]) code |= 8;
5296
- return code;
5297
- }
5298
- function bboxClip(feature2, bbox2) {
5299
- const geom = getGeom(feature2);
5300
- const type = geom.type;
5301
- const properties = feature2.type === "Feature" ? feature2.properties : {};
5302
- let coords = geom.coordinates;
5303
- switch (type) {
5304
- case "LineString":
5305
- case "MultiLineString": {
5306
- const lines = [];
5307
- if (type === "LineString") {
5308
- coords = [coords];
5309
- }
5310
- coords.forEach((line) => {
5311
- lineclip(line, bbox2, lines);
5312
- });
5313
- if (lines.length === 1) {
5314
- return lineString(lines[0], properties);
5315
- }
5316
- return multiLineString(lines, properties);
5317
- }
5318
- case "Polygon":
5319
- return polygon(clipPolygon(coords, bbox2), properties);
5320
- case "MultiPolygon":
5321
- return multiPolygon(
5322
- coords.map((poly) => {
5323
- return clipPolygon(poly, bbox2);
5324
- }),
5325
- properties
5326
- );
5327
- default:
5328
- throw new Error("geometry " + type + " not supported");
5329
- }
5330
- }
5331
- function clipPolygon(rings, bbox2) {
5332
- const outRings = [];
5333
- for (const ring of rings) {
5334
- const clipped = polygonclip(ring, bbox2);
5335
- if (clipped.length > 0) {
5336
- if (clipped[0][0] !== clipped[clipped.length - 1][0] || clipped[0][1] !== clipped[clipped.length - 1][1]) {
5337
- clipped.push(clipped[0]);
5338
- }
5339
- if (clipped.length >= 4) {
5340
- outRings.push(clipped);
5341
- }
5342
- }
5343
- }
5344
- return outRings;
5345
- }
5346
- var turf_bbox_clip_default = bboxClip;
5347
-
5348
- // src/filters/tileFeaturesSpatialIndex.ts
5349
- import { getResolution as h3GetResolution, polygonToCells } from "h3-js";
5396
+ import { getResolution as quadbinGetResolution } from "quadbin";
5397
+ import { getResolution as h3GetResolution } from "h3-js";
5350
5398
  function tileFeaturesSpatialIndex({
5351
5399
  tiles,
5352
5400
  spatialFilter,
@@ -5355,28 +5403,42 @@ function tileFeaturesSpatialIndex({
5355
5403
  }) {
5356
5404
  const map = /* @__PURE__ */ new Map();
5357
5405
  const spatialIndex = getSpatialIndex(spatialDataType);
5358
- const resolution = getResolution(tiles, spatialIndex);
5406
+ const cellResolution = getResolution(tiles, spatialIndex);
5359
5407
  const spatialIndexIDName = spatialDataColumn ? spatialDataColumn : spatialIndex;
5360
- if (!resolution) {
5408
+ if (!cellResolution) {
5361
5409
  return [];
5362
5410
  }
5363
- const cells = getCellsCoverGeometry(spatialFilter, spatialIndex, resolution);
5364
- if (!cells?.length) {
5365
- return [];
5411
+ let intersection3;
5412
+ if (spatialIndex === "h3" /* H3 */) {
5413
+ intersection3 = intersectTileH3(cellResolution, spatialFilter);
5366
5414
  }
5367
- const cellsSet = new Set(cells);
5368
5415
  for (const tile of tiles) {
5369
5416
  if (tile.isVisible === false || !tile.data) {
5370
5417
  continue;
5371
5418
  }
5419
+ if (spatialIndex === "quadbin" /* QUADBIN */) {
5420
+ const parent = getTileIndex(tile, spatialIndex);
5421
+ intersection3 = intersectTileQuadbin(
5422
+ parent,
5423
+ cellResolution,
5424
+ spatialFilter
5425
+ );
5426
+ }
5427
+ if (!intersection3) continue;
5372
5428
  tile.data.forEach((d) => {
5373
- if (cellsSet.has(d.id)) {
5429
+ if (intersection3 === true || intersection3.has(d.id)) {
5374
5430
  map.set(d.id, { ...d.properties, [spatialIndexIDName]: d.id });
5375
5431
  }
5376
5432
  });
5377
5433
  }
5378
5434
  return Array.from(map.values());
5379
5435
  }
5436
+ function getTileIndex(tile, spatialIndex) {
5437
+ if (spatialIndex === "quadbin" /* QUADBIN */) {
5438
+ return tile.index.q;
5439
+ }
5440
+ return tile.id;
5441
+ }
5380
5442
  function getResolution(tiles, spatialIndex) {
5381
5443
  const data = tiles.find((tile) => tile.data?.length)?.data;
5382
5444
  if (!data) {
@@ -5389,26 +5451,6 @@ function getResolution(tiles, spatialIndex) {
5389
5451
  return h3GetResolution(data[0].id);
5390
5452
  }
5391
5453
  }
5392
- var bboxWest = [-180, -90, 0, 90];
5393
- var bboxEast = [0, -90, 180, 90];
5394
- function getCellsCoverGeometry(geometry, spatialIndex, resolution) {
5395
- if (spatialIndex === "quadbin" /* QUADBIN */) {
5396
- return geometryToCells(geometry, resolution);
5397
- }
5398
- if (spatialIndex === "h3" /* H3 */) {
5399
- return polygonToCells(
5400
- turf_bbox_clip_default(geometry, bboxWest).geometry.coordinates,
5401
- resolution,
5402
- true
5403
- ).concat(
5404
- polygonToCells(
5405
- turf_bbox_clip_default(geometry, bboxEast).geometry.coordinates,
5406
- resolution,
5407
- true
5408
- )
5409
- );
5410
- }
5411
- }
5412
5454
  function getSpatialIndex(spatialDataType) {
5413
5455
  switch (spatialDataType) {
5414
5456
  case "h3":
@@ -5434,9 +5476,7 @@ var DEFAULT_AGGREGATION_EXP = `1 AS ${DEFAULT_AGGREGATION_EXP_ALIAS}`;
5434
5476
  // src/filters/tileFeaturesRaster.ts
5435
5477
  import {
5436
5478
  cellToChildren as _cellToChildren,
5437
- cellToBoundary,
5438
5479
  cellToTile,
5439
- geometryToCells as geometryToCells2,
5440
5480
  getResolution as getResolution2
5441
5481
  } from "quadbin";
5442
5482
  function tileFeaturesRaster({
@@ -5455,15 +5495,15 @@ function tileFeaturesRaster({
5455
5495
  const data = /* @__PURE__ */ new Map();
5456
5496
  for (const tile of tiles) {
5457
5497
  const parent = tile.index.q;
5458
- const tilePolygon = cellToBoundary(parent);
5459
- const tileFilter = turf_intersect_default(
5460
- featureCollection([feature(tilePolygon), feature(options.spatialFilter)])
5498
+ const intersection3 = intersectTileRaster(
5499
+ parent,
5500
+ cellResolution,
5501
+ options.spatialFilter
5461
5502
  );
5462
- const needsFilter = tileFilter ? !turf_boolean_within_default(tilePolygon, options.spatialFilter) : false;
5463
- const tileFilterCells = needsFilter ? new Set(geometryToCells2(tileFilter.geometry, cellResolution)) : null;
5503
+ if (intersection3 === false) continue;
5464
5504
  const tileSortedCells = cellToChildrenSorted(parent, cellResolution);
5465
5505
  for (let i = 0; i < tileSortedCells.length; i++) {
5466
- if (needsFilter && !tileFilterCells.has(tileSortedCells[i])) {
5506
+ if (intersection3 !== true && !intersection3.has(tileSortedCells[i])) {
5467
5507
  continue;
5468
5508
  }
5469
5509
  const cellData = {};
@@ -7186,7 +7226,7 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
7186
7226
  }
7187
7227
  _extractTileFeatures(spatialFilter) {
7188
7228
  const prevInputs = this._tileFeatureExtractPreviousInputs;
7189
- if (this._features.length && prevInputs.spatialFilter && booleanEqual(prevInputs.spatialFilter, spatialFilter)) {
7229
+ if (this._features.length && spatialFilterEquals(prevInputs.spatialFilter, spatialFilter)) {
7190
7230
  return;
7191
7231
  }
7192
7232
  this._features = tileFeatures({
@@ -7426,7 +7466,6 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
7426
7466
  * INTERNAL
7427
7467
  */
7428
7468
  _getFilteredFeatures(spatialFilter, filters, filterOwner) {
7429
- assert2(spatialFilter, "spatialFilter required for tilesets");
7430
7469
  this._extractTileFeatures(spatialFilter);
7431
7470
  return applyFilters(
7432
7471
  this._features,
@@ -7450,6 +7489,11 @@ function assertColumn(features, ...columnArgs) {
7450
7489
  function normalizeColumns(columns) {
7451
7490
  return Array.isArray(columns) ? columns : typeof columns === "string" ? [columns] : [];
7452
7491
  }
7492
+ function spatialFilterEquals(a, b) {
7493
+ if (a === b) return true;
7494
+ if (!a || !b) return false;
7495
+ return booleanEqual(a, b);
7496
+ }
7453
7497
 
7454
7498
  // src/widget-sources/widget-tileset-source.ts
7455
7499
  var WidgetTilesetSource = class extends WidgetSource {