@carto/api-client 0.4.6 → 0.4.7-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 +17 -1
- package/build/api/carto-api-error.d.ts +1 -1
- package/build/api/query.d.ts +1 -1
- package/build/api/request-with-parameters.d.ts +2 -2
- package/build/api-client.cjs +2365 -279
- package/build/api-client.cjs.map +1 -1
- package/build/api-client.modern.js +2274 -298
- package/build/api-client.modern.js.map +1 -1
- package/build/client.d.ts +2 -2
- package/build/constants-internal.d.ts +5 -5
- package/build/constants.d.ts +25 -3
- package/build/deck/get-data-filter-extension-props.d.ts +28 -0
- package/build/deck/index.d.ts +1 -0
- package/build/filters/Filter.d.ts +25 -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/filters.d.ts +2 -2
- package/build/geo.d.ts +1 -1
- package/build/index.d.ts +5 -0
- package/build/models/common.d.ts +5 -4
- package/build/models/index.d.ts +1 -1
- package/build/models/model.d.ts +2 -2
- 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/base-source.d.ts +2 -2
- package/build/sources/boundary-query-source.d.ts +1 -1
- package/build/sources/boundary-table-source.d.ts +1 -1
- package/build/sources/h3-query-source.d.ts +2 -2
- package/build/sources/h3-table-source.d.ts +2 -2
- package/build/sources/h3-tileset-source.d.ts +1 -1
- package/build/sources/index.d.ts +26 -26
- package/build/sources/quadbin-query-source.d.ts +2 -2
- package/build/sources/quadbin-table-source.d.ts +2 -2
- package/build/sources/quadbin-tileset-source.d.ts +1 -1
- package/build/sources/raster-source.d.ts +1 -1
- package/build/sources/types.d.ts +3 -3
- package/build/sources/vector-query-source.d.ts +1 -1
- package/build/sources/vector-table-source.d.ts +1 -1
- package/build/sources/vector-tileset-source.d.ts +1 -1
- package/build/spatial-index.d.ts +3 -3
- package/build/types-internal.d.ts +9 -5
- package/build/types.d.ts +74 -14
- 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 +3 -3
- package/build/widget-sources/index.d.ts +3 -1
- package/build/widget-sources/types.d.ts +38 -25
- package/build/widget-sources/widget-query-source.d.ts +4 -3
- 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 +4 -3
- package/build/widget-sources/widget-tileset-source.d.ts +75 -0
- package/package.json +46 -29
- package/src/api/carto-api-error.ts +1 -1
- package/src/api/query.ts +5 -5
- package/src/api/request-with-parameters.ts +6 -6
- package/src/client.ts +3 -3
- package/src/constants-internal.ts +5 -5
- package/src/constants.ts +28 -3
- package/src/deck/get-data-filter-extension-props.ts +164 -0
- package/src/deck/index.ts +1 -0
- package/src/filters/Filter.ts +179 -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 +50 -0
- package/src/filters/tileFeaturesGeometries.ts +444 -0
- package/src/filters/tileFeaturesSpatialIndex.ts +119 -0
- package/src/filters.ts +4 -4
- package/src/geo.ts +12 -14
- package/src/index.ts +7 -0
- package/src/models/common.ts +11 -9
- package/src/models/index.ts +1 -1
- package/src/models/model.ts +3 -4
- 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/base-source.ts +8 -8
- package/src/sources/boundary-query-source.ts +2 -2
- package/src/sources/boundary-table-source.ts +2 -2
- package/src/sources/h3-query-source.ts +7 -5
- package/src/sources/h3-table-source.ts +7 -5
- package/src/sources/h3-tileset-source.ts +2 -2
- package/src/sources/index.ts +26 -26
- package/src/sources/quadbin-query-source.ts +7 -5
- package/src/sources/quadbin-table-source.ts +7 -5
- package/src/sources/quadbin-tileset-source.ts +2 -2
- package/src/sources/raster-source.ts +3 -2
- package/src/sources/types.ts +3 -3
- package/src/sources/vector-query-source.ts +7 -5
- package/src/sources/vector-table-source.ts +7 -5
- package/src/sources/vector-tileset-source.ts +2 -2
- package/src/spatial-index.ts +4 -5
- package/src/types-internal.ts +11 -5
- package/src/types.ts +73 -15
- 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 +3 -3
- package/src/widget-sources/index.ts +3 -1
- package/src/widget-sources/types.ts +39 -25
- package/src/widget-sources/widget-query-source.ts +12 -5
- package/src/widget-sources/{widget-base-source.ts → widget-remote-source.ts} +51 -171
- package/src/widget-sources/widget-source.ts +173 -0
- package/src/widget-sources/widget-table-source.ts +12 -5
- package/src/widget-sources/widget-tileset-source.ts +456 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { TilesetSourceOptions } from '../sources/index.js';
|
|
2
|
+
import type { ModelSource } from '../models/index.js';
|
|
3
|
+
import { CategoryRequestOptions, CategoryResponse, FeaturesResponse, FormulaRequestOptions, FormulaResponse, HistogramRequestOptions, HistogramResponse, RangeRequestOptions, RangeResponse, ScatterRequestOptions, ScatterResponse, TableRequestOptions, TableResponse, TimeSeriesRequestOptions, TimeSeriesResponse } from './types.js';
|
|
4
|
+
import { TileFormat } from '../constants.js';
|
|
5
|
+
import { Filters, SpatialFilter } from '../types.js';
|
|
6
|
+
import { TileFeatureExtractOptions } from '../filters/index.js';
|
|
7
|
+
import { FeatureCollection } from 'geojson';
|
|
8
|
+
import { SpatialDataType } from '../sources/types.js';
|
|
9
|
+
import { WidgetSource, WidgetSourceProps } from './widget-source.js';
|
|
10
|
+
export type WidgetTilesetSourceProps = WidgetSourceProps & Omit<TilesetSourceOptions, 'filters'> & {
|
|
11
|
+
tileFormat: TileFormat;
|
|
12
|
+
spatialDataType: SpatialDataType;
|
|
13
|
+
};
|
|
14
|
+
export type WidgetTilesetSourceResult = {
|
|
15
|
+
widgetSource: WidgetTilesetSource;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Source for Widget API requests on a data source defined by a tileset.
|
|
19
|
+
*
|
|
20
|
+
* Generally not intended to be constructed directly. Instead, call
|
|
21
|
+
* {@link vectorTilesetSource}, {@link h3TilesetSource}, or {@link quadbinTilesetSource},
|
|
22
|
+
* which can be shared with map layers. Sources contain a `widgetSource`
|
|
23
|
+
* property, for use by widget implementations.
|
|
24
|
+
*
|
|
25
|
+
* Example:
|
|
26
|
+
*
|
|
27
|
+
* ```javascript
|
|
28
|
+
* import { vectorTilesetSource } from '@carto/api-client';
|
|
29
|
+
*
|
|
30
|
+
* const data = vectorTilesetSource({
|
|
31
|
+
* accessToken: '••••',
|
|
32
|
+
* connectionName: 'carto_dw',
|
|
33
|
+
* tableName: 'carto-demo-data.demo_rasters.my_tileset_source'
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* const { widgetSource } = await data;
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare class WidgetTilesetSource extends WidgetSource<WidgetTilesetSourceProps> {
|
|
40
|
+
private _tiles;
|
|
41
|
+
private _features;
|
|
42
|
+
private _tileFeatureExtractOptions;
|
|
43
|
+
private _tileFeatureExtractPreviousInputs;
|
|
44
|
+
protected getModelSource(filters: Filters | undefined, filterOwner: string): ModelSource;
|
|
45
|
+
/**
|
|
46
|
+
* Loads features as a list of tiles (typically provided by deck.gl).
|
|
47
|
+
* After tiles are loaded, {@link extractTileFeatures} must be called
|
|
48
|
+
* before computing statistics on the tiles.
|
|
49
|
+
*/
|
|
50
|
+
loadTiles(tiles: unknown[]): void;
|
|
51
|
+
/** Configures options used to extract features from tiles. */
|
|
52
|
+
setTileFeatureExtractOptions(options: TileFeatureExtractOptions): void;
|
|
53
|
+
protected _extractTileFeatures(spatialFilter: SpatialFilter): void;
|
|
54
|
+
/**
|
|
55
|
+
* Loads features as GeoJSON (used for testing).
|
|
56
|
+
* @experimental
|
|
57
|
+
* @internal Not for public use. Spatial filters in other method calls will be ignored.
|
|
58
|
+
*/
|
|
59
|
+
loadGeoJSON({ geojson, spatialFilter, }: {
|
|
60
|
+
geojson: FeatureCollection;
|
|
61
|
+
spatialFilter: SpatialFilter;
|
|
62
|
+
}): void;
|
|
63
|
+
getFeatures(): Promise<FeaturesResponse>;
|
|
64
|
+
getFormula({ column, operation, joinOperation, filters, filterOwner, spatialFilter, }: FormulaRequestOptions): Promise<FormulaResponse>;
|
|
65
|
+
getHistogram({ operation, ticks, column, joinOperation, filters, filterOwner, spatialFilter, }: HistogramRequestOptions): Promise<HistogramResponse>;
|
|
66
|
+
getCategories({ column, operation, operationColumn, joinOperation, filters, filterOwner, spatialFilter, }: CategoryRequestOptions): Promise<CategoryResponse>;
|
|
67
|
+
getScatter({ xAxisColumn, yAxisColumn, xAxisJoinOperation, yAxisJoinOperation, filters, filterOwner, spatialFilter, }: ScatterRequestOptions): Promise<ScatterResponse>;
|
|
68
|
+
getTable({ columns, searchFilterColumn, searchFilterText, sortBy, sortDirection, sortByColumnType, offset, limit, filters, filterOwner, spatialFilter, }: TableRequestOptions): Promise<TableResponse>;
|
|
69
|
+
getTimeSeries({ column, stepSize, operation, operationColumn, joinOperation, filters, filterOwner, spatialFilter, }: TimeSeriesRequestOptions): Promise<TimeSeriesResponse>;
|
|
70
|
+
getRange({ column, filters, filterOwner, spatialFilter, }: RangeRequestOptions): Promise<RangeResponse>;
|
|
71
|
+
/****************************************************************************
|
|
72
|
+
* INTERNAL
|
|
73
|
+
*/
|
|
74
|
+
private _getFilteredFeatures;
|
|
75
|
+
}
|
package/package.json
CHANGED
|
@@ -8,11 +8,10 @@
|
|
|
8
8
|
"homepage": "https://github.com/CartoDB/carto-api-client#readme",
|
|
9
9
|
"author": "Don McCurdy <donmccurdy@carto.com>",
|
|
10
10
|
"packageManager": "yarn@4.3.1",
|
|
11
|
-
"version": "0.4.
|
|
11
|
+
"version": "0.4.7-alpha.0",
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"publishConfig": {
|
|
14
|
-
"access": "public"
|
|
15
|
-
"tag": "alpha"
|
|
14
|
+
"access": "public"
|
|
16
15
|
},
|
|
17
16
|
"type": "module",
|
|
18
17
|
"sideEffects": false,
|
|
@@ -39,8 +38,10 @@
|
|
|
39
38
|
"test": "vitest run --typecheck",
|
|
40
39
|
"test:watch": "vitest watch --typecheck",
|
|
41
40
|
"coverage": "vitest run --coverage.enabled --coverage.all false",
|
|
42
|
-
"
|
|
43
|
-
"
|
|
41
|
+
"benchmark": "node scripts/benchmark.js",
|
|
42
|
+
"lint": "eslint .",
|
|
43
|
+
"format": "prettier \"**/*.{cjs,html,js,json,md,ts}\" --write",
|
|
44
|
+
"format:check": "prettier \"**/*.{cjs,html,js,json,md,ts}\" --check",
|
|
44
45
|
"clean": "rimraf build/*",
|
|
45
46
|
"postversion": "yarn postversion:check && yarn postversion:commit && yarn postversion:push",
|
|
46
47
|
"postversion:check": "yarn lint && yarn test",
|
|
@@ -56,45 +57,61 @@
|
|
|
56
57
|
"LICENSE.md"
|
|
57
58
|
],
|
|
58
59
|
"dependencies": {
|
|
59
|
-
"@
|
|
60
|
-
"@turf/bbox-
|
|
61
|
-
"@turf/
|
|
62
|
-
"@turf/
|
|
63
|
-
"@turf/
|
|
64
|
-
"@
|
|
60
|
+
"@loaders.gl/schema": "^4.3.3",
|
|
61
|
+
"@turf/bbox-clip": "^7.2.0",
|
|
62
|
+
"@turf/bbox-polygon": "^7.2.0",
|
|
63
|
+
"@turf/boolean-equal": "^7.2.0",
|
|
64
|
+
"@turf/boolean-intersects": "^7.2.0",
|
|
65
|
+
"@turf/boolean-within": "^7.2.0",
|
|
66
|
+
"@turf/helpers": "^7.2.0",
|
|
67
|
+
"@turf/intersect": "^7.2.0",
|
|
68
|
+
"@turf/invariant": "^7.2.0",
|
|
69
|
+
"@turf/union": "^7.2.0",
|
|
70
|
+
"@types/geojson": "^7946.0.16",
|
|
71
|
+
"h3-js": "4.1.0"
|
|
65
72
|
},
|
|
66
73
|
"devDependencies": {
|
|
67
|
-
"@deck.gl/aggregation-layers": "
|
|
68
|
-
"@deck.gl/carto": "
|
|
69
|
-
"@deck.gl/core": "
|
|
70
|
-
"@deck.gl/extensions": "
|
|
71
|
-
"@deck.gl/geo-layers": "
|
|
72
|
-
"@deck.gl/layers": "
|
|
73
|
-
"@deck.gl/mesh-layers": "
|
|
74
|
-
"@
|
|
75
|
-
"@lit/
|
|
74
|
+
"@deck.gl/aggregation-layers": "~9.1.0",
|
|
75
|
+
"@deck.gl/carto": "~9.1.0",
|
|
76
|
+
"@deck.gl/core": "~9.1.0",
|
|
77
|
+
"@deck.gl/extensions": "~9.1.0",
|
|
78
|
+
"@deck.gl/geo-layers": "~9.1.0",
|
|
79
|
+
"@deck.gl/layers": "~9.1.0",
|
|
80
|
+
"@deck.gl/mesh-layers": "~9.1.0",
|
|
81
|
+
"@eslint/js": "^9.20.0",
|
|
82
|
+
"@lit/react": "^1.0.7",
|
|
83
|
+
"@lit/task": "^1.0.2",
|
|
76
84
|
"@loaders.gl/core": "^4.3.3",
|
|
77
|
-
"@luma.gl/core": "9.0
|
|
78
|
-
"@luma.gl/engine": "9.0
|
|
85
|
+
"@luma.gl/core": "~9.1.0",
|
|
86
|
+
"@luma.gl/engine": "~9.1.0",
|
|
87
|
+
"@luma.gl/shadertools": "~9.1.0",
|
|
88
|
+
"@turf/buffer": "^7.2.0",
|
|
89
|
+
"@turf/random": "^7.2.0",
|
|
79
90
|
"@types/json-schema": "^7.0.15",
|
|
80
91
|
"@types/react": "^18.3.18",
|
|
81
92
|
"@types/semver": "^7.5.8",
|
|
82
|
-
"@vitest/coverage-istanbul": "^3.0.
|
|
93
|
+
"@vitest/coverage-istanbul": "^3.0.5",
|
|
83
94
|
"@webcomponents/webcomponentsjs": "^2.8.0",
|
|
84
95
|
"concurrently": "^9.1.2",
|
|
85
96
|
"echarts": "^5.6.0",
|
|
97
|
+
"eslint": "^9.20.1",
|
|
86
98
|
"lit": "^3.2.1",
|
|
87
99
|
"lit-analyzer": "^2.0.3",
|
|
88
|
-
"maplibre-gl": "^5.
|
|
100
|
+
"maplibre-gl": "^5.1.0",
|
|
89
101
|
"microbundle": "^0.15.1",
|
|
90
102
|
"prettier": "^3.4.2",
|
|
91
103
|
"rimraf": "^6.0.1",
|
|
92
|
-
"semver": "^7.
|
|
93
|
-
"
|
|
94
|
-
"
|
|
95
|
-
"
|
|
104
|
+
"semver": "^7.7.1",
|
|
105
|
+
"thenby": "^1.3.4",
|
|
106
|
+
"tinybench": "^3.1.1",
|
|
107
|
+
"typescript": "~5.8.2",
|
|
108
|
+
"typescript-eslint": "^8.24.0",
|
|
109
|
+
"vite": "^6.1.0",
|
|
110
|
+
"vitest": "3.0.7"
|
|
96
111
|
},
|
|
97
112
|
"resolutions": {
|
|
113
|
+
"@carto/api-client": "portal:./",
|
|
98
114
|
"rollup": "^4.20.0"
|
|
99
|
-
}
|
|
115
|
+
},
|
|
116
|
+
"stableVersion": "0.4.7"
|
|
100
117
|
}
|
package/src/api/query.ts
CHANGED
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import {SOURCE_DEFAULTS} from '../sources/index';
|
|
5
|
+
import {SOURCE_DEFAULTS} from '../sources/index.js';
|
|
6
6
|
import type {
|
|
7
7
|
SourceOptions,
|
|
8
8
|
QuerySourceOptions,
|
|
9
9
|
QueryResult,
|
|
10
|
-
} from '../sources/types';
|
|
11
|
-
import {buildQueryUrl} from './endpoints';
|
|
12
|
-
import {requestWithParameters} from './request-with-parameters';
|
|
13
|
-
import {APIErrorContext} from './carto-api-error';
|
|
10
|
+
} from '../sources/types.js';
|
|
11
|
+
import {buildQueryUrl} from './endpoints.js';
|
|
12
|
+
import {requestWithParameters} from './request-with-parameters.js';
|
|
13
|
+
import {APIErrorContext} from './carto-api-error.js';
|
|
14
14
|
|
|
15
15
|
export type QueryOptions = SourceOptions & QuerySourceOptions;
|
|
16
16
|
type UrlParameters = {q: string; queryParameters?: string};
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import {isPureObject} from '../utils';
|
|
6
|
-
import {CartoAPIError, APIErrorContext} from './carto-api-error';
|
|
7
|
-
import {V3_MINOR_VERSION} from '../constants-internal';
|
|
8
|
-
import {DEFAULT_MAX_LENGTH_URL} from '../constants-internal';
|
|
9
|
-
import {getClient} from '../client';
|
|
10
|
-
import {LocalCacheOptions} from '../sources/types';
|
|
5
|
+
import {isPureObject} from '../utils.js';
|
|
6
|
+
import {CartoAPIError, APIErrorContext} from './carto-api-error.js';
|
|
7
|
+
import {V3_MINOR_VERSION} from '../constants-internal.js';
|
|
8
|
+
import {DEFAULT_MAX_LENGTH_URL} from '../constants-internal.js';
|
|
9
|
+
import {getClient} from '../client.js';
|
|
10
|
+
import {LocalCacheOptions} from '../sources/types.js';
|
|
11
11
|
|
|
12
12
|
const DEFAULT_HEADERS = {
|
|
13
13
|
Accept: 'application/json',
|
package/src/client.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @internal
|
|
3
|
-
* @
|
|
3
|
+
* @privateRemarks Source: @carto/react-core, @carto/constants, @deck.gl/carto
|
|
4
4
|
*/
|
|
5
5
|
let client = 'deck-gl-carto';
|
|
6
6
|
|
|
@@ -8,7 +8,7 @@ let client = 'deck-gl-carto';
|
|
|
8
8
|
* Returns current client ID, used to categorize API requests. For internal use only.
|
|
9
9
|
*
|
|
10
10
|
* @internal
|
|
11
|
-
* @
|
|
11
|
+
* @privateRemarks Source: @carto/react-core
|
|
12
12
|
*/
|
|
13
13
|
export function getClient() {
|
|
14
14
|
return client;
|
|
@@ -18,7 +18,7 @@ export function getClient() {
|
|
|
18
18
|
* Sets current client ID, used to categorize API requests. For internal use only.
|
|
19
19
|
*
|
|
20
20
|
* @internal
|
|
21
|
-
* @
|
|
21
|
+
* @privateRemarks Source: @carto/react-core
|
|
22
22
|
*/
|
|
23
23
|
export function setClient(c: string) {
|
|
24
24
|
client = c;
|
|
@@ -7,26 +7,26 @@ export const API_CLIENT_VERSION = __CARTO_API_CLIENT_VERSION;
|
|
|
7
7
|
/** @internal */
|
|
8
8
|
export const V3_MINOR_VERSION = '3.4';
|
|
9
9
|
|
|
10
|
-
/** @
|
|
10
|
+
/** @privateRemarks Source: @carto/constants, @deck.gl/carto */
|
|
11
11
|
export const DEFAULT_GEO_COLUMN = 'geom';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Fastly default limit is 8192; leave some padding.
|
|
15
|
-
* @
|
|
15
|
+
* @privateRemarks Source: @deck.gl/carto
|
|
16
16
|
*/
|
|
17
17
|
export const DEFAULT_MAX_LENGTH_URL = 7000;
|
|
18
18
|
|
|
19
|
-
/** @
|
|
19
|
+
/** @privateRemarks Source: @deck.gl/carto */
|
|
20
20
|
export const DEFAULT_TILE_RESOLUTION = 0.5;
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
* @
|
|
23
|
+
* @privateRemarks Source: @deck.gl/carto
|
|
24
24
|
* @internal
|
|
25
25
|
*/
|
|
26
26
|
export const DEFAULT_AGGREGATION_RES_LEVEL_H3 = 4;
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
|
-
* @
|
|
29
|
+
* @privateRemarks Source: @deck.gl/carto
|
|
30
30
|
* @internal
|
|
31
31
|
*/
|
|
32
32
|
export const DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN = 6;
|
package/src/constants.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* };
|
|
11
11
|
* ```
|
|
12
12
|
*
|
|
13
|
-
* @
|
|
13
|
+
* @privateRemarks Source: @carto/react-api, @deck.gl/carto
|
|
14
14
|
*/
|
|
15
15
|
export enum FilterType {
|
|
16
16
|
IN = 'in',
|
|
@@ -22,12 +22,37 @@ export enum FilterType {
|
|
|
22
22
|
STRING_SEARCH = 'stringSearch',
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
/** @
|
|
25
|
+
/** @privateRemarks Source: @carto/constants */
|
|
26
26
|
export enum ApiVersion {
|
|
27
27
|
V1 = 'v1',
|
|
28
28
|
V2 = 'v2',
|
|
29
29
|
V3 = 'v3',
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
/** @
|
|
32
|
+
/** @privateRemarks Source: @carto/constants, @deck.gl/carto */
|
|
33
33
|
export const DEFAULT_API_BASE_URL = 'https://gcp-us-east1.api.carto.com';
|
|
34
|
+
|
|
35
|
+
/** @privateRemarks Source: @carto/react-core */
|
|
36
|
+
export enum TileFormat {
|
|
37
|
+
MVT = 'mvt',
|
|
38
|
+
JSON = 'json',
|
|
39
|
+
GEOJSON = 'geojson',
|
|
40
|
+
BINARY = 'binary',
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** @privateRemarks Source: @carto/react-core */
|
|
44
|
+
export enum SpatialIndex {
|
|
45
|
+
H3 = 'h3',
|
|
46
|
+
S2 = 's2',
|
|
47
|
+
QUADBIN = 'quadbin',
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** @privateRemarks Source: @carto/react-core */
|
|
51
|
+
export enum Provider {
|
|
52
|
+
BIGQUERY = 'bigquery',
|
|
53
|
+
REDSHIFT = 'redshift',
|
|
54
|
+
POSTGRES = 'postgres',
|
|
55
|
+
SNOWFLAKE = 'snowflake',
|
|
56
|
+
DATABRICKS = 'databricks',
|
|
57
|
+
DATABRICKS_REST = 'databricksRest',
|
|
58
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import {Feature} from 'geojson';
|
|
2
|
+
import {FilterLogicalOperator, Filters} from '../types.js';
|
|
3
|
+
import {FilterType} from '../constants.js';
|
|
4
|
+
import {_buildFeatureFilter} from '../filters/index.js';
|
|
5
|
+
import {FeatureData} from '../types-internal.js';
|
|
6
|
+
|
|
7
|
+
type TimeFilter = Filters['string'][FilterType.TIME] & {
|
|
8
|
+
params?: {offsetBy?: number};
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* deck.gl's DataFilterExtension supports GPU filtering with 1–4 values. We
|
|
13
|
+
* allocate filters[0] to generic filters and filters[1] to time filters.
|
|
14
|
+
*
|
|
15
|
+
* getFilterValue() _must_ return an array of the same size as the filterSize
|
|
16
|
+
* used to initialize the DataFilterExtension. We document that users must use
|
|
17
|
+
* filterSize=4 for compatibility with @link {getDataFilterExtensionProps}.
|
|
18
|
+
*/
|
|
19
|
+
const DEFAULT_FILTER_SIZE = 4;
|
|
20
|
+
|
|
21
|
+
/** @experimental Prefer type definition from deck.gl. */
|
|
22
|
+
export type _DataFilterExtensionProps = {
|
|
23
|
+
filterRange: number[][];
|
|
24
|
+
updateTriggers: Record<string, string>;
|
|
25
|
+
getFilterValue: (feature: Feature | FeatureData) => number[];
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Creates props for DataFilterExtension, from `@deck.gl/extensions`, given
|
|
30
|
+
* a set of filters. Requires that DataFilterExtension is initialized with
|
|
31
|
+
* filterSize=4, where the CARTO filters will occupy the first two slots.
|
|
32
|
+
*
|
|
33
|
+
* @example To create a deck.gl layer with GPU data filtering:
|
|
34
|
+
* ```typescript
|
|
35
|
+
* import {DataFilterExtension} from '@deck.gl/extensions';
|
|
36
|
+
* import {VectorTileLayer} from '@deck.gl/layers';
|
|
37
|
+
* import {getDataFilterExtensionProps} from '@carto/api-client';
|
|
38
|
+
*
|
|
39
|
+
* const layer = new VectorTileLayer({
|
|
40
|
+
* data: data,
|
|
41
|
+
* extensions: [new DataFilterExtension({filterSize: 4})],
|
|
42
|
+
* ...getDataFilterExtensionProps(filters),
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export function getDataFilterExtensionProps(
|
|
47
|
+
filters: Filters,
|
|
48
|
+
filtersLogicalOperator?: FilterLogicalOperator
|
|
49
|
+
): _DataFilterExtensionProps {
|
|
50
|
+
const {filtersWithoutTimeType, timeColumn, timeFilter} =
|
|
51
|
+
getFiltersByType(filters);
|
|
52
|
+
return {
|
|
53
|
+
filterRange: getFilterRange(timeFilter, DEFAULT_FILTER_SIZE),
|
|
54
|
+
updateTriggers: getUpdateTriggers(
|
|
55
|
+
filtersWithoutTimeType,
|
|
56
|
+
timeColumn,
|
|
57
|
+
timeFilter
|
|
58
|
+
),
|
|
59
|
+
getFilterValue: getFilterValue(
|
|
60
|
+
filtersWithoutTimeType,
|
|
61
|
+
timeColumn,
|
|
62
|
+
timeFilter,
|
|
63
|
+
DEFAULT_FILTER_SIZE,
|
|
64
|
+
filtersLogicalOperator
|
|
65
|
+
),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** @internal */
|
|
70
|
+
function getFiltersByType(filters: Filters) {
|
|
71
|
+
const filtersWithoutTimeType: Filters = {};
|
|
72
|
+
|
|
73
|
+
let timeColumn: string | null = null;
|
|
74
|
+
let timeFilter: TimeFilter | null = null;
|
|
75
|
+
|
|
76
|
+
for (const [column, columnData] of Object.entries(filters)) {
|
|
77
|
+
for (const [type, typeData] of Object.entries(columnData) as [
|
|
78
|
+
FilterType,
|
|
79
|
+
unknown,
|
|
80
|
+
][]) {
|
|
81
|
+
if (type === FilterType.TIME) {
|
|
82
|
+
timeColumn = column;
|
|
83
|
+
timeFilter = typeData as TimeFilter;
|
|
84
|
+
} else {
|
|
85
|
+
filtersWithoutTimeType[column] = {[type]: typeData};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
filtersWithoutTimeType,
|
|
92
|
+
timeColumn,
|
|
93
|
+
timeFilter,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** @internal */
|
|
98
|
+
function getFilterRange(
|
|
99
|
+
timeFilter: TimeFilter | null,
|
|
100
|
+
filterSize: number
|
|
101
|
+
): number[][] {
|
|
102
|
+
const result = Array(filterSize).fill([0, 0]);
|
|
103
|
+
// According to getFilterValue all filters are resolved as 0 or 1 in the first position of the array
|
|
104
|
+
// except the time filter value that is resolved with the real value of the feature in the second position of the array
|
|
105
|
+
result[0] = [1, 1];
|
|
106
|
+
if (timeFilter) {
|
|
107
|
+
const offsetBy = timeFilter.params?.offsetBy || 0;
|
|
108
|
+
result[1] = timeFilter.values[0].map((v) => v - offsetBy);
|
|
109
|
+
}
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** @internal */
|
|
114
|
+
function getUpdateTriggers(
|
|
115
|
+
filtersWithoutTimeType: Filters,
|
|
116
|
+
timeColumn: string | null,
|
|
117
|
+
timeFilter: TimeFilter | null
|
|
118
|
+
) {
|
|
119
|
+
const result: Record<string, object> = {...filtersWithoutTimeType};
|
|
120
|
+
|
|
121
|
+
// We don't want to change the layer UpdateTriggers every time that the time filter changes
|
|
122
|
+
// because this filter is changed by the time series widget during its animation
|
|
123
|
+
// so we remove the time filter value from the `updateTriggers`
|
|
124
|
+
if (timeColumn && timeFilter) {
|
|
125
|
+
result[timeColumn] = {
|
|
126
|
+
...result[timeColumn],
|
|
127
|
+
offsetBy: timeFilter.params?.offsetBy,
|
|
128
|
+
[FilterType.TIME]: {}, // Allows working with other filters, without an impact on performance.
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
getFilterValue: JSON.stringify(result),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** @internal */
|
|
137
|
+
function getFilterValue(
|
|
138
|
+
filtersWithoutTimeType: Filters,
|
|
139
|
+
timeColumn: string | null,
|
|
140
|
+
timeFilter: TimeFilter | null,
|
|
141
|
+
filterSize: number,
|
|
142
|
+
filtersLogicalOperator?: FilterLogicalOperator
|
|
143
|
+
) {
|
|
144
|
+
const result = Array(filterSize).fill(0);
|
|
145
|
+
const featureFilter = _buildFeatureFilter({
|
|
146
|
+
filters: filtersWithoutTimeType,
|
|
147
|
+
type: 'number',
|
|
148
|
+
filtersLogicalOperator,
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
// We evaluate all filters except the time filter using _buildFeatureFilter function.
|
|
152
|
+
// For the time filter, we return the value of the feature and we will change the getFilterRange result
|
|
153
|
+
// every time this filter changes
|
|
154
|
+
return (feature: Feature | FeatureData) => {
|
|
155
|
+
result[0] = featureFilter(feature);
|
|
156
|
+
|
|
157
|
+
if (timeColumn && timeFilter) {
|
|
158
|
+
const offsetBy = timeFilter.params?.offsetBy || 0;
|
|
159
|
+
const f = (feature.properties || feature) as Record<string, unknown>;
|
|
160
|
+
result[1] = (f[timeColumn] as number) - offsetBy;
|
|
161
|
+
}
|
|
162
|
+
return result;
|
|
163
|
+
};
|
|
164
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './get-data-filter-extension-props.js';
|