@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.
@@ -1513,6 +1513,110 @@
1513
1513
  return Array.from(map.values());
1514
1514
  }
1515
1515
 
1516
+ // node_modules/@math.gl/core/dist/lib/common.js
1517
+ var RADIANS_TO_DEGREES = 1 / Math.PI * 180;
1518
+ var DEGREES_TO_RADIANS = 1 / 180 * Math.PI;
1519
+ var DEFAULT_CONFIG = {
1520
+ EPSILON: 1e-12,
1521
+ debug: false,
1522
+ precision: 4,
1523
+ printTypes: false,
1524
+ printDegrees: false,
1525
+ printRowMajor: true,
1526
+ _cartographicRadians: false
1527
+ };
1528
+ globalThis.mathgl = globalThis.mathgl || { config: { ...DEFAULT_CONFIG } };
1529
+ var config = globalThis.mathgl.config;
1530
+ function isArray(value) {
1531
+ return Array.isArray(value) || ArrayBuffer.isView(value) && !(value instanceof DataView);
1532
+ }
1533
+ function lerp(a, b, t) {
1534
+ if (isArray(a)) {
1535
+ return a.map((ai, i) => lerp(ai, b[i], t));
1536
+ }
1537
+ return t * b + (1 - t) * a;
1538
+ }
1539
+
1540
+ // node_modules/@math.gl/web-mercator/dist/assert.js
1541
+ function assert2(condition, message) {
1542
+ if (!condition) {
1543
+ throw new Error(message || "@math.gl/web-mercator: assertion failed.");
1544
+ }
1545
+ }
1546
+
1547
+ // node_modules/@math.gl/web-mercator/dist/web-mercator-utils.js
1548
+ var PI = Math.PI;
1549
+ var PI_4 = PI / 4;
1550
+ var DEGREES_TO_RADIANS2 = PI / 180;
1551
+ var RADIANS_TO_DEGREES2 = 180 / PI;
1552
+ var TILE_SIZE = 512;
1553
+ function lngLatToWorld(lngLat) {
1554
+ const [lng, lat] = lngLat;
1555
+ assert2(Number.isFinite(lng));
1556
+ assert2(Number.isFinite(lat) && lat >= -90 && lat <= 90, "invalid latitude");
1557
+ const lambda2 = lng * DEGREES_TO_RADIANS2;
1558
+ const phi2 = lat * DEGREES_TO_RADIANS2;
1559
+ const x = TILE_SIZE * (lambda2 + PI) / (2 * PI);
1560
+ const y = TILE_SIZE * (PI + Math.log(Math.tan(PI_4 + phi2 * 0.5))) / (2 * PI);
1561
+ return [x, y];
1562
+ }
1563
+ function worldToLngLat(xy) {
1564
+ const [x, y] = xy;
1565
+ const lambda2 = x / TILE_SIZE * (2 * PI) - PI;
1566
+ const phi2 = 2 * (Math.atan(Math.exp(y / TILE_SIZE * (2 * PI) - PI)) - PI_4);
1567
+ return [lambda2 * RADIANS_TO_DEGREES2, phi2 * RADIANS_TO_DEGREES2];
1568
+ }
1569
+
1570
+ // node_modules/@math.gl/web-mercator/dist/get-bounds.js
1571
+ var DEGREES_TO_RADIANS3 = Math.PI / 180;
1572
+
1573
+ // src/utils/transformTileCoordsToWGS84.ts
1574
+ var TRANSFORM_FN = {
1575
+ Point: transformPoint,
1576
+ MultiPoint: transformMultiPoint,
1577
+ LineString: transformLineString,
1578
+ MultiLineString: transformMultiLineString,
1579
+ Polygon: transformPolygon,
1580
+ MultiPolygon: transformMultiPolygon
1581
+ };
1582
+ function transformTileCoordsToWGS84(geometry, bbox2) {
1583
+ const [west, south, east, north] = bbox2;
1584
+ const nw = lngLatToWorld([west, north]);
1585
+ const se = lngLatToWorld([east, south]);
1586
+ const projectedBbox = [nw, se];
1587
+ if (geometry.type === "GeometryCollection") {
1588
+ throw new Error("Unsupported geometry type GeometryCollection");
1589
+ }
1590
+ const transformFn = TRANSFORM_FN[geometry.type];
1591
+ const coordinates = transformFn(geometry.coordinates, projectedBbox);
1592
+ return { ...geometry, coordinates };
1593
+ }
1594
+ function transformPoint([pointX, pointY], [nw, se]) {
1595
+ const x = lerp(nw[0], se[0], pointX);
1596
+ const y = lerp(nw[1], se[1], pointY);
1597
+ return worldToLngLat([x, y]);
1598
+ }
1599
+ function getPoints(geometry, bbox2) {
1600
+ return geometry.map((g) => transformPoint(g, bbox2));
1601
+ }
1602
+ function transformMultiPoint(multiPoint, bbox2) {
1603
+ return getPoints(multiPoint, bbox2);
1604
+ }
1605
+ function transformLineString(line, bbox2) {
1606
+ return getPoints(line, bbox2);
1607
+ }
1608
+ function transformMultiLineString(multiLineString2, bbox2) {
1609
+ return multiLineString2.map(
1610
+ (lineString2) => transformLineString(lineString2, bbox2)
1611
+ );
1612
+ }
1613
+ function transformPolygon(polygon2, bbox2) {
1614
+ return polygon2.map((polygonRing) => getPoints(polygonRing, bbox2));
1615
+ }
1616
+ function transformMultiPolygon(multiPolygon2, bbox2) {
1617
+ return multiPolygon2.map((polygon2) => transformPolygon(polygon2, bbox2));
1618
+ }
1619
+
1516
1620
  // node_modules/@turf/bbox-polygon/dist/esm/index.js
1517
1621
  function bboxPolygon(bbox2, options = {}) {
1518
1622
  const west = Number(bbox2[0]);
@@ -1831,7 +1935,7 @@
1831
1935
  var POWS_TEN = [1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13];
1832
1936
  var SQRT_BASE = 1e7;
1833
1937
  var MAX = 1e9;
1834
- function clone(configObject) {
1938
+ function clone2(configObject) {
1835
1939
  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 = {
1836
1940
  prefix: "",
1837
1941
  groupSize: 3,
@@ -1957,7 +2061,7 @@
1957
2061
  x.c = [x.e = 0];
1958
2062
  }
1959
2063
  }
1960
- BigNumber2.clone = clone;
2064
+ BigNumber2.clone = clone2;
1961
2065
  BigNumber2.ROUND_UP = 0;
1962
2066
  BigNumber2.ROUND_DOWN = 1;
1963
2067
  BigNumber2.ROUND_CEIL = 2;
@@ -3160,7 +3264,7 @@
3160
3264
  }
3161
3265
  return str;
3162
3266
  }
3163
- var BigNumber = clone();
3267
+ var BigNumber = clone2();
3164
3268
  var bignumber_default = BigNumber;
3165
3269
 
3166
3270
  // node_modules/splaytree-ts/dist/esm/index.js
@@ -4729,117 +4833,7 @@
4729
4833
  }
4730
4834
  var turf_intersect_default = intersect;
4731
4835
 
4732
- // node_modules/@math.gl/core/dist/lib/common.js
4733
- var RADIANS_TO_DEGREES = 1 / Math.PI * 180;
4734
- var DEGREES_TO_RADIANS = 1 / 180 * Math.PI;
4735
- var DEFAULT_CONFIG = {
4736
- EPSILON: 1e-12,
4737
- debug: false,
4738
- precision: 4,
4739
- printTypes: false,
4740
- printDegrees: false,
4741
- printRowMajor: true,
4742
- _cartographicRadians: false
4743
- };
4744
- globalThis.mathgl = globalThis.mathgl || { config: { ...DEFAULT_CONFIG } };
4745
- var config = globalThis.mathgl.config;
4746
- function isArray(value) {
4747
- return Array.isArray(value) || ArrayBuffer.isView(value) && !(value instanceof DataView);
4748
- }
4749
- function lerp(a, b, t) {
4750
- if (isArray(a)) {
4751
- return a.map((ai, i) => lerp(ai, b[i], t));
4752
- }
4753
- return t * b + (1 - t) * a;
4754
- }
4755
-
4756
- // node_modules/@math.gl/web-mercator/dist/assert.js
4757
- function assert2(condition, message) {
4758
- if (!condition) {
4759
- throw new Error(message || "@math.gl/web-mercator: assertion failed.");
4760
- }
4761
- }
4762
-
4763
- // node_modules/@math.gl/web-mercator/dist/web-mercator-utils.js
4764
- var PI = Math.PI;
4765
- var PI_4 = PI / 4;
4766
- var DEGREES_TO_RADIANS2 = PI / 180;
4767
- var RADIANS_TO_DEGREES2 = 180 / PI;
4768
- var TILE_SIZE = 512;
4769
- function lngLatToWorld(lngLat) {
4770
- const [lng, lat] = lngLat;
4771
- assert2(Number.isFinite(lng));
4772
- assert2(Number.isFinite(lat) && lat >= -90 && lat <= 90, "invalid latitude");
4773
- const lambda2 = lng * DEGREES_TO_RADIANS2;
4774
- const phi2 = lat * DEGREES_TO_RADIANS2;
4775
- const x = TILE_SIZE * (lambda2 + PI) / (2 * PI);
4776
- const y = TILE_SIZE * (PI + Math.log(Math.tan(PI_4 + phi2 * 0.5))) / (2 * PI);
4777
- return [x, y];
4778
- }
4779
- function worldToLngLat(xy) {
4780
- const [x, y] = xy;
4781
- const lambda2 = x / TILE_SIZE * (2 * PI) - PI;
4782
- const phi2 = 2 * (Math.atan(Math.exp(y / TILE_SIZE * (2 * PI) - PI)) - PI_4);
4783
- return [lambda2 * RADIANS_TO_DEGREES2, phi2 * RADIANS_TO_DEGREES2];
4784
- }
4785
-
4786
- // node_modules/@math.gl/web-mercator/dist/get-bounds.js
4787
- var DEGREES_TO_RADIANS3 = Math.PI / 180;
4788
-
4789
4836
  // src/utils/transformToTileCoords.ts
4790
- var TRANSFORM_FN = {
4791
- Point: transformPoint,
4792
- MultiPoint: transformMultiPoint,
4793
- LineString: transformLineString,
4794
- MultiLineString: transformMultiLineString,
4795
- Polygon: transformPolygon,
4796
- MultiPolygon: transformMultiPolygon
4797
- };
4798
- function transformToTileCoords(geometry, bbox2) {
4799
- const [west, south, east, north] = bbox2;
4800
- const nw = projectFlat([west, north]);
4801
- const se = projectFlat([east, south]);
4802
- const projectedBbox = [nw, se];
4803
- if (geometry.type === "GeometryCollection") {
4804
- throw new Error("Unsupported geometry type GeometryCollection");
4805
- }
4806
- const transformFn = TRANSFORM_FN[geometry.type];
4807
- const coordinates = transformFn(geometry.coordinates, projectedBbox);
4808
- return { ...geometry, coordinates };
4809
- }
4810
- function transformPoint([pointX, pointY], [nw, se]) {
4811
- const x = inverseLerp(nw[0], se[0], pointX);
4812
- const y = inverseLerp(nw[1], se[1], pointY);
4813
- return [x, y];
4814
- }
4815
- function getPoints(geometry, bbox2) {
4816
- return geometry.map((g) => transformPoint(projectFlat(g), bbox2));
4817
- }
4818
- function transformMultiPoint(multiPoint, bbox2) {
4819
- return getPoints(multiPoint, bbox2);
4820
- }
4821
- function transformLineString(line, bbox2) {
4822
- return getPoints(line, bbox2);
4823
- }
4824
- function transformMultiLineString(multiLineString2, bbox2) {
4825
- return multiLineString2.map(
4826
- (lineString2) => transformLineString(lineString2, bbox2)
4827
- );
4828
- }
4829
- function transformPolygon(polygon2, bbox2) {
4830
- return polygon2.map((polygonRing) => getPoints(polygonRing, bbox2));
4831
- }
4832
- function transformMultiPolygon(multiPolygon2, bbox2) {
4833
- return multiPolygon2.map((polygon2) => transformPolygon(polygon2, bbox2));
4834
- }
4835
- function projectFlat(xyz) {
4836
- return lngLatToWorld(xyz);
4837
- }
4838
- function inverseLerp(a, b, x) {
4839
- return (x - a) / (b - a);
4840
- }
4841
-
4842
- // src/utils/transformTileCoordsToWGS84.ts
4843
4837
  var TRANSFORM_FN2 = {
4844
4838
  Point: transformPoint2,
4845
4839
  MultiPoint: transformMultiPoint2,
@@ -4848,10 +4842,10 @@
4848
4842
  Polygon: transformPolygon2,
4849
4843
  MultiPolygon: transformMultiPolygon2
4850
4844
  };
4851
- function transformTileCoordsToWGS84(geometry, bbox2) {
4845
+ function transformToTileCoords(geometry, bbox2) {
4852
4846
  const [west, south, east, north] = bbox2;
4853
- const nw = lngLatToWorld([west, north]);
4854
- const se = lngLatToWorld([east, south]);
4847
+ const nw = projectFlat([west, north]);
4848
+ const se = projectFlat([east, south]);
4855
4849
  const projectedBbox = [nw, se];
4856
4850
  if (geometry.type === "GeometryCollection") {
4857
4851
  throw new Error("Unsupported geometry type GeometryCollection");
@@ -4861,12 +4855,12 @@
4861
4855
  return { ...geometry, coordinates };
4862
4856
  }
4863
4857
  function transformPoint2([pointX, pointY], [nw, se]) {
4864
- const x = lerp(nw[0], se[0], pointX);
4865
- const y = lerp(nw[1], se[1], pointY);
4866
- return worldToLngLat([x, y]);
4858
+ const x = inverseLerp(nw[0], se[0], pointX);
4859
+ const y = inverseLerp(nw[1], se[1], pointY);
4860
+ return [x, y];
4867
4861
  }
4868
4862
  function getPoints2(geometry, bbox2) {
4869
- return geometry.map((g) => transformPoint2(g, bbox2));
4863
+ return geometry.map((g) => transformPoint2(projectFlat(g), bbox2));
4870
4864
  }
4871
4865
  function transformMultiPoint2(multiPoint, bbox2) {
4872
4866
  return getPoints2(multiPoint, bbox2);
@@ -4885,298 +4879,12 @@
4885
4879
  function transformMultiPolygon2(multiPolygon2, bbox2) {
4886
4880
  return multiPolygon2.map((polygon2) => transformPolygon2(polygon2, bbox2));
4887
4881
  }
4888
-
4889
- // src/filters/tileFeaturesGeometries.ts
4890
- var FEATURE_GEOM_PROPERTY = "__geomValue";
4891
- function tileFeaturesGeometries({
4892
- tiles: tiles2,
4893
- tileFormat,
4894
- spatialFilter,
4895
- uniqueIdProperty,
4896
- options
4897
- }) {
4898
- const map = /* @__PURE__ */ new Map();
4899
- for (const tile of tiles2) {
4900
- if (tile.isVisible === false || !tile.data) {
4901
- continue;
4902
- }
4903
- const bbox2 = [
4904
- tile.bbox.west,
4905
- tile.bbox.south,
4906
- tile.bbox.east,
4907
- tile.bbox.north
4908
- ];
4909
- const bboxToGeom = turf_bbox_polygon_default(bbox2);
4910
- const tileIsFullyVisible = turf_boolean_within_default(bboxToGeom, spatialFilter);
4911
- const spatialFilterFeature = {
4912
- type: "Feature",
4913
- geometry: spatialFilter,
4914
- properties: {}
4915
- };
4916
- const clippedGeometryToIntersect = turf_intersect_default(
4917
- featureCollection([bboxToGeom, spatialFilterFeature])
4918
- );
4919
- if (!clippedGeometryToIntersect) {
4920
- continue;
4921
- }
4922
- const transformedGeometryToIntersect = tileFormat === "mvt" /* MVT */ ? transformToTileCoords(clippedGeometryToIntersect.geometry, bbox2) : clippedGeometryToIntersect.geometry;
4923
- calculateFeatures({
4924
- map,
4925
- tileIsFullyVisible,
4926
- geometryIntersection: transformedGeometryToIntersect,
4927
- data: tile.data.points,
4928
- type: "Point",
4929
- bbox: bbox2,
4930
- tileFormat,
4931
- uniqueIdProperty,
4932
- options
4933
- });
4934
- calculateFeatures({
4935
- map,
4936
- tileIsFullyVisible,
4937
- geometryIntersection: transformedGeometryToIntersect,
4938
- data: tile.data.lines,
4939
- type: "LineString",
4940
- bbox: bbox2,
4941
- tileFormat,
4942
- uniqueIdProperty,
4943
- options
4944
- });
4945
- calculateFeatures({
4946
- map,
4947
- tileIsFullyVisible,
4948
- geometryIntersection: transformedGeometryToIntersect,
4949
- data: tile.data.polygons,
4950
- type: "Polygon",
4951
- bbox: bbox2,
4952
- tileFormat,
4953
- uniqueIdProperty,
4954
- options
4955
- });
4956
- }
4957
- return Array.from(map.values());
4958
- }
4959
- function processTileFeatureProperties({
4960
- map,
4961
- data,
4962
- startIndex,
4963
- endIndex,
4964
- type,
4965
- bbox: bbox2,
4966
- tileFormat,
4967
- uniqueIdProperty,
4968
- storeGeometry,
4969
- geometryIntersection
4970
- }) {
4971
- const tileProps = getPropertiesFromTile(data, startIndex);
4972
- const uniquePropertyValue = getUniquePropertyValue(
4973
- tileProps,
4974
- uniqueIdProperty,
4975
- map
4976
- );
4977
- if (!uniquePropertyValue || map.has(uniquePropertyValue)) {
4978
- return;
4979
- }
4980
- let geometry = null;
4981
- if (storeGeometry || geometryIntersection) {
4982
- const { positions } = data;
4983
- const ringCoordinates = getRingCoordinatesFor(
4984
- startIndex,
4985
- endIndex,
4986
- positions
4987
- );
4988
- geometry = getFeatureByType(ringCoordinates, type);
4989
- }
4990
- if (geometry && geometryIntersection && !turf_boolean_intersects_default(geometry, geometryIntersection)) {
4991
- return;
4992
- }
4993
- const properties = parseProperties(tileProps);
4994
- if (storeGeometry && geometry) {
4995
- properties[FEATURE_GEOM_PROPERTY] = tileFormat === "mvt" /* MVT */ ? transformTileCoordsToWGS84(geometry, bbox2) : geometry;
4996
- }
4997
- map.set(uniquePropertyValue, properties);
4998
- }
4999
- function addIntersectedFeaturesInTile({
5000
- map,
5001
- data,
5002
- geometryIntersection,
5003
- type,
5004
- bbox: bbox2,
5005
- tileFormat,
5006
- uniqueIdProperty,
5007
- options
5008
- }) {
5009
- const indices = getIndices(data, type);
5010
- const storeGeometry = options?.storeGeometry || false;
5011
- for (let i = 0; i < indices.length - 1; i++) {
5012
- const startIndex = indices[i];
5013
- const endIndex = indices[i + 1];
5014
- processTileFeatureProperties({
5015
- map,
5016
- data,
5017
- startIndex,
5018
- endIndex,
5019
- type,
5020
- bbox: bbox2,
5021
- tileFormat,
5022
- uniqueIdProperty,
5023
- storeGeometry,
5024
- geometryIntersection
5025
- });
5026
- }
5027
- }
5028
- function getIndices(data, type) {
5029
- let indices;
5030
- switch (type) {
5031
- case "Polygon":
5032
- indices = data.primitivePolygonIndices;
5033
- break;
5034
- case "LineString":
5035
- indices = data.pathIndices;
5036
- break;
5037
- case "Point":
5038
- indices = createIndicesForPoints(data);
5039
- break;
5040
- default:
5041
- throw new Error(
5042
- `Unsupported geometry type: ${type}`
5043
- );
5044
- }
5045
- return indices.value;
5046
- }
5047
- function getFeatureId(data, startIndex) {
5048
- return data.featureIds.value[startIndex];
5049
- }
5050
- function getPropertiesFromTile(data, startIndex) {
5051
- const featureId2 = getFeatureId(data, startIndex);
5052
- const { properties, numericProps, fields } = data;
5053
- const result = {
5054
- uniqueId: fields?.[featureId2]?.id,
5055
- properties: properties[featureId2],
5056
- numericProps: {}
5057
- };
5058
- for (const key in numericProps) {
5059
- result.numericProps[key] = numericProps[key].value[startIndex];
5060
- }
5061
- return result;
5062
- }
5063
- function parseProperties(tileProps) {
5064
- const { properties, numericProps } = tileProps;
5065
- return Object.assign({}, properties, numericProps);
5066
- }
5067
- function getUniquePropertyValue(tileProps, uniqueIdProperty, map) {
5068
- if (uniqueIdProperty) {
5069
- return getValueFromTileProps(tileProps, uniqueIdProperty);
5070
- }
5071
- if (tileProps.uniqueId) {
5072
- return tileProps.uniqueId;
5073
- }
5074
- const artificialId = map.size + 1;
5075
- return getValueFromTileProps(tileProps, "cartodb_id") || getValueFromTileProps(tileProps, "geoid") || artificialId;
5076
- }
5077
- function getValueFromTileProps(tileProps, propertyName) {
5078
- const { properties, numericProps } = tileProps;
5079
- return numericProps[propertyName] || properties[propertyName];
5080
- }
5081
- function getFeatureByType(coordinates, type) {
5082
- switch (type) {
5083
- case "Polygon":
5084
- return { type: "Polygon", coordinates: [coordinates] };
5085
- case "LineString":
5086
- return { type: "LineString", coordinates };
5087
- case "Point":
5088
- return { type: "Point", coordinates: coordinates[0] };
5089
- default:
5090
- throw new Error("Invalid geometry type");
5091
- }
5092
- }
5093
- function getRingCoordinatesFor(startIndex, endIndex, positions) {
5094
- const ringCoordinates = [];
5095
- for (let j = startIndex; j < endIndex; j++) {
5096
- ringCoordinates.push(
5097
- Array.from(
5098
- positions.value.subarray(j * positions.size, (j + 1) * positions.size)
5099
- )
5100
- );
5101
- }
5102
- return ringCoordinates;
5103
- }
5104
- function calculateFeatures({
5105
- map,
5106
- tileIsFullyVisible,
5107
- geometryIntersection,
5108
- data,
5109
- type,
5110
- bbox: bbox2,
5111
- tileFormat,
5112
- uniqueIdProperty,
5113
- options
5114
- }) {
5115
- if (!data?.properties.length) {
5116
- return;
5117
- }
5118
- if (tileIsFullyVisible) {
5119
- addAllFeaturesInTile({
5120
- map,
5121
- data,
5122
- type,
5123
- bbox: bbox2,
5124
- tileFormat,
5125
- uniqueIdProperty,
5126
- options
5127
- });
5128
- } else {
5129
- addIntersectedFeaturesInTile({
5130
- map,
5131
- data,
5132
- geometryIntersection,
5133
- type,
5134
- bbox: bbox2,
5135
- tileFormat,
5136
- uniqueIdProperty,
5137
- options
5138
- });
5139
- }
5140
- }
5141
- function addAllFeaturesInTile({
5142
- map,
5143
- data,
5144
- type,
5145
- bbox: bbox2,
5146
- tileFormat,
5147
- uniqueIdProperty,
5148
- options
5149
- }) {
5150
- const indices = getIndices(data, type);
5151
- const storeGeometry = options?.storeGeometry || false;
5152
- for (let i = 0; i < indices.length - 1; i++) {
5153
- const startIndex = indices[i];
5154
- const endIndex = indices[i + 1];
5155
- processTileFeatureProperties({
5156
- map,
5157
- data,
5158
- startIndex,
5159
- endIndex,
5160
- type,
5161
- bbox: bbox2,
5162
- tileFormat,
5163
- uniqueIdProperty,
5164
- storeGeometry
5165
- });
5166
- }
5167
- }
5168
- function createIndicesForPoints(data) {
5169
- const featureIds = data.featureIds.value;
5170
- const lastFeatureId = featureIds[featureIds.length - 1];
5171
- const PointIndicesArray = featureIds.constructor;
5172
- const pointIndices = {
5173
- value: new PointIndicesArray(featureIds.length + 1),
5174
- size: 1
5175
- };
5176
- pointIndices.value.set(featureIds);
5177
- pointIndices.value.set([lastFeatureId + 1], featureIds.length);
5178
- return pointIndices;
5179
- }
4882
+ function projectFlat(xyz) {
4883
+ return lngLatToWorld(xyz);
4884
+ }
4885
+ function inverseLerp(a, b, x) {
4886
+ return (x - a) / (b - a);
4887
+ }
5180
4888
 
5181
4889
  // node_modules/quadbin/dist/index.esm.js
5182
4890
  var d2r = Math.PI / 180;
@@ -5569,124 +5277,6 @@
5569
5277
  };
5570
5278
  }
5571
5279
 
5572
- // node_modules/@turf/bbox-clip/dist/esm/index.js
5573
- function lineclip(points, bbox2, result) {
5574
- var len = points.length, codeA = bitCode(points[0], bbox2), part = [], i, codeB, lastCode;
5575
- let a;
5576
- let b;
5577
- if (!result) result = [];
5578
- for (i = 1; i < len; i++) {
5579
- a = points[i - 1];
5580
- b = points[i];
5581
- codeB = lastCode = bitCode(b, bbox2);
5582
- while (true) {
5583
- if (!(codeA | codeB)) {
5584
- part.push(a);
5585
- if (codeB !== lastCode) {
5586
- part.push(b);
5587
- if (i < len - 1) {
5588
- result.push(part);
5589
- part = [];
5590
- }
5591
- } else if (i === len - 1) {
5592
- part.push(b);
5593
- }
5594
- break;
5595
- } else if (codeA & codeB) {
5596
- break;
5597
- } else if (codeA) {
5598
- a = intersect2(a, b, codeA, bbox2);
5599
- codeA = bitCode(a, bbox2);
5600
- } else {
5601
- b = intersect2(a, b, codeB, bbox2);
5602
- codeB = bitCode(b, bbox2);
5603
- }
5604
- }
5605
- codeA = lastCode;
5606
- }
5607
- if (part.length) result.push(part);
5608
- return result;
5609
- }
5610
- function polygonclip(points, bbox2) {
5611
- var result, edge, prev, prevInside, i, p, inside;
5612
- for (edge = 1; edge <= 8; edge *= 2) {
5613
- result = [];
5614
- prev = points[points.length - 1];
5615
- prevInside = !(bitCode(prev, bbox2) & edge);
5616
- for (i = 0; i < points.length; i++) {
5617
- p = points[i];
5618
- inside = !(bitCode(p, bbox2) & edge);
5619
- if (inside !== prevInside) result.push(intersect2(prev, p, edge, bbox2));
5620
- if (inside) result.push(p);
5621
- prev = p;
5622
- prevInside = inside;
5623
- }
5624
- points = result;
5625
- if (!points.length) break;
5626
- }
5627
- return result;
5628
- }
5629
- function intersect2(a, b, edge, bbox2) {
5630
- 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;
5631
- }
5632
- function bitCode(p, bbox2) {
5633
- var code = 0;
5634
- if (p[0] < bbox2[0]) code |= 1;
5635
- else if (p[0] > bbox2[2]) code |= 2;
5636
- if (p[1] < bbox2[1]) code |= 4;
5637
- else if (p[1] > bbox2[3]) code |= 8;
5638
- return code;
5639
- }
5640
- function bboxClip(feature2, bbox2) {
5641
- const geom = getGeom(feature2);
5642
- const type = geom.type;
5643
- const properties = feature2.type === "Feature" ? feature2.properties : {};
5644
- let coords = geom.coordinates;
5645
- switch (type) {
5646
- case "LineString":
5647
- case "MultiLineString": {
5648
- const lines = [];
5649
- if (type === "LineString") {
5650
- coords = [coords];
5651
- }
5652
- coords.forEach((line) => {
5653
- lineclip(line, bbox2, lines);
5654
- });
5655
- if (lines.length === 1) {
5656
- return lineString(lines[0], properties);
5657
- }
5658
- return multiLineString(lines, properties);
5659
- }
5660
- case "Polygon":
5661
- return polygon(clipPolygon(coords, bbox2), properties);
5662
- case "MultiPolygon":
5663
- return multiPolygon(
5664
- coords.map((poly) => {
5665
- return clipPolygon(poly, bbox2);
5666
- }),
5667
- properties
5668
- );
5669
- default:
5670
- throw new Error("geometry " + type + " not supported");
5671
- }
5672
- }
5673
- function clipPolygon(rings, bbox2) {
5674
- const outRings = [];
5675
- for (const ring of rings) {
5676
- const clipped = polygonclip(ring, bbox2);
5677
- if (clipped.length > 0) {
5678
- if (clipped[0][0] !== clipped[clipped.length - 1][0] || clipped[0][1] !== clipped[clipped.length - 1][1]) {
5679
- clipped.push(clipped[0]);
5680
- }
5681
- if (clipped.length >= 4) {
5682
- outRings.push(clipped);
5683
- }
5684
- }
5685
- }
5686
- return outRings;
5687
- }
5688
- var turf_bbox_clip_default = bboxClip;
5689
-
5690
5280
  // node_modules/h3-js/dist/h3-js.es.js
5691
5281
  var libh3 = function(libh32) {
5692
5282
  libh32 = libh32 || {};
@@ -19563,146 +19153,599 @@
19563
19153
  if (length2 > MAX_JS_ARRAY_LENGTH) {
19564
19154
  throw JSBindingError(E_ARRAY_LENGTH, length2);
19565
19155
  }
19566
- return length2;
19156
+ return length2;
19157
+ }
19158
+ var INVALID_HEXIDECIMAL_CHAR = /[^0-9a-fA-F]/;
19159
+ function h3IndexToSplitLong(h3Index) {
19160
+ if (Array.isArray(h3Index) && h3Index.length === 2 && Number.isInteger(h3Index[0]) && Number.isInteger(h3Index[1])) {
19161
+ return h3Index;
19162
+ }
19163
+ if (typeof h3Index !== "string" || INVALID_HEXIDECIMAL_CHAR.test(h3Index)) {
19164
+ return [0, 0];
19165
+ }
19166
+ var upper = parseInt(h3Index.substring(0, h3Index.length - 8), BASE_16);
19167
+ var lower = parseInt(h3Index.substring(h3Index.length - 8), BASE_16);
19168
+ return [lower, upper];
19169
+ }
19170
+ function hexFrom32Bit(num) {
19171
+ if (num >= 0) {
19172
+ return num.toString(BASE_16);
19173
+ }
19174
+ num = num & 2147483647;
19175
+ var tempStr = zeroPad(8, num.toString(BASE_16));
19176
+ var topNum = (parseInt(tempStr[0], BASE_16) + 8).toString(BASE_16);
19177
+ tempStr = topNum + tempStr.substring(1);
19178
+ return tempStr;
19179
+ }
19180
+ function splitLongToH3Index(lower, upper) {
19181
+ return hexFrom32Bit(upper) + zeroPad(8, hexFrom32Bit(lower));
19182
+ }
19183
+ function zeroPad(fullLen, numStr) {
19184
+ var numZeroes = fullLen - numStr.length;
19185
+ var outStr = "";
19186
+ for (var i = 0; i < numZeroes; i++) {
19187
+ outStr += "0";
19188
+ }
19189
+ outStr = outStr + numStr;
19190
+ return outStr;
19191
+ }
19192
+ var UPPER_BIT_DIVISOR = Math.pow(2, 32);
19193
+ function polygonArrayToGeoLoop(polygonArray, geoLoop, isGeoJson) {
19194
+ var numVerts = polygonArray.length;
19195
+ var geoCoordArray = libh3._calloc(numVerts, SZ_LATLNG);
19196
+ var latIndex = isGeoJson ? 1 : 0;
19197
+ var lngIndex = isGeoJson ? 0 : 1;
19198
+ for (var i = 0; i < numVerts * 2; i += 2) {
19199
+ libh3.HEAPF64.set([polygonArray[i / 2][latIndex], polygonArray[i / 2][lngIndex]].map(degsToRads), geoCoordArray / SZ_DBL + i);
19200
+ }
19201
+ libh3.HEAPU32.set([numVerts, geoCoordArray], geoLoop / SZ_INT);
19202
+ return geoLoop;
19203
+ }
19204
+ function coordinatesToGeoPolygon(coordinates, isGeoJson) {
19205
+ var numHoles = coordinates.length - 1;
19206
+ var geoPolygon = libh3._calloc(SZ_GEOPOLYGON);
19207
+ var geoLoopOffset = 0;
19208
+ var numHolesOffset = geoLoopOffset + SZ_GEOLOOP;
19209
+ var holesOffset = numHolesOffset + SZ_INT;
19210
+ polygonArrayToGeoLoop(coordinates[0], geoPolygon + geoLoopOffset, isGeoJson);
19211
+ var holes;
19212
+ if (numHoles > 0) {
19213
+ holes = libh3._calloc(numHoles, SZ_GEOLOOP);
19214
+ for (var i = 0; i < numHoles; i++) {
19215
+ polygonArrayToGeoLoop(coordinates[i + 1], holes + SZ_GEOLOOP * i, isGeoJson);
19216
+ }
19217
+ }
19218
+ libh3.setValue(geoPolygon + numHolesOffset, numHoles, "i32");
19219
+ libh3.setValue(geoPolygon + holesOffset, holes, "i32");
19220
+ return geoPolygon;
19221
+ }
19222
+ function destroyGeoPolygon(geoPolygon) {
19223
+ var geoLoopOffset = 0;
19224
+ var numHolesOffset = geoLoopOffset + SZ_GEOLOOP;
19225
+ var holesOffset = numHolesOffset + SZ_INT;
19226
+ var geoLoopArrayOffset = SZ_INT;
19227
+ libh3._free(libh3.getValue(geoPolygon + geoLoopOffset + geoLoopArrayOffset, "i8*"));
19228
+ var numHoles = libh3.getValue(geoPolygon + numHolesOffset, "i32");
19229
+ if (numHoles > 0) {
19230
+ var holes = libh3.getValue(geoPolygon + holesOffset, "i32");
19231
+ for (var i = 0; i < numHoles; i++) {
19232
+ libh3._free(libh3.getValue(holes + SZ_GEOLOOP * i + geoLoopArrayOffset, "i8*"));
19233
+ }
19234
+ libh3._free(holes);
19235
+ }
19236
+ libh3._free(geoPolygon);
19237
+ }
19238
+ function readH3IndexFromPointer(cAddress, offset) {
19239
+ if (offset === void 0) offset = 0;
19240
+ var lower = libh3.getValue(cAddress + SZ_H3INDEX * offset, "i32");
19241
+ var upper = libh3.getValue(cAddress + SZ_H3INDEX * offset + SZ_INT, "i32");
19242
+ return upper ? splitLongToH3Index(lower, upper) : null;
19243
+ }
19244
+ function readInt64AsDoubleFromPointer(cAddress) {
19245
+ return H3.readInt64AsDoubleFromPointer(cAddress);
19246
+ }
19247
+ function readArrayOfH3Indexes(cAddress, maxCount) {
19248
+ var out = [];
19249
+ for (var i = 0; i < maxCount; i++) {
19250
+ var h3Index = readH3IndexFromPointer(cAddress, i);
19251
+ if (h3Index !== null) {
19252
+ out.push(h3Index);
19253
+ }
19254
+ }
19255
+ return out;
19256
+ }
19257
+ function getResolution2(h3Index) {
19258
+ var ref = h3IndexToSplitLong(h3Index);
19259
+ var lower = ref[0];
19260
+ var upper = ref[1];
19261
+ if (!H3.isValidCell(lower, upper)) {
19262
+ return -1;
19263
+ }
19264
+ return H3.getResolution(lower, upper);
19265
+ }
19266
+ function polygonToCells(coordinates, res, isGeoJson) {
19267
+ validateRes(res);
19268
+ isGeoJson = Boolean(isGeoJson);
19269
+ if (coordinates.length === 0 || coordinates[0].length === 0) {
19270
+ return [];
19271
+ }
19272
+ var polygon2 = typeof coordinates[0][0] === "number" ? [coordinates] : coordinates;
19273
+ var geoPolygon = coordinatesToGeoPolygon(
19274
+ // @ts-expect-error - There's no way to convince TS that polygon is now number[][][]
19275
+ polygon2,
19276
+ isGeoJson
19277
+ );
19278
+ var countPtr = libh3._malloc(SZ_INT64);
19279
+ try {
19280
+ throwIfError(H3.maxPolygonToCellsSize(geoPolygon, res, 0, countPtr));
19281
+ var count = validateArrayLength(readInt64AsDoubleFromPointer(countPtr));
19282
+ var hexagons = libh3._calloc(count, SZ_H3INDEX);
19283
+ try {
19284
+ throwIfError(H3.polygonToCells(geoPolygon, res, 0, hexagons));
19285
+ return readArrayOfH3Indexes(hexagons, count);
19286
+ } finally {
19287
+ libh3._free(hexagons);
19288
+ }
19289
+ } finally {
19290
+ libh3._free(countPtr);
19291
+ destroyGeoPolygon(geoPolygon);
19292
+ }
19293
+ }
19294
+ function degsToRads(deg) {
19295
+ return deg * Math.PI / 180;
19296
+ }
19297
+
19298
+ // node_modules/@turf/bbox-clip/dist/esm/index.js
19299
+ function lineclip(points, bbox2, result) {
19300
+ var len = points.length, codeA = bitCode(points[0], bbox2), part = [], i, codeB, lastCode;
19301
+ let a;
19302
+ let b;
19303
+ if (!result) result = [];
19304
+ for (i = 1; i < len; i++) {
19305
+ a = points[i - 1];
19306
+ b = points[i];
19307
+ codeB = lastCode = bitCode(b, bbox2);
19308
+ while (true) {
19309
+ if (!(codeA | codeB)) {
19310
+ part.push(a);
19311
+ if (codeB !== lastCode) {
19312
+ part.push(b);
19313
+ if (i < len - 1) {
19314
+ result.push(part);
19315
+ part = [];
19316
+ }
19317
+ } else if (i === len - 1) {
19318
+ part.push(b);
19319
+ }
19320
+ break;
19321
+ } else if (codeA & codeB) {
19322
+ break;
19323
+ } else if (codeA) {
19324
+ a = intersect2(a, b, codeA, bbox2);
19325
+ codeA = bitCode(a, bbox2);
19326
+ } else {
19327
+ b = intersect2(a, b, codeB, bbox2);
19328
+ codeB = bitCode(b, bbox2);
19329
+ }
19330
+ }
19331
+ codeA = lastCode;
19332
+ }
19333
+ if (part.length) result.push(part);
19334
+ return result;
19335
+ }
19336
+ function polygonclip(points, bbox2) {
19337
+ var result, edge, prev, prevInside, i, p, inside;
19338
+ for (edge = 1; edge <= 8; edge *= 2) {
19339
+ result = [];
19340
+ prev = points[points.length - 1];
19341
+ prevInside = !(bitCode(prev, bbox2) & edge);
19342
+ for (i = 0; i < points.length; i++) {
19343
+ p = points[i];
19344
+ inside = !(bitCode(p, bbox2) & edge);
19345
+ if (inside !== prevInside) result.push(intersect2(prev, p, edge, bbox2));
19346
+ if (inside) result.push(p);
19347
+ prev = p;
19348
+ prevInside = inside;
19349
+ }
19350
+ points = result;
19351
+ if (!points.length) break;
19352
+ }
19353
+ return result;
19354
+ }
19355
+ function intersect2(a, b, edge, bbox2) {
19356
+ 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;
19357
+ }
19358
+ function bitCode(p, bbox2) {
19359
+ var code = 0;
19360
+ if (p[0] < bbox2[0]) code |= 1;
19361
+ else if (p[0] > bbox2[2]) code |= 2;
19362
+ if (p[1] < bbox2[1]) code |= 4;
19363
+ else if (p[1] > bbox2[3]) code |= 8;
19364
+ return code;
19365
+ }
19366
+ function bboxClip(feature2, bbox2) {
19367
+ const geom = getGeom(feature2);
19368
+ const type = geom.type;
19369
+ const properties = feature2.type === "Feature" ? feature2.properties : {};
19370
+ let coords = geom.coordinates;
19371
+ switch (type) {
19372
+ case "LineString":
19373
+ case "MultiLineString": {
19374
+ const lines = [];
19375
+ if (type === "LineString") {
19376
+ coords = [coords];
19377
+ }
19378
+ coords.forEach((line) => {
19379
+ lineclip(line, bbox2, lines);
19380
+ });
19381
+ if (lines.length === 1) {
19382
+ return lineString(lines[0], properties);
19383
+ }
19384
+ return multiLineString(lines, properties);
19385
+ }
19386
+ case "Polygon":
19387
+ return polygon(clipPolygon(coords, bbox2), properties);
19388
+ case "MultiPolygon":
19389
+ return multiPolygon(
19390
+ coords.map((poly) => {
19391
+ return clipPolygon(poly, bbox2);
19392
+ }),
19393
+ properties
19394
+ );
19395
+ default:
19396
+ throw new Error("geometry " + type + " not supported");
19397
+ }
19398
+ }
19399
+ function clipPolygon(rings, bbox2) {
19400
+ const outRings = [];
19401
+ for (const ring of rings) {
19402
+ const clipped = polygonclip(ring, bbox2);
19403
+ if (clipped.length > 0) {
19404
+ if (clipped[0][0] !== clipped[clipped.length - 1][0] || clipped[0][1] !== clipped[clipped.length - 1][1]) {
19405
+ clipped.push(clipped[0]);
19406
+ }
19407
+ if (clipped.length >= 4) {
19408
+ outRings.push(clipped);
19409
+ }
19410
+ }
19411
+ }
19412
+ return outRings;
19413
+ }
19414
+ var turf_bbox_clip_default = bboxClip;
19415
+
19416
+ // src/filters/tileIntersection.ts
19417
+ function intersectTileGeometry(tileBbox, tileFormat, spatialFilter) {
19418
+ const tilePolygon = turf_bbox_polygon_default(tileBbox);
19419
+ if (!spatialFilter || turf_boolean_within_default(tilePolygon, spatialFilter)) {
19420
+ return true;
19421
+ }
19422
+ const clippedSpatialFilter = turf_intersect_default(
19423
+ featureCollection([tilePolygon, feature(spatialFilter)])
19424
+ );
19425
+ if (!clippedSpatialFilter) {
19426
+ return false;
19427
+ }
19428
+ return tileFormat === "mvt" /* MVT */ ? transformToTileCoords(clippedSpatialFilter.geometry, tileBbox) : clippedSpatialFilter.geometry;
19429
+ }
19430
+ function intersectTileRaster(parent, cellResolution, spatialFilter) {
19431
+ return intersectTileQuadbin(parent, cellResolution, spatialFilter);
19432
+ }
19433
+ function intersectTileQuadbin(parent, cellResolution, spatialFilter) {
19434
+ const tilePolygon = cellToBoundary(parent);
19435
+ if (!spatialFilter || turf_boolean_within_default(tilePolygon, spatialFilter)) {
19436
+ return true;
19437
+ }
19438
+ const clippedSpatialFilter = turf_intersect_default(
19439
+ featureCollection([feature(tilePolygon), feature(spatialFilter)])
19440
+ );
19441
+ if (!clippedSpatialFilter) {
19442
+ return false;
19443
+ }
19444
+ const cells = geometryToCells(
19445
+ clippedSpatialFilter.geometry,
19446
+ cellResolution
19447
+ );
19448
+ return new Set(cells);
19449
+ }
19450
+ var BBOX_WEST = [-180, -90, 0, 90];
19451
+ var BBOX_EAST = [0, -90, 180, 90];
19452
+ function intersectTileH3(cellResolution, spatialFilter) {
19453
+ if (!spatialFilter) {
19454
+ return true;
19455
+ }
19456
+ const spatialFilterFeature = feature(spatialFilter);
19457
+ const cellsWest = polygonToCells(
19458
+ turf_bbox_clip_default(spatialFilterFeature, BBOX_WEST).geometry.coordinates,
19459
+ cellResolution,
19460
+ true
19461
+ );
19462
+ const cellsEast = polygonToCells(
19463
+ turf_bbox_clip_default(spatialFilterFeature, BBOX_EAST).geometry.coordinates,
19464
+ cellResolution,
19465
+ true
19466
+ );
19467
+ return new Set(cellsWest.concat(cellsEast));
19468
+ }
19469
+
19470
+ // src/filters/tileFeaturesGeometries.ts
19471
+ var FEATURE_GEOM_PROPERTY = "__geomValue";
19472
+ function tileFeaturesGeometries({
19473
+ tiles: tiles2,
19474
+ tileFormat,
19475
+ spatialFilter,
19476
+ uniqueIdProperty,
19477
+ options
19478
+ }) {
19479
+ const map = /* @__PURE__ */ new Map();
19480
+ for (const tile of tiles2) {
19481
+ if (tile.isVisible === false || !tile.data) {
19482
+ continue;
19483
+ }
19484
+ const tileBbox = [
19485
+ tile.bbox.west,
19486
+ tile.bbox.south,
19487
+ tile.bbox.east,
19488
+ tile.bbox.north
19489
+ ];
19490
+ const intersection3 = intersectTileGeometry(
19491
+ tileBbox,
19492
+ tileFormat,
19493
+ spatialFilter
19494
+ );
19495
+ if (intersection3 === false) continue;
19496
+ const transformedSpatialFilter = intersection3 === true ? void 0 : intersection3;
19497
+ calculateFeatures({
19498
+ map,
19499
+ spatialFilter: transformedSpatialFilter,
19500
+ data: tile.data.points,
19501
+ type: "Point",
19502
+ bbox: tileBbox,
19503
+ tileFormat,
19504
+ uniqueIdProperty,
19505
+ options
19506
+ });
19507
+ calculateFeatures({
19508
+ map,
19509
+ spatialFilter: transformedSpatialFilter,
19510
+ data: tile.data.lines,
19511
+ type: "LineString",
19512
+ bbox: tileBbox,
19513
+ tileFormat,
19514
+ uniqueIdProperty,
19515
+ options
19516
+ });
19517
+ calculateFeatures({
19518
+ map,
19519
+ spatialFilter: transformedSpatialFilter,
19520
+ data: tile.data.polygons,
19521
+ type: "Polygon",
19522
+ bbox: tileBbox,
19523
+ tileFormat,
19524
+ uniqueIdProperty,
19525
+ options
19526
+ });
19527
+ }
19528
+ return Array.from(map.values());
19529
+ }
19530
+ function processTileFeatureProperties({
19531
+ map,
19532
+ data,
19533
+ startIndex,
19534
+ endIndex,
19535
+ type,
19536
+ bbox: bbox2,
19537
+ tileFormat,
19538
+ uniqueIdProperty,
19539
+ storeGeometry,
19540
+ spatialFilter
19541
+ }) {
19542
+ const tileProps = getPropertiesFromTile(data, startIndex);
19543
+ const uniquePropertyValue = getUniquePropertyValue(
19544
+ tileProps,
19545
+ uniqueIdProperty,
19546
+ map
19547
+ );
19548
+ if (!uniquePropertyValue || map.has(uniquePropertyValue)) {
19549
+ return;
19550
+ }
19551
+ let geometry = null;
19552
+ if (storeGeometry || spatialFilter) {
19553
+ const { positions } = data;
19554
+ const ringCoordinates = getRingCoordinatesFor(
19555
+ startIndex,
19556
+ endIndex,
19557
+ positions
19558
+ );
19559
+ geometry = getFeatureByType(ringCoordinates, type);
19560
+ }
19561
+ if (geometry && spatialFilter && !turf_boolean_intersects_default(geometry, spatialFilter)) {
19562
+ return;
19563
+ }
19564
+ const properties = parseProperties(tileProps);
19565
+ if (storeGeometry && geometry) {
19566
+ properties[FEATURE_GEOM_PROPERTY] = tileFormat === "mvt" /* MVT */ ? transformTileCoordsToWGS84(geometry, bbox2) : geometry;
19567
+ }
19568
+ map.set(uniquePropertyValue, properties);
19569
+ }
19570
+ function addIntersectedFeaturesInTile({
19571
+ map,
19572
+ data,
19573
+ spatialFilter,
19574
+ type,
19575
+ bbox: bbox2,
19576
+ tileFormat,
19577
+ uniqueIdProperty,
19578
+ options
19579
+ }) {
19580
+ const indices = getIndices(data, type);
19581
+ const storeGeometry = options?.storeGeometry || false;
19582
+ for (let i = 0; i < indices.length - 1; i++) {
19583
+ const startIndex = indices[i];
19584
+ const endIndex = indices[i + 1];
19585
+ processTileFeatureProperties({
19586
+ map,
19587
+ data,
19588
+ startIndex,
19589
+ endIndex,
19590
+ type,
19591
+ bbox: bbox2,
19592
+ tileFormat,
19593
+ uniqueIdProperty,
19594
+ storeGeometry,
19595
+ spatialFilter
19596
+ });
19597
+ }
19598
+ }
19599
+ function getIndices(data, type) {
19600
+ let indices;
19601
+ switch (type) {
19602
+ case "Polygon":
19603
+ indices = data.primitivePolygonIndices;
19604
+ break;
19605
+ case "LineString":
19606
+ indices = data.pathIndices;
19607
+ break;
19608
+ case "Point":
19609
+ indices = createIndicesForPoints(data);
19610
+ break;
19611
+ default:
19612
+ throw new Error(
19613
+ `Unsupported geometry type: ${type}`
19614
+ );
19615
+ }
19616
+ return indices.value;
19567
19617
  }
19568
- var INVALID_HEXIDECIMAL_CHAR = /[^0-9a-fA-F]/;
19569
- function h3IndexToSplitLong(h3Index) {
19570
- if (Array.isArray(h3Index) && h3Index.length === 2 && Number.isInteger(h3Index[0]) && Number.isInteger(h3Index[1])) {
19571
- return h3Index;
19572
- }
19573
- if (typeof h3Index !== "string" || INVALID_HEXIDECIMAL_CHAR.test(h3Index)) {
19574
- return [0, 0];
19575
- }
19576
- var upper = parseInt(h3Index.substring(0, h3Index.length - 8), BASE_16);
19577
- var lower = parseInt(h3Index.substring(h3Index.length - 8), BASE_16);
19578
- return [lower, upper];
19618
+ function getFeatureId(data, startIndex) {
19619
+ return data.featureIds.value[startIndex];
19579
19620
  }
19580
- function hexFrom32Bit(num) {
19581
- if (num >= 0) {
19582
- return num.toString(BASE_16);
19621
+ function getPropertiesFromTile(data, startIndex) {
19622
+ const featureId2 = getFeatureId(data, startIndex);
19623
+ const { properties, numericProps, fields } = data;
19624
+ const result = {
19625
+ uniqueId: fields?.[featureId2]?.id,
19626
+ properties: properties[featureId2],
19627
+ numericProps: {}
19628
+ };
19629
+ for (const key in numericProps) {
19630
+ result.numericProps[key] = numericProps[key].value[startIndex];
19583
19631
  }
19584
- num = num & 2147483647;
19585
- var tempStr = zeroPad(8, num.toString(BASE_16));
19586
- var topNum = (parseInt(tempStr[0], BASE_16) + 8).toString(BASE_16);
19587
- tempStr = topNum + tempStr.substring(1);
19588
- return tempStr;
19632
+ return result;
19589
19633
  }
19590
- function splitLongToH3Index(lower, upper) {
19591
- return hexFrom32Bit(upper) + zeroPad(8, hexFrom32Bit(lower));
19634
+ function parseProperties(tileProps) {
19635
+ const { properties, numericProps } = tileProps;
19636
+ return Object.assign({}, properties, numericProps);
19592
19637
  }
19593
- function zeroPad(fullLen, numStr) {
19594
- var numZeroes = fullLen - numStr.length;
19595
- var outStr = "";
19596
- for (var i = 0; i < numZeroes; i++) {
19597
- outStr += "0";
19638
+ function getUniquePropertyValue(tileProps, uniqueIdProperty, map) {
19639
+ if (uniqueIdProperty) {
19640
+ return getValueFromTileProps(tileProps, uniqueIdProperty);
19598
19641
  }
19599
- outStr = outStr + numStr;
19600
- return outStr;
19601
- }
19602
- var UPPER_BIT_DIVISOR = Math.pow(2, 32);
19603
- function polygonArrayToGeoLoop(polygonArray, geoLoop, isGeoJson) {
19604
- var numVerts = polygonArray.length;
19605
- var geoCoordArray = libh3._calloc(numVerts, SZ_LATLNG);
19606
- var latIndex = isGeoJson ? 1 : 0;
19607
- var lngIndex = isGeoJson ? 0 : 1;
19608
- for (var i = 0; i < numVerts * 2; i += 2) {
19609
- libh3.HEAPF64.set([polygonArray[i / 2][latIndex], polygonArray[i / 2][lngIndex]].map(degsToRads), geoCoordArray / SZ_DBL + i);
19642
+ if (tileProps.uniqueId) {
19643
+ return tileProps.uniqueId;
19610
19644
  }
19611
- libh3.HEAPU32.set([numVerts, geoCoordArray], geoLoop / SZ_INT);
19612
- return geoLoop;
19645
+ const artificialId = map.size + 1;
19646
+ return getValueFromTileProps(tileProps, "cartodb_id") || getValueFromTileProps(tileProps, "geoid") || artificialId;
19613
19647
  }
19614
- function coordinatesToGeoPolygon(coordinates, isGeoJson) {
19615
- var numHoles = coordinates.length - 1;
19616
- var geoPolygon = libh3._calloc(SZ_GEOPOLYGON);
19617
- var geoLoopOffset = 0;
19618
- var numHolesOffset = geoLoopOffset + SZ_GEOLOOP;
19619
- var holesOffset = numHolesOffset + SZ_INT;
19620
- polygonArrayToGeoLoop(coordinates[0], geoPolygon + geoLoopOffset, isGeoJson);
19621
- var holes;
19622
- if (numHoles > 0) {
19623
- holes = libh3._calloc(numHoles, SZ_GEOLOOP);
19624
- for (var i = 0; i < numHoles; i++) {
19625
- polygonArrayToGeoLoop(coordinates[i + 1], holes + SZ_GEOLOOP * i, isGeoJson);
19626
- }
19627
- }
19628
- libh3.setValue(geoPolygon + numHolesOffset, numHoles, "i32");
19629
- libh3.setValue(geoPolygon + holesOffset, holes, "i32");
19630
- return geoPolygon;
19648
+ function getValueFromTileProps(tileProps, propertyName) {
19649
+ const { properties, numericProps } = tileProps;
19650
+ return numericProps[propertyName] || properties[propertyName];
19631
19651
  }
19632
- function destroyGeoPolygon(geoPolygon) {
19633
- var geoLoopOffset = 0;
19634
- var numHolesOffset = geoLoopOffset + SZ_GEOLOOP;
19635
- var holesOffset = numHolesOffset + SZ_INT;
19636
- var geoLoopArrayOffset = SZ_INT;
19637
- libh3._free(libh3.getValue(geoPolygon + geoLoopOffset + geoLoopArrayOffset, "i8*"));
19638
- var numHoles = libh3.getValue(geoPolygon + numHolesOffset, "i32");
19639
- if (numHoles > 0) {
19640
- var holes = libh3.getValue(geoPolygon + holesOffset, "i32");
19641
- for (var i = 0; i < numHoles; i++) {
19642
- libh3._free(libh3.getValue(holes + SZ_GEOLOOP * i + geoLoopArrayOffset, "i8*"));
19643
- }
19644
- libh3._free(holes);
19652
+ function getFeatureByType(coordinates, type) {
19653
+ switch (type) {
19654
+ case "Polygon":
19655
+ return { type: "Polygon", coordinates: [coordinates] };
19656
+ case "LineString":
19657
+ return { type: "LineString", coordinates };
19658
+ case "Point":
19659
+ return { type: "Point", coordinates: coordinates[0] };
19660
+ default:
19661
+ throw new Error("Invalid geometry type");
19645
19662
  }
19646
- libh3._free(geoPolygon);
19647
- }
19648
- function readH3IndexFromPointer(cAddress, offset) {
19649
- if (offset === void 0) offset = 0;
19650
- var lower = libh3.getValue(cAddress + SZ_H3INDEX * offset, "i32");
19651
- var upper = libh3.getValue(cAddress + SZ_H3INDEX * offset + SZ_INT, "i32");
19652
- return upper ? splitLongToH3Index(lower, upper) : null;
19653
19663
  }
19654
- function readInt64AsDoubleFromPointer(cAddress) {
19655
- return H3.readInt64AsDoubleFromPointer(cAddress);
19656
- }
19657
- function readArrayOfH3Indexes(cAddress, maxCount) {
19658
- var out = [];
19659
- for (var i = 0; i < maxCount; i++) {
19660
- var h3Index = readH3IndexFromPointer(cAddress, i);
19661
- if (h3Index !== null) {
19662
- out.push(h3Index);
19663
- }
19664
+ function getRingCoordinatesFor(startIndex, endIndex, positions) {
19665
+ const ringCoordinates = [];
19666
+ for (let j = startIndex; j < endIndex; j++) {
19667
+ ringCoordinates.push(
19668
+ Array.from(
19669
+ positions.value.subarray(j * positions.size, (j + 1) * positions.size)
19670
+ )
19671
+ );
19664
19672
  }
19665
- return out;
19673
+ return ringCoordinates;
19666
19674
  }
19667
- function getResolution2(h3Index) {
19668
- var ref = h3IndexToSplitLong(h3Index);
19669
- var lower = ref[0];
19670
- var upper = ref[1];
19671
- if (!H3.isValidCell(lower, upper)) {
19672
- return -1;
19675
+ function calculateFeatures({
19676
+ map,
19677
+ spatialFilter,
19678
+ data,
19679
+ type,
19680
+ bbox: bbox2,
19681
+ tileFormat,
19682
+ uniqueIdProperty,
19683
+ options
19684
+ }) {
19685
+ if (!data?.properties.length) {
19686
+ return;
19673
19687
  }
19674
- return H3.getResolution(lower, upper);
19675
- }
19676
- function polygonToCells(coordinates, res, isGeoJson) {
19677
- validateRes(res);
19678
- isGeoJson = Boolean(isGeoJson);
19679
- if (coordinates.length === 0 || coordinates[0].length === 0) {
19680
- return [];
19688
+ if (!spatialFilter) {
19689
+ addAllFeaturesInTile({
19690
+ map,
19691
+ data,
19692
+ type,
19693
+ bbox: bbox2,
19694
+ tileFormat,
19695
+ uniqueIdProperty,
19696
+ options
19697
+ });
19698
+ } else {
19699
+ addIntersectedFeaturesInTile({
19700
+ map,
19701
+ data,
19702
+ spatialFilter,
19703
+ type,
19704
+ bbox: bbox2,
19705
+ tileFormat,
19706
+ uniqueIdProperty,
19707
+ options
19708
+ });
19681
19709
  }
19682
- var polygon2 = typeof coordinates[0][0] === "number" ? [coordinates] : coordinates;
19683
- var geoPolygon = coordinatesToGeoPolygon(
19684
- // @ts-expect-error - There's no way to convince TS that polygon is now number[][][]
19685
- polygon2,
19686
- isGeoJson
19687
- );
19688
- var countPtr = libh3._malloc(SZ_INT64);
19689
- try {
19690
- throwIfError(H3.maxPolygonToCellsSize(geoPolygon, res, 0, countPtr));
19691
- var count = validateArrayLength(readInt64AsDoubleFromPointer(countPtr));
19692
- var hexagons = libh3._calloc(count, SZ_H3INDEX);
19693
- try {
19694
- throwIfError(H3.polygonToCells(geoPolygon, res, 0, hexagons));
19695
- return readArrayOfH3Indexes(hexagons, count);
19696
- } finally {
19697
- libh3._free(hexagons);
19698
- }
19699
- } finally {
19700
- libh3._free(countPtr);
19701
- destroyGeoPolygon(geoPolygon);
19710
+ }
19711
+ function addAllFeaturesInTile({
19712
+ map,
19713
+ data,
19714
+ type,
19715
+ bbox: bbox2,
19716
+ tileFormat,
19717
+ uniqueIdProperty,
19718
+ options
19719
+ }) {
19720
+ const indices = getIndices(data, type);
19721
+ const storeGeometry = options?.storeGeometry || false;
19722
+ for (let i = 0; i < indices.length - 1; i++) {
19723
+ const startIndex = indices[i];
19724
+ const endIndex = indices[i + 1];
19725
+ processTileFeatureProperties({
19726
+ map,
19727
+ data,
19728
+ startIndex,
19729
+ endIndex,
19730
+ type,
19731
+ bbox: bbox2,
19732
+ tileFormat,
19733
+ uniqueIdProperty,
19734
+ storeGeometry
19735
+ });
19702
19736
  }
19703
19737
  }
19704
- function degsToRads(deg) {
19705
- return deg * Math.PI / 180;
19738
+ function createIndicesForPoints(data) {
19739
+ const featureIds = data.featureIds.value;
19740
+ const lastFeatureId = featureIds[featureIds.length - 1];
19741
+ const PointIndicesArray = featureIds.constructor;
19742
+ const pointIndices = {
19743
+ value: new PointIndicesArray(featureIds.length + 1),
19744
+ size: 1
19745
+ };
19746
+ pointIndices.value.set(featureIds);
19747
+ pointIndices.value.set([lastFeatureId + 1], featureIds.length);
19748
+ return pointIndices;
19706
19749
  }
19707
19750
 
19708
19751
  // src/filters/tileFeaturesSpatialIndex.ts
@@ -19714,28 +19757,42 @@
19714
19757
  }) {
19715
19758
  const map = /* @__PURE__ */ new Map();
19716
19759
  const spatialIndex = getSpatialIndex(spatialDataType);
19717
- const resolution = getResolution3(tiles2, spatialIndex);
19760
+ const cellResolution = getResolution3(tiles2, spatialIndex);
19718
19761
  const spatialIndexIDName = spatialDataColumn ? spatialDataColumn : spatialIndex;
19719
- if (!resolution) {
19762
+ if (!cellResolution) {
19720
19763
  return [];
19721
19764
  }
19722
- const cells = getCellsCoverGeometry(spatialFilter, spatialIndex, resolution);
19723
- if (!cells?.length) {
19724
- return [];
19765
+ let intersection3;
19766
+ if (spatialIndex === "h3" /* H3 */) {
19767
+ intersection3 = intersectTileH3(cellResolution, spatialFilter);
19725
19768
  }
19726
- const cellsSet = new Set(cells);
19727
19769
  for (const tile of tiles2) {
19728
19770
  if (tile.isVisible === false || !tile.data) {
19729
19771
  continue;
19730
19772
  }
19773
+ if (spatialIndex === "quadbin" /* QUADBIN */) {
19774
+ const parent = getTileIndex(tile, spatialIndex);
19775
+ intersection3 = intersectTileQuadbin(
19776
+ parent,
19777
+ cellResolution,
19778
+ spatialFilter
19779
+ );
19780
+ }
19781
+ if (!intersection3) continue;
19731
19782
  tile.data.forEach((d) => {
19732
- if (cellsSet.has(d.id)) {
19783
+ if (intersection3 === true || intersection3.has(d.id)) {
19733
19784
  map.set(d.id, { ...d.properties, [spatialIndexIDName]: d.id });
19734
19785
  }
19735
19786
  });
19736
19787
  }
19737
19788
  return Array.from(map.values());
19738
19789
  }
19790
+ function getTileIndex(tile, spatialIndex) {
19791
+ if (spatialIndex === "quadbin" /* QUADBIN */) {
19792
+ return tile.index.q;
19793
+ }
19794
+ return tile.id;
19795
+ }
19739
19796
  function getResolution3(tiles2, spatialIndex) {
19740
19797
  const data = tiles2.find((tile) => tile.data?.length)?.data;
19741
19798
  if (!data) {
@@ -19748,26 +19805,6 @@
19748
19805
  return getResolution2(data[0].id);
19749
19806
  }
19750
19807
  }
19751
- var bboxWest = [-180, -90, 0, 90];
19752
- var bboxEast = [0, -90, 180, 90];
19753
- function getCellsCoverGeometry(geometry, spatialIndex, resolution) {
19754
- if (spatialIndex === "quadbin" /* QUADBIN */) {
19755
- return geometryToCells(geometry, resolution);
19756
- }
19757
- if (spatialIndex === "h3" /* H3 */) {
19758
- return polygonToCells(
19759
- turf_bbox_clip_default(geometry, bboxWest).geometry.coordinates,
19760
- resolution,
19761
- true
19762
- ).concat(
19763
- polygonToCells(
19764
- turf_bbox_clip_default(geometry, bboxEast).geometry.coordinates,
19765
- resolution,
19766
- true
19767
- )
19768
- );
19769
- }
19770
- }
19771
19808
  function getSpatialIndex(spatialDataType) {
19772
19809
  switch (spatialDataType) {
19773
19810
  case "h3":
@@ -19801,15 +19838,15 @@
19801
19838
  const data = /* @__PURE__ */ new Map();
19802
19839
  for (const tile of tiles2) {
19803
19840
  const parent = tile.index.q;
19804
- const tilePolygon = cellToBoundary(parent);
19805
- const tileFilter = turf_intersect_default(
19806
- featureCollection([feature(tilePolygon), feature(options.spatialFilter)])
19841
+ const intersection3 = intersectTileRaster(
19842
+ parent,
19843
+ cellResolution,
19844
+ options.spatialFilter
19807
19845
  );
19808
- const needsFilter = tileFilter ? !turf_boolean_within_default(tilePolygon, options.spatialFilter) : false;
19809
- const tileFilterCells = needsFilter ? new Set(geometryToCells(tileFilter.geometry, cellResolution)) : null;
19846
+ if (intersection3 === false) continue;
19810
19847
  const tileSortedCells = cellToChildrenSorted(parent, cellResolution);
19811
19848
  for (let i = 0; i < tileSortedCells.length; i++) {
19812
- if (needsFilter && !tileFilterCells.has(tileSortedCells[i])) {
19849
+ if (intersection3 !== true && !intersection3.has(tileSortedCells[i])) {
19813
19850
  continue;
19814
19851
  }
19815
19852
  const cellData = {};
@@ -20604,7 +20641,7 @@
20604
20641
  }
20605
20642
  _extractTileFeatures(spatialFilter) {
20606
20643
  const prevInputs = this._tileFeatureExtractPreviousInputs;
20607
- if (this._features.length && prevInputs.spatialFilter && booleanEqual(prevInputs.spatialFilter, spatialFilter)) {
20644
+ if (this._features.length && spatialFilterEquals(prevInputs.spatialFilter, spatialFilter)) {
20608
20645
  return;
20609
20646
  }
20610
20647
  this._features = tileFeatures({
@@ -20844,7 +20881,6 @@
20844
20881
  * INTERNAL
20845
20882
  */
20846
20883
  _getFilteredFeatures(spatialFilter, filters, filterOwner) {
20847
- assert(spatialFilter, "spatialFilter required for tilesets");
20848
20884
  this._extractTileFeatures(spatialFilter);
20849
20885
  return applyFilters(
20850
20886
  this._features,
@@ -20868,6 +20904,11 @@
20868
20904
  function normalizeColumns(columns) {
20869
20905
  return Array.isArray(columns) ? columns : typeof columns === "string" ? [columns] : [];
20870
20906
  }
20907
+ function spatialFilterEquals(a, b) {
20908
+ if (a === b) return true;
20909
+ if (!a || !b) return false;
20910
+ return booleanEqual(a, b);
20911
+ }
20871
20912
 
20872
20913
  // src/workers/widget-tileset-worker.ts
20873
20914
  var source;