@carto/api-client 0.5.15-alpha.raster-0 → 0.5.15-alpha.raster-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.
@@ -126,11 +126,13 @@ __export(src_exports, {
126
126
  WidgetTableSource: () => WidgetTableSource,
127
127
  WidgetTilesetSource: () => WidgetTilesetSource,
128
128
  _ErrorCode: () => ErrorCode,
129
+ _applyLayerGroupFilters: () => applyLayerGroupFilters,
129
130
  _buildFeatureFilter: () => _buildFeatureFilter,
130
131
  _createVecExprEvaluator: () => createVecExprEvaluator,
131
132
  _domainFromValues: () => domainFromValues,
132
133
  _evaluateVecExpr: () => evaluateVecExpr,
133
134
  _getHexagonResolution: () => _getHexagonResolution,
135
+ _getLog10ScaleSteps: () => getLog10ScaleSteps,
134
136
  _getRasterTileLayerStyleProps: () => getRasterTileLayerStyleProps,
135
137
  _validateVecExprSyntax: () => validateVecExprSyntax,
136
138
  addFilter: () => addFilter,
@@ -9492,6 +9494,37 @@ function formatDate(value) {
9492
9494
  function formatTimestamp(value) {
9493
9495
  return String(Math.floor(new Date(value).getTime() / 1e3));
9494
9496
  }
9497
+ function roundedPow10(exp) {
9498
+ const raw = Math.pow(10, exp);
9499
+ if (exp < 0) {
9500
+ const shift = Math.pow(10, -exp);
9501
+ return Math.round(raw * shift) / shift;
9502
+ }
9503
+ return raw;
9504
+ }
9505
+ function getLog10ScaleSteps({
9506
+ min: min2,
9507
+ max: max2,
9508
+ steps
9509
+ }) {
9510
+ if (min2 === 0) {
9511
+ if (max2 === Infinity) {
9512
+ return [...Array(steps - 1)].map((_v, i) => roundedPow10(i + 1));
9513
+ }
9514
+ const maxLog = Math.log10(max2);
9515
+ const endExponent = Math.ceil(maxLog);
9516
+ const startExponent = endExponent - steps + 1;
9517
+ return [...Array(steps - 1)].map(
9518
+ (_v, i) => roundedPow10(startExponent + i)
9519
+ );
9520
+ } else {
9521
+ const minLog = Math.log10(min2);
9522
+ const startExponent = Math.ceil(minLog) === minLog ? minLog + 1 : Math.ceil(minLog);
9523
+ return [...Array(steps - 1)].map(
9524
+ (_v, i) => roundedPow10(startExponent + i)
9525
+ );
9526
+ }
9527
+ }
9495
9528
 
9496
9529
  // src/fetch-map/layer-map.ts
9497
9530
  var SCALE_FUNCS = {
@@ -9615,6 +9648,13 @@ function getLayerProps(type, config2, dataset) {
9615
9648
  };
9616
9649
  }
9617
9650
  function domainFromAttribute(attribute, scaleType, scaleLength) {
9651
+ if (scaleType === "log10steps" && attribute.min !== void 0 && attribute.max !== void 0) {
9652
+ return getLog10ScaleSteps({
9653
+ min: attribute.min,
9654
+ max: attribute.max,
9655
+ steps: scaleLength
9656
+ });
9657
+ }
9618
9658
  if (scaleType === "ordinal" || scaleType === "point") {
9619
9659
  if (!attribute.categories) {
9620
9660
  return [0, 1];
@@ -9622,13 +9662,13 @@ function domainFromAttribute(attribute, scaleType, scaleLength) {
9622
9662
  return attribute.categories.map((c) => c.category).filter((c) => c !== void 0 && c !== null);
9623
9663
  }
9624
9664
  if (scaleType === "quantile" && attribute.quantiles) {
9625
- return attribute.quantiles.global ? attribute.quantiles.global[scaleLength] : attribute.quantiles[scaleLength];
9665
+ return "global" in attribute.quantiles ? attribute.quantiles.global[scaleLength] : attribute.quantiles[scaleLength];
9626
9666
  }
9627
9667
  let { min: min2 } = attribute;
9628
9668
  if (scaleType === "log" && min2 === 0) {
9629
9669
  min2 = 1e-5;
9630
9670
  }
9631
- return [min2, attribute.max];
9671
+ return [min2 ?? 0, attribute.max ?? 1];
9632
9672
  }
9633
9673
  function domainFromValues(values, scaleType) {
9634
9674
  if (scaleType === "ordinal" || scaleType === "point") {
@@ -9649,7 +9689,9 @@ function calculateDomain(data, name, scaleType, scaleLength) {
9649
9689
  if (data.tilestats) {
9650
9690
  const { attributes } = data.tilestats.layers[0];
9651
9691
  const attribute = attributes.find((a) => a.attribute === name);
9652
- return domainFromAttribute(attribute, scaleType, scaleLength);
9692
+ if (attribute) {
9693
+ return domainFromAttribute(attribute, scaleType, scaleLength);
9694
+ }
9653
9695
  }
9654
9696
  return [0, 1];
9655
9697
  }
@@ -9708,17 +9750,21 @@ function getColorAccessor({ name, colorColumn }, scaleType, { aggregation, range
9708
9750
  function calculateLayerScale(name, scaleType, range, data) {
9709
9751
  let domain = [];
9710
9752
  let scaleColor = [];
9711
- if (scaleType !== "identity") {
9712
- const { colorMap, colors } = range;
9713
- if (Array.isArray(colorMap)) {
9753
+ const { colors } = range;
9754
+ if (scaleType === "custom") {
9755
+ if (range.uiCustomScaleType === "logarithmic") {
9756
+ domain = calculateDomain(data, name, "log10steps", colors.length);
9757
+ scaleColor = colors;
9758
+ } else if (range.colorMap) {
9759
+ const { colorMap } = range;
9714
9760
  colorMap.forEach(([value, color2]) => {
9715
9761
  domain.push(value);
9716
9762
  scaleColor.push(color2);
9717
9763
  });
9718
- } else {
9719
- domain = calculateDomain(data, name, scaleType, colors.length);
9720
- scaleColor = colors;
9721
9764
  }
9765
+ } else if (scaleType !== "identity") {
9766
+ domain = calculateDomain(data, name, scaleType, colors.length);
9767
+ scaleColor = colors;
9722
9768
  if (scaleType === "ordinal") {
9723
9769
  domain = domain.slice(0, scaleColor.length);
9724
9770
  }
@@ -10099,10 +10145,11 @@ function domainFromRasterMetadataBand(band, scaleType, colorRange) {
10099
10145
  }
10100
10146
  if (scaleType === "custom") {
10101
10147
  if (colorRange.uiCustomScaleType === "logarithmic") {
10102
- if (colorRange.colorMap) {
10103
- return colorRange.colorMap?.map(([value]) => value) || [];
10104
- }
10105
- return [band.stats.min, band.stats.max];
10148
+ return getLog10ScaleSteps({
10149
+ min: band.stats.min,
10150
+ max: band.stats.max,
10151
+ steps: colorRange.colors.length
10152
+ });
10106
10153
  } else {
10107
10154
  return colorRange.colorMap?.map(([value]) => value) || [];
10108
10155
  }
@@ -10364,15 +10411,24 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
10364
10411
  radiusScale,
10365
10412
  strokeColorField,
10366
10413
  strokeColorScale,
10414
+ sizeField: strokeWidthField,
10415
+ sizeScale: strokeWidthScale,
10367
10416
  weightField
10368
10417
  } = visualChannels;
10369
10418
  if (layerType === "raster") {
10419
+ const rasterMetadata = data.raster_metadata;
10420
+ if (!rasterMetadata) {
10421
+ return {
10422
+ channelProps: {},
10423
+ scales: {}
10424
+ };
10425
+ }
10370
10426
  const rasterStyleType = config2.visConfig.rasterStyleType;
10371
10427
  if (rasterStyleType === "Rgb") {
10372
10428
  return {
10373
10429
  channelProps: getRasterTileLayerStylePropsRgb({
10374
10430
  layerConfig: config2,
10375
- rasterMetadata: data.raster_metadata,
10431
+ rasterMetadata,
10376
10432
  visualChannels
10377
10433
  }),
10378
10434
  scales: {}
@@ -10382,7 +10438,7 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
10382
10438
  channelProps: getRasterTileLayerStylePropsScaledBand({
10383
10439
  layerConfig: config2,
10384
10440
  visualChannels,
10385
- rasterMetadata: data.raster_metadata
10441
+ rasterMetadata
10386
10442
  }),
10387
10443
  scales: {
10388
10444
  ...colorField && {
@@ -10503,6 +10559,21 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
10503
10559
  ...domainAndRangeFromScale(scale2)
10504
10560
  };
10505
10561
  }
10562
+ if (strokeWidthField) {
10563
+ const { accessor, scale: scale2 } = getSizeAccessor(
10564
+ strokeWidthField,
10565
+ strokeWidthScale,
10566
+ visConfig.sizeAggregation,
10567
+ visConfig.sizeRange,
10568
+ data
10569
+ );
10570
+ result.getLineWidth = accessor;
10571
+ scales.lineWidth = updateTriggers.getLineWidth = {
10572
+ field: strokeWidthField,
10573
+ type: strokeWidthScale || "identity",
10574
+ ...domainAndRangeFromScale(scale2)
10575
+ };
10576
+ }
10506
10577
  if (heightField && visConfig.enable3d) {
10507
10578
  const { accessor, scale: scale2 } = getSizeAccessor(
10508
10579
  heightField,
@@ -11293,11 +11364,13 @@ function hashBuckets(initialCount) {
11293
11364
  WidgetTableSource,
11294
11365
  WidgetTilesetSource,
11295
11366
  _ErrorCode,
11367
+ _applyLayerGroupFilters,
11296
11368
  _buildFeatureFilter,
11297
11369
  _createVecExprEvaluator,
11298
11370
  _domainFromValues,
11299
11371
  _evaluateVecExpr,
11300
11372
  _getHexagonResolution,
11373
+ _getLog10ScaleSteps,
11301
11374
  _getRasterTileLayerStyleProps,
11302
11375
  _validateVecExprSyntax,
11303
11376
  addFilter,