@carto/api-client 0.5.0-alpha.2 → 0.5.0-alpha.3
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/build/api-client.cjs +150 -414
- package/build/api-client.cjs.map +1 -1
- package/build/api-client.modern.js +152 -422
- package/build/api-client.modern.js.map +1 -1
- package/build/filters/tileFeatures.d.ts +3 -2
- package/build/filters/tileFeaturesRaster.d.ts +16 -0
- package/build/index.d.ts +1 -0
- package/build/sources/raster-source.d.ts +2 -1
- package/build/sources/types.d.ts +1 -1
- package/build/spatial-index.d.ts +7 -1
- package/build/types.d.ts +8 -0
- package/build/widget-sources/index.d.ts +1 -0
- package/build/widget-sources/widget-raster-source.d.ts +11 -0
- package/build/widget-sources/widget-tileset-source.d.ts +5 -4
- package/package.json +12 -6
- package/src/filters/tileFeatures.ts +27 -11
- package/src/filters/tileFeaturesRaster.ts +111 -0
- package/src/index.ts +2 -0
- package/src/sources/raster-source.ts +14 -5
- package/src/sources/types.ts +1 -1
- package/src/spatial-index.ts +8 -6
- package/src/types.ts +6 -0
- package/src/widget-sources/index.ts +1 -0
- package/src/widget-sources/widget-raster-source.ts +14 -0
- package/src/widget-sources/widget-tileset-source.ts +6 -9
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SpatialFilter, Tile } from '../types';
|
|
2
2
|
import { TileFormat } from '../constants';
|
|
3
3
|
import { FeatureData } from '../types-internal';
|
|
4
|
-
import { SpatialDataType } from '../sources/types';
|
|
4
|
+
import { RasterMetadata, SpatialDataType } from '../sources/types';
|
|
5
5
|
/** @internalRemarks Source: @carto/react-core */
|
|
6
6
|
export type TileFeatures = {
|
|
7
7
|
tiles: Tile[];
|
|
@@ -10,6 +10,7 @@ export type TileFeatures = {
|
|
|
10
10
|
spatialDataColumn?: string;
|
|
11
11
|
spatialFilter?: SpatialFilter;
|
|
12
12
|
uniqueIdProperty?: string;
|
|
13
|
+
rasterMetadata?: RasterMetadata;
|
|
13
14
|
options?: TileFeatureExtractOptions;
|
|
14
15
|
};
|
|
15
16
|
/** @internalRemarks Source: @carto/react-core */
|
|
@@ -17,4 +18,4 @@ export type TileFeatureExtractOptions = {
|
|
|
17
18
|
storeGeometry?: boolean;
|
|
18
19
|
};
|
|
19
20
|
/** @internalRemarks Source: @carto/react-core */
|
|
20
|
-
export declare function tileFeatures({ tiles, spatialFilter, uniqueIdProperty, tileFormat, spatialDataColumn, spatialDataType, options, }: TileFeatures): FeatureData[];
|
|
21
|
+
export declare function tileFeatures({ tiles, spatialFilter, uniqueIdProperty, tileFormat, spatialDataColumn, spatialDataType, rasterMetadata, options, }: TileFeatures): FeatureData[];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { RasterTile, SpatialFilter, Tile } from '../types';
|
|
2
|
+
import { FeatureData } from '../types-internal';
|
|
3
|
+
import { RasterMetadata, SpatialDataType } from '../sources/types';
|
|
4
|
+
export type TileFeaturesRasterOptions = {
|
|
5
|
+
tiles: RasterTile[];
|
|
6
|
+
spatialFilter: SpatialFilter;
|
|
7
|
+
spatialDataColumn: string;
|
|
8
|
+
spatialDataType: SpatialDataType;
|
|
9
|
+
rasterMetadata: RasterMetadata;
|
|
10
|
+
};
|
|
11
|
+
export declare function tileFeaturesRaster({ tiles, ...options }: TileFeaturesRasterOptions): FeatureData[];
|
|
12
|
+
/**
|
|
13
|
+
* Detects whether a given {@link Tile} is a {@link RasterTile}.
|
|
14
|
+
* @privateRemarks Method of detection is arbitrary, and may be changed.
|
|
15
|
+
*/
|
|
16
|
+
export declare function isRasterTile(tile: Tile): tile is RasterTile;
|
package/build/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from './types.js';
|
|
|
8
8
|
export { APIErrorContext, APIRequestType, CartoAPIError, QueryOptions, buildPublicMapUrl, // Internal, but required for fetchMap().
|
|
9
9
|
buildStatsUrl, // Internal, but required for fetchMap().
|
|
10
10
|
query, requestWithParameters, } from './api/index.js';
|
|
11
|
+
export { _getHexagonResolution } from './spatial-index.js';
|
|
11
12
|
export * from './filters/index.js';
|
|
12
13
|
export * from './operations/index.js';
|
|
13
14
|
export * from './utils/makeIntervalComplete.js';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import { WidgetRasterSourceResult } from '../widget-sources';
|
|
1
2
|
import type { FilterOptions, SourceOptions, TilejsonResult, TilesetSourceOptions } from './types';
|
|
2
3
|
export type RasterSourceOptions = SourceOptions & TilesetSourceOptions & FilterOptions;
|
|
3
|
-
export type RasterSourceResponse = TilejsonResult;
|
|
4
|
+
export type RasterSourceResponse = TilejsonResult & WidgetRasterSourceResult;
|
|
4
5
|
export declare const rasterSource: (options: RasterSourceOptions) => Promise<RasterSourceResponse>;
|
package/build/sources/types.d.ts
CHANGED
|
@@ -319,7 +319,7 @@ export type RasterMetadataBand = {
|
|
|
319
319
|
/**
|
|
320
320
|
* Default color mapping for unique values (or if coloprinterp is `palette`)
|
|
321
321
|
*/
|
|
322
|
-
colortable?: Record<string, number
|
|
322
|
+
colortable?: Record<string, [number, number, number, number]>;
|
|
323
323
|
/**
|
|
324
324
|
* No value representation.
|
|
325
325
|
* Observed values:
|
package/build/spatial-index.d.ts
CHANGED
|
@@ -2,7 +2,13 @@ import type { ModelSource } from './models/model';
|
|
|
2
2
|
import type { AggregationOptions } from './sources/types';
|
|
3
3
|
import type { ViewState } from './widget-sources';
|
|
4
4
|
export declare function getSpatialFiltersResolution(source: Partial<ModelSource & AggregationOptions>, viewState: ViewState): number | undefined;
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Resolution conversion function. Takes a WebMercatorViewport and returns
|
|
7
|
+
* a H3 resolution such that the screen space size of the hexagons is
|
|
8
|
+
* "similar" to the given tileSize on screen. Intended for use with deck.gl.
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export declare function _getHexagonResolution(viewport: {
|
|
6
12
|
zoom: number;
|
|
7
13
|
latitude: number;
|
|
8
14
|
}, tileSize: number): number;
|
package/build/types.d.ts
CHANGED
|
@@ -44,6 +44,14 @@ export type SpatialIndexTile = Tile & {
|
|
|
44
44
|
id: bigint;
|
|
45
45
|
})[];
|
|
46
46
|
};
|
|
47
|
+
export type RasterTile = Tile & {
|
|
48
|
+
id: string;
|
|
49
|
+
index: {
|
|
50
|
+
q: bigint;
|
|
51
|
+
i: string;
|
|
52
|
+
};
|
|
53
|
+
data?: Raster;
|
|
54
|
+
};
|
|
47
55
|
/** @internalRemarks Source: @deck.gl/carto */
|
|
48
56
|
export type Raster = {
|
|
49
57
|
blockSize: number;
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
}
|
|
@@ -2,8 +2,9 @@ import { TilesetSourceOptions } from '../sources/index.js';
|
|
|
2
2
|
import type { ModelSource } from '../models/index.js';
|
|
3
3
|
import { CategoryRequestOptions, CategoryResponse, FeaturesRequestOptions, FeaturesResponse, FormulaRequestOptions, FormulaResponse, HistogramRequestOptions, HistogramResponse, RangeRequestOptions, RangeResponse, ScatterRequestOptions, ScatterResponse, TableRequestOptions, TableResponse, TimeSeriesRequestOptions, TimeSeriesResponse } from './types.js';
|
|
4
4
|
import { TileFormat } from '../constants.js';
|
|
5
|
-
import { SpatialFilter } from '../types.js';
|
|
5
|
+
import { SpatialFilter, Tile } from '../types.js';
|
|
6
6
|
import { TileFeatureExtractOptions } from '../filters/index.js';
|
|
7
|
+
import { FeatureData } from '../types-internal.js';
|
|
7
8
|
import { FeatureCollection } from 'geojson';
|
|
8
9
|
import { SpatialDataType } from '../sources/types.js';
|
|
9
10
|
import { WidgetSource, WidgetSourceProps } from './widget-source.js';
|
|
@@ -36,9 +37,9 @@ export type WidgetTilesetSourceResult = {
|
|
|
36
37
|
* const { widgetSource } = await data;
|
|
37
38
|
* ```
|
|
38
39
|
*/
|
|
39
|
-
export declare class WidgetTilesetSource extends WidgetSource<
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
export declare class WidgetTilesetSource<Props extends WidgetTilesetSourceProps = WidgetTilesetSourceProps> extends WidgetSource<Props> {
|
|
41
|
+
protected _tiles: Tile[];
|
|
42
|
+
protected _features: FeatureData[];
|
|
42
43
|
protected getModelSource(owner: string): ModelSource;
|
|
43
44
|
/**
|
|
44
45
|
* Loads features as a list of tiles (typically provided by deck.gl).
|
package/package.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carto/api-client",
|
|
3
3
|
"description": "Client library for CARTO APIs and framework-agnostic CARTO + deck.gl applications",
|
|
4
|
-
"repository":
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/CartoDB/carto-api-client.git"
|
|
7
|
+
},
|
|
8
|
+
"homepage": "https://github.com/CartoDB/carto-api-client#readme",
|
|
5
9
|
"author": "Don McCurdy <donmccurdy@carto.com>",
|
|
6
10
|
"packageManager": "yarn@4.3.1",
|
|
7
|
-
"version": "0.5.0-alpha.
|
|
11
|
+
"version": "0.5.0-alpha.3",
|
|
8
12
|
"license": "MIT",
|
|
9
13
|
"publishConfig": {
|
|
10
14
|
"access": "public",
|
|
@@ -62,7 +66,8 @@
|
|
|
62
66
|
"@turf/invariant": "^7.1.0",
|
|
63
67
|
"@turf/union": "^7.1.0",
|
|
64
68
|
"@types/geojson": "^7946.0.15",
|
|
65
|
-
"h3-js": "4.1.0"
|
|
69
|
+
"h3-js": "4.1.0",
|
|
70
|
+
"quadbin": "^0.4.0-alpha.2"
|
|
66
71
|
},
|
|
67
72
|
"devDependencies": {
|
|
68
73
|
"@deck.gl/aggregation-layers": "^9.0.38",
|
|
@@ -75,12 +80,13 @@
|
|
|
75
80
|
"@lit/react": "^1.0.6",
|
|
76
81
|
"@lit/task": "^1.0.1",
|
|
77
82
|
"@loaders.gl/core": "^4.3.3",
|
|
78
|
-
"@luma.gl/core": "9.0.27",
|
|
79
|
-
"@luma.gl/engine": "9.0.27",
|
|
83
|
+
"@luma.gl/core": "~9.0.27",
|
|
84
|
+
"@luma.gl/engine": "~9.0.27",
|
|
85
|
+
"@turf/buffer": "^7.2.0",
|
|
80
86
|
"@types/json-schema": "^7.0.15",
|
|
81
87
|
"@types/react": "^18.3.18",
|
|
82
88
|
"@types/semver": "^7.5.8",
|
|
83
|
-
"@vitest/coverage-istanbul": "^
|
|
89
|
+
"@vitest/coverage-istanbul": "^3.0.2",
|
|
84
90
|
"@webcomponents/webcomponentsjs": "^2.8.0",
|
|
85
91
|
"concurrently": "^9.1.2",
|
|
86
92
|
"echarts": "^5.6.0",
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {SpatialFilter, SpatialIndexTile, Tile} from '../types';
|
|
1
|
+
import {RasterTile, SpatialFilter, SpatialIndexTile, Tile} from '../types';
|
|
2
2
|
import {tileFeaturesGeometries} from './tileFeaturesGeometries';
|
|
3
3
|
import {tileFeaturesSpatialIndex} from './tileFeaturesSpatialIndex';
|
|
4
|
-
import {
|
|
4
|
+
import {TileFormat} from '../constants';
|
|
5
5
|
import {DEFAULT_GEO_COLUMN} from '../constants-internal';
|
|
6
6
|
import {FeatureData} from '../types-internal';
|
|
7
|
-
import {SpatialDataType} from '../sources/types';
|
|
7
|
+
import {RasterMetadata, SpatialDataType} from '../sources/types';
|
|
8
|
+
import {isRasterTile, tileFeaturesRaster} from './tileFeaturesRaster';
|
|
9
|
+
import {assert} from '../utils';
|
|
8
10
|
|
|
9
11
|
/** @internalRemarks Source: @carto/react-core */
|
|
10
12
|
export type TileFeatures = {
|
|
@@ -14,6 +16,7 @@ export type TileFeatures = {
|
|
|
14
16
|
spatialDataColumn?: string;
|
|
15
17
|
spatialFilter?: SpatialFilter;
|
|
16
18
|
uniqueIdProperty?: string;
|
|
19
|
+
rasterMetadata?: RasterMetadata;
|
|
17
20
|
options?: TileFeatureExtractOptions;
|
|
18
21
|
};
|
|
19
22
|
|
|
@@ -30,6 +33,7 @@ export function tileFeatures({
|
|
|
30
33
|
tileFormat,
|
|
31
34
|
spatialDataColumn = DEFAULT_GEO_COLUMN,
|
|
32
35
|
spatialDataType,
|
|
36
|
+
rasterMetadata,
|
|
33
37
|
options = {},
|
|
34
38
|
}: TileFeatures): FeatureData[] {
|
|
35
39
|
// TODO(cleanup): Is an empty response the expected result when spatialFilter
|
|
@@ -38,19 +42,31 @@ export function tileFeatures({
|
|
|
38
42
|
return [];
|
|
39
43
|
}
|
|
40
44
|
|
|
41
|
-
if (spatialDataType
|
|
42
|
-
return
|
|
43
|
-
tiles
|
|
45
|
+
if (spatialDataType === 'geo') {
|
|
46
|
+
return tileFeaturesGeometries({
|
|
47
|
+
tiles,
|
|
48
|
+
tileFormat,
|
|
49
|
+
spatialFilter,
|
|
50
|
+
uniqueIdProperty,
|
|
51
|
+
options,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (tiles.some(isRasterTile)) {
|
|
56
|
+
assert(rasterMetadata, 'Missing raster metadata');
|
|
57
|
+
return tileFeaturesRaster({
|
|
58
|
+
tiles: tiles as RasterTile[],
|
|
44
59
|
spatialFilter,
|
|
45
60
|
spatialDataColumn,
|
|
46
61
|
spatialDataType,
|
|
62
|
+
rasterMetadata,
|
|
47
63
|
});
|
|
48
64
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
65
|
+
|
|
66
|
+
return tileFeaturesSpatialIndex({
|
|
67
|
+
tiles: tiles as SpatialIndexTile[],
|
|
52
68
|
spatialFilter,
|
|
53
|
-
|
|
54
|
-
|
|
69
|
+
spatialDataColumn,
|
|
70
|
+
spatialDataType,
|
|
55
71
|
});
|
|
56
72
|
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import {
|
|
2
|
+
cellToChildren as _cellToChildren,
|
|
3
|
+
cellToTile,
|
|
4
|
+
geometryToCells,
|
|
5
|
+
getResolution,
|
|
6
|
+
} from 'quadbin';
|
|
7
|
+
import {RasterTile, SpatialFilter, Tile} from '../types';
|
|
8
|
+
import {FeatureData} from '../types-internal';
|
|
9
|
+
import {
|
|
10
|
+
RasterMetadata,
|
|
11
|
+
RasterMetadataBand,
|
|
12
|
+
SpatialDataType,
|
|
13
|
+
} from '../sources/types';
|
|
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 as bigint);
|
|
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 as bigint;
|
|
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 ? tile.data.hasOwnProperty('cells') : false;
|
|
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
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
+
import {getTileFormat} from '../utils/getTileFormat';
|
|
6
|
+
import {WidgetRasterSource, WidgetRasterSourceResult} from '../widget-sources';
|
|
5
7
|
import {baseSource} from './base-source';
|
|
6
8
|
import type {
|
|
7
9
|
FilterOptions,
|
|
@@ -18,7 +20,7 @@ type UrlParameters = {
|
|
|
18
20
|
filters?: Record<string, unknown>;
|
|
19
21
|
};
|
|
20
22
|
|
|
21
|
-
export type RasterSourceResponse = TilejsonResult;
|
|
23
|
+
export type RasterSourceResponse = TilejsonResult & WidgetRasterSourceResult;
|
|
22
24
|
|
|
23
25
|
export const rasterSource = async function (
|
|
24
26
|
options: RasterSourceOptions
|
|
@@ -29,9 +31,16 @@ export const rasterSource = async function (
|
|
|
29
31
|
urlParameters.filters = filters;
|
|
30
32
|
}
|
|
31
33
|
|
|
32
|
-
return baseSource<UrlParameters>(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
return baseSource<UrlParameters>('raster', options, urlParameters).then(
|
|
35
|
+
(result) => ({
|
|
36
|
+
...(result as TilejsonResult),
|
|
37
|
+
widgetSource: new WidgetRasterSource({
|
|
38
|
+
...options,
|
|
39
|
+
tileFormat: getTileFormat(result as TilejsonResult),
|
|
40
|
+
spatialDataColumn: 'quadbin',
|
|
41
|
+
spatialDataType: 'quadbin',
|
|
42
|
+
rasterMetadata: (result as TilejsonResult).raster_metadata!,
|
|
43
|
+
}),
|
|
44
|
+
})
|
|
36
45
|
) as Promise<RasterSourceResponse>;
|
|
37
46
|
};
|
package/src/sources/types.ts
CHANGED
|
@@ -373,7 +373,7 @@ export type RasterMetadataBand = {
|
|
|
373
373
|
/**
|
|
374
374
|
* Default color mapping for unique values (or if coloprinterp is `palette`)
|
|
375
375
|
*/
|
|
376
|
-
colortable?: Record<string, number
|
|
376
|
+
colortable?: Record<string, [number, number, number, number]>;
|
|
377
377
|
|
|
378
378
|
/**
|
|
379
379
|
* No value representation.
|
package/src/spatial-index.ts
CHANGED
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
} from './constants-internal';
|
|
5
5
|
import type {ModelSource} from './models/model';
|
|
6
6
|
import type {AggregationOptions} from './sources/types';
|
|
7
|
-
import {assert} from './utils';
|
|
8
7
|
import type {ViewState} from './widget-sources';
|
|
9
8
|
|
|
10
9
|
const DEFAULT_TILE_SIZE = 512;
|
|
@@ -40,7 +39,7 @@ export function getSpatialFiltersResolution(
|
|
|
40
39
|
: dataResolution;
|
|
41
40
|
|
|
42
41
|
const hexagonResolution =
|
|
43
|
-
|
|
42
|
+
_getHexagonResolution(viewState, tileSize) + aggregationResLevelOffset;
|
|
44
43
|
|
|
45
44
|
return Math.min(hexagonResolution, maxSpatialFiltersResolution);
|
|
46
45
|
}
|
|
@@ -88,10 +87,13 @@ const maxH3SpatialFiltersResolutions = [
|
|
|
88
87
|
// Relative scale factor (0 = no biasing, 2 = a few hexagons cover view)
|
|
89
88
|
const BIAS = 2;
|
|
90
89
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Resolution conversion function. Takes a WebMercatorViewport and returns
|
|
92
|
+
* a H3 resolution such that the screen space size of the hexagons is
|
|
93
|
+
* "similar" to the given tileSize on screen. Intended for use with deck.gl.
|
|
94
|
+
* @internal
|
|
95
|
+
*/
|
|
96
|
+
export function _getHexagonResolution(
|
|
95
97
|
viewport: {zoom: number; latitude: number},
|
|
96
98
|
tileSize: number
|
|
97
99
|
): number {
|
package/src/types.ts
CHANGED
|
@@ -40,6 +40,12 @@ export type SpatialIndexTile = Tile & {
|
|
|
40
40
|
data?: (Feature & {id: bigint})[];
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
+
export type RasterTile = Tile & {
|
|
44
|
+
id: string;
|
|
45
|
+
index: {q: bigint; i: string};
|
|
46
|
+
data?: Raster;
|
|
47
|
+
};
|
|
48
|
+
|
|
43
49
|
/** @internalRemarks Source: @deck.gl/carto */
|
|
44
50
|
export type Raster = {
|
|
45
51
|
blockSize: number;
|
|
@@ -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> {}
|
|
@@ -75,9 +75,11 @@ export type WidgetTilesetSourceResult = {widgetSource: WidgetTilesetSource};
|
|
|
75
75
|
* const { widgetSource } = await data;
|
|
76
76
|
* ```
|
|
77
77
|
*/
|
|
78
|
-
export class WidgetTilesetSource
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
export class WidgetTilesetSource<
|
|
79
|
+
Props extends WidgetTilesetSourceProps = WidgetTilesetSourceProps,
|
|
80
|
+
> extends WidgetSource<Props> {
|
|
81
|
+
protected _tiles: Tile[] = [];
|
|
82
|
+
protected _features: FeatureData[] = [];
|
|
81
83
|
|
|
82
84
|
protected override getModelSource(owner: string): ModelSource {
|
|
83
85
|
return {
|
|
@@ -106,9 +108,6 @@ export class WidgetTilesetSource extends WidgetSource<WidgetTilesetSourceProps>
|
|
|
106
108
|
options,
|
|
107
109
|
}: {
|
|
108
110
|
spatialFilter: SpatialFilter;
|
|
109
|
-
// TODO(cleanup): As an optional property, 'uniqueIdProperty' will be easy to forget.
|
|
110
|
-
// Would it be better to configure it on the source function, rather than separately
|
|
111
|
-
// on the layer and in 'loadTiles()'?
|
|
112
111
|
uniqueIdProperty?: string;
|
|
113
112
|
options?: TileFeatureExtractOptions;
|
|
114
113
|
}) {
|
|
@@ -117,9 +116,7 @@ export class WidgetTilesetSource extends WidgetSource<WidgetTilesetSourceProps>
|
|
|
117
116
|
options,
|
|
118
117
|
spatialFilter,
|
|
119
118
|
uniqueIdProperty,
|
|
120
|
-
|
|
121
|
-
spatialDataColumn: this.props.spatialDataColumn,
|
|
122
|
-
spatialDataType: this.props.spatialDataType,
|
|
119
|
+
...this.props,
|
|
123
120
|
});
|
|
124
121
|
}
|
|
125
122
|
|