@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.
package/build/worker.js CHANGED
@@ -1505,6 +1505,110 @@ function geojsonFeatures({
1505
1505
  return Array.from(map.values());
1506
1506
  }
1507
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
+
1508
1612
  // node_modules/@turf/bbox-polygon/dist/esm/index.js
1509
1613
  function bboxPolygon(bbox2, options = {}) {
1510
1614
  const west = Number(bbox2[0]);
@@ -1823,7 +1927,7 @@ var MAX_SAFE_INTEGER = 9007199254740991;
1823
1927
  var POWS_TEN = [1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13];
1824
1928
  var SQRT_BASE = 1e7;
1825
1929
  var MAX = 1e9;
1826
- function clone(configObject) {
1930
+ function clone2(configObject) {
1827
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 = {
1828
1932
  prefix: "",
1829
1933
  groupSize: 3,
@@ -1949,7 +2053,7 @@ function clone(configObject) {
1949
2053
  x.c = [x.e = 0];
1950
2054
  }
1951
2055
  }
1952
- BigNumber2.clone = clone;
2056
+ BigNumber2.clone = clone2;
1953
2057
  BigNumber2.ROUND_UP = 0;
1954
2058
  BigNumber2.ROUND_DOWN = 1;
1955
2059
  BigNumber2.ROUND_CEIL = 2;
@@ -3152,7 +3256,7 @@ function toFixedPoint(str, e, z) {
3152
3256
  }
3153
3257
  return str;
3154
3258
  }
3155
- var BigNumber = clone();
3259
+ var BigNumber = clone2();
3156
3260
  var bignumber_default = BigNumber;
3157
3261
 
3158
3262
  // node_modules/splaytree-ts/dist/esm/index.js
@@ -4721,117 +4825,7 @@ function intersect(features, options = {}) {
4721
4825
  }
4722
4826
  var turf_intersect_default = intersect;
4723
4827
 
4724
- // node_modules/@math.gl/core/dist/lib/common.js
4725
- var RADIANS_TO_DEGREES = 1 / Math.PI * 180;
4726
- var DEGREES_TO_RADIANS = 1 / 180 * Math.PI;
4727
- var DEFAULT_CONFIG = {
4728
- EPSILON: 1e-12,
4729
- debug: false,
4730
- precision: 4,
4731
- printTypes: false,
4732
- printDegrees: false,
4733
- printRowMajor: true,
4734
- _cartographicRadians: false
4735
- };
4736
- globalThis.mathgl = globalThis.mathgl || { config: { ...DEFAULT_CONFIG } };
4737
- var config = globalThis.mathgl.config;
4738
- function isArray(value) {
4739
- return Array.isArray(value) || ArrayBuffer.isView(value) && !(value instanceof DataView);
4740
- }
4741
- function lerp(a, b, t) {
4742
- if (isArray(a)) {
4743
- return a.map((ai, i) => lerp(ai, b[i], t));
4744
- }
4745
- return t * b + (1 - t) * a;
4746
- }
4747
-
4748
- // node_modules/@math.gl/web-mercator/dist/assert.js
4749
- function assert2(condition, message) {
4750
- if (!condition) {
4751
- throw new Error(message || "@math.gl/web-mercator: assertion failed.");
4752
- }
4753
- }
4754
-
4755
- // node_modules/@math.gl/web-mercator/dist/web-mercator-utils.js
4756
- var PI = Math.PI;
4757
- var PI_4 = PI / 4;
4758
- var DEGREES_TO_RADIANS2 = PI / 180;
4759
- var RADIANS_TO_DEGREES2 = 180 / PI;
4760
- var TILE_SIZE = 512;
4761
- function lngLatToWorld(lngLat) {
4762
- const [lng, lat] = lngLat;
4763
- assert2(Number.isFinite(lng));
4764
- assert2(Number.isFinite(lat) && lat >= -90 && lat <= 90, "invalid latitude");
4765
- const lambda2 = lng * DEGREES_TO_RADIANS2;
4766
- const phi2 = lat * DEGREES_TO_RADIANS2;
4767
- const x = TILE_SIZE * (lambda2 + PI) / (2 * PI);
4768
- const y = TILE_SIZE * (PI + Math.log(Math.tan(PI_4 + phi2 * 0.5))) / (2 * PI);
4769
- return [x, y];
4770
- }
4771
- function worldToLngLat(xy) {
4772
- const [x, y] = xy;
4773
- const lambda2 = x / TILE_SIZE * (2 * PI) - PI;
4774
- const phi2 = 2 * (Math.atan(Math.exp(y / TILE_SIZE * (2 * PI) - PI)) - PI_4);
4775
- return [lambda2 * RADIANS_TO_DEGREES2, phi2 * RADIANS_TO_DEGREES2];
4776
- }
4777
-
4778
- // node_modules/@math.gl/web-mercator/dist/get-bounds.js
4779
- var DEGREES_TO_RADIANS3 = Math.PI / 180;
4780
-
4781
4828
  // src/utils/transformToTileCoords.ts
4782
- var TRANSFORM_FN = {
4783
- Point: transformPoint,
4784
- MultiPoint: transformMultiPoint,
4785
- LineString: transformLineString,
4786
- MultiLineString: transformMultiLineString,
4787
- Polygon: transformPolygon,
4788
- MultiPolygon: transformMultiPolygon
4789
- };
4790
- function transformToTileCoords(geometry, bbox2) {
4791
- const [west, south, east, north] = bbox2;
4792
- const nw = projectFlat([west, north]);
4793
- const se = projectFlat([east, south]);
4794
- const projectedBbox = [nw, se];
4795
- if (geometry.type === "GeometryCollection") {
4796
- throw new Error("Unsupported geometry type GeometryCollection");
4797
- }
4798
- const transformFn = TRANSFORM_FN[geometry.type];
4799
- const coordinates = transformFn(geometry.coordinates, projectedBbox);
4800
- return { ...geometry, coordinates };
4801
- }
4802
- function transformPoint([pointX, pointY], [nw, se]) {
4803
- const x = inverseLerp(nw[0], se[0], pointX);
4804
- const y = inverseLerp(nw[1], se[1], pointY);
4805
- return [x, y];
4806
- }
4807
- function getPoints(geometry, bbox2) {
4808
- return geometry.map((g) => transformPoint(projectFlat(g), bbox2));
4809
- }
4810
- function transformMultiPoint(multiPoint, bbox2) {
4811
- return getPoints(multiPoint, bbox2);
4812
- }
4813
- function transformLineString(line, bbox2) {
4814
- return getPoints(line, bbox2);
4815
- }
4816
- function transformMultiLineString(multiLineString2, bbox2) {
4817
- return multiLineString2.map(
4818
- (lineString2) => transformLineString(lineString2, bbox2)
4819
- );
4820
- }
4821
- function transformPolygon(polygon2, bbox2) {
4822
- return polygon2.map((polygonRing) => getPoints(polygonRing, bbox2));
4823
- }
4824
- function transformMultiPolygon(multiPolygon2, bbox2) {
4825
- return multiPolygon2.map((polygon2) => transformPolygon(polygon2, bbox2));
4826
- }
4827
- function projectFlat(xyz) {
4828
- return lngLatToWorld(xyz);
4829
- }
4830
- function inverseLerp(a, b, x) {
4831
- return (x - a) / (b - a);
4832
- }
4833
-
4834
- // src/utils/transformTileCoordsToWGS84.ts
4835
4829
  var TRANSFORM_FN2 = {
4836
4830
  Point: transformPoint2,
4837
4831
  MultiPoint: transformMultiPoint2,
@@ -4840,10 +4834,10 @@ var TRANSFORM_FN2 = {
4840
4834
  Polygon: transformPolygon2,
4841
4835
  MultiPolygon: transformMultiPolygon2
4842
4836
  };
4843
- function transformTileCoordsToWGS84(geometry, bbox2) {
4837
+ function transformToTileCoords(geometry, bbox2) {
4844
4838
  const [west, south, east, north] = bbox2;
4845
- const nw = lngLatToWorld([west, north]);
4846
- const se = lngLatToWorld([east, south]);
4839
+ const nw = projectFlat([west, north]);
4840
+ const se = projectFlat([east, south]);
4847
4841
  const projectedBbox = [nw, se];
4848
4842
  if (geometry.type === "GeometryCollection") {
4849
4843
  throw new Error("Unsupported geometry type GeometryCollection");
@@ -4853,12 +4847,12 @@ function transformTileCoordsToWGS84(geometry, bbox2) {
4853
4847
  return { ...geometry, coordinates };
4854
4848
  }
4855
4849
  function transformPoint2([pointX, pointY], [nw, se]) {
4856
- const x = lerp(nw[0], se[0], pointX);
4857
- const y = lerp(nw[1], se[1], pointY);
4858
- 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];
4859
4853
  }
4860
4854
  function getPoints2(geometry, bbox2) {
4861
- return geometry.map((g) => transformPoint2(g, bbox2));
4855
+ return geometry.map((g) => transformPoint2(projectFlat(g), bbox2));
4862
4856
  }
4863
4857
  function transformMultiPoint2(multiPoint, bbox2) {
4864
4858
  return getPoints2(multiPoint, bbox2);
@@ -4877,70 +4871,245 @@ function transformPolygon2(polygon2, bbox2) {
4877
4871
  function transformMultiPolygon2(multiPolygon2, bbox2) {
4878
4872
  return multiPolygon2.map((polygon2) => transformPolygon2(polygon2, bbox2));
4879
4873
  }
4874
+ function projectFlat(xyz) {
4875
+ return lngLatToWorld(xyz);
4876
+ }
4877
+ function inverseLerp(a, b, x) {
4878
+ return (x - a) / (b - a);
4879
+ }
4880
4880
 
4881
- // src/filters/tileFeaturesGeometries.ts
4882
- var FEATURE_GEOM_PROPERTY = "__geomValue";
4883
- function tileFeaturesGeometries({
4884
- tiles,
4885
- tileFormat,
4886
- spatialFilter,
4887
- uniqueIdProperty,
4888
- options
4889
- }) {
4890
- const map = /* @__PURE__ */ new Map();
4891
- for (const tile of tiles) {
4892
- if (tile.isVisible === false || !tile.data) {
4893
- continue;
4894
- }
4895
- const bbox2 = [
4896
- tile.bbox.west,
4897
- tile.bbox.south,
4898
- tile.bbox.east,
4899
- tile.bbox.north
4900
- ];
4901
- const bboxToGeom = turf_bbox_polygon_default(bbox2);
4902
- const tileIsFullyVisible = turf_boolean_within_default(bboxToGeom, spatialFilter);
4903
- const spatialFilterFeature = {
4904
- type: "Feature",
4905
- geometry: spatialFilter,
4906
- properties: {}
4907
- };
4908
- const clippedGeometryToIntersect = turf_intersect_default(
4909
- featureCollection([bboxToGeom, spatialFilterFeature])
4910
- );
4911
- if (!clippedGeometryToIntersect) {
4912
- continue;
4913
- }
4914
- const transformedGeometryToIntersect = tileFormat === "mvt" /* MVT */ ? transformToTileCoords(clippedGeometryToIntersect.geometry, bbox2) : clippedGeometryToIntersect.geometry;
4915
- calculateFeatures({
4916
- map,
4917
- tileIsFullyVisible,
4918
- geometryIntersection: transformedGeometryToIntersect,
4919
- data: tile.data.points,
4881
+ // src/filters/tileIntersection.ts
4882
+ import {
4883
+ cellToBoundary as quadbinCellToBoundary,
4884
+ geometryToCells as quadbinGeometryToCells
4885
+ } from "quadbin";
4886
+ import { polygonToCells as h3PolygonToCells } from "h3-js";
4887
+
4888
+ // node_modules/@turf/bbox-clip/dist/esm/index.js
4889
+ function lineclip(points, bbox2, result) {
4890
+ var len = points.length, codeA = bitCode(points[0], bbox2), part = [], i, codeB, lastCode;
4891
+ let a;
4892
+ let b;
4893
+ if (!result) result = [];
4894
+ for (i = 1; i < len; i++) {
4895
+ a = points[i - 1];
4896
+ b = points[i];
4897
+ codeB = lastCode = bitCode(b, bbox2);
4898
+ while (true) {
4899
+ if (!(codeA | codeB)) {
4900
+ part.push(a);
4901
+ if (codeB !== lastCode) {
4902
+ part.push(b);
4903
+ if (i < len - 1) {
4904
+ result.push(part);
4905
+ part = [];
4906
+ }
4907
+ } else if (i === len - 1) {
4908
+ part.push(b);
4909
+ }
4910
+ break;
4911
+ } else if (codeA & codeB) {
4912
+ break;
4913
+ } else if (codeA) {
4914
+ a = intersect2(a, b, codeA, bbox2);
4915
+ codeA = bitCode(a, bbox2);
4916
+ } else {
4917
+ b = intersect2(a, b, codeB, bbox2);
4918
+ codeB = bitCode(b, bbox2);
4919
+ }
4920
+ }
4921
+ codeA = lastCode;
4922
+ }
4923
+ if (part.length) result.push(part);
4924
+ return result;
4925
+ }
4926
+ function polygonclip(points, bbox2) {
4927
+ var result, edge, prev, prevInside, i, p, inside;
4928
+ for (edge = 1; edge <= 8; edge *= 2) {
4929
+ result = [];
4930
+ prev = points[points.length - 1];
4931
+ prevInside = !(bitCode(prev, bbox2) & edge);
4932
+ for (i = 0; i < points.length; i++) {
4933
+ p = points[i];
4934
+ inside = !(bitCode(p, bbox2) & edge);
4935
+ if (inside !== prevInside) result.push(intersect2(prev, p, edge, bbox2));
4936
+ if (inside) result.push(p);
4937
+ prev = p;
4938
+ prevInside = inside;
4939
+ }
4940
+ points = result;
4941
+ if (!points.length) break;
4942
+ }
4943
+ return result;
4944
+ }
4945
+ function intersect2(a, b, edge, bbox2) {
4946
+ 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;
4947
+ }
4948
+ function bitCode(p, bbox2) {
4949
+ var code = 0;
4950
+ if (p[0] < bbox2[0]) code |= 1;
4951
+ else if (p[0] > bbox2[2]) code |= 2;
4952
+ if (p[1] < bbox2[1]) code |= 4;
4953
+ else if (p[1] > bbox2[3]) code |= 8;
4954
+ return code;
4955
+ }
4956
+ function bboxClip(feature2, bbox2) {
4957
+ const geom = getGeom(feature2);
4958
+ const type = geom.type;
4959
+ const properties = feature2.type === "Feature" ? feature2.properties : {};
4960
+ let coords = geom.coordinates;
4961
+ switch (type) {
4962
+ case "LineString":
4963
+ case "MultiLineString": {
4964
+ const lines = [];
4965
+ if (type === "LineString") {
4966
+ coords = [coords];
4967
+ }
4968
+ coords.forEach((line) => {
4969
+ lineclip(line, bbox2, lines);
4970
+ });
4971
+ if (lines.length === 1) {
4972
+ return lineString(lines[0], properties);
4973
+ }
4974
+ return multiLineString(lines, properties);
4975
+ }
4976
+ case "Polygon":
4977
+ return polygon(clipPolygon(coords, bbox2), properties);
4978
+ case "MultiPolygon":
4979
+ return multiPolygon(
4980
+ coords.map((poly) => {
4981
+ return clipPolygon(poly, bbox2);
4982
+ }),
4983
+ properties
4984
+ );
4985
+ default:
4986
+ throw new Error("geometry " + type + " not supported");
4987
+ }
4988
+ }
4989
+ function clipPolygon(rings, bbox2) {
4990
+ const outRings = [];
4991
+ for (const ring of rings) {
4992
+ const clipped = polygonclip(ring, bbox2);
4993
+ if (clipped.length > 0) {
4994
+ if (clipped[0][0] !== clipped[clipped.length - 1][0] || clipped[0][1] !== clipped[clipped.length - 1][1]) {
4995
+ clipped.push(clipped[0]);
4996
+ }
4997
+ if (clipped.length >= 4) {
4998
+ outRings.push(clipped);
4999
+ }
5000
+ }
5001
+ }
5002
+ return outRings;
5003
+ }
5004
+ var turf_bbox_clip_default = bboxClip;
5005
+
5006
+ // src/filters/tileIntersection.ts
5007
+ function intersectTileGeometry(tileBbox, tileFormat, spatialFilter) {
5008
+ const tilePolygon = turf_bbox_polygon_default(tileBbox);
5009
+ if (!spatialFilter || turf_boolean_within_default(tilePolygon, spatialFilter)) {
5010
+ return true;
5011
+ }
5012
+ const clippedSpatialFilter = turf_intersect_default(
5013
+ featureCollection([tilePolygon, feature(spatialFilter)])
5014
+ );
5015
+ if (!clippedSpatialFilter) {
5016
+ return false;
5017
+ }
5018
+ return tileFormat === "mvt" /* MVT */ ? transformToTileCoords(clippedSpatialFilter.geometry, tileBbox) : clippedSpatialFilter.geometry;
5019
+ }
5020
+ function intersectTileRaster(parent, cellResolution, spatialFilter) {
5021
+ return intersectTileQuadbin(parent, cellResolution, spatialFilter);
5022
+ }
5023
+ function intersectTileQuadbin(parent, cellResolution, spatialFilter) {
5024
+ const tilePolygon = quadbinCellToBoundary(parent);
5025
+ if (!spatialFilter || turf_boolean_within_default(tilePolygon, spatialFilter)) {
5026
+ return true;
5027
+ }
5028
+ const clippedSpatialFilter = turf_intersect_default(
5029
+ featureCollection([feature(tilePolygon), feature(spatialFilter)])
5030
+ );
5031
+ if (!clippedSpatialFilter) {
5032
+ return false;
5033
+ }
5034
+ const cells = quadbinGeometryToCells(
5035
+ clippedSpatialFilter.geometry,
5036
+ cellResolution
5037
+ );
5038
+ return new Set(cells);
5039
+ }
5040
+ var BBOX_WEST = [-180, -90, 0, 90];
5041
+ var BBOX_EAST = [0, -90, 180, 90];
5042
+ function intersectTileH3(cellResolution, spatialFilter) {
5043
+ if (!spatialFilter) {
5044
+ return true;
5045
+ }
5046
+ const spatialFilterFeature = feature(spatialFilter);
5047
+ const cellsWest = h3PolygonToCells(
5048
+ turf_bbox_clip_default(spatialFilterFeature, BBOX_WEST).geometry.coordinates,
5049
+ cellResolution,
5050
+ true
5051
+ );
5052
+ const cellsEast = h3PolygonToCells(
5053
+ turf_bbox_clip_default(spatialFilterFeature, BBOX_EAST).geometry.coordinates,
5054
+ cellResolution,
5055
+ true
5056
+ );
5057
+ return new Set(cellsWest.concat(cellsEast));
5058
+ }
5059
+
5060
+ // src/filters/tileFeaturesGeometries.ts
5061
+ var FEATURE_GEOM_PROPERTY = "__geomValue";
5062
+ function tileFeaturesGeometries({
5063
+ tiles,
5064
+ tileFormat,
5065
+ spatialFilter,
5066
+ uniqueIdProperty,
5067
+ options
5068
+ }) {
5069
+ const map = /* @__PURE__ */ new Map();
5070
+ for (const tile of tiles) {
5071
+ if (tile.isVisible === false || !tile.data) {
5072
+ continue;
5073
+ }
5074
+ const tileBbox = [
5075
+ tile.bbox.west,
5076
+ tile.bbox.south,
5077
+ tile.bbox.east,
5078
+ tile.bbox.north
5079
+ ];
5080
+ const intersection3 = intersectTileGeometry(
5081
+ tileBbox,
5082
+ tileFormat,
5083
+ spatialFilter
5084
+ );
5085
+ if (intersection3 === false) continue;
5086
+ const transformedSpatialFilter = intersection3 === true ? void 0 : intersection3;
5087
+ calculateFeatures({
5088
+ map,
5089
+ spatialFilter: transformedSpatialFilter,
5090
+ data: tile.data.points,
4920
5091
  type: "Point",
4921
- bbox: bbox2,
5092
+ bbox: tileBbox,
4922
5093
  tileFormat,
4923
5094
  uniqueIdProperty,
4924
5095
  options
4925
5096
  });
4926
5097
  calculateFeatures({
4927
5098
  map,
4928
- tileIsFullyVisible,
4929
- geometryIntersection: transformedGeometryToIntersect,
5099
+ spatialFilter: transformedSpatialFilter,
4930
5100
  data: tile.data.lines,
4931
5101
  type: "LineString",
4932
- bbox: bbox2,
5102
+ bbox: tileBbox,
4933
5103
  tileFormat,
4934
5104
  uniqueIdProperty,
4935
5105
  options
4936
5106
  });
4937
5107
  calculateFeatures({
4938
5108
  map,
4939
- tileIsFullyVisible,
4940
- geometryIntersection: transformedGeometryToIntersect,
5109
+ spatialFilter: transformedSpatialFilter,
4941
5110
  data: tile.data.polygons,
4942
5111
  type: "Polygon",
4943
- bbox: bbox2,
5112
+ bbox: tileBbox,
4944
5113
  tileFormat,
4945
5114
  uniqueIdProperty,
4946
5115
  options
@@ -4958,7 +5127,7 @@ function processTileFeatureProperties({
4958
5127
  tileFormat,
4959
5128
  uniqueIdProperty,
4960
5129
  storeGeometry,
4961
- geometryIntersection
5130
+ spatialFilter
4962
5131
  }) {
4963
5132
  const tileProps = getPropertiesFromTile(data, startIndex);
4964
5133
  const uniquePropertyValue = getUniquePropertyValue(
@@ -4970,7 +5139,7 @@ function processTileFeatureProperties({
4970
5139
  return;
4971
5140
  }
4972
5141
  let geometry = null;
4973
- if (storeGeometry || geometryIntersection) {
5142
+ if (storeGeometry || spatialFilter) {
4974
5143
  const { positions } = data;
4975
5144
  const ringCoordinates = getRingCoordinatesFor(
4976
5145
  startIndex,
@@ -4979,7 +5148,7 @@ function processTileFeatureProperties({
4979
5148
  );
4980
5149
  geometry = getFeatureByType(ringCoordinates, type);
4981
5150
  }
4982
- if (geometry && geometryIntersection && !turf_boolean_intersects_default(geometry, geometryIntersection)) {
5151
+ if (geometry && spatialFilter && !turf_boolean_intersects_default(geometry, spatialFilter)) {
4983
5152
  return;
4984
5153
  }
4985
5154
  const properties = parseProperties(tileProps);
@@ -4991,7 +5160,7 @@ function processTileFeatureProperties({
4991
5160
  function addIntersectedFeaturesInTile({
4992
5161
  map,
4993
5162
  data,
4994
- geometryIntersection,
5163
+ spatialFilter,
4995
5164
  type,
4996
5165
  bbox: bbox2,
4997
5166
  tileFormat,
@@ -5013,7 +5182,7 @@ function addIntersectedFeaturesInTile({
5013
5182
  tileFormat,
5014
5183
  uniqueIdProperty,
5015
5184
  storeGeometry,
5016
- geometryIntersection
5185
+ spatialFilter
5017
5186
  });
5018
5187
  }
5019
5188
  }
@@ -5095,8 +5264,7 @@ function getRingCoordinatesFor(startIndex, endIndex, positions) {
5095
5264
  }
5096
5265
  function calculateFeatures({
5097
5266
  map,
5098
- tileIsFullyVisible,
5099
- geometryIntersection,
5267
+ spatialFilter,
5100
5268
  data,
5101
5269
  type,
5102
5270
  bbox: bbox2,
@@ -5107,7 +5275,7 @@ function calculateFeatures({
5107
5275
  if (!data?.properties.length) {
5108
5276
  return;
5109
5277
  }
5110
- if (tileIsFullyVisible) {
5278
+ if (!spatialFilter) {
5111
5279
  addAllFeaturesInTile({
5112
5280
  map,
5113
5281
  data,
@@ -5121,7 +5289,7 @@ function calculateFeatures({
5121
5289
  addIntersectedFeaturesInTile({
5122
5290
  map,
5123
5291
  data,
5124
- geometryIntersection,
5292
+ spatialFilter,
5125
5293
  type,
5126
5294
  bbox: bbox2,
5127
5295
  tileFormat,
@@ -5171,128 +5339,8 @@ function createIndicesForPoints(data) {
5171
5339
  }
5172
5340
 
5173
5341
  // src/filters/tileFeaturesSpatialIndex.ts
5174
- import { getResolution as quadbinGetResolution, geometryToCells } from "quadbin";
5175
-
5176
- // node_modules/@turf/bbox-clip/dist/esm/index.js
5177
- function lineclip(points, bbox2, result) {
5178
- var len = points.length, codeA = bitCode(points[0], bbox2), part = [], i, codeB, lastCode;
5179
- let a;
5180
- let b;
5181
- if (!result) result = [];
5182
- for (i = 1; i < len; i++) {
5183
- a = points[i - 1];
5184
- b = points[i];
5185
- codeB = lastCode = bitCode(b, bbox2);
5186
- while (true) {
5187
- if (!(codeA | codeB)) {
5188
- part.push(a);
5189
- if (codeB !== lastCode) {
5190
- part.push(b);
5191
- if (i < len - 1) {
5192
- result.push(part);
5193
- part = [];
5194
- }
5195
- } else if (i === len - 1) {
5196
- part.push(b);
5197
- }
5198
- break;
5199
- } else if (codeA & codeB) {
5200
- break;
5201
- } else if (codeA) {
5202
- a = intersect2(a, b, codeA, bbox2);
5203
- codeA = bitCode(a, bbox2);
5204
- } else {
5205
- b = intersect2(a, b, codeB, bbox2);
5206
- codeB = bitCode(b, bbox2);
5207
- }
5208
- }
5209
- codeA = lastCode;
5210
- }
5211
- if (part.length) result.push(part);
5212
- return result;
5213
- }
5214
- function polygonclip(points, bbox2) {
5215
- var result, edge, prev, prevInside, i, p, inside;
5216
- for (edge = 1; edge <= 8; edge *= 2) {
5217
- result = [];
5218
- prev = points[points.length - 1];
5219
- prevInside = !(bitCode(prev, bbox2) & edge);
5220
- for (i = 0; i < points.length; i++) {
5221
- p = points[i];
5222
- inside = !(bitCode(p, bbox2) & edge);
5223
- if (inside !== prevInside) result.push(intersect2(prev, p, edge, bbox2));
5224
- if (inside) result.push(p);
5225
- prev = p;
5226
- prevInside = inside;
5227
- }
5228
- points = result;
5229
- if (!points.length) break;
5230
- }
5231
- return result;
5232
- }
5233
- function intersect2(a, b, edge, bbox2) {
5234
- 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;
5235
- }
5236
- function bitCode(p, bbox2) {
5237
- var code = 0;
5238
- if (p[0] < bbox2[0]) code |= 1;
5239
- else if (p[0] > bbox2[2]) code |= 2;
5240
- if (p[1] < bbox2[1]) code |= 4;
5241
- else if (p[1] > bbox2[3]) code |= 8;
5242
- return code;
5243
- }
5244
- function bboxClip(feature2, bbox2) {
5245
- const geom = getGeom(feature2);
5246
- const type = geom.type;
5247
- const properties = feature2.type === "Feature" ? feature2.properties : {};
5248
- let coords = geom.coordinates;
5249
- switch (type) {
5250
- case "LineString":
5251
- case "MultiLineString": {
5252
- const lines = [];
5253
- if (type === "LineString") {
5254
- coords = [coords];
5255
- }
5256
- coords.forEach((line) => {
5257
- lineclip(line, bbox2, lines);
5258
- });
5259
- if (lines.length === 1) {
5260
- return lineString(lines[0], properties);
5261
- }
5262
- return multiLineString(lines, properties);
5263
- }
5264
- case "Polygon":
5265
- return polygon(clipPolygon(coords, bbox2), properties);
5266
- case "MultiPolygon":
5267
- return multiPolygon(
5268
- coords.map((poly) => {
5269
- return clipPolygon(poly, bbox2);
5270
- }),
5271
- properties
5272
- );
5273
- default:
5274
- throw new Error("geometry " + type + " not supported");
5275
- }
5276
- }
5277
- function clipPolygon(rings, bbox2) {
5278
- const outRings = [];
5279
- for (const ring of rings) {
5280
- const clipped = polygonclip(ring, bbox2);
5281
- if (clipped.length > 0) {
5282
- if (clipped[0][0] !== clipped[clipped.length - 1][0] || clipped[0][1] !== clipped[clipped.length - 1][1]) {
5283
- clipped.push(clipped[0]);
5284
- }
5285
- if (clipped.length >= 4) {
5286
- outRings.push(clipped);
5287
- }
5288
- }
5289
- }
5290
- return outRings;
5291
- }
5292
- var turf_bbox_clip_default = bboxClip;
5293
-
5294
- // src/filters/tileFeaturesSpatialIndex.ts
5295
- import { getResolution as h3GetResolution, polygonToCells } from "h3-js";
5342
+ import { getResolution as quadbinGetResolution } from "quadbin";
5343
+ import { getResolution as h3GetResolution } from "h3-js";
5296
5344
  function tileFeaturesSpatialIndex({
5297
5345
  tiles,
5298
5346
  spatialFilter,
@@ -5301,28 +5349,42 @@ function tileFeaturesSpatialIndex({
5301
5349
  }) {
5302
5350
  const map = /* @__PURE__ */ new Map();
5303
5351
  const spatialIndex = getSpatialIndex(spatialDataType);
5304
- const resolution = getResolution(tiles, spatialIndex);
5352
+ const cellResolution = getResolution(tiles, spatialIndex);
5305
5353
  const spatialIndexIDName = spatialDataColumn ? spatialDataColumn : spatialIndex;
5306
- if (!resolution) {
5354
+ if (!cellResolution) {
5307
5355
  return [];
5308
5356
  }
5309
- const cells = getCellsCoverGeometry(spatialFilter, spatialIndex, resolution);
5310
- if (!cells?.length) {
5311
- return [];
5357
+ let intersection3;
5358
+ if (spatialIndex === "h3" /* H3 */) {
5359
+ intersection3 = intersectTileH3(cellResolution, spatialFilter);
5312
5360
  }
5313
- const cellsSet = new Set(cells);
5314
5361
  for (const tile of tiles) {
5315
5362
  if (tile.isVisible === false || !tile.data) {
5316
5363
  continue;
5317
5364
  }
5365
+ if (spatialIndex === "quadbin" /* QUADBIN */) {
5366
+ const parent = getTileIndex(tile, spatialIndex);
5367
+ intersection3 = intersectTileQuadbin(
5368
+ parent,
5369
+ cellResolution,
5370
+ spatialFilter
5371
+ );
5372
+ }
5373
+ if (!intersection3) continue;
5318
5374
  tile.data.forEach((d) => {
5319
- if (cellsSet.has(d.id)) {
5375
+ if (intersection3 === true || intersection3.has(d.id)) {
5320
5376
  map.set(d.id, { ...d.properties, [spatialIndexIDName]: d.id });
5321
5377
  }
5322
5378
  });
5323
5379
  }
5324
5380
  return Array.from(map.values());
5325
5381
  }
5382
+ function getTileIndex(tile, spatialIndex) {
5383
+ if (spatialIndex === "quadbin" /* QUADBIN */) {
5384
+ return tile.index.q;
5385
+ }
5386
+ return tile.id;
5387
+ }
5326
5388
  function getResolution(tiles, spatialIndex) {
5327
5389
  const data = tiles.find((tile) => tile.data?.length)?.data;
5328
5390
  if (!data) {
@@ -5335,26 +5397,6 @@ function getResolution(tiles, spatialIndex) {
5335
5397
  return h3GetResolution(data[0].id);
5336
5398
  }
5337
5399
  }
5338
- var bboxWest = [-180, -90, 0, 90];
5339
- var bboxEast = [0, -90, 180, 90];
5340
- function getCellsCoverGeometry(geometry, spatialIndex, resolution) {
5341
- if (spatialIndex === "quadbin" /* QUADBIN */) {
5342
- return geometryToCells(geometry, resolution);
5343
- }
5344
- if (spatialIndex === "h3" /* H3 */) {
5345
- return polygonToCells(
5346
- turf_bbox_clip_default(geometry, bboxWest).geometry.coordinates,
5347
- resolution,
5348
- true
5349
- ).concat(
5350
- polygonToCells(
5351
- turf_bbox_clip_default(geometry, bboxEast).geometry.coordinates,
5352
- resolution,
5353
- true
5354
- )
5355
- );
5356
- }
5357
- }
5358
5400
  function getSpatialIndex(spatialDataType) {
5359
5401
  switch (spatialDataType) {
5360
5402
  case "h3":
@@ -5375,67 +5417,8 @@ var DEFAULT_AGGREGATION_EXP = `1 AS ${DEFAULT_AGGREGATION_EXP_ALIAS}`;
5375
5417
  import {
5376
5418
  cellToChildren as _cellToChildren,
5377
5419
  cellToTile,
5378
- geometryToCells as geometryToCells2,
5379
5420
  getResolution as getResolution2
5380
5421
  } from "quadbin";
5381
-
5382
- // src/utils/CellSet.ts
5383
- var EMPTY_U32 = 2 ** 32 - 1;
5384
- var CellSet = class {
5385
- constructor(cells) {
5386
- /** List of cells stored by the set. Stored by reference, without copying. */
5387
- __publicField(this, "cells");
5388
- /** DataView representing a single cell ID. Pre-allocated to reduce memory during queries. */
5389
- __publicField(this, "cellView", new DataView(new ArrayBuffer(8)));
5390
- /** Hash table, mapping a hash index (computed) to an index in the 'cells' array. */
5391
- __publicField(this, "hashTable");
5392
- this.cells = cells;
5393
- this.hashTable = new Uint32Array(hashBuckets(cells.length)).fill(EMPTY_U32);
5394
- for (let cellIndex = 0; cellIndex < cells.length; cellIndex++) {
5395
- this.hashTable[this.hashLookup(cells[cellIndex])] = cellIndex;
5396
- }
5397
- }
5398
- has(cell) {
5399
- const hashIndex = this.hashLookup(cell);
5400
- return this.hashTable[hashIndex] !== EMPTY_U32;
5401
- }
5402
- hashLookup(cell) {
5403
- this.cellView.setBigUint64(0, cell);
5404
- const hashval = hash(this.cellView);
5405
- const hashmod = this.hashTable.length - 1;
5406
- let bucket = hashval & hashmod;
5407
- for (let probe = 0; probe <= hashmod; probe++) {
5408
- const cellIndex = this.hashTable[bucket];
5409
- if (cellIndex === EMPTY_U32 || cell === this.cells[cellIndex]) {
5410
- return bucket;
5411
- }
5412
- bucket = bucket + probe + 1 & hashmod;
5413
- }
5414
- throw new Error("Hash table full.");
5415
- }
5416
- };
5417
- function hash(view, h = 0) {
5418
- const m = 1540483477;
5419
- const r = 24;
5420
- for (let i = 0, il = view.byteLength / 4; i < il; i++) {
5421
- let k = view.getUint32(i * 4);
5422
- k = Math.imul(k, m) >>> 0;
5423
- k = (k ^ k >> r) >>> 0;
5424
- k = Math.imul(k, m) >>> 0;
5425
- h = Math.imul(h, m) >>> 0;
5426
- h = (h ^ k) >>> 0;
5427
- }
5428
- return h;
5429
- }
5430
- function hashBuckets(initialCount) {
5431
- let buckets = 1;
5432
- while (buckets < initialCount + initialCount / 4) {
5433
- buckets *= 2;
5434
- }
5435
- return buckets;
5436
- }
5437
-
5438
- // src/filters/tileFeaturesRaster.ts
5439
5422
  function tileFeaturesRaster({
5440
5423
  tiles,
5441
5424
  ...options
@@ -5449,15 +5432,20 @@ function tileFeaturesRaster({
5449
5432
  const tileResolution = getResolution2(tiles[0].index.q);
5450
5433
  const tileBlockSize = tiles[0].data.blockSize;
5451
5434
  const cellResolution = tileResolution + BigInt(Math.log2(tileBlockSize));
5452
- const spatialFilterCells = new CellSet(
5453
- geometryToCells2(options.spatialFilter, cellResolution)
5454
- );
5455
5435
  const data = /* @__PURE__ */ new Map();
5456
5436
  for (const tile of tiles) {
5457
5437
  const parent = tile.index.q;
5458
- const children = cellToChildrenSorted(parent, cellResolution);
5459
- for (let i = 0; i < children.length; i++) {
5460
- if (!spatialFilterCells.has(children[i])) continue;
5438
+ const intersection3 = intersectTileRaster(
5439
+ parent,
5440
+ cellResolution,
5441
+ options.spatialFilter
5442
+ );
5443
+ if (intersection3 === false) continue;
5444
+ const tileSortedCells = cellToChildrenSorted(parent, cellResolution);
5445
+ for (let i = 0; i < tileSortedCells.length; i++) {
5446
+ if (intersection3 !== true && !intersection3.has(tileSortedCells[i])) {
5447
+ continue;
5448
+ }
5461
5449
  const cellData = {};
5462
5450
  let cellDataExists = false;
5463
5451
  for (const band in tile.data.cells.numericProps) {
@@ -5469,7 +5457,7 @@ function tileFeaturesRaster({
5469
5457
  }
5470
5458
  }
5471
5459
  if (cellDataExists) {
5472
- data.set(children[i], cellData);
5460
+ data.set(tileSortedCells[i], cellData);
5473
5461
  }
5474
5462
  }
5475
5463
  }
@@ -6250,7 +6238,7 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
6250
6238
  }
6251
6239
  _extractTileFeatures(spatialFilter) {
6252
6240
  const prevInputs = this._tileFeatureExtractPreviousInputs;
6253
- if (this._features.length && prevInputs.spatialFilter && booleanEqual(prevInputs.spatialFilter, spatialFilter)) {
6241
+ if (this._features.length && spatialFilterEquals(prevInputs.spatialFilter, spatialFilter)) {
6254
6242
  return;
6255
6243
  }
6256
6244
  this._features = tileFeatures({
@@ -6490,7 +6478,6 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
6490
6478
  * INTERNAL
6491
6479
  */
6492
6480
  _getFilteredFeatures(spatialFilter, filters, filterOwner) {
6493
- assert(spatialFilter, "spatialFilter required for tilesets");
6494
6481
  this._extractTileFeatures(spatialFilter);
6495
6482
  return applyFilters(
6496
6483
  this._features,
@@ -6514,6 +6501,11 @@ function assertColumn(features, ...columnArgs) {
6514
6501
  function normalizeColumns(columns) {
6515
6502
  return Array.isArray(columns) ? columns : typeof columns === "string" ? [columns] : [];
6516
6503
  }
6504
+ function spatialFilterEquals(a, b) {
6505
+ if (a === b) return true;
6506
+ if (!a || !b) return false;
6507
+ return booleanEqual(a, b);
6508
+ }
6517
6509
 
6518
6510
  // src/workers/widget-tileset-worker.ts
6519
6511
  var source;