@carto/api-client 0.5.6-alpha.bundle.4 → 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/CHANGELOG.md +7 -0
- package/build/api-client.cjs +488 -361
- package/build/api-client.cjs.map +1 -1
- package/build/api-client.d.cts +35 -6
- package/build/api-client.d.ts +35 -6
- package/build/api-client.js +451 -325
- package/build/api-client.js.map +1 -1
- package/build/worker-compat.js +4227 -2968
- package/build/worker-compat.js.map +1 -1
- package/build/worker.js +408 -340
- package/build/worker.js.map +1 -1
- package/package.json +2 -2
- package/src/constants.ts +12 -0
- package/src/fetch-map/layer-map.ts +2 -1
- 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/types.ts +1 -1
- package/src/utils/CellSet.ts +90 -0
- package/src/widget-sources/widget-remote-source.ts +5 -5
- package/src/widget-sources/widget-tileset-source-impl.ts +15 -10
package/build/api-client.js
CHANGED
|
@@ -94,11 +94,11 @@ var FilterType = /* @__PURE__ */ ((FilterType2) => {
|
|
|
94
94
|
FilterType2["STRING_SEARCH"] = "stringSearch";
|
|
95
95
|
return FilterType2;
|
|
96
96
|
})(FilterType || {});
|
|
97
|
-
var ApiVersion = /* @__PURE__ */ ((
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
return
|
|
97
|
+
var ApiVersion = /* @__PURE__ */ ((ApiVersion3) => {
|
|
98
|
+
ApiVersion3["V1"] = "v1";
|
|
99
|
+
ApiVersion3["V2"] = "v2";
|
|
100
|
+
ApiVersion3["V3"] = "v3";
|
|
101
|
+
return ApiVersion3;
|
|
102
102
|
})(ApiVersion || {});
|
|
103
103
|
var DEFAULT_API_BASE_URL = "https://gcp-us-east1.api.carto.com";
|
|
104
104
|
var TileFormat = /* @__PURE__ */ ((TileFormat2) => {
|
|
@@ -126,6 +126,14 @@ var SpatialIndexColumn = Object.freeze({
|
|
|
126
126
|
["h3" /* H3 */]: ["h3", "hex", "h3id", "hex_id", "h3hex"],
|
|
127
127
|
["quadbin" /* QUADBIN */]: ["quadbin"]
|
|
128
128
|
});
|
|
129
|
+
var AggregationTypes = {
|
|
130
|
+
Count: "count",
|
|
131
|
+
Avg: "avg",
|
|
132
|
+
Min: "min",
|
|
133
|
+
Max: "max",
|
|
134
|
+
Sum: "sum",
|
|
135
|
+
Custom: "custom"
|
|
136
|
+
};
|
|
129
137
|
|
|
130
138
|
// src/utils/makeIntervalComplete.ts
|
|
131
139
|
function makeIntervalComplete(intervals) {
|
|
@@ -1550,6 +1558,110 @@ function geojsonFeatures({
|
|
|
1550
1558
|
return Array.from(map.values());
|
|
1551
1559
|
}
|
|
1552
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
|
+
|
|
1553
1665
|
// node_modules/@turf/bbox-polygon/dist/esm/index.js
|
|
1554
1666
|
function bboxPolygon(bbox2, options = {}) {
|
|
1555
1667
|
const west = Number(bbox2[0]);
|
|
@@ -1868,7 +1980,7 @@ var MAX_SAFE_INTEGER = 9007199254740991;
|
|
|
1868
1980
|
var POWS_TEN = [1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13];
|
|
1869
1981
|
var SQRT_BASE = 1e7;
|
|
1870
1982
|
var MAX = 1e9;
|
|
1871
|
-
function
|
|
1983
|
+
function clone2(configObject) {
|
|
1872
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 = {
|
|
1873
1985
|
prefix: "",
|
|
1874
1986
|
groupSize: 3,
|
|
@@ -1994,7 +2106,7 @@ function clone(configObject) {
|
|
|
1994
2106
|
x.c = [x.e = 0];
|
|
1995
2107
|
}
|
|
1996
2108
|
}
|
|
1997
|
-
BigNumber2.clone =
|
|
2109
|
+
BigNumber2.clone = clone2;
|
|
1998
2110
|
BigNumber2.ROUND_UP = 0;
|
|
1999
2111
|
BigNumber2.ROUND_DOWN = 1;
|
|
2000
2112
|
BigNumber2.ROUND_CEIL = 2;
|
|
@@ -3197,7 +3309,7 @@ function toFixedPoint(str, e, z) {
|
|
|
3197
3309
|
}
|
|
3198
3310
|
return str;
|
|
3199
3311
|
}
|
|
3200
|
-
var BigNumber =
|
|
3312
|
+
var BigNumber = clone2();
|
|
3201
3313
|
var bignumber_default = BigNumber;
|
|
3202
3314
|
|
|
3203
3315
|
// node_modules/splaytree-ts/dist/esm/index.js
|
|
@@ -4767,71 +4879,14 @@ function intersect(features, options = {}) {
|
|
|
4767
4879
|
}
|
|
4768
4880
|
var turf_intersect_default = intersect;
|
|
4769
4881
|
|
|
4770
|
-
// node_modules/@math.gl/core/dist/lib/common.js
|
|
4771
|
-
var RADIANS_TO_DEGREES = 1 / Math.PI * 180;
|
|
4772
|
-
var DEGREES_TO_RADIANS = 1 / 180 * Math.PI;
|
|
4773
|
-
var DEFAULT_CONFIG = {
|
|
4774
|
-
EPSILON: 1e-12,
|
|
4775
|
-
debug: false,
|
|
4776
|
-
precision: 4,
|
|
4777
|
-
printTypes: false,
|
|
4778
|
-
printDegrees: false,
|
|
4779
|
-
printRowMajor: true,
|
|
4780
|
-
_cartographicRadians: false
|
|
4781
|
-
};
|
|
4782
|
-
globalThis.mathgl = globalThis.mathgl || { config: { ...DEFAULT_CONFIG } };
|
|
4783
|
-
var config = globalThis.mathgl.config;
|
|
4784
|
-
function isArray(value) {
|
|
4785
|
-
return Array.isArray(value) || ArrayBuffer.isView(value) && !(value instanceof DataView);
|
|
4786
|
-
}
|
|
4787
|
-
function lerp(a, b, t) {
|
|
4788
|
-
if (isArray(a)) {
|
|
4789
|
-
return a.map((ai, i) => lerp(ai, b[i], t));
|
|
4790
|
-
}
|
|
4791
|
-
return t * b + (1 - t) * a;
|
|
4792
|
-
}
|
|
4793
|
-
|
|
4794
|
-
// node_modules/@math.gl/web-mercator/dist/assert.js
|
|
4795
|
-
function assert(condition, message) {
|
|
4796
|
-
if (!condition) {
|
|
4797
|
-
throw new Error(message || "@math.gl/web-mercator: assertion failed.");
|
|
4798
|
-
}
|
|
4799
|
-
}
|
|
4800
|
-
|
|
4801
|
-
// node_modules/@math.gl/web-mercator/dist/web-mercator-utils.js
|
|
4802
|
-
var PI = Math.PI;
|
|
4803
|
-
var PI_4 = PI / 4;
|
|
4804
|
-
var DEGREES_TO_RADIANS2 = PI / 180;
|
|
4805
|
-
var RADIANS_TO_DEGREES2 = 180 / PI;
|
|
4806
|
-
var TILE_SIZE = 512;
|
|
4807
|
-
function lngLatToWorld(lngLat) {
|
|
4808
|
-
const [lng, lat] = lngLat;
|
|
4809
|
-
assert(Number.isFinite(lng));
|
|
4810
|
-
assert(Number.isFinite(lat) && lat >= -90 && lat <= 90, "invalid latitude");
|
|
4811
|
-
const lambda2 = lng * DEGREES_TO_RADIANS2;
|
|
4812
|
-
const phi2 = lat * DEGREES_TO_RADIANS2;
|
|
4813
|
-
const x = TILE_SIZE * (lambda2 + PI) / (2 * PI);
|
|
4814
|
-
const y = TILE_SIZE * (PI + Math.log(Math.tan(PI_4 + phi2 * 0.5))) / (2 * PI);
|
|
4815
|
-
return [x, y];
|
|
4816
|
-
}
|
|
4817
|
-
function worldToLngLat(xy) {
|
|
4818
|
-
const [x, y] = xy;
|
|
4819
|
-
const lambda2 = x / TILE_SIZE * (2 * PI) - PI;
|
|
4820
|
-
const phi2 = 2 * (Math.atan(Math.exp(y / TILE_SIZE * (2 * PI) - PI)) - PI_4);
|
|
4821
|
-
return [lambda2 * RADIANS_TO_DEGREES2, phi2 * RADIANS_TO_DEGREES2];
|
|
4822
|
-
}
|
|
4823
|
-
|
|
4824
|
-
// node_modules/@math.gl/web-mercator/dist/get-bounds.js
|
|
4825
|
-
var DEGREES_TO_RADIANS3 = Math.PI / 180;
|
|
4826
|
-
|
|
4827
4882
|
// src/utils/transformToTileCoords.ts
|
|
4828
|
-
var
|
|
4829
|
-
Point:
|
|
4830
|
-
MultiPoint:
|
|
4831
|
-
LineString:
|
|
4832
|
-
MultiLineString:
|
|
4833
|
-
Polygon:
|
|
4834
|
-
MultiPolygon:
|
|
4883
|
+
var TRANSFORM_FN2 = {
|
|
4884
|
+
Point: transformPoint2,
|
|
4885
|
+
MultiPoint: transformMultiPoint2,
|
|
4886
|
+
LineString: transformLineString2,
|
|
4887
|
+
MultiLineString: transformMultiLineString2,
|
|
4888
|
+
Polygon: transformPolygon2,
|
|
4889
|
+
MultiPolygon: transformMultiPolygon2
|
|
4835
4890
|
};
|
|
4836
4891
|
function transformToTileCoords(geometry, bbox2) {
|
|
4837
4892
|
const [west, south, east, north] = bbox2;
|
|
@@ -4841,34 +4896,34 @@ function transformToTileCoords(geometry, bbox2) {
|
|
|
4841
4896
|
if (geometry.type === "GeometryCollection") {
|
|
4842
4897
|
throw new Error("Unsupported geometry type GeometryCollection");
|
|
4843
4898
|
}
|
|
4844
|
-
const transformFn =
|
|
4899
|
+
const transformFn = TRANSFORM_FN2[geometry.type];
|
|
4845
4900
|
const coordinates = transformFn(geometry.coordinates, projectedBbox);
|
|
4846
4901
|
return { ...geometry, coordinates };
|
|
4847
4902
|
}
|
|
4848
|
-
function
|
|
4903
|
+
function transformPoint2([pointX, pointY], [nw, se]) {
|
|
4849
4904
|
const x = inverseLerp(nw[0], se[0], pointX);
|
|
4850
4905
|
const y = inverseLerp(nw[1], se[1], pointY);
|
|
4851
4906
|
return [x, y];
|
|
4852
4907
|
}
|
|
4853
|
-
function
|
|
4854
|
-
return geometry.map((g) =>
|
|
4908
|
+
function getPoints2(geometry, bbox2) {
|
|
4909
|
+
return geometry.map((g) => transformPoint2(projectFlat(g), bbox2));
|
|
4855
4910
|
}
|
|
4856
|
-
function
|
|
4857
|
-
return
|
|
4911
|
+
function transformMultiPoint2(multiPoint, bbox2) {
|
|
4912
|
+
return getPoints2(multiPoint, bbox2);
|
|
4858
4913
|
}
|
|
4859
|
-
function
|
|
4860
|
-
return
|
|
4914
|
+
function transformLineString2(line, bbox2) {
|
|
4915
|
+
return getPoints2(line, bbox2);
|
|
4861
4916
|
}
|
|
4862
|
-
function
|
|
4917
|
+
function transformMultiLineString2(multiLineString2, bbox2) {
|
|
4863
4918
|
return multiLineString2.map(
|
|
4864
|
-
(lineString2) =>
|
|
4919
|
+
(lineString2) => transformLineString2(lineString2, bbox2)
|
|
4865
4920
|
);
|
|
4866
4921
|
}
|
|
4867
|
-
function
|
|
4868
|
-
return polygon2.map((polygonRing) =>
|
|
4922
|
+
function transformPolygon2(polygon2, bbox2) {
|
|
4923
|
+
return polygon2.map((polygonRing) => getPoints2(polygonRing, bbox2));
|
|
4869
4924
|
}
|
|
4870
|
-
function
|
|
4871
|
-
return multiPolygon2.map((polygon2) =>
|
|
4925
|
+
function transformMultiPolygon2(multiPolygon2, bbox2) {
|
|
4926
|
+
return multiPolygon2.map((polygon2) => transformPolygon2(polygon2, bbox2));
|
|
4872
4927
|
}
|
|
4873
4928
|
function projectFlat(xyz) {
|
|
4874
4929
|
return lngLatToWorld(xyz);
|
|
@@ -4877,51 +4932,195 @@ function inverseLerp(a, b, x) {
|
|
|
4877
4932
|
return (x - a) / (b - a);
|
|
4878
4933
|
}
|
|
4879
4934
|
|
|
4880
|
-
// src/
|
|
4881
|
-
|
|
4882
|
-
|
|
4883
|
-
|
|
4884
|
-
|
|
4885
|
-
|
|
4886
|
-
|
|
4887
|
-
|
|
4888
|
-
};
|
|
4889
|
-
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
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;
|
|
4896
4999
|
}
|
|
4897
|
-
|
|
4898
|
-
const coordinates = transformFn(geometry.coordinates, projectedBbox);
|
|
4899
|
-
return { ...geometry, coordinates };
|
|
5000
|
+
return result;
|
|
4900
5001
|
}
|
|
4901
|
-
function
|
|
4902
|
-
|
|
4903
|
-
const y = lerp(nw[1], se[1], pointY);
|
|
4904
|
-
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;
|
|
4905
5004
|
}
|
|
4906
|
-
function
|
|
4907
|
-
|
|
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;
|
|
4908
5012
|
}
|
|
4909
|
-
function
|
|
4910
|
-
|
|
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
|
+
}
|
|
4911
5045
|
}
|
|
4912
|
-
function
|
|
4913
|
-
|
|
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;
|
|
4914
5060
|
}
|
|
4915
|
-
|
|
4916
|
-
|
|
4917
|
-
|
|
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)])
|
|
4918
5071
|
);
|
|
5072
|
+
if (!clippedSpatialFilter) {
|
|
5073
|
+
return false;
|
|
5074
|
+
}
|
|
5075
|
+
return tileFormat === "mvt" /* MVT */ ? transformToTileCoords(clippedSpatialFilter.geometry, tileBbox) : clippedSpatialFilter.geometry;
|
|
4919
5076
|
}
|
|
4920
|
-
function
|
|
4921
|
-
return
|
|
5077
|
+
function intersectTileRaster(parent, cellResolution, spatialFilter) {
|
|
5078
|
+
return intersectTileQuadbin(parent, cellResolution, spatialFilter);
|
|
4922
5079
|
}
|
|
4923
|
-
function
|
|
4924
|
-
|
|
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));
|
|
4925
5124
|
}
|
|
4926
5125
|
|
|
4927
5126
|
// src/filters/tileFeaturesGeometries.ts
|
|
@@ -4938,55 +5137,45 @@ function tileFeaturesGeometries({
|
|
|
4938
5137
|
if (tile.isVisible === false || !tile.data) {
|
|
4939
5138
|
continue;
|
|
4940
5139
|
}
|
|
4941
|
-
const
|
|
5140
|
+
const tileBbox = [
|
|
4942
5141
|
tile.bbox.west,
|
|
4943
5142
|
tile.bbox.south,
|
|
4944
5143
|
tile.bbox.east,
|
|
4945
5144
|
tile.bbox.north
|
|
4946
5145
|
];
|
|
4947
|
-
const
|
|
4948
|
-
|
|
4949
|
-
|
|
4950
|
-
|
|
4951
|
-
geometry: spatialFilter,
|
|
4952
|
-
properties: {}
|
|
4953
|
-
};
|
|
4954
|
-
const clippedGeometryToIntersect = turf_intersect_default(
|
|
4955
|
-
featureCollection([bboxToGeom, spatialFilterFeature])
|
|
5146
|
+
const intersection3 = intersectTileGeometry(
|
|
5147
|
+
tileBbox,
|
|
5148
|
+
tileFormat,
|
|
5149
|
+
spatialFilter
|
|
4956
5150
|
);
|
|
4957
|
-
if (
|
|
4958
|
-
|
|
4959
|
-
}
|
|
4960
|
-
const transformedGeometryToIntersect = tileFormat === "mvt" /* MVT */ ? transformToTileCoords(clippedGeometryToIntersect.geometry, bbox2) : clippedGeometryToIntersect.geometry;
|
|
5151
|
+
if (intersection3 === false) continue;
|
|
5152
|
+
const transformedSpatialFilter = intersection3 === true ? void 0 : intersection3;
|
|
4961
5153
|
calculateFeatures({
|
|
4962
5154
|
map,
|
|
4963
|
-
|
|
4964
|
-
geometryIntersection: transformedGeometryToIntersect,
|
|
5155
|
+
spatialFilter: transformedSpatialFilter,
|
|
4965
5156
|
data: tile.data.points,
|
|
4966
5157
|
type: "Point",
|
|
4967
|
-
bbox:
|
|
5158
|
+
bbox: tileBbox,
|
|
4968
5159
|
tileFormat,
|
|
4969
5160
|
uniqueIdProperty,
|
|
4970
5161
|
options
|
|
4971
5162
|
});
|
|
4972
5163
|
calculateFeatures({
|
|
4973
5164
|
map,
|
|
4974
|
-
|
|
4975
|
-
geometryIntersection: transformedGeometryToIntersect,
|
|
5165
|
+
spatialFilter: transformedSpatialFilter,
|
|
4976
5166
|
data: tile.data.lines,
|
|
4977
5167
|
type: "LineString",
|
|
4978
|
-
bbox:
|
|
5168
|
+
bbox: tileBbox,
|
|
4979
5169
|
tileFormat,
|
|
4980
5170
|
uniqueIdProperty,
|
|
4981
5171
|
options
|
|
4982
5172
|
});
|
|
4983
5173
|
calculateFeatures({
|
|
4984
5174
|
map,
|
|
4985
|
-
|
|
4986
|
-
geometryIntersection: transformedGeometryToIntersect,
|
|
5175
|
+
spatialFilter: transformedSpatialFilter,
|
|
4987
5176
|
data: tile.data.polygons,
|
|
4988
5177
|
type: "Polygon",
|
|
4989
|
-
bbox:
|
|
5178
|
+
bbox: tileBbox,
|
|
4990
5179
|
tileFormat,
|
|
4991
5180
|
uniqueIdProperty,
|
|
4992
5181
|
options
|
|
@@ -5004,7 +5193,7 @@ function processTileFeatureProperties({
|
|
|
5004
5193
|
tileFormat,
|
|
5005
5194
|
uniqueIdProperty,
|
|
5006
5195
|
storeGeometry,
|
|
5007
|
-
|
|
5196
|
+
spatialFilter
|
|
5008
5197
|
}) {
|
|
5009
5198
|
const tileProps = getPropertiesFromTile(data, startIndex);
|
|
5010
5199
|
const uniquePropertyValue = getUniquePropertyValue(
|
|
@@ -5016,7 +5205,7 @@ function processTileFeatureProperties({
|
|
|
5016
5205
|
return;
|
|
5017
5206
|
}
|
|
5018
5207
|
let geometry = null;
|
|
5019
|
-
if (storeGeometry ||
|
|
5208
|
+
if (storeGeometry || spatialFilter) {
|
|
5020
5209
|
const { positions } = data;
|
|
5021
5210
|
const ringCoordinates = getRingCoordinatesFor(
|
|
5022
5211
|
startIndex,
|
|
@@ -5025,7 +5214,7 @@ function processTileFeatureProperties({
|
|
|
5025
5214
|
);
|
|
5026
5215
|
geometry = getFeatureByType(ringCoordinates, type);
|
|
5027
5216
|
}
|
|
5028
|
-
if (geometry &&
|
|
5217
|
+
if (geometry && spatialFilter && !turf_boolean_intersects_default(geometry, spatialFilter)) {
|
|
5029
5218
|
return;
|
|
5030
5219
|
}
|
|
5031
5220
|
const properties = parseProperties(tileProps);
|
|
@@ -5037,7 +5226,7 @@ function processTileFeatureProperties({
|
|
|
5037
5226
|
function addIntersectedFeaturesInTile({
|
|
5038
5227
|
map,
|
|
5039
5228
|
data,
|
|
5040
|
-
|
|
5229
|
+
spatialFilter,
|
|
5041
5230
|
type,
|
|
5042
5231
|
bbox: bbox2,
|
|
5043
5232
|
tileFormat,
|
|
@@ -5059,7 +5248,7 @@ function addIntersectedFeaturesInTile({
|
|
|
5059
5248
|
tileFormat,
|
|
5060
5249
|
uniqueIdProperty,
|
|
5061
5250
|
storeGeometry,
|
|
5062
|
-
|
|
5251
|
+
spatialFilter
|
|
5063
5252
|
});
|
|
5064
5253
|
}
|
|
5065
5254
|
}
|
|
@@ -5141,8 +5330,7 @@ function getRingCoordinatesFor(startIndex, endIndex, positions) {
|
|
|
5141
5330
|
}
|
|
5142
5331
|
function calculateFeatures({
|
|
5143
5332
|
map,
|
|
5144
|
-
|
|
5145
|
-
geometryIntersection,
|
|
5333
|
+
spatialFilter,
|
|
5146
5334
|
data,
|
|
5147
5335
|
type,
|
|
5148
5336
|
bbox: bbox2,
|
|
@@ -5153,7 +5341,7 @@ function calculateFeatures({
|
|
|
5153
5341
|
if (!data?.properties.length) {
|
|
5154
5342
|
return;
|
|
5155
5343
|
}
|
|
5156
|
-
if (
|
|
5344
|
+
if (!spatialFilter) {
|
|
5157
5345
|
addAllFeaturesInTile({
|
|
5158
5346
|
map,
|
|
5159
5347
|
data,
|
|
@@ -5167,7 +5355,7 @@ function calculateFeatures({
|
|
|
5167
5355
|
addIntersectedFeaturesInTile({
|
|
5168
5356
|
map,
|
|
5169
5357
|
data,
|
|
5170
|
-
|
|
5358
|
+
spatialFilter,
|
|
5171
5359
|
type,
|
|
5172
5360
|
bbox: bbox2,
|
|
5173
5361
|
tileFormat,
|
|
@@ -5217,128 +5405,8 @@ function createIndicesForPoints(data) {
|
|
|
5217
5405
|
}
|
|
5218
5406
|
|
|
5219
5407
|
// src/filters/tileFeaturesSpatialIndex.ts
|
|
5220
|
-
import { getResolution as quadbinGetResolution
|
|
5221
|
-
|
|
5222
|
-
// node_modules/@turf/bbox-clip/dist/esm/index.js
|
|
5223
|
-
function lineclip(points, bbox2, result) {
|
|
5224
|
-
var len = points.length, codeA = bitCode(points[0], bbox2), part = [], i, codeB, lastCode;
|
|
5225
|
-
let a;
|
|
5226
|
-
let b;
|
|
5227
|
-
if (!result) result = [];
|
|
5228
|
-
for (i = 1; i < len; i++) {
|
|
5229
|
-
a = points[i - 1];
|
|
5230
|
-
b = points[i];
|
|
5231
|
-
codeB = lastCode = bitCode(b, bbox2);
|
|
5232
|
-
while (true) {
|
|
5233
|
-
if (!(codeA | codeB)) {
|
|
5234
|
-
part.push(a);
|
|
5235
|
-
if (codeB !== lastCode) {
|
|
5236
|
-
part.push(b);
|
|
5237
|
-
if (i < len - 1) {
|
|
5238
|
-
result.push(part);
|
|
5239
|
-
part = [];
|
|
5240
|
-
}
|
|
5241
|
-
} else if (i === len - 1) {
|
|
5242
|
-
part.push(b);
|
|
5243
|
-
}
|
|
5244
|
-
break;
|
|
5245
|
-
} else if (codeA & codeB) {
|
|
5246
|
-
break;
|
|
5247
|
-
} else if (codeA) {
|
|
5248
|
-
a = intersect2(a, b, codeA, bbox2);
|
|
5249
|
-
codeA = bitCode(a, bbox2);
|
|
5250
|
-
} else {
|
|
5251
|
-
b = intersect2(a, b, codeB, bbox2);
|
|
5252
|
-
codeB = bitCode(b, bbox2);
|
|
5253
|
-
}
|
|
5254
|
-
}
|
|
5255
|
-
codeA = lastCode;
|
|
5256
|
-
}
|
|
5257
|
-
if (part.length) result.push(part);
|
|
5258
|
-
return result;
|
|
5259
|
-
}
|
|
5260
|
-
function polygonclip(points, bbox2) {
|
|
5261
|
-
var result, edge, prev, prevInside, i, p, inside;
|
|
5262
|
-
for (edge = 1; edge <= 8; edge *= 2) {
|
|
5263
|
-
result = [];
|
|
5264
|
-
prev = points[points.length - 1];
|
|
5265
|
-
prevInside = !(bitCode(prev, bbox2) & edge);
|
|
5266
|
-
for (i = 0; i < points.length; i++) {
|
|
5267
|
-
p = points[i];
|
|
5268
|
-
inside = !(bitCode(p, bbox2) & edge);
|
|
5269
|
-
if (inside !== prevInside) result.push(intersect2(prev, p, edge, bbox2));
|
|
5270
|
-
if (inside) result.push(p);
|
|
5271
|
-
prev = p;
|
|
5272
|
-
prevInside = inside;
|
|
5273
|
-
}
|
|
5274
|
-
points = result;
|
|
5275
|
-
if (!points.length) break;
|
|
5276
|
-
}
|
|
5277
|
-
return result;
|
|
5278
|
-
}
|
|
5279
|
-
function intersect2(a, b, edge, bbox2) {
|
|
5280
|
-
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;
|
|
5281
|
-
}
|
|
5282
|
-
function bitCode(p, bbox2) {
|
|
5283
|
-
var code = 0;
|
|
5284
|
-
if (p[0] < bbox2[0]) code |= 1;
|
|
5285
|
-
else if (p[0] > bbox2[2]) code |= 2;
|
|
5286
|
-
if (p[1] < bbox2[1]) code |= 4;
|
|
5287
|
-
else if (p[1] > bbox2[3]) code |= 8;
|
|
5288
|
-
return code;
|
|
5289
|
-
}
|
|
5290
|
-
function bboxClip(feature2, bbox2) {
|
|
5291
|
-
const geom = getGeom(feature2);
|
|
5292
|
-
const type = geom.type;
|
|
5293
|
-
const properties = feature2.type === "Feature" ? feature2.properties : {};
|
|
5294
|
-
let coords = geom.coordinates;
|
|
5295
|
-
switch (type) {
|
|
5296
|
-
case "LineString":
|
|
5297
|
-
case "MultiLineString": {
|
|
5298
|
-
const lines = [];
|
|
5299
|
-
if (type === "LineString") {
|
|
5300
|
-
coords = [coords];
|
|
5301
|
-
}
|
|
5302
|
-
coords.forEach((line) => {
|
|
5303
|
-
lineclip(line, bbox2, lines);
|
|
5304
|
-
});
|
|
5305
|
-
if (lines.length === 1) {
|
|
5306
|
-
return lineString(lines[0], properties);
|
|
5307
|
-
}
|
|
5308
|
-
return multiLineString(lines, properties);
|
|
5309
|
-
}
|
|
5310
|
-
case "Polygon":
|
|
5311
|
-
return polygon(clipPolygon(coords, bbox2), properties);
|
|
5312
|
-
case "MultiPolygon":
|
|
5313
|
-
return multiPolygon(
|
|
5314
|
-
coords.map((poly) => {
|
|
5315
|
-
return clipPolygon(poly, bbox2);
|
|
5316
|
-
}),
|
|
5317
|
-
properties
|
|
5318
|
-
);
|
|
5319
|
-
default:
|
|
5320
|
-
throw new Error("geometry " + type + " not supported");
|
|
5321
|
-
}
|
|
5322
|
-
}
|
|
5323
|
-
function clipPolygon(rings, bbox2) {
|
|
5324
|
-
const outRings = [];
|
|
5325
|
-
for (const ring of rings) {
|
|
5326
|
-
const clipped = polygonclip(ring, bbox2);
|
|
5327
|
-
if (clipped.length > 0) {
|
|
5328
|
-
if (clipped[0][0] !== clipped[clipped.length - 1][0] || clipped[0][1] !== clipped[clipped.length - 1][1]) {
|
|
5329
|
-
clipped.push(clipped[0]);
|
|
5330
|
-
}
|
|
5331
|
-
if (clipped.length >= 4) {
|
|
5332
|
-
outRings.push(clipped);
|
|
5333
|
-
}
|
|
5334
|
-
}
|
|
5335
|
-
}
|
|
5336
|
-
return outRings;
|
|
5337
|
-
}
|
|
5338
|
-
var turf_bbox_clip_default = bboxClip;
|
|
5339
|
-
|
|
5340
|
-
// src/filters/tileFeaturesSpatialIndex.ts
|
|
5341
|
-
import { getResolution as h3GetResolution, polygonToCells } from "h3-js";
|
|
5408
|
+
import { getResolution as quadbinGetResolution } from "quadbin";
|
|
5409
|
+
import { getResolution as h3GetResolution } from "h3-js";
|
|
5342
5410
|
function tileFeaturesSpatialIndex({
|
|
5343
5411
|
tiles,
|
|
5344
5412
|
spatialFilter,
|
|
@@ -5347,28 +5415,40 @@ function tileFeaturesSpatialIndex({
|
|
|
5347
5415
|
}) {
|
|
5348
5416
|
const map = /* @__PURE__ */ new Map();
|
|
5349
5417
|
const spatialIndex = getSpatialIndex(spatialDataType);
|
|
5350
|
-
const
|
|
5418
|
+
const cellResolution = getResolution(tiles, spatialIndex);
|
|
5351
5419
|
const spatialIndexIDName = spatialDataColumn ? spatialDataColumn : spatialIndex;
|
|
5352
|
-
if (!
|
|
5420
|
+
if (!cellResolution) {
|
|
5353
5421
|
return [];
|
|
5354
5422
|
}
|
|
5355
|
-
const cells = getCellsCoverGeometry(spatialFilter, spatialIndex, resolution);
|
|
5356
|
-
if (!cells?.length) {
|
|
5357
|
-
return [];
|
|
5358
|
-
}
|
|
5359
|
-
const cellsSet = new Set(cells);
|
|
5360
5423
|
for (const tile of tiles) {
|
|
5361
5424
|
if (tile.isVisible === false || !tile.data) {
|
|
5362
5425
|
continue;
|
|
5363
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;
|
|
5364
5438
|
tile.data.forEach((d) => {
|
|
5365
|
-
if (
|
|
5439
|
+
if (intersection3 === true || intersection3.has(d.id)) {
|
|
5366
5440
|
map.set(d.id, { ...d.properties, [spatialIndexIDName]: d.id });
|
|
5367
5441
|
}
|
|
5368
5442
|
});
|
|
5369
5443
|
}
|
|
5370
5444
|
return Array.from(map.values());
|
|
5371
5445
|
}
|
|
5446
|
+
function getTileIndex(tile, spatialIndex) {
|
|
5447
|
+
if (spatialIndex === "quadbin" /* QUADBIN */) {
|
|
5448
|
+
return tile.index.q;
|
|
5449
|
+
}
|
|
5450
|
+
return tile.id;
|
|
5451
|
+
}
|
|
5372
5452
|
function getResolution(tiles, spatialIndex) {
|
|
5373
5453
|
const data = tiles.find((tile) => tile.data?.length)?.data;
|
|
5374
5454
|
if (!data) {
|
|
@@ -5381,26 +5461,6 @@ function getResolution(tiles, spatialIndex) {
|
|
|
5381
5461
|
return h3GetResolution(data[0].id);
|
|
5382
5462
|
}
|
|
5383
5463
|
}
|
|
5384
|
-
var bboxWest = [-180, -90, 0, 90];
|
|
5385
|
-
var bboxEast = [0, -90, 180, 90];
|
|
5386
|
-
function getCellsCoverGeometry(geometry, spatialIndex, resolution) {
|
|
5387
|
-
if (spatialIndex === "quadbin" /* QUADBIN */) {
|
|
5388
|
-
return geometryToCells(geometry, resolution);
|
|
5389
|
-
}
|
|
5390
|
-
if (spatialIndex === "h3" /* H3 */) {
|
|
5391
|
-
return polygonToCells(
|
|
5392
|
-
turf_bbox_clip_default(geometry, bboxWest).geometry.coordinates,
|
|
5393
|
-
resolution,
|
|
5394
|
-
true
|
|
5395
|
-
).concat(
|
|
5396
|
-
polygonToCells(
|
|
5397
|
-
turf_bbox_clip_default(geometry, bboxEast).geometry.coordinates,
|
|
5398
|
-
resolution,
|
|
5399
|
-
true
|
|
5400
|
-
)
|
|
5401
|
-
);
|
|
5402
|
-
}
|
|
5403
|
-
}
|
|
5404
5464
|
function getSpatialIndex(spatialDataType) {
|
|
5405
5465
|
switch (spatialDataType) {
|
|
5406
5466
|
case "h3":
|
|
@@ -5427,7 +5487,6 @@ var DEFAULT_AGGREGATION_EXP = `1 AS ${DEFAULT_AGGREGATION_EXP_ALIAS}`;
|
|
|
5427
5487
|
import {
|
|
5428
5488
|
cellToChildren as _cellToChildren,
|
|
5429
5489
|
cellToTile,
|
|
5430
|
-
geometryToCells as geometryToCells2,
|
|
5431
5490
|
getResolution as getResolution2
|
|
5432
5491
|
} from "quadbin";
|
|
5433
5492
|
function tileFeaturesRaster({
|
|
@@ -5443,15 +5502,20 @@ function tileFeaturesRaster({
|
|
|
5443
5502
|
const tileResolution = getResolution2(tiles[0].index.q);
|
|
5444
5503
|
const tileBlockSize = tiles[0].data.blockSize;
|
|
5445
5504
|
const cellResolution = tileResolution + BigInt(Math.log2(tileBlockSize));
|
|
5446
|
-
const spatialFilterCells = new Set(
|
|
5447
|
-
geometryToCells2(options.spatialFilter, cellResolution)
|
|
5448
|
-
);
|
|
5449
5505
|
const data = /* @__PURE__ */ new Map();
|
|
5450
5506
|
for (const tile of tiles) {
|
|
5451
5507
|
const parent = tile.index.q;
|
|
5452
|
-
const
|
|
5453
|
-
|
|
5454
|
-
|
|
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
|
+
}
|
|
5455
5519
|
const cellData = {};
|
|
5456
5520
|
let cellDataExists = false;
|
|
5457
5521
|
for (const band in tile.data.cells.numericProps) {
|
|
@@ -5463,7 +5527,7 @@ function tileFeaturesRaster({
|
|
|
5463
5527
|
}
|
|
5464
5528
|
}
|
|
5465
5529
|
if (cellDataExists) {
|
|
5466
|
-
data.set(
|
|
5530
|
+
data.set(tileSortedCells[i], cellData);
|
|
5467
5531
|
}
|
|
5468
5532
|
}
|
|
5469
5533
|
}
|
|
@@ -6264,7 +6328,7 @@ var WidgetRemoteSource = class extends WidgetSource {
|
|
|
6264
6328
|
...params
|
|
6265
6329
|
} = options;
|
|
6266
6330
|
const { column, operation: operation2, operationColumn, operationExp } = params;
|
|
6267
|
-
if (operation2 ===
|
|
6331
|
+
if (operation2 === AggregationTypes.Custom) {
|
|
6268
6332
|
assert2(operationExp, "operationExp is required for custom operation");
|
|
6269
6333
|
}
|
|
6270
6334
|
return executeModel({
|
|
@@ -6323,7 +6387,7 @@ var WidgetRemoteSource = class extends WidgetSource {
|
|
|
6323
6387
|
...params
|
|
6324
6388
|
} = options;
|
|
6325
6389
|
const { column, operation: operation2 } = params;
|
|
6326
|
-
if (operation2 ===
|
|
6390
|
+
if (operation2 === AggregationTypes.Custom) {
|
|
6327
6391
|
assert2(operationExp, "operationExp is required for custom operation");
|
|
6328
6392
|
}
|
|
6329
6393
|
return executeModel({
|
|
@@ -6335,7 +6399,7 @@ var WidgetRemoteSource = class extends WidgetSource {
|
|
|
6335
6399
|
},
|
|
6336
6400
|
params: {
|
|
6337
6401
|
column: column ?? "*",
|
|
6338
|
-
operation: operation2 ??
|
|
6402
|
+
operation: operation2 ?? AggregationTypes.Count,
|
|
6339
6403
|
operationExp
|
|
6340
6404
|
},
|
|
6341
6405
|
opts: { signal, headers: this.props.headers }
|
|
@@ -6471,7 +6535,7 @@ var WidgetRemoteSource = class extends WidgetSource {
|
|
|
6471
6535
|
splitByCategoryLimit,
|
|
6472
6536
|
splitByCategoryValues
|
|
6473
6537
|
} = params;
|
|
6474
|
-
if (operation2 ===
|
|
6538
|
+
if (operation2 === AggregationTypes.Custom) {
|
|
6475
6539
|
assert2(operationExp, "operationExp is required for custom operation");
|
|
6476
6540
|
}
|
|
6477
6541
|
return executeModel({
|
|
@@ -7172,7 +7236,7 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
|
|
|
7172
7236
|
}
|
|
7173
7237
|
_extractTileFeatures(spatialFilter) {
|
|
7174
7238
|
const prevInputs = this._tileFeatureExtractPreviousInputs;
|
|
7175
|
-
if (this._features.length &&
|
|
7239
|
+
if (this._features.length && spatialFilterEquals(prevInputs.spatialFilter, spatialFilter)) {
|
|
7176
7240
|
return;
|
|
7177
7241
|
}
|
|
7178
7242
|
this._features = tileFeatures({
|
|
@@ -7203,7 +7267,7 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
|
|
|
7203
7267
|
}
|
|
7204
7268
|
async getFormula({
|
|
7205
7269
|
column = "*",
|
|
7206
|
-
operation: operation2 =
|
|
7270
|
+
operation: operation2 = AggregationTypes.Count,
|
|
7207
7271
|
joinOperation,
|
|
7208
7272
|
filters,
|
|
7209
7273
|
filterOwner,
|
|
@@ -7214,13 +7278,13 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
|
|
|
7214
7278
|
filters,
|
|
7215
7279
|
filterOwner
|
|
7216
7280
|
);
|
|
7217
|
-
if (filteredFeatures.length === 0 && operation2 !==
|
|
7281
|
+
if (filteredFeatures.length === 0 && operation2 !== AggregationTypes.Count) {
|
|
7218
7282
|
return { value: null };
|
|
7219
7283
|
}
|
|
7220
|
-
if (operation2 ===
|
|
7284
|
+
if (operation2 === AggregationTypes.Custom) {
|
|
7221
7285
|
throw new Error("Custom aggregation not supported for tilesets");
|
|
7222
7286
|
}
|
|
7223
|
-
if (column && column !== "*" || operation2 !==
|
|
7287
|
+
if (column && column !== "*" || operation2 !== AggregationTypes.Count) {
|
|
7224
7288
|
assertColumn(this._features, column);
|
|
7225
7289
|
}
|
|
7226
7290
|
const targetOperation = aggregationFunctions[operation2];
|
|
@@ -7229,7 +7293,7 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
|
|
|
7229
7293
|
};
|
|
7230
7294
|
}
|
|
7231
7295
|
async getHistogram({
|
|
7232
|
-
operation: operation2 =
|
|
7296
|
+
operation: operation2 = AggregationTypes.Count,
|
|
7233
7297
|
ticks,
|
|
7234
7298
|
column,
|
|
7235
7299
|
joinOperation,
|
|
@@ -7256,7 +7320,7 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
|
|
|
7256
7320
|
}
|
|
7257
7321
|
async getCategories({
|
|
7258
7322
|
column,
|
|
7259
|
-
operation: operation2 =
|
|
7323
|
+
operation: operation2 = AggregationTypes.Count,
|
|
7260
7324
|
operationColumn,
|
|
7261
7325
|
joinOperation,
|
|
7262
7326
|
filters,
|
|
@@ -7412,7 +7476,6 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
|
|
|
7412
7476
|
* INTERNAL
|
|
7413
7477
|
*/
|
|
7414
7478
|
_getFilteredFeatures(spatialFilter, filters, filterOwner) {
|
|
7415
|
-
assert2(spatialFilter, "spatialFilter required for tilesets");
|
|
7416
7479
|
this._extractTileFeatures(spatialFilter);
|
|
7417
7480
|
return applyFilters(
|
|
7418
7481
|
this._features,
|
|
@@ -7436,6 +7499,11 @@ function assertColumn(features, ...columnArgs) {
|
|
|
7436
7499
|
function normalizeColumns(columns) {
|
|
7437
7500
|
return Array.isArray(columns) ? columns : typeof columns === "string" ? [columns] : [];
|
|
7438
7501
|
}
|
|
7502
|
+
function spatialFilterEquals(a, b) {
|
|
7503
|
+
if (a === b) return true;
|
|
7504
|
+
if (!a || !b) return false;
|
|
7505
|
+
return booleanEqual(a, b);
|
|
7506
|
+
}
|
|
7439
7507
|
|
|
7440
7508
|
// src/widget-sources/widget-tileset-source.ts
|
|
7441
7509
|
var WidgetTilesetSource = class extends WidgetSource {
|
|
@@ -8976,7 +9044,7 @@ function negateAccessor(accessor) {
|
|
|
8976
9044
|
function getSizeAccessor({ name }, scaleType, aggregation, range, data) {
|
|
8977
9045
|
const scale2 = scaleType ? SCALE_FUNCS[scaleType]() : identity2;
|
|
8978
9046
|
if (scaleType) {
|
|
8979
|
-
if (aggregation !==
|
|
9047
|
+
if (aggregation !== AggregationTypes.Count) {
|
|
8980
9048
|
scale2.domain(calculateDomain(data, name, scaleType));
|
|
8981
9049
|
}
|
|
8982
9050
|
scale2.range(range);
|
|
@@ -9955,10 +10023,68 @@ function _getHexagonResolution(viewport, tileSize) {
|
|
|
9955
10023
|
Math.floor(hexagonScaleFactor + latitudeScaleFactor - BIAS)
|
|
9956
10024
|
);
|
|
9957
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
|
+
}
|
|
9958
10082
|
export {
|
|
10083
|
+
AggregationTypes,
|
|
9959
10084
|
ApiVersion,
|
|
9960
10085
|
basemap_styles_default as BASEMAP,
|
|
9961
10086
|
CartoAPIError,
|
|
10087
|
+
CellSet,
|
|
9962
10088
|
DEFAULT_API_BASE_URL,
|
|
9963
10089
|
FEATURE_GEOM_PROPERTY,
|
|
9964
10090
|
FilterType,
|