@carto/api-client 0.5.6 → 0.5.7-alpha-optional-spatial-filter.0
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 +462 -345
- package/build/api-client.cjs.map +1 -1
- package/build/api-client.d.cts +23 -5
- package/build/api-client.d.ts +23 -5
- package/build/api-client.js +426 -309
- package/build/api-client.js.map +1 -1
- package/build/worker-compat.js +4214 -2963
- package/build/worker-compat.js.map +1 -1
- package/build/worker.js +395 -335
- package/build/worker.js.map +1 -1
- package/package.json +2 -2
- package/src/filters/tileFeatures.ts +1 -1
- package/src/filters/tileFeaturesGeometries.ts +28 -55
- package/src/filters/tileFeaturesRaster.ts +16 -12
- package/src/filters/tileFeaturesSpatialIndex.ts +37 -52
- package/src/filters/tileIntersection.ts +158 -0
- package/src/index.ts +1 -0
- package/src/utils/CellSet.ts +90 -0
- package/src/widget-sources/widget-tileset-source-impl.ts +8 -4
package/build/api-client.js
CHANGED
|
@@ -1558,6 +1558,110 @@ function geojsonFeatures({
|
|
|
1558
1558
|
return Array.from(map.values());
|
|
1559
1559
|
}
|
|
1560
1560
|
|
|
1561
|
+
// node_modules/@math.gl/core/dist/lib/common.js
|
|
1562
|
+
var RADIANS_TO_DEGREES = 1 / Math.PI * 180;
|
|
1563
|
+
var DEGREES_TO_RADIANS = 1 / 180 * Math.PI;
|
|
1564
|
+
var DEFAULT_CONFIG = {
|
|
1565
|
+
EPSILON: 1e-12,
|
|
1566
|
+
debug: false,
|
|
1567
|
+
precision: 4,
|
|
1568
|
+
printTypes: false,
|
|
1569
|
+
printDegrees: false,
|
|
1570
|
+
printRowMajor: true,
|
|
1571
|
+
_cartographicRadians: false
|
|
1572
|
+
};
|
|
1573
|
+
globalThis.mathgl = globalThis.mathgl || { config: { ...DEFAULT_CONFIG } };
|
|
1574
|
+
var config = globalThis.mathgl.config;
|
|
1575
|
+
function isArray(value) {
|
|
1576
|
+
return Array.isArray(value) || ArrayBuffer.isView(value) && !(value instanceof DataView);
|
|
1577
|
+
}
|
|
1578
|
+
function lerp(a, b, t) {
|
|
1579
|
+
if (isArray(a)) {
|
|
1580
|
+
return a.map((ai, i) => lerp(ai, b[i], t));
|
|
1581
|
+
}
|
|
1582
|
+
return t * b + (1 - t) * a;
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1585
|
+
// node_modules/@math.gl/web-mercator/dist/assert.js
|
|
1586
|
+
function assert(condition, message) {
|
|
1587
|
+
if (!condition) {
|
|
1588
|
+
throw new Error(message || "@math.gl/web-mercator: assertion failed.");
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
|
|
1592
|
+
// node_modules/@math.gl/web-mercator/dist/web-mercator-utils.js
|
|
1593
|
+
var PI = Math.PI;
|
|
1594
|
+
var PI_4 = PI / 4;
|
|
1595
|
+
var DEGREES_TO_RADIANS2 = PI / 180;
|
|
1596
|
+
var RADIANS_TO_DEGREES2 = 180 / PI;
|
|
1597
|
+
var TILE_SIZE = 512;
|
|
1598
|
+
function lngLatToWorld(lngLat) {
|
|
1599
|
+
const [lng, lat] = lngLat;
|
|
1600
|
+
assert(Number.isFinite(lng));
|
|
1601
|
+
assert(Number.isFinite(lat) && lat >= -90 && lat <= 90, "invalid latitude");
|
|
1602
|
+
const lambda2 = lng * DEGREES_TO_RADIANS2;
|
|
1603
|
+
const phi2 = lat * DEGREES_TO_RADIANS2;
|
|
1604
|
+
const x = TILE_SIZE * (lambda2 + PI) / (2 * PI);
|
|
1605
|
+
const y = TILE_SIZE * (PI + Math.log(Math.tan(PI_4 + phi2 * 0.5))) / (2 * PI);
|
|
1606
|
+
return [x, y];
|
|
1607
|
+
}
|
|
1608
|
+
function worldToLngLat(xy) {
|
|
1609
|
+
const [x, y] = xy;
|
|
1610
|
+
const lambda2 = x / TILE_SIZE * (2 * PI) - PI;
|
|
1611
|
+
const phi2 = 2 * (Math.atan(Math.exp(y / TILE_SIZE * (2 * PI) - PI)) - PI_4);
|
|
1612
|
+
return [lambda2 * RADIANS_TO_DEGREES2, phi2 * RADIANS_TO_DEGREES2];
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1615
|
+
// node_modules/@math.gl/web-mercator/dist/get-bounds.js
|
|
1616
|
+
var DEGREES_TO_RADIANS3 = Math.PI / 180;
|
|
1617
|
+
|
|
1618
|
+
// src/utils/transformTileCoordsToWGS84.ts
|
|
1619
|
+
var TRANSFORM_FN = {
|
|
1620
|
+
Point: transformPoint,
|
|
1621
|
+
MultiPoint: transformMultiPoint,
|
|
1622
|
+
LineString: transformLineString,
|
|
1623
|
+
MultiLineString: transformMultiLineString,
|
|
1624
|
+
Polygon: transformPolygon,
|
|
1625
|
+
MultiPolygon: transformMultiPolygon
|
|
1626
|
+
};
|
|
1627
|
+
function transformTileCoordsToWGS84(geometry, bbox2) {
|
|
1628
|
+
const [west, south, east, north] = bbox2;
|
|
1629
|
+
const nw = lngLatToWorld([west, north]);
|
|
1630
|
+
const se = lngLatToWorld([east, south]);
|
|
1631
|
+
const projectedBbox = [nw, se];
|
|
1632
|
+
if (geometry.type === "GeometryCollection") {
|
|
1633
|
+
throw new Error("Unsupported geometry type GeometryCollection");
|
|
1634
|
+
}
|
|
1635
|
+
const transformFn = TRANSFORM_FN[geometry.type];
|
|
1636
|
+
const coordinates = transformFn(geometry.coordinates, projectedBbox);
|
|
1637
|
+
return { ...geometry, coordinates };
|
|
1638
|
+
}
|
|
1639
|
+
function transformPoint([pointX, pointY], [nw, se]) {
|
|
1640
|
+
const x = lerp(nw[0], se[0], pointX);
|
|
1641
|
+
const y = lerp(nw[1], se[1], pointY);
|
|
1642
|
+
return worldToLngLat([x, y]);
|
|
1643
|
+
}
|
|
1644
|
+
function getPoints(geometry, bbox2) {
|
|
1645
|
+
return geometry.map((g) => transformPoint(g, bbox2));
|
|
1646
|
+
}
|
|
1647
|
+
function transformMultiPoint(multiPoint, bbox2) {
|
|
1648
|
+
return getPoints(multiPoint, bbox2);
|
|
1649
|
+
}
|
|
1650
|
+
function transformLineString(line, bbox2) {
|
|
1651
|
+
return getPoints(line, bbox2);
|
|
1652
|
+
}
|
|
1653
|
+
function transformMultiLineString(multiLineString2, bbox2) {
|
|
1654
|
+
return multiLineString2.map(
|
|
1655
|
+
(lineString2) => transformLineString(lineString2, bbox2)
|
|
1656
|
+
);
|
|
1657
|
+
}
|
|
1658
|
+
function transformPolygon(polygon2, bbox2) {
|
|
1659
|
+
return polygon2.map((polygonRing) => getPoints(polygonRing, bbox2));
|
|
1660
|
+
}
|
|
1661
|
+
function transformMultiPolygon(multiPolygon2, bbox2) {
|
|
1662
|
+
return multiPolygon2.map((polygon2) => transformPolygon(polygon2, bbox2));
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1561
1665
|
// node_modules/@turf/bbox-polygon/dist/esm/index.js
|
|
1562
1666
|
function bboxPolygon(bbox2, options = {}) {
|
|
1563
1667
|
const west = Number(bbox2[0]);
|
|
@@ -1876,7 +1980,7 @@ var MAX_SAFE_INTEGER = 9007199254740991;
|
|
|
1876
1980
|
var POWS_TEN = [1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13];
|
|
1877
1981
|
var SQRT_BASE = 1e7;
|
|
1878
1982
|
var MAX = 1e9;
|
|
1879
|
-
function
|
|
1983
|
+
function clone2(configObject) {
|
|
1880
1984
|
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 = {
|
|
1881
1985
|
prefix: "",
|
|
1882
1986
|
groupSize: 3,
|
|
@@ -2002,7 +2106,7 @@ function clone(configObject) {
|
|
|
2002
2106
|
x.c = [x.e = 0];
|
|
2003
2107
|
}
|
|
2004
2108
|
}
|
|
2005
|
-
BigNumber2.clone =
|
|
2109
|
+
BigNumber2.clone = clone2;
|
|
2006
2110
|
BigNumber2.ROUND_UP = 0;
|
|
2007
2111
|
BigNumber2.ROUND_DOWN = 1;
|
|
2008
2112
|
BigNumber2.ROUND_CEIL = 2;
|
|
@@ -3205,7 +3309,7 @@ function toFixedPoint(str, e, z) {
|
|
|
3205
3309
|
}
|
|
3206
3310
|
return str;
|
|
3207
3311
|
}
|
|
3208
|
-
var BigNumber =
|
|
3312
|
+
var BigNumber = clone2();
|
|
3209
3313
|
var bignumber_default = BigNumber;
|
|
3210
3314
|
|
|
3211
3315
|
// node_modules/splaytree-ts/dist/esm/index.js
|
|
@@ -4775,71 +4879,14 @@ function intersect(features, options = {}) {
|
|
|
4775
4879
|
}
|
|
4776
4880
|
var turf_intersect_default = intersect;
|
|
4777
4881
|
|
|
4778
|
-
// node_modules/@math.gl/core/dist/lib/common.js
|
|
4779
|
-
var RADIANS_TO_DEGREES = 1 / Math.PI * 180;
|
|
4780
|
-
var DEGREES_TO_RADIANS = 1 / 180 * Math.PI;
|
|
4781
|
-
var DEFAULT_CONFIG = {
|
|
4782
|
-
EPSILON: 1e-12,
|
|
4783
|
-
debug: false,
|
|
4784
|
-
precision: 4,
|
|
4785
|
-
printTypes: false,
|
|
4786
|
-
printDegrees: false,
|
|
4787
|
-
printRowMajor: true,
|
|
4788
|
-
_cartographicRadians: false
|
|
4789
|
-
};
|
|
4790
|
-
globalThis.mathgl = globalThis.mathgl || { config: { ...DEFAULT_CONFIG } };
|
|
4791
|
-
var config = globalThis.mathgl.config;
|
|
4792
|
-
function isArray(value) {
|
|
4793
|
-
return Array.isArray(value) || ArrayBuffer.isView(value) && !(value instanceof DataView);
|
|
4794
|
-
}
|
|
4795
|
-
function lerp(a, b, t) {
|
|
4796
|
-
if (isArray(a)) {
|
|
4797
|
-
return a.map((ai, i) => lerp(ai, b[i], t));
|
|
4798
|
-
}
|
|
4799
|
-
return t * b + (1 - t) * a;
|
|
4800
|
-
}
|
|
4801
|
-
|
|
4802
|
-
// node_modules/@math.gl/web-mercator/dist/assert.js
|
|
4803
|
-
function assert(condition, message) {
|
|
4804
|
-
if (!condition) {
|
|
4805
|
-
throw new Error(message || "@math.gl/web-mercator: assertion failed.");
|
|
4806
|
-
}
|
|
4807
|
-
}
|
|
4808
|
-
|
|
4809
|
-
// node_modules/@math.gl/web-mercator/dist/web-mercator-utils.js
|
|
4810
|
-
var PI = Math.PI;
|
|
4811
|
-
var PI_4 = PI / 4;
|
|
4812
|
-
var DEGREES_TO_RADIANS2 = PI / 180;
|
|
4813
|
-
var RADIANS_TO_DEGREES2 = 180 / PI;
|
|
4814
|
-
var TILE_SIZE = 512;
|
|
4815
|
-
function lngLatToWorld(lngLat) {
|
|
4816
|
-
const [lng, lat] = lngLat;
|
|
4817
|
-
assert(Number.isFinite(lng));
|
|
4818
|
-
assert(Number.isFinite(lat) && lat >= -90 && lat <= 90, "invalid latitude");
|
|
4819
|
-
const lambda2 = lng * DEGREES_TO_RADIANS2;
|
|
4820
|
-
const phi2 = lat * DEGREES_TO_RADIANS2;
|
|
4821
|
-
const x = TILE_SIZE * (lambda2 + PI) / (2 * PI);
|
|
4822
|
-
const y = TILE_SIZE * (PI + Math.log(Math.tan(PI_4 + phi2 * 0.5))) / (2 * PI);
|
|
4823
|
-
return [x, y];
|
|
4824
|
-
}
|
|
4825
|
-
function worldToLngLat(xy) {
|
|
4826
|
-
const [x, y] = xy;
|
|
4827
|
-
const lambda2 = x / TILE_SIZE * (2 * PI) - PI;
|
|
4828
|
-
const phi2 = 2 * (Math.atan(Math.exp(y / TILE_SIZE * (2 * PI) - PI)) - PI_4);
|
|
4829
|
-
return [lambda2 * RADIANS_TO_DEGREES2, phi2 * RADIANS_TO_DEGREES2];
|
|
4830
|
-
}
|
|
4831
|
-
|
|
4832
|
-
// node_modules/@math.gl/web-mercator/dist/get-bounds.js
|
|
4833
|
-
var DEGREES_TO_RADIANS3 = Math.PI / 180;
|
|
4834
|
-
|
|
4835
4882
|
// src/utils/transformToTileCoords.ts
|
|
4836
|
-
var
|
|
4837
|
-
Point:
|
|
4838
|
-
MultiPoint:
|
|
4839
|
-
LineString:
|
|
4840
|
-
MultiLineString:
|
|
4841
|
-
Polygon:
|
|
4842
|
-
MultiPolygon:
|
|
4883
|
+
var TRANSFORM_FN2 = {
|
|
4884
|
+
Point: transformPoint2,
|
|
4885
|
+
MultiPoint: transformMultiPoint2,
|
|
4886
|
+
LineString: transformLineString2,
|
|
4887
|
+
MultiLineString: transformMultiLineString2,
|
|
4888
|
+
Polygon: transformPolygon2,
|
|
4889
|
+
MultiPolygon: transformMultiPolygon2
|
|
4843
4890
|
};
|
|
4844
4891
|
function transformToTileCoords(geometry, bbox2) {
|
|
4845
4892
|
const [west, south, east, north] = bbox2;
|
|
@@ -4849,34 +4896,34 @@ function transformToTileCoords(geometry, bbox2) {
|
|
|
4849
4896
|
if (geometry.type === "GeometryCollection") {
|
|
4850
4897
|
throw new Error("Unsupported geometry type GeometryCollection");
|
|
4851
4898
|
}
|
|
4852
|
-
const transformFn =
|
|
4899
|
+
const transformFn = TRANSFORM_FN2[geometry.type];
|
|
4853
4900
|
const coordinates = transformFn(geometry.coordinates, projectedBbox);
|
|
4854
4901
|
return { ...geometry, coordinates };
|
|
4855
4902
|
}
|
|
4856
|
-
function
|
|
4903
|
+
function transformPoint2([pointX, pointY], [nw, se]) {
|
|
4857
4904
|
const x = inverseLerp(nw[0], se[0], pointX);
|
|
4858
4905
|
const y = inverseLerp(nw[1], se[1], pointY);
|
|
4859
4906
|
return [x, y];
|
|
4860
4907
|
}
|
|
4861
|
-
function
|
|
4862
|
-
return geometry.map((g) =>
|
|
4908
|
+
function getPoints2(geometry, bbox2) {
|
|
4909
|
+
return geometry.map((g) => transformPoint2(projectFlat(g), bbox2));
|
|
4863
4910
|
}
|
|
4864
|
-
function
|
|
4865
|
-
return
|
|
4911
|
+
function transformMultiPoint2(multiPoint, bbox2) {
|
|
4912
|
+
return getPoints2(multiPoint, bbox2);
|
|
4866
4913
|
}
|
|
4867
|
-
function
|
|
4868
|
-
return
|
|
4914
|
+
function transformLineString2(line, bbox2) {
|
|
4915
|
+
return getPoints2(line, bbox2);
|
|
4869
4916
|
}
|
|
4870
|
-
function
|
|
4917
|
+
function transformMultiLineString2(multiLineString2, bbox2) {
|
|
4871
4918
|
return multiLineString2.map(
|
|
4872
|
-
(lineString2) =>
|
|
4919
|
+
(lineString2) => transformLineString2(lineString2, bbox2)
|
|
4873
4920
|
);
|
|
4874
4921
|
}
|
|
4875
|
-
function
|
|
4876
|
-
return polygon2.map((polygonRing) =>
|
|
4922
|
+
function transformPolygon2(polygon2, bbox2) {
|
|
4923
|
+
return polygon2.map((polygonRing) => getPoints2(polygonRing, bbox2));
|
|
4877
4924
|
}
|
|
4878
|
-
function
|
|
4879
|
-
return multiPolygon2.map((polygon2) =>
|
|
4925
|
+
function transformMultiPolygon2(multiPolygon2, bbox2) {
|
|
4926
|
+
return multiPolygon2.map((polygon2) => transformPolygon2(polygon2, bbox2));
|
|
4880
4927
|
}
|
|
4881
4928
|
function projectFlat(xyz) {
|
|
4882
4929
|
return lngLatToWorld(xyz);
|
|
@@ -4885,51 +4932,195 @@ function inverseLerp(a, b, x) {
|
|
|
4885
4932
|
return (x - a) / (b - a);
|
|
4886
4933
|
}
|
|
4887
4934
|
|
|
4888
|
-
// src/
|
|
4889
|
-
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
};
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
4900
|
-
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
|
|
4935
|
+
// src/filters/tileIntersection.ts
|
|
4936
|
+
import {
|
|
4937
|
+
cellToBoundary as quadbinCellToBoundary,
|
|
4938
|
+
geometryToCells as quadbinGeometryToCells
|
|
4939
|
+
} from "quadbin";
|
|
4940
|
+
import {
|
|
4941
|
+
cellToBoundary as h3CellToBoundary,
|
|
4942
|
+
polygonToCells as h3PolygonToCells
|
|
4943
|
+
} from "h3-js";
|
|
4944
|
+
|
|
4945
|
+
// node_modules/@turf/bbox-clip/dist/esm/index.js
|
|
4946
|
+
function lineclip(points, bbox2, result) {
|
|
4947
|
+
var len = points.length, codeA = bitCode(points[0], bbox2), part = [], i, codeB, lastCode;
|
|
4948
|
+
let a;
|
|
4949
|
+
let b;
|
|
4950
|
+
if (!result) result = [];
|
|
4951
|
+
for (i = 1; i < len; i++) {
|
|
4952
|
+
a = points[i - 1];
|
|
4953
|
+
b = points[i];
|
|
4954
|
+
codeB = lastCode = bitCode(b, bbox2);
|
|
4955
|
+
while (true) {
|
|
4956
|
+
if (!(codeA | codeB)) {
|
|
4957
|
+
part.push(a);
|
|
4958
|
+
if (codeB !== lastCode) {
|
|
4959
|
+
part.push(b);
|
|
4960
|
+
if (i < len - 1) {
|
|
4961
|
+
result.push(part);
|
|
4962
|
+
part = [];
|
|
4963
|
+
}
|
|
4964
|
+
} else if (i === len - 1) {
|
|
4965
|
+
part.push(b);
|
|
4966
|
+
}
|
|
4967
|
+
break;
|
|
4968
|
+
} else if (codeA & codeB) {
|
|
4969
|
+
break;
|
|
4970
|
+
} else if (codeA) {
|
|
4971
|
+
a = intersect2(a, b, codeA, bbox2);
|
|
4972
|
+
codeA = bitCode(a, bbox2);
|
|
4973
|
+
} else {
|
|
4974
|
+
b = intersect2(a, b, codeB, bbox2);
|
|
4975
|
+
codeB = bitCode(b, bbox2);
|
|
4976
|
+
}
|
|
4977
|
+
}
|
|
4978
|
+
codeA = lastCode;
|
|
4979
|
+
}
|
|
4980
|
+
if (part.length) result.push(part);
|
|
4981
|
+
return result;
|
|
4982
|
+
}
|
|
4983
|
+
function polygonclip(points, bbox2) {
|
|
4984
|
+
var result, edge, prev, prevInside, i, p, inside;
|
|
4985
|
+
for (edge = 1; edge <= 8; edge *= 2) {
|
|
4986
|
+
result = [];
|
|
4987
|
+
prev = points[points.length - 1];
|
|
4988
|
+
prevInside = !(bitCode(prev, bbox2) & edge);
|
|
4989
|
+
for (i = 0; i < points.length; i++) {
|
|
4990
|
+
p = points[i];
|
|
4991
|
+
inside = !(bitCode(p, bbox2) & edge);
|
|
4992
|
+
if (inside !== prevInside) result.push(intersect2(prev, p, edge, bbox2));
|
|
4993
|
+
if (inside) result.push(p);
|
|
4994
|
+
prev = p;
|
|
4995
|
+
prevInside = inside;
|
|
4996
|
+
}
|
|
4997
|
+
points = result;
|
|
4998
|
+
if (!points.length) break;
|
|
4904
4999
|
}
|
|
4905
|
-
|
|
4906
|
-
const coordinates = transformFn(geometry.coordinates, projectedBbox);
|
|
4907
|
-
return { ...geometry, coordinates };
|
|
5000
|
+
return result;
|
|
4908
5001
|
}
|
|
4909
|
-
function
|
|
4910
|
-
|
|
4911
|
-
const y = lerp(nw[1], se[1], pointY);
|
|
4912
|
-
return worldToLngLat([x, y]);
|
|
5002
|
+
function intersect2(a, b, edge, bbox2) {
|
|
5003
|
+
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;
|
|
4913
5004
|
}
|
|
4914
|
-
function
|
|
4915
|
-
|
|
5005
|
+
function bitCode(p, bbox2) {
|
|
5006
|
+
var code = 0;
|
|
5007
|
+
if (p[0] < bbox2[0]) code |= 1;
|
|
5008
|
+
else if (p[0] > bbox2[2]) code |= 2;
|
|
5009
|
+
if (p[1] < bbox2[1]) code |= 4;
|
|
5010
|
+
else if (p[1] > bbox2[3]) code |= 8;
|
|
5011
|
+
return code;
|
|
4916
5012
|
}
|
|
4917
|
-
function
|
|
4918
|
-
|
|
5013
|
+
function bboxClip(feature2, bbox2) {
|
|
5014
|
+
const geom = getGeom(feature2);
|
|
5015
|
+
const type = geom.type;
|
|
5016
|
+
const properties = feature2.type === "Feature" ? feature2.properties : {};
|
|
5017
|
+
let coords = geom.coordinates;
|
|
5018
|
+
switch (type) {
|
|
5019
|
+
case "LineString":
|
|
5020
|
+
case "MultiLineString": {
|
|
5021
|
+
const lines = [];
|
|
5022
|
+
if (type === "LineString") {
|
|
5023
|
+
coords = [coords];
|
|
5024
|
+
}
|
|
5025
|
+
coords.forEach((line) => {
|
|
5026
|
+
lineclip(line, bbox2, lines);
|
|
5027
|
+
});
|
|
5028
|
+
if (lines.length === 1) {
|
|
5029
|
+
return lineString(lines[0], properties);
|
|
5030
|
+
}
|
|
5031
|
+
return multiLineString(lines, properties);
|
|
5032
|
+
}
|
|
5033
|
+
case "Polygon":
|
|
5034
|
+
return polygon(clipPolygon(coords, bbox2), properties);
|
|
5035
|
+
case "MultiPolygon":
|
|
5036
|
+
return multiPolygon(
|
|
5037
|
+
coords.map((poly) => {
|
|
5038
|
+
return clipPolygon(poly, bbox2);
|
|
5039
|
+
}),
|
|
5040
|
+
properties
|
|
5041
|
+
);
|
|
5042
|
+
default:
|
|
5043
|
+
throw new Error("geometry " + type + " not supported");
|
|
5044
|
+
}
|
|
4919
5045
|
}
|
|
4920
|
-
function
|
|
4921
|
-
|
|
5046
|
+
function clipPolygon(rings, bbox2) {
|
|
5047
|
+
const outRings = [];
|
|
5048
|
+
for (const ring of rings) {
|
|
5049
|
+
const clipped = polygonclip(ring, bbox2);
|
|
5050
|
+
if (clipped.length > 0) {
|
|
5051
|
+
if (clipped[0][0] !== clipped[clipped.length - 1][0] || clipped[0][1] !== clipped[clipped.length - 1][1]) {
|
|
5052
|
+
clipped.push(clipped[0]);
|
|
5053
|
+
}
|
|
5054
|
+
if (clipped.length >= 4) {
|
|
5055
|
+
outRings.push(clipped);
|
|
5056
|
+
}
|
|
5057
|
+
}
|
|
5058
|
+
}
|
|
5059
|
+
return outRings;
|
|
4922
5060
|
}
|
|
4923
|
-
|
|
4924
|
-
|
|
4925
|
-
|
|
5061
|
+
var turf_bbox_clip_default = bboxClip;
|
|
5062
|
+
|
|
5063
|
+
// src/filters/tileIntersection.ts
|
|
5064
|
+
function intersectTileGeometry(tileBbox, tileFormat, spatialFilter) {
|
|
5065
|
+
const tilePolygon = turf_bbox_polygon_default(tileBbox);
|
|
5066
|
+
if (!spatialFilter || turf_boolean_within_default(tilePolygon, spatialFilter)) {
|
|
5067
|
+
return true;
|
|
5068
|
+
}
|
|
5069
|
+
const clippedSpatialFilter = turf_intersect_default(
|
|
5070
|
+
featureCollection([tilePolygon, feature(spatialFilter)])
|
|
4926
5071
|
);
|
|
5072
|
+
if (!clippedSpatialFilter) {
|
|
5073
|
+
return false;
|
|
5074
|
+
}
|
|
5075
|
+
return tileFormat === "mvt" /* MVT */ ? transformToTileCoords(clippedSpatialFilter.geometry, tileBbox) : clippedSpatialFilter.geometry;
|
|
4927
5076
|
}
|
|
4928
|
-
function
|
|
4929
|
-
return
|
|
5077
|
+
function intersectTileRaster(parent, cellResolution, spatialFilter) {
|
|
5078
|
+
return intersectTileQuadbin(parent, cellResolution, spatialFilter);
|
|
4930
5079
|
}
|
|
4931
|
-
function
|
|
4932
|
-
|
|
5080
|
+
function intersectTileQuadbin(parent, cellResolution, spatialFilter) {
|
|
5081
|
+
const tilePolygon = quadbinCellToBoundary(parent);
|
|
5082
|
+
if (!spatialFilter || turf_boolean_within_default(tilePolygon, spatialFilter)) {
|
|
5083
|
+
return true;
|
|
5084
|
+
}
|
|
5085
|
+
const clippedSpatialFilter = turf_intersect_default(
|
|
5086
|
+
featureCollection([feature(tilePolygon), feature(spatialFilter)])
|
|
5087
|
+
);
|
|
5088
|
+
if (!clippedSpatialFilter) {
|
|
5089
|
+
return false;
|
|
5090
|
+
}
|
|
5091
|
+
const cells = quadbinGeometryToCells(
|
|
5092
|
+
clippedSpatialFilter.geometry,
|
|
5093
|
+
cellResolution
|
|
5094
|
+
);
|
|
5095
|
+
return new Set(cells);
|
|
5096
|
+
}
|
|
5097
|
+
var BBOX_WEST = [-180, -90, 0, 90];
|
|
5098
|
+
var BBOX_EAST = [0, -90, 180, 90];
|
|
5099
|
+
function intersectTileH3(parent, cellResolution, spatialFilter) {
|
|
5100
|
+
const tilePolygon = {
|
|
5101
|
+
type: "Polygon",
|
|
5102
|
+
coordinates: [h3CellToBoundary(parent, true)]
|
|
5103
|
+
};
|
|
5104
|
+
if (!spatialFilter || turf_boolean_within_default(tilePolygon, spatialFilter)) {
|
|
5105
|
+
return true;
|
|
5106
|
+
}
|
|
5107
|
+
const clippedSpatialFilter = turf_intersect_default(
|
|
5108
|
+
featureCollection([feature(tilePolygon), feature(spatialFilter)])
|
|
5109
|
+
);
|
|
5110
|
+
if (!clippedSpatialFilter) {
|
|
5111
|
+
return false;
|
|
5112
|
+
}
|
|
5113
|
+
const cellsWest = h3PolygonToCells(
|
|
5114
|
+
turf_bbox_clip_default(clippedSpatialFilter, BBOX_WEST).geometry.coordinates,
|
|
5115
|
+
cellResolution,
|
|
5116
|
+
true
|
|
5117
|
+
);
|
|
5118
|
+
const cellsEast = h3PolygonToCells(
|
|
5119
|
+
turf_bbox_clip_default(clippedSpatialFilter, BBOX_EAST).geometry.coordinates,
|
|
5120
|
+
cellResolution,
|
|
5121
|
+
true
|
|
5122
|
+
);
|
|
5123
|
+
return new Set(cellsWest.concat(cellsEast));
|
|
4933
5124
|
}
|
|
4934
5125
|
|
|
4935
5126
|
// src/filters/tileFeaturesGeometries.ts
|
|
@@ -4946,55 +5137,45 @@ function tileFeaturesGeometries({
|
|
|
4946
5137
|
if (tile.isVisible === false || !tile.data) {
|
|
4947
5138
|
continue;
|
|
4948
5139
|
}
|
|
4949
|
-
const
|
|
5140
|
+
const tileBbox = [
|
|
4950
5141
|
tile.bbox.west,
|
|
4951
5142
|
tile.bbox.south,
|
|
4952
5143
|
tile.bbox.east,
|
|
4953
5144
|
tile.bbox.north
|
|
4954
5145
|
];
|
|
4955
|
-
const
|
|
4956
|
-
|
|
4957
|
-
|
|
4958
|
-
|
|
4959
|
-
geometry: spatialFilter,
|
|
4960
|
-
properties: {}
|
|
4961
|
-
};
|
|
4962
|
-
const clippedGeometryToIntersect = turf_intersect_default(
|
|
4963
|
-
featureCollection([bboxToGeom, spatialFilterFeature])
|
|
5146
|
+
const intersection3 = intersectTileGeometry(
|
|
5147
|
+
tileBbox,
|
|
5148
|
+
tileFormat,
|
|
5149
|
+
spatialFilter
|
|
4964
5150
|
);
|
|
4965
|
-
if (
|
|
4966
|
-
|
|
4967
|
-
}
|
|
4968
|
-
const transformedGeometryToIntersect = tileFormat === "mvt" /* MVT */ ? transformToTileCoords(clippedGeometryToIntersect.geometry, bbox2) : clippedGeometryToIntersect.geometry;
|
|
5151
|
+
if (intersection3 === false) continue;
|
|
5152
|
+
const transformedSpatialFilter = intersection3 === true ? void 0 : intersection3;
|
|
4969
5153
|
calculateFeatures({
|
|
4970
5154
|
map,
|
|
4971
|
-
|
|
4972
|
-
geometryIntersection: transformedGeometryToIntersect,
|
|
5155
|
+
spatialFilter: transformedSpatialFilter,
|
|
4973
5156
|
data: tile.data.points,
|
|
4974
5157
|
type: "Point",
|
|
4975
|
-
bbox:
|
|
5158
|
+
bbox: tileBbox,
|
|
4976
5159
|
tileFormat,
|
|
4977
5160
|
uniqueIdProperty,
|
|
4978
5161
|
options
|
|
4979
5162
|
});
|
|
4980
5163
|
calculateFeatures({
|
|
4981
5164
|
map,
|
|
4982
|
-
|
|
4983
|
-
geometryIntersection: transformedGeometryToIntersect,
|
|
5165
|
+
spatialFilter: transformedSpatialFilter,
|
|
4984
5166
|
data: tile.data.lines,
|
|
4985
5167
|
type: "LineString",
|
|
4986
|
-
bbox:
|
|
5168
|
+
bbox: tileBbox,
|
|
4987
5169
|
tileFormat,
|
|
4988
5170
|
uniqueIdProperty,
|
|
4989
5171
|
options
|
|
4990
5172
|
});
|
|
4991
5173
|
calculateFeatures({
|
|
4992
5174
|
map,
|
|
4993
|
-
|
|
4994
|
-
geometryIntersection: transformedGeometryToIntersect,
|
|
5175
|
+
spatialFilter: transformedSpatialFilter,
|
|
4995
5176
|
data: tile.data.polygons,
|
|
4996
5177
|
type: "Polygon",
|
|
4997
|
-
bbox:
|
|
5178
|
+
bbox: tileBbox,
|
|
4998
5179
|
tileFormat,
|
|
4999
5180
|
uniqueIdProperty,
|
|
5000
5181
|
options
|
|
@@ -5012,7 +5193,7 @@ function processTileFeatureProperties({
|
|
|
5012
5193
|
tileFormat,
|
|
5013
5194
|
uniqueIdProperty,
|
|
5014
5195
|
storeGeometry,
|
|
5015
|
-
|
|
5196
|
+
spatialFilter
|
|
5016
5197
|
}) {
|
|
5017
5198
|
const tileProps = getPropertiesFromTile(data, startIndex);
|
|
5018
5199
|
const uniquePropertyValue = getUniquePropertyValue(
|
|
@@ -5024,7 +5205,7 @@ function processTileFeatureProperties({
|
|
|
5024
5205
|
return;
|
|
5025
5206
|
}
|
|
5026
5207
|
let geometry = null;
|
|
5027
|
-
if (storeGeometry ||
|
|
5208
|
+
if (storeGeometry || spatialFilter) {
|
|
5028
5209
|
const { positions } = data;
|
|
5029
5210
|
const ringCoordinates = getRingCoordinatesFor(
|
|
5030
5211
|
startIndex,
|
|
@@ -5033,7 +5214,7 @@ function processTileFeatureProperties({
|
|
|
5033
5214
|
);
|
|
5034
5215
|
geometry = getFeatureByType(ringCoordinates, type);
|
|
5035
5216
|
}
|
|
5036
|
-
if (geometry &&
|
|
5217
|
+
if (geometry && spatialFilter && !turf_boolean_intersects_default(geometry, spatialFilter)) {
|
|
5037
5218
|
return;
|
|
5038
5219
|
}
|
|
5039
5220
|
const properties = parseProperties(tileProps);
|
|
@@ -5045,7 +5226,7 @@ function processTileFeatureProperties({
|
|
|
5045
5226
|
function addIntersectedFeaturesInTile({
|
|
5046
5227
|
map,
|
|
5047
5228
|
data,
|
|
5048
|
-
|
|
5229
|
+
spatialFilter,
|
|
5049
5230
|
type,
|
|
5050
5231
|
bbox: bbox2,
|
|
5051
5232
|
tileFormat,
|
|
@@ -5067,7 +5248,7 @@ function addIntersectedFeaturesInTile({
|
|
|
5067
5248
|
tileFormat,
|
|
5068
5249
|
uniqueIdProperty,
|
|
5069
5250
|
storeGeometry,
|
|
5070
|
-
|
|
5251
|
+
spatialFilter
|
|
5071
5252
|
});
|
|
5072
5253
|
}
|
|
5073
5254
|
}
|
|
@@ -5149,8 +5330,7 @@ function getRingCoordinatesFor(startIndex, endIndex, positions) {
|
|
|
5149
5330
|
}
|
|
5150
5331
|
function calculateFeatures({
|
|
5151
5332
|
map,
|
|
5152
|
-
|
|
5153
|
-
geometryIntersection,
|
|
5333
|
+
spatialFilter,
|
|
5154
5334
|
data,
|
|
5155
5335
|
type,
|
|
5156
5336
|
bbox: bbox2,
|
|
@@ -5161,7 +5341,7 @@ function calculateFeatures({
|
|
|
5161
5341
|
if (!data?.properties.length) {
|
|
5162
5342
|
return;
|
|
5163
5343
|
}
|
|
5164
|
-
if (
|
|
5344
|
+
if (!spatialFilter) {
|
|
5165
5345
|
addAllFeaturesInTile({
|
|
5166
5346
|
map,
|
|
5167
5347
|
data,
|
|
@@ -5175,7 +5355,7 @@ function calculateFeatures({
|
|
|
5175
5355
|
addIntersectedFeaturesInTile({
|
|
5176
5356
|
map,
|
|
5177
5357
|
data,
|
|
5178
|
-
|
|
5358
|
+
spatialFilter,
|
|
5179
5359
|
type,
|
|
5180
5360
|
bbox: bbox2,
|
|
5181
5361
|
tileFormat,
|
|
@@ -5225,128 +5405,8 @@ function createIndicesForPoints(data) {
|
|
|
5225
5405
|
}
|
|
5226
5406
|
|
|
5227
5407
|
// src/filters/tileFeaturesSpatialIndex.ts
|
|
5228
|
-
import { getResolution as quadbinGetResolution
|
|
5229
|
-
|
|
5230
|
-
// node_modules/@turf/bbox-clip/dist/esm/index.js
|
|
5231
|
-
function lineclip(points, bbox2, result) {
|
|
5232
|
-
var len = points.length, codeA = bitCode(points[0], bbox2), part = [], i, codeB, lastCode;
|
|
5233
|
-
let a;
|
|
5234
|
-
let b;
|
|
5235
|
-
if (!result) result = [];
|
|
5236
|
-
for (i = 1; i < len; i++) {
|
|
5237
|
-
a = points[i - 1];
|
|
5238
|
-
b = points[i];
|
|
5239
|
-
codeB = lastCode = bitCode(b, bbox2);
|
|
5240
|
-
while (true) {
|
|
5241
|
-
if (!(codeA | codeB)) {
|
|
5242
|
-
part.push(a);
|
|
5243
|
-
if (codeB !== lastCode) {
|
|
5244
|
-
part.push(b);
|
|
5245
|
-
if (i < len - 1) {
|
|
5246
|
-
result.push(part);
|
|
5247
|
-
part = [];
|
|
5248
|
-
}
|
|
5249
|
-
} else if (i === len - 1) {
|
|
5250
|
-
part.push(b);
|
|
5251
|
-
}
|
|
5252
|
-
break;
|
|
5253
|
-
} else if (codeA & codeB) {
|
|
5254
|
-
break;
|
|
5255
|
-
} else if (codeA) {
|
|
5256
|
-
a = intersect2(a, b, codeA, bbox2);
|
|
5257
|
-
codeA = bitCode(a, bbox2);
|
|
5258
|
-
} else {
|
|
5259
|
-
b = intersect2(a, b, codeB, bbox2);
|
|
5260
|
-
codeB = bitCode(b, bbox2);
|
|
5261
|
-
}
|
|
5262
|
-
}
|
|
5263
|
-
codeA = lastCode;
|
|
5264
|
-
}
|
|
5265
|
-
if (part.length) result.push(part);
|
|
5266
|
-
return result;
|
|
5267
|
-
}
|
|
5268
|
-
function polygonclip(points, bbox2) {
|
|
5269
|
-
var result, edge, prev, prevInside, i, p, inside;
|
|
5270
|
-
for (edge = 1; edge <= 8; edge *= 2) {
|
|
5271
|
-
result = [];
|
|
5272
|
-
prev = points[points.length - 1];
|
|
5273
|
-
prevInside = !(bitCode(prev, bbox2) & edge);
|
|
5274
|
-
for (i = 0; i < points.length; i++) {
|
|
5275
|
-
p = points[i];
|
|
5276
|
-
inside = !(bitCode(p, bbox2) & edge);
|
|
5277
|
-
if (inside !== prevInside) result.push(intersect2(prev, p, edge, bbox2));
|
|
5278
|
-
if (inside) result.push(p);
|
|
5279
|
-
prev = p;
|
|
5280
|
-
prevInside = inside;
|
|
5281
|
-
}
|
|
5282
|
-
points = result;
|
|
5283
|
-
if (!points.length) break;
|
|
5284
|
-
}
|
|
5285
|
-
return result;
|
|
5286
|
-
}
|
|
5287
|
-
function intersect2(a, b, edge, bbox2) {
|
|
5288
|
-
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;
|
|
5289
|
-
}
|
|
5290
|
-
function bitCode(p, bbox2) {
|
|
5291
|
-
var code = 0;
|
|
5292
|
-
if (p[0] < bbox2[0]) code |= 1;
|
|
5293
|
-
else if (p[0] > bbox2[2]) code |= 2;
|
|
5294
|
-
if (p[1] < bbox2[1]) code |= 4;
|
|
5295
|
-
else if (p[1] > bbox2[3]) code |= 8;
|
|
5296
|
-
return code;
|
|
5297
|
-
}
|
|
5298
|
-
function bboxClip(feature2, bbox2) {
|
|
5299
|
-
const geom = getGeom(feature2);
|
|
5300
|
-
const type = geom.type;
|
|
5301
|
-
const properties = feature2.type === "Feature" ? feature2.properties : {};
|
|
5302
|
-
let coords = geom.coordinates;
|
|
5303
|
-
switch (type) {
|
|
5304
|
-
case "LineString":
|
|
5305
|
-
case "MultiLineString": {
|
|
5306
|
-
const lines = [];
|
|
5307
|
-
if (type === "LineString") {
|
|
5308
|
-
coords = [coords];
|
|
5309
|
-
}
|
|
5310
|
-
coords.forEach((line) => {
|
|
5311
|
-
lineclip(line, bbox2, lines);
|
|
5312
|
-
});
|
|
5313
|
-
if (lines.length === 1) {
|
|
5314
|
-
return lineString(lines[0], properties);
|
|
5315
|
-
}
|
|
5316
|
-
return multiLineString(lines, properties);
|
|
5317
|
-
}
|
|
5318
|
-
case "Polygon":
|
|
5319
|
-
return polygon(clipPolygon(coords, bbox2), properties);
|
|
5320
|
-
case "MultiPolygon":
|
|
5321
|
-
return multiPolygon(
|
|
5322
|
-
coords.map((poly) => {
|
|
5323
|
-
return clipPolygon(poly, bbox2);
|
|
5324
|
-
}),
|
|
5325
|
-
properties
|
|
5326
|
-
);
|
|
5327
|
-
default:
|
|
5328
|
-
throw new Error("geometry " + type + " not supported");
|
|
5329
|
-
}
|
|
5330
|
-
}
|
|
5331
|
-
function clipPolygon(rings, bbox2) {
|
|
5332
|
-
const outRings = [];
|
|
5333
|
-
for (const ring of rings) {
|
|
5334
|
-
const clipped = polygonclip(ring, bbox2);
|
|
5335
|
-
if (clipped.length > 0) {
|
|
5336
|
-
if (clipped[0][0] !== clipped[clipped.length - 1][0] || clipped[0][1] !== clipped[clipped.length - 1][1]) {
|
|
5337
|
-
clipped.push(clipped[0]);
|
|
5338
|
-
}
|
|
5339
|
-
if (clipped.length >= 4) {
|
|
5340
|
-
outRings.push(clipped);
|
|
5341
|
-
}
|
|
5342
|
-
}
|
|
5343
|
-
}
|
|
5344
|
-
return outRings;
|
|
5345
|
-
}
|
|
5346
|
-
var turf_bbox_clip_default = bboxClip;
|
|
5347
|
-
|
|
5348
|
-
// src/filters/tileFeaturesSpatialIndex.ts
|
|
5349
|
-
import { getResolution as h3GetResolution, polygonToCells } from "h3-js";
|
|
5408
|
+
import { getResolution as quadbinGetResolution } from "quadbin";
|
|
5409
|
+
import { getResolution as h3GetResolution } from "h3-js";
|
|
5350
5410
|
function tileFeaturesSpatialIndex({
|
|
5351
5411
|
tiles,
|
|
5352
5412
|
spatialFilter,
|
|
@@ -5355,28 +5415,40 @@ function tileFeaturesSpatialIndex({
|
|
|
5355
5415
|
}) {
|
|
5356
5416
|
const map = /* @__PURE__ */ new Map();
|
|
5357
5417
|
const spatialIndex = getSpatialIndex(spatialDataType);
|
|
5358
|
-
const
|
|
5418
|
+
const cellResolution = getResolution(tiles, spatialIndex);
|
|
5359
5419
|
const spatialIndexIDName = spatialDataColumn ? spatialDataColumn : spatialIndex;
|
|
5360
|
-
if (!
|
|
5420
|
+
if (!cellResolution) {
|
|
5361
5421
|
return [];
|
|
5362
5422
|
}
|
|
5363
|
-
const cells = getCellsCoverGeometry(spatialFilter, spatialIndex, resolution);
|
|
5364
|
-
if (!cells?.length) {
|
|
5365
|
-
return [];
|
|
5366
|
-
}
|
|
5367
|
-
const cellsSet = new Set(cells);
|
|
5368
5423
|
for (const tile of tiles) {
|
|
5369
5424
|
if (tile.isVisible === false || !tile.data) {
|
|
5370
5425
|
continue;
|
|
5371
5426
|
}
|
|
5427
|
+
const parent = getTileIndex(tile, spatialIndex);
|
|
5428
|
+
const intersection3 = spatialIndex === "quadbin" /* QUADBIN */ ? intersectTileQuadbin(
|
|
5429
|
+
parent,
|
|
5430
|
+
cellResolution,
|
|
5431
|
+
spatialFilter
|
|
5432
|
+
) : intersectTileH3(
|
|
5433
|
+
parent,
|
|
5434
|
+
cellResolution,
|
|
5435
|
+
spatialFilter
|
|
5436
|
+
);
|
|
5437
|
+
if (!intersection3) continue;
|
|
5372
5438
|
tile.data.forEach((d) => {
|
|
5373
|
-
if (
|
|
5439
|
+
if (intersection3 === true || intersection3.has(d.id)) {
|
|
5374
5440
|
map.set(d.id, { ...d.properties, [spatialIndexIDName]: d.id });
|
|
5375
5441
|
}
|
|
5376
5442
|
});
|
|
5377
5443
|
}
|
|
5378
5444
|
return Array.from(map.values());
|
|
5379
5445
|
}
|
|
5446
|
+
function getTileIndex(tile, spatialIndex) {
|
|
5447
|
+
if (spatialIndex === "quadbin" /* QUADBIN */) {
|
|
5448
|
+
return tile.index.q;
|
|
5449
|
+
}
|
|
5450
|
+
return tile.id;
|
|
5451
|
+
}
|
|
5380
5452
|
function getResolution(tiles, spatialIndex) {
|
|
5381
5453
|
const data = tiles.find((tile) => tile.data?.length)?.data;
|
|
5382
5454
|
if (!data) {
|
|
@@ -5389,26 +5461,6 @@ function getResolution(tiles, spatialIndex) {
|
|
|
5389
5461
|
return h3GetResolution(data[0].id);
|
|
5390
5462
|
}
|
|
5391
5463
|
}
|
|
5392
|
-
var bboxWest = [-180, -90, 0, 90];
|
|
5393
|
-
var bboxEast = [0, -90, 180, 90];
|
|
5394
|
-
function getCellsCoverGeometry(geometry, spatialIndex, resolution) {
|
|
5395
|
-
if (spatialIndex === "quadbin" /* QUADBIN */) {
|
|
5396
|
-
return geometryToCells(geometry, resolution);
|
|
5397
|
-
}
|
|
5398
|
-
if (spatialIndex === "h3" /* H3 */) {
|
|
5399
|
-
return polygonToCells(
|
|
5400
|
-
turf_bbox_clip_default(geometry, bboxWest).geometry.coordinates,
|
|
5401
|
-
resolution,
|
|
5402
|
-
true
|
|
5403
|
-
).concat(
|
|
5404
|
-
polygonToCells(
|
|
5405
|
-
turf_bbox_clip_default(geometry, bboxEast).geometry.coordinates,
|
|
5406
|
-
resolution,
|
|
5407
|
-
true
|
|
5408
|
-
)
|
|
5409
|
-
);
|
|
5410
|
-
}
|
|
5411
|
-
}
|
|
5412
5464
|
function getSpatialIndex(spatialDataType) {
|
|
5413
5465
|
switch (spatialDataType) {
|
|
5414
5466
|
case "h3":
|
|
@@ -5435,7 +5487,6 @@ var DEFAULT_AGGREGATION_EXP = `1 AS ${DEFAULT_AGGREGATION_EXP_ALIAS}`;
|
|
|
5435
5487
|
import {
|
|
5436
5488
|
cellToChildren as _cellToChildren,
|
|
5437
5489
|
cellToTile,
|
|
5438
|
-
geometryToCells as geometryToCells2,
|
|
5439
5490
|
getResolution as getResolution2
|
|
5440
5491
|
} from "quadbin";
|
|
5441
5492
|
function tileFeaturesRaster({
|
|
@@ -5451,15 +5502,20 @@ function tileFeaturesRaster({
|
|
|
5451
5502
|
const tileResolution = getResolution2(tiles[0].index.q);
|
|
5452
5503
|
const tileBlockSize = tiles[0].data.blockSize;
|
|
5453
5504
|
const cellResolution = tileResolution + BigInt(Math.log2(tileBlockSize));
|
|
5454
|
-
const spatialFilterCells = new Set(
|
|
5455
|
-
geometryToCells2(options.spatialFilter, cellResolution)
|
|
5456
|
-
);
|
|
5457
5505
|
const data = /* @__PURE__ */ new Map();
|
|
5458
5506
|
for (const tile of tiles) {
|
|
5459
5507
|
const parent = tile.index.q;
|
|
5460
|
-
const
|
|
5461
|
-
|
|
5462
|
-
|
|
5508
|
+
const intersection3 = intersectTileRaster(
|
|
5509
|
+
parent,
|
|
5510
|
+
cellResolution,
|
|
5511
|
+
options.spatialFilter
|
|
5512
|
+
);
|
|
5513
|
+
if (intersection3 === false) continue;
|
|
5514
|
+
const tileSortedCells = cellToChildrenSorted(parent, cellResolution);
|
|
5515
|
+
for (let i = 0; i < tileSortedCells.length; i++) {
|
|
5516
|
+
if (intersection3 !== true && !intersection3.has(tileSortedCells[i])) {
|
|
5517
|
+
continue;
|
|
5518
|
+
}
|
|
5463
5519
|
const cellData = {};
|
|
5464
5520
|
let cellDataExists = false;
|
|
5465
5521
|
for (const band in tile.data.cells.numericProps) {
|
|
@@ -5471,7 +5527,7 @@ function tileFeaturesRaster({
|
|
|
5471
5527
|
}
|
|
5472
5528
|
}
|
|
5473
5529
|
if (cellDataExists) {
|
|
5474
|
-
data.set(
|
|
5530
|
+
data.set(tileSortedCells[i], cellData);
|
|
5475
5531
|
}
|
|
5476
5532
|
}
|
|
5477
5533
|
}
|
|
@@ -7180,7 +7236,7 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
|
|
|
7180
7236
|
}
|
|
7181
7237
|
_extractTileFeatures(spatialFilter) {
|
|
7182
7238
|
const prevInputs = this._tileFeatureExtractPreviousInputs;
|
|
7183
|
-
if (this._features.length &&
|
|
7239
|
+
if (this._features.length && spatialFilterEquals(prevInputs.spatialFilter, spatialFilter)) {
|
|
7184
7240
|
return;
|
|
7185
7241
|
}
|
|
7186
7242
|
this._features = tileFeatures({
|
|
@@ -7420,7 +7476,6 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
|
|
|
7420
7476
|
* INTERNAL
|
|
7421
7477
|
*/
|
|
7422
7478
|
_getFilteredFeatures(spatialFilter, filters, filterOwner) {
|
|
7423
|
-
assert2(spatialFilter, "spatialFilter required for tilesets");
|
|
7424
7479
|
this._extractTileFeatures(spatialFilter);
|
|
7425
7480
|
return applyFilters(
|
|
7426
7481
|
this._features,
|
|
@@ -7444,6 +7499,11 @@ function assertColumn(features, ...columnArgs) {
|
|
|
7444
7499
|
function normalizeColumns(columns) {
|
|
7445
7500
|
return Array.isArray(columns) ? columns : typeof columns === "string" ? [columns] : [];
|
|
7446
7501
|
}
|
|
7502
|
+
function spatialFilterEquals(a, b) {
|
|
7503
|
+
if (a === b) return true;
|
|
7504
|
+
if (!a || !b) return false;
|
|
7505
|
+
return booleanEqual(a, b);
|
|
7506
|
+
}
|
|
7447
7507
|
|
|
7448
7508
|
// src/widget-sources/widget-tileset-source.ts
|
|
7449
7509
|
var WidgetTilesetSource = class extends WidgetSource {
|
|
@@ -9963,11 +10023,68 @@ function _getHexagonResolution(viewport, tileSize) {
|
|
|
9963
10023
|
Math.floor(hexagonScaleFactor + latitudeScaleFactor - BIAS)
|
|
9964
10024
|
);
|
|
9965
10025
|
}
|
|
10026
|
+
|
|
10027
|
+
// src/utils/CellSet.ts
|
|
10028
|
+
var EMPTY_U32 = 2 ** 32 - 1;
|
|
10029
|
+
var CellSet = class {
|
|
10030
|
+
constructor(cells) {
|
|
10031
|
+
/** List of cells stored by the set. Stored by reference, without copying. */
|
|
10032
|
+
__publicField(this, "cells");
|
|
10033
|
+
/** DataView representing a single cell ID. Pre-allocated to reduce memory during queries. */
|
|
10034
|
+
__publicField(this, "cellView", new DataView(new ArrayBuffer(8)));
|
|
10035
|
+
/** Hash table, mapping a hash index (computed) to an index in the 'cells' array. */
|
|
10036
|
+
__publicField(this, "hashTable");
|
|
10037
|
+
this.cells = cells;
|
|
10038
|
+
this.hashTable = new Uint32Array(hashBuckets(cells.length)).fill(EMPTY_U32);
|
|
10039
|
+
for (let cellIndex = 0; cellIndex < cells.length; cellIndex++) {
|
|
10040
|
+
this.hashTable[this.hashLookup(cells[cellIndex])] = cellIndex;
|
|
10041
|
+
}
|
|
10042
|
+
}
|
|
10043
|
+
has(cell) {
|
|
10044
|
+
const hashIndex = this.hashLookup(cell);
|
|
10045
|
+
return this.hashTable[hashIndex] !== EMPTY_U32;
|
|
10046
|
+
}
|
|
10047
|
+
hashLookup(cell) {
|
|
10048
|
+
this.cellView.setBigUint64(0, cell);
|
|
10049
|
+
const hashval = hash(this.cellView);
|
|
10050
|
+
const hashmod = this.hashTable.length - 1;
|
|
10051
|
+
let bucket = hashval & hashmod;
|
|
10052
|
+
for (let probe = 0; probe <= hashmod; probe++) {
|
|
10053
|
+
const cellIndex = this.hashTable[bucket];
|
|
10054
|
+
if (cellIndex === EMPTY_U32 || cell === this.cells[cellIndex]) {
|
|
10055
|
+
return bucket;
|
|
10056
|
+
}
|
|
10057
|
+
bucket = bucket + probe + 1 & hashmod;
|
|
10058
|
+
}
|
|
10059
|
+
throw new Error("Hash table full.");
|
|
10060
|
+
}
|
|
10061
|
+
};
|
|
10062
|
+
function hash(view, h = 0) {
|
|
10063
|
+
const m = 1540483477;
|
|
10064
|
+
const r = 24;
|
|
10065
|
+
for (let i = 0, il = view.byteLength / 4; i < il; i++) {
|
|
10066
|
+
let k = view.getUint32(i * 4);
|
|
10067
|
+
k = Math.imul(k, m) >>> 0;
|
|
10068
|
+
k = (k ^ k >> r) >>> 0;
|
|
10069
|
+
k = Math.imul(k, m) >>> 0;
|
|
10070
|
+
h = Math.imul(h, m) >>> 0;
|
|
10071
|
+
h = (h ^ k) >>> 0;
|
|
10072
|
+
}
|
|
10073
|
+
return h;
|
|
10074
|
+
}
|
|
10075
|
+
function hashBuckets(initialCount) {
|
|
10076
|
+
let buckets = 1;
|
|
10077
|
+
while (buckets < initialCount + initialCount / 4) {
|
|
10078
|
+
buckets *= 2;
|
|
10079
|
+
}
|
|
10080
|
+
return buckets;
|
|
10081
|
+
}
|
|
9966
10082
|
export {
|
|
9967
10083
|
AggregationTypes,
|
|
9968
10084
|
ApiVersion,
|
|
9969
10085
|
basemap_styles_default as BASEMAP,
|
|
9970
10086
|
CartoAPIError,
|
|
10087
|
+
CellSet,
|
|
9971
10088
|
DEFAULT_API_BASE_URL,
|
|
9972
10089
|
FEATURE_GEOM_PROPERTY,
|
|
9973
10090
|
FilterType,
|