@carto/api-client 0.5.7-alpha-optional-spatial-filter.0 → 0.5.7-alpha-others-orderby.1

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,110 +1505,6 @@ 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
-
1612
1508
  // node_modules/@turf/bbox-polygon/dist/esm/index.js
1613
1509
  function bboxPolygon(bbox2, options = {}) {
1614
1510
  const west = Number(bbox2[0]);
@@ -1927,7 +1823,7 @@ var MAX_SAFE_INTEGER = 9007199254740991;
1927
1823
  var POWS_TEN = [1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13];
1928
1824
  var SQRT_BASE = 1e7;
1929
1825
  var MAX = 1e9;
1930
- function clone2(configObject) {
1826
+ function clone(configObject) {
1931
1827
  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 = {
1932
1828
  prefix: "",
1933
1829
  groupSize: 3,
@@ -2053,7 +1949,7 @@ function clone2(configObject) {
2053
1949
  x.c = [x.e = 0];
2054
1950
  }
2055
1951
  }
2056
- BigNumber2.clone = clone2;
1952
+ BigNumber2.clone = clone;
2057
1953
  BigNumber2.ROUND_UP = 0;
2058
1954
  BigNumber2.ROUND_DOWN = 1;
2059
1955
  BigNumber2.ROUND_CEIL = 2;
@@ -3256,7 +3152,7 @@ function toFixedPoint(str, e, z) {
3256
3152
  }
3257
3153
  return str;
3258
3154
  }
3259
- var BigNumber = clone2();
3155
+ var BigNumber = clone();
3260
3156
  var bignumber_default = BigNumber;
3261
3157
 
3262
3158
  // node_modules/splaytree-ts/dist/esm/index.js
@@ -4825,7 +4721,117 @@ function intersect(features, options = {}) {
4825
4721
  }
4826
4722
  var turf_intersect_default = intersect;
4827
4723
 
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
+
4828
4781
  // 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
4829
4835
  var TRANSFORM_FN2 = {
4830
4836
  Point: transformPoint2,
4831
4837
  MultiPoint: transformMultiPoint2,
@@ -4834,10 +4840,10 @@ var TRANSFORM_FN2 = {
4834
4840
  Polygon: transformPolygon2,
4835
4841
  MultiPolygon: transformMultiPolygon2
4836
4842
  };
4837
- function transformToTileCoords(geometry, bbox2) {
4843
+ function transformTileCoordsToWGS84(geometry, bbox2) {
4838
4844
  const [west, south, east, north] = bbox2;
4839
- const nw = projectFlat([west, north]);
4840
- const se = projectFlat([east, south]);
4845
+ const nw = lngLatToWorld([west, north]);
4846
+ const se = lngLatToWorld([east, south]);
4841
4847
  const projectedBbox = [nw, se];
4842
4848
  if (geometry.type === "GeometryCollection") {
4843
4849
  throw new Error("Unsupported geometry type GeometryCollection");
@@ -4847,12 +4853,12 @@ function transformToTileCoords(geometry, bbox2) {
4847
4853
  return { ...geometry, coordinates };
4848
4854
  }
4849
4855
  function transformPoint2([pointX, pointY], [nw, se]) {
4850
- const x = inverseLerp(nw[0], se[0], pointX);
4851
- const y = inverseLerp(nw[1], se[1], pointY);
4852
- return [x, y];
4856
+ const x = lerp(nw[0], se[0], pointX);
4857
+ const y = lerp(nw[1], se[1], pointY);
4858
+ return worldToLngLat([x, y]);
4853
4859
  }
4854
4860
  function getPoints2(geometry, bbox2) {
4855
- return geometry.map((g) => transformPoint2(projectFlat(g), bbox2));
4861
+ return geometry.map((g) => transformPoint2(g, bbox2));
4856
4862
  }
4857
4863
  function transformMultiPoint2(multiPoint, bbox2) {
4858
4864
  return getPoints2(multiPoint, bbox2);
@@ -4871,203 +4877,6 @@ function transformPolygon2(polygon2, bbox2) {
4871
4877
  function transformMultiPolygon2(multiPolygon2, bbox2) {
4872
4878
  return multiPolygon2.map((polygon2) => transformPolygon2(polygon2, bbox2));
4873
4879
  }
4874
- function projectFlat(xyz) {
4875
- return lngLatToWorld(xyz);
4876
- }
4877
- function inverseLerp(a, b, x) {
4878
- return (x - a) / (b - a);
4879
- }
4880
-
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
4880
 
5072
4881
  // src/filters/tileFeaturesGeometries.ts
5073
4882
  var FEATURE_GEOM_PROPERTY = "__geomValue";
@@ -5083,45 +4892,55 @@ function tileFeaturesGeometries({
5083
4892
  if (tile.isVisible === false || !tile.data) {
5084
4893
  continue;
5085
4894
  }
5086
- const tileBbox = [
4895
+ const bbox2 = [
5087
4896
  tile.bbox.west,
5088
4897
  tile.bbox.south,
5089
4898
  tile.bbox.east,
5090
4899
  tile.bbox.north
5091
4900
  ];
5092
- const intersection3 = intersectTileGeometry(
5093
- tileBbox,
5094
- tileFormat,
5095
- spatialFilter
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])
5096
4910
  );
5097
- if (intersection3 === false) continue;
5098
- const transformedSpatialFilter = intersection3 === true ? void 0 : intersection3;
4911
+ if (!clippedGeometryToIntersect) {
4912
+ continue;
4913
+ }
4914
+ const transformedGeometryToIntersect = tileFormat === "mvt" /* MVT */ ? transformToTileCoords(clippedGeometryToIntersect.geometry, bbox2) : clippedGeometryToIntersect.geometry;
5099
4915
  calculateFeatures({
5100
4916
  map,
5101
- spatialFilter: transformedSpatialFilter,
4917
+ tileIsFullyVisible,
4918
+ geometryIntersection: transformedGeometryToIntersect,
5102
4919
  data: tile.data.points,
5103
4920
  type: "Point",
5104
- bbox: tileBbox,
4921
+ bbox: bbox2,
5105
4922
  tileFormat,
5106
4923
  uniqueIdProperty,
5107
4924
  options
5108
4925
  });
5109
4926
  calculateFeatures({
5110
4927
  map,
5111
- spatialFilter: transformedSpatialFilter,
4928
+ tileIsFullyVisible,
4929
+ geometryIntersection: transformedGeometryToIntersect,
5112
4930
  data: tile.data.lines,
5113
4931
  type: "LineString",
5114
- bbox: tileBbox,
4932
+ bbox: bbox2,
5115
4933
  tileFormat,
5116
4934
  uniqueIdProperty,
5117
4935
  options
5118
4936
  });
5119
4937
  calculateFeatures({
5120
4938
  map,
5121
- spatialFilter: transformedSpatialFilter,
4939
+ tileIsFullyVisible,
4940
+ geometryIntersection: transformedGeometryToIntersect,
5122
4941
  data: tile.data.polygons,
5123
4942
  type: "Polygon",
5124
- bbox: tileBbox,
4943
+ bbox: bbox2,
5125
4944
  tileFormat,
5126
4945
  uniqueIdProperty,
5127
4946
  options
@@ -5139,7 +4958,7 @@ function processTileFeatureProperties({
5139
4958
  tileFormat,
5140
4959
  uniqueIdProperty,
5141
4960
  storeGeometry,
5142
- spatialFilter
4961
+ geometryIntersection
5143
4962
  }) {
5144
4963
  const tileProps = getPropertiesFromTile(data, startIndex);
5145
4964
  const uniquePropertyValue = getUniquePropertyValue(
@@ -5151,7 +4970,7 @@ function processTileFeatureProperties({
5151
4970
  return;
5152
4971
  }
5153
4972
  let geometry = null;
5154
- if (storeGeometry || spatialFilter) {
4973
+ if (storeGeometry || geometryIntersection) {
5155
4974
  const { positions } = data;
5156
4975
  const ringCoordinates = getRingCoordinatesFor(
5157
4976
  startIndex,
@@ -5160,7 +4979,7 @@ function processTileFeatureProperties({
5160
4979
  );
5161
4980
  geometry = getFeatureByType(ringCoordinates, type);
5162
4981
  }
5163
- if (geometry && spatialFilter && !turf_boolean_intersects_default(geometry, spatialFilter)) {
4982
+ if (geometry && geometryIntersection && !turf_boolean_intersects_default(geometry, geometryIntersection)) {
5164
4983
  return;
5165
4984
  }
5166
4985
  const properties = parseProperties(tileProps);
@@ -5172,7 +4991,7 @@ function processTileFeatureProperties({
5172
4991
  function addIntersectedFeaturesInTile({
5173
4992
  map,
5174
4993
  data,
5175
- spatialFilter,
4994
+ geometryIntersection,
5176
4995
  type,
5177
4996
  bbox: bbox2,
5178
4997
  tileFormat,
@@ -5194,7 +5013,7 @@ function addIntersectedFeaturesInTile({
5194
5013
  tileFormat,
5195
5014
  uniqueIdProperty,
5196
5015
  storeGeometry,
5197
- spatialFilter
5016
+ geometryIntersection
5198
5017
  });
5199
5018
  }
5200
5019
  }
@@ -5276,7 +5095,8 @@ function getRingCoordinatesFor(startIndex, endIndex, positions) {
5276
5095
  }
5277
5096
  function calculateFeatures({
5278
5097
  map,
5279
- spatialFilter,
5098
+ tileIsFullyVisible,
5099
+ geometryIntersection,
5280
5100
  data,
5281
5101
  type,
5282
5102
  bbox: bbox2,
@@ -5287,7 +5107,7 @@ function calculateFeatures({
5287
5107
  if (!data?.properties.length) {
5288
5108
  return;
5289
5109
  }
5290
- if (!spatialFilter) {
5110
+ if (tileIsFullyVisible) {
5291
5111
  addAllFeaturesInTile({
5292
5112
  map,
5293
5113
  data,
@@ -5301,7 +5121,7 @@ function calculateFeatures({
5301
5121
  addIntersectedFeaturesInTile({
5302
5122
  map,
5303
5123
  data,
5304
- spatialFilter,
5124
+ geometryIntersection,
5305
5125
  type,
5306
5126
  bbox: bbox2,
5307
5127
  tileFormat,
@@ -5351,8 +5171,128 @@ function createIndicesForPoints(data) {
5351
5171
  }
5352
5172
 
5353
5173
  // src/filters/tileFeaturesSpatialIndex.ts
5354
- import { getResolution as quadbinGetResolution } from "quadbin";
5355
- import { getResolution as h3GetResolution } from "h3-js";
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";
5356
5296
  function tileFeaturesSpatialIndex({
5357
5297
  tiles,
5358
5298
  spatialFilter,
@@ -5361,40 +5301,28 @@ function tileFeaturesSpatialIndex({
5361
5301
  }) {
5362
5302
  const map = /* @__PURE__ */ new Map();
5363
5303
  const spatialIndex = getSpatialIndex(spatialDataType);
5364
- const cellResolution = getResolution(tiles, spatialIndex);
5304
+ const resolution = getResolution(tiles, spatialIndex);
5365
5305
  const spatialIndexIDName = spatialDataColumn ? spatialDataColumn : spatialIndex;
5366
- if (!cellResolution) {
5306
+ if (!resolution) {
5307
+ return [];
5308
+ }
5309
+ const cells = getCellsCoverGeometry(spatialFilter, spatialIndex, resolution);
5310
+ if (!cells?.length) {
5367
5311
  return [];
5368
5312
  }
5313
+ const cellsSet = new Set(cells);
5369
5314
  for (const tile of tiles) {
5370
5315
  if (tile.isVisible === false || !tile.data) {
5371
5316
  continue;
5372
5317
  }
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;
5384
5318
  tile.data.forEach((d) => {
5385
- if (intersection3 === true || intersection3.has(d.id)) {
5319
+ if (cellsSet.has(d.id)) {
5386
5320
  map.set(d.id, { ...d.properties, [spatialIndexIDName]: d.id });
5387
5321
  }
5388
5322
  });
5389
5323
  }
5390
5324
  return Array.from(map.values());
5391
5325
  }
5392
- function getTileIndex(tile, spatialIndex) {
5393
- if (spatialIndex === "quadbin" /* QUADBIN */) {
5394
- return tile.index.q;
5395
- }
5396
- return tile.id;
5397
- }
5398
5326
  function getResolution(tiles, spatialIndex) {
5399
5327
  const data = tiles.find((tile) => tile.data?.length)?.data;
5400
5328
  if (!data) {
@@ -5407,6 +5335,26 @@ function getResolution(tiles, spatialIndex) {
5407
5335
  return h3GetResolution(data[0].id);
5408
5336
  }
5409
5337
  }
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
+ }
5410
5358
  function getSpatialIndex(spatialDataType) {
5411
5359
  switch (spatialDataType) {
5412
5360
  case "h3":
@@ -5426,7 +5374,9 @@ var DEFAULT_AGGREGATION_EXP = `1 AS ${DEFAULT_AGGREGATION_EXP_ALIAS}`;
5426
5374
  // src/filters/tileFeaturesRaster.ts
5427
5375
  import {
5428
5376
  cellToChildren as _cellToChildren,
5377
+ cellToBoundary,
5429
5378
  cellToTile,
5379
+ geometryToCells as geometryToCells2,
5430
5380
  getResolution as getResolution2
5431
5381
  } from "quadbin";
5432
5382
  function tileFeaturesRaster({
@@ -5445,15 +5395,15 @@ function tileFeaturesRaster({
5445
5395
  const data = /* @__PURE__ */ new Map();
5446
5396
  for (const tile of tiles) {
5447
5397
  const parent = tile.index.q;
5448
- const intersection3 = intersectTileRaster(
5449
- parent,
5450
- cellResolution,
5451
- options.spatialFilter
5398
+ const tilePolygon = cellToBoundary(parent);
5399
+ const tileFilter = turf_intersect_default(
5400
+ featureCollection([feature(tilePolygon), feature(options.spatialFilter)])
5452
5401
  );
5453
- if (intersection3 === false) continue;
5402
+ const needsFilter = tileFilter ? !turf_boolean_within_default(tilePolygon, options.spatialFilter) : false;
5403
+ const tileFilterCells = needsFilter ? new Set(geometryToCells2(tileFilter.geometry, cellResolution)) : null;
5454
5404
  const tileSortedCells = cellToChildrenSorted(parent, cellResolution);
5455
5405
  for (let i = 0; i < tileSortedCells.length; i++) {
5456
- if (intersection3 !== true && !intersection3.has(tileSortedCells[i])) {
5406
+ if (needsFilter && !tileFilterCells.has(tileSortedCells[i])) {
5457
5407
  continue;
5458
5408
  }
5459
5409
  const cellData = {};
@@ -5688,16 +5638,21 @@ function normalizeSortByOptions({
5688
5638
  });
5689
5639
  }
5690
5640
 
5641
+ // src/widget-sources/constants.ts
5642
+ var OTHERS_CATEGORY_NAME = "_carto_others";
5643
+
5691
5644
  // src/operations/groupBy.ts
5692
5645
  function groupValuesByColumn({
5693
5646
  data,
5694
5647
  valuesColumns,
5695
5648
  joinOperation,
5696
5649
  keysColumn,
5697
- operation: operation2
5650
+ operation: operation2,
5651
+ othersThreshold,
5652
+ orderBy = "frequency_desc"
5698
5653
  }) {
5699
5654
  if (Array.isArray(data) && data.length === 0) {
5700
- return null;
5655
+ return { rows: null };
5701
5656
  }
5702
5657
  const groups = data.reduce((accumulator, item) => {
5703
5658
  const group = item[keysColumn];
@@ -5712,13 +5667,44 @@ function groupValuesByColumn({
5712
5667
  return accumulator;
5713
5668
  }, /* @__PURE__ */ new Map());
5714
5669
  const targetOperation = aggregationFunctions[operation2];
5715
- if (targetOperation) {
5716
- return Array.from(groups).map(([name, value]) => ({
5717
- name,
5718
- value: targetOperation(value)
5719
- }));
5670
+ if (!targetOperation) {
5671
+ return { rows: [] };
5672
+ }
5673
+ const allCategories = Array.from(groups).map(([name, value]) => ({
5674
+ name,
5675
+ value: targetOperation(value)
5676
+ })).sort(getSorter(orderBy));
5677
+ if (othersThreshold && allCategories.length > othersThreshold) {
5678
+ const otherValue = allCategories.slice(othersThreshold).flatMap(({ name }) => groups.get(name));
5679
+ allCategories.push({
5680
+ name: OTHERS_CATEGORY_NAME,
5681
+ value: targetOperation(otherValue)
5682
+ });
5683
+ return {
5684
+ rows: allCategories,
5685
+ metadata: {
5686
+ others: targetOperation(otherValue)
5687
+ }
5688
+ };
5689
+ }
5690
+ return {
5691
+ rows: allCategories
5692
+ };
5693
+ }
5694
+ function getSorter(orderBy) {
5695
+ switch (orderBy) {
5696
+ case "frequency_asc":
5697
+ return (a, b) => a.value - b.value || localeCompare(a.name, b.name);
5698
+ case "frequency_desc":
5699
+ return (a, b) => b.value - a.value || localeCompare(a.name, b.name);
5700
+ case "alphabetical_asc":
5701
+ return (a, b) => localeCompare(a.name, b.name) || b.value - a.value;
5702
+ case "alphabetical_desc":
5703
+ return (a, b) => localeCompare(b.name, a.name) || b.value - a.value;
5720
5704
  }
5721
- return [];
5705
+ }
5706
+ function localeCompare(a, b) {
5707
+ return (a ?? "null").localeCompare(b ?? "null");
5722
5708
  }
5723
5709
 
5724
5710
  // src/utils/dateUtils.ts
@@ -6248,7 +6234,7 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
6248
6234
  }
6249
6235
  _extractTileFeatures(spatialFilter) {
6250
6236
  const prevInputs = this._tileFeatureExtractPreviousInputs;
6251
- if (this._features.length && spatialFilterEquals(prevInputs.spatialFilter, spatialFilter)) {
6237
+ if (this._features.length && prevInputs.spatialFilter && booleanEqual(prevInputs.spatialFilter, spatialFilter)) {
6252
6238
  return;
6253
6239
  }
6254
6240
  this._features = tileFeatures({
@@ -6337,7 +6323,10 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
6337
6323
  joinOperation,
6338
6324
  filters,
6339
6325
  filterOwner,
6340
- spatialFilter
6326
+ spatialFilter,
6327
+ othersThreshold,
6328
+ orderBy = "frequency_desc",
6329
+ rawResult
6341
6330
  }) {
6342
6331
  const filteredFeatures = this._getFilteredFeatures(
6343
6332
  spatialFilter,
@@ -6348,14 +6337,25 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
6348
6337
  return [];
6349
6338
  }
6350
6339
  assertColumn(this._features, column, operationColumn);
6351
- const groups = groupValuesByColumn({
6340
+ const result = groupValuesByColumn({
6352
6341
  data: filteredFeatures,
6353
6342
  valuesColumns: normalizeColumns(operationColumn || column),
6354
6343
  joinOperation,
6355
6344
  keysColumn: column,
6356
- operation: operation2
6345
+ operation: operation2,
6346
+ othersThreshold,
6347
+ orderBy
6357
6348
  });
6358
- return groups || [];
6349
+ if (rawResult) {
6350
+ return result;
6351
+ }
6352
+ if (!othersThreshold) {
6353
+ return result?.rows || [];
6354
+ }
6355
+ return [
6356
+ ...result?.rows || [],
6357
+ { name: OTHERS_CATEGORY_NAME, value: result?.metadata?.others }
6358
+ ];
6359
6359
  }
6360
6360
  async getScatter({
6361
6361
  xAxisColumn,
@@ -6488,6 +6488,7 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
6488
6488
  * INTERNAL
6489
6489
  */
6490
6490
  _getFilteredFeatures(spatialFilter, filters, filterOwner) {
6491
+ assert(spatialFilter, "spatialFilter required for tilesets");
6491
6492
  this._extractTileFeatures(spatialFilter);
6492
6493
  return applyFilters(
6493
6494
  this._features,
@@ -6511,11 +6512,6 @@ function assertColumn(features, ...columnArgs) {
6511
6512
  function normalizeColumns(columns) {
6512
6513
  return Array.isArray(columns) ? columns : typeof columns === "string" ? [columns] : [];
6513
6514
  }
6514
- function spatialFilterEquals(a, b) {
6515
- if (a === b) return true;
6516
- if (!a || !b) return false;
6517
- return booleanEqual(a, b);
6518
- }
6519
6515
 
6520
6516
  // src/workers/widget-tileset-worker.ts
6521
6517
  var source;