@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.
@@ -2056,50 +2056,6 @@ const boundaryTableSource = async function boundaryTableSource(options) {
2056
2056
  return baseSource('boundary', options, urlParameters);
2057
2057
  };
2058
2058
 
2059
- const DEFAULT_TILE_SIZE = 512;
2060
- const QUADBIN_ZOOM_MAX_OFFSET = 4;
2061
- function getSpatialFiltersResolution(source, viewState) {
2062
- var _source$dataResolutio, _source$aggregationRe;
2063
- const dataResolution = (_source$dataResolutio = source.dataResolution) != null ? _source$dataResolutio : Number.MAX_VALUE;
2064
- const aggregationResLevel = (_source$aggregationRe = source.aggregationResLevel) != null ? _source$aggregationRe : source.spatialDataType === 'h3' ? DEFAULT_AGGREGATION_RES_LEVEL_H3 : DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN;
2065
- const aggregationResLevelOffset = Math.max(0, Math.floor(aggregationResLevel));
2066
- const currentZoomInt = Math.ceil(viewState.zoom);
2067
- if (source.spatialDataType === 'h3') {
2068
- var _maxH3SpatialFiltersR, _maxH3SpatialFiltersR2;
2069
- const tileSize = DEFAULT_TILE_SIZE;
2070
- const maxResolutionForZoom = (_maxH3SpatialFiltersR = (_maxH3SpatialFiltersR2 = maxH3SpatialFiltersResolutions.find(([zoom]) => zoom === currentZoomInt)) == null ? void 0 : _maxH3SpatialFiltersR2[1]) != null ? _maxH3SpatialFiltersR : Math.max(0, currentZoomInt - 3);
2071
- const maxSpatialFiltersResolution = maxResolutionForZoom ? Math.min(dataResolution, maxResolutionForZoom) : dataResolution;
2072
- const hexagonResolution = _getHexagonResolution(viewState, tileSize) + aggregationResLevelOffset;
2073
- return Math.min(hexagonResolution, maxSpatialFiltersResolution);
2074
- }
2075
- if (source.spatialDataType === 'quadbin') {
2076
- const maxResolutionForZoom = currentZoomInt + QUADBIN_ZOOM_MAX_OFFSET;
2077
- const maxSpatialFiltersResolution = Math.min(dataResolution, maxResolutionForZoom);
2078
- const quadsResolution = Math.floor(viewState.zoom) + aggregationResLevelOffset;
2079
- return Math.min(quadsResolution, maxSpatialFiltersResolution);
2080
- }
2081
- return undefined;
2082
- }
2083
- 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]];
2084
- // stolen from https://github.com/visgl/deck.gl/blob/master/modules/carto/src/layers/h3-tileset-2d.ts
2085
- // Relative scale factor (0 = no biasing, 2 = a few hexagons cover view)
2086
- const BIAS = 2;
2087
- /**
2088
- * Resolution conversion function. Takes a WebMercatorViewport and returns
2089
- * a H3 resolution such that the screen space size of the hexagons is
2090
- * "similar" to the given tileSize on screen. Intended for use with deck.gl.
2091
- * @internal
2092
- */
2093
- function _getHexagonResolution(viewport, tileSize) {
2094
- // Difference in given tile size compared to deck's internal 512px tile size,
2095
- // expressed as an offset to the viewport zoom.
2096
- const zoomOffset = Math.log2(tileSize / DEFAULT_TILE_SIZE);
2097
- const hexagonScaleFactor = 2 / 3 * (viewport.zoom - zoomOffset);
2098
- const latitudeScaleFactor = Math.log(1 / Math.cos(Math.PI * viewport.latitude / 180));
2099
- // Clip and bias
2100
- return Math.max(0, Math.floor(hexagonScaleFactor + latitudeScaleFactor - BIAS));
2101
- }
2102
-
2103
2059
  /**
2104
2060
  * Source for Widget API requests on a data source defined by a SQL query.
2105
2061
  *
@@ -2127,16 +2083,6 @@ class WidgetSource {
2127
2083
  dataResolution: props.dataResolution
2128
2084
  };
2129
2085
  }
2130
- _getSpatialFiltersResolution(source, spatialFilter, referenceViewState) {
2131
- // spatialFiltersResolution applies only to spatial index sources.
2132
- if (!spatialFilter || source.spatialDataType === 'geo') {
2133
- return;
2134
- }
2135
- if (!referenceViewState) {
2136
- throw new Error('Missing required option, "spatialIndexReferenceViewState".');
2137
- }
2138
- return getSpatialFiltersResolution(source, referenceViewState);
2139
- }
2140
2086
  }
2141
2087
  /**
2142
2088
  * @todo TODO(v0.5): Remove WidgetBaseSource alias.
@@ -2250,8 +2196,7 @@ function executeModel(props) {
2250
2196
  filters,
2251
2197
  filtersLogicalOperator = 'and',
2252
2198
  spatialDataType = 'geo',
2253
- spatialFiltersMode = 'intersects',
2254
- spatialFiltersResolution = 0
2199
+ spatialFiltersMode = 'intersects'
2255
2200
  } = source;
2256
2201
  const queryParams = {
2257
2202
  type,
@@ -2277,9 +2222,6 @@ function executeModel(props) {
2277
2222
  queryParams.spatialDataType = spatialDataType;
2278
2223
  }
2279
2224
  if (spatialDataType !== 'geo') {
2280
- if (spatialFiltersResolution > 0) {
2281
- queryParams.spatialFiltersResolution = spatialFiltersResolution;
2282
- }
2283
2225
  queryParams.spatialFiltersMode = spatialFiltersMode;
2284
2226
  }
2285
2227
  const urlWithSearchParams = url + '?' + objectToURLSearchParams(queryParams).toString();
@@ -2313,14 +2255,14 @@ function objectToURLSearchParams(object) {
2313
2255
  return params;
2314
2256
  }
2315
2257
 
2316
- const _excluded = ["signal", "filters", "filterOwner", "spatialFilter", "spatialFiltersMode", "spatialIndexReferenceViewState"],
2317
- _excluded2 = ["abortController", "signal", "filters", "filterOwner", "spatialFilter", "spatialFiltersMode", "spatialIndexReferenceViewState"],
2318
- _excluded3 = ["abortController", "signal", "filters", "filterOwner", "spatialFilter", "spatialFiltersMode", "spatialIndexReferenceViewState", "operationExp"],
2319
- _excluded4 = ["abortController", "signal", "filters", "filterOwner", "spatialFilter", "spatialFiltersMode", "spatialIndexReferenceViewState"],
2320
- _excluded5 = ["abortController", "signal", "filters", "filterOwner", "spatialFilter", "spatialFiltersMode", "spatialIndexReferenceViewState"],
2321
- _excluded6 = ["abortController", "signal", "filters", "filterOwner", "spatialFilter", "spatialFiltersMode", "spatialIndexReferenceViewState"],
2322
- _excluded7 = ["abortController", "signal", "filters", "filterOwner", "spatialFilter", "spatialFiltersMode", "spatialIndexReferenceViewState"],
2323
- _excluded8 = ["abortController", "signal", "filters", "filterOwner", "spatialFilter", "spatialFiltersMode", "spatialIndexReferenceViewState"];
2258
+ const _excluded = ["signal", "filters", "filterOwner", "spatialFilter", "spatialFiltersMode"],
2259
+ _excluded2 = ["abortController", "signal", "filters", "filterOwner", "spatialFilter", "spatialFiltersMode"],
2260
+ _excluded3 = ["abortController", "signal", "filters", "filterOwner", "spatialFilter", "spatialFiltersMode", "operationExp"],
2261
+ _excluded4 = ["abortController", "signal", "filters", "filterOwner", "spatialFilter", "spatialFiltersMode"],
2262
+ _excluded5 = ["abortController", "signal", "filters", "filterOwner", "spatialFilter", "spatialFiltersMode"],
2263
+ _excluded6 = ["abortController", "signal", "filters", "filterOwner", "spatialFilter", "spatialFiltersMode"],
2264
+ _excluded7 = ["abortController", "signal", "filters", "filterOwner", "spatialFilter", "spatialFiltersMode"],
2265
+ _excluded8 = ["abortController", "signal", "filters", "filterOwner", "spatialFilter", "spatialFiltersMode"];
2324
2266
  /**
2325
2267
  * Source for Widget API requests.
2326
2268
  *
@@ -2333,8 +2275,7 @@ class WidgetRemoteSource extends WidgetSource {
2333
2275
  filters = this.props.filters,
2334
2276
  filterOwner,
2335
2277
  spatialFilter,
2336
- spatialFiltersMode,
2337
- spatialIndexReferenceViewState
2278
+ spatialFiltersMode
2338
2279
  } = options,
2339
2280
  params = _objectWithoutPropertiesLoose(options, _excluded);
2340
2281
  const {
@@ -2342,12 +2283,9 @@ class WidgetRemoteSource extends WidgetSource {
2342
2283
  operation,
2343
2284
  operationColumn
2344
2285
  } = params;
2345
- const source = this.getModelSource(filters, filterOwner);
2346
- const spatialFiltersResolution = this._getSpatialFiltersResolution(source, spatialFilter, spatialIndexReferenceViewState);
2347
2286
  return executeModel({
2348
2287
  model: 'category',
2349
- source: _extends({}, source, {
2350
- spatialFiltersResolution,
2288
+ source: _extends({}, this.getModelSource(filters, filterOwner), {
2351
2289
  spatialFiltersMode,
2352
2290
  spatialFilter
2353
2291
  }),
@@ -2369,8 +2307,7 @@ class WidgetRemoteSource extends WidgetSource {
2369
2307
  filters = this.props.filters,
2370
2308
  filterOwner,
2371
2309
  spatialFilter,
2372
- spatialFiltersMode,
2373
- spatialIndexReferenceViewState
2310
+ spatialFiltersMode
2374
2311
  } = options,
2375
2312
  params = _objectWithoutPropertiesLoose(options, _excluded2);
2376
2313
  const {
@@ -2381,12 +2318,9 @@ class WidgetRemoteSource extends WidgetSource {
2381
2318
  limit,
2382
2319
  tileResolution
2383
2320
  } = params;
2384
- const source = this.getModelSource(filters, filterOwner);
2385
- const spatialFiltersResolution = this._getSpatialFiltersResolution(source, spatialFilter, spatialIndexReferenceViewState);
2386
2321
  return executeModel({
2387
2322
  model: 'pick',
2388
- source: _extends({}, source, {
2389
- spatialFiltersResolution,
2323
+ source: _extends({}, this.getModelSource(filters, filterOwner), {
2390
2324
  spatialFiltersMode,
2391
2325
  spatialFilter
2392
2326
  }),
@@ -2417,7 +2351,6 @@ class WidgetRemoteSource extends WidgetSource {
2417
2351
  filterOwner,
2418
2352
  spatialFilter,
2419
2353
  spatialFiltersMode,
2420
- spatialIndexReferenceViewState,
2421
2354
  operationExp
2422
2355
  } = options,
2423
2356
  params = _objectWithoutPropertiesLoose(options, _excluded3);
@@ -2425,12 +2358,9 @@ class WidgetRemoteSource extends WidgetSource {
2425
2358
  column,
2426
2359
  operation
2427
2360
  } = params;
2428
- const source = this.getModelSource(filters, filterOwner);
2429
- const spatialFiltersResolution = this._getSpatialFiltersResolution(source, spatialFilter, spatialIndexReferenceViewState);
2430
2361
  return executeModel({
2431
2362
  model: 'formula',
2432
- source: _extends({}, source, {
2433
- spatialFiltersResolution,
2363
+ source: _extends({}, this.getModelSource(filters, filterOwner), {
2434
2364
  spatialFiltersMode,
2435
2365
  spatialFilter
2436
2366
  }),
@@ -2452,8 +2382,7 @@ class WidgetRemoteSource extends WidgetSource {
2452
2382
  filters = this.props.filters,
2453
2383
  filterOwner,
2454
2384
  spatialFilter,
2455
- spatialFiltersMode,
2456
- spatialIndexReferenceViewState
2385
+ spatialFiltersMode
2457
2386
  } = options,
2458
2387
  params = _objectWithoutPropertiesLoose(options, _excluded4);
2459
2388
  const {
@@ -2461,12 +2390,9 @@ class WidgetRemoteSource extends WidgetSource {
2461
2390
  operation,
2462
2391
  ticks
2463
2392
  } = params;
2464
- const source = this.getModelSource(filters, filterOwner);
2465
- const spatialFiltersResolution = this._getSpatialFiltersResolution(source, spatialFilter, spatialIndexReferenceViewState);
2466
2393
  const data = await executeModel({
2467
2394
  model: 'histogram',
2468
- source: _extends({}, source, {
2469
- spatialFiltersResolution,
2395
+ source: _extends({}, this.getModelSource(filters, filterOwner), {
2470
2396
  spatialFiltersMode,
2471
2397
  spatialFilter
2472
2398
  }),
@@ -2499,19 +2425,15 @@ class WidgetRemoteSource extends WidgetSource {
2499
2425
  filters = this.props.filters,
2500
2426
  filterOwner,
2501
2427
  spatialFilter,
2502
- spatialFiltersMode,
2503
- spatialIndexReferenceViewState
2428
+ spatialFiltersMode
2504
2429
  } = options,
2505
2430
  params = _objectWithoutPropertiesLoose(options, _excluded5);
2506
2431
  const {
2507
2432
  column
2508
2433
  } = params;
2509
- const source = this.getModelSource(filters, filterOwner);
2510
- const spatialFiltersResolution = this._getSpatialFiltersResolution(source, spatialFilter, spatialIndexReferenceViewState);
2511
2434
  return executeModel({
2512
2435
  model: 'range',
2513
- source: _extends({}, source, {
2514
- spatialFiltersResolution,
2436
+ source: _extends({}, this.getModelSource(filters, filterOwner), {
2515
2437
  spatialFiltersMode,
2516
2438
  spatialFilter
2517
2439
  }),
@@ -2531,8 +2453,7 @@ class WidgetRemoteSource extends WidgetSource {
2531
2453
  filters = this.props.filters,
2532
2454
  filterOwner,
2533
2455
  spatialFilter,
2534
- spatialFiltersMode,
2535
- spatialIndexReferenceViewState
2456
+ spatialFiltersMode
2536
2457
  } = options,
2537
2458
  params = _objectWithoutPropertiesLoose(options, _excluded6);
2538
2459
  const {
@@ -2541,14 +2462,11 @@ class WidgetRemoteSource extends WidgetSource {
2541
2462
  yAxisColumn,
2542
2463
  yAxisJoinOperation
2543
2464
  } = params;
2544
- const source = this.getModelSource(filters, filterOwner);
2545
- const spatialFiltersResolution = this._getSpatialFiltersResolution(source, spatialFilter, spatialIndexReferenceViewState);
2546
2465
  // Make sure this is sync with the same constant in cloud-native/maps-api
2547
2466
  const HARD_LIMIT = 500;
2548
2467
  return executeModel({
2549
2468
  model: 'scatterplot',
2550
- source: _extends({}, source, {
2551
- spatialFiltersResolution,
2469
+ source: _extends({}, this.getModelSource(filters, filterOwner), {
2552
2470
  spatialFiltersMode,
2553
2471
  spatialFilter
2554
2472
  }),
@@ -2575,8 +2493,7 @@ class WidgetRemoteSource extends WidgetSource {
2575
2493
  filters = this.props.filters,
2576
2494
  filterOwner,
2577
2495
  spatialFilter,
2578
- spatialFiltersMode,
2579
- spatialIndexReferenceViewState
2496
+ spatialFiltersMode
2580
2497
  } = options,
2581
2498
  params = _objectWithoutPropertiesLoose(options, _excluded7);
2582
2499
  const {
@@ -2586,12 +2503,9 @@ class WidgetRemoteSource extends WidgetSource {
2586
2503
  offset = 0,
2587
2504
  limit = 10
2588
2505
  } = params;
2589
- const source = this.getModelSource(filters, filterOwner);
2590
- const spatialFiltersResolution = this._getSpatialFiltersResolution(source, spatialFilter, spatialIndexReferenceViewState);
2591
2506
  return executeModel({
2592
2507
  model: 'table',
2593
- source: _extends({}, source, {
2594
- spatialFiltersResolution,
2508
+ source: _extends({}, this.getModelSource(filters, filterOwner), {
2595
2509
  spatialFiltersMode,
2596
2510
  spatialFilter
2597
2511
  }),
@@ -2622,8 +2536,7 @@ class WidgetRemoteSource extends WidgetSource {
2622
2536
  filters = this.props.filters,
2623
2537
  filterOwner,
2624
2538
  spatialFilter,
2625
- spatialFiltersMode,
2626
- spatialIndexReferenceViewState
2539
+ spatialFiltersMode
2627
2540
  } = options,
2628
2541
  params = _objectWithoutPropertiesLoose(options, _excluded8);
2629
2542
  const {
@@ -2637,12 +2550,9 @@ class WidgetRemoteSource extends WidgetSource {
2637
2550
  splitByCategoryLimit,
2638
2551
  splitByCategoryValues
2639
2552
  } = params;
2640
- const source = this.getModelSource(filters, filterOwner);
2641
- const spatialFiltersResolution = this._getSpatialFiltersResolution(source, spatialFilter, spatialIndexReferenceViewState);
2642
2553
  return executeModel({
2643
2554
  model: 'timeseries',
2644
- source: _extends({}, source, {
2645
- spatialFiltersResolution,
2555
+ source: _extends({}, this.getModelSource(filters, filterOwner), {
2646
2556
  spatialFiltersMode,
2647
2557
  spatialFilter
2648
2558
  }),
@@ -3725,5 +3635,27 @@ const query = async function query(options) {
3725
3635
  });
3726
3636
  };
3727
3637
 
3638
+ // Default tile display size in deck.gl, in viewport pixels. May differ
3639
+ // from size or resolution assumed when generating the tile data,
3640
+ const DEFAULT_TILE_SIZE = 512;
3641
+ // Relative scale factor (0 = no biasing, 2 = a few hexagons cover view)
3642
+ const BIAS = 2;
3643
+ /**
3644
+ * Resolution conversion function. Takes a WebMercatorViewport and returns
3645
+ * a H3 resolution such that the screen space size of the hexagons is
3646
+ * "similar" to the given tileSize on screen. Intended for use with deck.gl.
3647
+ * @internal
3648
+ * @privateRemarks Source: https://github.com/visgl/deck.gl/blob/master/modules/carto/src/layers/h3-tileset-2d.ts
3649
+ */
3650
+ function _getHexagonResolution(viewport, tileSize) {
3651
+ // Difference in given tile size compared to deck's internal 512px tile size,
3652
+ // expressed as an offset to the viewport zoom.
3653
+ const zoomOffset = Math.log2(tileSize / DEFAULT_TILE_SIZE);
3654
+ const hexagonScaleFactor = 2 / 3 * (viewport.zoom - zoomOffset);
3655
+ const latitudeScaleFactor = Math.log(1 / Math.cos(Math.PI * viewport.latitude / 180));
3656
+ // Clip and bias
3657
+ return Math.max(0, Math.floor(hexagonScaleFactor + latitudeScaleFactor - BIAS));
3658
+ }
3659
+
3728
3660
  export { ApiVersion, CartoAPIError, DEFAULT_API_BASE_URL, FEATURE_GEOM_PROPERTY, FilterType, Provider, SOURCE_DEFAULTS, SpatialIndex, TileFormat, WidgetBaseSource, WidgetQuerySource, WidgetRemoteSource, WidgetSource, WidgetTableSource, WidgetTilesetSource, _buildFeatureFilter, _getHexagonResolution, addFilter, aggregate, aggregationFunctions, applyFilters, applySorting, boundaryQuerySource, boundaryTableSource, buildBinaryFeatureFilter, buildPublicMapUrl, buildStatsUrl, clearFilters, createPolygonSpatialFilter, createViewportSpatialFilter, filterFunctions, geojsonFeatures, getClient, getDataFilterExtensionProps, getFilter, groupValuesByColumn, groupValuesByDateColumn, h3QuerySource, h3TableSource, h3TilesetSource, hasFilter, histogram, makeIntervalComplete, quadbinQuerySource, quadbinTableSource, quadbinTilesetSource, query, rasterSource, removeFilter, requestWithParameters, scatterPlot, setClient, tileFeatures, tileFeaturesGeometries, tileFeaturesSpatialIndex, transformToTileCoords, vectorQuerySource, vectorTableSource, vectorTilesetSource };
3729
3661
  //# sourceMappingURL=api-client.modern.js.map