@carto/api-client 0.5.0-alpha.1 → 0.5.0-alpha.11
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 +4 -0
- package/build/api-client.cjs +3163 -3206
- package/build/api-client.cjs.map +1 -1
- package/build/api-client.d.cts +1389 -0
- package/build/api-client.d.ts +1389 -0
- package/build/api-client.js +3674 -0
- package/build/api-client.js.map +1 -0
- package/build/worker.d.ts +2 -0
- package/build/worker.js +1949 -0
- package/build/worker.js.map +1 -0
- package/package.json +60 -45
- package/src/api/carto-api-error.ts +1 -1
- package/src/api/query.ts +5 -5
- package/src/api/request-with-parameters.ts +6 -6
- package/src/client.ts +3 -3
- package/src/constants-internal.ts +5 -11
- package/src/constants.ts +6 -6
- package/src/deck/get-data-filter-extension-props.ts +146 -0
- package/src/deck/index.ts +1 -0
- package/src/filters/Filter.ts +18 -8
- package/src/filters/FilterTypes.ts +2 -2
- package/src/filters/geosjonFeatures.ts +2 -2
- package/src/filters/tileFeatures.ts +12 -17
- package/src/filters.ts +4 -4
- package/src/geo.ts +12 -14
- package/src/global.d.ts +3 -8
- package/src/index.ts +3 -0
- package/src/models/common.ts +11 -9
- package/src/models/model.ts +3 -4
- package/src/operations/aggregation.ts +5 -5
- package/src/operations/applySorting.ts +4 -4
- package/src/operations/groupBy.ts +4 -4
- package/src/operations/groupByDate.ts +1 -1
- package/src/operations/histogram.ts +4 -4
- package/src/operations/scatterPlot.ts +4 -4
- package/src/sources/base-source.ts +8 -8
- package/src/sources/boundary-query-source.ts +2 -2
- package/src/sources/boundary-table-source.ts +2 -2
- package/src/sources/h3-query-source.ts +7 -5
- package/src/sources/h3-table-source.ts +7 -5
- package/src/sources/h3-tileset-source.ts +4 -4
- package/src/sources/index.ts +26 -26
- package/src/sources/quadbin-query-source.ts +7 -5
- package/src/sources/quadbin-table-source.ts +7 -5
- package/src/sources/quadbin-tileset-source.ts +4 -4
- package/src/sources/raster-source.ts +2 -2
- package/src/sources/types.ts +9 -3
- package/src/sources/vector-query-source.ts +2 -3
- package/src/sources/vector-table-source.ts +2 -3
- package/src/sources/vector-tileset-source.ts +5 -5
- package/src/spatial-index.ts +12 -10
- package/src/types-internal.ts +5 -5
- package/src/types.ts +15 -15
- package/src/utils/makeIntervalComplete.ts +1 -1
- package/src/utils.ts +3 -3
- package/src/widget-sources/index.ts +1 -0
- package/src/widget-sources/types.ts +6 -4
- package/src/widget-sources/widget-query-source.ts +6 -2
- package/src/widget-sources/widget-remote-source.ts +67 -26
- package/src/widget-sources/widget-source.ts +10 -25
- package/src/widget-sources/widget-table-source.ts +6 -2
- package/src/widget-sources/widget-tileset-source-impl.ts +417 -0
- package/src/widget-sources/widget-tileset-source.ts +200 -299
- package/src/workers/constants.ts +13 -0
- package/src/workers/types.ts +19 -0
- package/src/workers/widget-tileset-worker.ts +40 -0
- package/build/api/carto-api-error.d.ts +0 -26
- package/build/api/endpoints.d.ts +0 -24
- package/build/api/index.d.ts +0 -5
- package/build/api/query.d.ts +0 -3
- package/build/api/request-with-parameters.d.ts +0 -10
- package/build/api-client.modern.js +0 -3574
- package/build/api-client.modern.js.map +0 -1
- package/build/client.d.ts +0 -14
- package/build/constants-internal.d.ts +0 -26
- package/build/constants.d.ts +0 -53
- package/build/filters/Filter.d.ts +0 -13
- package/build/filters/FilterTypes.d.ts +0 -3
- package/build/filters/geosjonFeatures.d.ts +0 -8
- package/build/filters/index.d.ts +0 -6
- package/build/filters/tileFeatures.d.ts +0 -20
- package/build/filters/tileFeaturesGeometries.d.ts +0 -13
- package/build/filters/tileFeaturesSpatialIndex.d.ts +0 -10
- package/build/filters.d.ts +0 -39
- package/build/geo.d.ts +0 -19
- package/build/index.d.ts +0 -14
- package/build/models/common.d.ts +0 -27
- package/build/models/index.d.ts +0 -3
- package/build/models/model.d.ts +0 -37
- package/build/operations/aggregation.d.ts +0 -8
- package/build/operations/applySorting.d.ts +0 -20
- package/build/operations/groupBy.d.ts +0 -15
- package/build/operations/groupByDate.d.ts +0 -11
- package/build/operations/histogram.d.ts +0 -13
- package/build/operations/index.d.ts +0 -6
- package/build/operations/scatterPlot.d.ts +0 -14
- package/build/sources/base-source.d.ts +0 -4
- package/build/sources/boundary-query-source.d.ts +0 -10
- package/build/sources/boundary-table-source.d.ts +0 -8
- package/build/sources/h3-query-source.d.ts +0 -5
- package/build/sources/h3-table-source.d.ts +0 -5
- package/build/sources/h3-tileset-source.d.ts +0 -5
- package/build/sources/index.d.ts +0 -26
- package/build/sources/quadbin-query-source.d.ts +0 -5
- package/build/sources/quadbin-table-source.d.ts +0 -5
- package/build/sources/quadbin-tileset-source.d.ts +0 -5
- package/build/sources/raster-source.d.ts +0 -4
- package/build/sources/types.d.ts +0 -366
- package/build/sources/vector-query-source.d.ts +0 -5
- package/build/sources/vector-table-source.d.ts +0 -5
- package/build/sources/vector-tileset-source.d.ts +0 -5
- package/build/spatial-index.d.ts +0 -8
- package/build/types-internal.d.ts +0 -56
- package/build/types.d.ts +0 -140
- package/build/utils/dateUtils.d.ts +0 -10
- package/build/utils/getTileFormat.d.ts +0 -3
- package/build/utils/makeIntervalComplete.d.ts +0 -2
- package/build/utils/transformTileCoordsToWGS84.d.ts +0 -8
- package/build/utils/transformToTileCoords.d.ts +0 -9
- package/build/utils.d.ts +0 -32
- package/build/widget-sources/index.d.ts +0 -5
- package/build/widget-sources/types.d.ts +0 -158
- package/build/widget-sources/widget-query-source.d.ts +0 -33
- package/build/widget-sources/widget-remote-source.d.ts +0 -18
- package/build/widget-sources/widget-source.d.ts +0 -74
- package/build/widget-sources/widget-table-source.d.ts +0 -33
- package/build/widget-sources/widget-tileset-source.d.ts +0 -76
|
@@ -0,0 +1,3674 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __commonJS = (cb, mod2) => function __require() {
|
|
9
|
+
return mod2 || (0, cb[__getOwnPropNames(cb)[0]])((mod2 = { exports: {} }).exports, mod2), mod2.exports;
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__getProtoOf(mod2)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod2 || !mod2.__esModule ? __defProp(target, "default", { value: mod2, enumerable: true }) : target,
|
|
25
|
+
mod2
|
|
26
|
+
));
|
|
27
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
28
|
+
|
|
29
|
+
// node_modules/tilebelt/index.js
|
|
30
|
+
var require_tilebelt = __commonJS({
|
|
31
|
+
"node_modules/tilebelt/index.js"(exports, module) {
|
|
32
|
+
"use strict";
|
|
33
|
+
var d2r = Math.PI / 180;
|
|
34
|
+
var r2d = 180 / Math.PI;
|
|
35
|
+
function tileToBBOX(tile) {
|
|
36
|
+
var e = tile2lon(tile[0] + 1, tile[2]);
|
|
37
|
+
var w = tile2lon(tile[0], tile[2]);
|
|
38
|
+
var s = tile2lat(tile[1] + 1, tile[2]);
|
|
39
|
+
var n = tile2lat(tile[1], tile[2]);
|
|
40
|
+
return [w, s, e, n];
|
|
41
|
+
}
|
|
42
|
+
function tileToGeoJSON(tile) {
|
|
43
|
+
var bbox = tileToBBOX(tile);
|
|
44
|
+
var poly = {
|
|
45
|
+
type: "Polygon",
|
|
46
|
+
coordinates: [
|
|
47
|
+
[
|
|
48
|
+
[bbox[0], bbox[1]],
|
|
49
|
+
[bbox[0], bbox[3]],
|
|
50
|
+
[bbox[2], bbox[3]],
|
|
51
|
+
[bbox[2], bbox[1]],
|
|
52
|
+
[bbox[0], bbox[1]]
|
|
53
|
+
]
|
|
54
|
+
]
|
|
55
|
+
};
|
|
56
|
+
return poly;
|
|
57
|
+
}
|
|
58
|
+
function tile2lon(x, z) {
|
|
59
|
+
return x / Math.pow(2, z) * 360 - 180;
|
|
60
|
+
}
|
|
61
|
+
function tile2lat(y, z) {
|
|
62
|
+
var n = Math.PI - 2 * Math.PI * y / Math.pow(2, z);
|
|
63
|
+
return r2d * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n)));
|
|
64
|
+
}
|
|
65
|
+
function pointToTile(lon, lat, z) {
|
|
66
|
+
var tile = pointToTileFraction(lon, lat, z);
|
|
67
|
+
tile[0] = Math.floor(tile[0]);
|
|
68
|
+
tile[1] = Math.floor(tile[1]);
|
|
69
|
+
return tile;
|
|
70
|
+
}
|
|
71
|
+
function getChildren(tile) {
|
|
72
|
+
return [
|
|
73
|
+
[tile[0] * 2, tile[1] * 2, tile[2] + 1],
|
|
74
|
+
[tile[0] * 2 + 1, tile[1] * 2, tile[2] + 1],
|
|
75
|
+
[tile[0] * 2 + 1, tile[1] * 2 + 1, tile[2] + 1],
|
|
76
|
+
[tile[0] * 2, tile[1] * 2 + 1, tile[2] + 1]
|
|
77
|
+
];
|
|
78
|
+
}
|
|
79
|
+
function getParent(tile) {
|
|
80
|
+
if (tile[0] % 2 === 0 && tile[1] % 2 === 0) {
|
|
81
|
+
return [tile[0] / 2, tile[1] / 2, tile[2] - 1];
|
|
82
|
+
} else if (tile[0] % 2 === 0 && !tile[1] % 2 === 0) {
|
|
83
|
+
return [tile[0] / 2, (tile[1] - 1) / 2, tile[2] - 1];
|
|
84
|
+
} else if (!tile[0] % 2 === 0 && tile[1] % 2 === 0) {
|
|
85
|
+
return [(tile[0] - 1) / 2, tile[1] / 2, tile[2] - 1];
|
|
86
|
+
} else {
|
|
87
|
+
return [(tile[0] - 1) / 2, (tile[1] - 1) / 2, tile[2] - 1];
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function getSiblings(tile) {
|
|
91
|
+
return getChildren(getParent(tile));
|
|
92
|
+
}
|
|
93
|
+
function hasSiblings(tile, tiles2) {
|
|
94
|
+
var siblings = getSiblings(tile);
|
|
95
|
+
for (var i = 0; i < siblings.length; i++) {
|
|
96
|
+
if (!hasTile(tiles2, siblings[i])) return false;
|
|
97
|
+
}
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
function hasTile(tiles2, tile) {
|
|
101
|
+
for (var i = 0; i < tiles2.length; i++) {
|
|
102
|
+
if (tilesEqual(tiles2[i], tile)) return true;
|
|
103
|
+
}
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
function tilesEqual(tile1, tile2) {
|
|
107
|
+
return tile1[0] === tile2[0] && tile1[1] === tile2[1] && tile1[2] === tile2[2];
|
|
108
|
+
}
|
|
109
|
+
function tileToQuadkey(tile) {
|
|
110
|
+
var index = "";
|
|
111
|
+
for (var z = tile[2]; z > 0; z--) {
|
|
112
|
+
var b = 0;
|
|
113
|
+
var mask = 1 << z - 1;
|
|
114
|
+
if ((tile[0] & mask) !== 0) b++;
|
|
115
|
+
if ((tile[1] & mask) !== 0) b += 2;
|
|
116
|
+
index += b.toString();
|
|
117
|
+
}
|
|
118
|
+
return index;
|
|
119
|
+
}
|
|
120
|
+
function quadkeyToTile(quadkey) {
|
|
121
|
+
var x = 0;
|
|
122
|
+
var y = 0;
|
|
123
|
+
var z = quadkey.length;
|
|
124
|
+
for (var i = z; i > 0; i--) {
|
|
125
|
+
var mask = 1 << i - 1;
|
|
126
|
+
switch (quadkey[z - i]) {
|
|
127
|
+
case "0":
|
|
128
|
+
break;
|
|
129
|
+
case "1":
|
|
130
|
+
x |= mask;
|
|
131
|
+
break;
|
|
132
|
+
case "2":
|
|
133
|
+
y |= mask;
|
|
134
|
+
break;
|
|
135
|
+
case "3":
|
|
136
|
+
x |= mask;
|
|
137
|
+
y |= mask;
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return [x, y, z];
|
|
142
|
+
}
|
|
143
|
+
function bboxToTile(bboxCoords) {
|
|
144
|
+
var min2 = pointToTile(bboxCoords[0], bboxCoords[1], 32);
|
|
145
|
+
var max2 = pointToTile(bboxCoords[2], bboxCoords[3], 32);
|
|
146
|
+
var bbox = [min2[0], min2[1], max2[0], max2[1]];
|
|
147
|
+
var z = getBboxZoom(bbox);
|
|
148
|
+
if (z === 0) return [0, 0, 0];
|
|
149
|
+
var x = bbox[0] >>> 32 - z;
|
|
150
|
+
var y = bbox[1] >>> 32 - z;
|
|
151
|
+
return [x, y, z];
|
|
152
|
+
}
|
|
153
|
+
function getBboxZoom(bbox) {
|
|
154
|
+
var MAX_ZOOM = 28;
|
|
155
|
+
for (var z = 0; z < MAX_ZOOM; z++) {
|
|
156
|
+
var mask = 1 << 32 - (z + 1);
|
|
157
|
+
if ((bbox[0] & mask) != (bbox[2] & mask) || (bbox[1] & mask) != (bbox[3] & mask)) {
|
|
158
|
+
return z;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return MAX_ZOOM;
|
|
162
|
+
}
|
|
163
|
+
function pointToTileFraction(lon, lat, z) {
|
|
164
|
+
var sin2 = Math.sin(lat * d2r), z2 = Math.pow(2, z), x = z2 * (lon / 360 + 0.5), y = z2 * (0.5 - 0.25 * Math.log((1 + sin2) / (1 - sin2)) / Math.PI);
|
|
165
|
+
return [x, y, z];
|
|
166
|
+
}
|
|
167
|
+
module.exports = {
|
|
168
|
+
tileToGeoJSON,
|
|
169
|
+
tileToBBOX,
|
|
170
|
+
getChildren,
|
|
171
|
+
getParent,
|
|
172
|
+
getSiblings,
|
|
173
|
+
hasTile,
|
|
174
|
+
hasSiblings,
|
|
175
|
+
tilesEqual,
|
|
176
|
+
tileToQuadkey,
|
|
177
|
+
quadkeyToTile,
|
|
178
|
+
pointToTile,
|
|
179
|
+
bboxToTile,
|
|
180
|
+
pointToTileFraction
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// node_modules/@mapbox/tile-cover/index.js
|
|
186
|
+
var require_tile_cover = __commonJS({
|
|
187
|
+
"node_modules/@mapbox/tile-cover/index.js"(exports) {
|
|
188
|
+
"use strict";
|
|
189
|
+
var tilebelt = require_tilebelt();
|
|
190
|
+
exports.geojson = function(geom, limits) {
|
|
191
|
+
return {
|
|
192
|
+
type: "FeatureCollection",
|
|
193
|
+
features: getTiles(geom, limits).map(tileToFeature)
|
|
194
|
+
};
|
|
195
|
+
};
|
|
196
|
+
function tileToFeature(t) {
|
|
197
|
+
return {
|
|
198
|
+
type: "Feature",
|
|
199
|
+
geometry: tilebelt.tileToGeoJSON(t),
|
|
200
|
+
properties: {}
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
exports.tiles = getTiles;
|
|
204
|
+
exports.indexes = function(geom, limits) {
|
|
205
|
+
return getTiles(geom, limits).map(tilebelt.tileToQuadkey);
|
|
206
|
+
};
|
|
207
|
+
function getTiles(geom, limits) {
|
|
208
|
+
var i, tile, coords = geom.coordinates, maxZoom = limits.max_zoom, tileHash = {}, tiles2 = [];
|
|
209
|
+
if (geom.type === "Point") {
|
|
210
|
+
return [tilebelt.pointToTile(coords[0], coords[1], maxZoom)];
|
|
211
|
+
} else if (geom.type === "MultiPoint") {
|
|
212
|
+
for (i = 0; i < coords.length; i++) {
|
|
213
|
+
tile = tilebelt.pointToTile(coords[i][0], coords[i][1], maxZoom);
|
|
214
|
+
tileHash[toID(tile[0], tile[1], tile[2])] = true;
|
|
215
|
+
}
|
|
216
|
+
} else if (geom.type === "LineString") {
|
|
217
|
+
lineCover(tileHash, coords, maxZoom);
|
|
218
|
+
} else if (geom.type === "MultiLineString") {
|
|
219
|
+
for (i = 0; i < coords.length; i++) {
|
|
220
|
+
lineCover(tileHash, coords[i], maxZoom);
|
|
221
|
+
}
|
|
222
|
+
} else if (geom.type === "Polygon") {
|
|
223
|
+
polygonCover(tileHash, tiles2, coords, maxZoom);
|
|
224
|
+
} else if (geom.type === "MultiPolygon") {
|
|
225
|
+
for (i = 0; i < coords.length; i++) {
|
|
226
|
+
polygonCover(tileHash, tiles2, coords[i], maxZoom);
|
|
227
|
+
}
|
|
228
|
+
} else {
|
|
229
|
+
throw new Error("Geometry type not implemented");
|
|
230
|
+
}
|
|
231
|
+
if (limits.min_zoom !== maxZoom) {
|
|
232
|
+
var len = tiles2.length;
|
|
233
|
+
appendHashTiles(tileHash, tiles2);
|
|
234
|
+
for (i = 0; i < len; i++) {
|
|
235
|
+
var t = tiles2[i];
|
|
236
|
+
tileHash[toID(t[0], t[1], t[2])] = true;
|
|
237
|
+
}
|
|
238
|
+
return mergeTiles(tileHash, tiles2, limits);
|
|
239
|
+
}
|
|
240
|
+
appendHashTiles(tileHash, tiles2);
|
|
241
|
+
return tiles2;
|
|
242
|
+
}
|
|
243
|
+
function mergeTiles(tileHash, tiles2, limits) {
|
|
244
|
+
var mergedTiles = [];
|
|
245
|
+
for (var z = limits.max_zoom; z > limits.min_zoom; z--) {
|
|
246
|
+
var parentTileHash = {};
|
|
247
|
+
var parentTiles = [];
|
|
248
|
+
for (var i = 0; i < tiles2.length; i++) {
|
|
249
|
+
var t = tiles2[i];
|
|
250
|
+
if (t[0] % 2 === 0 && t[1] % 2 === 0) {
|
|
251
|
+
var id2 = toID(t[0] + 1, t[1], z), id3 = toID(t[0], t[1] + 1, z), id4 = toID(t[0] + 1, t[1] + 1, z);
|
|
252
|
+
if (tileHash[id2] && tileHash[id3] && tileHash[id4]) {
|
|
253
|
+
tileHash[toID(t[0], t[1], t[2])] = false;
|
|
254
|
+
tileHash[id2] = false;
|
|
255
|
+
tileHash[id3] = false;
|
|
256
|
+
tileHash[id4] = false;
|
|
257
|
+
var parentTile = [t[0] / 2, t[1] / 2, z - 1];
|
|
258
|
+
if (z - 1 === limits.min_zoom) mergedTiles.push(parentTile);
|
|
259
|
+
else {
|
|
260
|
+
parentTileHash[toID(t[0] / 2, t[1] / 2, z - 1)] = true;
|
|
261
|
+
parentTiles.push(parentTile);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
for (i = 0; i < tiles2.length; i++) {
|
|
267
|
+
t = tiles2[i];
|
|
268
|
+
if (tileHash[toID(t[0], t[1], t[2])]) mergedTiles.push(t);
|
|
269
|
+
}
|
|
270
|
+
tileHash = parentTileHash;
|
|
271
|
+
tiles2 = parentTiles;
|
|
272
|
+
}
|
|
273
|
+
return mergedTiles;
|
|
274
|
+
}
|
|
275
|
+
function polygonCover(tileHash, tileArray, geom, zoom) {
|
|
276
|
+
var intersections = [];
|
|
277
|
+
for (var i = 0; i < geom.length; i++) {
|
|
278
|
+
var ring = [];
|
|
279
|
+
lineCover(tileHash, geom[i], zoom, ring);
|
|
280
|
+
for (var j = 0, len = ring.length, k = len - 1; j < len; k = j++) {
|
|
281
|
+
var m = (j + 1) % len;
|
|
282
|
+
var y = ring[j][1];
|
|
283
|
+
if ((y > ring[k][1] || y > ring[m][1]) && // not local minimum
|
|
284
|
+
(y < ring[k][1] || y < ring[m][1]) && // not local maximum
|
|
285
|
+
y !== ring[m][1]) intersections.push(ring[j]);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
intersections.sort(compareTiles);
|
|
289
|
+
for (i = 0; i < intersections.length; i += 2) {
|
|
290
|
+
y = intersections[i][1];
|
|
291
|
+
for (var x = intersections[i][0] + 1; x < intersections[i + 1][0]; x++) {
|
|
292
|
+
var id = toID(x, y, zoom);
|
|
293
|
+
if (!tileHash[id]) {
|
|
294
|
+
tileArray.push([x, y, zoom]);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
function compareTiles(a, b) {
|
|
300
|
+
return a[1] - b[1] || a[0] - b[0];
|
|
301
|
+
}
|
|
302
|
+
function lineCover(tileHash, coords, maxZoom, ring) {
|
|
303
|
+
var prevX, prevY;
|
|
304
|
+
for (var i = 0; i < coords.length - 1; i++) {
|
|
305
|
+
var start = tilebelt.pointToTileFraction(coords[i][0], coords[i][1], maxZoom), stop = tilebelt.pointToTileFraction(coords[i + 1][0], coords[i + 1][1], maxZoom), x0 = start[0], y0 = start[1], x1 = stop[0], y1 = stop[1], dx = x1 - x0, dy = y1 - y0;
|
|
306
|
+
if (dy === 0 && dx === 0) continue;
|
|
307
|
+
var sx = dx > 0 ? 1 : -1, sy = dy > 0 ? 1 : -1, x = Math.floor(x0), y = Math.floor(y0), tMaxX = dx === 0 ? Infinity : Math.abs(((dx > 0 ? 1 : 0) + x - x0) / dx), tMaxY = dy === 0 ? Infinity : Math.abs(((dy > 0 ? 1 : 0) + y - y0) / dy), tdx = Math.abs(sx / dx), tdy = Math.abs(sy / dy);
|
|
308
|
+
if (x !== prevX || y !== prevY) {
|
|
309
|
+
tileHash[toID(x, y, maxZoom)] = true;
|
|
310
|
+
if (ring && y !== prevY) ring.push([x, y]);
|
|
311
|
+
prevX = x;
|
|
312
|
+
prevY = y;
|
|
313
|
+
}
|
|
314
|
+
while (tMaxX < 1 || tMaxY < 1) {
|
|
315
|
+
if (tMaxX < tMaxY) {
|
|
316
|
+
tMaxX += tdx;
|
|
317
|
+
x += sx;
|
|
318
|
+
} else {
|
|
319
|
+
tMaxY += tdy;
|
|
320
|
+
y += sy;
|
|
321
|
+
}
|
|
322
|
+
tileHash[toID(x, y, maxZoom)] = true;
|
|
323
|
+
if (ring && y !== prevY) ring.push([x, y]);
|
|
324
|
+
prevX = x;
|
|
325
|
+
prevY = y;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
if (ring && y === ring[0][1]) ring.pop();
|
|
329
|
+
}
|
|
330
|
+
function appendHashTiles(hash, tiles2) {
|
|
331
|
+
var keys = Object.keys(hash);
|
|
332
|
+
for (var i = 0; i < keys.length; i++) {
|
|
333
|
+
tiles2.push(fromID(+keys[i]));
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
function toID(x, y, z) {
|
|
337
|
+
var dim = 2 * (1 << z);
|
|
338
|
+
return (dim * y + x) * 32 + z;
|
|
339
|
+
}
|
|
340
|
+
function fromID(id) {
|
|
341
|
+
var z = id % 32, dim = 2 * (1 << z), xy = (id - z) / 32, x = xy % dim, y = (xy - x) / dim % dim;
|
|
342
|
+
return [x, y, z];
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
// node_modules/thenby/thenBy.module.js
|
|
348
|
+
var require_thenBy_module = __commonJS({
|
|
349
|
+
"node_modules/thenby/thenBy.module.js"(exports, module) {
|
|
350
|
+
"use strict";
|
|
351
|
+
module.exports = function() {
|
|
352
|
+
function identity(v) {
|
|
353
|
+
return v;
|
|
354
|
+
}
|
|
355
|
+
function ignoreCase(v) {
|
|
356
|
+
return typeof v === "string" ? v.toLowerCase() : v;
|
|
357
|
+
}
|
|
358
|
+
function makeCompareFunction(f, opt) {
|
|
359
|
+
opt = typeof opt === "object" ? opt : { direction: opt };
|
|
360
|
+
if (typeof f != "function") {
|
|
361
|
+
var prop = f;
|
|
362
|
+
f = function(v1) {
|
|
363
|
+
return !!v1[prop] ? v1[prop] : "";
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
if (f.length === 1) {
|
|
367
|
+
var uf = f;
|
|
368
|
+
var preprocess = opt.ignoreCase ? ignoreCase : identity;
|
|
369
|
+
var cmp = opt.cmp || function(v1, v2) {
|
|
370
|
+
return v1 < v2 ? -1 : v1 > v2 ? 1 : 0;
|
|
371
|
+
};
|
|
372
|
+
f = function(v1, v2) {
|
|
373
|
+
return cmp(preprocess(uf(v1)), preprocess(uf(v2)));
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
const descTokens = { "-1": "", desc: "" };
|
|
377
|
+
if (opt.direction in descTokens) return function(v1, v2) {
|
|
378
|
+
return -f(v1, v2);
|
|
379
|
+
};
|
|
380
|
+
return f;
|
|
381
|
+
}
|
|
382
|
+
function tb(func, opt) {
|
|
383
|
+
var x = typeof this == "function" && !this.firstBy ? this : false;
|
|
384
|
+
var y = makeCompareFunction(func, opt);
|
|
385
|
+
var f = x ? function(a, b) {
|
|
386
|
+
return x(a, b) || y(a, b);
|
|
387
|
+
} : y;
|
|
388
|
+
f.thenBy = tb;
|
|
389
|
+
return f;
|
|
390
|
+
}
|
|
391
|
+
tb.firstBy = tb;
|
|
392
|
+
return tb;
|
|
393
|
+
}();
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
// src/client.ts
|
|
398
|
+
var client = "deck-gl-carto";
|
|
399
|
+
function getClient() {
|
|
400
|
+
return client;
|
|
401
|
+
}
|
|
402
|
+
function setClient(c) {
|
|
403
|
+
client = c;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// src/constants.ts
|
|
407
|
+
var FilterType = /* @__PURE__ */ ((FilterType2) => {
|
|
408
|
+
FilterType2["IN"] = "in";
|
|
409
|
+
FilterType2["BETWEEN"] = "between";
|
|
410
|
+
FilterType2["CLOSED_OPEN"] = "closed_open";
|
|
411
|
+
FilterType2["TIME"] = "time";
|
|
412
|
+
FilterType2["STRING_SEARCH"] = "stringSearch";
|
|
413
|
+
return FilterType2;
|
|
414
|
+
})(FilterType || {});
|
|
415
|
+
var ApiVersion = /* @__PURE__ */ ((ApiVersion2) => {
|
|
416
|
+
ApiVersion2["V1"] = "v1";
|
|
417
|
+
ApiVersion2["V2"] = "v2";
|
|
418
|
+
ApiVersion2["V3"] = "v3";
|
|
419
|
+
return ApiVersion2;
|
|
420
|
+
})(ApiVersion || {});
|
|
421
|
+
var DEFAULT_API_BASE_URL = "https://gcp-us-east1.api.carto.com";
|
|
422
|
+
var TileFormat = /* @__PURE__ */ ((TileFormat2) => {
|
|
423
|
+
TileFormat2["MVT"] = "mvt";
|
|
424
|
+
TileFormat2["JSON"] = "json";
|
|
425
|
+
TileFormat2["GEOJSON"] = "geojson";
|
|
426
|
+
TileFormat2["BINARY"] = "binary";
|
|
427
|
+
return TileFormat2;
|
|
428
|
+
})(TileFormat || {});
|
|
429
|
+
var SpatialIndex = /* @__PURE__ */ ((SpatialIndex2) => {
|
|
430
|
+
SpatialIndex2["H3"] = "h3";
|
|
431
|
+
SpatialIndex2["S2"] = "s2";
|
|
432
|
+
SpatialIndex2["QUADBIN"] = "quadbin";
|
|
433
|
+
return SpatialIndex2;
|
|
434
|
+
})(SpatialIndex || {});
|
|
435
|
+
var Provider = /* @__PURE__ */ ((Provider2) => {
|
|
436
|
+
Provider2["BIGQUERY"] = "bigquery";
|
|
437
|
+
Provider2["REDSHIFT"] = "redshift";
|
|
438
|
+
Provider2["POSTGRES"] = "postgres";
|
|
439
|
+
Provider2["SNOWFLAKE"] = "snowflake";
|
|
440
|
+
Provider2["DATABRICKS"] = "databricks";
|
|
441
|
+
Provider2["DATABRICKS_REST"] = "databricksRest";
|
|
442
|
+
return Provider2;
|
|
443
|
+
})(Provider || {});
|
|
444
|
+
|
|
445
|
+
// src/utils/makeIntervalComplete.ts
|
|
446
|
+
function makeIntervalComplete(intervals) {
|
|
447
|
+
return intervals.map((val) => {
|
|
448
|
+
if (val[0] === void 0 || val[0] === null) {
|
|
449
|
+
return [Number.MIN_SAFE_INTEGER, val[1]];
|
|
450
|
+
}
|
|
451
|
+
if (val[1] === void 0 || val[1] === null) {
|
|
452
|
+
return [val[0], Number.MAX_SAFE_INTEGER];
|
|
453
|
+
}
|
|
454
|
+
return val;
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// src/filters/FilterTypes.ts
|
|
459
|
+
var filterFunctions = {
|
|
460
|
+
["in" /* IN */]: filterIn,
|
|
461
|
+
["between" /* BETWEEN */]: filterBetween,
|
|
462
|
+
["time" /* TIME */]: filterTime,
|
|
463
|
+
["closed_open" /* CLOSED_OPEN */]: filterClosedOpen,
|
|
464
|
+
["stringSearch" /* STRING_SEARCH */]: filterStringSearch
|
|
465
|
+
};
|
|
466
|
+
function filterIn(filterValues, featureValue) {
|
|
467
|
+
return filterValues.includes(featureValue);
|
|
468
|
+
}
|
|
469
|
+
function filterBetween(filterValues, featureValue) {
|
|
470
|
+
const checkRange = (range) => {
|
|
471
|
+
const [lowerBound, upperBound] = range;
|
|
472
|
+
return featureValue >= lowerBound && featureValue <= upperBound;
|
|
473
|
+
};
|
|
474
|
+
return makeIntervalComplete(filterValues).some(
|
|
475
|
+
checkRange
|
|
476
|
+
);
|
|
477
|
+
}
|
|
478
|
+
function filterTime(filterValues, featureValue) {
|
|
479
|
+
const featureValueAsTimestamp = new Date(featureValue).getTime();
|
|
480
|
+
if (isFinite(featureValueAsTimestamp)) {
|
|
481
|
+
return filterBetween(filterValues, featureValueAsTimestamp);
|
|
482
|
+
} else {
|
|
483
|
+
throw new Error(`Column used to filter by time isn't well formatted.`);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
function filterClosedOpen(filterValues, featureValue) {
|
|
487
|
+
const checkRange = (range) => {
|
|
488
|
+
const [lowerBound, upperBound] = range;
|
|
489
|
+
return featureValue >= lowerBound && featureValue < upperBound;
|
|
490
|
+
};
|
|
491
|
+
return makeIntervalComplete(filterValues).some(
|
|
492
|
+
checkRange
|
|
493
|
+
);
|
|
494
|
+
}
|
|
495
|
+
function filterStringSearch(filterValues, featureValue, params = {}) {
|
|
496
|
+
const normalizedFeatureValue = normalize(featureValue, params);
|
|
497
|
+
const stringRegExp = params.useRegExp ? filterValues : filterValues.map((filterValue) => {
|
|
498
|
+
let stringRegExp2 = escapeRegExp(normalize(filterValue, params));
|
|
499
|
+
if (params.mustStart) stringRegExp2 = `^${stringRegExp2}`;
|
|
500
|
+
if (params.mustEnd) stringRegExp2 = `${stringRegExp2}$`;
|
|
501
|
+
return stringRegExp2;
|
|
502
|
+
});
|
|
503
|
+
const regex = new RegExp(
|
|
504
|
+
stringRegExp.join("|"),
|
|
505
|
+
params.caseSensitive ? "g" : "gi"
|
|
506
|
+
);
|
|
507
|
+
return !!normalizedFeatureValue.match(regex);
|
|
508
|
+
}
|
|
509
|
+
var specialCharRegExp = /[.*+?^${}()|[\]\\]/g;
|
|
510
|
+
var normalizeRegExp = /\p{Diacritic}/gu;
|
|
511
|
+
function escapeRegExp(value) {
|
|
512
|
+
return value.replace(specialCharRegExp, "\\$&");
|
|
513
|
+
}
|
|
514
|
+
function normalize(data, params) {
|
|
515
|
+
let normalizedData = String(data);
|
|
516
|
+
if (!params.keepSpecialCharacters)
|
|
517
|
+
normalizedData = normalizedData.normalize("NFD").replace(normalizeRegExp, "");
|
|
518
|
+
return normalizedData;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
// src/filters/Filter.ts
|
|
522
|
+
var LOGICAL_OPERATOR_METHODS = {
|
|
523
|
+
and: "every",
|
|
524
|
+
or: "some"
|
|
525
|
+
};
|
|
526
|
+
function passesFilter(columns, filters, feature2, filtersLogicalOperator) {
|
|
527
|
+
const method = LOGICAL_OPERATOR_METHODS[filtersLogicalOperator];
|
|
528
|
+
return columns[method]((column) => {
|
|
529
|
+
const columnFilters = filters[column];
|
|
530
|
+
const columnFilterTypes = Object.keys(columnFilters);
|
|
531
|
+
if (!feature2 || feature2[column] === null || feature2[column] === void 0) {
|
|
532
|
+
return false;
|
|
533
|
+
}
|
|
534
|
+
return columnFilterTypes.every((filter) => {
|
|
535
|
+
const filterFunction = filterFunctions[filter];
|
|
536
|
+
if (!filterFunction) {
|
|
537
|
+
throw new Error(`"${filter}" filter is not implemented.`);
|
|
538
|
+
}
|
|
539
|
+
return filterFunction(
|
|
540
|
+
columnFilters[filter].values,
|
|
541
|
+
feature2[column],
|
|
542
|
+
columnFilters[filter].params
|
|
543
|
+
);
|
|
544
|
+
});
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
function _buildFeatureFilter({
|
|
548
|
+
filters = {},
|
|
549
|
+
type = "boolean",
|
|
550
|
+
filtersLogicalOperator = "and"
|
|
551
|
+
}) {
|
|
552
|
+
const columns = Object.keys(filters);
|
|
553
|
+
if (!columns.length) {
|
|
554
|
+
return () => type === "number" ? 1 : true;
|
|
555
|
+
}
|
|
556
|
+
return (feature2) => {
|
|
557
|
+
const f = feature2.properties || feature2;
|
|
558
|
+
const featurePassesFilter = passesFilter(
|
|
559
|
+
columns,
|
|
560
|
+
filters,
|
|
561
|
+
f,
|
|
562
|
+
filtersLogicalOperator
|
|
563
|
+
);
|
|
564
|
+
return type === "number" ? Number(featurePassesFilter) : featurePassesFilter;
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
function applyFilters(features, filters, filtersLogicalOperator) {
|
|
568
|
+
return Object.keys(filters).length ? features.filter(_buildFeatureFilter({ filters, filtersLogicalOperator })) : features;
|
|
569
|
+
}
|
|
570
|
+
function buildBinaryFeatureFilter({ filters = {} }) {
|
|
571
|
+
const columns = Object.keys(filters);
|
|
572
|
+
if (!columns.length) {
|
|
573
|
+
return () => 1;
|
|
574
|
+
}
|
|
575
|
+
return (featureIdIdx, binaryData) => passesFilterUsingBinary(columns, filters, featureIdIdx, binaryData);
|
|
576
|
+
}
|
|
577
|
+
function getValueFromNumericProps(featureIdIdx, binaryData, { column }) {
|
|
578
|
+
return binaryData.numericProps?.[column]?.value[featureIdIdx];
|
|
579
|
+
}
|
|
580
|
+
function getValueFromProperties(featureIdIdx, binaryData, { column }) {
|
|
581
|
+
const propertyIdx = binaryData.featureIds.value[featureIdIdx];
|
|
582
|
+
return binaryData.properties[propertyIdx]?.[column];
|
|
583
|
+
}
|
|
584
|
+
var GET_VALUE_BY_BINARY_PROP = {
|
|
585
|
+
properties: getValueFromProperties,
|
|
586
|
+
numericProps: getValueFromNumericProps
|
|
587
|
+
};
|
|
588
|
+
function getBinaryPropertyByFilterValues(filterValues) {
|
|
589
|
+
return typeof filterValues.flat()[0] === "string" ? "properties" : "numericProps";
|
|
590
|
+
}
|
|
591
|
+
function getFeatureValue(featureIdIdx, binaryData, filter) {
|
|
592
|
+
const { column, values } = filter;
|
|
593
|
+
const binaryProp = getBinaryPropertyByFilterValues(values);
|
|
594
|
+
const getFeatureValueFn = GET_VALUE_BY_BINARY_PROP[binaryProp];
|
|
595
|
+
return getFeatureValueFn(featureIdIdx, binaryData, { column });
|
|
596
|
+
}
|
|
597
|
+
function passesFilterUsingBinary(columns, filters, featureIdIdx, binaryData) {
|
|
598
|
+
return columns.every((column) => {
|
|
599
|
+
const columnFilters = filters[column];
|
|
600
|
+
return Object.entries(columnFilters).every(([type, { values }]) => {
|
|
601
|
+
const filterFn = filterFunctions[type];
|
|
602
|
+
if (!filterFn) {
|
|
603
|
+
throw new Error(`"${type}" filter is not implemented.`);
|
|
604
|
+
}
|
|
605
|
+
if (!values) return 0;
|
|
606
|
+
const featureValue = getFeatureValue(featureIdIdx, binaryData, {
|
|
607
|
+
type,
|
|
608
|
+
column,
|
|
609
|
+
values
|
|
610
|
+
});
|
|
611
|
+
if (featureValue === void 0 || featureValue === null) return 0;
|
|
612
|
+
return filterFn(values, featureValue);
|
|
613
|
+
});
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
// src/filters/geosjonFeatures.ts
|
|
618
|
+
import intersects from "@turf/boolean-intersects";
|
|
619
|
+
function geojsonFeatures({
|
|
620
|
+
geojson,
|
|
621
|
+
spatialFilter,
|
|
622
|
+
uniqueIdProperty
|
|
623
|
+
}) {
|
|
624
|
+
let uniqueIdx = 0;
|
|
625
|
+
const map = /* @__PURE__ */ new Map();
|
|
626
|
+
if (!spatialFilter) {
|
|
627
|
+
return [];
|
|
628
|
+
}
|
|
629
|
+
for (const feature2 of geojson.features) {
|
|
630
|
+
const uniqueId = uniqueIdProperty ? feature2.properties[uniqueIdProperty] : ++uniqueIdx;
|
|
631
|
+
if (!map.has(uniqueId) && intersects(spatialFilter, feature2)) {
|
|
632
|
+
map.set(uniqueId, feature2.properties);
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
return Array.from(map.values());
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
// src/filters/tileFeaturesGeometries.ts
|
|
639
|
+
import bboxPolygon from "@turf/bbox-polygon";
|
|
640
|
+
import intersects2 from "@turf/boolean-intersects";
|
|
641
|
+
import booleanWithin from "@turf/boolean-within";
|
|
642
|
+
import intersect from "@turf/intersect";
|
|
643
|
+
|
|
644
|
+
// node_modules/@math.gl/core/dist/lib/common.js
|
|
645
|
+
var RADIANS_TO_DEGREES = 1 / Math.PI * 180;
|
|
646
|
+
var DEGREES_TO_RADIANS = 1 / 180 * Math.PI;
|
|
647
|
+
var DEFAULT_CONFIG = {
|
|
648
|
+
EPSILON: 1e-12,
|
|
649
|
+
debug: false,
|
|
650
|
+
precision: 4,
|
|
651
|
+
printTypes: false,
|
|
652
|
+
printDegrees: false,
|
|
653
|
+
printRowMajor: true,
|
|
654
|
+
_cartographicRadians: false
|
|
655
|
+
};
|
|
656
|
+
globalThis.mathgl = globalThis.mathgl || { config: { ...DEFAULT_CONFIG } };
|
|
657
|
+
var config = globalThis.mathgl.config;
|
|
658
|
+
function isArray(value) {
|
|
659
|
+
return Array.isArray(value) || ArrayBuffer.isView(value) && !(value instanceof DataView);
|
|
660
|
+
}
|
|
661
|
+
function lerp(a, b, t) {
|
|
662
|
+
if (isArray(a)) {
|
|
663
|
+
return a.map((ai, i) => lerp(ai, b[i], t));
|
|
664
|
+
}
|
|
665
|
+
return t * b + (1 - t) * a;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
// node_modules/@math.gl/web-mercator/dist/assert.js
|
|
669
|
+
function assert(condition, message) {
|
|
670
|
+
if (!condition) {
|
|
671
|
+
throw new Error(message || "@math.gl/web-mercator: assertion failed.");
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
// node_modules/@math.gl/web-mercator/dist/web-mercator-utils.js
|
|
676
|
+
var PI = Math.PI;
|
|
677
|
+
var PI_4 = PI / 4;
|
|
678
|
+
var DEGREES_TO_RADIANS2 = PI / 180;
|
|
679
|
+
var RADIANS_TO_DEGREES2 = 180 / PI;
|
|
680
|
+
var TILE_SIZE = 512;
|
|
681
|
+
function lngLatToWorld(lngLat) {
|
|
682
|
+
const [lng, lat] = lngLat;
|
|
683
|
+
assert(Number.isFinite(lng));
|
|
684
|
+
assert(Number.isFinite(lat) && lat >= -90 && lat <= 90, "invalid latitude");
|
|
685
|
+
const lambda2 = lng * DEGREES_TO_RADIANS2;
|
|
686
|
+
const phi2 = lat * DEGREES_TO_RADIANS2;
|
|
687
|
+
const x = TILE_SIZE * (lambda2 + PI) / (2 * PI);
|
|
688
|
+
const y = TILE_SIZE * (PI + Math.log(Math.tan(PI_4 + phi2 * 0.5))) / (2 * PI);
|
|
689
|
+
return [x, y];
|
|
690
|
+
}
|
|
691
|
+
function worldToLngLat(xy) {
|
|
692
|
+
const [x, y] = xy;
|
|
693
|
+
const lambda2 = x / TILE_SIZE * (2 * PI) - PI;
|
|
694
|
+
const phi2 = 2 * (Math.atan(Math.exp(y / TILE_SIZE * (2 * PI) - PI)) - PI_4);
|
|
695
|
+
return [lambda2 * RADIANS_TO_DEGREES2, phi2 * RADIANS_TO_DEGREES2];
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
// node_modules/@math.gl/web-mercator/dist/get-bounds.js
|
|
699
|
+
var DEGREES_TO_RADIANS3 = Math.PI / 180;
|
|
700
|
+
|
|
701
|
+
// src/utils/transformToTileCoords.ts
|
|
702
|
+
var TRANSFORM_FN = {
|
|
703
|
+
Point: transformPoint,
|
|
704
|
+
MultiPoint: transformMultiPoint,
|
|
705
|
+
LineString: transformLineString,
|
|
706
|
+
MultiLineString: transformMultiLineString,
|
|
707
|
+
Polygon: transformPolygon,
|
|
708
|
+
MultiPolygon: transformMultiPolygon
|
|
709
|
+
};
|
|
710
|
+
function transformToTileCoords(geometry, bbox) {
|
|
711
|
+
const [west, south, east, north] = bbox;
|
|
712
|
+
const nw = projectFlat([west, north]);
|
|
713
|
+
const se = projectFlat([east, south]);
|
|
714
|
+
const projectedBbox = [nw, se];
|
|
715
|
+
if (geometry.type === "GeometryCollection") {
|
|
716
|
+
throw new Error("Unsupported geometry type GeometryCollection");
|
|
717
|
+
}
|
|
718
|
+
const transformFn = TRANSFORM_FN[geometry.type];
|
|
719
|
+
const coordinates = transformFn(geometry.coordinates, projectedBbox);
|
|
720
|
+
return { ...geometry, coordinates };
|
|
721
|
+
}
|
|
722
|
+
function transformPoint([pointX, pointY], [nw, se]) {
|
|
723
|
+
const x = inverseLerp(nw[0], se[0], pointX);
|
|
724
|
+
const y = inverseLerp(nw[1], se[1], pointY);
|
|
725
|
+
return [x, y];
|
|
726
|
+
}
|
|
727
|
+
function getPoints(geometry, bbox) {
|
|
728
|
+
return geometry.map((g) => transformPoint(projectFlat(g), bbox));
|
|
729
|
+
}
|
|
730
|
+
function transformMultiPoint(multiPoint, bbox) {
|
|
731
|
+
return getPoints(multiPoint, bbox);
|
|
732
|
+
}
|
|
733
|
+
function transformLineString(line, bbox) {
|
|
734
|
+
return getPoints(line, bbox);
|
|
735
|
+
}
|
|
736
|
+
function transformMultiLineString(multiLineString, bbox) {
|
|
737
|
+
return multiLineString.map(
|
|
738
|
+
(lineString) => transformLineString(lineString, bbox)
|
|
739
|
+
);
|
|
740
|
+
}
|
|
741
|
+
function transformPolygon(polygon2, bbox) {
|
|
742
|
+
return polygon2.map((polygonRing) => getPoints(polygonRing, bbox));
|
|
743
|
+
}
|
|
744
|
+
function transformMultiPolygon(multiPolygon2, bbox) {
|
|
745
|
+
return multiPolygon2.map((polygon2) => transformPolygon(polygon2, bbox));
|
|
746
|
+
}
|
|
747
|
+
function projectFlat(xyz) {
|
|
748
|
+
return lngLatToWorld(xyz);
|
|
749
|
+
}
|
|
750
|
+
function inverseLerp(a, b, x) {
|
|
751
|
+
return (x - a) / (b - a);
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
// src/utils/transformTileCoordsToWGS84.ts
|
|
755
|
+
var TRANSFORM_FN2 = {
|
|
756
|
+
Point: transformPoint2,
|
|
757
|
+
MultiPoint: transformMultiPoint2,
|
|
758
|
+
LineString: transformLineString2,
|
|
759
|
+
MultiLineString: transformMultiLineString2,
|
|
760
|
+
Polygon: transformPolygon2,
|
|
761
|
+
MultiPolygon: transformMultiPolygon2
|
|
762
|
+
};
|
|
763
|
+
function transformTileCoordsToWGS84(geometry, bbox) {
|
|
764
|
+
const [west, south, east, north] = bbox;
|
|
765
|
+
const nw = lngLatToWorld([west, north]);
|
|
766
|
+
const se = lngLatToWorld([east, south]);
|
|
767
|
+
const projectedBbox = [nw, se];
|
|
768
|
+
if (geometry.type === "GeometryCollection") {
|
|
769
|
+
throw new Error("Unsupported geometry type GeometryCollection");
|
|
770
|
+
}
|
|
771
|
+
const transformFn = TRANSFORM_FN2[geometry.type];
|
|
772
|
+
const coordinates = transformFn(geometry.coordinates, projectedBbox);
|
|
773
|
+
return { ...geometry, coordinates };
|
|
774
|
+
}
|
|
775
|
+
function transformPoint2([pointX, pointY], [nw, se]) {
|
|
776
|
+
const x = lerp(nw[0], se[0], pointX);
|
|
777
|
+
const y = lerp(nw[1], se[1], pointY);
|
|
778
|
+
return worldToLngLat([x, y]);
|
|
779
|
+
}
|
|
780
|
+
function getPoints2(geometry, bbox) {
|
|
781
|
+
return geometry.map((g) => transformPoint2(g, bbox));
|
|
782
|
+
}
|
|
783
|
+
function transformMultiPoint2(multiPoint, bbox) {
|
|
784
|
+
return getPoints2(multiPoint, bbox);
|
|
785
|
+
}
|
|
786
|
+
function transformLineString2(line, bbox) {
|
|
787
|
+
return getPoints2(line, bbox);
|
|
788
|
+
}
|
|
789
|
+
function transformMultiLineString2(multiLineString, bbox) {
|
|
790
|
+
return multiLineString.map(
|
|
791
|
+
(lineString) => transformLineString2(lineString, bbox)
|
|
792
|
+
);
|
|
793
|
+
}
|
|
794
|
+
function transformPolygon2(polygon2, bbox) {
|
|
795
|
+
return polygon2.map((polygonRing) => getPoints2(polygonRing, bbox));
|
|
796
|
+
}
|
|
797
|
+
function transformMultiPolygon2(multiPolygon2, bbox) {
|
|
798
|
+
return multiPolygon2.map((polygon2) => transformPolygon2(polygon2, bbox));
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
// src/filters/tileFeaturesGeometries.ts
|
|
802
|
+
import { featureCollection } from "@turf/helpers";
|
|
803
|
+
var FEATURE_GEOM_PROPERTY = "__geomValue";
|
|
804
|
+
function tileFeaturesGeometries({
|
|
805
|
+
tiles: tiles2,
|
|
806
|
+
tileFormat,
|
|
807
|
+
spatialFilter,
|
|
808
|
+
uniqueIdProperty,
|
|
809
|
+
options
|
|
810
|
+
}) {
|
|
811
|
+
const map = /* @__PURE__ */ new Map();
|
|
812
|
+
for (const tile of tiles2) {
|
|
813
|
+
if (tile.isVisible === false || !tile.data) {
|
|
814
|
+
continue;
|
|
815
|
+
}
|
|
816
|
+
const bbox = [
|
|
817
|
+
tile.bbox.west,
|
|
818
|
+
tile.bbox.south,
|
|
819
|
+
tile.bbox.east,
|
|
820
|
+
tile.bbox.north
|
|
821
|
+
];
|
|
822
|
+
const bboxToGeom = bboxPolygon(bbox);
|
|
823
|
+
const tileIsFullyVisible = booleanWithin(bboxToGeom, spatialFilter);
|
|
824
|
+
const spatialFilterFeature = {
|
|
825
|
+
type: "Feature",
|
|
826
|
+
geometry: spatialFilter,
|
|
827
|
+
properties: {}
|
|
828
|
+
};
|
|
829
|
+
const clippedGeometryToIntersect = intersect(
|
|
830
|
+
featureCollection([bboxToGeom, spatialFilterFeature])
|
|
831
|
+
);
|
|
832
|
+
if (!clippedGeometryToIntersect) {
|
|
833
|
+
continue;
|
|
834
|
+
}
|
|
835
|
+
const transformedGeometryToIntersect = tileFormat === "mvt" /* MVT */ ? transformToTileCoords(clippedGeometryToIntersect.geometry, bbox) : clippedGeometryToIntersect.geometry;
|
|
836
|
+
createIndicesForPoints(tile.data.points);
|
|
837
|
+
calculateFeatures({
|
|
838
|
+
map,
|
|
839
|
+
tileIsFullyVisible,
|
|
840
|
+
geometryIntersection: transformedGeometryToIntersect,
|
|
841
|
+
data: tile.data.points,
|
|
842
|
+
type: "Point",
|
|
843
|
+
bbox,
|
|
844
|
+
tileFormat,
|
|
845
|
+
uniqueIdProperty,
|
|
846
|
+
options
|
|
847
|
+
});
|
|
848
|
+
calculateFeatures({
|
|
849
|
+
map,
|
|
850
|
+
tileIsFullyVisible,
|
|
851
|
+
geometryIntersection: transformedGeometryToIntersect,
|
|
852
|
+
data: tile.data.lines,
|
|
853
|
+
type: "LineString",
|
|
854
|
+
bbox,
|
|
855
|
+
tileFormat,
|
|
856
|
+
uniqueIdProperty,
|
|
857
|
+
options
|
|
858
|
+
});
|
|
859
|
+
calculateFeatures({
|
|
860
|
+
map,
|
|
861
|
+
tileIsFullyVisible,
|
|
862
|
+
geometryIntersection: transformedGeometryToIntersect,
|
|
863
|
+
data: tile.data.polygons,
|
|
864
|
+
type: "Polygon",
|
|
865
|
+
bbox,
|
|
866
|
+
tileFormat,
|
|
867
|
+
uniqueIdProperty,
|
|
868
|
+
options
|
|
869
|
+
});
|
|
870
|
+
}
|
|
871
|
+
return Array.from(map.values());
|
|
872
|
+
}
|
|
873
|
+
function processTileFeatureProperties({
|
|
874
|
+
map,
|
|
875
|
+
data,
|
|
876
|
+
startIndex,
|
|
877
|
+
endIndex,
|
|
878
|
+
type,
|
|
879
|
+
bbox,
|
|
880
|
+
tileFormat,
|
|
881
|
+
uniqueIdProperty,
|
|
882
|
+
storeGeometry,
|
|
883
|
+
geometryIntersection
|
|
884
|
+
}) {
|
|
885
|
+
const tileProps = getPropertiesFromTile(data, startIndex);
|
|
886
|
+
const uniquePropertyValue = getUniquePropertyValue(
|
|
887
|
+
tileProps,
|
|
888
|
+
uniqueIdProperty,
|
|
889
|
+
map
|
|
890
|
+
);
|
|
891
|
+
if (!uniquePropertyValue || map.has(uniquePropertyValue)) {
|
|
892
|
+
return;
|
|
893
|
+
}
|
|
894
|
+
let geometry = null;
|
|
895
|
+
if (storeGeometry || geometryIntersection) {
|
|
896
|
+
const { positions } = data;
|
|
897
|
+
const ringCoordinates = getRingCoordinatesFor(
|
|
898
|
+
startIndex,
|
|
899
|
+
endIndex,
|
|
900
|
+
positions
|
|
901
|
+
);
|
|
902
|
+
geometry = getFeatureByType(ringCoordinates, type);
|
|
903
|
+
}
|
|
904
|
+
if (geometry && geometryIntersection && !intersects2(geometry, geometryIntersection)) {
|
|
905
|
+
return;
|
|
906
|
+
}
|
|
907
|
+
const properties = parseProperties(tileProps);
|
|
908
|
+
if (storeGeometry && geometry) {
|
|
909
|
+
properties[FEATURE_GEOM_PROPERTY] = tileFormat === "mvt" /* MVT */ ? transformTileCoordsToWGS84(geometry, bbox) : geometry;
|
|
910
|
+
}
|
|
911
|
+
map.set(uniquePropertyValue, properties);
|
|
912
|
+
}
|
|
913
|
+
function addIntersectedFeaturesInTile({
|
|
914
|
+
map,
|
|
915
|
+
data,
|
|
916
|
+
geometryIntersection,
|
|
917
|
+
type,
|
|
918
|
+
bbox,
|
|
919
|
+
tileFormat,
|
|
920
|
+
uniqueIdProperty,
|
|
921
|
+
options
|
|
922
|
+
}) {
|
|
923
|
+
const indices = getIndices(data);
|
|
924
|
+
const storeGeometry = options?.storeGeometry || false;
|
|
925
|
+
for (let i = 0; i < indices.length - 1; i++) {
|
|
926
|
+
const startIndex = indices[i];
|
|
927
|
+
const endIndex = indices[i + 1];
|
|
928
|
+
processTileFeatureProperties({
|
|
929
|
+
map,
|
|
930
|
+
data,
|
|
931
|
+
startIndex,
|
|
932
|
+
endIndex,
|
|
933
|
+
type,
|
|
934
|
+
bbox,
|
|
935
|
+
tileFormat,
|
|
936
|
+
uniqueIdProperty,
|
|
937
|
+
storeGeometry,
|
|
938
|
+
geometryIntersection
|
|
939
|
+
});
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
function getIndices(data) {
|
|
943
|
+
let indices;
|
|
944
|
+
switch (data.type) {
|
|
945
|
+
case "Point":
|
|
946
|
+
indices = data.pointIndices;
|
|
947
|
+
break;
|
|
948
|
+
case "LineString":
|
|
949
|
+
indices = data.pathIndices;
|
|
950
|
+
break;
|
|
951
|
+
case "Polygon":
|
|
952
|
+
indices = data.primitivePolygonIndices;
|
|
953
|
+
break;
|
|
954
|
+
default:
|
|
955
|
+
throw new Error(`Unexpected type, "${data.type}"`);
|
|
956
|
+
}
|
|
957
|
+
return indices.value;
|
|
958
|
+
}
|
|
959
|
+
function getFeatureId(data, startIndex) {
|
|
960
|
+
return data.featureIds.value[startIndex];
|
|
961
|
+
}
|
|
962
|
+
function getPropertiesFromTile(data, startIndex) {
|
|
963
|
+
const featureId = getFeatureId(data, startIndex);
|
|
964
|
+
const { properties, numericProps, fields } = data;
|
|
965
|
+
const result = {
|
|
966
|
+
uniqueId: fields?.[featureId]?.id,
|
|
967
|
+
properties: properties[featureId],
|
|
968
|
+
numericProps: {}
|
|
969
|
+
};
|
|
970
|
+
for (const key in numericProps) {
|
|
971
|
+
result.numericProps[key] = numericProps[key].value[startIndex];
|
|
972
|
+
}
|
|
973
|
+
return result;
|
|
974
|
+
}
|
|
975
|
+
function parseProperties(tileProps) {
|
|
976
|
+
const { properties, numericProps } = tileProps;
|
|
977
|
+
return Object.assign({}, properties, numericProps);
|
|
978
|
+
}
|
|
979
|
+
function getUniquePropertyValue(tileProps, uniqueIdProperty, map) {
|
|
980
|
+
if (uniqueIdProperty) {
|
|
981
|
+
return getValueFromTileProps(tileProps, uniqueIdProperty);
|
|
982
|
+
}
|
|
983
|
+
if (tileProps.uniqueId) {
|
|
984
|
+
return tileProps.uniqueId;
|
|
985
|
+
}
|
|
986
|
+
const artificialId = map.size + 1;
|
|
987
|
+
return getValueFromTileProps(tileProps, "cartodb_id") || getValueFromTileProps(tileProps, "geoid") || artificialId;
|
|
988
|
+
}
|
|
989
|
+
function getValueFromTileProps(tileProps, propertyName) {
|
|
990
|
+
const { properties, numericProps } = tileProps;
|
|
991
|
+
return numericProps[propertyName] || properties[propertyName];
|
|
992
|
+
}
|
|
993
|
+
function getFeatureByType(coordinates, type) {
|
|
994
|
+
switch (type) {
|
|
995
|
+
case "Polygon":
|
|
996
|
+
return { type: "Polygon", coordinates: [coordinates] };
|
|
997
|
+
case "LineString":
|
|
998
|
+
return { type: "LineString", coordinates };
|
|
999
|
+
case "Point":
|
|
1000
|
+
return { type: "Point", coordinates: coordinates[0] };
|
|
1001
|
+
default:
|
|
1002
|
+
throw new Error("Invalid geometry type");
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
function getRingCoordinatesFor(startIndex, endIndex, positions) {
|
|
1006
|
+
const ringCoordinates = [];
|
|
1007
|
+
for (let j = startIndex; j < endIndex; j++) {
|
|
1008
|
+
ringCoordinates.push(
|
|
1009
|
+
Array.from(
|
|
1010
|
+
positions.value.subarray(j * positions.size, (j + 1) * positions.size)
|
|
1011
|
+
)
|
|
1012
|
+
);
|
|
1013
|
+
}
|
|
1014
|
+
return ringCoordinates;
|
|
1015
|
+
}
|
|
1016
|
+
function calculateFeatures({
|
|
1017
|
+
map,
|
|
1018
|
+
tileIsFullyVisible,
|
|
1019
|
+
geometryIntersection,
|
|
1020
|
+
data,
|
|
1021
|
+
type,
|
|
1022
|
+
bbox,
|
|
1023
|
+
tileFormat,
|
|
1024
|
+
uniqueIdProperty,
|
|
1025
|
+
options
|
|
1026
|
+
}) {
|
|
1027
|
+
if (!data?.properties.length) {
|
|
1028
|
+
return;
|
|
1029
|
+
}
|
|
1030
|
+
if (tileIsFullyVisible) {
|
|
1031
|
+
addAllFeaturesInTile({
|
|
1032
|
+
map,
|
|
1033
|
+
data,
|
|
1034
|
+
type,
|
|
1035
|
+
bbox,
|
|
1036
|
+
tileFormat,
|
|
1037
|
+
uniqueIdProperty,
|
|
1038
|
+
options
|
|
1039
|
+
});
|
|
1040
|
+
} else {
|
|
1041
|
+
addIntersectedFeaturesInTile({
|
|
1042
|
+
map,
|
|
1043
|
+
data,
|
|
1044
|
+
geometryIntersection,
|
|
1045
|
+
type,
|
|
1046
|
+
bbox,
|
|
1047
|
+
tileFormat,
|
|
1048
|
+
uniqueIdProperty,
|
|
1049
|
+
options
|
|
1050
|
+
});
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
function addAllFeaturesInTile({
|
|
1054
|
+
map,
|
|
1055
|
+
data,
|
|
1056
|
+
type,
|
|
1057
|
+
bbox,
|
|
1058
|
+
tileFormat,
|
|
1059
|
+
uniqueIdProperty,
|
|
1060
|
+
options
|
|
1061
|
+
}) {
|
|
1062
|
+
const indices = getIndices(data);
|
|
1063
|
+
const storeGeometry = options?.storeGeometry || false;
|
|
1064
|
+
for (let i = 0; i < indices.length - 1; i++) {
|
|
1065
|
+
const startIndex = indices[i];
|
|
1066
|
+
const endIndex = indices[i + 1];
|
|
1067
|
+
processTileFeatureProperties({
|
|
1068
|
+
map,
|
|
1069
|
+
data,
|
|
1070
|
+
startIndex,
|
|
1071
|
+
endIndex,
|
|
1072
|
+
type,
|
|
1073
|
+
bbox,
|
|
1074
|
+
tileFormat,
|
|
1075
|
+
uniqueIdProperty,
|
|
1076
|
+
storeGeometry
|
|
1077
|
+
});
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
function createIndicesForPoints(data) {
|
|
1081
|
+
const featureIds = data.featureIds.value;
|
|
1082
|
+
const lastFeatureId = featureIds[featureIds.length - 1];
|
|
1083
|
+
const PointIndicesArray = featureIds.constructor;
|
|
1084
|
+
const pointIndices = {
|
|
1085
|
+
value: new PointIndicesArray(featureIds.length + 1),
|
|
1086
|
+
size: 1
|
|
1087
|
+
};
|
|
1088
|
+
pointIndices.value.set(featureIds);
|
|
1089
|
+
pointIndices.value.set([lastFeatureId + 1], featureIds.length);
|
|
1090
|
+
data.pointIndices = pointIndices;
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
// node_modules/quadbin/dist/esm/index.js
|
|
1094
|
+
var import_tile_cover = __toESM(require_tile_cover(), 1);
|
|
1095
|
+
var B = [
|
|
1096
|
+
0x5555555555555555n,
|
|
1097
|
+
0x3333333333333333n,
|
|
1098
|
+
0x0f0f0f0f0f0f0f0fn,
|
|
1099
|
+
0x00ff00ff00ff00ffn,
|
|
1100
|
+
0x0000ffff0000ffffn,
|
|
1101
|
+
0x00000000ffffffffn
|
|
1102
|
+
];
|
|
1103
|
+
var S = [0n, 1n, 2n, 4n, 8n, 16n];
|
|
1104
|
+
function tileToCell(tile) {
|
|
1105
|
+
if (tile.z < 0 || tile.z > 26) {
|
|
1106
|
+
throw new Error("Wrong zoom");
|
|
1107
|
+
}
|
|
1108
|
+
const z = BigInt(tile.z);
|
|
1109
|
+
let x = BigInt(tile.x) << 32n - z;
|
|
1110
|
+
let y = BigInt(tile.y) << 32n - z;
|
|
1111
|
+
for (let i = 0; i < 5; i++) {
|
|
1112
|
+
const s = S[5 - i];
|
|
1113
|
+
const b = B[4 - i];
|
|
1114
|
+
x = (x | x << s) & b;
|
|
1115
|
+
y = (y | y << s) & b;
|
|
1116
|
+
}
|
|
1117
|
+
const quadbin = 0x4000000000000000n | 1n << 59n | // | (mode << 59) | (mode_dep << 57)
|
|
1118
|
+
z << 52n | (x | y << 1n) >> 12n | 0xfffffffffffffn >> z * 2n;
|
|
1119
|
+
return quadbin;
|
|
1120
|
+
}
|
|
1121
|
+
function getResolution(quadbin) {
|
|
1122
|
+
return quadbin >> 52n & 0x1fn;
|
|
1123
|
+
}
|
|
1124
|
+
function geometryToCells(geometry, resolution) {
|
|
1125
|
+
const zoom = Number(resolution);
|
|
1126
|
+
return (0, import_tile_cover.tiles)(geometry, {
|
|
1127
|
+
min_zoom: zoom,
|
|
1128
|
+
max_zoom: zoom
|
|
1129
|
+
}).map(([x, y, z]) => tileToCell({ x, y, z }));
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
// src/filters/tileFeaturesSpatialIndex.ts
|
|
1133
|
+
import bboxClip from "@turf/bbox-clip";
|
|
1134
|
+
import { getResolution as h3GetResolution, polygonToCells } from "h3-js";
|
|
1135
|
+
function tileFeaturesSpatialIndex({
|
|
1136
|
+
tiles: tiles2,
|
|
1137
|
+
spatialFilter,
|
|
1138
|
+
spatialDataColumn,
|
|
1139
|
+
spatialDataType
|
|
1140
|
+
}) {
|
|
1141
|
+
const map = /* @__PURE__ */ new Map();
|
|
1142
|
+
const spatialIndex = getSpatialIndex(spatialDataType);
|
|
1143
|
+
const resolution = getResolution2(tiles2, spatialIndex);
|
|
1144
|
+
const spatialIndexIDName = spatialDataColumn ? spatialDataColumn : spatialIndex;
|
|
1145
|
+
if (!resolution) {
|
|
1146
|
+
return [];
|
|
1147
|
+
}
|
|
1148
|
+
const cells = getCellsCoverGeometry(spatialFilter, spatialIndex, resolution);
|
|
1149
|
+
if (!cells?.length) {
|
|
1150
|
+
return [];
|
|
1151
|
+
}
|
|
1152
|
+
const cellsSet = new Set(cells);
|
|
1153
|
+
for (const tile of tiles2) {
|
|
1154
|
+
if (tile.isVisible === false || !tile.data) {
|
|
1155
|
+
continue;
|
|
1156
|
+
}
|
|
1157
|
+
tile.data.forEach((d) => {
|
|
1158
|
+
if (cellsSet.has(d.id)) {
|
|
1159
|
+
map.set(d.id, { ...d.properties, [spatialIndexIDName]: d.id });
|
|
1160
|
+
}
|
|
1161
|
+
});
|
|
1162
|
+
}
|
|
1163
|
+
return Array.from(map.values());
|
|
1164
|
+
}
|
|
1165
|
+
function getResolution2(tiles2, spatialIndex) {
|
|
1166
|
+
const data = tiles2.find((tile) => tile.data?.length)?.data;
|
|
1167
|
+
if (!data) {
|
|
1168
|
+
return;
|
|
1169
|
+
}
|
|
1170
|
+
if (spatialIndex === "quadbin" /* QUADBIN */) {
|
|
1171
|
+
return Number(getResolution(data[0].id));
|
|
1172
|
+
}
|
|
1173
|
+
if (spatialIndex === "h3" /* H3 */) {
|
|
1174
|
+
return h3GetResolution(data[0].id);
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
var bboxWest = [-180, -90, 0, 90];
|
|
1178
|
+
var bboxEast = [0, -90, 180, 90];
|
|
1179
|
+
function getCellsCoverGeometry(geometry, spatialIndex, resolution) {
|
|
1180
|
+
if (spatialIndex === "quadbin" /* QUADBIN */) {
|
|
1181
|
+
return geometryToCells(geometry, resolution);
|
|
1182
|
+
}
|
|
1183
|
+
if (spatialIndex === "h3" /* H3 */) {
|
|
1184
|
+
return polygonToCells(
|
|
1185
|
+
bboxClip(geometry, bboxWest).geometry.coordinates,
|
|
1186
|
+
resolution,
|
|
1187
|
+
true
|
|
1188
|
+
).concat(
|
|
1189
|
+
polygonToCells(
|
|
1190
|
+
bboxClip(geometry, bboxEast).geometry.coordinates,
|
|
1191
|
+
resolution,
|
|
1192
|
+
true
|
|
1193
|
+
)
|
|
1194
|
+
);
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
function getSpatialIndex(spatialDataType) {
|
|
1198
|
+
switch (spatialDataType) {
|
|
1199
|
+
case "h3":
|
|
1200
|
+
return "h3" /* H3 */;
|
|
1201
|
+
case "quadbin":
|
|
1202
|
+
return "quadbin" /* QUADBIN */;
|
|
1203
|
+
default:
|
|
1204
|
+
throw new Error("Unexpected spatial data type");
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
// src/constants-internal.ts
|
|
1209
|
+
var V3_MINOR_VERSION = "3.4";
|
|
1210
|
+
var DEFAULT_GEO_COLUMN = "geom";
|
|
1211
|
+
var DEFAULT_MAX_LENGTH_URL = 7e3;
|
|
1212
|
+
var DEFAULT_TILE_RESOLUTION = 0.5;
|
|
1213
|
+
var DEFAULT_AGGREGATION_RES_LEVEL_H3 = 4;
|
|
1214
|
+
var DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN = 6;
|
|
1215
|
+
|
|
1216
|
+
// src/filters/tileFeatures.ts
|
|
1217
|
+
function tileFeatures({
|
|
1218
|
+
tiles: tiles2,
|
|
1219
|
+
spatialFilter,
|
|
1220
|
+
uniqueIdProperty,
|
|
1221
|
+
tileFormat,
|
|
1222
|
+
spatialDataColumn = DEFAULT_GEO_COLUMN,
|
|
1223
|
+
spatialDataType,
|
|
1224
|
+
options = {}
|
|
1225
|
+
}) {
|
|
1226
|
+
if (spatialDataType !== "geo") {
|
|
1227
|
+
return tileFeaturesSpatialIndex({
|
|
1228
|
+
tiles: tiles2,
|
|
1229
|
+
spatialFilter,
|
|
1230
|
+
spatialDataColumn,
|
|
1231
|
+
spatialDataType
|
|
1232
|
+
});
|
|
1233
|
+
}
|
|
1234
|
+
return tileFeaturesGeometries({
|
|
1235
|
+
tiles: tiles2,
|
|
1236
|
+
tileFormat,
|
|
1237
|
+
spatialFilter,
|
|
1238
|
+
uniqueIdProperty,
|
|
1239
|
+
options
|
|
1240
|
+
});
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
// src/deck/get-data-filter-extension-props.ts
|
|
1244
|
+
function getDataFilterExtensionProps(filters, filtersLogicalOperator, filterSize) {
|
|
1245
|
+
filterSize ?? (filterSize = 4);
|
|
1246
|
+
const { filtersWithoutTimeType, timeColumn, timeFilter } = getFiltersByType(filters);
|
|
1247
|
+
return {
|
|
1248
|
+
filterRange: getFilterRange(timeFilter, filterSize),
|
|
1249
|
+
updateTriggers: getUpdateTriggers(
|
|
1250
|
+
filtersWithoutTimeType,
|
|
1251
|
+
timeColumn,
|
|
1252
|
+
timeFilter
|
|
1253
|
+
),
|
|
1254
|
+
getFilterValue: getFilterValue(
|
|
1255
|
+
filtersWithoutTimeType,
|
|
1256
|
+
timeColumn,
|
|
1257
|
+
timeFilter,
|
|
1258
|
+
filterSize,
|
|
1259
|
+
filtersLogicalOperator
|
|
1260
|
+
)
|
|
1261
|
+
};
|
|
1262
|
+
}
|
|
1263
|
+
function getFiltersByType(filters) {
|
|
1264
|
+
const filtersWithoutTimeType = {};
|
|
1265
|
+
let timeColumn = null;
|
|
1266
|
+
let timeFilter = null;
|
|
1267
|
+
for (const [column, columnData] of Object.entries(filters)) {
|
|
1268
|
+
for (const [type, typeData] of Object.entries(columnData)) {
|
|
1269
|
+
if (type === "time" /* TIME */) {
|
|
1270
|
+
timeColumn = column;
|
|
1271
|
+
timeFilter = typeData;
|
|
1272
|
+
} else {
|
|
1273
|
+
filtersWithoutTimeType[column] = { [type]: typeData };
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
return {
|
|
1278
|
+
filtersWithoutTimeType,
|
|
1279
|
+
timeColumn,
|
|
1280
|
+
timeFilter
|
|
1281
|
+
};
|
|
1282
|
+
}
|
|
1283
|
+
function getFilterRange(timeFilter, filterSize) {
|
|
1284
|
+
const result = Array(filterSize).fill([0, 0]);
|
|
1285
|
+
result[0] = [1, 1];
|
|
1286
|
+
if (timeFilter) {
|
|
1287
|
+
const offsetBy = timeFilter.params?.offsetBy || 0;
|
|
1288
|
+
result[1] = timeFilter.values[0].map((v) => v - offsetBy);
|
|
1289
|
+
}
|
|
1290
|
+
return result;
|
|
1291
|
+
}
|
|
1292
|
+
function getUpdateTriggers(filtersWithoutTimeType, timeColumn, timeFilter) {
|
|
1293
|
+
const result = { ...filtersWithoutTimeType };
|
|
1294
|
+
if (timeColumn && timeFilter) {
|
|
1295
|
+
result[timeColumn] = {
|
|
1296
|
+
...result[timeColumn],
|
|
1297
|
+
offsetBy: timeFilter.params?.offsetBy,
|
|
1298
|
+
["time" /* TIME */]: {}
|
|
1299
|
+
// Allows working with other filters, without an impact on performance.
|
|
1300
|
+
};
|
|
1301
|
+
}
|
|
1302
|
+
return {
|
|
1303
|
+
getFilterValue: JSON.stringify(result)
|
|
1304
|
+
};
|
|
1305
|
+
}
|
|
1306
|
+
function getFilterValue(filtersWithoutTimeType, timeColumn, timeFilter, filterSize, filtersLogicalOperator) {
|
|
1307
|
+
const result = Array(filterSize).fill(0);
|
|
1308
|
+
const featureFilter = _buildFeatureFilter({
|
|
1309
|
+
filters: filtersWithoutTimeType,
|
|
1310
|
+
type: "number",
|
|
1311
|
+
filtersLogicalOperator
|
|
1312
|
+
});
|
|
1313
|
+
return (feature2) => {
|
|
1314
|
+
result[0] = featureFilter(feature2);
|
|
1315
|
+
if (timeColumn && timeFilter) {
|
|
1316
|
+
const offsetBy = timeFilter.params?.offsetBy || 0;
|
|
1317
|
+
const f = feature2.properties || feature2;
|
|
1318
|
+
result[1] = f[timeColumn] - offsetBy;
|
|
1319
|
+
}
|
|
1320
|
+
return result;
|
|
1321
|
+
};
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
// src/utils.ts
|
|
1325
|
+
var FILTER_TYPES = new Set(Object.values(FilterType));
|
|
1326
|
+
var isFilterType = (type) => FILTER_TYPES.has(type);
|
|
1327
|
+
function getApplicableFilters(owner, filters) {
|
|
1328
|
+
if (!filters) return {};
|
|
1329
|
+
const applicableFilters = {};
|
|
1330
|
+
for (const column in filters) {
|
|
1331
|
+
for (const type in filters[column]) {
|
|
1332
|
+
if (!isFilterType(type)) continue;
|
|
1333
|
+
const filter = filters[column][type];
|
|
1334
|
+
const isApplicable = !owner || !filter?.owner || filter?.owner !== owner;
|
|
1335
|
+
if (filter && isApplicable) {
|
|
1336
|
+
applicableFilters[column] || (applicableFilters[column] = {});
|
|
1337
|
+
applicableFilters[column][type] = filter;
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
return applicableFilters;
|
|
1342
|
+
}
|
|
1343
|
+
function normalizeObjectKeys(el) {
|
|
1344
|
+
if (Array.isArray(el)) {
|
|
1345
|
+
return el.map((value) => normalizeObjectKeys(value));
|
|
1346
|
+
} else if (typeof el !== "object") {
|
|
1347
|
+
return el;
|
|
1348
|
+
}
|
|
1349
|
+
return Object.entries(el).reduce(
|
|
1350
|
+
(acc, [key, value]) => {
|
|
1351
|
+
acc[key.toLowerCase()] = typeof value === "object" && value ? normalizeObjectKeys(value) : value;
|
|
1352
|
+
return acc;
|
|
1353
|
+
},
|
|
1354
|
+
{}
|
|
1355
|
+
);
|
|
1356
|
+
}
|
|
1357
|
+
function assert2(condition, message) {
|
|
1358
|
+
if (!condition) {
|
|
1359
|
+
throw new Error(message);
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
var _InvalidColumnError = class _InvalidColumnError extends Error {
|
|
1363
|
+
constructor(message) {
|
|
1364
|
+
super(`${_InvalidColumnError.NAME}: ${message}`);
|
|
1365
|
+
this.name = _InvalidColumnError.NAME;
|
|
1366
|
+
}
|
|
1367
|
+
static is(error) {
|
|
1368
|
+
return error instanceof _InvalidColumnError || error.message?.includes(_InvalidColumnError.NAME);
|
|
1369
|
+
}
|
|
1370
|
+
};
|
|
1371
|
+
__publicField(_InvalidColumnError, "NAME", "InvalidColumnError");
|
|
1372
|
+
var InvalidColumnError = _InvalidColumnError;
|
|
1373
|
+
function isEmptyObject(object) {
|
|
1374
|
+
for (const _ in object) {
|
|
1375
|
+
return false;
|
|
1376
|
+
}
|
|
1377
|
+
return true;
|
|
1378
|
+
}
|
|
1379
|
+
var isObject = (x) => x !== null && typeof x === "object";
|
|
1380
|
+
var isPureObject = (x) => isObject(x) && x.constructor === {}.constructor;
|
|
1381
|
+
|
|
1382
|
+
// src/filters.ts
|
|
1383
|
+
function addFilter(filters, { column, type, values, owner }) {
|
|
1384
|
+
if (!filters[column]) {
|
|
1385
|
+
filters[column] = {};
|
|
1386
|
+
}
|
|
1387
|
+
const filter = { values, owner };
|
|
1388
|
+
filters[column][type] = filter;
|
|
1389
|
+
return filters;
|
|
1390
|
+
}
|
|
1391
|
+
function removeFilter(filters, { column, owner }) {
|
|
1392
|
+
const filter = filters[column];
|
|
1393
|
+
if (!filter) {
|
|
1394
|
+
return filters;
|
|
1395
|
+
}
|
|
1396
|
+
if (owner) {
|
|
1397
|
+
for (const type of Object.values(FilterType)) {
|
|
1398
|
+
if (owner === filter[type]?.owner) {
|
|
1399
|
+
delete filter[type];
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
if (!owner || isEmptyObject(filter)) {
|
|
1404
|
+
delete filters[column];
|
|
1405
|
+
}
|
|
1406
|
+
return filters;
|
|
1407
|
+
}
|
|
1408
|
+
function clearFilters(filters) {
|
|
1409
|
+
for (const column of Object.keys(filters)) {
|
|
1410
|
+
delete filters[column];
|
|
1411
|
+
}
|
|
1412
|
+
return filters;
|
|
1413
|
+
}
|
|
1414
|
+
function hasFilter(filters, { column, owner }) {
|
|
1415
|
+
const filter = filters[column];
|
|
1416
|
+
if (!filter) {
|
|
1417
|
+
return false;
|
|
1418
|
+
}
|
|
1419
|
+
if (!owner) {
|
|
1420
|
+
return true;
|
|
1421
|
+
}
|
|
1422
|
+
for (const type of Object.values(FilterType)) {
|
|
1423
|
+
if (owner === filter[type]?.owner) {
|
|
1424
|
+
return true;
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
return false;
|
|
1428
|
+
}
|
|
1429
|
+
function getFilter(filters, { column, type, owner }) {
|
|
1430
|
+
const filter = filters[column];
|
|
1431
|
+
if (!filter) {
|
|
1432
|
+
return null;
|
|
1433
|
+
}
|
|
1434
|
+
if (!owner || owner === filter[type]?.owner) {
|
|
1435
|
+
return filter[type] || null;
|
|
1436
|
+
}
|
|
1437
|
+
return null;
|
|
1438
|
+
}
|
|
1439
|
+
|
|
1440
|
+
// src/geo.ts
|
|
1441
|
+
import bboxClip2 from "@turf/bbox-clip";
|
|
1442
|
+
import bboxPolygon2 from "@turf/bbox-polygon";
|
|
1443
|
+
import union from "@turf/union";
|
|
1444
|
+
import { getType } from "@turf/invariant";
|
|
1445
|
+
import { polygon, multiPolygon, feature, featureCollection as featureCollection2 } from "@turf/helpers";
|
|
1446
|
+
function createViewportSpatialFilter(viewport) {
|
|
1447
|
+
if (_isGlobalViewport(viewport)) {
|
|
1448
|
+
return;
|
|
1449
|
+
}
|
|
1450
|
+
return createPolygonSpatialFilter(bboxPolygon2(viewport).geometry);
|
|
1451
|
+
}
|
|
1452
|
+
function createPolygonSpatialFilter(spatialFilter) {
|
|
1453
|
+
return spatialFilter && _normalizeGeometry(spatialFilter) || void 0;
|
|
1454
|
+
}
|
|
1455
|
+
function _isGlobalViewport(viewport) {
|
|
1456
|
+
const [minx, miny, maxx, maxy] = viewport;
|
|
1457
|
+
return maxx - minx > 179.5 * 2 && maxy - miny > 85.05 * 2;
|
|
1458
|
+
}
|
|
1459
|
+
function _normalizeGeometry(geometry) {
|
|
1460
|
+
const WORLD = [-180, -90, 180, 90];
|
|
1461
|
+
const worldClip = _clean(
|
|
1462
|
+
bboxClip2(geometry, WORLD).geometry
|
|
1463
|
+
);
|
|
1464
|
+
const geometryTxWest = _tx(geometry, 360);
|
|
1465
|
+
const geometryTxEast = _tx(geometry, -360);
|
|
1466
|
+
let result = worldClip;
|
|
1467
|
+
if (result && geometryTxWest) {
|
|
1468
|
+
const worldWestClip = _clean(
|
|
1469
|
+
bboxClip2(geometryTxWest, WORLD).geometry
|
|
1470
|
+
);
|
|
1471
|
+
if (worldWestClip) {
|
|
1472
|
+
const collection = featureCollection2([
|
|
1473
|
+
feature(result),
|
|
1474
|
+
feature(worldWestClip)
|
|
1475
|
+
]);
|
|
1476
|
+
const merged = union(collection);
|
|
1477
|
+
result = merged ? _clean(merged.geometry) : result;
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
if (result && geometryTxEast) {
|
|
1481
|
+
const worldEastClip = _clean(
|
|
1482
|
+
bboxClip2(geometryTxEast, WORLD).geometry
|
|
1483
|
+
);
|
|
1484
|
+
if (worldEastClip) {
|
|
1485
|
+
const collection = featureCollection2([
|
|
1486
|
+
feature(result),
|
|
1487
|
+
feature(worldEastClip)
|
|
1488
|
+
]);
|
|
1489
|
+
const merged = union(collection);
|
|
1490
|
+
result = merged ? _clean(merged.geometry) : result;
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
return result;
|
|
1494
|
+
}
|
|
1495
|
+
function _cleanPolygonCoords(cc) {
|
|
1496
|
+
const coords = cc.filter((c) => c.length > 0);
|
|
1497
|
+
return coords.length > 0 ? coords : null;
|
|
1498
|
+
}
|
|
1499
|
+
function _cleanMultiPolygonCoords(ccc) {
|
|
1500
|
+
const coords = ccc.map(_cleanPolygonCoords).filter((cc) => cc);
|
|
1501
|
+
return coords.length > 0 ? coords : null;
|
|
1502
|
+
}
|
|
1503
|
+
function _clean(geometry) {
|
|
1504
|
+
if (!geometry) {
|
|
1505
|
+
return null;
|
|
1506
|
+
}
|
|
1507
|
+
if (_isPolygon(geometry)) {
|
|
1508
|
+
const coords = _cleanPolygonCoords(geometry.coordinates);
|
|
1509
|
+
return coords ? polygon(coords).geometry : null;
|
|
1510
|
+
}
|
|
1511
|
+
if (_isMultiPolygon(geometry)) {
|
|
1512
|
+
const coords = _cleanMultiPolygonCoords(geometry.coordinates);
|
|
1513
|
+
return coords ? multiPolygon(coords).geometry : null;
|
|
1514
|
+
}
|
|
1515
|
+
return null;
|
|
1516
|
+
}
|
|
1517
|
+
function _txContourCoords(cc, distance) {
|
|
1518
|
+
return cc.map((c) => [c[0] + distance, c[1]]);
|
|
1519
|
+
}
|
|
1520
|
+
function _txPolygonCoords(ccc, distance) {
|
|
1521
|
+
return ccc.map((cc) => _txContourCoords(cc, distance));
|
|
1522
|
+
}
|
|
1523
|
+
function _txMultiPolygonCoords(cccc, distance) {
|
|
1524
|
+
return cccc.map((ccc) => _txPolygonCoords(ccc, distance));
|
|
1525
|
+
}
|
|
1526
|
+
function _tx(geometry, distance) {
|
|
1527
|
+
if (geometry && getType(geometry) === "Polygon") {
|
|
1528
|
+
const coords = _txPolygonCoords(
|
|
1529
|
+
geometry.coordinates,
|
|
1530
|
+
distance
|
|
1531
|
+
);
|
|
1532
|
+
return polygon(coords).geometry;
|
|
1533
|
+
} else if (geometry && getType(geometry) === "MultiPolygon") {
|
|
1534
|
+
const coords = _txMultiPolygonCoords(
|
|
1535
|
+
geometry.coordinates,
|
|
1536
|
+
distance
|
|
1537
|
+
);
|
|
1538
|
+
return multiPolygon(coords).geometry;
|
|
1539
|
+
} else {
|
|
1540
|
+
return null;
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
function _isPolygon(geometry) {
|
|
1544
|
+
return getType(geometry) === "Polygon";
|
|
1545
|
+
}
|
|
1546
|
+
function _isMultiPolygon(geometry) {
|
|
1547
|
+
return getType(geometry) === "MultiPolygon";
|
|
1548
|
+
}
|
|
1549
|
+
|
|
1550
|
+
// src/api/endpoints.ts
|
|
1551
|
+
function joinPath(...args) {
|
|
1552
|
+
return args.map((part) => part.endsWith("/") ? part.slice(0, -1) : part).join("/");
|
|
1553
|
+
}
|
|
1554
|
+
function buildV3Path(apiBaseUrl, version, endpoint, ...rest) {
|
|
1555
|
+
return joinPath(apiBaseUrl, version, endpoint, ...rest);
|
|
1556
|
+
}
|
|
1557
|
+
function buildPublicMapUrl({
|
|
1558
|
+
apiBaseUrl,
|
|
1559
|
+
cartoMapId
|
|
1560
|
+
}) {
|
|
1561
|
+
return buildV3Path(apiBaseUrl, "v3", "maps", "public", cartoMapId);
|
|
1562
|
+
}
|
|
1563
|
+
function buildStatsUrl({
|
|
1564
|
+
attribute,
|
|
1565
|
+
apiBaseUrl,
|
|
1566
|
+
connectionName,
|
|
1567
|
+
source,
|
|
1568
|
+
type
|
|
1569
|
+
}) {
|
|
1570
|
+
if (type === "query") {
|
|
1571
|
+
return buildV3Path(apiBaseUrl, "v3", "stats", connectionName, attribute);
|
|
1572
|
+
}
|
|
1573
|
+
return buildV3Path(
|
|
1574
|
+
apiBaseUrl,
|
|
1575
|
+
"v3",
|
|
1576
|
+
"stats",
|
|
1577
|
+
connectionName,
|
|
1578
|
+
source,
|
|
1579
|
+
attribute
|
|
1580
|
+
);
|
|
1581
|
+
}
|
|
1582
|
+
function buildSourceUrl({
|
|
1583
|
+
apiBaseUrl,
|
|
1584
|
+
connectionName,
|
|
1585
|
+
endpoint
|
|
1586
|
+
}) {
|
|
1587
|
+
return buildV3Path(apiBaseUrl, "v3", "maps", connectionName, endpoint);
|
|
1588
|
+
}
|
|
1589
|
+
function buildQueryUrl({
|
|
1590
|
+
apiBaseUrl,
|
|
1591
|
+
connectionName
|
|
1592
|
+
}) {
|
|
1593
|
+
return buildV3Path(apiBaseUrl, "v3", "sql", connectionName, "query");
|
|
1594
|
+
}
|
|
1595
|
+
|
|
1596
|
+
// src/api/carto-api-error.ts
|
|
1597
|
+
var CartoAPIError = class extends Error {
|
|
1598
|
+
constructor(error, errorContext, response, responseJson) {
|
|
1599
|
+
let responseString = "Failed to connect";
|
|
1600
|
+
if (response) {
|
|
1601
|
+
responseString = "Server returned: ";
|
|
1602
|
+
if (response.status === 400) {
|
|
1603
|
+
responseString += "Bad request";
|
|
1604
|
+
} else if (response.status === 401 || response.status === 403) {
|
|
1605
|
+
responseString += "Unauthorized access";
|
|
1606
|
+
} else if (response.status === 404) {
|
|
1607
|
+
responseString += "Not found";
|
|
1608
|
+
} else {
|
|
1609
|
+
responseString += "Error";
|
|
1610
|
+
}
|
|
1611
|
+
responseString += ` (${response.status}):`;
|
|
1612
|
+
}
|
|
1613
|
+
responseString += ` ${error.message || error}`;
|
|
1614
|
+
let message = `${errorContext.requestType} API request failed`;
|
|
1615
|
+
message += `
|
|
1616
|
+
${responseString}`;
|
|
1617
|
+
for (const key of Object.keys(errorContext)) {
|
|
1618
|
+
if (key === "requestType") continue;
|
|
1619
|
+
message += `
|
|
1620
|
+
${formatErrorKey(key)}: ${errorContext[key]}`;
|
|
1621
|
+
}
|
|
1622
|
+
message += "\n";
|
|
1623
|
+
super(message);
|
|
1624
|
+
/** Source error from server */
|
|
1625
|
+
__publicField(this, "error");
|
|
1626
|
+
/** Context (API call & parameters) in which error occured */
|
|
1627
|
+
__publicField(this, "errorContext");
|
|
1628
|
+
/** Response from server */
|
|
1629
|
+
__publicField(this, "response");
|
|
1630
|
+
/** JSON Response from server */
|
|
1631
|
+
__publicField(this, "responseJson");
|
|
1632
|
+
this.name = "CartoAPIError";
|
|
1633
|
+
this.response = response;
|
|
1634
|
+
this.responseJson = responseJson;
|
|
1635
|
+
this.error = error;
|
|
1636
|
+
this.errorContext = errorContext;
|
|
1637
|
+
}
|
|
1638
|
+
};
|
|
1639
|
+
function formatErrorKey(key) {
|
|
1640
|
+
return key.replace(/([A-Z])/g, " $1").replace(/^./, (s) => s.toUpperCase());
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
// src/api/request-with-parameters.ts
|
|
1644
|
+
var DEFAULT_HEADERS = {
|
|
1645
|
+
Accept: "application/json",
|
|
1646
|
+
"Content-Type": "application/json"
|
|
1647
|
+
};
|
|
1648
|
+
var DEFAULT_REQUEST_CACHE = /* @__PURE__ */ new Map();
|
|
1649
|
+
async function requestWithParameters({
|
|
1650
|
+
baseUrl,
|
|
1651
|
+
parameters = {},
|
|
1652
|
+
headers: customHeaders = {},
|
|
1653
|
+
errorContext,
|
|
1654
|
+
maxLengthURL = DEFAULT_MAX_LENGTH_URL,
|
|
1655
|
+
localCache
|
|
1656
|
+
}) {
|
|
1657
|
+
parameters = {
|
|
1658
|
+
v: V3_MINOR_VERSION,
|
|
1659
|
+
client: getClient(),
|
|
1660
|
+
...typeof deck !== "undefined" && deck.VERSION && { deckglVersion: deck.VERSION },
|
|
1661
|
+
...parameters
|
|
1662
|
+
};
|
|
1663
|
+
baseUrl = excludeURLParameters(baseUrl, Object.keys(parameters));
|
|
1664
|
+
const key = createCacheKey(baseUrl, parameters, customHeaders);
|
|
1665
|
+
const {
|
|
1666
|
+
cache: REQUEST_CACHE,
|
|
1667
|
+
canReadCache,
|
|
1668
|
+
canStoreInCache
|
|
1669
|
+
} = getCacheSettings(localCache);
|
|
1670
|
+
if (canReadCache && REQUEST_CACHE.has(key)) {
|
|
1671
|
+
return REQUEST_CACHE.get(key);
|
|
1672
|
+
}
|
|
1673
|
+
const url = createURLWithParameters(baseUrl, parameters);
|
|
1674
|
+
const headers = { ...DEFAULT_HEADERS, ...customHeaders };
|
|
1675
|
+
const fetchPromise = url.length > maxLengthURL ? fetch(baseUrl, {
|
|
1676
|
+
method: "POST",
|
|
1677
|
+
body: JSON.stringify(parameters),
|
|
1678
|
+
headers
|
|
1679
|
+
}) : fetch(url, { headers });
|
|
1680
|
+
let response;
|
|
1681
|
+
let responseJson;
|
|
1682
|
+
const jsonPromise = fetchPromise.then((_response) => {
|
|
1683
|
+
response = _response;
|
|
1684
|
+
return response.json();
|
|
1685
|
+
}).then((json) => {
|
|
1686
|
+
responseJson = json;
|
|
1687
|
+
if (!response || !response.ok) {
|
|
1688
|
+
throw new Error(json.error);
|
|
1689
|
+
}
|
|
1690
|
+
return json;
|
|
1691
|
+
}).catch((error) => {
|
|
1692
|
+
if (canStoreInCache) {
|
|
1693
|
+
REQUEST_CACHE.delete(key);
|
|
1694
|
+
}
|
|
1695
|
+
throw new CartoAPIError(error, errorContext, response, responseJson);
|
|
1696
|
+
});
|
|
1697
|
+
if (canStoreInCache) {
|
|
1698
|
+
REQUEST_CACHE.set(key, jsonPromise);
|
|
1699
|
+
}
|
|
1700
|
+
return jsonPromise;
|
|
1701
|
+
}
|
|
1702
|
+
function getCacheSettings(localCache) {
|
|
1703
|
+
const canReadCache = localCache?.cacheControl?.includes("no-cache") ? false : true;
|
|
1704
|
+
const canStoreInCache = localCache?.cacheControl?.includes("no-store") ? false : true;
|
|
1705
|
+
const cache = localCache?.cache || DEFAULT_REQUEST_CACHE;
|
|
1706
|
+
return {
|
|
1707
|
+
cache,
|
|
1708
|
+
canReadCache,
|
|
1709
|
+
canStoreInCache
|
|
1710
|
+
};
|
|
1711
|
+
}
|
|
1712
|
+
function createCacheKey(baseUrl, parameters, headers) {
|
|
1713
|
+
const parameterEntries = Object.entries(parameters).sort(
|
|
1714
|
+
([a], [b]) => a > b ? 1 : -1
|
|
1715
|
+
);
|
|
1716
|
+
const headerEntries = Object.entries(headers).sort(
|
|
1717
|
+
([a], [b]) => a > b ? 1 : -1
|
|
1718
|
+
);
|
|
1719
|
+
return JSON.stringify({
|
|
1720
|
+
baseUrl,
|
|
1721
|
+
parameters: parameterEntries,
|
|
1722
|
+
headers: headerEntries
|
|
1723
|
+
});
|
|
1724
|
+
}
|
|
1725
|
+
function createURLWithParameters(baseUrlString, parameters) {
|
|
1726
|
+
const baseUrl = new URL(baseUrlString);
|
|
1727
|
+
for (const [key, value] of Object.entries(parameters)) {
|
|
1728
|
+
if (isPureObject(value) || Array.isArray(value)) {
|
|
1729
|
+
baseUrl.searchParams.set(key, JSON.stringify(value));
|
|
1730
|
+
} else {
|
|
1731
|
+
baseUrl.searchParams.set(
|
|
1732
|
+
key,
|
|
1733
|
+
value.toString()
|
|
1734
|
+
);
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
return baseUrl.toString();
|
|
1738
|
+
}
|
|
1739
|
+
function excludeURLParameters(baseUrlString, parameters) {
|
|
1740
|
+
const baseUrl = new URL(baseUrlString);
|
|
1741
|
+
for (const param of parameters) {
|
|
1742
|
+
if (baseUrl.searchParams.has(param)) {
|
|
1743
|
+
baseUrl.searchParams.delete(param);
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
return baseUrl.toString();
|
|
1747
|
+
}
|
|
1748
|
+
|
|
1749
|
+
// src/sources/base-source.ts
|
|
1750
|
+
var SOURCE_DEFAULTS = {
|
|
1751
|
+
apiBaseUrl: DEFAULT_API_BASE_URL,
|
|
1752
|
+
clientId: getClient(),
|
|
1753
|
+
format: "tilejson",
|
|
1754
|
+
headers: {},
|
|
1755
|
+
maxLengthURL: DEFAULT_MAX_LENGTH_URL
|
|
1756
|
+
};
|
|
1757
|
+
async function baseSource(endpoint, options, urlParameters) {
|
|
1758
|
+
const { accessToken, connectionName, cache, ...optionalOptions } = options;
|
|
1759
|
+
const mergedOptions = {
|
|
1760
|
+
...SOURCE_DEFAULTS,
|
|
1761
|
+
accessToken,
|
|
1762
|
+
connectionName,
|
|
1763
|
+
endpoint
|
|
1764
|
+
};
|
|
1765
|
+
for (const key in optionalOptions) {
|
|
1766
|
+
if (optionalOptions[key]) {
|
|
1767
|
+
mergedOptions[key] = optionalOptions[key];
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
const baseUrl = buildSourceUrl(mergedOptions);
|
|
1771
|
+
const { clientId, maxLengthURL, format, localCache } = mergedOptions;
|
|
1772
|
+
const headers = {
|
|
1773
|
+
Authorization: `Bearer ${options.accessToken}`,
|
|
1774
|
+
...options.headers
|
|
1775
|
+
};
|
|
1776
|
+
const parameters = { client: clientId, ...urlParameters };
|
|
1777
|
+
const errorContext = {
|
|
1778
|
+
requestType: "Map instantiation",
|
|
1779
|
+
connection: options.connectionName,
|
|
1780
|
+
type: endpoint,
|
|
1781
|
+
source: JSON.stringify(parameters, void 0, 2)
|
|
1782
|
+
};
|
|
1783
|
+
const mapInstantiation = await requestWithParameters({
|
|
1784
|
+
baseUrl,
|
|
1785
|
+
parameters,
|
|
1786
|
+
headers,
|
|
1787
|
+
errorContext,
|
|
1788
|
+
maxLengthURL,
|
|
1789
|
+
localCache
|
|
1790
|
+
});
|
|
1791
|
+
const dataUrl = mapInstantiation[format].url[0];
|
|
1792
|
+
if (cache) {
|
|
1793
|
+
cache.value = parseInt(
|
|
1794
|
+
new URL(dataUrl).searchParams.get("cache") || "",
|
|
1795
|
+
10
|
|
1796
|
+
);
|
|
1797
|
+
}
|
|
1798
|
+
errorContext.requestType = "Map data";
|
|
1799
|
+
if (format === "tilejson") {
|
|
1800
|
+
const json = await requestWithParameters({
|
|
1801
|
+
baseUrl: dataUrl,
|
|
1802
|
+
headers,
|
|
1803
|
+
errorContext,
|
|
1804
|
+
maxLengthURL,
|
|
1805
|
+
localCache
|
|
1806
|
+
});
|
|
1807
|
+
if (accessToken) {
|
|
1808
|
+
json.accessToken = accessToken;
|
|
1809
|
+
}
|
|
1810
|
+
return json;
|
|
1811
|
+
}
|
|
1812
|
+
return await requestWithParameters({
|
|
1813
|
+
baseUrl: dataUrl,
|
|
1814
|
+
headers,
|
|
1815
|
+
errorContext,
|
|
1816
|
+
maxLengthURL,
|
|
1817
|
+
localCache
|
|
1818
|
+
});
|
|
1819
|
+
}
|
|
1820
|
+
|
|
1821
|
+
// src/sources/boundary-query-source.ts
|
|
1822
|
+
var boundaryQuerySource = async function(options) {
|
|
1823
|
+
const {
|
|
1824
|
+
columns,
|
|
1825
|
+
filters,
|
|
1826
|
+
tilesetTableName,
|
|
1827
|
+
propertiesSqlQuery,
|
|
1828
|
+
queryParameters
|
|
1829
|
+
} = options;
|
|
1830
|
+
const urlParameters = {
|
|
1831
|
+
tilesetTableName,
|
|
1832
|
+
propertiesSqlQuery
|
|
1833
|
+
};
|
|
1834
|
+
if (columns) {
|
|
1835
|
+
urlParameters.columns = columns.join(",");
|
|
1836
|
+
}
|
|
1837
|
+
if (filters) {
|
|
1838
|
+
urlParameters.filters = filters;
|
|
1839
|
+
}
|
|
1840
|
+
if (queryParameters) {
|
|
1841
|
+
urlParameters.queryParameters = queryParameters;
|
|
1842
|
+
}
|
|
1843
|
+
return baseSource(
|
|
1844
|
+
"boundary",
|
|
1845
|
+
options,
|
|
1846
|
+
urlParameters
|
|
1847
|
+
);
|
|
1848
|
+
};
|
|
1849
|
+
|
|
1850
|
+
// src/sources/boundary-table-source.ts
|
|
1851
|
+
var boundaryTableSource = async function(options) {
|
|
1852
|
+
const { filters, tilesetTableName, columns, propertiesTableName } = options;
|
|
1853
|
+
const urlParameters = {
|
|
1854
|
+
tilesetTableName,
|
|
1855
|
+
propertiesTableName
|
|
1856
|
+
};
|
|
1857
|
+
if (columns) {
|
|
1858
|
+
urlParameters.columns = columns.join(",");
|
|
1859
|
+
}
|
|
1860
|
+
if (filters) {
|
|
1861
|
+
urlParameters.filters = filters;
|
|
1862
|
+
}
|
|
1863
|
+
return baseSource(
|
|
1864
|
+
"boundary",
|
|
1865
|
+
options,
|
|
1866
|
+
urlParameters
|
|
1867
|
+
);
|
|
1868
|
+
};
|
|
1869
|
+
|
|
1870
|
+
// src/spatial-index.ts
|
|
1871
|
+
var DEFAULT_TILE_SIZE = 512;
|
|
1872
|
+
var QUADBIN_ZOOM_MAX_OFFSET = 4;
|
|
1873
|
+
function getSpatialFiltersResolution(source, viewState) {
|
|
1874
|
+
const dataResolution = source.dataResolution ?? Number.MAX_VALUE;
|
|
1875
|
+
const aggregationResLevel = source.aggregationResLevel ?? (source.spatialDataType === "h3" ? DEFAULT_AGGREGATION_RES_LEVEL_H3 : DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN);
|
|
1876
|
+
const aggregationResLevelOffset = Math.max(
|
|
1877
|
+
0,
|
|
1878
|
+
Math.floor(aggregationResLevel)
|
|
1879
|
+
);
|
|
1880
|
+
const currentZoomInt = Math.ceil(viewState.zoom);
|
|
1881
|
+
if (source.spatialDataType === "h3") {
|
|
1882
|
+
const tileSize = DEFAULT_TILE_SIZE;
|
|
1883
|
+
const maxResolutionForZoom = maxH3SpatialFiltersResolutions.find(
|
|
1884
|
+
([zoom]) => zoom === currentZoomInt
|
|
1885
|
+
)?.[1] ?? Math.max(0, currentZoomInt - 3);
|
|
1886
|
+
const maxSpatialFiltersResolution = maxResolutionForZoom ? Math.min(dataResolution, maxResolutionForZoom) : dataResolution;
|
|
1887
|
+
const hexagonResolution = _getHexagonResolution(viewState, tileSize) + aggregationResLevelOffset;
|
|
1888
|
+
return Math.min(hexagonResolution, maxSpatialFiltersResolution);
|
|
1889
|
+
}
|
|
1890
|
+
if (source.spatialDataType === "quadbin") {
|
|
1891
|
+
const maxResolutionForZoom = currentZoomInt + QUADBIN_ZOOM_MAX_OFFSET;
|
|
1892
|
+
const maxSpatialFiltersResolution = Math.min(
|
|
1893
|
+
dataResolution,
|
|
1894
|
+
maxResolutionForZoom
|
|
1895
|
+
);
|
|
1896
|
+
const quadsResolution = Math.floor(viewState.zoom) + aggregationResLevelOffset;
|
|
1897
|
+
return Math.min(quadsResolution, maxSpatialFiltersResolution);
|
|
1898
|
+
}
|
|
1899
|
+
return void 0;
|
|
1900
|
+
}
|
|
1901
|
+
var maxH3SpatialFiltersResolutions = [
|
|
1902
|
+
[20, 14],
|
|
1903
|
+
[19, 13],
|
|
1904
|
+
[18, 12],
|
|
1905
|
+
[17, 11],
|
|
1906
|
+
[16, 10],
|
|
1907
|
+
[15, 9],
|
|
1908
|
+
[14, 8],
|
|
1909
|
+
[13, 7],
|
|
1910
|
+
[12, 7],
|
|
1911
|
+
[11, 7],
|
|
1912
|
+
[10, 6],
|
|
1913
|
+
[9, 6],
|
|
1914
|
+
[8, 5],
|
|
1915
|
+
[7, 4],
|
|
1916
|
+
[6, 4],
|
|
1917
|
+
[5, 3],
|
|
1918
|
+
[4, 2],
|
|
1919
|
+
[3, 1],
|
|
1920
|
+
[2, 1],
|
|
1921
|
+
[1, 0]
|
|
1922
|
+
];
|
|
1923
|
+
var BIAS = 2;
|
|
1924
|
+
function _getHexagonResolution(viewport, tileSize) {
|
|
1925
|
+
const zoomOffset = Math.log2(tileSize / DEFAULT_TILE_SIZE);
|
|
1926
|
+
const hexagonScaleFactor = 2 / 3 * (viewport.zoom - zoomOffset);
|
|
1927
|
+
const latitudeScaleFactor = Math.log(
|
|
1928
|
+
1 / Math.cos(Math.PI * viewport.latitude / 180)
|
|
1929
|
+
);
|
|
1930
|
+
return Math.max(
|
|
1931
|
+
0,
|
|
1932
|
+
Math.floor(hexagonScaleFactor + latitudeScaleFactor - BIAS)
|
|
1933
|
+
);
|
|
1934
|
+
}
|
|
1935
|
+
|
|
1936
|
+
// src/widget-sources/widget-source.ts
|
|
1937
|
+
var _WidgetSource = class _WidgetSource {
|
|
1938
|
+
constructor(props) {
|
|
1939
|
+
__publicField(this, "props");
|
|
1940
|
+
this.props = { ..._WidgetSource.defaultProps, ...props };
|
|
1941
|
+
}
|
|
1942
|
+
/**
|
|
1943
|
+
* Destroys the widget source and releases allocated resources.
|
|
1944
|
+
*
|
|
1945
|
+
* For remote sources (tables, queries) this has no effect, but for local
|
|
1946
|
+
* sources (tilesets, rasters) these resources will affect performance
|
|
1947
|
+
* and stability if many (10+) sources are created and not released.
|
|
1948
|
+
*/
|
|
1949
|
+
destroy() {
|
|
1950
|
+
}
|
|
1951
|
+
_getSpatialFiltersResolution(source, spatialFilter, referenceViewState) {
|
|
1952
|
+
if (!spatialFilter || source.spatialDataType === "geo") {
|
|
1953
|
+
return;
|
|
1954
|
+
}
|
|
1955
|
+
if (!referenceViewState) {
|
|
1956
|
+
throw new Error(
|
|
1957
|
+
'Missing required option, "spatialIndexReferenceViewState".'
|
|
1958
|
+
);
|
|
1959
|
+
}
|
|
1960
|
+
return getSpatialFiltersResolution(source, referenceViewState);
|
|
1961
|
+
}
|
|
1962
|
+
};
|
|
1963
|
+
__publicField(_WidgetSource, "defaultProps", {
|
|
1964
|
+
apiVersion: "v3" /* V3 */,
|
|
1965
|
+
apiBaseUrl: DEFAULT_API_BASE_URL,
|
|
1966
|
+
clientId: getClient(),
|
|
1967
|
+
filters: {},
|
|
1968
|
+
filtersLogicalOperator: "and"
|
|
1969
|
+
});
|
|
1970
|
+
var WidgetSource = _WidgetSource;
|
|
1971
|
+
|
|
1972
|
+
// src/models/common.ts
|
|
1973
|
+
function dealWithApiError({
|
|
1974
|
+
response,
|
|
1975
|
+
data
|
|
1976
|
+
}) {
|
|
1977
|
+
if (data.error === "Column not found") {
|
|
1978
|
+
throw new InvalidColumnError(`${data.error} ${data.column_name}`);
|
|
1979
|
+
}
|
|
1980
|
+
if (typeof data.error === "string" && data.error?.includes("Missing columns")) {
|
|
1981
|
+
throw new InvalidColumnError(data.error);
|
|
1982
|
+
}
|
|
1983
|
+
switch (response.status) {
|
|
1984
|
+
case 401:
|
|
1985
|
+
throw new Error("Unauthorized access. Invalid credentials");
|
|
1986
|
+
case 403:
|
|
1987
|
+
throw new Error("Forbidden access to the requested data");
|
|
1988
|
+
default:
|
|
1989
|
+
throw new Error(
|
|
1990
|
+
data && data.error && typeof data.error === "string" ? data.error : JSON.stringify(data?.hint || data.error?.[0])
|
|
1991
|
+
);
|
|
1992
|
+
}
|
|
1993
|
+
}
|
|
1994
|
+
async function makeCall({
|
|
1995
|
+
url,
|
|
1996
|
+
accessToken,
|
|
1997
|
+
opts
|
|
1998
|
+
}) {
|
|
1999
|
+
let response;
|
|
2000
|
+
let data;
|
|
2001
|
+
const isPost = opts?.method === "POST";
|
|
2002
|
+
try {
|
|
2003
|
+
response = await fetch(url.toString(), {
|
|
2004
|
+
headers: {
|
|
2005
|
+
Authorization: `Bearer ${accessToken}`,
|
|
2006
|
+
...isPost && { "Content-Type": "application/json" },
|
|
2007
|
+
...opts.headers
|
|
2008
|
+
},
|
|
2009
|
+
...isPost && {
|
|
2010
|
+
method: opts?.method,
|
|
2011
|
+
body: opts?.body
|
|
2012
|
+
},
|
|
2013
|
+
signal: opts?.signal,
|
|
2014
|
+
...opts?.otherOptions
|
|
2015
|
+
});
|
|
2016
|
+
data = await response.json();
|
|
2017
|
+
} catch (error) {
|
|
2018
|
+
if (error.name === "AbortError") throw error;
|
|
2019
|
+
throw new Error(`Failed request: ${error}`);
|
|
2020
|
+
}
|
|
2021
|
+
if (!response.ok) {
|
|
2022
|
+
dealWithApiError({ response, data });
|
|
2023
|
+
}
|
|
2024
|
+
return data;
|
|
2025
|
+
}
|
|
2026
|
+
|
|
2027
|
+
// src/models/model.ts
|
|
2028
|
+
var AVAILABLE_MODELS = [
|
|
2029
|
+
"category",
|
|
2030
|
+
"histogram",
|
|
2031
|
+
"formula",
|
|
2032
|
+
"pick",
|
|
2033
|
+
"timeseries",
|
|
2034
|
+
"range",
|
|
2035
|
+
"scatterplot",
|
|
2036
|
+
"table"
|
|
2037
|
+
];
|
|
2038
|
+
var { V3 } = ApiVersion;
|
|
2039
|
+
var REQUEST_GET_MAX_URL_LENGTH = 2048;
|
|
2040
|
+
function executeModel(props) {
|
|
2041
|
+
assert2(props.source, "executeModel: missing source");
|
|
2042
|
+
assert2(props.model, "executeModel: missing model");
|
|
2043
|
+
assert2(props.params, "executeModel: missing params");
|
|
2044
|
+
assert2(
|
|
2045
|
+
AVAILABLE_MODELS.includes(props.model),
|
|
2046
|
+
`executeModel: model provided isn't valid. Available models: ${AVAILABLE_MODELS.join(
|
|
2047
|
+
", "
|
|
2048
|
+
)}`
|
|
2049
|
+
);
|
|
2050
|
+
const { model, source, params, opts } = props;
|
|
2051
|
+
const { type, apiVersion, apiBaseUrl, accessToken, connectionName, clientId } = source;
|
|
2052
|
+
assert2(apiBaseUrl, "executeModel: missing apiBaseUrl");
|
|
2053
|
+
assert2(accessToken, "executeModel: missing accessToken");
|
|
2054
|
+
assert2(apiVersion === V3, "executeModel: SQL Model API requires CARTO 3+");
|
|
2055
|
+
assert2(type !== "tileset", "executeModel: Tilesets not supported");
|
|
2056
|
+
let url = `${apiBaseUrl}/v3/sql/${connectionName}/model/${model}`;
|
|
2057
|
+
const {
|
|
2058
|
+
data,
|
|
2059
|
+
filters,
|
|
2060
|
+
filtersLogicalOperator = "and",
|
|
2061
|
+
spatialDataType = "geo",
|
|
2062
|
+
spatialFiltersMode = "intersects",
|
|
2063
|
+
spatialFiltersResolution = 0
|
|
2064
|
+
} = source;
|
|
2065
|
+
const queryParams = {
|
|
2066
|
+
type,
|
|
2067
|
+
client: clientId,
|
|
2068
|
+
source: data,
|
|
2069
|
+
params,
|
|
2070
|
+
queryParameters: source.queryParameters || "",
|
|
2071
|
+
filters,
|
|
2072
|
+
filtersLogicalOperator
|
|
2073
|
+
};
|
|
2074
|
+
const spatialDataColumn = source.spatialDataColumn || DEFAULT_GEO_COLUMN;
|
|
2075
|
+
if (model === "pick") {
|
|
2076
|
+
queryParams.spatialDataColumn = spatialDataColumn;
|
|
2077
|
+
}
|
|
2078
|
+
const spatialFilters = source.spatialFilter ? { [spatialDataColumn]: source.spatialFilter } : void 0;
|
|
2079
|
+
if (spatialFilters) {
|
|
2080
|
+
queryParams.spatialFilters = spatialFilters;
|
|
2081
|
+
queryParams.spatialDataColumn = spatialDataColumn;
|
|
2082
|
+
queryParams.spatialDataType = spatialDataType;
|
|
2083
|
+
}
|
|
2084
|
+
if (spatialDataType !== "geo") {
|
|
2085
|
+
if (spatialFiltersResolution > 0) {
|
|
2086
|
+
queryParams.spatialFiltersResolution = spatialFiltersResolution;
|
|
2087
|
+
}
|
|
2088
|
+
queryParams.spatialFiltersMode = spatialFiltersMode;
|
|
2089
|
+
}
|
|
2090
|
+
const urlWithSearchParams = url + "?" + objectToURLSearchParams(queryParams).toString();
|
|
2091
|
+
const isGet = urlWithSearchParams.length <= REQUEST_GET_MAX_URL_LENGTH;
|
|
2092
|
+
if (isGet) {
|
|
2093
|
+
url = urlWithSearchParams;
|
|
2094
|
+
}
|
|
2095
|
+
return makeCall({
|
|
2096
|
+
url,
|
|
2097
|
+
accessToken: source.accessToken,
|
|
2098
|
+
opts: {
|
|
2099
|
+
...opts,
|
|
2100
|
+
method: isGet ? "GET" : "POST",
|
|
2101
|
+
...!isGet && { body: JSON.stringify(queryParams) }
|
|
2102
|
+
}
|
|
2103
|
+
});
|
|
2104
|
+
}
|
|
2105
|
+
function objectToURLSearchParams(object) {
|
|
2106
|
+
const params = new URLSearchParams();
|
|
2107
|
+
for (const key in object) {
|
|
2108
|
+
if (isPureObject(object[key])) {
|
|
2109
|
+
params.append(key, JSON.stringify(object[key]));
|
|
2110
|
+
} else if (Array.isArray(object[key])) {
|
|
2111
|
+
params.append(key, JSON.stringify(object[key]));
|
|
2112
|
+
} else if (object[key] === null) {
|
|
2113
|
+
params.append(key, "null");
|
|
2114
|
+
} else if (object[key] !== void 0) {
|
|
2115
|
+
params.append(key, String(object[key]));
|
|
2116
|
+
}
|
|
2117
|
+
}
|
|
2118
|
+
return params;
|
|
2119
|
+
}
|
|
2120
|
+
|
|
2121
|
+
// src/widget-sources/widget-remote-source.ts
|
|
2122
|
+
var WidgetRemoteSource = class extends WidgetSource {
|
|
2123
|
+
_getModelSource(filters, filterOwner) {
|
|
2124
|
+
const props = this.props;
|
|
2125
|
+
return {
|
|
2126
|
+
apiVersion: props.apiVersion,
|
|
2127
|
+
apiBaseUrl: props.apiBaseUrl,
|
|
2128
|
+
clientId: props.clientId,
|
|
2129
|
+
accessToken: props.accessToken,
|
|
2130
|
+
connectionName: props.connectionName,
|
|
2131
|
+
filters: getApplicableFilters(filterOwner, filters || props.filters),
|
|
2132
|
+
filtersLogicalOperator: props.filtersLogicalOperator,
|
|
2133
|
+
spatialDataType: props.spatialDataType,
|
|
2134
|
+
spatialDataColumn: props.spatialDataColumn,
|
|
2135
|
+
dataResolution: props.dataResolution
|
|
2136
|
+
};
|
|
2137
|
+
}
|
|
2138
|
+
async getCategories(options) {
|
|
2139
|
+
const {
|
|
2140
|
+
signal,
|
|
2141
|
+
filters = this.props.filters,
|
|
2142
|
+
filterOwner,
|
|
2143
|
+
spatialFilter,
|
|
2144
|
+
spatialFiltersMode,
|
|
2145
|
+
spatialIndexReferenceViewState,
|
|
2146
|
+
...params
|
|
2147
|
+
} = options;
|
|
2148
|
+
const { column, operation, operationColumn } = params;
|
|
2149
|
+
const source = this.getModelSource(filters, filterOwner);
|
|
2150
|
+
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
2151
|
+
source,
|
|
2152
|
+
spatialFilter,
|
|
2153
|
+
spatialIndexReferenceViewState
|
|
2154
|
+
);
|
|
2155
|
+
return executeModel({
|
|
2156
|
+
model: "category",
|
|
2157
|
+
source: {
|
|
2158
|
+
...source,
|
|
2159
|
+
spatialFiltersResolution,
|
|
2160
|
+
spatialFiltersMode,
|
|
2161
|
+
spatialFilter
|
|
2162
|
+
},
|
|
2163
|
+
params: {
|
|
2164
|
+
column,
|
|
2165
|
+
operation,
|
|
2166
|
+
operationColumn: operationColumn || column
|
|
2167
|
+
},
|
|
2168
|
+
opts: { signal, headers: this.props.headers }
|
|
2169
|
+
}).then((res) => normalizeObjectKeys(res.rows));
|
|
2170
|
+
}
|
|
2171
|
+
async getFeatures(options) {
|
|
2172
|
+
const {
|
|
2173
|
+
signal,
|
|
2174
|
+
filters = this.props.filters,
|
|
2175
|
+
filterOwner,
|
|
2176
|
+
spatialFilter,
|
|
2177
|
+
spatialFiltersMode,
|
|
2178
|
+
spatialIndexReferenceViewState,
|
|
2179
|
+
...params
|
|
2180
|
+
} = options;
|
|
2181
|
+
const { columns, dataType, featureIds, z, limit, tileResolution } = params;
|
|
2182
|
+
const source = this.getModelSource(filters, filterOwner);
|
|
2183
|
+
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
2184
|
+
source,
|
|
2185
|
+
spatialFilter,
|
|
2186
|
+
spatialIndexReferenceViewState
|
|
2187
|
+
);
|
|
2188
|
+
return executeModel({
|
|
2189
|
+
model: "pick",
|
|
2190
|
+
source: {
|
|
2191
|
+
...source,
|
|
2192
|
+
spatialFiltersResolution,
|
|
2193
|
+
spatialFiltersMode,
|
|
2194
|
+
spatialFilter
|
|
2195
|
+
},
|
|
2196
|
+
params: {
|
|
2197
|
+
columns,
|
|
2198
|
+
dataType,
|
|
2199
|
+
featureIds,
|
|
2200
|
+
z,
|
|
2201
|
+
limit: limit || 1e3,
|
|
2202
|
+
tileResolution: tileResolution || DEFAULT_TILE_RESOLUTION
|
|
2203
|
+
},
|
|
2204
|
+
opts: { signal, headers: this.props.headers }
|
|
2205
|
+
// Avoid `normalizeObjectKeys()`, which changes column names.
|
|
2206
|
+
}).then(({ rows }) => ({ rows }));
|
|
2207
|
+
}
|
|
2208
|
+
async getFormula(options) {
|
|
2209
|
+
const {
|
|
2210
|
+
signal,
|
|
2211
|
+
filters = this.props.filters,
|
|
2212
|
+
filterOwner,
|
|
2213
|
+
spatialFilter,
|
|
2214
|
+
spatialFiltersMode,
|
|
2215
|
+
spatialIndexReferenceViewState,
|
|
2216
|
+
operationExp,
|
|
2217
|
+
...params
|
|
2218
|
+
} = options;
|
|
2219
|
+
const { column, operation } = params;
|
|
2220
|
+
const source = this.getModelSource(filters, filterOwner);
|
|
2221
|
+
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
2222
|
+
source,
|
|
2223
|
+
spatialFilter,
|
|
2224
|
+
spatialIndexReferenceViewState
|
|
2225
|
+
);
|
|
2226
|
+
return executeModel({
|
|
2227
|
+
model: "formula",
|
|
2228
|
+
source: {
|
|
2229
|
+
...source,
|
|
2230
|
+
spatialFiltersResolution,
|
|
2231
|
+
spatialFiltersMode,
|
|
2232
|
+
spatialFilter
|
|
2233
|
+
},
|
|
2234
|
+
params: {
|
|
2235
|
+
column: column ?? "*",
|
|
2236
|
+
operation: operation ?? "count",
|
|
2237
|
+
operationExp
|
|
2238
|
+
},
|
|
2239
|
+
opts: { signal, headers: this.props.headers }
|
|
2240
|
+
}).then((res) => normalizeObjectKeys(res.rows[0]));
|
|
2241
|
+
}
|
|
2242
|
+
async getHistogram(options) {
|
|
2243
|
+
const {
|
|
2244
|
+
signal,
|
|
2245
|
+
filters = this.props.filters,
|
|
2246
|
+
filterOwner,
|
|
2247
|
+
spatialFilter,
|
|
2248
|
+
spatialFiltersMode,
|
|
2249
|
+
spatialIndexReferenceViewState,
|
|
2250
|
+
...params
|
|
2251
|
+
} = options;
|
|
2252
|
+
const { column, operation, ticks } = params;
|
|
2253
|
+
const source = this.getModelSource(filters, filterOwner);
|
|
2254
|
+
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
2255
|
+
source,
|
|
2256
|
+
spatialFilter,
|
|
2257
|
+
spatialIndexReferenceViewState
|
|
2258
|
+
);
|
|
2259
|
+
const data = await executeModel({
|
|
2260
|
+
model: "histogram",
|
|
2261
|
+
source: {
|
|
2262
|
+
...source,
|
|
2263
|
+
spatialFiltersResolution,
|
|
2264
|
+
spatialFiltersMode,
|
|
2265
|
+
spatialFilter
|
|
2266
|
+
},
|
|
2267
|
+
params: { column, operation, ticks },
|
|
2268
|
+
opts: { signal, headers: this.props.headers }
|
|
2269
|
+
}).then((res) => normalizeObjectKeys(res.rows));
|
|
2270
|
+
if (data.length) {
|
|
2271
|
+
const result = Array(ticks.length + 1).fill(0);
|
|
2272
|
+
data.forEach(
|
|
2273
|
+
({ tick, value }) => result[tick] = value
|
|
2274
|
+
);
|
|
2275
|
+
return result;
|
|
2276
|
+
}
|
|
2277
|
+
return [];
|
|
2278
|
+
}
|
|
2279
|
+
async getRange(options) {
|
|
2280
|
+
const {
|
|
2281
|
+
signal,
|
|
2282
|
+
filters = this.props.filters,
|
|
2283
|
+
filterOwner,
|
|
2284
|
+
spatialFilter,
|
|
2285
|
+
spatialFiltersMode,
|
|
2286
|
+
spatialIndexReferenceViewState,
|
|
2287
|
+
...params
|
|
2288
|
+
} = options;
|
|
2289
|
+
const { column } = params;
|
|
2290
|
+
const source = this.getModelSource(filters, filterOwner);
|
|
2291
|
+
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
2292
|
+
source,
|
|
2293
|
+
spatialFilter,
|
|
2294
|
+
spatialIndexReferenceViewState
|
|
2295
|
+
);
|
|
2296
|
+
return executeModel({
|
|
2297
|
+
model: "range",
|
|
2298
|
+
source: {
|
|
2299
|
+
...source,
|
|
2300
|
+
spatialFiltersResolution,
|
|
2301
|
+
spatialFiltersMode,
|
|
2302
|
+
spatialFilter
|
|
2303
|
+
},
|
|
2304
|
+
params: { column },
|
|
2305
|
+
opts: { signal, headers: this.props.headers }
|
|
2306
|
+
}).then((res) => normalizeObjectKeys(res.rows[0]));
|
|
2307
|
+
}
|
|
2308
|
+
async getScatter(options) {
|
|
2309
|
+
const {
|
|
2310
|
+
signal,
|
|
2311
|
+
filters = this.props.filters,
|
|
2312
|
+
filterOwner,
|
|
2313
|
+
spatialFilter,
|
|
2314
|
+
spatialFiltersMode,
|
|
2315
|
+
spatialIndexReferenceViewState,
|
|
2316
|
+
...params
|
|
2317
|
+
} = options;
|
|
2318
|
+
const { xAxisColumn, xAxisJoinOperation, yAxisColumn, yAxisJoinOperation } = params;
|
|
2319
|
+
const source = this.getModelSource(filters, filterOwner);
|
|
2320
|
+
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
2321
|
+
source,
|
|
2322
|
+
spatialFilter,
|
|
2323
|
+
spatialIndexReferenceViewState
|
|
2324
|
+
);
|
|
2325
|
+
const HARD_LIMIT = 500;
|
|
2326
|
+
return executeModel({
|
|
2327
|
+
model: "scatterplot",
|
|
2328
|
+
source: {
|
|
2329
|
+
...source,
|
|
2330
|
+
spatialFiltersResolution,
|
|
2331
|
+
spatialFiltersMode,
|
|
2332
|
+
spatialFilter
|
|
2333
|
+
},
|
|
2334
|
+
params: {
|
|
2335
|
+
xAxisColumn,
|
|
2336
|
+
xAxisJoinOperation,
|
|
2337
|
+
yAxisColumn,
|
|
2338
|
+
yAxisJoinOperation,
|
|
2339
|
+
limit: HARD_LIMIT
|
|
2340
|
+
},
|
|
2341
|
+
opts: { signal, headers: this.props.headers }
|
|
2342
|
+
}).then((res) => normalizeObjectKeys(res.rows)).then((res) => res.map(({ x, y }) => [x, y]));
|
|
2343
|
+
}
|
|
2344
|
+
async getTable(options) {
|
|
2345
|
+
const {
|
|
2346
|
+
signal,
|
|
2347
|
+
filters = this.props.filters,
|
|
2348
|
+
filterOwner,
|
|
2349
|
+
spatialFilter,
|
|
2350
|
+
spatialFiltersMode,
|
|
2351
|
+
spatialIndexReferenceViewState,
|
|
2352
|
+
...params
|
|
2353
|
+
} = options;
|
|
2354
|
+
const { columns, sortBy, sortDirection, offset = 0, limit = 10 } = params;
|
|
2355
|
+
const source = this.getModelSource(filters, filterOwner);
|
|
2356
|
+
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
2357
|
+
source,
|
|
2358
|
+
spatialFilter,
|
|
2359
|
+
spatialIndexReferenceViewState
|
|
2360
|
+
);
|
|
2361
|
+
return executeModel({
|
|
2362
|
+
model: "table",
|
|
2363
|
+
source: {
|
|
2364
|
+
...source,
|
|
2365
|
+
spatialFiltersResolution,
|
|
2366
|
+
spatialFiltersMode,
|
|
2367
|
+
spatialFilter
|
|
2368
|
+
},
|
|
2369
|
+
params: {
|
|
2370
|
+
column: columns,
|
|
2371
|
+
sortBy,
|
|
2372
|
+
sortDirection,
|
|
2373
|
+
limit,
|
|
2374
|
+
offset
|
|
2375
|
+
},
|
|
2376
|
+
opts: { signal, headers: this.props.headers }
|
|
2377
|
+
}).then((res) => ({
|
|
2378
|
+
// Avoid `normalizeObjectKeys()`, which changes column names.
|
|
2379
|
+
rows: res.rows ?? res.ROWS,
|
|
2380
|
+
totalCount: res.metadata?.total ?? res.METADATA?.TOTAL
|
|
2381
|
+
}));
|
|
2382
|
+
}
|
|
2383
|
+
async getTimeSeries(options) {
|
|
2384
|
+
const {
|
|
2385
|
+
signal,
|
|
2386
|
+
filters = this.props.filters,
|
|
2387
|
+
filterOwner,
|
|
2388
|
+
spatialFilter,
|
|
2389
|
+
spatialFiltersMode,
|
|
2390
|
+
spatialIndexReferenceViewState,
|
|
2391
|
+
...params
|
|
2392
|
+
} = options;
|
|
2393
|
+
const {
|
|
2394
|
+
column,
|
|
2395
|
+
operationColumn,
|
|
2396
|
+
joinOperation,
|
|
2397
|
+
operation,
|
|
2398
|
+
stepSize,
|
|
2399
|
+
stepMultiplier,
|
|
2400
|
+
splitByCategory,
|
|
2401
|
+
splitByCategoryLimit,
|
|
2402
|
+
splitByCategoryValues
|
|
2403
|
+
} = params;
|
|
2404
|
+
const source = this.getModelSource(filters, filterOwner);
|
|
2405
|
+
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
2406
|
+
source,
|
|
2407
|
+
spatialFilter,
|
|
2408
|
+
spatialIndexReferenceViewState
|
|
2409
|
+
);
|
|
2410
|
+
return executeModel({
|
|
2411
|
+
model: "timeseries",
|
|
2412
|
+
source: {
|
|
2413
|
+
...source,
|
|
2414
|
+
spatialFiltersResolution,
|
|
2415
|
+
spatialFiltersMode,
|
|
2416
|
+
spatialFilter
|
|
2417
|
+
},
|
|
2418
|
+
params: {
|
|
2419
|
+
column,
|
|
2420
|
+
stepSize,
|
|
2421
|
+
stepMultiplier,
|
|
2422
|
+
operationColumn: operationColumn || column,
|
|
2423
|
+
joinOperation,
|
|
2424
|
+
operation,
|
|
2425
|
+
splitByCategory,
|
|
2426
|
+
splitByCategoryLimit,
|
|
2427
|
+
splitByCategoryValues
|
|
2428
|
+
},
|
|
2429
|
+
opts: { signal, headers: this.props.headers }
|
|
2430
|
+
}).then((res) => ({
|
|
2431
|
+
rows: normalizeObjectKeys(res.rows),
|
|
2432
|
+
categories: res.metadata?.categories
|
|
2433
|
+
}));
|
|
2434
|
+
}
|
|
2435
|
+
};
|
|
2436
|
+
|
|
2437
|
+
// src/widget-sources/widget-query-source.ts
|
|
2438
|
+
var WidgetQuerySource = class extends WidgetRemoteSource {
|
|
2439
|
+
getModelSource(filters, filterOwner) {
|
|
2440
|
+
return {
|
|
2441
|
+
...super._getModelSource(filters, filterOwner),
|
|
2442
|
+
type: "query",
|
|
2443
|
+
data: this.props.sqlQuery,
|
|
2444
|
+
queryParameters: this.props.queryParameters
|
|
2445
|
+
};
|
|
2446
|
+
}
|
|
2447
|
+
};
|
|
2448
|
+
|
|
2449
|
+
// src/widget-sources/widget-table-source.ts
|
|
2450
|
+
var WidgetTableSource = class extends WidgetRemoteSource {
|
|
2451
|
+
getModelSource(filters, filterOwner) {
|
|
2452
|
+
return {
|
|
2453
|
+
...super._getModelSource(filters, filterOwner),
|
|
2454
|
+
type: "table",
|
|
2455
|
+
data: this.props.tableName
|
|
2456
|
+
};
|
|
2457
|
+
}
|
|
2458
|
+
};
|
|
2459
|
+
|
|
2460
|
+
// src/operations/aggregation.ts
|
|
2461
|
+
var aggregationFunctions = {
|
|
2462
|
+
count: (values) => values.length,
|
|
2463
|
+
min: (...args) => applyAggregationFunction(min, ...args),
|
|
2464
|
+
max: (...args) => applyAggregationFunction(max, ...args),
|
|
2465
|
+
sum: (...args) => applyAggregationFunction(sum, ...args),
|
|
2466
|
+
avg: (...args) => applyAggregationFunction(avg, ...args)
|
|
2467
|
+
};
|
|
2468
|
+
function aggregate(feature2, keys, operation) {
|
|
2469
|
+
if (!keys?.length) {
|
|
2470
|
+
throw new Error("Cannot aggregate a feature without having keys");
|
|
2471
|
+
} else if (keys.length === 1) {
|
|
2472
|
+
const value = feature2[keys[0]];
|
|
2473
|
+
return isPotentiallyValidNumber(value) ? Number(value) : value;
|
|
2474
|
+
}
|
|
2475
|
+
const aggregationFn = aggregationFunctions[operation];
|
|
2476
|
+
if (!aggregationFn) {
|
|
2477
|
+
throw new Error(`${operation} isn't a valid aggregation function`);
|
|
2478
|
+
}
|
|
2479
|
+
return aggregationFn(
|
|
2480
|
+
keys.map((column) => {
|
|
2481
|
+
const value = feature2[column];
|
|
2482
|
+
return isPotentiallyValidNumber(value) ? Number(value) : value;
|
|
2483
|
+
})
|
|
2484
|
+
);
|
|
2485
|
+
}
|
|
2486
|
+
function isPotentiallyValidNumber(value) {
|
|
2487
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
2488
|
+
}
|
|
2489
|
+
var applyAggregationFunction = (aggFn, values, keys, operation) => {
|
|
2490
|
+
const normalizedKeys = normalizeKeys(keys);
|
|
2491
|
+
const elements = (normalizedKeys?.length || 0) <= 1 ? filterFalsyElements(values, normalizedKeys || []) : values;
|
|
2492
|
+
return aggFn(elements, keys, operation);
|
|
2493
|
+
};
|
|
2494
|
+
function filterFalsyElements(values, keys) {
|
|
2495
|
+
const filterFn = (value) => value !== null && value !== void 0;
|
|
2496
|
+
if (!keys?.length) {
|
|
2497
|
+
return values.filter(filterFn);
|
|
2498
|
+
}
|
|
2499
|
+
return values.filter((v) => filterFn(v[keys[0]]));
|
|
2500
|
+
}
|
|
2501
|
+
function avg(values, keys, joinOperation) {
|
|
2502
|
+
return sum(values, keys, joinOperation) / (values.length || 1);
|
|
2503
|
+
}
|
|
2504
|
+
function sum(values, keys, joinOperation) {
|
|
2505
|
+
const normalizedKeys = normalizeKeys(keys);
|
|
2506
|
+
if (normalizedKeys) {
|
|
2507
|
+
return values.reduce(
|
|
2508
|
+
(a, b) => a + aggregate(b, normalizedKeys, joinOperation),
|
|
2509
|
+
0
|
|
2510
|
+
);
|
|
2511
|
+
}
|
|
2512
|
+
return values.reduce((a, b) => a + b, 0);
|
|
2513
|
+
}
|
|
2514
|
+
function min(values, keys, joinOperation) {
|
|
2515
|
+
const normalizedKeys = normalizeKeys(keys);
|
|
2516
|
+
if (normalizedKeys) {
|
|
2517
|
+
return values.reduce(
|
|
2518
|
+
(a, b) => Math.min(a, aggregate(b, normalizedKeys, joinOperation)),
|
|
2519
|
+
Infinity
|
|
2520
|
+
);
|
|
2521
|
+
}
|
|
2522
|
+
return Math.min(...values);
|
|
2523
|
+
}
|
|
2524
|
+
function max(values, keys, joinOperation) {
|
|
2525
|
+
const normalizedKeys = normalizeKeys(keys);
|
|
2526
|
+
if (normalizedKeys) {
|
|
2527
|
+
return values.reduce(
|
|
2528
|
+
(a, b) => Math.max(a, aggregate(b, normalizedKeys, joinOperation)),
|
|
2529
|
+
-Infinity
|
|
2530
|
+
);
|
|
2531
|
+
}
|
|
2532
|
+
return Math.max(...values);
|
|
2533
|
+
}
|
|
2534
|
+
function normalizeKeys(keys) {
|
|
2535
|
+
return Array.isArray(keys) ? keys : typeof keys === "string" ? [keys] : void 0;
|
|
2536
|
+
}
|
|
2537
|
+
|
|
2538
|
+
// src/operations/applySorting.ts
|
|
2539
|
+
var import_thenby = __toESM(require_thenBy_module(), 1);
|
|
2540
|
+
function applySorting(features, {
|
|
2541
|
+
sortBy,
|
|
2542
|
+
sortByDirection = "asc",
|
|
2543
|
+
sortByColumnType = "string"
|
|
2544
|
+
} = {}) {
|
|
2545
|
+
if (sortBy === void 0) {
|
|
2546
|
+
return features;
|
|
2547
|
+
}
|
|
2548
|
+
const isValidSortBy = Array.isArray(sortBy) && sortBy.length || // sortBy can be an array of columns
|
|
2549
|
+
typeof sortBy === "string";
|
|
2550
|
+
if (!isValidSortBy) {
|
|
2551
|
+
throw new Error("Sorting options are bad formatted");
|
|
2552
|
+
}
|
|
2553
|
+
const sortFn = createSortFn({
|
|
2554
|
+
sortBy,
|
|
2555
|
+
sortByDirection,
|
|
2556
|
+
sortByColumnType: sortByColumnType || "string"
|
|
2557
|
+
});
|
|
2558
|
+
return features.sort(sortFn);
|
|
2559
|
+
}
|
|
2560
|
+
function createSortFn({
|
|
2561
|
+
sortBy,
|
|
2562
|
+
sortByDirection,
|
|
2563
|
+
sortByColumnType
|
|
2564
|
+
}) {
|
|
2565
|
+
const [firstSortOption, ...othersSortOptions] = normalizeSortByOptions({
|
|
2566
|
+
sortBy,
|
|
2567
|
+
sortByDirection,
|
|
2568
|
+
sortByColumnType
|
|
2569
|
+
});
|
|
2570
|
+
let sortFn = (0, import_thenby.firstBy)(...firstSortOption);
|
|
2571
|
+
for (const sortOptions of othersSortOptions) {
|
|
2572
|
+
sortFn = sortFn.thenBy(...sortOptions);
|
|
2573
|
+
}
|
|
2574
|
+
return sortFn;
|
|
2575
|
+
}
|
|
2576
|
+
function normalizeSortByOptions({
|
|
2577
|
+
sortBy,
|
|
2578
|
+
sortByDirection,
|
|
2579
|
+
sortByColumnType
|
|
2580
|
+
}) {
|
|
2581
|
+
const numberFormat = sortByColumnType === "number" && {
|
|
2582
|
+
cmp: (a, b) => a - b
|
|
2583
|
+
};
|
|
2584
|
+
if (!Array.isArray(sortBy)) {
|
|
2585
|
+
sortBy = [sortBy];
|
|
2586
|
+
}
|
|
2587
|
+
return sortBy.map((sortByEl) => {
|
|
2588
|
+
if (typeof sortByEl === "string") {
|
|
2589
|
+
return [sortByEl, { direction: sortByDirection, ...numberFormat }];
|
|
2590
|
+
}
|
|
2591
|
+
if (Array.isArray(sortByEl)) {
|
|
2592
|
+
if (sortByEl[1] === void 0) {
|
|
2593
|
+
return [sortByEl, { direction: sortByDirection, ...numberFormat }];
|
|
2594
|
+
}
|
|
2595
|
+
if (typeof sortByEl[1] === "object") {
|
|
2596
|
+
const othersSortOptions = numberFormat ? { ...numberFormat, ...sortByEl[1] } : sortByEl[1];
|
|
2597
|
+
return [
|
|
2598
|
+
sortByEl[0],
|
|
2599
|
+
{ direction: sortByDirection, ...othersSortOptions }
|
|
2600
|
+
];
|
|
2601
|
+
}
|
|
2602
|
+
}
|
|
2603
|
+
return sortByEl;
|
|
2604
|
+
});
|
|
2605
|
+
}
|
|
2606
|
+
|
|
2607
|
+
// src/operations/groupBy.ts
|
|
2608
|
+
function groupValuesByColumn({
|
|
2609
|
+
data,
|
|
2610
|
+
valuesColumns,
|
|
2611
|
+
joinOperation,
|
|
2612
|
+
keysColumn,
|
|
2613
|
+
operation
|
|
2614
|
+
}) {
|
|
2615
|
+
if (Array.isArray(data) && data.length === 0) {
|
|
2616
|
+
return null;
|
|
2617
|
+
}
|
|
2618
|
+
const groups = data.reduce((accumulator, item) => {
|
|
2619
|
+
const group = item[keysColumn];
|
|
2620
|
+
const values = accumulator.get(group) || [];
|
|
2621
|
+
accumulator.set(group, values);
|
|
2622
|
+
const aggregatedValue = aggregate(item, valuesColumns, joinOperation);
|
|
2623
|
+
const isValid = (operation === "count" ? true : aggregatedValue !== null) && aggregatedValue !== void 0;
|
|
2624
|
+
if (isValid) {
|
|
2625
|
+
values.push(aggregatedValue);
|
|
2626
|
+
accumulator.set(group, values);
|
|
2627
|
+
}
|
|
2628
|
+
return accumulator;
|
|
2629
|
+
}, /* @__PURE__ */ new Map());
|
|
2630
|
+
const targetOperation = aggregationFunctions[operation];
|
|
2631
|
+
if (targetOperation) {
|
|
2632
|
+
return Array.from(groups).map(([name, value]) => ({
|
|
2633
|
+
name,
|
|
2634
|
+
value: targetOperation(value)
|
|
2635
|
+
}));
|
|
2636
|
+
}
|
|
2637
|
+
return [];
|
|
2638
|
+
}
|
|
2639
|
+
|
|
2640
|
+
// src/utils/dateUtils.ts
|
|
2641
|
+
function getUTCMonday(date) {
|
|
2642
|
+
const dateCp = new Date(date);
|
|
2643
|
+
const day = dateCp.getUTCDay();
|
|
2644
|
+
const diff = dateCp.getUTCDate() - day + (day ? 1 : -6);
|
|
2645
|
+
dateCp.setUTCDate(diff);
|
|
2646
|
+
return Date.UTC(
|
|
2647
|
+
dateCp.getUTCFullYear(),
|
|
2648
|
+
dateCp.getUTCMonth(),
|
|
2649
|
+
dateCp.getUTCDate()
|
|
2650
|
+
);
|
|
2651
|
+
}
|
|
2652
|
+
|
|
2653
|
+
// src/operations/groupByDate.ts
|
|
2654
|
+
var GROUP_KEY_FN_MAPPING = {
|
|
2655
|
+
year: (date) => Date.UTC(date.getUTCFullYear()),
|
|
2656
|
+
month: (date) => Date.UTC(date.getUTCFullYear(), date.getUTCMonth()),
|
|
2657
|
+
week: (date) => getUTCMonday(date),
|
|
2658
|
+
day: (date) => Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()),
|
|
2659
|
+
hour: (date) => Date.UTC(
|
|
2660
|
+
date.getUTCFullYear(),
|
|
2661
|
+
date.getUTCMonth(),
|
|
2662
|
+
date.getUTCDate(),
|
|
2663
|
+
date.getUTCHours()
|
|
2664
|
+
),
|
|
2665
|
+
minute: (date) => Date.UTC(
|
|
2666
|
+
date.getUTCFullYear(),
|
|
2667
|
+
date.getUTCMonth(),
|
|
2668
|
+
date.getUTCDate(),
|
|
2669
|
+
date.getUTCHours(),
|
|
2670
|
+
date.getUTCMinutes()
|
|
2671
|
+
),
|
|
2672
|
+
second: (date) => Date.UTC(
|
|
2673
|
+
date.getUTCFullYear(),
|
|
2674
|
+
date.getUTCMonth(),
|
|
2675
|
+
date.getUTCDate(),
|
|
2676
|
+
date.getUTCHours(),
|
|
2677
|
+
date.getUTCMinutes(),
|
|
2678
|
+
date.getUTCSeconds()
|
|
2679
|
+
)
|
|
2680
|
+
};
|
|
2681
|
+
function groupValuesByDateColumn({
|
|
2682
|
+
data,
|
|
2683
|
+
valuesColumns,
|
|
2684
|
+
joinOperation,
|
|
2685
|
+
keysColumn,
|
|
2686
|
+
groupType,
|
|
2687
|
+
operation
|
|
2688
|
+
}) {
|
|
2689
|
+
if (Array.isArray(data) && data.length === 0) {
|
|
2690
|
+
return null;
|
|
2691
|
+
}
|
|
2692
|
+
const groupKeyFn = GROUP_KEY_FN_MAPPING[groupType];
|
|
2693
|
+
if (!groupKeyFn) {
|
|
2694
|
+
return null;
|
|
2695
|
+
}
|
|
2696
|
+
const groups = data.reduce((acc, item) => {
|
|
2697
|
+
const value = item[keysColumn];
|
|
2698
|
+
const formattedValue = new Date(value);
|
|
2699
|
+
const groupKey = groupKeyFn(formattedValue);
|
|
2700
|
+
if (!isNaN(groupKey)) {
|
|
2701
|
+
let groupedValues = acc.get(groupKey);
|
|
2702
|
+
if (!groupedValues) {
|
|
2703
|
+
groupedValues = [];
|
|
2704
|
+
acc.set(groupKey, groupedValues);
|
|
2705
|
+
}
|
|
2706
|
+
const aggregatedValue = aggregate(item, valuesColumns, joinOperation);
|
|
2707
|
+
const isValid = aggregatedValue !== null && aggregatedValue !== void 0;
|
|
2708
|
+
if (isValid) {
|
|
2709
|
+
groupedValues.push(aggregatedValue);
|
|
2710
|
+
acc.set(groupKey, groupedValues);
|
|
2711
|
+
}
|
|
2712
|
+
}
|
|
2713
|
+
return acc;
|
|
2714
|
+
}, /* @__PURE__ */ new Map());
|
|
2715
|
+
const targetOperation = aggregationFunctions[operation];
|
|
2716
|
+
return [...groups.entries()].map(([name, value]) => ({
|
|
2717
|
+
name,
|
|
2718
|
+
value: targetOperation(value)
|
|
2719
|
+
})).sort((a, b) => a.name - b.name);
|
|
2720
|
+
}
|
|
2721
|
+
|
|
2722
|
+
// src/operations/histogram.ts
|
|
2723
|
+
function histogram({
|
|
2724
|
+
data,
|
|
2725
|
+
valuesColumns,
|
|
2726
|
+
joinOperation,
|
|
2727
|
+
ticks,
|
|
2728
|
+
operation
|
|
2729
|
+
}) {
|
|
2730
|
+
if (Array.isArray(data) && data.length === 0) {
|
|
2731
|
+
return [];
|
|
2732
|
+
}
|
|
2733
|
+
const binsContainer = [Number.MIN_SAFE_INTEGER, ...ticks].map(
|
|
2734
|
+
(tick, index, arr) => ({
|
|
2735
|
+
bin: index,
|
|
2736
|
+
start: tick,
|
|
2737
|
+
end: index === arr.length - 1 ? Number.MAX_SAFE_INTEGER : arr[index + 1],
|
|
2738
|
+
values: []
|
|
2739
|
+
})
|
|
2740
|
+
);
|
|
2741
|
+
data.forEach((feature2) => {
|
|
2742
|
+
const featureValue = aggregate(
|
|
2743
|
+
feature2,
|
|
2744
|
+
valuesColumns,
|
|
2745
|
+
joinOperation
|
|
2746
|
+
);
|
|
2747
|
+
const isValid = featureValue !== null && featureValue !== void 0;
|
|
2748
|
+
if (!isValid) {
|
|
2749
|
+
return;
|
|
2750
|
+
}
|
|
2751
|
+
const binContainer = binsContainer.find(
|
|
2752
|
+
(bin) => bin.start <= featureValue && bin.end > featureValue
|
|
2753
|
+
);
|
|
2754
|
+
if (!binContainer) {
|
|
2755
|
+
return;
|
|
2756
|
+
}
|
|
2757
|
+
binContainer.values.push(featureValue);
|
|
2758
|
+
});
|
|
2759
|
+
const targetOperation = aggregationFunctions[operation];
|
|
2760
|
+
const transformedBins = binsContainer.map(
|
|
2761
|
+
(binContainer) => binContainer.values
|
|
2762
|
+
);
|
|
2763
|
+
return transformedBins.map(
|
|
2764
|
+
(values) => values.length ? targetOperation(values) : 0
|
|
2765
|
+
);
|
|
2766
|
+
}
|
|
2767
|
+
|
|
2768
|
+
// src/operations/scatterPlot.ts
|
|
2769
|
+
function scatterPlot({
|
|
2770
|
+
data,
|
|
2771
|
+
xAxisColumns,
|
|
2772
|
+
xAxisJoinOperation,
|
|
2773
|
+
yAxisColumns,
|
|
2774
|
+
yAxisJoinOperation
|
|
2775
|
+
}) {
|
|
2776
|
+
return data.reduce(
|
|
2777
|
+
(acc, feature2) => {
|
|
2778
|
+
const xValue = aggregate(
|
|
2779
|
+
feature2,
|
|
2780
|
+
xAxisColumns,
|
|
2781
|
+
xAxisJoinOperation
|
|
2782
|
+
);
|
|
2783
|
+
const xIsValid = xValue !== null && xValue !== void 0;
|
|
2784
|
+
const yValue = aggregate(
|
|
2785
|
+
feature2,
|
|
2786
|
+
yAxisColumns,
|
|
2787
|
+
yAxisJoinOperation
|
|
2788
|
+
);
|
|
2789
|
+
const yIsValid = yValue !== null && yValue !== void 0;
|
|
2790
|
+
if (xIsValid && yIsValid) {
|
|
2791
|
+
acc.push([xValue, yValue]);
|
|
2792
|
+
}
|
|
2793
|
+
return acc;
|
|
2794
|
+
},
|
|
2795
|
+
[]
|
|
2796
|
+
);
|
|
2797
|
+
}
|
|
2798
|
+
|
|
2799
|
+
// src/widget-sources/widget-tileset-source-impl.ts
|
|
2800
|
+
import { booleanEqual } from "@turf/boolean-equal";
|
|
2801
|
+
var WidgetTilesetSourceImpl = class extends WidgetSource {
|
|
2802
|
+
constructor() {
|
|
2803
|
+
super(...arguments);
|
|
2804
|
+
__publicField(this, "_tiles", []);
|
|
2805
|
+
__publicField(this, "_features", []);
|
|
2806
|
+
__publicField(this, "_tileFeatureExtractOptions", {});
|
|
2807
|
+
__publicField(this, "_tileFeatureExtractPreviousInputs", {});
|
|
2808
|
+
}
|
|
2809
|
+
/**
|
|
2810
|
+
* Loads features as a list of tiles (typically provided by deck.gl).
|
|
2811
|
+
* After tiles are loaded, {@link extractTileFeatures} must be called
|
|
2812
|
+
* before computing statistics on the tiles.
|
|
2813
|
+
*/
|
|
2814
|
+
loadTiles(tiles2) {
|
|
2815
|
+
this._tiles = tiles2;
|
|
2816
|
+
this._features.length = 0;
|
|
2817
|
+
}
|
|
2818
|
+
/** Configures options used to extract features from tiles. */
|
|
2819
|
+
setTileFeatureExtractOptions(options) {
|
|
2820
|
+
this._tileFeatureExtractOptions = options;
|
|
2821
|
+
this._features.length = 0;
|
|
2822
|
+
}
|
|
2823
|
+
_extractTileFeatures(spatialFilter) {
|
|
2824
|
+
const prevInputs = this._tileFeatureExtractPreviousInputs;
|
|
2825
|
+
if (this._features.length && prevInputs.spatialFilter && booleanEqual(prevInputs.spatialFilter, spatialFilter)) {
|
|
2826
|
+
return;
|
|
2827
|
+
}
|
|
2828
|
+
this._features = tileFeatures({
|
|
2829
|
+
tiles: this._tiles,
|
|
2830
|
+
tileFormat: this.props.tileFormat,
|
|
2831
|
+
...this._tileFeatureExtractOptions,
|
|
2832
|
+
spatialFilter,
|
|
2833
|
+
spatialDataColumn: this.props.spatialDataColumn,
|
|
2834
|
+
spatialDataType: this.props.spatialDataType
|
|
2835
|
+
});
|
|
2836
|
+
prevInputs.spatialFilter = spatialFilter;
|
|
2837
|
+
}
|
|
2838
|
+
/**
|
|
2839
|
+
* Loads features as GeoJSON (used for testing).
|
|
2840
|
+
* @experimental
|
|
2841
|
+
* @internal Not for public use. Spatial filters in other method calls will be ignored.
|
|
2842
|
+
*/
|
|
2843
|
+
loadGeoJSON({
|
|
2844
|
+
geojson,
|
|
2845
|
+
spatialFilter
|
|
2846
|
+
}) {
|
|
2847
|
+
this._features = geojsonFeatures({
|
|
2848
|
+
geojson,
|
|
2849
|
+
spatialFilter,
|
|
2850
|
+
...this._tileFeatureExtractOptions
|
|
2851
|
+
});
|
|
2852
|
+
this._tileFeatureExtractPreviousInputs.spatialFilter = spatialFilter;
|
|
2853
|
+
}
|
|
2854
|
+
async getFeatures() {
|
|
2855
|
+
throw new Error("getFeatures not supported for tilesets");
|
|
2856
|
+
}
|
|
2857
|
+
async getFormula({
|
|
2858
|
+
column = "*",
|
|
2859
|
+
operation = "count",
|
|
2860
|
+
joinOperation,
|
|
2861
|
+
filters,
|
|
2862
|
+
filterOwner,
|
|
2863
|
+
spatialFilter
|
|
2864
|
+
}) {
|
|
2865
|
+
if (operation === "custom") {
|
|
2866
|
+
throw new Error("Custom aggregation not supported for tilesets");
|
|
2867
|
+
}
|
|
2868
|
+
if (column && column !== "*" || operation !== "count") {
|
|
2869
|
+
assertColumn(this._features, column);
|
|
2870
|
+
}
|
|
2871
|
+
const filteredFeatures = this._getFilteredFeatures(
|
|
2872
|
+
spatialFilter,
|
|
2873
|
+
filters,
|
|
2874
|
+
filterOwner
|
|
2875
|
+
);
|
|
2876
|
+
if (filteredFeatures.length === 0 && operation !== "count") {
|
|
2877
|
+
return { value: null };
|
|
2878
|
+
}
|
|
2879
|
+
const targetOperation = aggregationFunctions[operation];
|
|
2880
|
+
return {
|
|
2881
|
+
value: targetOperation(filteredFeatures, column, joinOperation)
|
|
2882
|
+
};
|
|
2883
|
+
}
|
|
2884
|
+
async getHistogram({
|
|
2885
|
+
operation = "count",
|
|
2886
|
+
ticks,
|
|
2887
|
+
column,
|
|
2888
|
+
joinOperation,
|
|
2889
|
+
filters,
|
|
2890
|
+
filterOwner,
|
|
2891
|
+
spatialFilter
|
|
2892
|
+
}) {
|
|
2893
|
+
const filteredFeatures = this._getFilteredFeatures(
|
|
2894
|
+
spatialFilter,
|
|
2895
|
+
filters,
|
|
2896
|
+
filterOwner
|
|
2897
|
+
);
|
|
2898
|
+
if (!this._features.length) {
|
|
2899
|
+
return [];
|
|
2900
|
+
}
|
|
2901
|
+
assertColumn(this._features, column);
|
|
2902
|
+
return histogram({
|
|
2903
|
+
data: filteredFeatures,
|
|
2904
|
+
valuesColumns: normalizeColumns(column),
|
|
2905
|
+
joinOperation,
|
|
2906
|
+
ticks,
|
|
2907
|
+
operation
|
|
2908
|
+
});
|
|
2909
|
+
}
|
|
2910
|
+
async getCategories({
|
|
2911
|
+
column,
|
|
2912
|
+
operation = "count",
|
|
2913
|
+
operationColumn,
|
|
2914
|
+
joinOperation,
|
|
2915
|
+
filters,
|
|
2916
|
+
filterOwner,
|
|
2917
|
+
spatialFilter
|
|
2918
|
+
}) {
|
|
2919
|
+
const filteredFeatures = this._getFilteredFeatures(
|
|
2920
|
+
spatialFilter,
|
|
2921
|
+
filters,
|
|
2922
|
+
filterOwner
|
|
2923
|
+
);
|
|
2924
|
+
if (!filteredFeatures.length) {
|
|
2925
|
+
return [];
|
|
2926
|
+
}
|
|
2927
|
+
assertColumn(this._features, column, operationColumn);
|
|
2928
|
+
const groups = groupValuesByColumn({
|
|
2929
|
+
data: filteredFeatures,
|
|
2930
|
+
valuesColumns: normalizeColumns(operationColumn || column),
|
|
2931
|
+
joinOperation,
|
|
2932
|
+
keysColumn: column,
|
|
2933
|
+
operation
|
|
2934
|
+
});
|
|
2935
|
+
return groups || [];
|
|
2936
|
+
}
|
|
2937
|
+
async getScatter({
|
|
2938
|
+
xAxisColumn,
|
|
2939
|
+
yAxisColumn,
|
|
2940
|
+
xAxisJoinOperation,
|
|
2941
|
+
yAxisJoinOperation,
|
|
2942
|
+
filters,
|
|
2943
|
+
filterOwner,
|
|
2944
|
+
spatialFilter
|
|
2945
|
+
}) {
|
|
2946
|
+
const filteredFeatures = this._getFilteredFeatures(
|
|
2947
|
+
spatialFilter,
|
|
2948
|
+
filters,
|
|
2949
|
+
filterOwner
|
|
2950
|
+
);
|
|
2951
|
+
if (!filteredFeatures.length) {
|
|
2952
|
+
return [];
|
|
2953
|
+
}
|
|
2954
|
+
assertColumn(this._features, xAxisColumn, yAxisColumn);
|
|
2955
|
+
return scatterPlot({
|
|
2956
|
+
data: filteredFeatures,
|
|
2957
|
+
xAxisColumns: normalizeColumns(xAxisColumn),
|
|
2958
|
+
xAxisJoinOperation,
|
|
2959
|
+
yAxisColumns: normalizeColumns(yAxisColumn),
|
|
2960
|
+
yAxisJoinOperation
|
|
2961
|
+
});
|
|
2962
|
+
}
|
|
2963
|
+
async getTable({
|
|
2964
|
+
columns,
|
|
2965
|
+
searchFilterColumn,
|
|
2966
|
+
searchFilterText,
|
|
2967
|
+
sortBy,
|
|
2968
|
+
sortDirection,
|
|
2969
|
+
sortByColumnType,
|
|
2970
|
+
offset = 0,
|
|
2971
|
+
limit = 10,
|
|
2972
|
+
filters,
|
|
2973
|
+
filterOwner,
|
|
2974
|
+
spatialFilter
|
|
2975
|
+
}) {
|
|
2976
|
+
let filteredFeatures = this._getFilteredFeatures(
|
|
2977
|
+
spatialFilter,
|
|
2978
|
+
filters,
|
|
2979
|
+
filterOwner
|
|
2980
|
+
);
|
|
2981
|
+
if (!filteredFeatures.length) {
|
|
2982
|
+
return { rows: [], totalCount: 0 };
|
|
2983
|
+
}
|
|
2984
|
+
if (searchFilterColumn && searchFilterText) {
|
|
2985
|
+
filteredFeatures = filteredFeatures.filter(
|
|
2986
|
+
(row) => row[searchFilterColumn] && String(row[searchFilterColumn]).toLowerCase().includes(String(searchFilterText).toLowerCase())
|
|
2987
|
+
);
|
|
2988
|
+
}
|
|
2989
|
+
let rows = applySorting(filteredFeatures, {
|
|
2990
|
+
sortBy,
|
|
2991
|
+
sortByDirection: sortDirection,
|
|
2992
|
+
sortByColumnType
|
|
2993
|
+
});
|
|
2994
|
+
const totalCount = rows.length;
|
|
2995
|
+
rows = rows.slice(
|
|
2996
|
+
Math.min(offset, totalCount),
|
|
2997
|
+
Math.min(offset + limit, totalCount)
|
|
2998
|
+
);
|
|
2999
|
+
rows = rows.map((srcRow) => {
|
|
3000
|
+
const dstRow = {};
|
|
3001
|
+
for (const column of columns) {
|
|
3002
|
+
dstRow[column] = srcRow[column];
|
|
3003
|
+
}
|
|
3004
|
+
return dstRow;
|
|
3005
|
+
});
|
|
3006
|
+
return { rows, totalCount };
|
|
3007
|
+
}
|
|
3008
|
+
async getTimeSeries({
|
|
3009
|
+
column,
|
|
3010
|
+
stepSize,
|
|
3011
|
+
operation,
|
|
3012
|
+
operationColumn,
|
|
3013
|
+
joinOperation,
|
|
3014
|
+
filters,
|
|
3015
|
+
filterOwner,
|
|
3016
|
+
spatialFilter
|
|
3017
|
+
}) {
|
|
3018
|
+
const filteredFeatures = this._getFilteredFeatures(
|
|
3019
|
+
spatialFilter,
|
|
3020
|
+
filters,
|
|
3021
|
+
filterOwner
|
|
3022
|
+
);
|
|
3023
|
+
if (!filteredFeatures.length) {
|
|
3024
|
+
return { rows: [] };
|
|
3025
|
+
}
|
|
3026
|
+
assertColumn(this._features, column, operationColumn);
|
|
3027
|
+
const rows = groupValuesByDateColumn({
|
|
3028
|
+
data: filteredFeatures,
|
|
3029
|
+
valuesColumns: normalizeColumns(operationColumn || column),
|
|
3030
|
+
keysColumn: column,
|
|
3031
|
+
groupType: stepSize,
|
|
3032
|
+
operation,
|
|
3033
|
+
joinOperation
|
|
3034
|
+
}) || [];
|
|
3035
|
+
return { rows };
|
|
3036
|
+
}
|
|
3037
|
+
async getRange({
|
|
3038
|
+
column,
|
|
3039
|
+
filters,
|
|
3040
|
+
filterOwner,
|
|
3041
|
+
spatialFilter
|
|
3042
|
+
}) {
|
|
3043
|
+
assertColumn(this._features, column);
|
|
3044
|
+
const filteredFeatures = this._getFilteredFeatures(
|
|
3045
|
+
spatialFilter,
|
|
3046
|
+
filters,
|
|
3047
|
+
filterOwner
|
|
3048
|
+
);
|
|
3049
|
+
if (!this._features.length) {
|
|
3050
|
+
return null;
|
|
3051
|
+
}
|
|
3052
|
+
return {
|
|
3053
|
+
min: aggregationFunctions.min(filteredFeatures, column),
|
|
3054
|
+
max: aggregationFunctions.max(filteredFeatures, column)
|
|
3055
|
+
};
|
|
3056
|
+
}
|
|
3057
|
+
/****************************************************************************
|
|
3058
|
+
* INTERNAL
|
|
3059
|
+
*/
|
|
3060
|
+
_getFilteredFeatures(spatialFilter, filters, filterOwner) {
|
|
3061
|
+
assert2(spatialFilter, "spatialFilter required for tilesets");
|
|
3062
|
+
this._extractTileFeatures(spatialFilter);
|
|
3063
|
+
return applyFilters(
|
|
3064
|
+
this._features,
|
|
3065
|
+
getApplicableFilters(filterOwner, filters || this.props.filters),
|
|
3066
|
+
this.props.filtersLogicalOperator || "and"
|
|
3067
|
+
);
|
|
3068
|
+
}
|
|
3069
|
+
};
|
|
3070
|
+
function assertColumn(features, ...columnArgs) {
|
|
3071
|
+
const columns = Array.from(new Set(columnArgs.map(normalizeColumns).flat()));
|
|
3072
|
+
const featureKeys = Object.keys(features[0]);
|
|
3073
|
+
const invalidColumns = columns.filter(
|
|
3074
|
+
(column) => !featureKeys.includes(column)
|
|
3075
|
+
);
|
|
3076
|
+
if (invalidColumns.length) {
|
|
3077
|
+
throw new InvalidColumnError(
|
|
3078
|
+
`Missing column(s): ${invalidColumns.join(", ")}`
|
|
3079
|
+
);
|
|
3080
|
+
}
|
|
3081
|
+
}
|
|
3082
|
+
function normalizeColumns(columns) {
|
|
3083
|
+
return Array.isArray(columns) ? columns : typeof columns === "string" ? [columns] : [];
|
|
3084
|
+
}
|
|
3085
|
+
|
|
3086
|
+
// src/widget-sources/widget-tileset-source.ts
|
|
3087
|
+
var WidgetTilesetSource = class extends WidgetSource {
|
|
3088
|
+
constructor(props) {
|
|
3089
|
+
super(props);
|
|
3090
|
+
__publicField(this, "_localImpl", null);
|
|
3091
|
+
__publicField(this, "_workerImpl", null);
|
|
3092
|
+
__publicField(this, "_workerEnabled");
|
|
3093
|
+
__publicField(this, "_workerNextRequestId", 1);
|
|
3094
|
+
this._workerEnabled = (props.widgetWorker ?? true) && true && typeof Worker !== "undefined";
|
|
3095
|
+
if (!this._workerEnabled) {
|
|
3096
|
+
this._localImpl = new WidgetTilesetSourceImpl(this.props);
|
|
3097
|
+
}
|
|
3098
|
+
}
|
|
3099
|
+
destroy() {
|
|
3100
|
+
this._localImpl?.destroy();
|
|
3101
|
+
this._localImpl = null;
|
|
3102
|
+
this._workerImpl?.terminate();
|
|
3103
|
+
this._workerImpl = null;
|
|
3104
|
+
super.destroy();
|
|
3105
|
+
}
|
|
3106
|
+
/////////////////////////////////////////////////////////////////////////////
|
|
3107
|
+
// WEB WORKER MANAGEMENT
|
|
3108
|
+
/**
|
|
3109
|
+
* Returns an initialized Worker, to be reused for the lifecycle of this
|
|
3110
|
+
* source instance.
|
|
3111
|
+
*/
|
|
3112
|
+
_getWorker() {
|
|
3113
|
+
if (this._workerImpl) {
|
|
3114
|
+
return this._workerImpl;
|
|
3115
|
+
}
|
|
3116
|
+
this._workerImpl = new Worker(
|
|
3117
|
+
new URL("@carto/api-client/worker", import.meta.url),
|
|
3118
|
+
{
|
|
3119
|
+
type: "module",
|
|
3120
|
+
name: "cartowidgettileset"
|
|
3121
|
+
}
|
|
3122
|
+
);
|
|
3123
|
+
this._workerImpl.postMessage({
|
|
3124
|
+
method: "init" /* INIT */,
|
|
3125
|
+
params: [this.props]
|
|
3126
|
+
});
|
|
3127
|
+
return this._workerImpl;
|
|
3128
|
+
}
|
|
3129
|
+
/** Executes a given method on the worker. */
|
|
3130
|
+
_executeWorkerMethod(method, params, signal) {
|
|
3131
|
+
if (!this._workerEnabled) {
|
|
3132
|
+
return this._localImpl[method](...params);
|
|
3133
|
+
}
|
|
3134
|
+
const worker = this._getWorker();
|
|
3135
|
+
const requestId = this._workerNextRequestId++;
|
|
3136
|
+
const options = params[0];
|
|
3137
|
+
if (options?.spatialIndexReferenceViewState) {
|
|
3138
|
+
const { zoom, latitude, longitude } = options.spatialIndexReferenceViewState;
|
|
3139
|
+
options.spatialIndexReferenceViewState = { zoom, latitude, longitude };
|
|
3140
|
+
}
|
|
3141
|
+
let resolve = null;
|
|
3142
|
+
let reject = null;
|
|
3143
|
+
function onMessage(e) {
|
|
3144
|
+
const response = e.data;
|
|
3145
|
+
if (response.requestId !== requestId) return;
|
|
3146
|
+
if (signal?.aborted) {
|
|
3147
|
+
reject(new Error(signal.reason));
|
|
3148
|
+
} else if (response.ok) {
|
|
3149
|
+
resolve(response.result);
|
|
3150
|
+
} else {
|
|
3151
|
+
reject(new Error(response.error));
|
|
3152
|
+
}
|
|
3153
|
+
}
|
|
3154
|
+
function onAbort() {
|
|
3155
|
+
reject(new Error(signal.reason));
|
|
3156
|
+
}
|
|
3157
|
+
worker.addEventListener("message", onMessage);
|
|
3158
|
+
signal?.addEventListener("abort", onAbort);
|
|
3159
|
+
const promise = new Promise((_resolve, _reject) => {
|
|
3160
|
+
resolve = _resolve;
|
|
3161
|
+
reject = _reject;
|
|
3162
|
+
worker.postMessage({
|
|
3163
|
+
requestId,
|
|
3164
|
+
method,
|
|
3165
|
+
params
|
|
3166
|
+
});
|
|
3167
|
+
});
|
|
3168
|
+
void promise.finally(() => {
|
|
3169
|
+
worker.removeEventListener("message", onMessage);
|
|
3170
|
+
signal?.removeEventListener("abort", onAbort);
|
|
3171
|
+
});
|
|
3172
|
+
return promise;
|
|
3173
|
+
}
|
|
3174
|
+
/////////////////////////////////////////////////////////////////////////////
|
|
3175
|
+
// DATA LOADING
|
|
3176
|
+
/**
|
|
3177
|
+
* Loads features as a list of tiles (typically provided by deck.gl).
|
|
3178
|
+
* After tiles are loaded, {@link extractTileFeatures} must be called
|
|
3179
|
+
* before computing statistics on the tiles.
|
|
3180
|
+
*/
|
|
3181
|
+
loadTiles(tiles2) {
|
|
3182
|
+
if (!this._workerEnabled) {
|
|
3183
|
+
return this._localImpl.loadTiles(tiles2);
|
|
3184
|
+
}
|
|
3185
|
+
const worker = this._getWorker();
|
|
3186
|
+
tiles2 = tiles2.map(({ id, bbox, data }) => ({
|
|
3187
|
+
id,
|
|
3188
|
+
bbox,
|
|
3189
|
+
data
|
|
3190
|
+
}));
|
|
3191
|
+
worker.postMessage({
|
|
3192
|
+
method: "loadTiles" /* LOAD_TILES */,
|
|
3193
|
+
params: [tiles2]
|
|
3194
|
+
});
|
|
3195
|
+
}
|
|
3196
|
+
/** Configures options used to extract features from tiles. */
|
|
3197
|
+
setTileFeatureExtractOptions(options) {
|
|
3198
|
+
if (!this._workerEnabled) {
|
|
3199
|
+
return this._localImpl?.setTileFeatureExtractOptions(options);
|
|
3200
|
+
}
|
|
3201
|
+
const worker = this._getWorker();
|
|
3202
|
+
worker.postMessage({
|
|
3203
|
+
type: "setTileFeatureExtractOptions" /* SET_TILE_FEATURE_EXTRACT_OPTIONS */,
|
|
3204
|
+
params: [options]
|
|
3205
|
+
});
|
|
3206
|
+
}
|
|
3207
|
+
/**
|
|
3208
|
+
* Loads features as GeoJSON (used for testing).
|
|
3209
|
+
* @experimental
|
|
3210
|
+
* @internal Not for public use. Spatial filters in other method calls will be ignored.
|
|
3211
|
+
*/
|
|
3212
|
+
loadGeoJSON({
|
|
3213
|
+
geojson,
|
|
3214
|
+
spatialFilter
|
|
3215
|
+
}) {
|
|
3216
|
+
if (!this._workerEnabled) {
|
|
3217
|
+
return this._localImpl.loadGeoJSON({ geojson, spatialFilter });
|
|
3218
|
+
}
|
|
3219
|
+
const worker = this._getWorker();
|
|
3220
|
+
worker.postMessage({
|
|
3221
|
+
method: "loadGeoJSON" /* LOAD_GEOJSON */,
|
|
3222
|
+
params: [{ geojson, spatialFilter }]
|
|
3223
|
+
});
|
|
3224
|
+
}
|
|
3225
|
+
/////////////////////////////////////////////////////////////////////////////
|
|
3226
|
+
// WIDGETS API
|
|
3227
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
3228
|
+
async getFeatures() {
|
|
3229
|
+
throw new Error("getFeatures not supported for tilesets");
|
|
3230
|
+
}
|
|
3231
|
+
async getFormula({
|
|
3232
|
+
signal,
|
|
3233
|
+
...options
|
|
3234
|
+
}) {
|
|
3235
|
+
return this._executeWorkerMethod("getFormula" /* GET_FORMULA */, [options], signal);
|
|
3236
|
+
}
|
|
3237
|
+
async getHistogram({
|
|
3238
|
+
signal,
|
|
3239
|
+
...options
|
|
3240
|
+
}) {
|
|
3241
|
+
return this._executeWorkerMethod("getHistogram" /* GET_HISTOGRAM */, [options], signal);
|
|
3242
|
+
}
|
|
3243
|
+
async getCategories({
|
|
3244
|
+
signal,
|
|
3245
|
+
...options
|
|
3246
|
+
}) {
|
|
3247
|
+
return this._executeWorkerMethod("getCategories" /* GET_CATEGORIES */, [options], signal);
|
|
3248
|
+
}
|
|
3249
|
+
async getScatter({
|
|
3250
|
+
signal,
|
|
3251
|
+
...options
|
|
3252
|
+
}) {
|
|
3253
|
+
return this._executeWorkerMethod("getScatter" /* GET_SCATTER */, [options], signal);
|
|
3254
|
+
}
|
|
3255
|
+
async getTable({
|
|
3256
|
+
signal,
|
|
3257
|
+
...options
|
|
3258
|
+
}) {
|
|
3259
|
+
return this._executeWorkerMethod("getTable" /* GET_TABLE */, [options], signal);
|
|
3260
|
+
}
|
|
3261
|
+
async getTimeSeries({
|
|
3262
|
+
signal,
|
|
3263
|
+
...options
|
|
3264
|
+
}) {
|
|
3265
|
+
return this._executeWorkerMethod("getTimeSeries" /* GET_TIME_SERIES */, [options], signal);
|
|
3266
|
+
}
|
|
3267
|
+
async getRange({
|
|
3268
|
+
signal,
|
|
3269
|
+
...options
|
|
3270
|
+
}) {
|
|
3271
|
+
return this._executeWorkerMethod("getRange" /* GET_RANGE */, [options], signal);
|
|
3272
|
+
}
|
|
3273
|
+
};
|
|
3274
|
+
|
|
3275
|
+
// src/sources/h3-query-source.ts
|
|
3276
|
+
var h3QuerySource = async function(options) {
|
|
3277
|
+
const {
|
|
3278
|
+
aggregationExp,
|
|
3279
|
+
aggregationResLevel = DEFAULT_AGGREGATION_RES_LEVEL_H3,
|
|
3280
|
+
sqlQuery,
|
|
3281
|
+
spatialDataColumn = "h3",
|
|
3282
|
+
queryParameters,
|
|
3283
|
+
filters
|
|
3284
|
+
} = options;
|
|
3285
|
+
const spatialDataType = "h3";
|
|
3286
|
+
const urlParameters = {
|
|
3287
|
+
aggregationExp,
|
|
3288
|
+
spatialDataColumn,
|
|
3289
|
+
spatialDataType,
|
|
3290
|
+
q: sqlQuery
|
|
3291
|
+
};
|
|
3292
|
+
if (aggregationResLevel) {
|
|
3293
|
+
urlParameters.aggregationResLevel = String(aggregationResLevel);
|
|
3294
|
+
}
|
|
3295
|
+
if (queryParameters) {
|
|
3296
|
+
urlParameters.queryParameters = queryParameters;
|
|
3297
|
+
}
|
|
3298
|
+
if (filters) {
|
|
3299
|
+
urlParameters.filters = filters;
|
|
3300
|
+
}
|
|
3301
|
+
return baseSource("query", options, urlParameters).then(
|
|
3302
|
+
(result) => ({
|
|
3303
|
+
...result,
|
|
3304
|
+
widgetSource: new WidgetQuerySource({
|
|
3305
|
+
...options,
|
|
3306
|
+
// NOTE: Parameters with default values above must be explicitly passed here.
|
|
3307
|
+
spatialDataColumn,
|
|
3308
|
+
spatialDataType
|
|
3309
|
+
})
|
|
3310
|
+
})
|
|
3311
|
+
);
|
|
3312
|
+
};
|
|
3313
|
+
|
|
3314
|
+
// src/sources/h3-table-source.ts
|
|
3315
|
+
var h3TableSource = async function(options) {
|
|
3316
|
+
const {
|
|
3317
|
+
aggregationExp,
|
|
3318
|
+
aggregationResLevel = DEFAULT_AGGREGATION_RES_LEVEL_H3,
|
|
3319
|
+
spatialDataColumn = "h3",
|
|
3320
|
+
tableName,
|
|
3321
|
+
filters
|
|
3322
|
+
} = options;
|
|
3323
|
+
const spatialDataType = "h3";
|
|
3324
|
+
const urlParameters = {
|
|
3325
|
+
aggregationExp,
|
|
3326
|
+
name: tableName,
|
|
3327
|
+
spatialDataColumn,
|
|
3328
|
+
spatialDataType
|
|
3329
|
+
};
|
|
3330
|
+
if (aggregationResLevel) {
|
|
3331
|
+
urlParameters.aggregationResLevel = String(aggregationResLevel);
|
|
3332
|
+
}
|
|
3333
|
+
if (filters) {
|
|
3334
|
+
urlParameters.filters = filters;
|
|
3335
|
+
}
|
|
3336
|
+
return baseSource("table", options, urlParameters).then(
|
|
3337
|
+
(result) => ({
|
|
3338
|
+
...result,
|
|
3339
|
+
widgetSource: new WidgetTableSource({
|
|
3340
|
+
...options,
|
|
3341
|
+
// NOTE: Parameters with default values above must be explicitly passed here.
|
|
3342
|
+
spatialDataColumn,
|
|
3343
|
+
spatialDataType
|
|
3344
|
+
})
|
|
3345
|
+
})
|
|
3346
|
+
);
|
|
3347
|
+
};
|
|
3348
|
+
|
|
3349
|
+
// src/utils/getTileFormat.ts
|
|
3350
|
+
function getTileFormat(tilejson) {
|
|
3351
|
+
const tileParams = new URL(tilejson.tiles[0]).searchParams;
|
|
3352
|
+
return tileParams.get("formatTiles") === "mvt" ? "mvt" /* MVT */ : "binary" /* BINARY */;
|
|
3353
|
+
}
|
|
3354
|
+
|
|
3355
|
+
// src/sources/h3-tileset-source.ts
|
|
3356
|
+
var h3TilesetSource = async function(options) {
|
|
3357
|
+
const { tableName, spatialDataColumn = "h3" } = options;
|
|
3358
|
+
const urlParameters = { name: tableName };
|
|
3359
|
+
return baseSource("tileset", options, urlParameters).then(
|
|
3360
|
+
(result) => ({
|
|
3361
|
+
...result,
|
|
3362
|
+
widgetSource: new WidgetTilesetSource({
|
|
3363
|
+
...options,
|
|
3364
|
+
tileFormat: getTileFormat(result),
|
|
3365
|
+
spatialDataColumn,
|
|
3366
|
+
spatialDataType: "h3"
|
|
3367
|
+
})
|
|
3368
|
+
})
|
|
3369
|
+
);
|
|
3370
|
+
};
|
|
3371
|
+
|
|
3372
|
+
// src/sources/raster-source.ts
|
|
3373
|
+
var rasterSource = async function(options) {
|
|
3374
|
+
const { tableName, filters } = options;
|
|
3375
|
+
const urlParameters = { name: tableName };
|
|
3376
|
+
if (filters) {
|
|
3377
|
+
urlParameters.filters = filters;
|
|
3378
|
+
}
|
|
3379
|
+
return baseSource(
|
|
3380
|
+
"raster",
|
|
3381
|
+
options,
|
|
3382
|
+
urlParameters
|
|
3383
|
+
);
|
|
3384
|
+
};
|
|
3385
|
+
|
|
3386
|
+
// src/sources/quadbin-query-source.ts
|
|
3387
|
+
var quadbinQuerySource = async function(options) {
|
|
3388
|
+
const {
|
|
3389
|
+
aggregationExp,
|
|
3390
|
+
aggregationResLevel = DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN,
|
|
3391
|
+
sqlQuery,
|
|
3392
|
+
spatialDataColumn = "quadbin",
|
|
3393
|
+
queryParameters,
|
|
3394
|
+
filters
|
|
3395
|
+
} = options;
|
|
3396
|
+
const spatialDataType = "quadbin";
|
|
3397
|
+
const urlParameters = {
|
|
3398
|
+
aggregationExp,
|
|
3399
|
+
q: sqlQuery,
|
|
3400
|
+
spatialDataColumn,
|
|
3401
|
+
spatialDataType
|
|
3402
|
+
};
|
|
3403
|
+
if (aggregationResLevel) {
|
|
3404
|
+
urlParameters.aggregationResLevel = String(aggregationResLevel);
|
|
3405
|
+
}
|
|
3406
|
+
if (queryParameters) {
|
|
3407
|
+
urlParameters.queryParameters = queryParameters;
|
|
3408
|
+
}
|
|
3409
|
+
if (filters) {
|
|
3410
|
+
urlParameters.filters = filters;
|
|
3411
|
+
}
|
|
3412
|
+
return baseSource("query", options, urlParameters).then(
|
|
3413
|
+
(result) => ({
|
|
3414
|
+
...result,
|
|
3415
|
+
widgetSource: new WidgetQuerySource({
|
|
3416
|
+
...options,
|
|
3417
|
+
// NOTE: Parameters with default values above must be explicitly passed here.
|
|
3418
|
+
spatialDataColumn,
|
|
3419
|
+
spatialDataType
|
|
3420
|
+
})
|
|
3421
|
+
})
|
|
3422
|
+
);
|
|
3423
|
+
};
|
|
3424
|
+
|
|
3425
|
+
// src/sources/quadbin-table-source.ts
|
|
3426
|
+
var quadbinTableSource = async function(options) {
|
|
3427
|
+
const {
|
|
3428
|
+
aggregationExp,
|
|
3429
|
+
aggregationResLevel = DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN,
|
|
3430
|
+
spatialDataColumn = "quadbin",
|
|
3431
|
+
tableName,
|
|
3432
|
+
filters
|
|
3433
|
+
} = options;
|
|
3434
|
+
const spatialDataType = "quadbin";
|
|
3435
|
+
const urlParameters = {
|
|
3436
|
+
aggregationExp,
|
|
3437
|
+
name: tableName,
|
|
3438
|
+
spatialDataColumn,
|
|
3439
|
+
spatialDataType
|
|
3440
|
+
};
|
|
3441
|
+
if (aggregationResLevel) {
|
|
3442
|
+
urlParameters.aggregationResLevel = String(aggregationResLevel);
|
|
3443
|
+
}
|
|
3444
|
+
if (filters) {
|
|
3445
|
+
urlParameters.filters = filters;
|
|
3446
|
+
}
|
|
3447
|
+
return baseSource("table", options, urlParameters).then(
|
|
3448
|
+
(result) => ({
|
|
3449
|
+
...result,
|
|
3450
|
+
widgetSource: new WidgetTableSource({
|
|
3451
|
+
...options,
|
|
3452
|
+
// NOTE: Parameters with default values above must be explicitly passed here.
|
|
3453
|
+
spatialDataColumn,
|
|
3454
|
+
spatialDataType
|
|
3455
|
+
})
|
|
3456
|
+
})
|
|
3457
|
+
);
|
|
3458
|
+
};
|
|
3459
|
+
|
|
3460
|
+
// src/sources/quadbin-tileset-source.ts
|
|
3461
|
+
var quadbinTilesetSource = async function(options) {
|
|
3462
|
+
const { tableName, spatialDataColumn = "quadbin" } = options;
|
|
3463
|
+
const urlParameters = { name: tableName };
|
|
3464
|
+
return baseSource("tileset", options, urlParameters).then(
|
|
3465
|
+
(result) => ({
|
|
3466
|
+
...result,
|
|
3467
|
+
widgetSource: new WidgetTilesetSource({
|
|
3468
|
+
...options,
|
|
3469
|
+
tileFormat: getTileFormat(result),
|
|
3470
|
+
spatialDataColumn,
|
|
3471
|
+
spatialDataType: "quadbin"
|
|
3472
|
+
})
|
|
3473
|
+
})
|
|
3474
|
+
);
|
|
3475
|
+
};
|
|
3476
|
+
|
|
3477
|
+
// src/sources/vector-query-source.ts
|
|
3478
|
+
var vectorQuerySource = async function(options) {
|
|
3479
|
+
const {
|
|
3480
|
+
columns,
|
|
3481
|
+
filters,
|
|
3482
|
+
spatialDataColumn = DEFAULT_GEO_COLUMN,
|
|
3483
|
+
sqlQuery,
|
|
3484
|
+
tileResolution = DEFAULT_TILE_RESOLUTION,
|
|
3485
|
+
queryParameters,
|
|
3486
|
+
aggregationExp
|
|
3487
|
+
} = options;
|
|
3488
|
+
const spatialDataType = "geo";
|
|
3489
|
+
const urlParameters = {
|
|
3490
|
+
spatialDataColumn,
|
|
3491
|
+
spatialDataType,
|
|
3492
|
+
tileResolution: tileResolution.toString(),
|
|
3493
|
+
q: sqlQuery
|
|
3494
|
+
};
|
|
3495
|
+
if (columns) {
|
|
3496
|
+
urlParameters.columns = columns.join(",");
|
|
3497
|
+
}
|
|
3498
|
+
if (filters) {
|
|
3499
|
+
urlParameters.filters = filters;
|
|
3500
|
+
}
|
|
3501
|
+
if (queryParameters) {
|
|
3502
|
+
urlParameters.queryParameters = queryParameters;
|
|
3503
|
+
}
|
|
3504
|
+
if (aggregationExp) {
|
|
3505
|
+
urlParameters.aggregationExp = aggregationExp;
|
|
3506
|
+
}
|
|
3507
|
+
return baseSource("query", options, urlParameters).then(
|
|
3508
|
+
(result) => ({
|
|
3509
|
+
...result,
|
|
3510
|
+
widgetSource: new WidgetQuerySource({
|
|
3511
|
+
...options,
|
|
3512
|
+
// NOTE: Parameters with default values above must be explicitly passed here.
|
|
3513
|
+
spatialDataColumn,
|
|
3514
|
+
spatialDataType,
|
|
3515
|
+
tileResolution
|
|
3516
|
+
})
|
|
3517
|
+
})
|
|
3518
|
+
);
|
|
3519
|
+
};
|
|
3520
|
+
|
|
3521
|
+
// src/sources/vector-table-source.ts
|
|
3522
|
+
var vectorTableSource = async function(options) {
|
|
3523
|
+
const {
|
|
3524
|
+
columns,
|
|
3525
|
+
filters,
|
|
3526
|
+
spatialDataColumn = DEFAULT_GEO_COLUMN,
|
|
3527
|
+
tableName,
|
|
3528
|
+
tileResolution = DEFAULT_TILE_RESOLUTION,
|
|
3529
|
+
aggregationExp
|
|
3530
|
+
} = options;
|
|
3531
|
+
const spatialDataType = "geo";
|
|
3532
|
+
const urlParameters = {
|
|
3533
|
+
name: tableName,
|
|
3534
|
+
spatialDataColumn,
|
|
3535
|
+
spatialDataType,
|
|
3536
|
+
tileResolution: tileResolution.toString()
|
|
3537
|
+
};
|
|
3538
|
+
if (columns) {
|
|
3539
|
+
urlParameters.columns = columns.join(",");
|
|
3540
|
+
}
|
|
3541
|
+
if (filters) {
|
|
3542
|
+
urlParameters.filters = filters;
|
|
3543
|
+
}
|
|
3544
|
+
if (aggregationExp) {
|
|
3545
|
+
urlParameters.aggregationExp = aggregationExp;
|
|
3546
|
+
}
|
|
3547
|
+
return baseSource("table", options, urlParameters).then(
|
|
3548
|
+
(result) => ({
|
|
3549
|
+
...result,
|
|
3550
|
+
widgetSource: new WidgetTableSource({
|
|
3551
|
+
...options,
|
|
3552
|
+
// NOTE: Parameters with default values above must be explicitly passed here.
|
|
3553
|
+
spatialDataColumn,
|
|
3554
|
+
spatialDataType,
|
|
3555
|
+
tileResolution
|
|
3556
|
+
})
|
|
3557
|
+
})
|
|
3558
|
+
);
|
|
3559
|
+
};
|
|
3560
|
+
|
|
3561
|
+
// src/sources/vector-tileset-source.ts
|
|
3562
|
+
var vectorTilesetSource = async function(options) {
|
|
3563
|
+
const { tableName, spatialDataColumn = DEFAULT_GEO_COLUMN } = options;
|
|
3564
|
+
const urlParameters = { name: tableName };
|
|
3565
|
+
return baseSource("tileset", options, urlParameters).then(
|
|
3566
|
+
(result) => ({
|
|
3567
|
+
...result,
|
|
3568
|
+
widgetSource: new WidgetTilesetSource({
|
|
3569
|
+
...options,
|
|
3570
|
+
tileFormat: getTileFormat(result),
|
|
3571
|
+
spatialDataColumn,
|
|
3572
|
+
spatialDataType: "geo"
|
|
3573
|
+
})
|
|
3574
|
+
})
|
|
3575
|
+
);
|
|
3576
|
+
};
|
|
3577
|
+
|
|
3578
|
+
// src/api/query.ts
|
|
3579
|
+
var query = async function(options) {
|
|
3580
|
+
const {
|
|
3581
|
+
apiBaseUrl = SOURCE_DEFAULTS.apiBaseUrl,
|
|
3582
|
+
clientId = SOURCE_DEFAULTS.clientId,
|
|
3583
|
+
maxLengthURL = SOURCE_DEFAULTS.maxLengthURL,
|
|
3584
|
+
localCache,
|
|
3585
|
+
connectionName,
|
|
3586
|
+
sqlQuery,
|
|
3587
|
+
queryParameters
|
|
3588
|
+
} = options;
|
|
3589
|
+
const urlParameters = { q: sqlQuery };
|
|
3590
|
+
if (queryParameters) {
|
|
3591
|
+
urlParameters.queryParameters = JSON.stringify(queryParameters);
|
|
3592
|
+
}
|
|
3593
|
+
const baseUrl = buildQueryUrl({ apiBaseUrl, connectionName });
|
|
3594
|
+
const headers = {
|
|
3595
|
+
Authorization: `Bearer ${options.accessToken}`,
|
|
3596
|
+
...options.headers
|
|
3597
|
+
};
|
|
3598
|
+
const parameters = { client: clientId, ...urlParameters };
|
|
3599
|
+
const errorContext = {
|
|
3600
|
+
requestType: "SQL",
|
|
3601
|
+
connection: options.connectionName,
|
|
3602
|
+
type: "query",
|
|
3603
|
+
source: JSON.stringify(parameters, void 0, 2)
|
|
3604
|
+
};
|
|
3605
|
+
return await requestWithParameters({
|
|
3606
|
+
baseUrl,
|
|
3607
|
+
parameters,
|
|
3608
|
+
headers,
|
|
3609
|
+
errorContext,
|
|
3610
|
+
maxLengthURL,
|
|
3611
|
+
localCache
|
|
3612
|
+
});
|
|
3613
|
+
};
|
|
3614
|
+
export {
|
|
3615
|
+
ApiVersion,
|
|
3616
|
+
CartoAPIError,
|
|
3617
|
+
DEFAULT_API_BASE_URL,
|
|
3618
|
+
FEATURE_GEOM_PROPERTY,
|
|
3619
|
+
FilterType,
|
|
3620
|
+
Provider,
|
|
3621
|
+
SOURCE_DEFAULTS,
|
|
3622
|
+
SpatialIndex,
|
|
3623
|
+
TileFormat,
|
|
3624
|
+
WidgetQuerySource,
|
|
3625
|
+
WidgetRemoteSource,
|
|
3626
|
+
WidgetSource,
|
|
3627
|
+
WidgetTableSource,
|
|
3628
|
+
WidgetTilesetSource,
|
|
3629
|
+
_buildFeatureFilter,
|
|
3630
|
+
_getHexagonResolution,
|
|
3631
|
+
addFilter,
|
|
3632
|
+
aggregate,
|
|
3633
|
+
aggregationFunctions,
|
|
3634
|
+
applyFilters,
|
|
3635
|
+
applySorting,
|
|
3636
|
+
boundaryQuerySource,
|
|
3637
|
+
boundaryTableSource,
|
|
3638
|
+
buildBinaryFeatureFilter,
|
|
3639
|
+
buildPublicMapUrl,
|
|
3640
|
+
buildStatsUrl,
|
|
3641
|
+
clearFilters,
|
|
3642
|
+
createPolygonSpatialFilter,
|
|
3643
|
+
createViewportSpatialFilter,
|
|
3644
|
+
filterFunctions,
|
|
3645
|
+
geojsonFeatures,
|
|
3646
|
+
getClient,
|
|
3647
|
+
getDataFilterExtensionProps,
|
|
3648
|
+
getFilter,
|
|
3649
|
+
groupValuesByColumn,
|
|
3650
|
+
groupValuesByDateColumn,
|
|
3651
|
+
h3QuerySource,
|
|
3652
|
+
h3TableSource,
|
|
3653
|
+
h3TilesetSource,
|
|
3654
|
+
hasFilter,
|
|
3655
|
+
histogram,
|
|
3656
|
+
makeIntervalComplete,
|
|
3657
|
+
quadbinQuerySource,
|
|
3658
|
+
quadbinTableSource,
|
|
3659
|
+
quadbinTilesetSource,
|
|
3660
|
+
query,
|
|
3661
|
+
rasterSource,
|
|
3662
|
+
removeFilter,
|
|
3663
|
+
requestWithParameters,
|
|
3664
|
+
scatterPlot,
|
|
3665
|
+
setClient,
|
|
3666
|
+
tileFeatures,
|
|
3667
|
+
tileFeaturesGeometries,
|
|
3668
|
+
tileFeaturesSpatialIndex,
|
|
3669
|
+
transformToTileCoords,
|
|
3670
|
+
vectorQuerySource,
|
|
3671
|
+
vectorTableSource,
|
|
3672
|
+
vectorTilesetSource
|
|
3673
|
+
};
|
|
3674
|
+
//# sourceMappingURL=api-client.js.map
|