@carto/api-client 0.5.31 → 0.5.32-alpha.307c0b4.122

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 CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ - feat(fetchMap): Support line & polygon stroke dash styles (#297)
6
+
5
7
  ### 0.5.31
6
8
 
7
9
  - feat(sources): rename `featureBbox` source option to `prepareLabels` (Maps API `featureBbox` param unchanged)
@@ -176,6 +176,7 @@ __export(src_exports, {
176
176
  getIconUrlAccessor: () => getIconUrlAccessor,
177
177
  getLayerDescriptor: () => getLayerDescriptor,
178
178
  getLayerProps: () => getLayerProps,
179
+ getLineStyleAccessor: () => getLineStyleAccessor,
179
180
  getMaxMarkerSize: () => getMaxMarkerSize,
180
181
  getSizeAccessor: () => getSizeAccessor,
181
182
  getSorter: () => getSorter,
@@ -10150,6 +10151,19 @@ function getIconUrlAccessor(field, range, {
10150
10151
  };
10151
10152
  return normalizeAccessor(accessor, data);
10152
10153
  }
10154
+ function getLineStyleAccessor(field, range, data) {
10155
+ const fallback = range.othersDashArray ?? [0, 0];
10156
+ const mapping = {};
10157
+ for (const { value, dashArray } of range.dashArrayMap) {
10158
+ mapping[value] = dashArray;
10159
+ }
10160
+ const accessor = (properties) => mapping[properties[field.name]] ?? fallback;
10161
+ return {
10162
+ accessor: normalizeAccessor(accessor, data),
10163
+ domain: range.dashArrayMap.map(({ value }) => value),
10164
+ range: range.dashArrayMap.map(({ dashArray }) => dashArray)
10165
+ };
10166
+ }
10153
10167
  function getMaxMarkerSize(visConfig, visualChannels) {
10154
10168
  const { radiusRange, radius, sizeMaxPixels } = visConfig;
10155
10169
  const { radiusField, sizeField } = visualChannels;
@@ -10863,6 +10877,10 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
10863
10877
  const result = {};
10864
10878
  const updateTriggers = {};
10865
10879
  const scales = {};
10880
+ const isVectorTile = layerType === "mvt" || layerType === "tileset";
10881
+ const geometry = data.tilestats?.layers?.[0]?.geometry;
10882
+ const isLine = geometry === "Line" || geometry === "LineString" || geometry === "MultiLineString";
10883
+ const isPolygon = geometry === "Polygon" || geometry === "MultiPolygon";
10866
10884
  {
10867
10885
  const { colorField, colorScale } = visualChannels;
10868
10886
  const { colorRange } = visConfig;
@@ -11023,6 +11041,43 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
11023
11041
  };
11024
11042
  }
11025
11043
  }
11044
+ {
11045
+ const strokeVisible = isLine || isPolygon && Boolean(visConfig.stroked);
11046
+ if (isVectorTile && strokeVisible) {
11047
+ const { lineStyleField, lineStyleScale } = visualChannels;
11048
+ const { lineStyleRange } = visConfig;
11049
+ if (visConfig.lineStyle && visConfig.lineStyle !== "solid") {
11050
+ if (visConfig.lineStyle === "dotted") {
11051
+ result.lineCapRounded = true;
11052
+ }
11053
+ result.lineStyle = visConfig.lineStyle;
11054
+ if (visConfig.dashArray) {
11055
+ result.dashArray = visConfig.dashArray;
11056
+ result.getDashArray = visConfig.dashArray;
11057
+ }
11058
+ }
11059
+ if (lineStyleField && lineStyleScale && lineStyleRange) {
11060
+ const { accessor, ...scaleProps } = getLineStyleAccessor(
11061
+ lineStyleField,
11062
+ lineStyleRange,
11063
+ data
11064
+ );
11065
+ result.getDashArray = accessor;
11066
+ scales.lineStyle = updateTriggers.getDashArray = {
11067
+ field: lineStyleField,
11068
+ type: lineStyleScale,
11069
+ ...scaleProps
11070
+ };
11071
+ const dashArrays = [
11072
+ ...lineStyleRange.dashArrayMap.map(({ dashArray }) => dashArray),
11073
+ ...lineStyleRange.othersDashArray ? [lineStyleRange.othersDashArray] : []
11074
+ ];
11075
+ if (dashArrays.some(([dash]) => dash === 0)) {
11076
+ result.lineCapRounded = true;
11077
+ }
11078
+ }
11079
+ }
11080
+ }
11026
11081
  {
11027
11082
  const { heightField, heightScale } = visualChannels;
11028
11083
  const { enable3d, heightRange } = visConfig;
@@ -11151,9 +11206,7 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
11151
11206
  } = secondaryLabel || {};
11152
11207
  result.getText = mainLabel.field && getTextAccessor(mainLabel.field, data);
11153
11208
  const getSecondaryText = secondaryField && getTextAccessor(secondaryField, data);
11154
- const geometry = data.tilestats?.layers?.[0]?.geometry;
11155
- const isLineOrPolygon = geometry === "Polygon" || geometry === "MultiPolygon" || geometry === "Line" || geometry === "LineString" || geometry === "MultiLineString";
11156
- if (isLineOrPolygon && (layerType === "tileset" || layerType === "mvt")) {
11209
+ if ((isLine || isPolygon) && isVectorTile) {
11157
11210
  const uniqueIdProperty = visConfig.textLabelUniqueIdField;
11158
11211
  result.autoLabels = uniqueIdProperty ? { uniqueIdProperty } : true;
11159
11212
  result.pointType = "text";
@@ -11939,6 +11992,7 @@ function hashBuckets(initialCount) {
11939
11992
  getIconUrlAccessor,
11940
11993
  getLayerDescriptor,
11941
11994
  getLayerProps,
11995
+ getLineStyleAccessor,
11942
11996
  getMaxMarkerSize,
11943
11997
  getSizeAccessor,
11944
11998
  getSorter,