@carto/api-client 0.5.2-alpha.0 → 0.5.2-alpha.2

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 (65) hide show
  1. package/build/api-client.cjs +125 -14
  2. package/build/api-client.cjs.map +1 -1
  3. package/build/api-client.d.cts +47 -1
  4. package/build/api-client.d.ts +47 -1
  5. package/build/api-client.js +119 -14
  6. package/build/api-client.js.map +1 -1
  7. package/build/worker.js +28 -19
  8. package/build/worker.js.map +1 -1
  9. package/package.json +5 -4
  10. package/src/api/carto-api-error.ts +1 -1
  11. package/src/api/endpoints.ts +1 -1
  12. package/src/api/index.ts +2 -2
  13. package/src/api/query.ts +1 -1
  14. package/src/api/request-with-parameters.ts +2 -2
  15. package/src/deck/get-data-filter-extension-props.ts +3 -3
  16. package/src/fetch-map/basemap-styles.ts +2 -2
  17. package/src/fetch-map/basemap.ts +2 -2
  18. package/src/fetch-map/fetch-map.ts +3 -3
  19. package/src/fetch-map/layer-map.ts +82 -5
  20. package/src/fetch-map/parse-map.ts +71 -7
  21. package/src/fetch-map/source.ts +10 -10
  22. package/src/fetch-map/types.ts +7 -3
  23. package/src/filters/Filter.ts +4 -4
  24. package/src/filters/FilterTypes.ts +1 -1
  25. package/src/filters/geosjonFeatures.ts +3 -3
  26. package/src/filters/tileFeatures.ts +8 -3
  27. package/src/filters/tileFeaturesGeometries.ts +5 -5
  28. package/src/filters/tileFeaturesRaster.ts +3 -3
  29. package/src/filters/tileFeaturesSpatialIndex.ts +4 -4
  30. package/src/filters.ts +1 -1
  31. package/src/geo.ts +1 -1
  32. package/src/index.ts +3 -3
  33. package/src/models/model.ts +6 -3
  34. package/src/operations/aggregation.ts +14 -4
  35. package/src/operations/applySorting.ts +2 -2
  36. package/src/operations/groupBy.ts +2 -2
  37. package/src/operations/groupByDate.ts +2 -2
  38. package/src/operations/histogram.ts +2 -2
  39. package/src/operations/scatterPlot.ts +2 -2
  40. package/src/sources/base-source.ts +7 -4
  41. package/src/sources/boundary-query-source.ts +1 -1
  42. package/src/sources/h3-query-source.ts +1 -1
  43. package/src/sources/h3-table-source.ts +1 -1
  44. package/src/sources/h3-tileset-source.ts +1 -1
  45. package/src/sources/quadbin-query-source.ts +1 -1
  46. package/src/sources/quadbin-table-source.ts +1 -1
  47. package/src/sources/quadbin-tileset-source.ts +1 -1
  48. package/src/sources/raster-source.ts +1 -1
  49. package/src/sources/types.ts +7 -3
  50. package/src/sources/vector-query-source.ts +1 -1
  51. package/src/sources/vector-table-source.ts +1 -1
  52. package/src/sources/vector-tileset-source.ts +1 -1
  53. package/src/utils/getTileFormat.ts +1 -1
  54. package/src/utils/makeIntervalComplete.ts +1 -1
  55. package/src/utils/transformTileCoordsToWGS84.ts +1 -1
  56. package/src/utils/transformToTileCoords.ts +1 -1
  57. package/src/utils.ts +35 -0
  58. package/src/widget-sources/types.ts +5 -2
  59. package/src/widget-sources/widget-query-source.ts +4 -4
  60. package/src/widget-sources/widget-raster-source.ts +2 -2
  61. package/src/widget-sources/widget-remote-source.ts +4 -4
  62. package/src/widget-sources/widget-source.ts +3 -3
  63. package/src/widget-sources/widget-table-source.ts +4 -4
  64. package/src/widget-sources/widget-tileset-source-impl.ts +6 -5
  65. package/src/widget-sources/widget-tileset-source.ts +7 -7
@@ -5510,6 +5510,9 @@ __export(src_exports, {
5510
5510
  SOURCE_DEFAULTS: () => SOURCE_DEFAULTS,
5511
5511
  SpatialIndex: () => SpatialIndex,
5512
5512
  SpatialIndexColumn: () => SpatialIndexColumn,
5513
+ TEXT_LABEL_INDEX: () => TEXT_LABEL_INDEX,
5514
+ TEXT_NUMBER_FORMATTER: () => TEXT_NUMBER_FORMATTER,
5515
+ TEXT_OUTLINE_OPACITY: () => TEXT_OUTLINE_OPACITY,
5513
5516
  TileFormat: () => TileFormat,
5514
5517
  WidgetQuerySource: () => WidgetQuerySource,
5515
5518
  WidgetRasterSource: () => WidgetRasterSource,
@@ -5530,6 +5533,8 @@ __export(src_exports, {
5530
5533
  buildBinaryFeatureFilter: () => buildBinaryFeatureFilter,
5531
5534
  buildPublicMapUrl: () => buildPublicMapUrl,
5532
5535
  buildStatsUrl: () => buildStatsUrl,
5536
+ calculateClusterRadius: () => calculateClusterRadius,
5537
+ calculateClusterTextFontSize: () => calculateClusterTextFontSize,
5533
5538
  clearFilters: () => clearFilters,
5534
5539
  configureSource: () => configureSource,
5535
5540
  createPolygonSpatialFilter: () => createPolygonSpatialFilter,
@@ -5544,6 +5549,7 @@ __export(src_exports, {
5544
5549
  getColorValueAccessor: () => getColorValueAccessor,
5545
5550
  getColumnNameFromGeoColumn: () => getColumnNameFromGeoColumn,
5546
5551
  getDataFilterExtensionProps: () => getDataFilterExtensionProps,
5552
+ getDefaultAggregationExpColumnAliasForLayerType: () => getDefaultAggregationExpColumnAliasForLayerType,
5547
5553
  getFilter: () => getFilter,
5548
5554
  getIconUrlAccessor: () => getIconUrlAccessor,
5549
5555
  getLayerProps: () => getLayerProps,
@@ -11097,6 +11103,7 @@ function isValidBandValue(value, nodata) {
11097
11103
 
11098
11104
  // src/utils.ts
11099
11105
  init_cjs_shims();
11106
+ var FILTER_TYPES = new Set(Object.values(FilterType));
11100
11107
  function normalizeObjectKeys(el) {
11101
11108
  if (Array.isArray(el)) {
11102
11109
  return el.map((value) => normalizeObjectKeys(value));
@@ -11518,7 +11525,7 @@ async function baseSource(endpoint, options, urlParameters) {
11518
11525
  type: endpoint,
11519
11526
  source: JSON.stringify(parameters, void 0, 2)
11520
11527
  };
11521
- const mapInstantiation = await requestWithParameters({
11528
+ const { tilejson, schema } = await requestWithParameters({
11522
11529
  baseUrl,
11523
11530
  parameters,
11524
11531
  headers,
@@ -11526,7 +11533,7 @@ async function baseSource(endpoint, options, urlParameters) {
11526
11533
  maxLengthURL,
11527
11534
  localCache
11528
11535
  });
11529
- const dataUrl = mapInstantiation.tilejson.url[0];
11536
+ const dataUrl = tilejson.url[0];
11530
11537
  if (cache) {
11531
11538
  cache.value = parseInt(
11532
11539
  new URL(dataUrl).searchParams.get("cache") || "",
@@ -11545,6 +11552,9 @@ async function baseSource(endpoint, options, urlParameters) {
11545
11552
  if (accessToken) {
11546
11553
  json.accessToken = accessToken;
11547
11554
  }
11555
+ if (schema) {
11556
+ json.schema = schema;
11557
+ }
11548
11558
  return json;
11549
11559
  }
11550
11560
 
@@ -11785,8 +11795,8 @@ function objectToURLSearchParams(object) {
11785
11795
 
11786
11796
  // src/filters.ts
11787
11797
  init_cjs_shims();
11788
- var FILTER_TYPES = new Set(Object.values(FilterType));
11789
- var isFilterType = (type) => FILTER_TYPES.has(type);
11798
+ var FILTER_TYPES2 = new Set(Object.values(FilterType));
11799
+ var isFilterType = (type) => FILTER_TYPES2.has(type);
11790
11800
  function addFilter(filters, { column, type, values, owner }) {
11791
11801
  if (!filters[column]) {
11792
11802
  filters[column] = {};
@@ -11801,7 +11811,7 @@ function removeFilter(filters, { column, owner }) {
11801
11811
  return filters;
11802
11812
  }
11803
11813
  if (owner) {
11804
- for (const type of FILTER_TYPES) {
11814
+ for (const type of FILTER_TYPES2) {
11805
11815
  if (owner === filter[type]?.owner) {
11806
11816
  delete filter[type];
11807
11817
  }
@@ -11826,7 +11836,7 @@ function hasFilter(filters, { column, owner }) {
11826
11836
  if (!owner) {
11827
11837
  return true;
11828
11838
  }
11829
- for (const type of FILTER_TYPES) {
11839
+ for (const type of FILTER_TYPES2) {
11830
11840
  if (owner === filter[type]?.owner) {
11831
11841
  return true;
11832
11842
  }
@@ -12195,7 +12205,11 @@ function min(values, keys, joinOperation) {
12195
12205
  Infinity
12196
12206
  );
12197
12207
  }
12198
- return Math.min(...values);
12208
+ let min3 = Number.POSITIVE_INFINITY;
12209
+ for (const value of values) {
12210
+ min3 = Math.min(min3, value);
12211
+ }
12212
+ return min3;
12199
12213
  }
12200
12214
  function max(values, keys, joinOperation) {
12201
12215
  const normalizedKeys = normalizeKeys(keys);
@@ -12205,7 +12219,11 @@ function max(values, keys, joinOperation) {
12205
12219
  -Infinity
12206
12220
  );
12207
12221
  }
12208
- return Math.max(...values);
12222
+ let max3 = Number.NEGATIVE_INFINITY;
12223
+ for (const value of values) {
12224
+ max3 = Math.max(max3, value);
12225
+ }
12226
+ return max3;
12209
12227
  }
12210
12228
  function normalizeKeys(keys) {
12211
12229
  return Array.isArray(keys) ? keys : typeof keys === "string" ? [keys] : void 0;
@@ -14557,7 +14575,8 @@ var customMarkersPropsMap = {
14557
14575
  var heatmapTilePropsMap = {
14558
14576
  visConfig: {
14559
14577
  colorRange: (x) => ({ colorRange: x.colors.map(hexToRGBA) }),
14560
- radius: "radiusPixels"
14578
+ radius: (radius) => ({ radiusPixels: 20 + radius }),
14579
+ opacity: "opacity"
14561
14580
  }
14562
14581
  };
14563
14582
  var defaultProps = {
@@ -14578,6 +14597,12 @@ var deprecatedLayerTypes = [
14578
14597
  "hexagonId",
14579
14598
  "point"
14580
14599
  ];
14600
+ var TEXT_LABEL_INDEX = 0;
14601
+ var TEXT_OUTLINE_OPACITY = 64;
14602
+ var TEXT_NUMBER_FORMATTER = new Intl.NumberFormat("en-US", {
14603
+ maximumFractionDigits: 2,
14604
+ notation: "compact"
14605
+ });
14581
14606
  function getLayerProps(type, config2, dataset) {
14582
14607
  if (deprecatedLayerTypes.includes(type)) {
14583
14608
  throw new Error(
@@ -14669,9 +14694,7 @@ function findAccessorKey(keys, properties) {
14669
14694
  return [key];
14670
14695
  }
14671
14696
  }
14672
- throw new Error(
14673
- `Could not find property for any accessor key: ${keys.join(", ")}`
14674
- );
14697
+ return keys;
14675
14698
  }
14676
14699
  function getColorValueAccessor({ name }, colorAggregation, data) {
14677
14700
  const aggregator = AGGREGATION_FUNC[colorAggregation];
@@ -14798,6 +14821,40 @@ function getTextAccessor({ name, type }, data) {
14798
14821
  };
14799
14822
  return normalizeAccessor(accessor, data);
14800
14823
  }
14824
+ function calculateClusterRadius(properties, stats, radiusRange, column) {
14825
+ const { min: min3, max: max3 } = stats[column];
14826
+ const value = properties[column];
14827
+ if (min3 === max3) return radiusRange[1];
14828
+ const normalizedValue = (value - min3) / (max3 - min3);
14829
+ return radiusRange[0] + normalizedValue * (radiusRange[1] - radiusRange[0]);
14830
+ }
14831
+ function getDefaultAggregationExpColumnAliasForLayerType(layerType, provider, schema) {
14832
+ if (schema && layerType === "clusterTile") {
14833
+ return getColumnAliasForAggregationExp(
14834
+ getDefaultColumnFromSchemaForAggregationExp(schema),
14835
+ "count",
14836
+ provider
14837
+ );
14838
+ } else {
14839
+ return DEFAULT_AGGREGATION_EXP_ALIAS;
14840
+ }
14841
+ }
14842
+ function getColumnAliasForAggregationExp(name, aggregation, provider) {
14843
+ const columnAlias = `${name}_${aggregation}`;
14844
+ return provider === "snowflake" ? columnAlias.toUpperCase() : columnAlias;
14845
+ }
14846
+ function getDefaultColumnFromSchemaForAggregationExp(schema) {
14847
+ return schema ? schema[0].name : "";
14848
+ }
14849
+ function calculateClusterTextFontSize(radius) {
14850
+ if (radius >= 80) return 24;
14851
+ if (radius >= 72) return 24;
14852
+ if (radius >= 56) return 20;
14853
+ if (radius >= 40) return 16;
14854
+ if (radius >= 24) return 13;
14855
+ if (radius >= 8) return 11;
14856
+ return 11;
14857
+ }
14801
14858
 
14802
14859
  // src/fetch-map/parse-map.ts
14803
14860
  function parseMap(json) {
@@ -14838,7 +14895,14 @@ function parseMap(json) {
14838
14895
  ...defaultProps2,
14839
14896
  ...createInteractionProps(interactionConfig),
14840
14897
  ...styleProps,
14841
- ...createChannelProps(id, type, config3, visualChannels, data),
14898
+ ...createChannelProps(
14899
+ id,
14900
+ type,
14901
+ config3,
14902
+ visualChannels,
14903
+ data,
14904
+ dataset
14905
+ ),
14842
14906
  // Must come after style
14843
14907
  ...createParametersProp(
14844
14908
  layerBlending,
@@ -14913,7 +14977,7 @@ function createStyleProps(config2, mapping) {
14913
14977
  result.highlightColor = config2.visConfig.enable3d ? [255, 255, 255, 60] : [252, 242, 26, 255];
14914
14978
  return result;
14915
14979
  }
14916
- function createChannelProps(id, type, config2, visualChannels, data) {
14980
+ function createChannelProps(id, type, config2, visualChannels, data, dataset) {
14917
14981
  const {
14918
14982
  colorField,
14919
14983
  colorScale,
@@ -14973,6 +15037,47 @@ function createChannelProps(id, type, config2, visualChannels, data) {
14973
15037
  };
14974
15038
  }
14975
15039
  }
15040
+ if (type === "clusterTile") {
15041
+ const aggregationExpAlias = getDefaultAggregationExpColumnAliasForLayerType(
15042
+ type,
15043
+ dataset.providerId,
15044
+ data.schema
15045
+ );
15046
+ result.pointType = visConfig.isTextVisible ? "circle+text" : "circle";
15047
+ result.clusterLevel = visConfig.clusterLevel;
15048
+ result.getWeight = (d) => {
15049
+ return d.properties[aggregationExpAlias];
15050
+ };
15051
+ result.getPointRadius = (d, info) => {
15052
+ return calculateClusterRadius(
15053
+ d.properties,
15054
+ info.data.attributes.stats,
15055
+ visConfig.radiusRange,
15056
+ aggregationExpAlias
15057
+ );
15058
+ };
15059
+ result.textCharacterSet = "auto";
15060
+ result.textFontFamily = "Inter, sans";
15061
+ result.textFontSettings = { sdf: true };
15062
+ result.textFontWeight = 600;
15063
+ result.getText = (d) => TEXT_NUMBER_FORMATTER.format(d.properties[aggregationExpAlias]);
15064
+ result.getTextColor = config2.textLabel[TEXT_LABEL_INDEX].color;
15065
+ result.textOutlineColor = [
15066
+ ...config2.textLabel[TEXT_LABEL_INDEX].outlineColor,
15067
+ TEXT_OUTLINE_OPACITY
15068
+ ];
15069
+ result.textOutlineWidth = 5;
15070
+ result.textSizeUnits = "pixels";
15071
+ result.getTextSize = (d, info) => {
15072
+ const radius = calculateClusterRadius(
15073
+ d.properties,
15074
+ info.data.attributes.stats,
15075
+ visConfig.radiusRange,
15076
+ aggregationExpAlias
15077
+ );
15078
+ return calculateClusterTextFontSize(radius);
15079
+ };
15080
+ }
14976
15081
  if (radiusField || sizeField) {
14977
15082
  result.getPointRadius = getSizeAccessor(
14978
15083
  // @ts-ignore
@@ -15691,6 +15796,9 @@ function _getHexagonResolution(viewport, tileSize) {
15691
15796
  SOURCE_DEFAULTS,
15692
15797
  SpatialIndex,
15693
15798
  SpatialIndexColumn,
15799
+ TEXT_LABEL_INDEX,
15800
+ TEXT_NUMBER_FORMATTER,
15801
+ TEXT_OUTLINE_OPACITY,
15694
15802
  TileFormat,
15695
15803
  WidgetQuerySource,
15696
15804
  WidgetRasterSource,
@@ -15711,6 +15819,8 @@ function _getHexagonResolution(viewport, tileSize) {
15711
15819
  buildBinaryFeatureFilter,
15712
15820
  buildPublicMapUrl,
15713
15821
  buildStatsUrl,
15822
+ calculateClusterRadius,
15823
+ calculateClusterTextFontSize,
15714
15824
  clearFilters,
15715
15825
  configureSource,
15716
15826
  createPolygonSpatialFilter,
@@ -15725,6 +15835,7 @@ function _getHexagonResolution(viewport, tileSize) {
15725
15835
  getColorValueAccessor,
15726
15836
  getColumnNameFromGeoColumn,
15727
15837
  getDataFilterExtensionProps,
15838
+ getDefaultAggregationExpColumnAliasForLayerType,
15728
15839
  getFilter,
15729
15840
  getIconUrlAccessor,
15730
15841
  getLayerProps,