@carto/api-client 0.5.0-alpha.4 → 0.5.0-alpha.5

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.
Files changed (94) hide show
  1. package/build/api-client.cjs +2794 -2698
  2. package/build/api-client.d.cts +1373 -0
  3. package/build/api-client.d.ts +1373 -0
  4. package/build/api-client.js +1712 -0
  5. package/build/chunk-V3E7BKVR.js +2063 -0
  6. package/build/worker.d.ts +2 -0
  7. package/build/worker.js +25 -0
  8. package/package.json +18 -18
  9. package/src/constants-internal.ts +0 -6
  10. package/src/filters/tileFeatures.ts +10 -26
  11. package/src/global.d.ts +3 -8
  12. package/src/sources/h3-tileset-source.ts +8 -1
  13. package/src/sources/quadbin-tileset-source.ts +8 -1
  14. package/src/sources/raster-source.ts +5 -18
  15. package/src/sources/types.ts +7 -1
  16. package/src/sources/vector-tileset-source.ts +8 -1
  17. package/src/types.ts +0 -6
  18. package/src/widget-sources/index.ts +1 -1
  19. package/src/widget-sources/widget-remote-source.ts +35 -2
  20. package/src/widget-sources/widget-source.ts +1 -38
  21. package/src/widget-sources/widget-tileset-source.ts +7 -18
  22. package/src/widget-sources/widget-tileset-worker-source.ts +238 -0
  23. package/src/workers/constants.ts +13 -0
  24. package/src/workers/types.ts +20 -0
  25. package/src/workers/utils.ts +33 -0
  26. package/src/workers/widget-tileset-worker.ts +36 -0
  27. package/build/api/carto-api-error.d.ts +0 -26
  28. package/build/api/endpoints.d.ts +0 -24
  29. package/build/api/index.d.ts +0 -5
  30. package/build/api/query.d.ts +0 -3
  31. package/build/api/request-with-parameters.d.ts +0 -10
  32. package/build/api-client.cjs.map +0 -1
  33. package/build/api-client.modern.js +0 -3445
  34. package/build/api-client.modern.js.map +0 -1
  35. package/build/client.d.ts +0 -14
  36. package/build/constants-internal.d.ts +0 -26
  37. package/build/constants.d.ts +0 -53
  38. package/build/deck/get-data-filter-extension-props.d.ts +0 -18
  39. package/build/deck/index.d.ts +0 -1
  40. package/build/filters/Filter.d.ts +0 -25
  41. package/build/filters/FilterTypes.d.ts +0 -3
  42. package/build/filters/geosjonFeatures.d.ts +0 -8
  43. package/build/filters/index.d.ts +0 -6
  44. package/build/filters/tileFeatures.d.ts +0 -21
  45. package/build/filters/tileFeaturesGeometries.d.ts +0 -13
  46. package/build/filters/tileFeaturesRaster.d.ts +0 -16
  47. package/build/filters/tileFeaturesSpatialIndex.d.ts +0 -10
  48. package/build/filters.d.ts +0 -39
  49. package/build/geo.d.ts +0 -19
  50. package/build/index.d.ts +0 -16
  51. package/build/models/common.d.ts +0 -28
  52. package/build/models/index.d.ts +0 -3
  53. package/build/models/model.d.ts +0 -37
  54. package/build/operations/aggregation.d.ts +0 -8
  55. package/build/operations/applySorting.d.ts +0 -20
  56. package/build/operations/groupBy.d.ts +0 -15
  57. package/build/operations/groupByDate.d.ts +0 -11
  58. package/build/operations/histogram.d.ts +0 -13
  59. package/build/operations/index.d.ts +0 -6
  60. package/build/operations/scatterPlot.d.ts +0 -14
  61. package/build/sources/base-source.d.ts +0 -4
  62. package/build/sources/boundary-query-source.d.ts +0 -10
  63. package/build/sources/boundary-table-source.d.ts +0 -8
  64. package/build/sources/h3-query-source.d.ts +0 -5
  65. package/build/sources/h3-table-source.d.ts +0 -5
  66. package/build/sources/h3-tileset-source.d.ts +0 -5
  67. package/build/sources/index.d.ts +0 -26
  68. package/build/sources/quadbin-query-source.d.ts +0 -5
  69. package/build/sources/quadbin-table-source.d.ts +0 -5
  70. package/build/sources/quadbin-tileset-source.d.ts +0 -5
  71. package/build/sources/raster-source.d.ts +0 -5
  72. package/build/sources/types.d.ts +0 -366
  73. package/build/sources/vector-query-source.d.ts +0 -5
  74. package/build/sources/vector-table-source.d.ts +0 -5
  75. package/build/sources/vector-tileset-source.d.ts +0 -5
  76. package/build/spatial-index.d.ts +0 -14
  77. package/build/types-internal.d.ts +0 -56
  78. package/build/types.d.ts +0 -148
  79. package/build/utils/dateUtils.d.ts +0 -10
  80. package/build/utils/getTileFormat.d.ts +0 -3
  81. package/build/utils/makeIntervalComplete.d.ts +0 -2
  82. package/build/utils/transformTileCoordsToWGS84.d.ts +0 -8
  83. package/build/utils/transformToTileCoords.d.ts +0 -9
  84. package/build/utils.d.ts +0 -32
  85. package/build/widget-sources/index.d.ts +0 -7
  86. package/build/widget-sources/types.d.ts +0 -160
  87. package/build/widget-sources/widget-query-source.d.ts +0 -34
  88. package/build/widget-sources/widget-raster-source.d.ts +0 -11
  89. package/build/widget-sources/widget-remote-source.d.ts +0 -21
  90. package/build/widget-sources/widget-source.d.ts +0 -74
  91. package/build/widget-sources/widget-table-source.d.ts +0 -34
  92. package/build/widget-sources/widget-tileset-source.d.ts +0 -75
  93. package/src/filters/tileFeaturesRaster.ts +0 -111
  94. package/src/widget-sources/widget-raster-source.ts +0 -14
@@ -1,160 +0,0 @@
1
- import { SpatialFilterPolyfillMode, TileResolution } from '../sources/types.js';
2
- import { Filters, GroupDateType, SortColumnType, SortDirection, SpatialFilter } from '../types.js';
3
- /******************************************************************************
4
- * WIDGET API REQUESTS
5
- */
6
- export interface ViewState {
7
- zoom: number;
8
- latitude: number;
9
- longitude: number;
10
- }
11
- /** Common options for {@link WidgetRemoteSource} requests. */
12
- interface BaseRequestOptions {
13
- spatialFilter?: SpatialFilter;
14
- spatialFiltersMode?: SpatialFilterPolyfillMode;
15
- /** Required for table- and query-based spatial index sources (H3, Quadbin). */
16
- spatialIndexReferenceViewState?: ViewState;
17
- abortController?: AbortController;
18
- /** Overrides source filters, if any. */
19
- filters?: Filters;
20
- filterOwner?: string;
21
- }
22
- /** Options for {@link WidgetRemoteSource#getCategories}. */
23
- export interface CategoryRequestOptions extends BaseRequestOptions {
24
- column: string;
25
- operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
26
- operationColumn?: string;
27
- /** Local only. */
28
- joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
29
- }
30
- /**
31
- * Options for {@link WidgetRemoteSource#getFeatures}.
32
- * @experimental
33
- * @internal
34
- */
35
- export interface FeaturesRequestOptions extends BaseRequestOptions {
36
- /**
37
- * Feature IDs, as found in `_carto_feature_id`. Feature IDs are a hash
38
- * of geometry, and features with identical geometry will have the same
39
- * feature ID. Order is important; features in the result set will be
40
- * sorted according to the order of IDs in the request.
41
- */
42
- featureIds: string[];
43
- /**
44
- * Columns to be returned for each picked object. Note that for datasets
45
- * containing features with identical geometry, more than one result per
46
- * requested feature ID may be returned. To match results back to the
47
- * requested feature ID, include `_carto_feature_id` in the columns list.
48
- */
49
- columns: string[];
50
- /** Topology of objects to be picked. */
51
- dataType: 'points' | 'lines' | 'polygons';
52
- /** Zoom level, required if using 'points' data type. */
53
- z?: number;
54
- /**
55
- * Maximum number of objects to return in the result set. For datasets
56
- * containing features with identical geometry, those features will have
57
- * the same feature IDs, and so more results may be returned than feature IDs
58
- * given in the request.
59
- */
60
- limit?: number;
61
- /**
62
- * Must match `tileResolution` used when obtaining the `_carto_feature_id`
63
- * column, typically in a layer's tile requests.
64
- */
65
- tileResolution?: TileResolution;
66
- }
67
- /** Options for {@link WidgetRemoteSource#getFormula}. */
68
- export interface FormulaRequestOptions extends BaseRequestOptions {
69
- column: string;
70
- operation?: 'count' | 'avg' | 'min' | 'max' | 'sum' | 'custom';
71
- operationExp?: string;
72
- joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
73
- }
74
- /** Options for {@link WidgetRemoteSource#getHistogram}. */
75
- export interface HistogramRequestOptions extends BaseRequestOptions {
76
- column: string;
77
- ticks: number[];
78
- operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
79
- /** Local only. */
80
- joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
81
- }
82
- /** Options for {@link WidgetRemoteSource#getRange}. */
83
- export interface RangeRequestOptions extends BaseRequestOptions {
84
- column: string;
85
- }
86
- /** Options for {@link WidgetRemoteSource#getScatter}. */
87
- export interface ScatterRequestOptions extends BaseRequestOptions {
88
- xAxisColumn: string;
89
- xAxisJoinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
90
- yAxisColumn: string;
91
- yAxisJoinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
92
- }
93
- /** Options for {@link WidgetRemoteSource#getTable}. */
94
- export interface TableRequestOptions extends BaseRequestOptions {
95
- columns: string[];
96
- sortBy?: string;
97
- sortDirection?: SortDirection;
98
- sortByColumnType?: SortColumnType;
99
- offset?: number;
100
- limit?: number;
101
- /** Local only. */
102
- searchFilterColumn?: string;
103
- /** Local only. */
104
- searchFilterText?: string;
105
- }
106
- /** Options for {@link WidgetRemoteSource#getTimeSeries}. */
107
- export interface TimeSeriesRequestOptions extends BaseRequestOptions {
108
- column: string;
109
- stepSize: GroupDateType;
110
- stepMultiplier?: number;
111
- operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
112
- operationColumn?: string;
113
- joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
114
- splitByCategory?: string;
115
- splitByCategoryLimit?: number;
116
- splitByCategoryValues?: string[];
117
- }
118
- /******************************************************************************
119
- * WIDGET API RESPONSES
120
- */
121
- /**
122
- * Response from {@link WidgetRemoteSource#getFeatures}.
123
- * @experimental
124
- * @internal
125
- */
126
- export type FeaturesResponse = {
127
- rows: Record<string, unknown>[];
128
- };
129
- /** Response from {@link WidgetRemoteSource#getFormula}. */
130
- export type FormulaResponse = {
131
- value: number | null;
132
- };
133
- /** Response from {@link WidgetRemoteSource#getCategories}. */
134
- export type CategoryResponse = {
135
- name: string;
136
- value: number;
137
- }[];
138
- /** Response from {@link WidgetRemoteSource#getRange}. */
139
- export type RangeResponse = {
140
- min: number;
141
- max: number;
142
- } | null;
143
- /** Response from {@link WidgetRemoteSource#getTable}. */
144
- export type TableResponse = {
145
- totalCount: number;
146
- rows: Record<string, number | string>[];
147
- };
148
- /** Response from {@link WidgetRemoteSource#getScatter}. */
149
- export type ScatterResponse = [number, number][];
150
- /** Response from {@link WidgetRemoteSource#getTimeSeries}. */
151
- export type TimeSeriesResponse = {
152
- rows: {
153
- name: string;
154
- value: number;
155
- }[];
156
- categories?: string[];
157
- };
158
- /** Response from {@link WidgetRemoteSource#getHistogram}. */
159
- export type HistogramResponse = number[];
160
- export {};
@@ -1,34 +0,0 @@
1
- import { H3QuerySourceOptions, QuadbinQuerySourceOptions, VectorQuerySourceOptions } from '../sources/index.js';
2
- import { WidgetRemoteSource, WidgetRemoteSourceProps } from './widget-remote-source.js';
3
- import { ModelSource } from '../models/model.js';
4
- import { Filters } from '../types.js';
5
- type LayerQuerySourceOptions = Omit<VectorQuerySourceOptions, 'filters'> | Omit<H3QuerySourceOptions, 'filters'> | Omit<QuadbinQuerySourceOptions, 'filters'>;
6
- export type WidgetQuerySourceResult = {
7
- widgetSource: WidgetQuerySource;
8
- };
9
- /**
10
- * Source for Widget API requests on a data source defined by a SQL query.
11
- *
12
- * Generally not intended to be constructed directly. Instead, call
13
- * {@link vectorQuerySource}, {@link h3QuerySource}, or {@link quadbinQuerySource},
14
- * which can be shared with map layers. Sources contain a `widgetSource` property,
15
- * for use by widget implementations.
16
- *
17
- * Example:
18
- *
19
- * ```javascript
20
- * import { vectorQuerySource } from '@carto/api-client';
21
- *
22
- * const data = vectorQuerySource({
23
- * accessToken: '••••',
24
- * connectionName: 'carto_dw',
25
- * sqlQuery: 'SELECT * FROM carto-demo-data.demo_tables.retail_stores'
26
- * });
27
- *
28
- * const { widgetSource } = await data;
29
- * ```
30
- */
31
- export declare class WidgetQuerySource extends WidgetRemoteSource<LayerQuerySourceOptions & WidgetRemoteSourceProps> {
32
- protected getModelSource(filters: Filters | undefined, filterOwner?: string): ModelSource;
33
- }
34
- export {};
@@ -1,11 +0,0 @@
1
- import { RasterMetadata } from '../sources/index.js';
2
- import { WidgetTilesetSource, WidgetTilesetSourceProps } from './widget-tileset-source.js';
3
- export type WidgetRasterSourceProps = WidgetTilesetSourceProps & {
4
- rasterMetadata: RasterMetadata;
5
- spatialDataType: 'quadbin';
6
- };
7
- export type WidgetRasterSourceResult = {
8
- widgetSource: WidgetRasterSource;
9
- };
10
- export declare class WidgetRasterSource extends WidgetTilesetSource<WidgetRasterSourceProps> {
11
- }
@@ -1,21 +0,0 @@
1
- import { CategoryRequestOptions, CategoryResponse, FeaturesRequestOptions, FeaturesResponse, FormulaRequestOptions, FormulaResponse, HistogramRequestOptions, HistogramResponse, RangeRequestOptions, RangeResponse, ScatterRequestOptions, ScatterResponse, TableRequestOptions, TableResponse, TimeSeriesRequestOptions, TimeSeriesResponse } from './types.js';
2
- import { WidgetSource, WidgetSourceProps } from './widget-source.js';
3
- export type WidgetRemoteSourceProps = WidgetSourceProps;
4
- /**
5
- * Source for Widget API requests.
6
- *
7
- * Abstract class. Use {@link WidgetQuerySource} or {@link WidgetTableSource}.
8
- */
9
- export declare abstract class WidgetRemoteSource<Props extends WidgetRemoteSourceProps> extends WidgetSource<Props> {
10
- protected _headers: Record<string, string>;
11
- /** Assigns HTTP headers to be included on API requests from this source. */
12
- setRequestHeaders(headers: Record<string, string>): void;
13
- getCategories(options: CategoryRequestOptions): Promise<CategoryResponse>;
14
- getFeatures(options: FeaturesRequestOptions): Promise<FeaturesResponse>;
15
- getFormula(options: FormulaRequestOptions): Promise<FormulaResponse>;
16
- getHistogram(options: HistogramRequestOptions): Promise<HistogramResponse>;
17
- getRange(options: RangeRequestOptions): Promise<RangeResponse>;
18
- getScatter(options: ScatterRequestOptions): Promise<ScatterResponse>;
19
- getTable(options: TableRequestOptions): Promise<TableResponse>;
20
- getTimeSeries(options: TimeSeriesRequestOptions): Promise<TimeSeriesResponse>;
21
- }
@@ -1,74 +0,0 @@
1
- import { CategoryRequestOptions, CategoryResponse, FeaturesRequestOptions, FeaturesResponse, FormulaRequestOptions, FormulaResponse, HistogramRequestOptions, HistogramResponse, RangeRequestOptions, RangeResponse, ScatterRequestOptions, ScatterResponse, TableRequestOptions, TableResponse, TimeSeriesRequestOptions, TimeSeriesResponse, ViewState } from './types.js';
2
- import { FilterLogicalOperator, Filter, SpatialFilter, Filters } from '../types.js';
3
- import { ModelSource } from '../models/model.js';
4
- import { SourceOptions } from '../sources/index.js';
5
- import { ApiVersion } from '../constants.js';
6
- export interface WidgetSourceProps extends Omit<SourceOptions, 'filters'> {
7
- apiVersion?: ApiVersion;
8
- filters?: Record<string, Filter>;
9
- filtersLogicalOperator?: FilterLogicalOperator;
10
- }
11
- /**
12
- * Source for Widget API requests on a data source defined by a SQL query.
13
- *
14
- * Abstract class. Use {@link WidgetQuerySource} or {@link WidgetTableSource}.
15
- */
16
- export declare abstract class WidgetSource<Props extends WidgetSourceProps> {
17
- readonly props: Props;
18
- static defaultProps: Partial<WidgetSourceProps>;
19
- constructor(props: Props);
20
- /**
21
- * Subclasses of {@link WidgetRemoteSource} must implement this method, calling
22
- * {@link WidgetRemoteSource.prototype._getModelSource} for common source
23
- * properties, and adding additional required properties including 'type' and
24
- * 'data'.
25
- */
26
- protected abstract getModelSource(filters: Filters | undefined, filterOwner?: string): ModelSource;
27
- protected _getModelSource(filters: Filters | undefined, filterOwner?: string): Omit<ModelSource, 'type' | 'data'>;
28
- protected _getSpatialFiltersResolution(source: Omit<ModelSource, 'type' | 'data'>, spatialFilter?: SpatialFilter, referenceViewState?: ViewState): number | undefined;
29
- /**
30
- * Returns a list of labeled datapoints for categorical data. Suitable for
31
- * charts including grouped bar charts, pie charts, and tree charts.
32
- */
33
- abstract getCategories(options: CategoryRequestOptions): Promise<CategoryResponse>;
34
- /**
35
- * Given a list of feature IDs (as found in `_carto_feature_id`) returns all
36
- * matching features. In datasets containing features with duplicate geometries,
37
- * feature IDs may be duplicated (IDs are a hash of geometry) and so more
38
- * results may be returned than IDs in the request.
39
- * @internal
40
- * @experimental
41
- */
42
- abstract getFeatures(options: FeaturesRequestOptions): Promise<FeaturesResponse>;
43
- /**
44
- * Returns a scalar numerical statistic over all matching data. Suitable
45
- * for 'headline' or 'scorecard' figures such as counts and sums.
46
- */
47
- abstract getFormula(options: FormulaRequestOptions): Promise<FormulaResponse>;
48
- /**
49
- * Returns a list of labeled datapoints for 'bins' of data defined as ticks
50
- * over a numerical range. Suitable for histogram charts.
51
- */
52
- abstract getHistogram(options: HistogramRequestOptions): Promise<HistogramResponse>;
53
- /**
54
- * Returns a range (min and max) for a numerical column of matching rows.
55
- * Suitable for displaying certain 'headline' or 'scorecard' statistics,
56
- * or rendering a range slider UI for filtering.
57
- */
58
- abstract getRange(options: RangeRequestOptions): Promise<RangeResponse>;
59
- /**
60
- * Returns a list of bivariate datapoints defined as numerical 'x' and 'y'
61
- * values. Suitable for rendering scatter plots.
62
- */
63
- abstract getScatter(options: ScatterRequestOptions): Promise<ScatterResponse>;
64
- /**
65
- * Returns a list of arbitrary data rows, with support for pagination and
66
- * sorting. Suitable for displaying tables and lists.
67
- */
68
- abstract getTable(options: TableRequestOptions): Promise<TableResponse>;
69
- /**
70
- * Returns a series of labeled numerical values, grouped into equally-sized
71
- * time intervals. Suitable for rendering time series charts.
72
- */
73
- abstract getTimeSeries(options: TimeSeriesRequestOptions): Promise<TimeSeriesResponse>;
74
- }
@@ -1,34 +0,0 @@
1
- import { H3TableSourceOptions, QuadbinTableSourceOptions, VectorTableSourceOptions } from '../sources/index.js';
2
- import { WidgetRemoteSource, WidgetRemoteSourceProps } from './widget-remote-source.js';
3
- import { ModelSource } from '../models/model.js';
4
- import { Filters } from '../types.js';
5
- type LayerTableSourceOptions = Omit<VectorTableSourceOptions, 'filters'> | Omit<H3TableSourceOptions, 'filters'> | Omit<QuadbinTableSourceOptions, 'filters'>;
6
- export type WidgetTableSourceResult = {
7
- widgetSource: WidgetTableSource;
8
- };
9
- /**
10
- * Source for Widget API requests on a data source defined as a table.
11
- *
12
- * Generally not intended to be constructed directly. Instead, call
13
- * {@link vectorTableSource}, {@link h3TableSource}, or {@link quadbinTableSource},
14
- * which can be shared with map layers. Sources contain a `widgetSource` property,
15
- * for use by widget implementations.
16
- *
17
- * Example:
18
- *
19
- * ```javascript
20
- * import { vectorTableSource } from '@carto/api-client';
21
- *
22
- * const data = vectorTableSource({
23
- * accessToken: '••••',
24
- * connectionName: 'carto_dw',
25
- * tableName: 'carto-demo-data.demo_tables.retail_stores'
26
- * });
27
- *
28
- * const { widgetSource } = await data;
29
- * ```
30
- */
31
- export declare class WidgetTableSource extends WidgetRemoteSource<LayerTableSourceOptions & WidgetRemoteSourceProps> {
32
- protected getModelSource(filters: Filters | undefined, filterOwner?: string): ModelSource;
33
- }
34
- export {};
@@ -1,75 +0,0 @@
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<Props extends WidgetTilesetSourceProps = WidgetTilesetSourceProps> extends WidgetSource<Props> {
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
- }
@@ -1,111 +0,0 @@
1
- import {
2
- cellToChildren as _cellToChildren,
3
- cellToTile,
4
- geometryToCells,
5
- getResolution,
6
- } from 'quadbin';
7
- import {RasterTile, SpatialFilter, Tile} from '../types.js';
8
- import {FeatureData} from '../types-internal.js';
9
- import {
10
- RasterMetadata,
11
- RasterMetadataBand,
12
- SpatialDataType,
13
- } from '../sources/types.js';
14
-
15
- export type TileFeaturesRasterOptions = {
16
- tiles: RasterTile[];
17
- spatialFilter: SpatialFilter;
18
- spatialDataColumn: string;
19
- spatialDataType: SpatialDataType;
20
- rasterMetadata: RasterMetadata;
21
- };
22
-
23
- export function tileFeaturesRaster({
24
- tiles,
25
- ...options
26
- }: TileFeaturesRasterOptions): FeatureData[] {
27
- // Cache band metadata for faster lookup while iterating over pixels.
28
- const bandMetadataByName: Record<string, RasterMetadataBand> = {};
29
- for (const band of options.rasterMetadata.bands) {
30
- bandMetadataByName[band.name] = band;
31
- }
32
-
33
- // Omit empty and invisible tiles for simpler processing and types.
34
- tiles = tiles.filter(isRasterTileVisible);
35
- if (tiles.length === 0) return [];
36
-
37
- // Raster tiles, and all pixels, are quadbin cells. Resolution of a pixel is
38
- // the resolution of the tile, plus the number of subdivisions. Block size
39
- // must be square, N x N, where N is a power of two.
40
- const tileResolution = getResolution(tiles[0].index.q);
41
- const tileBlockSize = tiles[0].data!.blockSize;
42
- const cellResolution = tileResolution + BigInt(Math.log2(tileBlockSize));
43
-
44
- // Compute covering cells for the spatial filter, at same resolution as the
45
- // raster pixels, to be used as a mask.
46
- const spatialFilterCells = new Set(
47
- geometryToCells(options.spatialFilter, cellResolution)
48
- );
49
-
50
- const data = new Map<bigint, FeatureData>();
51
-
52
- for (const tile of tiles as Required<RasterTile>[]) {
53
- const parent = tile.index.q;
54
-
55
- const children = cellToChildrenSorted(parent, cellResolution);
56
-
57
- // For each pixel/cell within the spatial filter, create a FeatureData.
58
- // Order is row-major, starting from NW and ending at SE.
59
- for (let i = 0; i < children.length; i++) {
60
- if (!spatialFilterCells.has(children[i])) continue;
61
-
62
- const cellData: FeatureData = {};
63
- let cellDataExists = false;
64
-
65
- for (const band in tile.data.cells.numericProps) {
66
- const value = tile.data.cells.numericProps[band].value[i];
67
- // TODO(cleanup): nodata should be a number, not a string.
68
- if (Number(bandMetadataByName[band].nodata) !== value) {
69
- cellData[band] = tile.data.cells.numericProps[band].value[i];
70
- cellDataExists = true;
71
- }
72
- }
73
-
74
- if (cellDataExists) {
75
- data.set(children[i], cellData);
76
- }
77
- }
78
- }
79
-
80
- return Array.from(data.values());
81
- }
82
-
83
- /**
84
- * Detects whether a given {@link Tile} is a {@link RasterTile}.
85
- * @privateRemarks Method of detection is arbitrary, and may be changed.
86
- */
87
- export function isRasterTile(tile: Tile): tile is RasterTile {
88
- return !!(tile.data as Record<string, unknown>)?.cells;
89
- }
90
-
91
- function isRasterTileVisible(tile: RasterTile): tile is Required<RasterTile> {
92
- return !!(tile.isVisible && tile.data?.cells?.numericProps);
93
- }
94
-
95
- /**
96
- * For the raster format, children are sorted in row-major order, starting from
97
- * NW and ending at SE. Order returned by quadbin's cellToChildren() is not
98
- * defined (and not related to the raster format), so sort explicitly here.
99
- */
100
- function cellToChildrenSorted(parent: bigint, resolution: bigint): bigint[] {
101
- return _cellToChildren(parent, resolution).sort(
102
- (cellA: bigint, cellB: bigint) => {
103
- const tileA = cellToTile(cellA);
104
- const tileB = cellToTile(cellB);
105
- if (tileA.y !== tileB.y) {
106
- return tileA.y > tileB.y ? 1 : -1;
107
- }
108
- return tileA.x > tileB.x ? 1 : -1;
109
- }
110
- );
111
- }
@@ -1,14 +0,0 @@
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> {}