@deck.gl/carto 9.0.29 → 9.0.30

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.
Files changed (39) hide show
  1. package/dist/api/common.d.ts +1 -1
  2. package/dist/api/common.d.ts.map +1 -1
  3. package/dist/api/common.js +2 -1
  4. package/dist/api/fetch-map.d.ts +7 -1
  5. package/dist/api/fetch-map.d.ts.map +1 -1
  6. package/dist/api/fetch-map.js +17 -15
  7. package/dist/api/query.d.ts.map +1 -1
  8. package/dist/api/query.js +3 -2
  9. package/dist/api/request-with-parameters.d.ts +2 -1
  10. package/dist/api/request-with-parameters.d.ts.map +1 -1
  11. package/dist/api/request-with-parameters.js +3 -3
  12. package/dist/cartoRasterTile-worker.js +1 -1
  13. package/dist/cartoSpatialTile-worker.js +1 -1
  14. package/dist/cartoVectorTile-worker.js +1 -1
  15. package/dist/dist.dev.js +57 -30
  16. package/dist/index.cjs +49 -32
  17. package/dist/index.cjs.map +2 -2
  18. package/dist/layers/cluster-tile-layer.d.ts.map +1 -1
  19. package/dist/layers/cluster-tile-layer.js +12 -2
  20. package/dist/layers/cluster-utils.d.ts +1 -1
  21. package/dist/layers/cluster-utils.d.ts.map +1 -1
  22. package/dist/layers/cluster-utils.js +5 -5
  23. package/dist/layers/schema/carto-raster-tile-loader.js +1 -1
  24. package/dist/layers/schema/carto-spatial-tile-loader.js +1 -1
  25. package/dist/layers/schema/carto-vector-tile-loader.js +1 -1
  26. package/dist/sources/base-source.d.ts.map +1 -1
  27. package/dist/sources/base-source.js +10 -6
  28. package/dist/sources/types.d.ts +6 -0
  29. package/dist/sources/types.d.ts.map +1 -1
  30. package/dist.min.js +9 -9
  31. package/package.json +2 -2
  32. package/src/api/common.ts +3 -1
  33. package/src/api/fetch-map.ts +38 -18
  34. package/src/api/query.ts +3 -1
  35. package/src/api/request-with-parameters.ts +5 -3
  36. package/src/layers/cluster-tile-layer.ts +14 -1
  37. package/src/layers/cluster-utils.ts +5 -4
  38. package/src/sources/base-source.ts +10 -6
  39. package/src/sources/types.ts +7 -0
package/dist/index.cjs CHANGED
@@ -74,18 +74,18 @@ var import_core6 = require("@deck.gl/core");
74
74
  // dist/layers/cluster-utils.js
75
75
  var import_quadbin = require("quadbin");
76
76
  var import_core = require("@deck.gl/core");
77
- function aggregateTile(tile, aggregationLevels, properties = [], getPosition, getWeight) {
77
+ function aggregateTile(tile, tileAggregationCache, aggregationLevels, properties = [], getPosition, getWeight) {
78
78
  var _a;
79
79
  if (!tile.content)
80
80
  return false;
81
81
  if (!tile.userData)
82
82
  tile.userData = {};
83
- const cell0 = (_a = tile.userData[aggregationLevels]) == null ? void 0 : _a[0];
83
+ const cell0 = (_a = tileAggregationCache.get(aggregationLevels)) == null ? void 0 : _a[0];
84
84
  if (cell0) {
85
85
  if (properties.every((property) => property.name in cell0)) {
86
86
  return false;
87
87
  }
88
- tile.userData = {};
88
+ tileAggregationCache.clear();
89
89
  }
90
90
  const out = {};
91
91
  for (const cell of tile.content) {
@@ -125,7 +125,7 @@ function aggregateTile(tile, aggregationLevels, properties = [], getPosition, ge
125
125
  }
126
126
  }
127
127
  }
128
- tile.userData[aggregationLevels] = Object.values(out);
128
+ tileAggregationCache.set(aggregationLevels, Object.values(out));
129
129
  return true;
130
130
  }
131
131
  function extractAggregationProperties(tile) {
@@ -548,7 +548,7 @@ function binaryToSpatialjson(binary) {
548
548
  }
549
549
 
550
550
  // dist/layers/schema/carto-spatial-tile-loader.js
551
- var VERSION = true ? "9.0.29" : "latest";
551
+ var VERSION = true ? "9.0.30" : "latest";
552
552
  var id = "cartoSpatialTile";
553
553
  var DEFAULT_OPTIONS = {
554
554
  cartoSpatialTile: {
@@ -661,6 +661,10 @@ var defaultProps = {
661
661
  tileSize: DEFAULT_TILE_SIZE
662
662
  };
663
663
  var _ClusterGeoJsonLayer = class extends import_geo_layers2.TileLayer {
664
+ initializeState() {
665
+ super.initializeState();
666
+ this.state.aggregationCache = /* @__PURE__ */ new WeakMap();
667
+ }
664
668
  renderLayers() {
665
669
  var _a;
666
670
  const visibleTiles = (_a = this.state.tileset) == null ? void 0 : _a.tiles.filter((tile) => {
@@ -672,15 +676,21 @@ var _ClusterGeoJsonLayer = class extends import_geo_layers2.TileLayer {
672
676
  visibleTiles.sort((a, b) => b.zoom - a.zoom);
673
677
  const { zoom } = this.context.viewport;
674
678
  const { clusterLevel, getPosition, getWeight } = this.props;
679
+ const { aggregationCache } = this.state;
675
680
  const properties = extractAggregationProperties(visibleTiles[0]);
676
681
  const data = [];
677
682
  let needsUpdate = false;
678
683
  for (const tile of visibleTiles) {
679
684
  const overZoom = Math.round(zoom - tile.zoom);
680
685
  const aggregationLevels = Math.round(clusterLevel) - overZoom;
681
- const didAggregate = aggregateTile(tile, aggregationLevels, properties, getPosition, getWeight);
686
+ let tileAggregationCache = aggregationCache.get(tile.content);
687
+ if (!tileAggregationCache) {
688
+ tileAggregationCache = /* @__PURE__ */ new Map();
689
+ aggregationCache.set(tile.content, tileAggregationCache);
690
+ }
691
+ const didAggregate = aggregateTile(tile, tileAggregationCache, aggregationLevels, properties, getPosition, getWeight);
682
692
  needsUpdate ||= didAggregate;
683
- data.push(...tile.userData[aggregationLevels]);
693
+ data.push(...tileAggregationCache.get(aggregationLevels));
684
694
  }
685
695
  data.sort((a, b) => Number(b.count - a.count));
686
696
  const clusterIds = data == null ? void 0 : data.map((tile) => tile.id);
@@ -912,7 +922,7 @@ var TileReader3 = class {
912
922
  };
913
923
 
914
924
  // dist/layers/schema/carto-raster-tile-loader.js
915
- var VERSION2 = true ? "9.0.29" : "latest";
925
+ var VERSION2 = true ? "9.0.30" : "latest";
916
926
  var id2 = "cartoRasterTile";
917
927
  var DEFAULT_OPTIONS2 = {
918
928
  cartoRasterTile: {
@@ -1994,7 +2004,7 @@ var carto_properties_tile_loader_default = CartoPropertiesTileLoader;
1994
2004
 
1995
2005
  // dist/layers/schema/carto-vector-tile-loader.js
1996
2006
  var import_earcut = __toESM(require("earcut"), 1);
1997
- var VERSION3 = true ? "9.0.29" : "latest";
2007
+ var VERSION3 = true ? "9.0.30" : "latest";
1998
2008
  var id3 = "cartoVectorTile";
1999
2009
  var DEFAULT_OPTIONS3 = {
2000
2010
  cartoVectorTile: {
@@ -2413,7 +2423,7 @@ function colorContinuous({ attr, domain, colors = DEFAULT_PALETTE, nullColor = N
2413
2423
  var DEFAULT_API_BASE_URL = "https://gcp-us-east1.api.carto.com";
2414
2424
  var DEFAULT_CLIENT = "deck-gl-carto";
2415
2425
  var V3_MINOR_VERSION = "3.4";
2416
- var MAX_GET_LENGTH = 8192;
2426
+ var DEFAULT_MAX_LENGTH_URL = 7e3;
2417
2427
 
2418
2428
  // dist/api/endpoints.js
2419
2429
  function joinPath(...args) {
@@ -2449,7 +2459,7 @@ var DEFAULT_HEADERS = {
2449
2459
  "Content-Type": "application/json"
2450
2460
  };
2451
2461
  var REQUEST_CACHE = /* @__PURE__ */ new Map();
2452
- async function requestWithParameters({ baseUrl, parameters = {}, headers: customHeaders = {}, errorContext }) {
2462
+ async function requestWithParameters({ baseUrl, parameters = {}, headers: customHeaders = {}, errorContext, maxLengthURL = DEFAULT_MAX_LENGTH_URL }) {
2453
2463
  parameters = { ...DEFAULT_PARAMETERS, ...parameters };
2454
2464
  baseUrl = excludeURLParameters(baseUrl, Object.keys(parameters));
2455
2465
  const key = createCacheKey(baseUrl, parameters, customHeaders);
@@ -2458,7 +2468,7 @@ async function requestWithParameters({ baseUrl, parameters = {}, headers: custom
2458
2468
  }
2459
2469
  const url = createURLWithParameters(baseUrl, parameters);
2460
2470
  const headers = { ...DEFAULT_HEADERS, ...customHeaders };
2461
- const fetchPromise = url.length > MAX_GET_LENGTH ? fetch(baseUrl, { method: "POST", body: JSON.stringify(parameters), headers }) : fetch(url, { headers });
2471
+ const fetchPromise = url.length > maxLengthURL ? fetch(baseUrl, { method: "POST", body: JSON.stringify(parameters), headers }) : fetch(url, { headers });
2462
2472
  let response;
2463
2473
  let responseJson;
2464
2474
  const jsonPromise = fetchPromise.then((_response) => {
@@ -2508,7 +2518,8 @@ var SOURCE_DEFAULTS = {
2508
2518
  apiBaseUrl: DEFAULT_API_BASE_URL,
2509
2519
  clientId: DEFAULT_CLIENT,
2510
2520
  format: "tilejson",
2511
- headers: {}
2521
+ headers: {},
2522
+ maxLengthURL: DEFAULT_MAX_LENGTH_URL
2512
2523
  };
2513
2524
  async function baseSource(endpoint, options, urlParameters) {
2514
2525
  const { accessToken, connectionName, cache, ...optionalOptions } = options;
@@ -2519,7 +2530,7 @@ async function baseSource(endpoint, options, urlParameters) {
2519
2530
  }
2520
2531
  }
2521
2532
  const baseUrl = buildSourceUrl(mergedOptions);
2522
- const { clientId, format } = mergedOptions;
2533
+ const { clientId, maxLengthURL, format } = mergedOptions;
2523
2534
  const headers = { Authorization: `Bearer ${options.accessToken}`, ...options.headers };
2524
2535
  const parameters = { client: clientId, ...urlParameters };
2525
2536
  const errorContext = {
@@ -2532,7 +2543,8 @@ async function baseSource(endpoint, options, urlParameters) {
2532
2543
  baseUrl,
2533
2544
  parameters,
2534
2545
  headers,
2535
- errorContext
2546
+ errorContext,
2547
+ maxLengthURL
2536
2548
  });
2537
2549
  const dataUrl = mapInstantiation[format].url[0];
2538
2550
  if (cache) {
@@ -2543,7 +2555,8 @@ async function baseSource(endpoint, options, urlParameters) {
2543
2555
  const json = await requestWithParameters({
2544
2556
  baseUrl: dataUrl,
2545
2557
  headers,
2546
- errorContext
2558
+ errorContext,
2559
+ maxLengthURL
2547
2560
  });
2548
2561
  if (accessToken) {
2549
2562
  json.accessToken = accessToken;
@@ -2553,7 +2566,8 @@ async function baseSource(endpoint, options, urlParameters) {
2553
2566
  return await requestWithParameters({
2554
2567
  baseUrl: dataUrl,
2555
2568
  headers,
2556
- errorContext
2569
+ errorContext,
2570
+ maxLengthURL
2557
2571
  });
2558
2572
  }
2559
2573
 
@@ -3412,7 +3426,7 @@ async function fetchBasemapProps({ config, errorContext, applyLayerFilters = tru
3412
3426
  }
3413
3427
 
3414
3428
  // dist/api/fetch-map.js
3415
- async function _fetchMapDataset(dataset, accessToken, apiBaseUrl, clientId, headers) {
3429
+ async function _fetchMapDataset(dataset, accessToken, apiBaseUrl, clientId, headers, maxLengthURL = DEFAULT_MAX_LENGTH_URL) {
3416
3430
  const { aggregationExp, aggregationResLevel, connectionName, columns, format, geoColumn, source, type, queryParameters } = dataset;
3417
3431
  const cache = {};
3418
3432
  const globalOptions = {
@@ -3422,7 +3436,8 @@ async function _fetchMapDataset(dataset, accessToken, apiBaseUrl, clientId, head
3422
3436
  clientId,
3423
3437
  connectionName,
3424
3438
  format,
3425
- headers
3439
+ headers,
3440
+ maxLengthURL
3426
3441
  };
3427
3442
  if (type === "tileset") {
3428
3443
  dataset.data = await vectorTilesetSource({ ...globalOptions, tableName: source });
@@ -3463,7 +3478,7 @@ async function _fetchMapDataset(dataset, accessToken, apiBaseUrl, clientId, head
3463
3478
  }
3464
3479
  return cacheChanged;
3465
3480
  }
3466
- async function _fetchTilestats(attribute, dataset, accessToken, apiBaseUrl) {
3481
+ async function _fetchTilestats(attribute, dataset, accessToken, apiBaseUrl, maxLengthURL = DEFAULT_MAX_LENGTH_URL) {
3467
3482
  const { connectionName, data, id: id4, source, type, queryParameters } = dataset;
3468
3483
  const errorContext = {
3469
3484
  requestType: "Tile stats",
@@ -3491,18 +3506,19 @@ async function _fetchTilestats(attribute, dataset, accessToken, apiBaseUrl) {
3491
3506
  baseUrl,
3492
3507
  headers,
3493
3508
  parameters,
3494
- errorContext
3509
+ errorContext,
3510
+ maxLengthURL
3495
3511
  });
3496
3512
  const { attributes } = data.tilestats.layers[0];
3497
3513
  const index = attributes.findIndex((d) => d.attribute === attribute);
3498
3514
  attributes[index] = stats;
3499
3515
  return true;
3500
3516
  }
3501
- async function fillInMapDatasets({ datasets, token }, clientId, apiBaseUrl, headers) {
3502
- const promises = datasets.map((dataset) => _fetchMapDataset(dataset, token, apiBaseUrl, clientId, headers));
3517
+ async function fillInMapDatasets({ datasets, token }, clientId, apiBaseUrl, headers, maxLengthURL = DEFAULT_MAX_LENGTH_URL) {
3518
+ const promises = datasets.map((dataset) => _fetchMapDataset(dataset, token, apiBaseUrl, clientId, headers, maxLengthURL));
3503
3519
  return await Promise.all(promises);
3504
3520
  }
3505
- async function fillInTileStats({ datasets, keplerMapConfig, token }, apiBaseUrl) {
3521
+ async function fillInTileStats({ datasets, keplerMapConfig, token }, apiBaseUrl, maxLengthURL = DEFAULT_MAX_LENGTH_URL) {
3506
3522
  var _a;
3507
3523
  const attributes = [];
3508
3524
  const { layers } = keplerMapConfig.config.visState;
@@ -3523,10 +3539,10 @@ async function fillInTileStats({ datasets, keplerMapConfig, token }, apiBaseUrl)
3523
3539
  filteredAttributes.push(a);
3524
3540
  }
3525
3541
  }
3526
- const promises = filteredAttributes.map(({ attribute, dataset }) => _fetchTilestats(attribute, dataset, token, apiBaseUrl));
3542
+ const promises = filteredAttributes.map(({ attribute, dataset }) => _fetchTilestats(attribute, dataset, token, apiBaseUrl, maxLengthURL));
3527
3543
  return await Promise.all(promises);
3528
3544
  }
3529
- async function fetchMap({ accessToken, apiBaseUrl = DEFAULT_API_BASE_URL, cartoMapId, clientId = DEFAULT_CLIENT, headers = {}, autoRefresh, onNewData }) {
3545
+ async function fetchMap({ accessToken, apiBaseUrl = DEFAULT_API_BASE_URL, cartoMapId, clientId = DEFAULT_CLIENT, headers = {}, autoRefresh, onNewData, maxLengthURL = DEFAULT_MAX_LENGTH_URL }) {
3530
3546
  assert(cartoMapId, 'Must define CARTO map id: fetchMap({cartoMapId: "XXXX-XXXX-XXXX"})');
3531
3547
  assert(apiBaseUrl, "Must define apiBaseUrl");
3532
3548
  if (accessToken) {
@@ -3539,14 +3555,14 @@ async function fetchMap({ accessToken, apiBaseUrl = DEFAULT_API_BASE_URL, cartoM
3539
3555
  }
3540
3556
  const baseUrl = buildPublicMapUrl({ apiBaseUrl, cartoMapId });
3541
3557
  const errorContext = { requestType: "Public map", mapId: cartoMapId };
3542
- const map = await requestWithParameters({ baseUrl, headers, errorContext });
3558
+ const map = await requestWithParameters({ baseUrl, headers, errorContext, maxLengthURL });
3543
3559
  let stopAutoRefresh;
3544
3560
  if (autoRefresh) {
3545
3561
  const intervalId = setInterval(async () => {
3546
3562
  const changed = await fillInMapDatasets(map, clientId, apiBaseUrl, {
3547
3563
  ...headers,
3548
3564
  "If-Modified-Since": new Date().toUTCString()
3549
- });
3565
+ }, maxLengthURL);
3550
3566
  if (onNewData && changed.some((v) => v === true)) {
3551
3567
  onNewData(parseMap(map));
3552
3568
  }
@@ -3568,9 +3584,9 @@ async function fetchMap({ accessToken, apiBaseUrl = DEFAULT_API_BASE_URL, cartoM
3568
3584
  });
3569
3585
  const [basemap] = await Promise.all([
3570
3586
  fetchBasemapProps({ config: map.keplerMapConfig.config, errorContext }),
3571
- fillInMapDatasets(map, clientId, apiBaseUrl, headers)
3587
+ fillInMapDatasets(map, clientId, apiBaseUrl, headers, maxLengthURL)
3572
3588
  ]);
3573
- await fillInTileStats(map, apiBaseUrl);
3589
+ await fillInTileStats(map, apiBaseUrl, maxLengthURL);
3574
3590
  const out = { ...parseMap(map), basemap, ...{ stopAutoRefresh } };
3575
3591
  const textLayers = out.layers.filter((layer) => {
3576
3592
  const pointType = layer.props.pointType || "";
@@ -3585,7 +3601,7 @@ async function fetchMap({ accessToken, apiBaseUrl = DEFAULT_API_BASE_URL, cartoM
3585
3601
 
3586
3602
  // dist/api/query.js
3587
3603
  var query = async function(options) {
3588
- const { apiBaseUrl = SOURCE_DEFAULTS.apiBaseUrl, clientId = SOURCE_DEFAULTS.clientId, connectionName, sqlQuery, queryParameters } = options;
3604
+ const { apiBaseUrl = SOURCE_DEFAULTS.apiBaseUrl, clientId = SOURCE_DEFAULTS.clientId, maxLengthURL = SOURCE_DEFAULTS.maxLengthURL, connectionName, sqlQuery, queryParameters } = options;
3589
3605
  const urlParameters = { q: sqlQuery };
3590
3606
  if (queryParameters) {
3591
3607
  urlParameters.queryParameters = JSON.stringify(queryParameters);
@@ -3603,7 +3619,8 @@ var query = async function(options) {
3603
3619
  baseUrl,
3604
3620
  parameters,
3605
3621
  headers,
3606
- errorContext
3622
+ errorContext,
3623
+ maxLengthURL
3607
3624
  });
3608
3625
  };
3609
3626