@carto/api-client 0.4.8-alpha.0 → 0.4.9-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/build/api-client.cjs +31 -100
- package/build/api-client.cjs.map +1 -1
- package/build/api-client.modern.js +46 -114
- package/build/api-client.modern.js.map +1 -1
- package/build/models/model.d.ts +0 -1
- package/build/spatial-index.d.ts +1 -4
- package/build/widget-sources/types.d.ts +0 -2
- package/build/widget-sources/widget-source.d.ts +2 -3
- package/package.json +7 -2
- package/src/models/model.ts +0 -5
- package/src/spatial-index.ts +3 -84
- package/src/widget-sources/types.ts +0 -2
- package/src/widget-sources/widget-remote-source.ts +8 -74
- package/src/widget-sources/widget-source.ts +1 -27
package/CHANGELOG.md
CHANGED
|
@@ -11,6 +11,14 @@
|
|
|
11
11
|
|
|
12
12
|
## 0.4
|
|
13
13
|
|
|
14
|
+
### 0.4.9 (Unreleased)
|
|
15
|
+
|
|
16
|
+
- feat: Remove spatialIndexReferenceViewState param (#128)
|
|
17
|
+
|
|
18
|
+
### 0.4.8
|
|
19
|
+
|
|
20
|
+
- fix: Fix clientId defaults in query and source calls (#122)
|
|
21
|
+
|
|
14
22
|
### 0.4.7
|
|
15
23
|
|
|
16
24
|
- fix: Fix clientId customization in table and query widget calls (#120)
|
package/build/api-client.cjs
CHANGED
|
@@ -2104,51 +2104,6 @@ const boundaryTableSource = function (options) {
|
|
|
2104
2104
|
}
|
|
2105
2105
|
};
|
|
2106
2106
|
|
|
2107
|
-
const DEFAULT_TILE_SIZE = 512;
|
|
2108
|
-
const QUADBIN_ZOOM_MAX_OFFSET = 4;
|
|
2109
|
-
function getSpatialFiltersResolution(source, viewState) {
|
|
2110
|
-
const dataResolution = source.dataResolution ?? Number.MAX_VALUE;
|
|
2111
|
-
const aggregationResLevel = source.aggregationResLevel ?? (source.spatialDataType === 'h3' ? DEFAULT_AGGREGATION_RES_LEVEL_H3 : DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN);
|
|
2112
|
-
const aggregationResLevelOffset = Math.max(0, Math.floor(aggregationResLevel));
|
|
2113
|
-
const currentZoomInt = Math.ceil(viewState.zoom);
|
|
2114
|
-
if (source.spatialDataType === 'h3') {
|
|
2115
|
-
const tileSize = DEFAULT_TILE_SIZE;
|
|
2116
|
-
const maxResolutionForZoom = maxH3SpatialFiltersResolutions.find(_ref => {
|
|
2117
|
-
let [zoom] = _ref;
|
|
2118
|
-
return zoom === currentZoomInt;
|
|
2119
|
-
})?.[1] ?? Math.max(0, currentZoomInt - 3);
|
|
2120
|
-
const maxSpatialFiltersResolution = maxResolutionForZoom ? Math.min(dataResolution, maxResolutionForZoom) : dataResolution;
|
|
2121
|
-
const hexagonResolution = _getHexagonResolution(viewState, tileSize) + aggregationResLevelOffset;
|
|
2122
|
-
return Math.min(hexagonResolution, maxSpatialFiltersResolution);
|
|
2123
|
-
}
|
|
2124
|
-
if (source.spatialDataType === 'quadbin') {
|
|
2125
|
-
const maxResolutionForZoom = currentZoomInt + QUADBIN_ZOOM_MAX_OFFSET;
|
|
2126
|
-
const maxSpatialFiltersResolution = Math.min(dataResolution, maxResolutionForZoom);
|
|
2127
|
-
const quadsResolution = Math.floor(viewState.zoom) + aggregationResLevelOffset;
|
|
2128
|
-
return Math.min(quadsResolution, maxSpatialFiltersResolution);
|
|
2129
|
-
}
|
|
2130
|
-
return undefined;
|
|
2131
|
-
}
|
|
2132
|
-
const maxH3SpatialFiltersResolutions = [[20, 14], [19, 13], [18, 12], [17, 11], [16, 10], [15, 9], [14, 8], [13, 7], [12, 7], [11, 7], [10, 6], [9, 6], [8, 5], [7, 4], [6, 4], [5, 3], [4, 2], [3, 1], [2, 1], [1, 0]];
|
|
2133
|
-
// stolen from https://github.com/visgl/deck.gl/blob/master/modules/carto/src/layers/h3-tileset-2d.ts
|
|
2134
|
-
// Relative scale factor (0 = no biasing, 2 = a few hexagons cover view)
|
|
2135
|
-
const BIAS = 2;
|
|
2136
|
-
/**
|
|
2137
|
-
* Resolution conversion function. Takes a WebMercatorViewport and returns
|
|
2138
|
-
* a H3 resolution such that the screen space size of the hexagons is
|
|
2139
|
-
* "similar" to the given tileSize on screen. Intended for use with deck.gl.
|
|
2140
|
-
* @internal
|
|
2141
|
-
*/
|
|
2142
|
-
function _getHexagonResolution(viewport, tileSize) {
|
|
2143
|
-
// Difference in given tile size compared to deck's internal 512px tile size,
|
|
2144
|
-
// expressed as an offset to the viewport zoom.
|
|
2145
|
-
const zoomOffset = Math.log2(tileSize / DEFAULT_TILE_SIZE);
|
|
2146
|
-
const hexagonScaleFactor = 2 / 3 * (viewport.zoom - zoomOffset);
|
|
2147
|
-
const latitudeScaleFactor = Math.log(1 / Math.cos(Math.PI * viewport.latitude / 180));
|
|
2148
|
-
// Clip and bias
|
|
2149
|
-
return Math.max(0, Math.floor(hexagonScaleFactor + latitudeScaleFactor - BIAS));
|
|
2150
|
-
}
|
|
2151
|
-
|
|
2152
2107
|
/**
|
|
2153
2108
|
* Source for Widget API requests on a data source defined by a SQL query.
|
|
2154
2109
|
*
|
|
@@ -2179,16 +2134,6 @@ class WidgetSource {
|
|
|
2179
2134
|
dataResolution: props.dataResolution
|
|
2180
2135
|
};
|
|
2181
2136
|
}
|
|
2182
|
-
_getSpatialFiltersResolution(source, spatialFilter, referenceViewState) {
|
|
2183
|
-
// spatialFiltersResolution applies only to spatial index sources.
|
|
2184
|
-
if (!spatialFilter || source.spatialDataType === 'geo') {
|
|
2185
|
-
return;
|
|
2186
|
-
}
|
|
2187
|
-
if (!referenceViewState) {
|
|
2188
|
-
throw new Error('Missing required option, "spatialIndexReferenceViewState".');
|
|
2189
|
-
}
|
|
2190
|
-
return getSpatialFiltersResolution(source, referenceViewState);
|
|
2191
|
-
}
|
|
2192
2137
|
}
|
|
2193
2138
|
/**
|
|
2194
2139
|
* @todo TODO(v0.5): Remove WidgetBaseSource alias.
|
|
@@ -2332,8 +2277,7 @@ function executeModel(props) {
|
|
|
2332
2277
|
filters,
|
|
2333
2278
|
filtersLogicalOperator = 'and',
|
|
2334
2279
|
spatialDataType = 'geo',
|
|
2335
|
-
spatialFiltersMode = 'intersects'
|
|
2336
|
-
spatialFiltersResolution = 0
|
|
2280
|
+
spatialFiltersMode = 'intersects'
|
|
2337
2281
|
} = source;
|
|
2338
2282
|
const queryParams = {
|
|
2339
2283
|
type,
|
|
@@ -2359,9 +2303,6 @@ function executeModel(props) {
|
|
|
2359
2303
|
queryParams.spatialDataType = spatialDataType;
|
|
2360
2304
|
}
|
|
2361
2305
|
if (spatialDataType !== 'geo') {
|
|
2362
|
-
if (spatialFiltersResolution > 0) {
|
|
2363
|
-
queryParams.spatialFiltersResolution = spatialFiltersResolution;
|
|
2364
|
-
}
|
|
2365
2306
|
queryParams.spatialFiltersMode = spatialFiltersMode;
|
|
2366
2307
|
}
|
|
2367
2308
|
const urlWithSearchParams = url + '?' + objectToURLSearchParams(queryParams).toString();
|
|
@@ -2412,7 +2353,6 @@ class WidgetRemoteSource extends WidgetSource {
|
|
|
2412
2353
|
filterOwner,
|
|
2413
2354
|
spatialFilter,
|
|
2414
2355
|
spatialFiltersMode,
|
|
2415
|
-
spatialIndexReferenceViewState,
|
|
2416
2356
|
...params
|
|
2417
2357
|
} = options;
|
|
2418
2358
|
const {
|
|
@@ -2420,13 +2360,10 @@ class WidgetRemoteSource extends WidgetSource {
|
|
|
2420
2360
|
operation,
|
|
2421
2361
|
operationColumn
|
|
2422
2362
|
} = params;
|
|
2423
|
-
const source = _this.getModelSource(filters, filterOwner);
|
|
2424
|
-
const spatialFiltersResolution = _this._getSpatialFiltersResolution(source, spatialFilter, spatialIndexReferenceViewState);
|
|
2425
2363
|
return Promise.resolve(executeModel({
|
|
2426
2364
|
model: 'category',
|
|
2427
2365
|
source: {
|
|
2428
|
-
...
|
|
2429
|
-
spatialFiltersResolution,
|
|
2366
|
+
..._this.getModelSource(filters, filterOwner),
|
|
2430
2367
|
spatialFiltersMode,
|
|
2431
2368
|
spatialFilter
|
|
2432
2369
|
},
|
|
@@ -2454,7 +2391,6 @@ class WidgetRemoteSource extends WidgetSource {
|
|
|
2454
2391
|
filterOwner,
|
|
2455
2392
|
spatialFilter,
|
|
2456
2393
|
spatialFiltersMode,
|
|
2457
|
-
spatialIndexReferenceViewState,
|
|
2458
2394
|
...params
|
|
2459
2395
|
} = options;
|
|
2460
2396
|
const {
|
|
@@ -2465,13 +2401,10 @@ class WidgetRemoteSource extends WidgetSource {
|
|
|
2465
2401
|
limit,
|
|
2466
2402
|
tileResolution
|
|
2467
2403
|
} = params;
|
|
2468
|
-
const source = _this2.getModelSource(filters, filterOwner);
|
|
2469
|
-
const spatialFiltersResolution = _this2._getSpatialFiltersResolution(source, spatialFilter, spatialIndexReferenceViewState);
|
|
2470
2404
|
return Promise.resolve(executeModel({
|
|
2471
2405
|
model: 'pick',
|
|
2472
2406
|
source: {
|
|
2473
|
-
...
|
|
2474
|
-
spatialFiltersResolution,
|
|
2407
|
+
..._this2.getModelSource(filters, filterOwner),
|
|
2475
2408
|
spatialFiltersMode,
|
|
2476
2409
|
spatialFilter
|
|
2477
2410
|
},
|
|
@@ -2510,7 +2443,6 @@ class WidgetRemoteSource extends WidgetSource {
|
|
|
2510
2443
|
filterOwner,
|
|
2511
2444
|
spatialFilter,
|
|
2512
2445
|
spatialFiltersMode,
|
|
2513
|
-
spatialIndexReferenceViewState,
|
|
2514
2446
|
operationExp,
|
|
2515
2447
|
...params
|
|
2516
2448
|
} = options;
|
|
@@ -2518,13 +2450,10 @@ class WidgetRemoteSource extends WidgetSource {
|
|
|
2518
2450
|
column,
|
|
2519
2451
|
operation
|
|
2520
2452
|
} = params;
|
|
2521
|
-
const source = _this3.getModelSource(filters, filterOwner);
|
|
2522
|
-
const spatialFiltersResolution = _this3._getSpatialFiltersResolution(source, spatialFilter, spatialIndexReferenceViewState);
|
|
2523
2453
|
return Promise.resolve(executeModel({
|
|
2524
2454
|
model: 'formula',
|
|
2525
2455
|
source: {
|
|
2526
|
-
...
|
|
2527
|
-
spatialFiltersResolution,
|
|
2456
|
+
..._this3.getModelSource(filters, filterOwner),
|
|
2528
2457
|
spatialFiltersMode,
|
|
2529
2458
|
spatialFilter
|
|
2530
2459
|
},
|
|
@@ -2552,7 +2481,6 @@ class WidgetRemoteSource extends WidgetSource {
|
|
|
2552
2481
|
filterOwner,
|
|
2553
2482
|
spatialFilter,
|
|
2554
2483
|
spatialFiltersMode,
|
|
2555
|
-
spatialIndexReferenceViewState,
|
|
2556
2484
|
...params
|
|
2557
2485
|
} = options;
|
|
2558
2486
|
const {
|
|
@@ -2560,13 +2488,10 @@ class WidgetRemoteSource extends WidgetSource {
|
|
|
2560
2488
|
operation,
|
|
2561
2489
|
ticks
|
|
2562
2490
|
} = params;
|
|
2563
|
-
const source = _this4.getModelSource(filters, filterOwner);
|
|
2564
|
-
const spatialFiltersResolution = _this4._getSpatialFiltersResolution(source, spatialFilter, spatialIndexReferenceViewState);
|
|
2565
2491
|
return Promise.resolve(executeModel({
|
|
2566
2492
|
model: 'histogram',
|
|
2567
2493
|
source: {
|
|
2568
|
-
...
|
|
2569
|
-
spatialFiltersResolution,
|
|
2494
|
+
..._this4.getModelSource(filters, filterOwner),
|
|
2570
2495
|
spatialFiltersMode,
|
|
2571
2496
|
spatialFilter
|
|
2572
2497
|
},
|
|
@@ -2609,19 +2534,15 @@ class WidgetRemoteSource extends WidgetSource {
|
|
|
2609
2534
|
filterOwner,
|
|
2610
2535
|
spatialFilter,
|
|
2611
2536
|
spatialFiltersMode,
|
|
2612
|
-
spatialIndexReferenceViewState,
|
|
2613
2537
|
...params
|
|
2614
2538
|
} = options;
|
|
2615
2539
|
const {
|
|
2616
2540
|
column
|
|
2617
2541
|
} = params;
|
|
2618
|
-
const source = _this5.getModelSource(filters, filterOwner);
|
|
2619
|
-
const spatialFiltersResolution = _this5._getSpatialFiltersResolution(source, spatialFilter, spatialIndexReferenceViewState);
|
|
2620
2542
|
return Promise.resolve(executeModel({
|
|
2621
2543
|
model: 'range',
|
|
2622
2544
|
source: {
|
|
2623
|
-
...
|
|
2624
|
-
spatialFiltersResolution,
|
|
2545
|
+
..._this5.getModelSource(filters, filterOwner),
|
|
2625
2546
|
spatialFiltersMode,
|
|
2626
2547
|
spatialFilter
|
|
2627
2548
|
},
|
|
@@ -2647,7 +2568,6 @@ class WidgetRemoteSource extends WidgetSource {
|
|
|
2647
2568
|
filterOwner,
|
|
2648
2569
|
spatialFilter,
|
|
2649
2570
|
spatialFiltersMode,
|
|
2650
|
-
spatialIndexReferenceViewState,
|
|
2651
2571
|
...params
|
|
2652
2572
|
} = options;
|
|
2653
2573
|
const {
|
|
@@ -2656,15 +2576,12 @@ class WidgetRemoteSource extends WidgetSource {
|
|
|
2656
2576
|
yAxisColumn,
|
|
2657
2577
|
yAxisJoinOperation
|
|
2658
2578
|
} = params;
|
|
2659
|
-
const source = _this6.getModelSource(filters, filterOwner);
|
|
2660
|
-
const spatialFiltersResolution = _this6._getSpatialFiltersResolution(source, spatialFilter, spatialIndexReferenceViewState);
|
|
2661
2579
|
// Make sure this is sync with the same constant in cloud-native/maps-api
|
|
2662
2580
|
const HARD_LIMIT = 500;
|
|
2663
2581
|
return Promise.resolve(executeModel({
|
|
2664
2582
|
model: 'scatterplot',
|
|
2665
2583
|
source: {
|
|
2666
|
-
...
|
|
2667
|
-
spatialFiltersResolution,
|
|
2584
|
+
..._this6.getModelSource(filters, filterOwner),
|
|
2668
2585
|
spatialFiltersMode,
|
|
2669
2586
|
spatialFilter
|
|
2670
2587
|
},
|
|
@@ -2700,7 +2617,6 @@ class WidgetRemoteSource extends WidgetSource {
|
|
|
2700
2617
|
filterOwner,
|
|
2701
2618
|
spatialFilter,
|
|
2702
2619
|
spatialFiltersMode,
|
|
2703
|
-
spatialIndexReferenceViewState,
|
|
2704
2620
|
...params
|
|
2705
2621
|
} = options;
|
|
2706
2622
|
const {
|
|
@@ -2710,13 +2626,10 @@ class WidgetRemoteSource extends WidgetSource {
|
|
|
2710
2626
|
offset = 0,
|
|
2711
2627
|
limit = 10
|
|
2712
2628
|
} = params;
|
|
2713
|
-
const source = _this7.getModelSource(filters, filterOwner);
|
|
2714
|
-
const spatialFiltersResolution = _this7._getSpatialFiltersResolution(source, spatialFilter, spatialIndexReferenceViewState);
|
|
2715
2629
|
return Promise.resolve(executeModel({
|
|
2716
2630
|
model: 'table',
|
|
2717
2631
|
source: {
|
|
2718
|
-
...
|
|
2719
|
-
spatialFiltersResolution,
|
|
2632
|
+
..._this7.getModelSource(filters, filterOwner),
|
|
2720
2633
|
spatialFiltersMode,
|
|
2721
2634
|
spatialFilter
|
|
2722
2635
|
},
|
|
@@ -2750,7 +2663,6 @@ class WidgetRemoteSource extends WidgetSource {
|
|
|
2750
2663
|
filterOwner,
|
|
2751
2664
|
spatialFilter,
|
|
2752
2665
|
spatialFiltersMode,
|
|
2753
|
-
spatialIndexReferenceViewState,
|
|
2754
2666
|
...params
|
|
2755
2667
|
} = options;
|
|
2756
2668
|
const {
|
|
@@ -2764,13 +2676,10 @@ class WidgetRemoteSource extends WidgetSource {
|
|
|
2764
2676
|
splitByCategoryLimit,
|
|
2765
2677
|
splitByCategoryValues
|
|
2766
2678
|
} = params;
|
|
2767
|
-
const source = _this8.getModelSource(filters, filterOwner);
|
|
2768
|
-
const spatialFiltersResolution = _this8._getSpatialFiltersResolution(source, spatialFilter, spatialIndexReferenceViewState);
|
|
2769
2679
|
return Promise.resolve(executeModel({
|
|
2770
2680
|
model: 'timeseries',
|
|
2771
2681
|
source: {
|
|
2772
|
-
...
|
|
2773
|
-
spatialFiltersResolution,
|
|
2682
|
+
..._this8.getModelSource(filters, filterOwner),
|
|
2774
2683
|
spatialFiltersMode,
|
|
2775
2684
|
spatialFilter
|
|
2776
2685
|
},
|
|
@@ -4011,6 +3920,28 @@ const query = function (options) {
|
|
|
4011
3920
|
}
|
|
4012
3921
|
};
|
|
4013
3922
|
|
|
3923
|
+
// Default tile display size in deck.gl, in viewport pixels. May differ
|
|
3924
|
+
// from size or resolution assumed when generating the tile data,
|
|
3925
|
+
const DEFAULT_TILE_SIZE = 512;
|
|
3926
|
+
// Relative scale factor (0 = no biasing, 2 = a few hexagons cover view)
|
|
3927
|
+
const BIAS = 2;
|
|
3928
|
+
/**
|
|
3929
|
+
* Resolution conversion function. Takes a WebMercatorViewport and returns
|
|
3930
|
+
* a H3 resolution such that the screen space size of the hexagons is
|
|
3931
|
+
* "similar" to the given tileSize on screen. Intended for use with deck.gl.
|
|
3932
|
+
* @internal
|
|
3933
|
+
* @privateRemarks Source: https://github.com/visgl/deck.gl/blob/master/modules/carto/src/layers/h3-tileset-2d.ts
|
|
3934
|
+
*/
|
|
3935
|
+
function _getHexagonResolution(viewport, tileSize) {
|
|
3936
|
+
// Difference in given tile size compared to deck's internal 512px tile size,
|
|
3937
|
+
// expressed as an offset to the viewport zoom.
|
|
3938
|
+
const zoomOffset = Math.log2(tileSize / DEFAULT_TILE_SIZE);
|
|
3939
|
+
const hexagonScaleFactor = 2 / 3 * (viewport.zoom - zoomOffset);
|
|
3940
|
+
const latitudeScaleFactor = Math.log(1 / Math.cos(Math.PI * viewport.latitude / 180));
|
|
3941
|
+
// Clip and bias
|
|
3942
|
+
return Math.max(0, Math.floor(hexagonScaleFactor + latitudeScaleFactor - BIAS));
|
|
3943
|
+
}
|
|
3944
|
+
|
|
4014
3945
|
exports.CartoAPIError = CartoAPIError;
|
|
4015
3946
|
exports.DEFAULT_API_BASE_URL = DEFAULT_API_BASE_URL;
|
|
4016
3947
|
exports.FEATURE_GEOM_PROPERTY = FEATURE_GEOM_PROPERTY;
|