@carto/api-client 0.5.7-alpha-optional-spatial-filter.1 → 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/api-client.cjs +436 -406
- package/build/api-client.cjs.map +1 -1
- package/build/api-client.d.cts +45 -17
- package/build/api-client.d.ts +45 -17
- package/build/api-client.js +400 -371
- package/build/api-client.js.map +1 -1
- package/build/worker-compat.js +865 -856
- package/build/worker-compat.js.map +1 -1
- package/build/worker.js +373 -367
- package/build/worker.js.map +1 -1
- package/package.json +1 -1
- package/src/filters/tileFeatures.ts +1 -1
- package/src/filters/tileFeaturesGeometries.ts +55 -28
- package/src/filters/tileFeaturesRaster.ts +21 -10
- package/src/filters/tileFeaturesSpatialIndex.ts +50 -37
- package/src/operations/groupBy.ts +61 -12
- package/src/operations/groupByDate.ts +6 -1
- package/src/widget-sources/constants.ts +6 -0
- package/src/widget-sources/index.ts +1 -0
- package/src/widget-sources/types.ts +25 -1
- package/src/widget-sources/widget-remote-source.ts +28 -5
- package/src/widget-sources/widget-tileset-source-impl.ts +23 -10
- package/src/filters/tileIntersection.ts +0 -155
package/build/worker-compat.js
CHANGED
|
@@ -1513,110 +1513,6 @@
|
|
|
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
|
-
|
|
1620
1516
|
// node_modules/@turf/bbox-polygon/dist/esm/index.js
|
|
1621
1517
|
function bboxPolygon(bbox2, options = {}) {
|
|
1622
1518
|
const west = Number(bbox2[0]);
|
|
@@ -1935,7 +1831,7 @@
|
|
|
1935
1831
|
var POWS_TEN = [1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13];
|
|
1936
1832
|
var SQRT_BASE = 1e7;
|
|
1937
1833
|
var MAX = 1e9;
|
|
1938
|
-
function
|
|
1834
|
+
function clone(configObject) {
|
|
1939
1835
|
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 = {
|
|
1940
1836
|
prefix: "",
|
|
1941
1837
|
groupSize: 3,
|
|
@@ -2061,7 +1957,7 @@
|
|
|
2061
1957
|
x.c = [x.e = 0];
|
|
2062
1958
|
}
|
|
2063
1959
|
}
|
|
2064
|
-
BigNumber2.clone =
|
|
1960
|
+
BigNumber2.clone = clone;
|
|
2065
1961
|
BigNumber2.ROUND_UP = 0;
|
|
2066
1962
|
BigNumber2.ROUND_DOWN = 1;
|
|
2067
1963
|
BigNumber2.ROUND_CEIL = 2;
|
|
@@ -3264,7 +3160,7 @@
|
|
|
3264
3160
|
}
|
|
3265
3161
|
return str;
|
|
3266
3162
|
}
|
|
3267
|
-
var BigNumber =
|
|
3163
|
+
var BigNumber = clone();
|
|
3268
3164
|
var bignumber_default = BigNumber;
|
|
3269
3165
|
|
|
3270
3166
|
// node_modules/splaytree-ts/dist/esm/index.js
|
|
@@ -4833,7 +4729,117 @@
|
|
|
4833
4729
|
}
|
|
4834
4730
|
var turf_intersect_default = intersect;
|
|
4835
4731
|
|
|
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
|
+
|
|
4836
4789
|
// 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
|
|
4837
4843
|
var TRANSFORM_FN2 = {
|
|
4838
4844
|
Point: transformPoint2,
|
|
4839
4845
|
MultiPoint: transformMultiPoint2,
|
|
@@ -4842,10 +4848,10 @@
|
|
|
4842
4848
|
Polygon: transformPolygon2,
|
|
4843
4849
|
MultiPolygon: transformMultiPolygon2
|
|
4844
4850
|
};
|
|
4845
|
-
function
|
|
4851
|
+
function transformTileCoordsToWGS84(geometry, bbox2) {
|
|
4846
4852
|
const [west, south, east, north] = bbox2;
|
|
4847
|
-
const nw =
|
|
4848
|
-
const se =
|
|
4853
|
+
const nw = lngLatToWorld([west, north]);
|
|
4854
|
+
const se = lngLatToWorld([east, south]);
|
|
4849
4855
|
const projectedBbox = [nw, se];
|
|
4850
4856
|
if (geometry.type === "GeometryCollection") {
|
|
4851
4857
|
throw new Error("Unsupported geometry type GeometryCollection");
|
|
@@ -4855,12 +4861,12 @@
|
|
|
4855
4861
|
return { ...geometry, coordinates };
|
|
4856
4862
|
}
|
|
4857
4863
|
function transformPoint2([pointX, pointY], [nw, se]) {
|
|
4858
|
-
const x =
|
|
4859
|
-
const y =
|
|
4860
|
-
return [x, y];
|
|
4864
|
+
const x = lerp(nw[0], se[0], pointX);
|
|
4865
|
+
const y = lerp(nw[1], se[1], pointY);
|
|
4866
|
+
return worldToLngLat([x, y]);
|
|
4861
4867
|
}
|
|
4862
4868
|
function getPoints2(geometry, bbox2) {
|
|
4863
|
-
return geometry.map((g) => transformPoint2(
|
|
4869
|
+
return geometry.map((g) => transformPoint2(g, bbox2));
|
|
4864
4870
|
}
|
|
4865
4871
|
function transformMultiPoint2(multiPoint, bbox2) {
|
|
4866
4872
|
return getPoints2(multiPoint, bbox2);
|
|
@@ -4879,132 +4885,418 @@
|
|
|
4879
4885
|
function transformMultiPolygon2(multiPolygon2, bbox2) {
|
|
4880
4886
|
return multiPolygon2.map((polygon2) => transformPolygon2(polygon2, bbox2));
|
|
4881
4887
|
}
|
|
4882
|
-
function projectFlat(xyz) {
|
|
4883
|
-
return lngLatToWorld(xyz);
|
|
4884
|
-
}
|
|
4885
|
-
function inverseLerp(a, b, x) {
|
|
4886
|
-
return (x - a) / (b - a);
|
|
4887
|
-
}
|
|
4888
4888
|
|
|
4889
|
-
//
|
|
4890
|
-
var
|
|
4891
|
-
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
4900
|
-
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
|
|
4905
|
-
|
|
4906
|
-
|
|
4907
|
-
|
|
4908
|
-
|
|
4909
|
-
|
|
4910
|
-
|
|
4911
|
-
|
|
4912
|
-
|
|
4913
|
-
|
|
4914
|
-
|
|
4915
|
-
|
|
4916
|
-
|
|
4917
|
-
|
|
4918
|
-
|
|
4919
|
-
|
|
4920
|
-
|
|
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());
|
|
4921
4958
|
}
|
|
4922
|
-
function
|
|
4923
|
-
|
|
4924
|
-
|
|
4925
|
-
|
|
4926
|
-
|
|
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);
|
|
4927
4998
|
}
|
|
4928
|
-
function
|
|
4929
|
-
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
|
|
4933
|
-
|
|
4934
|
-
|
|
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
|
+
}
|
|
4935
5027
|
}
|
|
4936
|
-
function
|
|
4937
|
-
|
|
4938
|
-
|
|
4939
|
-
|
|
4940
|
-
|
|
4941
|
-
|
|
4942
|
-
|
|
4943
|
-
|
|
4944
|
-
|
|
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
|
+
);
|
|
4945
5044
|
}
|
|
5045
|
+
return indices.value;
|
|
4946
5046
|
}
|
|
4947
|
-
function
|
|
4948
|
-
return
|
|
5047
|
+
function getFeatureId(data, startIndex) {
|
|
5048
|
+
return data.featureIds.value[startIndex];
|
|
4949
5049
|
}
|
|
4950
|
-
function
|
|
4951
|
-
|
|
4952
|
-
|
|
4953
|
-
|
|
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];
|
|
4954
5060
|
}
|
|
4955
|
-
return
|
|
5061
|
+
return result;
|
|
4956
5062
|
}
|
|
4957
|
-
function
|
|
4958
|
-
|
|
4959
|
-
|
|
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);
|
|
4960
5070
|
}
|
|
4961
|
-
|
|
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;
|
|
4962
5076
|
}
|
|
4963
|
-
function
|
|
4964
|
-
|
|
5077
|
+
function getValueFromTileProps(tileProps, propertyName) {
|
|
5078
|
+
const { properties, numericProps } = tileProps;
|
|
5079
|
+
return numericProps[propertyName] || properties[propertyName];
|
|
4965
5080
|
}
|
|
4966
|
-
function
|
|
4967
|
-
|
|
4968
|
-
|
|
4969
|
-
|
|
4970
|
-
|
|
4971
|
-
|
|
4972
|
-
|
|
4973
|
-
|
|
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");
|
|
4974
5091
|
}
|
|
4975
|
-
return index;
|
|
4976
5092
|
}
|
|
4977
|
-
function
|
|
4978
|
-
|
|
4979
|
-
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
|
|
4984
|
-
|
|
4985
|
-
break;
|
|
4986
|
-
case "1":
|
|
4987
|
-
x |= mask;
|
|
4988
|
-
break;
|
|
4989
|
-
case "2":
|
|
4990
|
-
y |= mask;
|
|
4991
|
-
break;
|
|
4992
|
-
case "3":
|
|
4993
|
-
x |= mask;
|
|
4994
|
-
y |= mask;
|
|
4995
|
-
break;
|
|
4996
|
-
}
|
|
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
|
+
);
|
|
4997
5101
|
}
|
|
4998
|
-
return
|
|
5102
|
+
return ringCoordinates;
|
|
4999
5103
|
}
|
|
5000
|
-
function
|
|
5001
|
-
|
|
5002
|
-
|
|
5003
|
-
|
|
5004
|
-
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
|
|
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
|
+
}
|
|
5180
|
+
|
|
5181
|
+
// node_modules/quadbin/dist/index.esm.js
|
|
5182
|
+
var d2r = Math.PI / 180;
|
|
5183
|
+
var r2d = 180 / Math.PI;
|
|
5184
|
+
function tileToBBOX(tile) {
|
|
5185
|
+
var e = tile2lon(tile[0] + 1, tile[2]);
|
|
5186
|
+
var w = tile2lon(tile[0], tile[2]);
|
|
5187
|
+
var s = tile2lat(tile[1] + 1, tile[2]);
|
|
5188
|
+
var n = tile2lat(tile[1], tile[2]);
|
|
5189
|
+
return [w, s, e, n];
|
|
5190
|
+
}
|
|
5191
|
+
function tileToGeoJSON(tile) {
|
|
5192
|
+
var bbox2 = tileToBBOX(tile);
|
|
5193
|
+
var poly = {
|
|
5194
|
+
type: "Polygon",
|
|
5195
|
+
coordinates: [
|
|
5196
|
+
[
|
|
5197
|
+
[bbox2[0], bbox2[1]],
|
|
5198
|
+
[bbox2[0], bbox2[3]],
|
|
5199
|
+
[bbox2[2], bbox2[3]],
|
|
5200
|
+
[bbox2[2], bbox2[1]],
|
|
5201
|
+
[bbox2[0], bbox2[1]]
|
|
5202
|
+
]
|
|
5203
|
+
]
|
|
5204
|
+
};
|
|
5205
|
+
return poly;
|
|
5206
|
+
}
|
|
5207
|
+
function tile2lon(x, z) {
|
|
5208
|
+
return x / Math.pow(2, z) * 360 - 180;
|
|
5209
|
+
}
|
|
5210
|
+
function tile2lat(y, z) {
|
|
5211
|
+
var n = Math.PI - 2 * Math.PI * y / Math.pow(2, z);
|
|
5212
|
+
return r2d * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n)));
|
|
5213
|
+
}
|
|
5214
|
+
function pointToTile(lon, lat, z) {
|
|
5215
|
+
var tile = pointToTileFraction(lon, lat, z);
|
|
5216
|
+
tile[0] = Math.floor(tile[0]);
|
|
5217
|
+
tile[1] = Math.floor(tile[1]);
|
|
5218
|
+
return tile;
|
|
5219
|
+
}
|
|
5220
|
+
function getChildren(tile) {
|
|
5221
|
+
return [
|
|
5222
|
+
[tile[0] * 2, tile[1] * 2, tile[2] + 1],
|
|
5223
|
+
[tile[0] * 2 + 1, tile[1] * 2, tile[2] + 1],
|
|
5224
|
+
[tile[0] * 2 + 1, tile[1] * 2 + 1, tile[2] + 1],
|
|
5225
|
+
[tile[0] * 2, tile[1] * 2 + 1, tile[2] + 1]
|
|
5226
|
+
];
|
|
5227
|
+
}
|
|
5228
|
+
function getParent(tile) {
|
|
5229
|
+
if (tile[0] % 2 === 0 && tile[1] % 2 === 0) {
|
|
5230
|
+
return [tile[0] / 2, tile[1] / 2, tile[2] - 1];
|
|
5231
|
+
} else if (tile[0] % 2 === 0 && !tile[1] % 2 === 0) {
|
|
5232
|
+
return [tile[0] / 2, (tile[1] - 1) / 2, tile[2] - 1];
|
|
5233
|
+
} else if (!tile[0] % 2 === 0 && tile[1] % 2 === 0) {
|
|
5234
|
+
return [(tile[0] - 1) / 2, tile[1] / 2, tile[2] - 1];
|
|
5235
|
+
} else {
|
|
5236
|
+
return [(tile[0] - 1) / 2, (tile[1] - 1) / 2, tile[2] - 1];
|
|
5237
|
+
}
|
|
5238
|
+
}
|
|
5239
|
+
function getSiblings(tile) {
|
|
5240
|
+
return getChildren(getParent(tile));
|
|
5241
|
+
}
|
|
5242
|
+
function hasSiblings(tile, tiles2) {
|
|
5243
|
+
var siblings = getSiblings(tile);
|
|
5244
|
+
for (var i = 0; i < siblings.length; i++) {
|
|
5245
|
+
if (!hasTile(tiles2, siblings[i])) return false;
|
|
5246
|
+
}
|
|
5247
|
+
return true;
|
|
5248
|
+
}
|
|
5249
|
+
function hasTile(tiles2, tile) {
|
|
5250
|
+
for (var i = 0; i < tiles2.length; i++) {
|
|
5251
|
+
if (tilesEqual(tiles2[i], tile)) return true;
|
|
5252
|
+
}
|
|
5253
|
+
return false;
|
|
5254
|
+
}
|
|
5255
|
+
function tilesEqual(tile1, tile2) {
|
|
5256
|
+
return tile1[0] === tile2[0] && tile1[1] === tile2[1] && tile1[2] === tile2[2];
|
|
5257
|
+
}
|
|
5258
|
+
function tileToQuadkey(tile) {
|
|
5259
|
+
var index = "";
|
|
5260
|
+
for (var z = tile[2]; z > 0; z--) {
|
|
5261
|
+
var b = 0;
|
|
5262
|
+
var mask = 1 << z - 1;
|
|
5263
|
+
if ((tile[0] & mask) !== 0) b++;
|
|
5264
|
+
if ((tile[1] & mask) !== 0) b += 2;
|
|
5265
|
+
index += b.toString();
|
|
5266
|
+
}
|
|
5267
|
+
return index;
|
|
5268
|
+
}
|
|
5269
|
+
function quadkeyToTile(quadkey) {
|
|
5270
|
+
var x = 0;
|
|
5271
|
+
var y = 0;
|
|
5272
|
+
var z = quadkey.length;
|
|
5273
|
+
for (var i = z; i > 0; i--) {
|
|
5274
|
+
var mask = 1 << i - 1;
|
|
5275
|
+
switch (quadkey[z - i]) {
|
|
5276
|
+
case "0":
|
|
5277
|
+
break;
|
|
5278
|
+
case "1":
|
|
5279
|
+
x |= mask;
|
|
5280
|
+
break;
|
|
5281
|
+
case "2":
|
|
5282
|
+
y |= mask;
|
|
5283
|
+
break;
|
|
5284
|
+
case "3":
|
|
5285
|
+
x |= mask;
|
|
5286
|
+
y |= mask;
|
|
5287
|
+
break;
|
|
5288
|
+
}
|
|
5289
|
+
}
|
|
5290
|
+
return [x, y, z];
|
|
5291
|
+
}
|
|
5292
|
+
function bboxToTile(bboxCoords) {
|
|
5293
|
+
var min2 = pointToTile(bboxCoords[0], bboxCoords[1], 32);
|
|
5294
|
+
var max2 = pointToTile(bboxCoords[2], bboxCoords[3], 32);
|
|
5295
|
+
var bbox2 = [min2[0], min2[1], max2[0], max2[1]];
|
|
5296
|
+
var z = getBboxZoom(bbox2);
|
|
5297
|
+
if (z === 0) return [0, 0, 0];
|
|
5298
|
+
var x = bbox2[0] >>> 32 - z;
|
|
5299
|
+
var y = bbox2[1] >>> 32 - z;
|
|
5008
5300
|
return [x, y, z];
|
|
5009
5301
|
}
|
|
5010
5302
|
function getBboxZoom(bbox2) {
|
|
@@ -5277,39 +5569,157 @@
|
|
|
5277
5569
|
};
|
|
5278
5570
|
}
|
|
5279
5571
|
|
|
5280
|
-
// node_modules/
|
|
5281
|
-
|
|
5282
|
-
|
|
5283
|
-
|
|
5284
|
-
|
|
5285
|
-
|
|
5286
|
-
for (
|
|
5287
|
-
|
|
5288
|
-
|
|
5289
|
-
|
|
5290
|
-
|
|
5291
|
-
|
|
5292
|
-
|
|
5293
|
-
|
|
5294
|
-
|
|
5295
|
-
|
|
5296
|
-
|
|
5297
|
-
|
|
5298
|
-
|
|
5299
|
-
|
|
5300
|
-
|
|
5301
|
-
|
|
5302
|
-
|
|
5303
|
-
|
|
5304
|
-
|
|
5305
|
-
|
|
5306
|
-
|
|
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
|
+
}
|
|
5307
5604
|
}
|
|
5308
|
-
|
|
5605
|
+
codeA = lastCode;
|
|
5309
5606
|
}
|
|
5310
|
-
|
|
5311
|
-
|
|
5312
|
-
|
|
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
|
+
// node_modules/h3-js/dist/h3-js.es.js
|
|
5691
|
+
var libh3 = function(libh32) {
|
|
5692
|
+
libh32 = libh32 || {};
|
|
5693
|
+
var Module = typeof libh32 !== "undefined" ? libh32 : {};
|
|
5694
|
+
var moduleOverrides = {};
|
|
5695
|
+
var key;
|
|
5696
|
+
for (key in Module) {
|
|
5697
|
+
if (Module.hasOwnProperty(key)) {
|
|
5698
|
+
moduleOverrides[key] = Module[key];
|
|
5699
|
+
}
|
|
5700
|
+
}
|
|
5701
|
+
var arguments_ = [];
|
|
5702
|
+
var thisProgram = "./this.program";
|
|
5703
|
+
var ENVIRONMENT_IS_WEB = false;
|
|
5704
|
+
var ENVIRONMENT_IS_WORKER = false;
|
|
5705
|
+
var ENVIRONMENT_IS_NODE = false;
|
|
5706
|
+
var ENVIRONMENT_HAS_NODE = false;
|
|
5707
|
+
var ENVIRONMENT_IS_SHELL = false;
|
|
5708
|
+
ENVIRONMENT_IS_WEB = typeof window === "object";
|
|
5709
|
+
ENVIRONMENT_IS_WORKER = typeof importScripts === "function";
|
|
5710
|
+
ENVIRONMENT_HAS_NODE = typeof process === "object" && typeof process.versions === "object" && typeof process.versions.node === "string";
|
|
5711
|
+
ENVIRONMENT_IS_NODE = ENVIRONMENT_HAS_NODE && !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_WORKER;
|
|
5712
|
+
ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER;
|
|
5713
|
+
var scriptDirectory = "";
|
|
5714
|
+
function locateFile(path) {
|
|
5715
|
+
if (Module["locateFile"]) {
|
|
5716
|
+
return Module["locateFile"](path, scriptDirectory);
|
|
5717
|
+
}
|
|
5718
|
+
return scriptDirectory + path;
|
|
5719
|
+
}
|
|
5720
|
+
var read_, readAsync, readBinary;
|
|
5721
|
+
if (ENVIRONMENT_IS_NODE) {
|
|
5722
|
+
scriptDirectory = __dirname + "/";
|
|
5313
5723
|
var nodeFS;
|
|
5314
5724
|
var nodePath;
|
|
5315
5725
|
read_ = function shell_read(filename, binary) {
|
|
@@ -19174,578 +19584,125 @@
|
|
|
19174
19584
|
num = num & 2147483647;
|
|
19175
19585
|
var tempStr = zeroPad(8, num.toString(BASE_16));
|
|
19176
19586
|
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;
|
|
19587
|
+
tempStr = topNum + tempStr.substring(1);
|
|
19588
|
+
return tempStr;
|
|
19617
19589
|
}
|
|
19618
|
-
function
|
|
19619
|
-
return
|
|
19590
|
+
function splitLongToH3Index(lower, upper) {
|
|
19591
|
+
return hexFrom32Bit(upper) + zeroPad(8, hexFrom32Bit(lower));
|
|
19620
19592
|
}
|
|
19621
|
-
function
|
|
19622
|
-
|
|
19623
|
-
|
|
19624
|
-
|
|
19625
|
-
|
|
19626
|
-
properties: properties[featureId2],
|
|
19627
|
-
numericProps: {}
|
|
19628
|
-
};
|
|
19629
|
-
for (const key in numericProps) {
|
|
19630
|
-
result.numericProps[key] = numericProps[key].value[startIndex];
|
|
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";
|
|
19631
19598
|
}
|
|
19632
|
-
|
|
19599
|
+
outStr = outStr + numStr;
|
|
19600
|
+
return outStr;
|
|
19633
19601
|
}
|
|
19634
|
-
|
|
19635
|
-
|
|
19636
|
-
|
|
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);
|
|
19610
|
+
}
|
|
19611
|
+
libh3.HEAPU32.set([numVerts, geoCoordArray], geoLoop / SZ_INT);
|
|
19612
|
+
return geoLoop;
|
|
19637
19613
|
}
|
|
19638
|
-
function
|
|
19639
|
-
|
|
19640
|
-
|
|
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
|
+
}
|
|
19641
19627
|
}
|
|
19642
|
-
|
|
19643
|
-
|
|
19628
|
+
libh3.setValue(geoPolygon + numHolesOffset, numHoles, "i32");
|
|
19629
|
+
libh3.setValue(geoPolygon + holesOffset, holes, "i32");
|
|
19630
|
+
return geoPolygon;
|
|
19631
|
+
}
|
|
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);
|
|
19644
19645
|
}
|
|
19645
|
-
|
|
19646
|
-
return getValueFromTileProps(tileProps, "cartodb_id") || getValueFromTileProps(tileProps, "geoid") || artificialId;
|
|
19646
|
+
libh3._free(geoPolygon);
|
|
19647
19647
|
}
|
|
19648
|
-
function
|
|
19649
|
-
|
|
19650
|
-
|
|
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;
|
|
19651
19653
|
}
|
|
19652
|
-
function
|
|
19653
|
-
|
|
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");
|
|
19662
|
-
}
|
|
19654
|
+
function readInt64AsDoubleFromPointer(cAddress) {
|
|
19655
|
+
return H3.readInt64AsDoubleFromPointer(cAddress);
|
|
19663
19656
|
}
|
|
19664
|
-
function
|
|
19665
|
-
|
|
19666
|
-
for (
|
|
19667
|
-
|
|
19668
|
-
|
|
19669
|
-
|
|
19670
|
-
|
|
19671
|
-
);
|
|
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
|
+
}
|
|
19672
19664
|
}
|
|
19673
|
-
return
|
|
19665
|
+
return out;
|
|
19674
19666
|
}
|
|
19675
|
-
function
|
|
19676
|
-
|
|
19677
|
-
|
|
19678
|
-
|
|
19679
|
-
|
|
19680
|
-
|
|
19681
|
-
tileFormat,
|
|
19682
|
-
uniqueIdProperty,
|
|
19683
|
-
options
|
|
19684
|
-
}) {
|
|
19685
|
-
if (!data?.properties.length) {
|
|
19686
|
-
return;
|
|
19687
|
-
}
|
|
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
|
-
});
|
|
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;
|
|
19709
19673
|
}
|
|
19674
|
+
return H3.getResolution(lower, upper);
|
|
19710
19675
|
}
|
|
19711
|
-
function
|
|
19712
|
-
|
|
19713
|
-
|
|
19714
|
-
|
|
19715
|
-
|
|
19716
|
-
|
|
19717
|
-
|
|
19718
|
-
|
|
19719
|
-
|
|
19720
|
-
|
|
19721
|
-
|
|
19722
|
-
|
|
19723
|
-
|
|
19724
|
-
|
|
19725
|
-
|
|
19726
|
-
|
|
19727
|
-
|
|
19728
|
-
|
|
19729
|
-
|
|
19730
|
-
|
|
19731
|
-
|
|
19732
|
-
|
|
19733
|
-
|
|
19734
|
-
|
|
19735
|
-
|
|
19676
|
+
function polygonToCells(coordinates, res, isGeoJson) {
|
|
19677
|
+
validateRes(res);
|
|
19678
|
+
isGeoJson = Boolean(isGeoJson);
|
|
19679
|
+
if (coordinates.length === 0 || coordinates[0].length === 0) {
|
|
19680
|
+
return [];
|
|
19681
|
+
}
|
|
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);
|
|
19736
19702
|
}
|
|
19737
19703
|
}
|
|
19738
|
-
function
|
|
19739
|
-
|
|
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;
|
|
19704
|
+
function degsToRads(deg) {
|
|
19705
|
+
return deg * Math.PI / 180;
|
|
19749
19706
|
}
|
|
19750
19707
|
|
|
19751
19708
|
// src/filters/tileFeaturesSpatialIndex.ts
|
|
@@ -19757,42 +19714,28 @@
|
|
|
19757
19714
|
}) {
|
|
19758
19715
|
const map = /* @__PURE__ */ new Map();
|
|
19759
19716
|
const spatialIndex = getSpatialIndex(spatialDataType);
|
|
19760
|
-
const
|
|
19717
|
+
const resolution = getResolution3(tiles2, spatialIndex);
|
|
19761
19718
|
const spatialIndexIDName = spatialDataColumn ? spatialDataColumn : spatialIndex;
|
|
19762
|
-
if (!
|
|
19719
|
+
if (!resolution) {
|
|
19763
19720
|
return [];
|
|
19764
19721
|
}
|
|
19765
|
-
|
|
19766
|
-
if (
|
|
19767
|
-
|
|
19722
|
+
const cells = getCellsCoverGeometry(spatialFilter, spatialIndex, resolution);
|
|
19723
|
+
if (!cells?.length) {
|
|
19724
|
+
return [];
|
|
19768
19725
|
}
|
|
19726
|
+
const cellsSet = new Set(cells);
|
|
19769
19727
|
for (const tile of tiles2) {
|
|
19770
19728
|
if (tile.isVisible === false || !tile.data) {
|
|
19771
19729
|
continue;
|
|
19772
19730
|
}
|
|
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;
|
|
19782
19731
|
tile.data.forEach((d) => {
|
|
19783
|
-
if (
|
|
19732
|
+
if (cellsSet.has(d.id)) {
|
|
19784
19733
|
map.set(d.id, { ...d.properties, [spatialIndexIDName]: d.id });
|
|
19785
19734
|
}
|
|
19786
19735
|
});
|
|
19787
19736
|
}
|
|
19788
19737
|
return Array.from(map.values());
|
|
19789
19738
|
}
|
|
19790
|
-
function getTileIndex(tile, spatialIndex) {
|
|
19791
|
-
if (spatialIndex === "quadbin" /* QUADBIN */) {
|
|
19792
|
-
return tile.index.q;
|
|
19793
|
-
}
|
|
19794
|
-
return tile.id;
|
|
19795
|
-
}
|
|
19796
19739
|
function getResolution3(tiles2, spatialIndex) {
|
|
19797
19740
|
const data = tiles2.find((tile) => tile.data?.length)?.data;
|
|
19798
19741
|
if (!data) {
|
|
@@ -19805,6 +19748,26 @@
|
|
|
19805
19748
|
return getResolution2(data[0].id);
|
|
19806
19749
|
}
|
|
19807
19750
|
}
|
|
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
|
+
}
|
|
19808
19771
|
function getSpatialIndex(spatialDataType) {
|
|
19809
19772
|
switch (spatialDataType) {
|
|
19810
19773
|
case "h3":
|
|
@@ -19838,15 +19801,15 @@
|
|
|
19838
19801
|
const data = /* @__PURE__ */ new Map();
|
|
19839
19802
|
for (const tile of tiles2) {
|
|
19840
19803
|
const parent = tile.index.q;
|
|
19841
|
-
const
|
|
19842
|
-
|
|
19843
|
-
|
|
19844
|
-
options.spatialFilter
|
|
19804
|
+
const tilePolygon = cellToBoundary(parent);
|
|
19805
|
+
const tileFilter = turf_intersect_default(
|
|
19806
|
+
featureCollection([feature(tilePolygon), feature(options.spatialFilter)])
|
|
19845
19807
|
);
|
|
19846
|
-
|
|
19808
|
+
const needsFilter = tileFilter ? !turf_boolean_within_default(tilePolygon, options.spatialFilter) : false;
|
|
19809
|
+
const tileFilterCells = needsFilter ? new Set(geometryToCells(tileFilter.geometry, cellResolution)) : null;
|
|
19847
19810
|
const tileSortedCells = cellToChildrenSorted(parent, cellResolution);
|
|
19848
19811
|
for (let i = 0; i < tileSortedCells.length; i++) {
|
|
19849
|
-
if (
|
|
19812
|
+
if (needsFilter && !tileFilterCells.has(tileSortedCells[i])) {
|
|
19850
19813
|
continue;
|
|
19851
19814
|
}
|
|
19852
19815
|
const cellData = {};
|
|
@@ -20081,16 +20044,21 @@
|
|
|
20081
20044
|
});
|
|
20082
20045
|
}
|
|
20083
20046
|
|
|
20047
|
+
// src/widget-sources/constants.ts
|
|
20048
|
+
var OTHERS_CATEGORY_NAME = "_carto_others";
|
|
20049
|
+
|
|
20084
20050
|
// src/operations/groupBy.ts
|
|
20085
20051
|
function groupValuesByColumn({
|
|
20086
20052
|
data,
|
|
20087
20053
|
valuesColumns,
|
|
20088
20054
|
joinOperation,
|
|
20089
20055
|
keysColumn,
|
|
20090
|
-
operation: operation2
|
|
20056
|
+
operation: operation2,
|
|
20057
|
+
othersThreshold,
|
|
20058
|
+
orderBy = "frequency_desc"
|
|
20091
20059
|
}) {
|
|
20092
20060
|
if (Array.isArray(data) && data.length === 0) {
|
|
20093
|
-
return null;
|
|
20061
|
+
return { rows: null };
|
|
20094
20062
|
}
|
|
20095
20063
|
const groups = data.reduce((accumulator, item) => {
|
|
20096
20064
|
const group = item[keysColumn];
|
|
@@ -20105,13 +20073,44 @@
|
|
|
20105
20073
|
return accumulator;
|
|
20106
20074
|
}, /* @__PURE__ */ new Map());
|
|
20107
20075
|
const targetOperation = aggregationFunctions[operation2];
|
|
20108
|
-
if (targetOperation) {
|
|
20109
|
-
return
|
|
20110
|
-
|
|
20111
|
-
|
|
20112
|
-
|
|
20076
|
+
if (!targetOperation) {
|
|
20077
|
+
return { rows: [] };
|
|
20078
|
+
}
|
|
20079
|
+
const allCategories = Array.from(groups).map(([name, value]) => ({
|
|
20080
|
+
name,
|
|
20081
|
+
value: targetOperation(value)
|
|
20082
|
+
})).sort(getSorter(orderBy));
|
|
20083
|
+
if (othersThreshold && allCategories.length > othersThreshold) {
|
|
20084
|
+
const otherValue = allCategories.slice(othersThreshold).flatMap(({ name }) => groups.get(name));
|
|
20085
|
+
allCategories.push({
|
|
20086
|
+
name: OTHERS_CATEGORY_NAME,
|
|
20087
|
+
value: targetOperation(otherValue)
|
|
20088
|
+
});
|
|
20089
|
+
return {
|
|
20090
|
+
rows: allCategories,
|
|
20091
|
+
metadata: {
|
|
20092
|
+
others: targetOperation(otherValue)
|
|
20093
|
+
}
|
|
20094
|
+
};
|
|
20095
|
+
}
|
|
20096
|
+
return {
|
|
20097
|
+
rows: allCategories
|
|
20098
|
+
};
|
|
20099
|
+
}
|
|
20100
|
+
function getSorter(orderBy) {
|
|
20101
|
+
switch (orderBy) {
|
|
20102
|
+
case "frequency_asc":
|
|
20103
|
+
return (a, b) => a.value - b.value || localeCompare(a.name, b.name);
|
|
20104
|
+
case "frequency_desc":
|
|
20105
|
+
return (a, b) => b.value - a.value || localeCompare(a.name, b.name);
|
|
20106
|
+
case "alphabetical_asc":
|
|
20107
|
+
return (a, b) => localeCompare(a.name, b.name) || b.value - a.value;
|
|
20108
|
+
case "alphabetical_desc":
|
|
20109
|
+
return (a, b) => localeCompare(b.name, a.name) || b.value - a.value;
|
|
20113
20110
|
}
|
|
20114
|
-
|
|
20111
|
+
}
|
|
20112
|
+
function localeCompare(a, b) {
|
|
20113
|
+
return (a ?? "null").localeCompare(b ?? "null");
|
|
20115
20114
|
}
|
|
20116
20115
|
|
|
20117
20116
|
// src/utils/dateUtils.ts
|
|
@@ -20641,7 +20640,7 @@
|
|
|
20641
20640
|
}
|
|
20642
20641
|
_extractTileFeatures(spatialFilter) {
|
|
20643
20642
|
const prevInputs = this._tileFeatureExtractPreviousInputs;
|
|
20644
|
-
if (this._features.length &&
|
|
20643
|
+
if (this._features.length && prevInputs.spatialFilter && booleanEqual(prevInputs.spatialFilter, spatialFilter)) {
|
|
20645
20644
|
return;
|
|
20646
20645
|
}
|
|
20647
20646
|
this._features = tileFeatures({
|
|
@@ -20730,7 +20729,10 @@
|
|
|
20730
20729
|
joinOperation,
|
|
20731
20730
|
filters,
|
|
20732
20731
|
filterOwner,
|
|
20733
|
-
spatialFilter
|
|
20732
|
+
spatialFilter,
|
|
20733
|
+
othersThreshold,
|
|
20734
|
+
orderBy = "frequency_desc",
|
|
20735
|
+
rawResult
|
|
20734
20736
|
}) {
|
|
20735
20737
|
const filteredFeatures = this._getFilteredFeatures(
|
|
20736
20738
|
spatialFilter,
|
|
@@ -20741,14 +20743,25 @@
|
|
|
20741
20743
|
return [];
|
|
20742
20744
|
}
|
|
20743
20745
|
assertColumn(this._features, column, operationColumn);
|
|
20744
|
-
const
|
|
20746
|
+
const result = groupValuesByColumn({
|
|
20745
20747
|
data: filteredFeatures,
|
|
20746
20748
|
valuesColumns: normalizeColumns(operationColumn || column),
|
|
20747
20749
|
joinOperation,
|
|
20748
20750
|
keysColumn: column,
|
|
20749
|
-
operation: operation2
|
|
20751
|
+
operation: operation2,
|
|
20752
|
+
othersThreshold,
|
|
20753
|
+
orderBy
|
|
20750
20754
|
});
|
|
20751
|
-
|
|
20755
|
+
if (rawResult) {
|
|
20756
|
+
return result;
|
|
20757
|
+
}
|
|
20758
|
+
if (!othersThreshold) {
|
|
20759
|
+
return result?.rows || [];
|
|
20760
|
+
}
|
|
20761
|
+
return [
|
|
20762
|
+
...result?.rows || [],
|
|
20763
|
+
{ name: OTHERS_CATEGORY_NAME, value: result?.metadata?.others }
|
|
20764
|
+
];
|
|
20752
20765
|
}
|
|
20753
20766
|
async getScatter({
|
|
20754
20767
|
xAxisColumn,
|
|
@@ -20881,6 +20894,7 @@
|
|
|
20881
20894
|
* INTERNAL
|
|
20882
20895
|
*/
|
|
20883
20896
|
_getFilteredFeatures(spatialFilter, filters, filterOwner) {
|
|
20897
|
+
assert(spatialFilter, "spatialFilter required for tilesets");
|
|
20884
20898
|
this._extractTileFeatures(spatialFilter);
|
|
20885
20899
|
return applyFilters(
|
|
20886
20900
|
this._features,
|
|
@@ -20904,11 +20918,6 @@
|
|
|
20904
20918
|
function normalizeColumns(columns) {
|
|
20905
20919
|
return Array.isArray(columns) ? columns : typeof columns === "string" ? [columns] : [];
|
|
20906
20920
|
}
|
|
20907
|
-
function spatialFilterEquals(a, b) {
|
|
20908
|
-
if (a === b) return true;
|
|
20909
|
-
if (!a || !b) return false;
|
|
20910
|
-
return booleanEqual(a, b);
|
|
20911
|
-
}
|
|
20912
20921
|
|
|
20913
20922
|
// src/workers/widget-tileset-worker.ts
|
|
20914
20923
|
var source;
|