@carto/api-client 0.5.0-alpha.9 → 0.5.1-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 +30 -1
- package/build/api-client.cjs +15241 -3358
- package/build/api-client.cjs.map +1 -0
- package/build/api-client.d.cts +528 -181
- package/build/api-client.d.ts +528 -181
- package/build/api-client.js +14685 -2911
- package/build/api-client.js.map +1 -0
- package/build/worker.js +5117 -619
- package/build/worker.js.map +1 -0
- package/package.json +49 -32
- package/src/api/query.ts +2 -1
- package/src/constants-internal.ts +10 -0
- package/src/constants.ts +5 -1
- package/src/deck/get-data-filter-extension-props.ts +27 -9
- 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/filters/tileFeatures.ts +27 -10
- package/src/filters/tileFeaturesRaster.ts +122 -0
- package/src/index.ts +1 -0
- package/src/models/model.ts +0 -7
- package/src/sources/base-source.ts +4 -2
- package/src/sources/h3-tileset-source.ts +1 -1
- package/src/sources/quadbin-tileset-source.ts +1 -1
- package/src/sources/raster-source.ts +18 -5
- package/src/sources/types.ts +15 -8
- package/src/sources/vector-tileset-source.ts +1 -1
- package/src/spatial-index.ts +3 -84
- package/src/types.ts +16 -2
- package/src/widget-sources/index.ts +1 -0
- package/src/widget-sources/types.ts +1 -3
- package/src/widget-sources/widget-raster-source.ts +14 -0
- package/src/widget-sources/widget-remote-source.ts +16 -91
- package/src/widget-sources/widget-source.ts +9 -25
- package/src/widget-sources/widget-tileset-source-impl.ts +16 -19
- package/src/widget-sources/widget-tileset-source.ts +24 -21
- package/src/workers/widget-tileset-worker.ts +1 -1
package/src/sources/types.ts
CHANGED
|
@@ -116,11 +116,6 @@ export type AggregationOptions = {
|
|
|
116
116
|
* @default 6 for quadbin and 4 for h3 sources
|
|
117
117
|
*/
|
|
118
118
|
aggregationResLevel?: number;
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Original resolution of the spatial index data as stored in the DW
|
|
122
|
-
*/
|
|
123
|
-
dataResolution?: number;
|
|
124
119
|
};
|
|
125
120
|
|
|
126
121
|
export type FilterOptions = {
|
|
@@ -196,7 +191,7 @@ export type TilesetSourceOptions = {
|
|
|
196
191
|
* Whether to use Web Workers for local widget calculations. Workers
|
|
197
192
|
* are used by default if the runtime environment supports ES Module Workers.
|
|
198
193
|
*/
|
|
199
|
-
|
|
194
|
+
widgetWorker?: boolean;
|
|
200
195
|
};
|
|
201
196
|
|
|
202
197
|
export type ColumnsOption = {
|
|
@@ -364,8 +359,20 @@ export enum RasterBandColorinterp {
|
|
|
364
359
|
Palette = 'palette',
|
|
365
360
|
}
|
|
366
361
|
|
|
362
|
+
export type RasterBandType =
|
|
363
|
+
| 'uint8'
|
|
364
|
+
| 'int8'
|
|
365
|
+
| 'uint16'
|
|
366
|
+
| 'int16'
|
|
367
|
+
| 'uint32'
|
|
368
|
+
| 'int32'
|
|
369
|
+
| 'uint64'
|
|
370
|
+
| 'int64'
|
|
371
|
+
| 'float32'
|
|
372
|
+
| 'float64';
|
|
373
|
+
|
|
367
374
|
export type RasterMetadataBand = {
|
|
368
|
-
type:
|
|
375
|
+
type: RasterBandType;
|
|
369
376
|
name: string;
|
|
370
377
|
stats: RasterMetadataBandStats;
|
|
371
378
|
/**
|
|
@@ -379,7 +386,7 @@ export type RasterMetadataBand = {
|
|
|
379
386
|
/**
|
|
380
387
|
* Default color mapping for unique values (or if coloprinterp is `palette`)
|
|
381
388
|
*/
|
|
382
|
-
colortable?: Record<string, number
|
|
389
|
+
colortable?: Record<string, [number, number, number, number]>;
|
|
383
390
|
|
|
384
391
|
/**
|
|
385
392
|
* No value representation.
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
+
import {baseSource} from './base-source.js';
|
|
5
6
|
import {DEFAULT_GEO_COLUMN} from '../constants-internal.js';
|
|
6
7
|
import {getTileFormat} from '../utils/getTileFormat.js';
|
|
7
8
|
import {
|
|
8
9
|
WidgetTilesetSource,
|
|
9
10
|
WidgetTilesetSourceResult,
|
|
10
11
|
} from '../widget-sources/index.js';
|
|
11
|
-
import {baseSource} from './base-source.js';
|
|
12
12
|
import type {
|
|
13
13
|
SourceOptions,
|
|
14
14
|
TilesetSourceOptions,
|
package/src/spatial-index.ts
CHANGED
|
@@ -1,88 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN,
|
|
4
|
-
} from './constants-internal.js';
|
|
5
|
-
import type {ModelSource} from './models/model.js';
|
|
6
|
-
import type {AggregationOptions} from './sources/types.js';
|
|
7
|
-
import type {ViewState} from './widget-sources/index.js';
|
|
8
|
-
|
|
1
|
+
// Default tile display size in deck.gl, in viewport pixels. May differ
|
|
2
|
+
// from size or resolution assumed when generating the tile data,
|
|
9
3
|
const DEFAULT_TILE_SIZE = 512;
|
|
10
|
-
const QUADBIN_ZOOM_MAX_OFFSET = 4;
|
|
11
|
-
|
|
12
|
-
export function getSpatialFiltersResolution(
|
|
13
|
-
source: Partial<ModelSource & AggregationOptions>,
|
|
14
|
-
viewState: ViewState
|
|
15
|
-
): number | undefined {
|
|
16
|
-
const dataResolution = source.dataResolution ?? Number.MAX_VALUE;
|
|
17
|
-
|
|
18
|
-
const aggregationResLevel =
|
|
19
|
-
source.aggregationResLevel ??
|
|
20
|
-
(source.spatialDataType === 'h3'
|
|
21
|
-
? DEFAULT_AGGREGATION_RES_LEVEL_H3
|
|
22
|
-
: DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN);
|
|
23
|
-
|
|
24
|
-
const aggregationResLevelOffset = Math.max(
|
|
25
|
-
0,
|
|
26
|
-
Math.floor(aggregationResLevel)
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
const currentZoomInt = Math.ceil(viewState.zoom);
|
|
30
|
-
if (source.spatialDataType === 'h3') {
|
|
31
|
-
const tileSize = DEFAULT_TILE_SIZE;
|
|
32
|
-
const maxResolutionForZoom =
|
|
33
|
-
maxH3SpatialFiltersResolutions.find(
|
|
34
|
-
([zoom]) => zoom === currentZoomInt
|
|
35
|
-
)?.[1] ?? Math.max(0, currentZoomInt - 3);
|
|
36
|
-
|
|
37
|
-
const maxSpatialFiltersResolution = maxResolutionForZoom
|
|
38
|
-
? Math.min(dataResolution, maxResolutionForZoom)
|
|
39
|
-
: dataResolution;
|
|
40
|
-
|
|
41
|
-
const hexagonResolution =
|
|
42
|
-
_getHexagonResolution(viewState, tileSize) + aggregationResLevelOffset;
|
|
43
|
-
|
|
44
|
-
return Math.min(hexagonResolution, maxSpatialFiltersResolution);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (source.spatialDataType === 'quadbin') {
|
|
48
|
-
const maxResolutionForZoom = currentZoomInt + QUADBIN_ZOOM_MAX_OFFSET;
|
|
49
|
-
const maxSpatialFiltersResolution = Math.min(
|
|
50
|
-
dataResolution,
|
|
51
|
-
maxResolutionForZoom
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
const quadsResolution =
|
|
55
|
-
Math.floor(viewState.zoom) + aggregationResLevelOffset;
|
|
56
|
-
return Math.min(quadsResolution, maxSpatialFiltersResolution);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return undefined;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const maxH3SpatialFiltersResolutions = [
|
|
63
|
-
[20, 14],
|
|
64
|
-
[19, 13],
|
|
65
|
-
[18, 12],
|
|
66
|
-
[17, 11],
|
|
67
|
-
[16, 10],
|
|
68
|
-
[15, 9],
|
|
69
|
-
[14, 8],
|
|
70
|
-
[13, 7],
|
|
71
|
-
[12, 7],
|
|
72
|
-
[11, 7],
|
|
73
|
-
[10, 6],
|
|
74
|
-
[9, 6],
|
|
75
|
-
[8, 5],
|
|
76
|
-
[7, 4],
|
|
77
|
-
[6, 4],
|
|
78
|
-
[5, 3],
|
|
79
|
-
[4, 2],
|
|
80
|
-
[3, 1],
|
|
81
|
-
[2, 1],
|
|
82
|
-
[1, 0],
|
|
83
|
-
];
|
|
84
|
-
|
|
85
|
-
// stolen from https://github.com/visgl/deck.gl/blob/master/modules/carto/src/layers/h3-tileset-2d.ts
|
|
86
4
|
|
|
87
5
|
// Relative scale factor (0 = no biasing, 2 = a few hexagons cover view)
|
|
88
6
|
const BIAS = 2;
|
|
@@ -92,6 +10,7 @@ const BIAS = 2;
|
|
|
92
10
|
* a H3 resolution such that the screen space size of the hexagons is
|
|
93
11
|
* "similar" to the given tileSize on screen. Intended for use with deck.gl.
|
|
94
12
|
* @internal
|
|
13
|
+
* @privateRemarks Source: https://github.com/visgl/deck.gl/blob/master/modules/carto/src/layers/h3-tileset-2d.ts
|
|
95
14
|
*/
|
|
96
15
|
export function _getHexagonResolution(
|
|
97
16
|
viewport: {zoom: number; latitude: number},
|
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".
|
|
@@ -28,8 +38,6 @@ export type Viewport = [number, number, number, number];
|
|
|
28
38
|
export type Tile = {
|
|
29
39
|
index: {x: number; y: number; z: number};
|
|
30
40
|
id: string;
|
|
31
|
-
content: unknown;
|
|
32
|
-
zoom: number;
|
|
33
41
|
bbox: {west: number; east: number; north: number; south: number};
|
|
34
42
|
isVisible: boolean;
|
|
35
43
|
data?: BinaryFeatureCollection;
|
|
@@ -40,6 +48,12 @@ export type SpatialIndexTile = Tile & {
|
|
|
40
48
|
data?: (Feature & {id: bigint})[];
|
|
41
49
|
};
|
|
42
50
|
|
|
51
|
+
export type RasterTile = Tile & {
|
|
52
|
+
id: string;
|
|
53
|
+
index: {q: bigint; i: string};
|
|
54
|
+
data?: Raster;
|
|
55
|
+
};
|
|
56
|
+
|
|
43
57
|
/** @privateRemarks Source: @deck.gl/carto */
|
|
44
58
|
export type Raster = {
|
|
45
59
|
blockSize: number;
|
|
@@ -18,12 +18,10 @@ export interface ViewState {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
/** Common options for {@link WidgetRemoteSource} requests. */
|
|
21
|
-
interface BaseRequestOptions {
|
|
21
|
+
export interface BaseRequestOptions {
|
|
22
22
|
signal?: AbortSignal;
|
|
23
23
|
spatialFilter?: SpatialFilter;
|
|
24
24
|
spatialFiltersMode?: SpatialFilterPolyfillMode;
|
|
25
|
-
/** Required for table- and query-based spatial index sources (H3, Quadbin). */
|
|
26
|
-
spatialIndexReferenceViewState?: ViewState;
|
|
27
25
|
/** Overrides source filters, if any. */
|
|
28
26
|
filters?: Filters;
|
|
29
27
|
filterOwner?: string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {RasterMetadata} from '../sources/index.js';
|
|
2
|
+
import {
|
|
3
|
+
WidgetTilesetSource,
|
|
4
|
+
WidgetTilesetSourceProps,
|
|
5
|
+
} from './widget-tileset-source.js';
|
|
6
|
+
|
|
7
|
+
export type WidgetRasterSourceProps = WidgetTilesetSourceProps & {
|
|
8
|
+
rasterMetadata: RasterMetadata;
|
|
9
|
+
spatialDataType: 'quadbin';
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type WidgetRasterSourceResult = {widgetSource: WidgetRasterSource};
|
|
13
|
+
|
|
14
|
+
export class WidgetRasterSource extends WidgetTilesetSource<WidgetRasterSourceProps> {}
|
|
@@ -22,7 +22,6 @@ import {DEFAULT_TILE_RESOLUTION} from '../constants-internal.js';
|
|
|
22
22
|
import {WidgetSource, WidgetSourceProps} from './widget-source.js';
|
|
23
23
|
import {Filters} from '../types.js';
|
|
24
24
|
import {ApiVersion} from '../constants.js';
|
|
25
|
-
import {AggregationOptions} from '../sources/types.js';
|
|
26
25
|
|
|
27
26
|
export type WidgetRemoteSourceProps = WidgetSourceProps;
|
|
28
27
|
|
|
@@ -34,13 +33,6 @@ export type WidgetRemoteSourceProps = WidgetSourceProps;
|
|
|
34
33
|
export abstract class WidgetRemoteSource<
|
|
35
34
|
Props extends WidgetRemoteSourceProps,
|
|
36
35
|
> extends WidgetSource<Props> {
|
|
37
|
-
protected _headers: Record<string, string> = {};
|
|
38
|
-
|
|
39
|
-
/** Assigns HTTP headers to be included on API requests from this source. */
|
|
40
|
-
setRequestHeaders(headers: Record<string, string>): void {
|
|
41
|
-
this._headers = headers;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
36
|
/**
|
|
45
37
|
* Subclasses of {@link WidgetRemoteSource} must implement this method, calling
|
|
46
38
|
* {@link WidgetRemoteSource.prototype._getModelSource} for common source
|
|
@@ -67,7 +59,6 @@ export abstract class WidgetRemoteSource<
|
|
|
67
59
|
filtersLogicalOperator: props.filtersLogicalOperator,
|
|
68
60
|
spatialDataType: props.spatialDataType,
|
|
69
61
|
spatialDataColumn: props.spatialDataColumn,
|
|
70
|
-
dataResolution: (props as Partial<AggregationOptions>).dataResolution,
|
|
71
62
|
};
|
|
72
63
|
}
|
|
73
64
|
|
|
@@ -80,24 +71,16 @@ export abstract class WidgetRemoteSource<
|
|
|
80
71
|
filterOwner,
|
|
81
72
|
spatialFilter,
|
|
82
73
|
spatialFiltersMode,
|
|
83
|
-
spatialIndexReferenceViewState,
|
|
84
74
|
...params
|
|
85
75
|
} = options;
|
|
86
76
|
const {column, operation, operationColumn} = params;
|
|
87
|
-
const source = this.getModelSource(filters, filterOwner);
|
|
88
|
-
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
89
|
-
source,
|
|
90
|
-
spatialFilter,
|
|
91
|
-
spatialIndexReferenceViewState
|
|
92
|
-
);
|
|
93
77
|
|
|
94
78
|
type CategoriesModelResponse = {rows: {name: string; value: number}[]};
|
|
95
79
|
|
|
96
80
|
return executeModel({
|
|
97
81
|
model: 'category',
|
|
98
82
|
source: {
|
|
99
|
-
...
|
|
100
|
-
spatialFiltersResolution,
|
|
83
|
+
...this.getModelSource(filters, filterOwner),
|
|
101
84
|
spatialFiltersMode,
|
|
102
85
|
spatialFilter,
|
|
103
86
|
},
|
|
@@ -106,7 +89,7 @@ export abstract class WidgetRemoteSource<
|
|
|
106
89
|
operation,
|
|
107
90
|
operationColumn: operationColumn || column,
|
|
108
91
|
},
|
|
109
|
-
opts: {signal, headers: this.
|
|
92
|
+
opts: {signal, headers: this.props.headers},
|
|
110
93
|
}).then((res: CategoriesModelResponse) => normalizeObjectKeys(res.rows));
|
|
111
94
|
}
|
|
112
95
|
|
|
@@ -119,24 +102,16 @@ export abstract class WidgetRemoteSource<
|
|
|
119
102
|
filterOwner,
|
|
120
103
|
spatialFilter,
|
|
121
104
|
spatialFiltersMode,
|
|
122
|
-
spatialIndexReferenceViewState,
|
|
123
105
|
...params
|
|
124
106
|
} = options;
|
|
125
107
|
const {columns, dataType, featureIds, z, limit, tileResolution} = params;
|
|
126
|
-
const source = this.getModelSource(filters, filterOwner);
|
|
127
|
-
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
128
|
-
source,
|
|
129
|
-
spatialFilter,
|
|
130
|
-
spatialIndexReferenceViewState
|
|
131
|
-
);
|
|
132
108
|
|
|
133
109
|
type FeaturesModelResponse = {rows: Record<string, unknown>[]};
|
|
134
110
|
|
|
135
111
|
return executeModel({
|
|
136
112
|
model: 'pick',
|
|
137
113
|
source: {
|
|
138
|
-
...
|
|
139
|
-
spatialFiltersResolution,
|
|
114
|
+
...this.getModelSource(filters, filterOwner),
|
|
140
115
|
spatialFiltersMode,
|
|
141
116
|
spatialFilter,
|
|
142
117
|
},
|
|
@@ -148,7 +123,7 @@ export abstract class WidgetRemoteSource<
|
|
|
148
123
|
limit: limit || 1000,
|
|
149
124
|
tileResolution: tileResolution || DEFAULT_TILE_RESOLUTION,
|
|
150
125
|
},
|
|
151
|
-
opts: {signal, headers: this.
|
|
126
|
+
opts: {signal, headers: this.props.headers},
|
|
152
127
|
// Avoid `normalizeObjectKeys()`, which changes column names.
|
|
153
128
|
}).then(({rows}: FeaturesModelResponse) => ({rows}));
|
|
154
129
|
}
|
|
@@ -160,25 +135,17 @@ export abstract class WidgetRemoteSource<
|
|
|
160
135
|
filterOwner,
|
|
161
136
|
spatialFilter,
|
|
162
137
|
spatialFiltersMode,
|
|
163
|
-
spatialIndexReferenceViewState,
|
|
164
138
|
operationExp,
|
|
165
139
|
...params
|
|
166
140
|
} = options;
|
|
167
141
|
const {column, operation} = params;
|
|
168
|
-
const source = this.getModelSource(filters, filterOwner);
|
|
169
|
-
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
170
|
-
source,
|
|
171
|
-
spatialFilter,
|
|
172
|
-
spatialIndexReferenceViewState
|
|
173
|
-
);
|
|
174
142
|
|
|
175
143
|
type FormulaModelResponse = {rows: {value: number}[]};
|
|
176
144
|
|
|
177
145
|
return executeModel({
|
|
178
146
|
model: 'formula',
|
|
179
147
|
source: {
|
|
180
|
-
...
|
|
181
|
-
spatialFiltersResolution,
|
|
148
|
+
...this.getModelSource(filters, filterOwner),
|
|
182
149
|
spatialFiltersMode,
|
|
183
150
|
spatialFilter,
|
|
184
151
|
},
|
|
@@ -187,7 +154,7 @@ export abstract class WidgetRemoteSource<
|
|
|
187
154
|
operation: operation ?? 'count',
|
|
188
155
|
operationExp,
|
|
189
156
|
},
|
|
190
|
-
opts: {signal, headers: this.
|
|
157
|
+
opts: {signal, headers: this.props.headers},
|
|
191
158
|
}).then((res: FormulaModelResponse) => normalizeObjectKeys(res.rows[0]));
|
|
192
159
|
}
|
|
193
160
|
|
|
@@ -200,29 +167,21 @@ export abstract class WidgetRemoteSource<
|
|
|
200
167
|
filterOwner,
|
|
201
168
|
spatialFilter,
|
|
202
169
|
spatialFiltersMode,
|
|
203
|
-
spatialIndexReferenceViewState,
|
|
204
170
|
...params
|
|
205
171
|
} = options;
|
|
206
172
|
const {column, operation, ticks} = params;
|
|
207
|
-
const source = this.getModelSource(filters, filterOwner);
|
|
208
|
-
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
209
|
-
source,
|
|
210
|
-
spatialFilter,
|
|
211
|
-
spatialIndexReferenceViewState
|
|
212
|
-
);
|
|
213
173
|
|
|
214
174
|
type HistogramModelResponse = {rows: {tick: number; value: number}[]};
|
|
215
175
|
|
|
216
176
|
const data = await executeModel({
|
|
217
177
|
model: 'histogram',
|
|
218
178
|
source: {
|
|
219
|
-
...
|
|
220
|
-
spatialFiltersResolution,
|
|
179
|
+
...this.getModelSource(filters, filterOwner),
|
|
221
180
|
spatialFiltersMode,
|
|
222
181
|
spatialFilter,
|
|
223
182
|
},
|
|
224
183
|
params: {column, operation, ticks},
|
|
225
|
-
opts: {signal, headers: this.
|
|
184
|
+
opts: {signal, headers: this.props.headers},
|
|
226
185
|
}).then((res: HistogramModelResponse) => normalizeObjectKeys(res.rows));
|
|
227
186
|
|
|
228
187
|
if (data.length) {
|
|
@@ -245,29 +204,21 @@ export abstract class WidgetRemoteSource<
|
|
|
245
204
|
filterOwner,
|
|
246
205
|
spatialFilter,
|
|
247
206
|
spatialFiltersMode,
|
|
248
|
-
spatialIndexReferenceViewState,
|
|
249
207
|
...params
|
|
250
208
|
} = options;
|
|
251
209
|
const {column} = params;
|
|
252
|
-
const source = this.getModelSource(filters, filterOwner);
|
|
253
|
-
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
254
|
-
source,
|
|
255
|
-
spatialFilter,
|
|
256
|
-
spatialIndexReferenceViewState
|
|
257
|
-
);
|
|
258
210
|
|
|
259
211
|
type RangeModelResponse = {rows: {min: number; max: number}[]};
|
|
260
212
|
|
|
261
213
|
return executeModel({
|
|
262
214
|
model: 'range',
|
|
263
215
|
source: {
|
|
264
|
-
...
|
|
265
|
-
spatialFiltersResolution,
|
|
216
|
+
...this.getModelSource(filters, filterOwner),
|
|
266
217
|
spatialFiltersMode,
|
|
267
218
|
spatialFilter,
|
|
268
219
|
},
|
|
269
220
|
params: {column},
|
|
270
|
-
opts: {signal, headers: this.
|
|
221
|
+
opts: {signal, headers: this.props.headers},
|
|
271
222
|
}).then((res: RangeModelResponse) => normalizeObjectKeys(res.rows[0]));
|
|
272
223
|
}
|
|
273
224
|
|
|
@@ -278,19 +229,11 @@ export abstract class WidgetRemoteSource<
|
|
|
278
229
|
filterOwner,
|
|
279
230
|
spatialFilter,
|
|
280
231
|
spatialFiltersMode,
|
|
281
|
-
spatialIndexReferenceViewState,
|
|
282
232
|
...params
|
|
283
233
|
} = options;
|
|
284
234
|
const {xAxisColumn, xAxisJoinOperation, yAxisColumn, yAxisJoinOperation} =
|
|
285
235
|
params;
|
|
286
236
|
|
|
287
|
-
const source = this.getModelSource(filters, filterOwner);
|
|
288
|
-
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
289
|
-
source,
|
|
290
|
-
spatialFilter,
|
|
291
|
-
spatialIndexReferenceViewState
|
|
292
|
-
);
|
|
293
|
-
|
|
294
237
|
// Make sure this is sync with the same constant in cloud-native/maps-api
|
|
295
238
|
const HARD_LIMIT = 500;
|
|
296
239
|
|
|
@@ -299,8 +242,7 @@ export abstract class WidgetRemoteSource<
|
|
|
299
242
|
return executeModel({
|
|
300
243
|
model: 'scatterplot',
|
|
301
244
|
source: {
|
|
302
|
-
...
|
|
303
|
-
spatialFiltersResolution,
|
|
245
|
+
...this.getModelSource(filters, filterOwner),
|
|
304
246
|
spatialFiltersMode,
|
|
305
247
|
spatialFilter,
|
|
306
248
|
},
|
|
@@ -311,7 +253,7 @@ export abstract class WidgetRemoteSource<
|
|
|
311
253
|
yAxisJoinOperation,
|
|
312
254
|
limit: HARD_LIMIT,
|
|
313
255
|
},
|
|
314
|
-
opts: {signal, headers: this.
|
|
256
|
+
opts: {signal, headers: this.props.headers},
|
|
315
257
|
})
|
|
316
258
|
.then((res: ScatterModelResponse) => normalizeObjectKeys(res.rows))
|
|
317
259
|
.then((res) => res.map(({x, y}: {x: number; y: number}) => [x, y]));
|
|
@@ -324,16 +266,9 @@ export abstract class WidgetRemoteSource<
|
|
|
324
266
|
filterOwner,
|
|
325
267
|
spatialFilter,
|
|
326
268
|
spatialFiltersMode,
|
|
327
|
-
spatialIndexReferenceViewState,
|
|
328
269
|
...params
|
|
329
270
|
} = options;
|
|
330
271
|
const {columns, sortBy, sortDirection, offset = 0, limit = 10} = params;
|
|
331
|
-
const source = this.getModelSource(filters, filterOwner);
|
|
332
|
-
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
333
|
-
source,
|
|
334
|
-
spatialFilter,
|
|
335
|
-
spatialIndexReferenceViewState
|
|
336
|
-
);
|
|
337
272
|
|
|
338
273
|
type TableModelResponse = {
|
|
339
274
|
rows: Record<string, number | string>[];
|
|
@@ -343,8 +278,7 @@ export abstract class WidgetRemoteSource<
|
|
|
343
278
|
return executeModel({
|
|
344
279
|
model: 'table',
|
|
345
280
|
source: {
|
|
346
|
-
...
|
|
347
|
-
spatialFiltersResolution,
|
|
281
|
+
...this.getModelSource(filters, filterOwner),
|
|
348
282
|
spatialFiltersMode,
|
|
349
283
|
spatialFilter,
|
|
350
284
|
},
|
|
@@ -355,7 +289,7 @@ export abstract class WidgetRemoteSource<
|
|
|
355
289
|
limit,
|
|
356
290
|
offset,
|
|
357
291
|
},
|
|
358
|
-
opts: {signal, headers: this.
|
|
292
|
+
opts: {signal, headers: this.props.headers},
|
|
359
293
|
}).then((res: TableModelResponse) => ({
|
|
360
294
|
// Avoid `normalizeObjectKeys()`, which changes column names.
|
|
361
295
|
rows: res.rows ?? (res as any).ROWS,
|
|
@@ -372,7 +306,6 @@ export abstract class WidgetRemoteSource<
|
|
|
372
306
|
filterOwner,
|
|
373
307
|
spatialFilter,
|
|
374
308
|
spatialFiltersMode,
|
|
375
|
-
spatialIndexReferenceViewState,
|
|
376
309
|
...params
|
|
377
310
|
} = options;
|
|
378
311
|
const {
|
|
@@ -387,13 +320,6 @@ export abstract class WidgetRemoteSource<
|
|
|
387
320
|
splitByCategoryValues,
|
|
388
321
|
} = params;
|
|
389
322
|
|
|
390
|
-
const source = this.getModelSource(filters, filterOwner);
|
|
391
|
-
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
392
|
-
source,
|
|
393
|
-
spatialFilter,
|
|
394
|
-
spatialIndexReferenceViewState
|
|
395
|
-
);
|
|
396
|
-
|
|
397
323
|
type TimeSeriesModelResponse = {
|
|
398
324
|
rows: {name: string; value: number}[];
|
|
399
325
|
metadata: {categories: string[]};
|
|
@@ -402,8 +328,7 @@ export abstract class WidgetRemoteSource<
|
|
|
402
328
|
return executeModel({
|
|
403
329
|
model: 'timeseries',
|
|
404
330
|
source: {
|
|
405
|
-
...
|
|
406
|
-
spatialFiltersResolution,
|
|
331
|
+
...this.getModelSource(filters, filterOwner),
|
|
407
332
|
spatialFiltersMode,
|
|
408
333
|
spatialFilter,
|
|
409
334
|
},
|
|
@@ -418,7 +343,7 @@ export abstract class WidgetRemoteSource<
|
|
|
418
343
|
splitByCategoryLimit,
|
|
419
344
|
splitByCategoryValues,
|
|
420
345
|
},
|
|
421
|
-
opts: {signal, headers: this.
|
|
346
|
+
opts: {signal, headers: this.props.headers},
|
|
422
347
|
}).then((res: TimeSeriesModelResponse) => ({
|
|
423
348
|
rows: normalizeObjectKeys(res.rows),
|
|
424
349
|
categories: res.metadata?.categories,
|
|
@@ -15,14 +15,11 @@ import {
|
|
|
15
15
|
TableResponse,
|
|
16
16
|
TimeSeriesRequestOptions,
|
|
17
17
|
TimeSeriesResponse,
|
|
18
|
-
ViewState,
|
|
19
18
|
} from './types.js';
|
|
20
|
-
import {FilterLogicalOperator, Filter
|
|
19
|
+
import {FilterLogicalOperator, Filter} from '../types.js';
|
|
21
20
|
import {getClient} from '../client.js';
|
|
22
|
-
import {ModelSource} from '../models/model.js';
|
|
23
21
|
import {SourceOptions} from '../sources/index.js';
|
|
24
22
|
import {ApiVersion, DEFAULT_API_BASE_URL} from '../constants.js';
|
|
25
|
-
import {getSpatialFiltersResolution} from '../spatial-index.js';
|
|
26
23
|
|
|
27
24
|
export interface WidgetSourceProps extends Omit<SourceOptions, 'filters'> {
|
|
28
25
|
apiVersion?: ApiVersion;
|
|
@@ -35,7 +32,9 @@ export interface WidgetSourceProps extends Omit<SourceOptions, 'filters'> {
|
|
|
35
32
|
*
|
|
36
33
|
* Abstract class. Use {@link WidgetQuerySource} or {@link WidgetTableSource}.
|
|
37
34
|
*/
|
|
38
|
-
export abstract class WidgetSource<
|
|
35
|
+
export abstract class WidgetSource<
|
|
36
|
+
Props extends WidgetSourceProps = WidgetSourceProps,
|
|
37
|
+
> {
|
|
39
38
|
readonly props: Props;
|
|
40
39
|
|
|
41
40
|
static defaultProps: Partial<WidgetSourceProps> = {
|
|
@@ -47,7 +46,11 @@ export abstract class WidgetSource<Props extends WidgetSourceProps> {
|
|
|
47
46
|
};
|
|
48
47
|
|
|
49
48
|
constructor(props: Props) {
|
|
50
|
-
this.props = {
|
|
49
|
+
this.props = {
|
|
50
|
+
...WidgetSource.defaultProps,
|
|
51
|
+
clientId: getClient(), // Refresh clientId, default may have changed.
|
|
52
|
+
...props,
|
|
53
|
+
};
|
|
51
54
|
}
|
|
52
55
|
|
|
53
56
|
/**
|
|
@@ -61,25 +64,6 @@ export abstract class WidgetSource<Props extends WidgetSourceProps> {
|
|
|
61
64
|
// no-op in most cases, but required for worker sources.
|
|
62
65
|
}
|
|
63
66
|
|
|
64
|
-
protected _getSpatialFiltersResolution(
|
|
65
|
-
source: Omit<ModelSource, 'type' | 'data'>,
|
|
66
|
-
spatialFilter?: SpatialFilter,
|
|
67
|
-
referenceViewState?: ViewState
|
|
68
|
-
): number | undefined {
|
|
69
|
-
// spatialFiltersResolution applies only to spatial index sources.
|
|
70
|
-
if (!spatialFilter || source.spatialDataType === 'geo') {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (!referenceViewState) {
|
|
75
|
-
throw new Error(
|
|
76
|
-
'Missing required option, "spatialIndexReferenceViewState".'
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return getSpatialFiltersResolution(source, referenceViewState);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
67
|
/**
|
|
84
68
|
* Returns a list of labeled datapoints for categorical data. Suitable for
|
|
85
69
|
* charts including grouped bar charts, pie charts, and tree charts.
|