@carto/api-client 0.4.3 → 0.5.0-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 +4 -0
- package/build/api/query.d.ts +1 -1
- package/build/api-client.cjs +2388 -261
- package/build/api-client.cjs.map +1 -1
- package/build/api-client.modern.js +2237 -262
- package/build/api-client.modern.js.map +1 -1
- package/build/constants.d.ts +22 -0
- package/build/filters/Filter.d.ts +13 -0
- package/build/filters/FilterTypes.d.ts +3 -0
- package/build/filters/geosjonFeatures.d.ts +8 -0
- package/build/filters/index.d.ts +6 -0
- package/build/filters/tileFeatures.d.ts +20 -0
- package/build/filters/tileFeaturesGeometries.d.ts +13 -0
- package/build/filters/tileFeaturesSpatialIndex.d.ts +10 -0
- package/build/index.d.ts +4 -0
- package/build/models/index.d.ts +1 -1
- package/build/models/model.d.ts +7 -1
- package/build/operations/aggregation.d.ts +8 -0
- package/build/operations/applySorting.d.ts +20 -0
- package/build/operations/groupBy.d.ts +15 -0
- package/build/operations/groupByDate.d.ts +11 -0
- package/build/operations/histogram.d.ts +13 -0
- package/build/operations/index.d.ts +6 -0
- package/build/operations/scatterPlot.d.ts +14 -0
- package/build/sources/h3-tileset-source.d.ts +2 -1
- package/build/sources/index.d.ts +1 -1
- package/build/sources/quadbin-tileset-source.d.ts +2 -1
- package/build/sources/types.d.ts +36 -41
- package/build/sources/vector-tileset-source.d.ts +2 -1
- package/build/spatial-index.d.ts +8 -0
- package/build/types-internal.d.ts +4 -0
- package/build/types.d.ts +61 -1
- package/build/utils/dateUtils.d.ts +10 -0
- package/build/utils/getTileFormat.d.ts +3 -0
- package/build/utils/makeIntervalComplete.d.ts +2 -0
- package/build/utils/transformTileCoordsToWGS84.d.ts +8 -0
- package/build/utils/transformToTileCoords.d.ts +9 -0
- package/build/utils.d.ts +1 -1
- package/build/widget-sources/index.d.ts +2 -1
- package/build/widget-sources/types.d.ts +40 -23
- package/build/widget-sources/widget-query-source.d.ts +2 -2
- package/build/widget-sources/widget-remote-source.d.ts +18 -0
- package/build/widget-sources/{widget-base-source.d.ts → widget-source.d.ts} +16 -41
- package/build/widget-sources/widget-table-source.d.ts +2 -2
- package/build/widget-sources/widget-tileset-source.d.ts +67 -0
- package/package.json +36 -35
- package/src/api/query.ts +1 -2
- package/src/constants.ts +25 -0
- package/src/filters/Filter.ts +169 -0
- package/src/filters/FilterTypes.ts +109 -0
- package/src/filters/geosjonFeatures.ts +32 -0
- package/src/filters/index.ts +6 -0
- package/src/filters/tileFeatures.ts +56 -0
- package/src/filters/tileFeaturesGeometries.ts +444 -0
- package/src/filters/tileFeaturesSpatialIndex.ts +119 -0
- package/src/index.ts +6 -0
- package/src/models/index.ts +1 -1
- package/src/models/model.ts +47 -24
- package/src/operations/aggregation.ts +154 -0
- package/src/operations/applySorting.ts +109 -0
- package/src/operations/groupBy.ts +59 -0
- package/src/operations/groupByDate.ts +98 -0
- package/src/operations/histogram.ts +66 -0
- package/src/operations/index.ts +6 -0
- package/src/operations/scatterPlot.ts +50 -0
- package/src/sources/h3-query-source.ts +7 -1
- package/src/sources/h3-table-source.ts +6 -1
- package/src/sources/h3-tileset-source.ts +18 -6
- package/src/sources/index.ts +1 -1
- package/src/sources/quadbin-query-source.ts +6 -1
- package/src/sources/quadbin-table-source.ts +6 -1
- package/src/sources/quadbin-tileset-source.ts +18 -6
- package/src/sources/raster-source.ts +1 -0
- package/src/sources/types.ts +41 -45
- package/src/sources/vector-query-source.ts +10 -3
- package/src/sources/vector-table-source.ts +10 -3
- package/src/sources/vector-tileset-source.ts +19 -6
- package/src/spatial-index.ts +111 -0
- package/src/types-internal.ts +6 -0
- package/src/types.ts +60 -2
- package/src/utils/dateUtils.ts +28 -0
- package/src/utils/getTileFormat.ts +9 -0
- package/src/utils/makeIntervalComplete.ts +17 -0
- package/src/utils/transformTileCoordsToWGS84.ts +77 -0
- package/src/utils/transformToTileCoords.ts +85 -0
- package/src/utils.ts +9 -6
- package/src/widget-sources/index.ts +2 -1
- package/src/widget-sources/types.ts +42 -23
- package/src/widget-sources/widget-query-source.ts +6 -3
- package/src/widget-sources/{widget-base-source.ts → widget-remote-source.ts} +169 -144
- package/src/widget-sources/widget-source.ts +160 -0
- package/src/widget-sources/widget-table-source.ts +6 -3
- package/src/widget-sources/widget-tileset-source.ts +396 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import {lngLatToWorld} from '@math.gl/web-mercator';
|
|
2
|
+
import {BBox, GeoJsonGeometryTypes, Geometry, Position} from 'geojson';
|
|
3
|
+
|
|
4
|
+
type TransformFn = (coordinates: any[], bbox: Position[]) => any[];
|
|
5
|
+
|
|
6
|
+
const TRANSFORM_FN: Record<
|
|
7
|
+
Exclude<GeoJsonGeometryTypes, 'GeometryCollection'>,
|
|
8
|
+
TransformFn
|
|
9
|
+
> = {
|
|
10
|
+
Point: transformPoint,
|
|
11
|
+
MultiPoint: transformMultiPoint,
|
|
12
|
+
LineString: transformLineString,
|
|
13
|
+
MultiLineString: transformMultiLineString,
|
|
14
|
+
Polygon: transformPolygon,
|
|
15
|
+
MultiPolygon: transformMultiPolygon,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Transform WGS84 coordinates to tile coords.
|
|
20
|
+
* It's the inverse of deck.gl coordinate-transform (https://github.com/visgl/deck.gl/blob/master/modules/geo-layers/src/mvt-layer/coordinate-transform.js)
|
|
21
|
+
*
|
|
22
|
+
* @param geometry - any valid geojson geometry
|
|
23
|
+
* @param bbox - geojson bbox
|
|
24
|
+
*/
|
|
25
|
+
export function transformToTileCoords<T extends Geometry>(
|
|
26
|
+
geometry: T,
|
|
27
|
+
bbox: BBox
|
|
28
|
+
): T {
|
|
29
|
+
const [west, south, east, north] = bbox;
|
|
30
|
+
const nw = projectFlat([west, north]);
|
|
31
|
+
const se = projectFlat([east, south]);
|
|
32
|
+
const projectedBbox = [nw, se];
|
|
33
|
+
|
|
34
|
+
if (geometry.type === 'GeometryCollection') {
|
|
35
|
+
throw new Error('Unsupported geometry type GeometryCollection');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const transformFn = TRANSFORM_FN[geometry.type];
|
|
39
|
+
const coordinates = transformFn(geometry.coordinates, projectedBbox);
|
|
40
|
+
return {...geometry, coordinates};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function transformPoint([pointX, pointY]: Position, [nw, se]: Position[]) {
|
|
44
|
+
const x = inverseLerp(nw[0], se[0], pointX);
|
|
45
|
+
const y = inverseLerp(nw[1], se[1], pointY);
|
|
46
|
+
|
|
47
|
+
return [x, y];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function getPoints(geometry: Position[], bbox: Position[]) {
|
|
51
|
+
return geometry.map((g) => transformPoint(projectFlat(g), bbox));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function transformMultiPoint(multiPoint: Position[], bbox: Position[]) {
|
|
55
|
+
return getPoints(multiPoint, bbox);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function transformLineString(line: Position[], bbox: Position[]) {
|
|
59
|
+
return getPoints(line, bbox);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function transformMultiLineString(
|
|
63
|
+
multiLineString: Position[][],
|
|
64
|
+
bbox: Position[]
|
|
65
|
+
) {
|
|
66
|
+
return multiLineString.map((lineString) =>
|
|
67
|
+
transformLineString(lineString, bbox)
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function transformPolygon(polygon: Position[][], bbox: Position[]) {
|
|
72
|
+
return polygon.map((polygonRing) => getPoints(polygonRing, bbox));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function transformMultiPolygon(multiPolygon: Position[][][], bbox: Position[]) {
|
|
76
|
+
return multiPolygon.map((polygon) => transformPolygon(polygon, bbox));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function projectFlat(xyz: Position): Position {
|
|
80
|
+
return lngLatToWorld(xyz);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function inverseLerp(a: number, b: number, x: number): number {
|
|
84
|
+
return (x - a) / (b - a);
|
|
85
|
+
}
|
package/src/utils.ts
CHANGED
|
@@ -49,15 +49,18 @@ export function normalizeObjectKeys<T, R extends Row<T>>(el: R): R {
|
|
|
49
49
|
return el;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
return Object.entries(el as Record<string, T>).reduce(
|
|
53
|
-
acc[key
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
return Object.entries(el as Record<string, T>).reduce(
|
|
53
|
+
(acc, [key, value]) => {
|
|
54
|
+
acc[key.toLowerCase()] =
|
|
55
|
+
typeof value === 'object' && value ? normalizeObjectKeys(value) : value;
|
|
56
|
+
return acc;
|
|
57
|
+
},
|
|
58
|
+
{} as Record<string, T>
|
|
59
|
+
) as R;
|
|
57
60
|
}
|
|
58
61
|
|
|
59
62
|
/** @internalRemarks Source: @carto/react-core */
|
|
60
|
-
export function assert(condition: unknown, message: string) {
|
|
63
|
+
export function assert(condition: unknown, message: string): asserts condition {
|
|
61
64
|
if (!condition) {
|
|
62
65
|
throw new Error(message);
|
|
63
66
|
}
|
|
@@ -1,31 +1,43 @@
|
|
|
1
|
-
import {TileResolution} from '../sources/types';
|
|
1
|
+
import {SpatialFilterPolyfillMode, TileResolution} from '../sources/types';
|
|
2
2
|
import {
|
|
3
3
|
GroupDateType,
|
|
4
4
|
SortColumnType,
|
|
5
5
|
SortDirection,
|
|
6
6
|
SpatialFilter,
|
|
7
7
|
} from '../types';
|
|
8
|
+
import type {WidgetRemoteSource} from './widget-remote-source';
|
|
8
9
|
|
|
9
10
|
/******************************************************************************
|
|
10
11
|
* WIDGET API REQUESTS
|
|
11
12
|
*/
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
export interface ViewState {
|
|
15
|
+
zoom: number;
|
|
16
|
+
latitude: number;
|
|
17
|
+
longitude: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Common options for {@link WidgetRemoteSource} requests. */
|
|
14
21
|
interface BaseRequestOptions {
|
|
15
22
|
spatialFilter?: SpatialFilter;
|
|
23
|
+
spatialFiltersMode?: SpatialFilterPolyfillMode;
|
|
24
|
+
/** Required for table- and query-based spatial index sources (H3, Quadbin). */
|
|
25
|
+
spatialIndexReferenceViewState?: ViewState;
|
|
16
26
|
abortController?: AbortController;
|
|
17
27
|
filterOwner?: string;
|
|
18
28
|
}
|
|
19
29
|
|
|
20
|
-
/** Options for {@link
|
|
30
|
+
/** Options for {@link WidgetRemoteSource#getCategories}. */
|
|
21
31
|
export interface CategoryRequestOptions extends BaseRequestOptions {
|
|
22
32
|
column: string;
|
|
23
33
|
operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
24
34
|
operationColumn?: string;
|
|
35
|
+
/** Local only. */
|
|
36
|
+
joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
25
37
|
}
|
|
26
38
|
|
|
27
39
|
/**
|
|
28
|
-
* Options for {@link
|
|
40
|
+
* Options for {@link WidgetRemoteSource#getFeatures}.
|
|
29
41
|
* @experimental
|
|
30
42
|
* @internal
|
|
31
43
|
*/
|
|
@@ -67,26 +79,29 @@ export interface FeaturesRequestOptions extends BaseRequestOptions {
|
|
|
67
79
|
tileResolution?: TileResolution;
|
|
68
80
|
}
|
|
69
81
|
|
|
70
|
-
/** Options for {@link
|
|
82
|
+
/** Options for {@link WidgetRemoteSource#getFormula}. */
|
|
71
83
|
export interface FormulaRequestOptions extends BaseRequestOptions {
|
|
72
84
|
column: string;
|
|
73
|
-
operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
85
|
+
operation?: 'count' | 'avg' | 'min' | 'max' | 'sum' | 'custom';
|
|
74
86
|
operationExp?: string;
|
|
87
|
+
joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
75
88
|
}
|
|
76
89
|
|
|
77
|
-
/** Options for {@link
|
|
90
|
+
/** Options for {@link WidgetRemoteSource#getHistogram}. */
|
|
78
91
|
export interface HistogramRequestOptions extends BaseRequestOptions {
|
|
79
92
|
column: string;
|
|
80
93
|
ticks: number[];
|
|
81
94
|
operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
95
|
+
/** Local only. */
|
|
96
|
+
joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
82
97
|
}
|
|
83
98
|
|
|
84
|
-
/** Options for {@link
|
|
99
|
+
/** Options for {@link WidgetRemoteSource#getRange}. */
|
|
85
100
|
export interface RangeRequestOptions extends BaseRequestOptions {
|
|
86
101
|
column: string;
|
|
87
102
|
}
|
|
88
103
|
|
|
89
|
-
/** Options for {@link
|
|
104
|
+
/** Options for {@link WidgetRemoteSource#getScatter}. */
|
|
90
105
|
export interface ScatterRequestOptions extends BaseRequestOptions {
|
|
91
106
|
xAxisColumn: string;
|
|
92
107
|
xAxisJoinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
@@ -94,7 +109,7 @@ export interface ScatterRequestOptions extends BaseRequestOptions {
|
|
|
94
109
|
yAxisJoinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
95
110
|
}
|
|
96
111
|
|
|
97
|
-
/** Options for {@link
|
|
112
|
+
/** Options for {@link WidgetRemoteSource#getTable}. */
|
|
98
113
|
export interface TableRequestOptions extends BaseRequestOptions {
|
|
99
114
|
columns: string[];
|
|
100
115
|
sortBy?: string;
|
|
@@ -102,12 +117,16 @@ export interface TableRequestOptions extends BaseRequestOptions {
|
|
|
102
117
|
sortByColumnType?: SortColumnType;
|
|
103
118
|
offset?: number;
|
|
104
119
|
limit?: number;
|
|
120
|
+
/** Local only. */
|
|
121
|
+
searchFilterColumn?: string;
|
|
122
|
+
/** Local only. */
|
|
123
|
+
searchFilterText?: string;
|
|
105
124
|
}
|
|
106
125
|
|
|
107
|
-
/** Options for {@link
|
|
126
|
+
/** Options for {@link WidgetRemoteSource#getTimeSeries}. */
|
|
108
127
|
export interface TimeSeriesRequestOptions extends BaseRequestOptions {
|
|
109
128
|
column: string;
|
|
110
|
-
stepSize
|
|
129
|
+
stepSize: GroupDateType;
|
|
111
130
|
stepMultiplier?: number;
|
|
112
131
|
operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
113
132
|
operationColumn?: string;
|
|
@@ -122,35 +141,35 @@ export interface TimeSeriesRequestOptions extends BaseRequestOptions {
|
|
|
122
141
|
*/
|
|
123
142
|
|
|
124
143
|
/**
|
|
125
|
-
* Response from {@link
|
|
144
|
+
* Response from {@link WidgetRemoteSource#getFeatures}.
|
|
126
145
|
* @experimental
|
|
127
146
|
* @internal
|
|
128
147
|
*/
|
|
129
148
|
export type FeaturesResponse = {rows: Record<string, unknown>[]};
|
|
130
149
|
|
|
131
|
-
/** Response from {@link
|
|
132
|
-
export type FormulaResponse = {value: number};
|
|
150
|
+
/** Response from {@link WidgetRemoteSource#getFormula}. */
|
|
151
|
+
export type FormulaResponse = {value: number | null};
|
|
133
152
|
|
|
134
|
-
/** Response from {@link
|
|
153
|
+
/** Response from {@link WidgetRemoteSource#getCategories}. */
|
|
135
154
|
export type CategoryResponse = {name: string; value: number}[];
|
|
136
155
|
|
|
137
|
-
/** Response from {@link
|
|
138
|
-
export type RangeResponse = {min: number; max: number};
|
|
156
|
+
/** Response from {@link WidgetRemoteSource#getRange}. */
|
|
157
|
+
export type RangeResponse = {min: number; max: number} | null;
|
|
139
158
|
|
|
140
|
-
/** Response from {@link
|
|
159
|
+
/** Response from {@link WidgetRemoteSource#getTable}. */
|
|
141
160
|
export type TableResponse = {
|
|
142
161
|
totalCount: number;
|
|
143
162
|
rows: Record<string, number | string>[];
|
|
144
163
|
};
|
|
145
164
|
|
|
146
|
-
/** Response from {@link
|
|
165
|
+
/** Response from {@link WidgetRemoteSource#getScatter}. */
|
|
147
166
|
export type ScatterResponse = [number, number][];
|
|
148
167
|
|
|
149
|
-
/** Response from {@link
|
|
168
|
+
/** Response from {@link WidgetRemoteSource#getTimeSeries}. */
|
|
150
169
|
export type TimeSeriesResponse = {
|
|
151
170
|
rows: {name: string; value: number}[];
|
|
152
|
-
categories
|
|
171
|
+
categories?: string[];
|
|
153
172
|
};
|
|
154
173
|
|
|
155
|
-
/** Response from {@link
|
|
174
|
+
/** Response from {@link WidgetRemoteSource#getHistogram}. */
|
|
156
175
|
export type HistogramResponse = number[];
|
|
@@ -3,7 +3,10 @@ import {
|
|
|
3
3
|
QuadbinQuerySourceOptions,
|
|
4
4
|
VectorQuerySourceOptions,
|
|
5
5
|
} from '../sources/index.js';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
WidgetRemoteSource,
|
|
8
|
+
WidgetRemoteSourceProps,
|
|
9
|
+
} from './widget-remote-source.js';
|
|
7
10
|
import {ModelSource} from '../models/model.js';
|
|
8
11
|
|
|
9
12
|
type LayerQuerySourceOptions =
|
|
@@ -35,8 +38,8 @@ export type WidgetQuerySourceResult = {widgetSource: WidgetQuerySource};
|
|
|
35
38
|
* const { widgetSource } = await data;
|
|
36
39
|
* ```
|
|
37
40
|
*/
|
|
38
|
-
export class WidgetQuerySource extends
|
|
39
|
-
LayerQuerySourceOptions &
|
|
41
|
+
export class WidgetQuerySource extends WidgetRemoteSource<
|
|
42
|
+
LayerQuerySourceOptions & WidgetRemoteSourceProps
|
|
40
43
|
> {
|
|
41
44
|
protected override getModelSource(owner: string): ModelSource {
|
|
42
45
|
return {
|