@carto/api-client 0.4.9 → 0.4.10-alpha.0
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 +5 -0
- package/build/api-client.cjs +10409 -2202
- package/build/api-client.cjs.map +1 -1
- package/build/api-client.modern.js +9955 -1938
- package/build/api-client.modern.js.map +1 -1
- package/build/constants-internal.d.ts +8 -0
- package/build/constants.d.ts +4 -1
- package/build/fetch-map/basemap-styles.d.ts +27 -0
- package/build/fetch-map/basemap.d.ts +17 -0
- package/build/fetch-map/fetch-map.d.ts +47 -0
- package/build/fetch-map/index.d.ts +7 -0
- package/build/fetch-map/layer-map.d.ts +28 -0
- package/build/fetch-map/parse-map.d.ts +39 -0
- package/build/fetch-map/source.d.ts +20 -0
- package/build/fetch-map/types.d.ts +220 -0
- package/build/fetch-map/utils.d.ts +18 -0
- package/build/index.d.ts +1 -0
- package/build/models/model.d.ts +0 -2
- package/build/sources/types.d.ts +4 -1
- package/build/types.d.ts +2 -0
- package/package.json +25 -21
- package/src/constants-internal.ts +10 -0
- package/src/constants.ts +5 -1
- package/src/fetch-map/basemap-styles.ts +159 -0
- package/src/fetch-map/basemap.ts +120 -0
- package/src/fetch-map/fetch-map.ts +331 -0
- package/src/fetch-map/index.ts +13 -0
- package/src/fetch-map/layer-map.ts +461 -0
- package/src/fetch-map/parse-map.ts +425 -0
- package/src/fetch-map/source.ts +233 -0
- package/src/fetch-map/types.ts +268 -0
- package/src/fetch-map/utils.ts +69 -0
- package/src/index.ts +1 -0
- package/src/models/model.ts +0 -2
- package/src/sources/types.ts +4 -1
- package/src/types.ts +10 -0
- package/src/widget-sources/widget-source.ts +0 -2
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import {LayerType, SCALE_TYPE} from './layer-map.js';
|
|
2
|
+
import {Format, MapType, ProviderType, QueryParameters} from '../types.js';
|
|
3
|
+
import {TilejsonResult, GeojsonResult, JsonResult} from '../sources/types.js';
|
|
4
|
+
|
|
5
|
+
export type VisualChannelField = {
|
|
6
|
+
name: string;
|
|
7
|
+
type: string;
|
|
8
|
+
colorColumn?: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type VisualChannels = {
|
|
12
|
+
colorField?: VisualChannelField;
|
|
13
|
+
colorScale?: SCALE_TYPE;
|
|
14
|
+
|
|
15
|
+
customMarkersField?: VisualChannelField;
|
|
16
|
+
customMarkersScale?: SCALE_TYPE;
|
|
17
|
+
|
|
18
|
+
radiusField?: VisualChannelField;
|
|
19
|
+
radiusScale?: SCALE_TYPE;
|
|
20
|
+
|
|
21
|
+
rotationScale?: SCALE_TYPE;
|
|
22
|
+
rotationField?: VisualChannelField;
|
|
23
|
+
|
|
24
|
+
sizeField?: VisualChannelField;
|
|
25
|
+
sizeScale?: SCALE_TYPE;
|
|
26
|
+
|
|
27
|
+
strokeColorField?: VisualChannelField;
|
|
28
|
+
strokeColorScale?: SCALE_TYPE;
|
|
29
|
+
|
|
30
|
+
heightField?: VisualChannelField;
|
|
31
|
+
heightScale?: SCALE_TYPE;
|
|
32
|
+
|
|
33
|
+
weightField?: VisualChannelField;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type ColorRange = {
|
|
37
|
+
category: string;
|
|
38
|
+
colors: string[];
|
|
39
|
+
colorMap: string[][] | undefined;
|
|
40
|
+
name: string;
|
|
41
|
+
type: string;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export type CustomMarkersRange = {
|
|
45
|
+
markerMap: {
|
|
46
|
+
value: string;
|
|
47
|
+
markerUrl?: string;
|
|
48
|
+
}[];
|
|
49
|
+
othersMarker?: string;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export type VisConfig = {
|
|
53
|
+
filled?: boolean;
|
|
54
|
+
opacity?: number;
|
|
55
|
+
enable3d?: boolean;
|
|
56
|
+
|
|
57
|
+
colorAggregation?: any;
|
|
58
|
+
colorRange: ColorRange;
|
|
59
|
+
|
|
60
|
+
customMarkers?: boolean;
|
|
61
|
+
customMarkersRange?: CustomMarkersRange | null;
|
|
62
|
+
customMarkersUrl?: string | null;
|
|
63
|
+
|
|
64
|
+
radius: number;
|
|
65
|
+
radiusRange?: number[];
|
|
66
|
+
|
|
67
|
+
sizeAggregation?: any;
|
|
68
|
+
sizeRange?: any;
|
|
69
|
+
|
|
70
|
+
strokeColorAggregation?: any;
|
|
71
|
+
strokeOpacity?: number;
|
|
72
|
+
strokeColorRange?: ColorRange;
|
|
73
|
+
|
|
74
|
+
heightRange?: any;
|
|
75
|
+
heightAggregation?: any;
|
|
76
|
+
|
|
77
|
+
weightAggregation?: any;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export type TextLabel = {
|
|
81
|
+
field: VisualChannelField | null | undefined;
|
|
82
|
+
alignment?: 'center' | 'bottom' | 'top';
|
|
83
|
+
anchor?: 'middle' | 'start' | 'end';
|
|
84
|
+
size: number;
|
|
85
|
+
color?: number[];
|
|
86
|
+
offset?: [number, number];
|
|
87
|
+
outlineColor?: number[];
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export type MapLayerConfig = {
|
|
91
|
+
columns?: Record<string, any>;
|
|
92
|
+
color?: number[];
|
|
93
|
+
label?: string;
|
|
94
|
+
dataId: string;
|
|
95
|
+
textLabel: TextLabel[];
|
|
96
|
+
visConfig: VisConfig;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export type MapConfigLayer = {
|
|
100
|
+
type: LayerType;
|
|
101
|
+
id: string;
|
|
102
|
+
config: MapLayerConfig;
|
|
103
|
+
visualChannels: VisualChannels;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export interface CustomStyle {
|
|
107
|
+
url?: string;
|
|
108
|
+
style?: any;
|
|
109
|
+
customAttribution?: string;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// TODO replace with more complete type from Builder
|
|
113
|
+
export type KeplerMapConfig = {
|
|
114
|
+
filters: any;
|
|
115
|
+
mapState: any;
|
|
116
|
+
mapStyle: {
|
|
117
|
+
styleType: string;
|
|
118
|
+
visibleLayerGroups: Record<string, boolean>;
|
|
119
|
+
};
|
|
120
|
+
popupSettings: any;
|
|
121
|
+
visState: {
|
|
122
|
+
layers: MapConfigLayer[];
|
|
123
|
+
layerBlending: any;
|
|
124
|
+
interactionConfig: any;
|
|
125
|
+
};
|
|
126
|
+
customBaseMaps?: {
|
|
127
|
+
customStyle?: CustomStyle;
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export type BasemapType = 'maplibre' | 'google-maps';
|
|
132
|
+
|
|
133
|
+
export type Basemap = MapLibreBasemap | GoogleBasemap;
|
|
134
|
+
|
|
135
|
+
export type BasemapCommon = {
|
|
136
|
+
/**
|
|
137
|
+
* Type of basemap.
|
|
138
|
+
*/
|
|
139
|
+
type: BasemapType;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Custom attribution for style data if not provided by style definition.
|
|
143
|
+
*/
|
|
144
|
+
attribution?: string;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Properties of the basemap. These properties are specific to the basemap type.
|
|
148
|
+
*/
|
|
149
|
+
props: Record<string, any>;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export type MapLibreBasemap = BasemapCommon & {
|
|
153
|
+
type: 'maplibre';
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* MapLibre map properties.
|
|
157
|
+
*
|
|
158
|
+
* Meant to be passed to directly to `maplibregl.Map` object.
|
|
159
|
+
*/
|
|
160
|
+
props: MapLibreBasemapProps;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Layer groups to be displayed in the basemap.
|
|
164
|
+
*/
|
|
165
|
+
visibleLayerGroups?: Record<string, boolean>;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* If `style` has been filtered by `visibleLayerGroups` then this property contains original style object, so user
|
|
169
|
+
* can use `applyLayerGroupFilters` again with new settings.
|
|
170
|
+
*/
|
|
171
|
+
rawStyle?: string | Record<string, any>;
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
// Cherry-pick of maplibregl Map API props that are supported/provided by fetchMap interface
|
|
175
|
+
export type MapLibreBasemapProps = {
|
|
176
|
+
style: string | Record<string, any>;
|
|
177
|
+
center: [number, number];
|
|
178
|
+
zoom: number;
|
|
179
|
+
pitch?: number;
|
|
180
|
+
bearing?: number;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
export type GoogleBasemap = BasemapCommon & {
|
|
184
|
+
type: 'google-maps';
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Google map properties.
|
|
188
|
+
*
|
|
189
|
+
* Meant to be passed to directly to `google.maps.Map` object.
|
|
190
|
+
*/
|
|
191
|
+
props: GoogleBasemapProps;
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
// Cherry-pick of Google Map API props that are supported/provided by fetchMap interface
|
|
195
|
+
export type GoogleBasemapProps = {
|
|
196
|
+
mapTypeId: string;
|
|
197
|
+
mapId?: string;
|
|
198
|
+
center?: {lat: number; lng: number};
|
|
199
|
+
zoom?: number;
|
|
200
|
+
tilt?: number;
|
|
201
|
+
heading?: number;
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
export type Dataset = {
|
|
205
|
+
id: string;
|
|
206
|
+
type: MapType;
|
|
207
|
+
source: string;
|
|
208
|
+
cache?: number;
|
|
209
|
+
connectionName: string;
|
|
210
|
+
geoColumn: string;
|
|
211
|
+
data: TilejsonResult | GeojsonResult | JsonResult;
|
|
212
|
+
columns: string[];
|
|
213
|
+
format: Format;
|
|
214
|
+
aggregationExp: string;
|
|
215
|
+
aggregationResLevel: number;
|
|
216
|
+
queryParameters: QueryParameters;
|
|
217
|
+
connectionId?: string;
|
|
218
|
+
providerId: ProviderType;
|
|
219
|
+
createdAt?: string;
|
|
220
|
+
updatedAt?: string;
|
|
221
|
+
label?: string;
|
|
222
|
+
color?: string;
|
|
223
|
+
uniqueIdProperty?: string;
|
|
224
|
+
queryTemplate?: string | null;
|
|
225
|
+
name?: string | null;
|
|
226
|
+
spatialIndex?: string | null;
|
|
227
|
+
exportToBucketAvailable?: boolean;
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
export type AttributeType = 'String' | 'Number' | 'Timestamp' | 'Boolean';
|
|
231
|
+
|
|
232
|
+
export type AttributeStatsBase = {
|
|
233
|
+
attribute: string;
|
|
234
|
+
type: AttributeType;
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
export type AttributeStatsNumber = AttributeStatsBase & {
|
|
238
|
+
type: 'Number';
|
|
239
|
+
min: number;
|
|
240
|
+
avg: number;
|
|
241
|
+
max: number;
|
|
242
|
+
sum: number;
|
|
243
|
+
quantiles: number[][];
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
export type AttributeStatsTimestamp = AttributeStatsBase & {
|
|
247
|
+
type: 'Timestamp';
|
|
248
|
+
min: string;
|
|
249
|
+
max: string;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
export interface AttributeStatsStringCategory {
|
|
253
|
+
category: string;
|
|
254
|
+
frequency: number;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export type AttributeStatsString = AttributeStatsBase & {
|
|
258
|
+
type: 'String' | 'Boolean';
|
|
259
|
+
categories: AttributeStatsStringCategory[];
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Result of getAttributeStats request to backend.
|
|
264
|
+
*/
|
|
265
|
+
export type AttributeStats =
|
|
266
|
+
| AttributeStatsString
|
|
267
|
+
| AttributeStatsNumber
|
|
268
|
+
| AttributeStatsTimestamp;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type {BinaryFeature} from '@loaders.gl/schema';
|
|
2
|
+
import type {Dataset} from './types.js';
|
|
3
|
+
type Properties = BinaryFeature['properties'];
|
|
4
|
+
type NumericProps = BinaryFeature['numericProps'];
|
|
5
|
+
|
|
6
|
+
// Returns a Proxy object that allows accessing binary data
|
|
7
|
+
// as if it were JSON properties
|
|
8
|
+
export function createBinaryProxy(
|
|
9
|
+
data: {numericProps: NumericProps; properties: Properties[]},
|
|
10
|
+
index: number
|
|
11
|
+
) {
|
|
12
|
+
const {properties, numericProps} = data;
|
|
13
|
+
return new Proxy(properties[index] || {}, {
|
|
14
|
+
get(target, property) {
|
|
15
|
+
if (property in numericProps) {
|
|
16
|
+
return numericProps[property as string].value[index];
|
|
17
|
+
}
|
|
18
|
+
return target[property as any];
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
has(target, property) {
|
|
22
|
+
return property in numericProps || property in target;
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
ownKeys(target) {
|
|
26
|
+
return [...Object.keys(numericProps), ...Reflect.ownKeys(target)];
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
getOwnPropertyDescriptor() {
|
|
30
|
+
return {enumerable: true, configurable: true};
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function scaleIdentity() {
|
|
36
|
+
let unknown: any;
|
|
37
|
+
|
|
38
|
+
function scale(x: any) {
|
|
39
|
+
return x === null ? unknown : x;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
scale.invert = scale;
|
|
43
|
+
|
|
44
|
+
scale.domain = scale.range = (d: any) => d;
|
|
45
|
+
|
|
46
|
+
scale.unknown = (u: any) => {
|
|
47
|
+
if (u) {
|
|
48
|
+
unknown = u;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return unknown;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
scale.copy = () => {
|
|
55
|
+
const scaleCopy = scaleIdentity();
|
|
56
|
+
scaleCopy.unknown(unknown);
|
|
57
|
+
return scaleCopy;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
return scale;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function isRemoteCalculationSupported(dataset: Dataset) {
|
|
64
|
+
if (dataset?.type === 'tileset' || dataset.providerId === 'databricks') {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return true;
|
|
69
|
+
}
|
package/src/index.ts
CHANGED
package/src/models/model.ts
CHANGED
|
@@ -40,8 +40,6 @@ export interface ModelSource {
|
|
|
40
40
|
spatialDataColumn?: string;
|
|
41
41
|
spatialDataType?: SpatialDataType;
|
|
42
42
|
spatialFiltersMode?: SpatialFilterPolyfillMode;
|
|
43
|
-
/** original resolution of the spatial index data as stored in the DW */
|
|
44
|
-
dataResolution?: number;
|
|
45
43
|
}
|
|
46
44
|
|
|
47
45
|
const {V3} = ApiVersion;
|
package/src/sources/types.ts
CHANGED
|
@@ -118,7 +118,10 @@ export type AggregationOptions = {
|
|
|
118
118
|
aggregationResLevel?: number;
|
|
119
119
|
|
|
120
120
|
/**
|
|
121
|
-
*
|
|
121
|
+
* Deprecated parameter previously used for H3 and Quadbin widgets. Now has
|
|
122
|
+
* no effect and will be removed in a future version.
|
|
123
|
+
* @deprecated Parameter has no effect.
|
|
124
|
+
* @todo TODO(v0.5): Remove spatialIndexReferenceViewState parameter.
|
|
122
125
|
*/
|
|
123
126
|
dataResolution?: number;
|
|
124
127
|
};
|
package/src/types.ts
CHANGED
|
@@ -12,6 +12,16 @@ export type Format = 'json' | 'geojson' | 'tilejson';
|
|
|
12
12
|
/** @privateRemarks Source: @carto/constants, @deck.gl/carto */
|
|
13
13
|
export type MapType = 'boundary' | 'query' | 'table' | 'tileset' | 'raster';
|
|
14
14
|
|
|
15
|
+
/** @privateRemarks Source: cloud-native */
|
|
16
|
+
export type ProviderType =
|
|
17
|
+
| 'bigquery'
|
|
18
|
+
| 'postgres'
|
|
19
|
+
| 'snowflake'
|
|
20
|
+
| 'redshift'
|
|
21
|
+
| 'databricks'
|
|
22
|
+
| 'carto'
|
|
23
|
+
| 'carto_dw';
|
|
24
|
+
|
|
15
25
|
/**
|
|
16
26
|
* Alias for GeoJSON 'BBox' type, semantically representing a viewport.
|
|
17
27
|
* Order of values is "west", "south", "east", "north".
|
|
@@ -22,7 +22,6 @@ import {getClient} from '../client.js';
|
|
|
22
22
|
import {ModelSource} from '../models/model.js';
|
|
23
23
|
import {SourceOptions} from '../sources/index.js';
|
|
24
24
|
import {ApiVersion, DEFAULT_API_BASE_URL} from '../constants.js';
|
|
25
|
-
import {AggregationOptions} from '../sources/types.js';
|
|
26
25
|
|
|
27
26
|
export interface WidgetSourceProps extends Omit<SourceOptions, 'filters'> {
|
|
28
27
|
apiVersion?: ApiVersion;
|
|
@@ -80,7 +79,6 @@ export abstract class WidgetSource<Props extends WidgetSourceProps> {
|
|
|
80
79
|
filtersLogicalOperator: props.filtersLogicalOperator,
|
|
81
80
|
spatialDataType: props.spatialDataType,
|
|
82
81
|
spatialDataColumn: props.spatialDataColumn,
|
|
83
|
-
dataResolution: (props as Partial<AggregationOptions>).dataResolution,
|
|
84
82
|
};
|
|
85
83
|
}
|
|
86
84
|
|