@carto/api-client 0.5.27 → 0.5.29
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 +11 -0
- package/build/api-client.cjs +63 -6
- package/build/api-client.cjs.map +1 -1
- package/build/api-client.d.cts +24 -2
- package/build/api-client.d.ts +24 -2
- package/build/api-client.js +63 -6
- package/build/api-client.js.map +1 -1
- package/package.json +1 -1
- package/src/fetch-map/fetch-map.ts +22 -0
- package/src/fetch-map/layer-map.ts +3 -2
- package/src/fetch-map/parse-map.ts +51 -1
- package/src/fetch-map/source.ts +2 -0
- package/src/fetch-map/types.ts +7 -0
- package/src/sources/vector-query-source.ts +14 -1
- package/src/sources/vector-table-source.ts +14 -1
package/build/api-client.d.cts
CHANGED
|
@@ -882,6 +882,10 @@ type VisConfig = {
|
|
|
882
882
|
radiusAggregation?: string;
|
|
883
883
|
radiusAggregationExp?: string;
|
|
884
884
|
radiusAggregationDomain?: [number, number];
|
|
885
|
+
sizeMinPixels?: number;
|
|
886
|
+
sizeMaxPixels?: number;
|
|
887
|
+
radiusScaleWithZoom?: boolean;
|
|
888
|
+
radiusReferenceZoom?: number;
|
|
885
889
|
sizeAggregation?: string;
|
|
886
890
|
sizeAggregationExp?: string;
|
|
887
891
|
sizeAggregationDomain?: [number, number];
|
|
@@ -903,6 +907,7 @@ type VisConfig = {
|
|
|
903
907
|
rasterStyleType?: 'Rgb' | 'ColorRange' | 'UniqueValues';
|
|
904
908
|
colorBands?: RasterLayerConfigColorBand[];
|
|
905
909
|
uniqueValuesColorRange?: ColorRange;
|
|
910
|
+
textLabelUniqueIdField?: string | null;
|
|
906
911
|
};
|
|
907
912
|
type TextLabel = {
|
|
908
913
|
field: VisualChannelField | null | undefined;
|
|
@@ -1035,6 +1040,7 @@ type Dataset = {
|
|
|
1035
1040
|
name?: string | null;
|
|
1036
1041
|
spatialIndex?: string | null;
|
|
1037
1042
|
exportToBucketAvailable?: boolean;
|
|
1043
|
+
featureBbox?: boolean;
|
|
1038
1044
|
};
|
|
1039
1045
|
|
|
1040
1046
|
type StyleLayerGroupSlug = 'label' | 'road' | 'border' | 'building' | 'water' | 'land';
|
|
@@ -1988,11 +1994,27 @@ type VectorTilesetSourceOptions = SourceOptions & TilesetSourceOptions;
|
|
|
1988
1994
|
type VectorTilesetSourceResponse = TilejsonResult & WidgetTilesetSourceResult;
|
|
1989
1995
|
declare const vectorTilesetSource: (options: VectorTilesetSourceOptions) => Promise<VectorTilesetSourceResponse>;
|
|
1990
1996
|
|
|
1991
|
-
type VectorTableSourceOptions = SourceOptions & TableSourceOptions & FilterOptions & ColumnsOption
|
|
1997
|
+
type VectorTableSourceOptions = SourceOptions & TableSourceOptions & FilterOptions & ColumnsOption & {
|
|
1998
|
+
/**
|
|
1999
|
+
* If `true`, the server includes a `_carto_bbox` property on each polygon
|
|
2000
|
+
* feature, containing the bounding box of the full (unclipped) geometry as
|
|
2001
|
+
* a `"west,south,east,north"` string in WGS84. Used by clients to compute
|
|
2002
|
+
* stable label positions for polygons that span multiple tiles.
|
|
2003
|
+
*/
|
|
2004
|
+
featureBbox?: boolean;
|
|
2005
|
+
};
|
|
1992
2006
|
type VectorTableSourceResponse = TilejsonResult & WidgetTableSourceResult;
|
|
1993
2007
|
declare const vectorTableSource: (options: VectorTableSourceOptions) => Promise<VectorTableSourceResponse>;
|
|
1994
2008
|
|
|
1995
|
-
type VectorQuerySourceOptions = SourceOptions & QuerySourceOptions & FilterOptions & ColumnsOption
|
|
2009
|
+
type VectorQuerySourceOptions = SourceOptions & QuerySourceOptions & FilterOptions & ColumnsOption & {
|
|
2010
|
+
/**
|
|
2011
|
+
* If `true`, the server includes a `_carto_bbox` property on each polygon
|
|
2012
|
+
* feature, containing the bounding box of the full (unclipped) geometry as
|
|
2013
|
+
* a `"west,south,east,north"` string in WGS84. Used by clients to compute
|
|
2014
|
+
* stable label positions for polygons that span multiple tiles.
|
|
2015
|
+
*/
|
|
2016
|
+
featureBbox?: boolean;
|
|
2017
|
+
};
|
|
1996
2018
|
type VectorQuerySourceResponse = TilejsonResult & WidgetQuerySourceResult;
|
|
1997
2019
|
declare const vectorQuerySource: (options: VectorQuerySourceOptions) => Promise<VectorQuerySourceResponse>;
|
|
1998
2020
|
|
package/build/api-client.d.ts
CHANGED
|
@@ -882,6 +882,10 @@ type VisConfig = {
|
|
|
882
882
|
radiusAggregation?: string;
|
|
883
883
|
radiusAggregationExp?: string;
|
|
884
884
|
radiusAggregationDomain?: [number, number];
|
|
885
|
+
sizeMinPixels?: number;
|
|
886
|
+
sizeMaxPixels?: number;
|
|
887
|
+
radiusScaleWithZoom?: boolean;
|
|
888
|
+
radiusReferenceZoom?: number;
|
|
885
889
|
sizeAggregation?: string;
|
|
886
890
|
sizeAggregationExp?: string;
|
|
887
891
|
sizeAggregationDomain?: [number, number];
|
|
@@ -903,6 +907,7 @@ type VisConfig = {
|
|
|
903
907
|
rasterStyleType?: 'Rgb' | 'ColorRange' | 'UniqueValues';
|
|
904
908
|
colorBands?: RasterLayerConfigColorBand[];
|
|
905
909
|
uniqueValuesColorRange?: ColorRange;
|
|
910
|
+
textLabelUniqueIdField?: string | null;
|
|
906
911
|
};
|
|
907
912
|
type TextLabel = {
|
|
908
913
|
field: VisualChannelField | null | undefined;
|
|
@@ -1035,6 +1040,7 @@ type Dataset = {
|
|
|
1035
1040
|
name?: string | null;
|
|
1036
1041
|
spatialIndex?: string | null;
|
|
1037
1042
|
exportToBucketAvailable?: boolean;
|
|
1043
|
+
featureBbox?: boolean;
|
|
1038
1044
|
};
|
|
1039
1045
|
|
|
1040
1046
|
type StyleLayerGroupSlug = 'label' | 'road' | 'border' | 'building' | 'water' | 'land';
|
|
@@ -1988,11 +1994,27 @@ type VectorTilesetSourceOptions = SourceOptions & TilesetSourceOptions;
|
|
|
1988
1994
|
type VectorTilesetSourceResponse = TilejsonResult & WidgetTilesetSourceResult;
|
|
1989
1995
|
declare const vectorTilesetSource: (options: VectorTilesetSourceOptions) => Promise<VectorTilesetSourceResponse>;
|
|
1990
1996
|
|
|
1991
|
-
type VectorTableSourceOptions = SourceOptions & TableSourceOptions & FilterOptions & ColumnsOption
|
|
1997
|
+
type VectorTableSourceOptions = SourceOptions & TableSourceOptions & FilterOptions & ColumnsOption & {
|
|
1998
|
+
/**
|
|
1999
|
+
* If `true`, the server includes a `_carto_bbox` property on each polygon
|
|
2000
|
+
* feature, containing the bounding box of the full (unclipped) geometry as
|
|
2001
|
+
* a `"west,south,east,north"` string in WGS84. Used by clients to compute
|
|
2002
|
+
* stable label positions for polygons that span multiple tiles.
|
|
2003
|
+
*/
|
|
2004
|
+
featureBbox?: boolean;
|
|
2005
|
+
};
|
|
1992
2006
|
type VectorTableSourceResponse = TilejsonResult & WidgetTableSourceResult;
|
|
1993
2007
|
declare const vectorTableSource: (options: VectorTableSourceOptions) => Promise<VectorTableSourceResponse>;
|
|
1994
2008
|
|
|
1995
|
-
type VectorQuerySourceOptions = SourceOptions & QuerySourceOptions & FilterOptions & ColumnsOption
|
|
2009
|
+
type VectorQuerySourceOptions = SourceOptions & QuerySourceOptions & FilterOptions & ColumnsOption & {
|
|
2010
|
+
/**
|
|
2011
|
+
* If `true`, the server includes a `_carto_bbox` property on each polygon
|
|
2012
|
+
* feature, containing the bounding box of the full (unclipped) geometry as
|
|
2013
|
+
* a `"west,south,east,north"` string in WGS84. Used by clients to compute
|
|
2014
|
+
* stable label positions for polygons that span multiple tiles.
|
|
2015
|
+
*/
|
|
2016
|
+
featureBbox?: boolean;
|
|
2017
|
+
};
|
|
1996
2018
|
type VectorQuerySourceResponse = TilejsonResult & WidgetQuerySourceResult;
|
|
1997
2019
|
declare const vectorQuerySource: (options: VectorQuerySourceOptions) => Promise<VectorQuerySourceResponse>;
|
|
1998
2020
|
|
package/build/api-client.js
CHANGED
|
@@ -8242,7 +8242,8 @@ var vectorQuerySource = async function(options) {
|
|
|
8242
8242
|
sqlQuery,
|
|
8243
8243
|
tileResolution = DEFAULT_TILE_RESOLUTION,
|
|
8244
8244
|
queryParameters,
|
|
8245
|
-
aggregationExp
|
|
8245
|
+
aggregationExp,
|
|
8246
|
+
featureBbox
|
|
8246
8247
|
} = options;
|
|
8247
8248
|
const spatialDataType = "geo";
|
|
8248
8249
|
const urlParameters = {
|
|
@@ -8263,6 +8264,9 @@ var vectorQuerySource = async function(options) {
|
|
|
8263
8264
|
if (aggregationExp) {
|
|
8264
8265
|
urlParameters.aggregationExp = aggregationExp;
|
|
8265
8266
|
}
|
|
8267
|
+
if (featureBbox) {
|
|
8268
|
+
urlParameters.featureBbox = true;
|
|
8269
|
+
}
|
|
8266
8270
|
return baseSource("query", options, urlParameters).then(
|
|
8267
8271
|
(result) => ({
|
|
8268
8272
|
...result,
|
|
@@ -8285,7 +8289,8 @@ var vectorTableSource = async function(options) {
|
|
|
8285
8289
|
spatialDataColumn = DEFAULT_GEO_COLUMN,
|
|
8286
8290
|
tableName,
|
|
8287
8291
|
tileResolution = DEFAULT_TILE_RESOLUTION,
|
|
8288
|
-
aggregationExp
|
|
8292
|
+
aggregationExp,
|
|
8293
|
+
featureBbox
|
|
8289
8294
|
} = options;
|
|
8290
8295
|
const spatialDataType = "geo";
|
|
8291
8296
|
const urlParameters = {
|
|
@@ -8303,6 +8308,9 @@ var vectorTableSource = async function(options) {
|
|
|
8303
8308
|
if (aggregationExp) {
|
|
8304
8309
|
urlParameters.aggregationExp = aggregationExp;
|
|
8305
8310
|
}
|
|
8311
|
+
if (featureBbox) {
|
|
8312
|
+
urlParameters.featureBbox = true;
|
|
8313
|
+
}
|
|
8306
8314
|
return baseSource("table", options, urlParameters).then(
|
|
8307
8315
|
(result) => ({
|
|
8308
8316
|
...result,
|
|
@@ -9699,10 +9707,11 @@ function getIconUrlAccessor(field, range, {
|
|
|
9699
9707
|
return normalizeAccessor(accessor, data);
|
|
9700
9708
|
}
|
|
9701
9709
|
function getMaxMarkerSize(visConfig, visualChannels) {
|
|
9702
|
-
const { radiusRange, radius } = visConfig;
|
|
9710
|
+
const { radiusRange, radius, sizeMaxPixels } = visConfig;
|
|
9703
9711
|
const { radiusField, sizeField } = visualChannels;
|
|
9704
9712
|
const field = radiusField || sizeField;
|
|
9705
|
-
|
|
9713
|
+
const baseSize = radiusRange && field ? radiusRange[1] : radius;
|
|
9714
|
+
return Math.ceil(sizeMaxPixels ?? baseSize);
|
|
9706
9715
|
}
|
|
9707
9716
|
function negateAccessor(accessor) {
|
|
9708
9717
|
if (typeof accessor === "function") {
|
|
@@ -10213,6 +10222,7 @@ function getLayerDescriptor({
|
|
|
10213
10222
|
...createInteractionProps(interactionConfig),
|
|
10214
10223
|
...styleProps,
|
|
10215
10224
|
...channelProps,
|
|
10225
|
+
...createZoomScaleProps(config2, visualChannels),
|
|
10216
10226
|
...createParametersProp(layerBlending, styleProps.parameters || {}),
|
|
10217
10227
|
// Must come after style
|
|
10218
10228
|
...createLoadOptions(data.accessToken)
|
|
@@ -10282,6 +10292,28 @@ function createInteractionProps(interactionConfig) {
|
|
|
10282
10292
|
pickable
|
|
10283
10293
|
};
|
|
10284
10294
|
}
|
|
10295
|
+
function createZoomScaleProps(config2, visualChannels) {
|
|
10296
|
+
const { visConfig } = config2;
|
|
10297
|
+
if (!visConfig.radiusScaleWithZoom || visualChannels.radiusField || visualChannels.sizeField) {
|
|
10298
|
+
return {};
|
|
10299
|
+
}
|
|
10300
|
+
const scale2 = Math.pow(2, -visConfig.radiusReferenceZoom);
|
|
10301
|
+
const result = {
|
|
10302
|
+
pointRadiusUnits: "common",
|
|
10303
|
+
pointRadiusScale: scale2,
|
|
10304
|
+
iconSizeUnits: "common",
|
|
10305
|
+
iconSizeScale: scale2
|
|
10306
|
+
};
|
|
10307
|
+
if (visConfig.sizeMinPixels !== void 0) {
|
|
10308
|
+
result.pointRadiusMinPixels = visConfig.sizeMinPixels;
|
|
10309
|
+
result.iconSizeMinPixels = visConfig.sizeMinPixels;
|
|
10310
|
+
}
|
|
10311
|
+
if (visConfig.sizeMaxPixels !== void 0) {
|
|
10312
|
+
result.pointRadiusMaxPixels = visConfig.sizeMaxPixels;
|
|
10313
|
+
result.iconSizeMaxPixels = visConfig.sizeMaxPixels;
|
|
10314
|
+
}
|
|
10315
|
+
return result;
|
|
10316
|
+
}
|
|
10285
10317
|
function mapProps(source, target, mapping) {
|
|
10286
10318
|
for (const sourceKey in mapping) {
|
|
10287
10319
|
const sourceValue = source[sourceKey];
|
|
@@ -10671,7 +10703,15 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
|
|
|
10671
10703
|
} = secondaryLabel || {};
|
|
10672
10704
|
result.getText = mainLabel.field && getTextAccessor(mainLabel.field, data);
|
|
10673
10705
|
const getSecondaryText = secondaryField && getTextAccessor(secondaryField, data);
|
|
10674
|
-
|
|
10706
|
+
const geometry = data.tilestats?.layers?.[0]?.geometry;
|
|
10707
|
+
const isLineOrPolygon = geometry === "Polygon" || geometry === "MultiPolygon" || geometry === "Line" || geometry === "LineString" || geometry === "MultiLineString";
|
|
10708
|
+
if (isLineOrPolygon && (layerType === "tileset" || layerType === "mvt")) {
|
|
10709
|
+
const uniqueIdProperty = visConfig.textLabelUniqueIdField;
|
|
10710
|
+
result.autoLabels = uniqueIdProperty ? { uniqueIdProperty } : true;
|
|
10711
|
+
result.pointType = "text";
|
|
10712
|
+
} else {
|
|
10713
|
+
result.pointType = `${result.pointType}+text`;
|
|
10714
|
+
}
|
|
10675
10715
|
result.textCharacterSet = "auto";
|
|
10676
10716
|
result.textFontFamily = "Inter, sans";
|
|
10677
10717
|
result.textFontSettings = { sdf: true };
|
|
@@ -10830,11 +10870,13 @@ function configureSource({
|
|
|
10830
10870
|
tileResolution,
|
|
10831
10871
|
...queryParameters && { queryParameters }
|
|
10832
10872
|
};
|
|
10873
|
+
const { featureBbox } = dataset;
|
|
10833
10874
|
const vectorOptions = {
|
|
10834
10875
|
spatialDataColumn,
|
|
10835
10876
|
...columns && { columns },
|
|
10836
10877
|
...filters && { filters },
|
|
10837
|
-
...aggregationExp && { aggregationExp }
|
|
10878
|
+
...aggregationExp && { aggregationExp },
|
|
10879
|
+
...featureBbox && { featureBbox }
|
|
10838
10880
|
};
|
|
10839
10881
|
if (type === "raster") {
|
|
10840
10882
|
return rasterSource({
|
|
@@ -11118,6 +11160,21 @@ async function fetchMap({
|
|
|
11118
11160
|
}
|
|
11119
11161
|
}
|
|
11120
11162
|
});
|
|
11163
|
+
const layers = map.keplerMapConfig.config.visState.layers;
|
|
11164
|
+
const datasetsWithLabels = /* @__PURE__ */ new Set();
|
|
11165
|
+
for (const layer of layers) {
|
|
11166
|
+
const hasTextLabel = layer.config?.textLabel?.some(
|
|
11167
|
+
(t) => t.field?.name
|
|
11168
|
+
);
|
|
11169
|
+
if (hasTextLabel) {
|
|
11170
|
+
datasetsWithLabels.add(layer.config.dataId);
|
|
11171
|
+
}
|
|
11172
|
+
}
|
|
11173
|
+
map.datasets.forEach((dataset) => {
|
|
11174
|
+
if (datasetsWithLabels.has(dataset.id) && (dataset.type === "table" || dataset.type === "query")) {
|
|
11175
|
+
dataset.featureBbox = true;
|
|
11176
|
+
}
|
|
11177
|
+
});
|
|
11121
11178
|
const [basemap] = await Promise.all([
|
|
11122
11179
|
fetchBasemapProps({ config: map.keplerMapConfig.config, errorContext }),
|
|
11123
11180
|
// Mutates map.datasets so that dataset.data contains data
|