@carto/api-client 0.5.7-alpha-optional-spatial-filter.0 → 0.5.7-alpha-others-orderby.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/api-client.cjs +437 -414
- 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 +401 -382
- package/build/api-client.js.map +1 -1
- package/build/worker-compat.js +865 -900
- package/build/worker-compat.js.map +1 -1
- package/build/worker.js +374 -378
- 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 +52 -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 -158
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) {
|
|
@@ -19175,623 +19585,124 @@
|
|
|
19175
19585
|
var tempStr = zeroPad(8, num.toString(BASE_16));
|
|
19176
19586
|
var topNum = (parseInt(tempStr[0], BASE_16) + 8).toString(BASE_16);
|
|
19177
19587
|
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 readSingleCoord(cAddress) {
|
|
19258
|
-
return radsToDegs(libh3.getValue(cAddress, "double"));
|
|
19259
|
-
}
|
|
19260
|
-
function readLatLng(cAddress) {
|
|
19261
|
-
return [readSingleCoord(cAddress), readSingleCoord(cAddress + SZ_DBL)];
|
|
19262
|
-
}
|
|
19263
|
-
function readLatLngGeoJson(cAddress) {
|
|
19264
|
-
return [readSingleCoord(cAddress + SZ_DBL), readSingleCoord(cAddress)];
|
|
19265
|
-
}
|
|
19266
|
-
function readCellBoundary(cellBoundary, geoJsonCoords, closedLoop) {
|
|
19267
|
-
var numVerts = libh3.getValue(cellBoundary, "i32");
|
|
19268
|
-
var vertsPos = cellBoundary + SZ_DBL;
|
|
19269
|
-
var out = [];
|
|
19270
|
-
var readCoord = geoJsonCoords ? readLatLngGeoJson : readLatLng;
|
|
19271
|
-
for (var i = 0; i < numVerts * 2; i += 2) {
|
|
19272
|
-
out.push(readCoord(vertsPos + SZ_DBL * i));
|
|
19273
|
-
}
|
|
19274
|
-
if (closedLoop) {
|
|
19275
|
-
out.push(out[0]);
|
|
19276
|
-
}
|
|
19277
|
-
return out;
|
|
19278
|
-
}
|
|
19279
|
-
function getResolution2(h3Index) {
|
|
19280
|
-
var ref = h3IndexToSplitLong(h3Index);
|
|
19281
|
-
var lower = ref[0];
|
|
19282
|
-
var upper = ref[1];
|
|
19283
|
-
if (!H3.isValidCell(lower, upper)) {
|
|
19284
|
-
return -1;
|
|
19285
|
-
}
|
|
19286
|
-
return H3.getResolution(lower, upper);
|
|
19287
|
-
}
|
|
19288
|
-
function cellToBoundary2(h3Index, formatAsGeoJson) {
|
|
19289
|
-
var cellBoundary = libh3._malloc(SZ_CELLBOUNDARY);
|
|
19290
|
-
var ref = h3IndexToSplitLong(h3Index);
|
|
19291
|
-
var lower = ref[0];
|
|
19292
|
-
var upper = ref[1];
|
|
19293
|
-
try {
|
|
19294
|
-
throwIfError(H3.cellToBoundary(lower, upper, cellBoundary));
|
|
19295
|
-
return readCellBoundary(cellBoundary, formatAsGeoJson, formatAsGeoJson);
|
|
19296
|
-
} finally {
|
|
19297
|
-
libh3._free(cellBoundary);
|
|
19298
|
-
}
|
|
19299
|
-
}
|
|
19300
|
-
function polygonToCells(coordinates, res, isGeoJson) {
|
|
19301
|
-
validateRes(res);
|
|
19302
|
-
isGeoJson = Boolean(isGeoJson);
|
|
19303
|
-
if (coordinates.length === 0 || coordinates[0].length === 0) {
|
|
19304
|
-
return [];
|
|
19305
|
-
}
|
|
19306
|
-
var polygon2 = typeof coordinates[0][0] === "number" ? [coordinates] : coordinates;
|
|
19307
|
-
var geoPolygon = coordinatesToGeoPolygon(
|
|
19308
|
-
// @ts-expect-error - There's no way to convince TS that polygon is now number[][][]
|
|
19309
|
-
polygon2,
|
|
19310
|
-
isGeoJson
|
|
19311
|
-
);
|
|
19312
|
-
var countPtr = libh3._malloc(SZ_INT64);
|
|
19313
|
-
try {
|
|
19314
|
-
throwIfError(H3.maxPolygonToCellsSize(geoPolygon, res, 0, countPtr));
|
|
19315
|
-
var count = validateArrayLength(readInt64AsDoubleFromPointer(countPtr));
|
|
19316
|
-
var hexagons = libh3._calloc(count, SZ_H3INDEX);
|
|
19317
|
-
try {
|
|
19318
|
-
throwIfError(H3.polygonToCells(geoPolygon, res, 0, hexagons));
|
|
19319
|
-
return readArrayOfH3Indexes(hexagons, count);
|
|
19320
|
-
} finally {
|
|
19321
|
-
libh3._free(hexagons);
|
|
19322
|
-
}
|
|
19323
|
-
} finally {
|
|
19324
|
-
libh3._free(countPtr);
|
|
19325
|
-
destroyGeoPolygon(geoPolygon);
|
|
19326
|
-
}
|
|
19327
|
-
}
|
|
19328
|
-
function degsToRads(deg) {
|
|
19329
|
-
return deg * Math.PI / 180;
|
|
19330
|
-
}
|
|
19331
|
-
function radsToDegs(rad) {
|
|
19332
|
-
return rad * 180 / Math.PI;
|
|
19333
|
-
}
|
|
19334
|
-
|
|
19335
|
-
// node_modules/@turf/bbox-clip/dist/esm/index.js
|
|
19336
|
-
function lineclip(points, bbox2, result) {
|
|
19337
|
-
var len = points.length, codeA = bitCode(points[0], bbox2), part = [], i, codeB, lastCode;
|
|
19338
|
-
let a;
|
|
19339
|
-
let b;
|
|
19340
|
-
if (!result) result = [];
|
|
19341
|
-
for (i = 1; i < len; i++) {
|
|
19342
|
-
a = points[i - 1];
|
|
19343
|
-
b = points[i];
|
|
19344
|
-
codeB = lastCode = bitCode(b, bbox2);
|
|
19345
|
-
while (true) {
|
|
19346
|
-
if (!(codeA | codeB)) {
|
|
19347
|
-
part.push(a);
|
|
19348
|
-
if (codeB !== lastCode) {
|
|
19349
|
-
part.push(b);
|
|
19350
|
-
if (i < len - 1) {
|
|
19351
|
-
result.push(part);
|
|
19352
|
-
part = [];
|
|
19353
|
-
}
|
|
19354
|
-
} else if (i === len - 1) {
|
|
19355
|
-
part.push(b);
|
|
19356
|
-
}
|
|
19357
|
-
break;
|
|
19358
|
-
} else if (codeA & codeB) {
|
|
19359
|
-
break;
|
|
19360
|
-
} else if (codeA) {
|
|
19361
|
-
a = intersect2(a, b, codeA, bbox2);
|
|
19362
|
-
codeA = bitCode(a, bbox2);
|
|
19363
|
-
} else {
|
|
19364
|
-
b = intersect2(a, b, codeB, bbox2);
|
|
19365
|
-
codeB = bitCode(b, bbox2);
|
|
19366
|
-
}
|
|
19367
|
-
}
|
|
19368
|
-
codeA = lastCode;
|
|
19369
|
-
}
|
|
19370
|
-
if (part.length) result.push(part);
|
|
19371
|
-
return result;
|
|
19372
|
-
}
|
|
19373
|
-
function polygonclip(points, bbox2) {
|
|
19374
|
-
var result, edge, prev, prevInside, i, p, inside;
|
|
19375
|
-
for (edge = 1; edge <= 8; edge *= 2) {
|
|
19376
|
-
result = [];
|
|
19377
|
-
prev = points[points.length - 1];
|
|
19378
|
-
prevInside = !(bitCode(prev, bbox2) & edge);
|
|
19379
|
-
for (i = 0; i < points.length; i++) {
|
|
19380
|
-
p = points[i];
|
|
19381
|
-
inside = !(bitCode(p, bbox2) & edge);
|
|
19382
|
-
if (inside !== prevInside) result.push(intersect2(prev, p, edge, bbox2));
|
|
19383
|
-
if (inside) result.push(p);
|
|
19384
|
-
prev = p;
|
|
19385
|
-
prevInside = inside;
|
|
19386
|
-
}
|
|
19387
|
-
points = result;
|
|
19388
|
-
if (!points.length) break;
|
|
19389
|
-
}
|
|
19390
|
-
return result;
|
|
19391
|
-
}
|
|
19392
|
-
function intersect2(a, b, edge, bbox2) {
|
|
19393
|
-
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;
|
|
19394
|
-
}
|
|
19395
|
-
function bitCode(p, bbox2) {
|
|
19396
|
-
var code = 0;
|
|
19397
|
-
if (p[0] < bbox2[0]) code |= 1;
|
|
19398
|
-
else if (p[0] > bbox2[2]) code |= 2;
|
|
19399
|
-
if (p[1] < bbox2[1]) code |= 4;
|
|
19400
|
-
else if (p[1] > bbox2[3]) code |= 8;
|
|
19401
|
-
return code;
|
|
19402
|
-
}
|
|
19403
|
-
function bboxClip(feature2, bbox2) {
|
|
19404
|
-
const geom = getGeom(feature2);
|
|
19405
|
-
const type = geom.type;
|
|
19406
|
-
const properties = feature2.type === "Feature" ? feature2.properties : {};
|
|
19407
|
-
let coords = geom.coordinates;
|
|
19408
|
-
switch (type) {
|
|
19409
|
-
case "LineString":
|
|
19410
|
-
case "MultiLineString": {
|
|
19411
|
-
const lines = [];
|
|
19412
|
-
if (type === "LineString") {
|
|
19413
|
-
coords = [coords];
|
|
19414
|
-
}
|
|
19415
|
-
coords.forEach((line) => {
|
|
19416
|
-
lineclip(line, bbox2, lines);
|
|
19417
|
-
});
|
|
19418
|
-
if (lines.length === 1) {
|
|
19419
|
-
return lineString(lines[0], properties);
|
|
19420
|
-
}
|
|
19421
|
-
return multiLineString(lines, properties);
|
|
19422
|
-
}
|
|
19423
|
-
case "Polygon":
|
|
19424
|
-
return polygon(clipPolygon(coords, bbox2), properties);
|
|
19425
|
-
case "MultiPolygon":
|
|
19426
|
-
return multiPolygon(
|
|
19427
|
-
coords.map((poly) => {
|
|
19428
|
-
return clipPolygon(poly, bbox2);
|
|
19429
|
-
}),
|
|
19430
|
-
properties
|
|
19431
|
-
);
|
|
19432
|
-
default:
|
|
19433
|
-
throw new Error("geometry " + type + " not supported");
|
|
19434
|
-
}
|
|
19435
|
-
}
|
|
19436
|
-
function clipPolygon(rings, bbox2) {
|
|
19437
|
-
const outRings = [];
|
|
19438
|
-
for (const ring of rings) {
|
|
19439
|
-
const clipped = polygonclip(ring, bbox2);
|
|
19440
|
-
if (clipped.length > 0) {
|
|
19441
|
-
if (clipped[0][0] !== clipped[clipped.length - 1][0] || clipped[0][1] !== clipped[clipped.length - 1][1]) {
|
|
19442
|
-
clipped.push(clipped[0]);
|
|
19443
|
-
}
|
|
19444
|
-
if (clipped.length >= 4) {
|
|
19445
|
-
outRings.push(clipped);
|
|
19446
|
-
}
|
|
19447
|
-
}
|
|
19448
|
-
}
|
|
19449
|
-
return outRings;
|
|
19450
|
-
}
|
|
19451
|
-
var turf_bbox_clip_default = bboxClip;
|
|
19452
|
-
|
|
19453
|
-
// src/filters/tileIntersection.ts
|
|
19454
|
-
function intersectTileGeometry(tileBbox, tileFormat, spatialFilter) {
|
|
19455
|
-
const tilePolygon = turf_bbox_polygon_default(tileBbox);
|
|
19456
|
-
if (!spatialFilter || turf_boolean_within_default(tilePolygon, spatialFilter)) {
|
|
19457
|
-
return true;
|
|
19458
|
-
}
|
|
19459
|
-
const clippedSpatialFilter = turf_intersect_default(
|
|
19460
|
-
featureCollection([tilePolygon, feature(spatialFilter)])
|
|
19461
|
-
);
|
|
19462
|
-
if (!clippedSpatialFilter) {
|
|
19463
|
-
return false;
|
|
19464
|
-
}
|
|
19465
|
-
return tileFormat === "mvt" /* MVT */ ? transformToTileCoords(clippedSpatialFilter.geometry, tileBbox) : clippedSpatialFilter.geometry;
|
|
19466
|
-
}
|
|
19467
|
-
function intersectTileRaster(parent, cellResolution, spatialFilter) {
|
|
19468
|
-
return intersectTileQuadbin(parent, cellResolution, spatialFilter);
|
|
19469
|
-
}
|
|
19470
|
-
function intersectTileQuadbin(parent, cellResolution, spatialFilter) {
|
|
19471
|
-
const tilePolygon = cellToBoundary(parent);
|
|
19472
|
-
if (!spatialFilter || turf_boolean_within_default(tilePolygon, spatialFilter)) {
|
|
19473
|
-
return true;
|
|
19474
|
-
}
|
|
19475
|
-
const clippedSpatialFilter = turf_intersect_default(
|
|
19476
|
-
featureCollection([feature(tilePolygon), feature(spatialFilter)])
|
|
19477
|
-
);
|
|
19478
|
-
if (!clippedSpatialFilter) {
|
|
19479
|
-
return false;
|
|
19480
|
-
}
|
|
19481
|
-
const cells = geometryToCells(
|
|
19482
|
-
clippedSpatialFilter.geometry,
|
|
19483
|
-
cellResolution
|
|
19484
|
-
);
|
|
19485
|
-
return new Set(cells);
|
|
19486
|
-
}
|
|
19487
|
-
var BBOX_WEST = [-180, -90, 0, 90];
|
|
19488
|
-
var BBOX_EAST = [0, -90, 180, 90];
|
|
19489
|
-
function intersectTileH3(parent, cellResolution, spatialFilter) {
|
|
19490
|
-
const tilePolygon = {
|
|
19491
|
-
type: "Polygon",
|
|
19492
|
-
coordinates: [cellToBoundary2(parent, true)]
|
|
19493
|
-
};
|
|
19494
|
-
if (!spatialFilter || turf_boolean_within_default(tilePolygon, spatialFilter)) {
|
|
19495
|
-
return true;
|
|
19496
|
-
}
|
|
19497
|
-
const clippedSpatialFilter = turf_intersect_default(
|
|
19498
|
-
featureCollection([feature(tilePolygon), feature(spatialFilter)])
|
|
19499
|
-
);
|
|
19500
|
-
if (!clippedSpatialFilter) {
|
|
19501
|
-
return false;
|
|
19502
|
-
}
|
|
19503
|
-
const cellsWest = polygonToCells(
|
|
19504
|
-
turf_bbox_clip_default(clippedSpatialFilter, BBOX_WEST).geometry.coordinates,
|
|
19505
|
-
cellResolution,
|
|
19506
|
-
true
|
|
19507
|
-
);
|
|
19508
|
-
const cellsEast = polygonToCells(
|
|
19509
|
-
turf_bbox_clip_default(clippedSpatialFilter, BBOX_EAST).geometry.coordinates,
|
|
19510
|
-
cellResolution,
|
|
19511
|
-
true
|
|
19512
|
-
);
|
|
19513
|
-
return new Set(cellsWest.concat(cellsEast));
|
|
19514
|
-
}
|
|
19515
|
-
|
|
19516
|
-
// src/filters/tileFeaturesGeometries.ts
|
|
19517
|
-
var FEATURE_GEOM_PROPERTY = "__geomValue";
|
|
19518
|
-
function tileFeaturesGeometries({
|
|
19519
|
-
tiles: tiles2,
|
|
19520
|
-
tileFormat,
|
|
19521
|
-
spatialFilter,
|
|
19522
|
-
uniqueIdProperty,
|
|
19523
|
-
options
|
|
19524
|
-
}) {
|
|
19525
|
-
const map = /* @__PURE__ */ new Map();
|
|
19526
|
-
for (const tile of tiles2) {
|
|
19527
|
-
if (tile.isVisible === false || !tile.data) {
|
|
19528
|
-
continue;
|
|
19529
|
-
}
|
|
19530
|
-
const tileBbox = [
|
|
19531
|
-
tile.bbox.west,
|
|
19532
|
-
tile.bbox.south,
|
|
19533
|
-
tile.bbox.east,
|
|
19534
|
-
tile.bbox.north
|
|
19535
|
-
];
|
|
19536
|
-
const intersection3 = intersectTileGeometry(
|
|
19537
|
-
tileBbox,
|
|
19538
|
-
tileFormat,
|
|
19539
|
-
spatialFilter
|
|
19540
|
-
);
|
|
19541
|
-
if (intersection3 === false) continue;
|
|
19542
|
-
const transformedSpatialFilter = intersection3 === true ? void 0 : intersection3;
|
|
19543
|
-
calculateFeatures({
|
|
19544
|
-
map,
|
|
19545
|
-
spatialFilter: transformedSpatialFilter,
|
|
19546
|
-
data: tile.data.points,
|
|
19547
|
-
type: "Point",
|
|
19548
|
-
bbox: tileBbox,
|
|
19549
|
-
tileFormat,
|
|
19550
|
-
uniqueIdProperty,
|
|
19551
|
-
options
|
|
19552
|
-
});
|
|
19553
|
-
calculateFeatures({
|
|
19554
|
-
map,
|
|
19555
|
-
spatialFilter: transformedSpatialFilter,
|
|
19556
|
-
data: tile.data.lines,
|
|
19557
|
-
type: "LineString",
|
|
19558
|
-
bbox: tileBbox,
|
|
19559
|
-
tileFormat,
|
|
19560
|
-
uniqueIdProperty,
|
|
19561
|
-
options
|
|
19562
|
-
});
|
|
19563
|
-
calculateFeatures({
|
|
19564
|
-
map,
|
|
19565
|
-
spatialFilter: transformedSpatialFilter,
|
|
19566
|
-
data: tile.data.polygons,
|
|
19567
|
-
type: "Polygon",
|
|
19568
|
-
bbox: tileBbox,
|
|
19569
|
-
tileFormat,
|
|
19570
|
-
uniqueIdProperty,
|
|
19571
|
-
options
|
|
19572
|
-
});
|
|
19573
|
-
}
|
|
19574
|
-
return Array.from(map.values());
|
|
19575
|
-
}
|
|
19576
|
-
function processTileFeatureProperties({
|
|
19577
|
-
map,
|
|
19578
|
-
data,
|
|
19579
|
-
startIndex,
|
|
19580
|
-
endIndex,
|
|
19581
|
-
type,
|
|
19582
|
-
bbox: bbox2,
|
|
19583
|
-
tileFormat,
|
|
19584
|
-
uniqueIdProperty,
|
|
19585
|
-
storeGeometry,
|
|
19586
|
-
spatialFilter
|
|
19587
|
-
}) {
|
|
19588
|
-
const tileProps = getPropertiesFromTile(data, startIndex);
|
|
19589
|
-
const uniquePropertyValue = getUniquePropertyValue(
|
|
19590
|
-
tileProps,
|
|
19591
|
-
uniqueIdProperty,
|
|
19592
|
-
map
|
|
19593
|
-
);
|
|
19594
|
-
if (!uniquePropertyValue || map.has(uniquePropertyValue)) {
|
|
19595
|
-
return;
|
|
19596
|
-
}
|
|
19597
|
-
let geometry = null;
|
|
19598
|
-
if (storeGeometry || spatialFilter) {
|
|
19599
|
-
const { positions } = data;
|
|
19600
|
-
const ringCoordinates = getRingCoordinatesFor(
|
|
19601
|
-
startIndex,
|
|
19602
|
-
endIndex,
|
|
19603
|
-
positions
|
|
19604
|
-
);
|
|
19605
|
-
geometry = getFeatureByType(ringCoordinates, type);
|
|
19606
|
-
}
|
|
19607
|
-
if (geometry && spatialFilter && !turf_boolean_intersects_default(geometry, spatialFilter)) {
|
|
19608
|
-
return;
|
|
19609
|
-
}
|
|
19610
|
-
const properties = parseProperties(tileProps);
|
|
19611
|
-
if (storeGeometry && geometry) {
|
|
19612
|
-
properties[FEATURE_GEOM_PROPERTY] = tileFormat === "mvt" /* MVT */ ? transformTileCoordsToWGS84(geometry, bbox2) : geometry;
|
|
19613
|
-
}
|
|
19614
|
-
map.set(uniquePropertyValue, properties);
|
|
19615
|
-
}
|
|
19616
|
-
function addIntersectedFeaturesInTile({
|
|
19617
|
-
map,
|
|
19618
|
-
data,
|
|
19619
|
-
spatialFilter,
|
|
19620
|
-
type,
|
|
19621
|
-
bbox: bbox2,
|
|
19622
|
-
tileFormat,
|
|
19623
|
-
uniqueIdProperty,
|
|
19624
|
-
options
|
|
19625
|
-
}) {
|
|
19626
|
-
const indices = getIndices(data, type);
|
|
19627
|
-
const storeGeometry = options?.storeGeometry || false;
|
|
19628
|
-
for (let i = 0; i < indices.length - 1; i++) {
|
|
19629
|
-
const startIndex = indices[i];
|
|
19630
|
-
const endIndex = indices[i + 1];
|
|
19631
|
-
processTileFeatureProperties({
|
|
19632
|
-
map,
|
|
19633
|
-
data,
|
|
19634
|
-
startIndex,
|
|
19635
|
-
endIndex,
|
|
19636
|
-
type,
|
|
19637
|
-
bbox: bbox2,
|
|
19638
|
-
tileFormat,
|
|
19639
|
-
uniqueIdProperty,
|
|
19640
|
-
storeGeometry,
|
|
19641
|
-
spatialFilter
|
|
19642
|
-
});
|
|
19643
|
-
}
|
|
19644
|
-
}
|
|
19645
|
-
function getIndices(data, type) {
|
|
19646
|
-
let indices;
|
|
19647
|
-
switch (type) {
|
|
19648
|
-
case "Polygon":
|
|
19649
|
-
indices = data.primitivePolygonIndices;
|
|
19650
|
-
break;
|
|
19651
|
-
case "LineString":
|
|
19652
|
-
indices = data.pathIndices;
|
|
19653
|
-
break;
|
|
19654
|
-
case "Point":
|
|
19655
|
-
indices = createIndicesForPoints(data);
|
|
19656
|
-
break;
|
|
19657
|
-
default:
|
|
19658
|
-
throw new Error(
|
|
19659
|
-
`Unsupported geometry type: ${type}`
|
|
19660
|
-
);
|
|
19661
|
-
}
|
|
19662
|
-
return indices.value;
|
|
19588
|
+
return tempStr;
|
|
19663
19589
|
}
|
|
19664
|
-
function
|
|
19665
|
-
return
|
|
19590
|
+
function splitLongToH3Index(lower, upper) {
|
|
19591
|
+
return hexFrom32Bit(upper) + zeroPad(8, hexFrom32Bit(lower));
|
|
19666
19592
|
}
|
|
19667
|
-
function
|
|
19668
|
-
|
|
19669
|
-
|
|
19670
|
-
|
|
19671
|
-
|
|
19672
|
-
properties: properties[featureId2],
|
|
19673
|
-
numericProps: {}
|
|
19674
|
-
};
|
|
19675
|
-
for (const key in numericProps) {
|
|
19676
|
-
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";
|
|
19677
19598
|
}
|
|
19678
|
-
|
|
19599
|
+
outStr = outStr + numStr;
|
|
19600
|
+
return outStr;
|
|
19679
19601
|
}
|
|
19680
|
-
|
|
19681
|
-
|
|
19682
|
-
|
|
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;
|
|
19683
19613
|
}
|
|
19684
|
-
function
|
|
19685
|
-
|
|
19686
|
-
|
|
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
|
+
}
|
|
19687
19627
|
}
|
|
19688
|
-
|
|
19689
|
-
|
|
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);
|
|
19690
19645
|
}
|
|
19691
|
-
|
|
19692
|
-
return getValueFromTileProps(tileProps, "cartodb_id") || getValueFromTileProps(tileProps, "geoid") || artificialId;
|
|
19646
|
+
libh3._free(geoPolygon);
|
|
19693
19647
|
}
|
|
19694
|
-
function
|
|
19695
|
-
|
|
19696
|
-
|
|
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;
|
|
19697
19653
|
}
|
|
19698
|
-
function
|
|
19699
|
-
|
|
19700
|
-
case "Polygon":
|
|
19701
|
-
return { type: "Polygon", coordinates: [coordinates] };
|
|
19702
|
-
case "LineString":
|
|
19703
|
-
return { type: "LineString", coordinates };
|
|
19704
|
-
case "Point":
|
|
19705
|
-
return { type: "Point", coordinates: coordinates[0] };
|
|
19706
|
-
default:
|
|
19707
|
-
throw new Error("Invalid geometry type");
|
|
19708
|
-
}
|
|
19654
|
+
function readInt64AsDoubleFromPointer(cAddress) {
|
|
19655
|
+
return H3.readInt64AsDoubleFromPointer(cAddress);
|
|
19709
19656
|
}
|
|
19710
|
-
function
|
|
19711
|
-
|
|
19712
|
-
for (
|
|
19713
|
-
|
|
19714
|
-
|
|
19715
|
-
|
|
19716
|
-
|
|
19717
|
-
);
|
|
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
|
+
}
|
|
19718
19664
|
}
|
|
19719
|
-
return
|
|
19665
|
+
return out;
|
|
19720
19666
|
}
|
|
19721
|
-
function
|
|
19722
|
-
|
|
19723
|
-
|
|
19724
|
-
|
|
19725
|
-
|
|
19726
|
-
|
|
19727
|
-
tileFormat,
|
|
19728
|
-
uniqueIdProperty,
|
|
19729
|
-
options
|
|
19730
|
-
}) {
|
|
19731
|
-
if (!data?.properties.length) {
|
|
19732
|
-
return;
|
|
19733
|
-
}
|
|
19734
|
-
if (!spatialFilter) {
|
|
19735
|
-
addAllFeaturesInTile({
|
|
19736
|
-
map,
|
|
19737
|
-
data,
|
|
19738
|
-
type,
|
|
19739
|
-
bbox: bbox2,
|
|
19740
|
-
tileFormat,
|
|
19741
|
-
uniqueIdProperty,
|
|
19742
|
-
options
|
|
19743
|
-
});
|
|
19744
|
-
} else {
|
|
19745
|
-
addIntersectedFeaturesInTile({
|
|
19746
|
-
map,
|
|
19747
|
-
data,
|
|
19748
|
-
spatialFilter,
|
|
19749
|
-
type,
|
|
19750
|
-
bbox: bbox2,
|
|
19751
|
-
tileFormat,
|
|
19752
|
-
uniqueIdProperty,
|
|
19753
|
-
options
|
|
19754
|
-
});
|
|
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;
|
|
19755
19673
|
}
|
|
19674
|
+
return H3.getResolution(lower, upper);
|
|
19756
19675
|
}
|
|
19757
|
-
function
|
|
19758
|
-
|
|
19759
|
-
|
|
19760
|
-
|
|
19761
|
-
|
|
19762
|
-
|
|
19763
|
-
|
|
19764
|
-
|
|
19765
|
-
|
|
19766
|
-
|
|
19767
|
-
|
|
19768
|
-
|
|
19769
|
-
|
|
19770
|
-
|
|
19771
|
-
|
|
19772
|
-
|
|
19773
|
-
|
|
19774
|
-
|
|
19775
|
-
|
|
19776
|
-
|
|
19777
|
-
|
|
19778
|
-
|
|
19779
|
-
|
|
19780
|
-
|
|
19781
|
-
|
|
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);
|
|
19782
19702
|
}
|
|
19783
19703
|
}
|
|
19784
|
-
function
|
|
19785
|
-
|
|
19786
|
-
const lastFeatureId = featureIds[featureIds.length - 1];
|
|
19787
|
-
const PointIndicesArray = featureIds.constructor;
|
|
19788
|
-
const pointIndices = {
|
|
19789
|
-
value: new PointIndicesArray(featureIds.length + 1),
|
|
19790
|
-
size: 1
|
|
19791
|
-
};
|
|
19792
|
-
pointIndices.value.set(featureIds);
|
|
19793
|
-
pointIndices.value.set([lastFeatureId + 1], featureIds.length);
|
|
19794
|
-
return pointIndices;
|
|
19704
|
+
function degsToRads(deg) {
|
|
19705
|
+
return deg * Math.PI / 180;
|
|
19795
19706
|
}
|
|
19796
19707
|
|
|
19797
19708
|
// src/filters/tileFeaturesSpatialIndex.ts
|
|
@@ -19803,40 +19714,28 @@
|
|
|
19803
19714
|
}) {
|
|
19804
19715
|
const map = /* @__PURE__ */ new Map();
|
|
19805
19716
|
const spatialIndex = getSpatialIndex(spatialDataType);
|
|
19806
|
-
const
|
|
19717
|
+
const resolution = getResolution3(tiles2, spatialIndex);
|
|
19807
19718
|
const spatialIndexIDName = spatialDataColumn ? spatialDataColumn : spatialIndex;
|
|
19808
|
-
if (!
|
|
19719
|
+
if (!resolution) {
|
|
19720
|
+
return [];
|
|
19721
|
+
}
|
|
19722
|
+
const cells = getCellsCoverGeometry(spatialFilter, spatialIndex, resolution);
|
|
19723
|
+
if (!cells?.length) {
|
|
19809
19724
|
return [];
|
|
19810
19725
|
}
|
|
19726
|
+
const cellsSet = new Set(cells);
|
|
19811
19727
|
for (const tile of tiles2) {
|
|
19812
19728
|
if (tile.isVisible === false || !tile.data) {
|
|
19813
19729
|
continue;
|
|
19814
19730
|
}
|
|
19815
|
-
const parent = getTileIndex(tile, spatialIndex);
|
|
19816
|
-
const intersection3 = spatialIndex === "quadbin" /* QUADBIN */ ? intersectTileQuadbin(
|
|
19817
|
-
parent,
|
|
19818
|
-
cellResolution,
|
|
19819
|
-
spatialFilter
|
|
19820
|
-
) : intersectTileH3(
|
|
19821
|
-
parent,
|
|
19822
|
-
cellResolution,
|
|
19823
|
-
spatialFilter
|
|
19824
|
-
);
|
|
19825
|
-
if (!intersection3) continue;
|
|
19826
19731
|
tile.data.forEach((d) => {
|
|
19827
|
-
if (
|
|
19732
|
+
if (cellsSet.has(d.id)) {
|
|
19828
19733
|
map.set(d.id, { ...d.properties, [spatialIndexIDName]: d.id });
|
|
19829
19734
|
}
|
|
19830
19735
|
});
|
|
19831
19736
|
}
|
|
19832
19737
|
return Array.from(map.values());
|
|
19833
19738
|
}
|
|
19834
|
-
function getTileIndex(tile, spatialIndex) {
|
|
19835
|
-
if (spatialIndex === "quadbin" /* QUADBIN */) {
|
|
19836
|
-
return tile.index.q;
|
|
19837
|
-
}
|
|
19838
|
-
return tile.id;
|
|
19839
|
-
}
|
|
19840
19739
|
function getResolution3(tiles2, spatialIndex) {
|
|
19841
19740
|
const data = tiles2.find((tile) => tile.data?.length)?.data;
|
|
19842
19741
|
if (!data) {
|
|
@@ -19849,6 +19748,26 @@
|
|
|
19849
19748
|
return getResolution2(data[0].id);
|
|
19850
19749
|
}
|
|
19851
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
|
+
}
|
|
19852
19771
|
function getSpatialIndex(spatialDataType) {
|
|
19853
19772
|
switch (spatialDataType) {
|
|
19854
19773
|
case "h3":
|
|
@@ -19882,15 +19801,15 @@
|
|
|
19882
19801
|
const data = /* @__PURE__ */ new Map();
|
|
19883
19802
|
for (const tile of tiles2) {
|
|
19884
19803
|
const parent = tile.index.q;
|
|
19885
|
-
const
|
|
19886
|
-
|
|
19887
|
-
|
|
19888
|
-
options.spatialFilter
|
|
19804
|
+
const tilePolygon = cellToBoundary(parent);
|
|
19805
|
+
const tileFilter = turf_intersect_default(
|
|
19806
|
+
featureCollection([feature(tilePolygon), feature(options.spatialFilter)])
|
|
19889
19807
|
);
|
|
19890
|
-
|
|
19808
|
+
const needsFilter = tileFilter ? !turf_boolean_within_default(tilePolygon, options.spatialFilter) : false;
|
|
19809
|
+
const tileFilterCells = needsFilter ? new Set(geometryToCells(tileFilter.geometry, cellResolution)) : null;
|
|
19891
19810
|
const tileSortedCells = cellToChildrenSorted(parent, cellResolution);
|
|
19892
19811
|
for (let i = 0; i < tileSortedCells.length; i++) {
|
|
19893
|
-
if (
|
|
19812
|
+
if (needsFilter && !tileFilterCells.has(tileSortedCells[i])) {
|
|
19894
19813
|
continue;
|
|
19895
19814
|
}
|
|
19896
19815
|
const cellData = {};
|
|
@@ -20125,16 +20044,21 @@
|
|
|
20125
20044
|
});
|
|
20126
20045
|
}
|
|
20127
20046
|
|
|
20047
|
+
// src/widget-sources/constants.ts
|
|
20048
|
+
var OTHERS_CATEGORY_NAME = "_carto_others";
|
|
20049
|
+
|
|
20128
20050
|
// src/operations/groupBy.ts
|
|
20129
20051
|
function groupValuesByColumn({
|
|
20130
20052
|
data,
|
|
20131
20053
|
valuesColumns,
|
|
20132
20054
|
joinOperation,
|
|
20133
20055
|
keysColumn,
|
|
20134
|
-
operation: operation2
|
|
20056
|
+
operation: operation2,
|
|
20057
|
+
othersThreshold,
|
|
20058
|
+
orderBy = "frequency_desc"
|
|
20135
20059
|
}) {
|
|
20136
20060
|
if (Array.isArray(data) && data.length === 0) {
|
|
20137
|
-
return null;
|
|
20061
|
+
return { rows: null };
|
|
20138
20062
|
}
|
|
20139
20063
|
const groups = data.reduce((accumulator, item) => {
|
|
20140
20064
|
const group = item[keysColumn];
|
|
@@ -20149,13 +20073,44 @@
|
|
|
20149
20073
|
return accumulator;
|
|
20150
20074
|
}, /* @__PURE__ */ new Map());
|
|
20151
20075
|
const targetOperation = aggregationFunctions[operation2];
|
|
20152
|
-
if (targetOperation) {
|
|
20153
|
-
return
|
|
20154
|
-
|
|
20155
|
-
|
|
20156
|
-
|
|
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;
|
|
20157
20110
|
}
|
|
20158
|
-
|
|
20111
|
+
}
|
|
20112
|
+
function localeCompare(a, b) {
|
|
20113
|
+
return (a ?? "null").localeCompare(b ?? "null");
|
|
20159
20114
|
}
|
|
20160
20115
|
|
|
20161
20116
|
// src/utils/dateUtils.ts
|
|
@@ -20685,7 +20640,7 @@
|
|
|
20685
20640
|
}
|
|
20686
20641
|
_extractTileFeatures(spatialFilter) {
|
|
20687
20642
|
const prevInputs = this._tileFeatureExtractPreviousInputs;
|
|
20688
|
-
if (this._features.length &&
|
|
20643
|
+
if (this._features.length && prevInputs.spatialFilter && booleanEqual(prevInputs.spatialFilter, spatialFilter)) {
|
|
20689
20644
|
return;
|
|
20690
20645
|
}
|
|
20691
20646
|
this._features = tileFeatures({
|
|
@@ -20774,7 +20729,10 @@
|
|
|
20774
20729
|
joinOperation,
|
|
20775
20730
|
filters,
|
|
20776
20731
|
filterOwner,
|
|
20777
|
-
spatialFilter
|
|
20732
|
+
spatialFilter,
|
|
20733
|
+
othersThreshold,
|
|
20734
|
+
orderBy = "frequency_desc",
|
|
20735
|
+
rawResult
|
|
20778
20736
|
}) {
|
|
20779
20737
|
const filteredFeatures = this._getFilteredFeatures(
|
|
20780
20738
|
spatialFilter,
|
|
@@ -20785,14 +20743,25 @@
|
|
|
20785
20743
|
return [];
|
|
20786
20744
|
}
|
|
20787
20745
|
assertColumn(this._features, column, operationColumn);
|
|
20788
|
-
const
|
|
20746
|
+
const result = groupValuesByColumn({
|
|
20789
20747
|
data: filteredFeatures,
|
|
20790
20748
|
valuesColumns: normalizeColumns(operationColumn || column),
|
|
20791
20749
|
joinOperation,
|
|
20792
20750
|
keysColumn: column,
|
|
20793
|
-
operation: operation2
|
|
20751
|
+
operation: operation2,
|
|
20752
|
+
othersThreshold,
|
|
20753
|
+
orderBy
|
|
20794
20754
|
});
|
|
20795
|
-
|
|
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
|
+
];
|
|
20796
20765
|
}
|
|
20797
20766
|
async getScatter({
|
|
20798
20767
|
xAxisColumn,
|
|
@@ -20925,6 +20894,7 @@
|
|
|
20925
20894
|
* INTERNAL
|
|
20926
20895
|
*/
|
|
20927
20896
|
_getFilteredFeatures(spatialFilter, filters, filterOwner) {
|
|
20897
|
+
assert(spatialFilter, "spatialFilter required for tilesets");
|
|
20928
20898
|
this._extractTileFeatures(spatialFilter);
|
|
20929
20899
|
return applyFilters(
|
|
20930
20900
|
this._features,
|
|
@@ -20948,11 +20918,6 @@
|
|
|
20948
20918
|
function normalizeColumns(columns) {
|
|
20949
20919
|
return Array.isArray(columns) ? columns : typeof columns === "string" ? [columns] : [];
|
|
20950
20920
|
}
|
|
20951
|
-
function spatialFilterEquals(a, b) {
|
|
20952
|
-
if (a === b) return true;
|
|
20953
|
-
if (!a || !b) return false;
|
|
20954
|
-
return booleanEqual(a, b);
|
|
20955
|
-
}
|
|
20956
20921
|
|
|
20957
20922
|
// src/workers/widget-tileset-worker.ts
|
|
20958
20923
|
var source;
|