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