@deck.gl/carto 9.0.0-beta.8 → 9.0.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.
Files changed (81) hide show
  1. package/dist/api/common.d.ts +1 -1
  2. package/dist/api/common.js +1 -1
  3. package/dist/api/fetch-map.d.ts.map +1 -1
  4. package/dist/api/fetch-map.js +8 -3
  5. package/dist/api/request-with-parameters.d.ts.map +1 -1
  6. package/dist/api/request-with-parameters.js +35 -35
  7. package/dist/cartoRasterTile-worker.js +53 -21
  8. package/dist/cartoSpatialTile-worker.js +49 -14
  9. package/dist/cartoVectorTile-worker.js +49 -14
  10. package/dist/constants.d.ts +5 -0
  11. package/dist/constants.d.ts.map +1 -0
  12. package/dist/constants.js +4 -0
  13. package/dist/dist.dev.js +809 -632
  14. package/dist/index.cjs +92 -71
  15. package/dist/index.cjs.map +4 -4
  16. package/dist/index.d.ts +1 -1
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/layers/h3-tile-layer.d.ts.map +1 -1
  19. package/dist/layers/h3-tile-layer.js +3 -1
  20. package/dist/layers/quadbin-tile-layer.d.ts.map +1 -1
  21. package/dist/layers/quadbin-tile-layer.js +3 -1
  22. package/dist/layers/raster-layer.d.ts.map +1 -1
  23. package/dist/layers/raster-layer.js +5 -6
  24. package/dist/layers/raster-tile-layer.d.ts.map +1 -1
  25. package/dist/layers/raster-tile-layer.js +3 -1
  26. package/dist/layers/schema/carto-raster-tile-loader.d.ts +2 -2
  27. package/dist/layers/schema/carto-raster-tile-loader.d.ts.map +1 -1
  28. package/dist/layers/schema/carto-raster-tile-loader.js +3 -4
  29. package/dist/layers/schema/carto-raster-tile.d.ts.map +1 -1
  30. package/dist/layers/schema/carto-raster-tile.js +2 -4
  31. package/dist/layers/schema/carto-spatial-tile-loader.js +1 -1
  32. package/dist/layers/schema/carto-vector-tile-loader.js +1 -1
  33. package/dist/layers/spatial-index-tile-layer.d.ts.map +1 -1
  34. package/dist/layers/spatial-index-tile-layer.js +4 -1
  35. package/dist/layers/vector-tile-layer.d.ts +5 -5
  36. package/dist/layers/vector-tile-layer.d.ts.map +1 -1
  37. package/dist/layers/vector-tile-layer.js +3 -1
  38. package/dist/sources/h3-query-source.d.ts.map +1 -1
  39. package/dist/sources/h3-query-source.js +2 -1
  40. package/dist/sources/h3-table-source.d.ts.map +1 -1
  41. package/dist/sources/h3-table-source.js +2 -4
  42. package/dist/sources/index.d.ts +1 -0
  43. package/dist/sources/index.d.ts.map +1 -1
  44. package/dist/sources/quadbin-query-source.d.ts.map +1 -1
  45. package/dist/sources/quadbin-query-source.js +2 -1
  46. package/dist/sources/quadbin-table-source.d.ts.map +1 -1
  47. package/dist/sources/quadbin-table-source.js +2 -4
  48. package/dist/sources/types.d.ts +38 -6
  49. package/dist/sources/types.d.ts.map +1 -1
  50. package/dist/sources/vector-query-source.d.ts +2 -4
  51. package/dist/sources/vector-query-source.d.ts.map +1 -1
  52. package/dist/sources/vector-query-source.js +8 -2
  53. package/dist/sources/vector-table-source.d.ts +2 -2
  54. package/dist/sources/vector-table-source.d.ts.map +1 -1
  55. package/dist/sources/vector-table-source.js +8 -2
  56. package/dist/utils.d.ts.map +1 -1
  57. package/dist/utils.js +5 -1
  58. package/dist.min.js +9 -9
  59. package/package.json +15 -15
  60. package/src/api/common.ts +1 -1
  61. package/src/api/fetch-map.ts +8 -3
  62. package/src/api/request-with-parameters.ts +47 -34
  63. package/src/constants.ts +5 -0
  64. package/src/index.ts +7 -3
  65. package/src/layers/h3-tile-layer.ts +3 -1
  66. package/src/layers/quadbin-tile-layer.ts +3 -1
  67. package/src/layers/raster-layer.ts +7 -12
  68. package/src/layers/raster-tile-layer.ts +3 -1
  69. package/src/layers/schema/carto-raster-tile-loader.ts +5 -5
  70. package/src/layers/schema/carto-raster-tile.ts +3 -4
  71. package/src/layers/spatial-index-tile-layer.ts +4 -1
  72. package/src/layers/vector-tile-layer.ts +12 -8
  73. package/src/sources/h3-query-source.ts +2 -1
  74. package/src/sources/h3-table-source.ts +2 -6
  75. package/src/sources/index.ts +7 -0
  76. package/src/sources/quadbin-query-source.ts +2 -1
  77. package/src/sources/quadbin-table-source.ts +2 -6
  78. package/src/sources/types.ts +41 -6
  79. package/src/sources/vector-query-source.ts +22 -6
  80. package/src/sources/vector-table-source.ts +21 -3
  81. package/src/utils.ts +5 -1
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "CARTO official integration with Deck.gl. Build geospatial applications using CARTO and Deck.gl.",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
- "version": "9.0.0-beta.8",
6
+ "version": "9.0.0",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
@@ -42,12 +42,12 @@
42
42
  "prepublishOnly": "npm run build-bundle && npm run build-bundle -- --env=dev"
43
43
  },
44
44
  "dependencies": {
45
- "@loaders.gl/gis": "^4.2.0-alpha.5",
46
- "@loaders.gl/loader-utils": "^4.2.0-alpha.5",
47
- "@loaders.gl/mvt": "^4.2.0-alpha.5",
48
- "@loaders.gl/schema": "^4.2.0-alpha.5",
49
- "@loaders.gl/tiles": "^4.2.0-alpha.5",
50
- "@luma.gl/constants": "9.0.0-beta.10",
45
+ "@loaders.gl/gis": "^4.1.4",
46
+ "@loaders.gl/loader-utils": "^4.1.4",
47
+ "@loaders.gl/mvt": "^4.1.4",
48
+ "@loaders.gl/schema": "^4.1.4",
49
+ "@loaders.gl/tiles": "^4.1.4",
50
+ "@luma.gl/constants": "^9.0.6",
51
51
  "@math.gl/web-mercator": "^4.0.0",
52
52
  "@types/d3-array": "^3.0.2",
53
53
  "@types/d3-color": "^1.4.2",
@@ -64,13 +64,13 @@
64
64
  "quadbin": "^0.2.0"
65
65
  },
66
66
  "peerDependencies": {
67
- "@deck.gl/aggregation-layers": "^9.0.0-beta",
68
- "@deck.gl/core": "^9.0.0-beta",
69
- "@deck.gl/extensions": "^9.0.0-beta",
70
- "@deck.gl/geo-layers": "^9.0.0-beta",
71
- "@deck.gl/layers": "^9.0.0-beta",
72
- "@loaders.gl/core": "^4.2.0-alpha.5",
73
- "@luma.gl/core": "9.0.0-beta.10"
67
+ "@deck.gl/aggregation-layers": "^9.0.0",
68
+ "@deck.gl/core": "^9.0.0",
69
+ "@deck.gl/extensions": "^9.0.0",
70
+ "@deck.gl/geo-layers": "^9.0.0",
71
+ "@deck.gl/layers": "^9.0.0",
72
+ "@loaders.gl/core": "^4.1.0",
73
+ "@luma.gl/core": "^9.0.0"
74
74
  },
75
- "gitHead": "8867a1047c2693d44e4af9507c296cf7ab61f9e8"
75
+ "gitHead": "fcb5ccf0a899e651949b24986488211e278e9321"
76
76
  }
package/src/api/common.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export const DEFAULT_API_BASE_URL = 'https://gcp-us-east1.api.carto.com';
2
2
  export const DEFAULT_CLIENT = 'deck-gl-carto';
3
- export const V3_MINOR_VERSION = '3.3';
3
+ export const V3_MINOR_VERSION = '3.4';
4
4
  export const MAX_GET_LENGTH = 8192;
5
5
 
6
6
  export const DEFAULT_PARAMETERS = {
@@ -80,19 +80,24 @@ async function _fetchMapDataset(
80
80
  if (type === 'table') {
81
81
  dataset.data = await vectorTableSource({...options, columns, tableName: source});
82
82
  } else if (type === 'query') {
83
- dataset.data = await vectorQuerySource({...options, sqlQuery: source, queryParameters});
83
+ dataset.data = await vectorQuerySource({
84
+ ...options,
85
+ columns,
86
+ sqlQuery: source,
87
+ queryParameters
88
+ });
84
89
  }
85
90
  } else if (spatialDataType === 'h3') {
86
91
  const options = {...globalOptions, aggregationExp, aggregationResLevel, spatialDataColumn};
87
92
  if (type === 'table') {
88
- dataset.data = await h3TableSource({...options, columns, tableName: source});
93
+ dataset.data = await h3TableSource({...options, tableName: source});
89
94
  } else if (type === 'query') {
90
95
  dataset.data = await h3QuerySource({...options, sqlQuery: source, queryParameters});
91
96
  }
92
97
  } else if (spatialDataType === 'quadbin') {
93
98
  const options = {...globalOptions, aggregationExp, aggregationResLevel, spatialDataColumn};
94
99
  if (type === 'table') {
95
- dataset.data = await quadbinTableSource({...options, columns, tableName: source});
100
+ dataset.data = await quadbinTableSource({...options, tableName: source});
96
101
  } else if (type === 'query') {
97
102
  dataset.data = await quadbinQuerySource({...options, sqlQuery: source, queryParameters});
98
103
  }
@@ -9,7 +9,7 @@ function encodeParameter(name: string, value: string | boolean | number): string
9
9
  return `${name}=${encodeURIComponent(value)}`;
10
10
  }
11
11
 
12
- const REQUEST_CACHE = new Map();
12
+ const REQUEST_CACHE = new Map<string, Promise<unknown>>();
13
13
  export async function requestWithParameters<T = any>({
14
14
  accessToken,
15
15
  baseUrl,
@@ -23,46 +23,59 @@ export async function requestWithParameters<T = any>({
23
23
  headers: Record<string, string>;
24
24
  errorContext: APIErrorContext;
25
25
  }): Promise<T> {
26
- const key = JSON.stringify({baseUrl, parameters, customHeaders});
26
+ const key = createCacheKey(baseUrl, parameters || {}, customHeaders || {});
27
27
  if (REQUEST_CACHE.has(key)) {
28
- return REQUEST_CACHE.get(key);
29
- }
30
-
31
- let url = baseUrl;
32
- if (parameters) {
33
- const allParameters = {...DEFAULT_PARAMETERS, ...parameters};
34
- const encodedParameters = Object.entries(allParameters).map(([key, value]) => {
35
- return encodeParameter(key, value);
36
- });
37
- url += `?${encodedParameters.join('&')}`;
28
+ return REQUEST_CACHE.get(key) as Promise<T>;
38
29
  }
39
30
 
31
+ const url = parameters ? createURLWithParameters(baseUrl, parameters) : baseUrl;
40
32
  const headers = {...DEFAULT_HEADERS, ...customHeaders};
41
- try {
42
- /* global fetch */
43
- let response: Response;
44
- if (url.length > MAX_GET_LENGTH) {
45
- response = await fetch(baseUrl, {method: 'POST', body: JSON.stringify(parameters), headers});
46
- } else {
47
- response = await fetch(url, {headers});
48
- }
49
- let json: any;
50
- try {
51
- json = await response.json();
33
+
34
+ /* global fetch */
35
+ const fetchPromise =
36
+ url.length > MAX_GET_LENGTH
37
+ ? fetch(baseUrl, {method: 'POST', body: JSON.stringify(parameters), headers})
38
+ : fetch(url, {headers});
39
+
40
+ let response: Response | undefined;
41
+ const jsonPromise: Promise<T> = fetchPromise
42
+ .then((_response: Response) => {
43
+ response = _response;
44
+ return response.json();
45
+ })
46
+ .then((json: any) => {
47
+ if (!response || !response.ok) {
48
+ throw new Error(json.error);
49
+ }
52
50
  if (accessToken) {
53
51
  json.accessToken = accessToken;
54
52
  }
55
- } catch {
56
- json = {error: ''};
57
- }
58
- if (!response.ok) {
53
+ return json;
54
+ })
55
+ .catch((error: Error) => {
59
56
  REQUEST_CACHE.delete(key);
60
- throw new CartoAPIError(json.error, errorContext, response);
61
- }
57
+ throw new CartoAPIError(error, errorContext, response);
58
+ });
62
59
 
63
- REQUEST_CACHE.set(key, json);
64
- return json;
65
- } catch (error) {
66
- throw new CartoAPIError(error as Error, errorContext);
67
- }
60
+ REQUEST_CACHE.set(key, jsonPromise);
61
+ return jsonPromise;
62
+ }
63
+
64
+ function createCacheKey(
65
+ baseUrl: string,
66
+ parameters: Record<string, string>,
67
+ headers: Record<string, string>
68
+ ): string {
69
+ const parameterEntries = Object.entries(parameters).sort(([a], [b]) => (a > b ? 1 : -1));
70
+ const headerEntries = Object.entries(headers).sort(([a], [b]) => (a > b ? 1 : -1));
71
+ return JSON.stringify({baseUrl, parameters: parameterEntries, headers: headerEntries});
72
+ }
73
+
74
+ function createURLWithParameters(baseUrl: string, parameters: Record<string, string>): string {
75
+ const encodedParameters = Object.entries({...DEFAULT_PARAMETERS, ...parameters}).map(
76
+ ([key, value]) => {
77
+ return encodeParameter(key, value);
78
+ }
79
+ );
80
+ return `${baseUrl}?${encodedParameters.join('&')}`;
68
81
  }
@@ -0,0 +1,5 @@
1
+ export const DEFAULT_TILE_SIZE = 512;
2
+ export const DEFAULT_TILE_RESOLUTION = 0.5;
3
+
4
+ export const DEFAULT_AGGREGATION_RES_LEVEL_H3 = 4;
5
+ export const DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN = 6;
package/src/index.ts CHANGED
@@ -83,7 +83,13 @@ export {
83
83
  };
84
84
 
85
85
  export type {
86
+ GeojsonResult,
87
+ JsonResult,
86
88
  TilejsonResult,
89
+ SourceOptions,
90
+ QuerySourceOptions,
91
+ TableSourceOptions,
92
+ TilesetSourceOptions,
87
93
  BoundaryQuerySourceOptions,
88
94
  BoundaryTableSourceOptions,
89
95
  H3QuerySourceOptions,
@@ -95,7 +101,5 @@ export type {
95
101
  QuadbinTilesetSourceOptions,
96
102
  VectorQuerySourceOptions,
97
103
  VectorTableSourceOptions,
98
- VectorTilesetSourceOptions,
99
- GeojsonResult,
100
- JsonResult
104
+ VectorTilesetSourceOptions
101
105
  } from './sources/index';
@@ -4,6 +4,7 @@ import H3Tileset2D, {getHexagonResolution} from './h3-tileset-2d';
4
4
  import SpatialIndexTileLayer, {SpatialIndexTileLayerProps} from './spatial-index-tile-layer';
5
5
  import type {TilejsonResult} from '../sources/types';
6
6
  import {injectAccessToken, TilejsonPropType} from './utils';
7
+ import {DEFAULT_TILE_SIZE} from '../constants';
7
8
 
8
9
  export const renderSubLayers = props => {
9
10
  const {data} = props;
@@ -18,7 +19,8 @@ export const renderSubLayers = props => {
18
19
  };
19
20
 
20
21
  const defaultProps: DefaultProps<H3TileLayerProps> = {
21
- data: TilejsonPropType
22
+ data: TilejsonPropType,
23
+ tileSize: DEFAULT_TILE_SIZE
22
24
  };
23
25
 
24
26
  /** All properties supported by H3TileLayer. */
@@ -5,6 +5,7 @@ import SpatialIndexTileLayer, {SpatialIndexTileLayerProps} from './spatial-index
5
5
  import {hexToBigInt} from 'quadbin';
6
6
  import type {TilejsonResult} from '../sources/types';
7
7
  import {injectAccessToken, TilejsonPropType} from './utils';
8
+ import {DEFAULT_TILE_SIZE} from '../constants';
8
9
 
9
10
  export const renderSubLayers = props => {
10
11
  const {data} = props;
@@ -16,7 +17,8 @@ export const renderSubLayers = props => {
16
17
  };
17
18
 
18
19
  const defaultProps: DefaultProps<QuadbinTileLayerProps> = {
19
- data: TilejsonPropType
20
+ data: TilejsonPropType,
21
+ tileSize: DEFAULT_TILE_SIZE
20
22
  };
21
23
 
22
24
  /** All properties supported by QuadbinTileLayer. */
@@ -10,7 +10,7 @@ import {ColumnLayer, ColumnLayerProps} from '@deck.gl/layers';
10
10
  import {quadbinToOffset} from './quadbin-utils';
11
11
  import {Raster} from './schema/carto-raster-tile-loader';
12
12
  import vs from './raster-layer-vertex.glsl';
13
- import {assert, createBinaryProxy} from '../utils';
13
+ import {createBinaryProxy} from '../utils';
14
14
 
15
15
  const defaultProps: DefaultProps<RasterLayerProps> = {
16
16
  ...ColumnLayer.defaultProps,
@@ -30,8 +30,8 @@ class RasterColumnLayer extends ColumnLayer {
30
30
 
31
31
  getShaders() {
32
32
  const shaders = super.getShaders();
33
- const data = this.props.data as unknown as Raster & {length: number};
34
- const BLOCK_WIDTH = data.blockWidth || Math.sqrt(data.length);
33
+ const data = this.props.data as unknown as {data: Raster; length: number};
34
+ const BLOCK_WIDTH = data.data.blockSize ?? Math.sqrt(data.length);
35
35
  return {...shaders, defines: {...shaders.defines, BLOCK_WIDTH}, vs};
36
36
  }
37
37
 
@@ -93,17 +93,12 @@ export default class RasterLayer<DataT = any, ExtraProps = {}> extends Composite
93
93
  getLineWidth,
94
94
  tileIndex,
95
95
  updateTriggers
96
- } = this.props;
96
+ } = this.props as typeof this.props & {data: Raster};
97
97
  if (!data || !tileIndex) return null;
98
98
 
99
- const {blockWidth, blockHeight} = data as unknown as Raster;
100
- assert(
101
- blockWidth === blockHeight,
102
- `blockWidth (${blockWidth}) must equal blockHeight (${blockHeight})`
103
- );
104
-
99
+ const blockSize = data.blockSize ?? 0;
105
100
  const [xOffset, yOffset, scale] = quadbinToOffset(tileIndex);
106
- const offset = [xOffset, yOffset, scale / blockWidth];
101
+ const offset = [xOffset, yOffset, scale / blockSize];
107
102
 
108
103
  // Filled Column Layer
109
104
  const CellLayer = this.getSubLayerClass('column', RasterColumnLayer);
@@ -121,7 +116,7 @@ export default class RasterLayer<DataT = any, ExtraProps = {}> extends Composite
121
116
  {
122
117
  data: {
123
118
  data, // Pass through data for getSubLayerAccessor()
124
- length: blockWidth * blockHeight
119
+ length: blockSize * blockSize
125
120
  },
126
121
  offset
127
122
  }
@@ -4,6 +4,7 @@ import QuadbinTileset2D from './quadbin-tileset-2d';
4
4
  import SpatialIndexTileLayer, {SpatialIndexTileLayerProps} from './spatial-index-tile-layer';
5
5
  import type {TilejsonResult} from '../sources/types';
6
6
  import {injectAccessToken, TilejsonPropType} from './utils';
7
+ import {DEFAULT_TILE_SIZE} from '../constants';
7
8
 
8
9
  export const renderSubLayers = props => {
9
10
  const tileIndex = props.tile?.index?.q;
@@ -12,7 +13,8 @@ export const renderSubLayers = props => {
12
13
  };
13
14
 
14
15
  const defaultProps: DefaultProps<RasterTileLayerProps> = {
15
- data: TilejsonPropType
16
+ data: TilejsonPropType,
17
+ tileSize: DEFAULT_TILE_SIZE
16
18
  };
17
19
 
18
20
  /** All properties supported by RasterTileLayer. */
@@ -36,8 +36,8 @@ const CartoRasterTileLoader: LoaderWithParser = {
36
36
  };
37
37
 
38
38
  export type Raster = {
39
- blockWidth: number;
40
- blockHeight: number;
39
+ /** Raster tiles are square, with 'blockSize' width and height in pixels. */
40
+ blockSize: number;
41
41
  cells: {
42
42
  numericProps: NumericProps;
43
43
  properties: Properties[];
@@ -49,14 +49,14 @@ function parseCartoRasterTile(
49
49
  options?: CartoRasterTileLoaderOptions
50
50
  ): Raster | null {
51
51
  if (!arrayBuffer) return null;
52
- const tile = parsePbf(arrayBuffer, TileReader);
53
- const {bands, blockHeight, blockWidth} = tile;
52
+ const {bands, blockSize} = parsePbf(arrayBuffer, TileReader);
53
+
54
54
  const numericProps = {};
55
55
  for (let i = 0; i < bands.length; i++) {
56
56
  const {name, data} = bands[i];
57
57
  numericProps[name] = data;
58
58
  }
59
- return {blockWidth, blockHeight, cells: {numericProps, properties: []}};
59
+ return {blockSize, cells: {numericProps, properties: []}};
60
60
  }
61
61
 
62
62
  export default CartoRasterTileLoader;
@@ -36,11 +36,10 @@ export class BandReader {
36
36
 
37
37
  export class TileReader {
38
38
  static read(pbf, end) {
39
- return pbf.readFields(TileReader._readField, {blockWidth: 0, blockHeight: 0, bands: []}, end);
39
+ return pbf.readFields(TileReader._readField, {blockSize: 0, bands: []}, end);
40
40
  }
41
41
  static _readField(this: void, tag, obj, pbf) {
42
- if (tag === 1) obj.blockWidth = pbf.readVarint();
43
- else if (tag === 2) obj.blockHeight = pbf.readVarint();
44
- else if (tag === 3) obj.bands.push(BandReader.read(pbf, pbf.readVarint() + pbf.pos));
42
+ if (tag === 1) obj.blockSize = pbf.readVarint();
43
+ else if (tag === 2) obj.bands.push(BandReader.read(pbf, pbf.readVarint() + pbf.pos));
45
44
  }
46
45
  }
@@ -6,12 +6,15 @@ registerLoaders([CartoRasterTileLoader, CartoSpatialTileLoader]);
6
6
 
7
7
  import {PickingInfo} from '@deck.gl/core';
8
8
  import {TileLayer, _Tile2DHeader as Tile2DHeader, TileLayerProps} from '@deck.gl/geo-layers';
9
+ import {DEFAULT_TILE_SIZE} from '../constants';
9
10
 
10
11
  function isFeatureIdDefined(value: unknown): boolean {
11
12
  return value !== undefined && value !== null && value !== '';
12
13
  }
13
14
 
14
- const defaultProps: DefaultProps<SpatialIndexTileLayerProps> = {};
15
+ const defaultProps: DefaultProps<SpatialIndexTileLayerProps> = {
16
+ tileSize: DEFAULT_TILE_SIZE
17
+ };
15
18
 
16
19
  /** All properties supported by SpatialIndexTileLayer. */
17
20
  export type SpatialIndexTileLayerProps<DataT = unknown> = _SpatialIndexTileLayerProps &
@@ -16,19 +16,22 @@ import {
16
16
  import {GeoJsonLayer} from '@deck.gl/layers';
17
17
  import {binaryToGeojson} from '@loaders.gl/gis';
18
18
  import type {BinaryFeatureCollection} from '@loaders.gl/schema';
19
- import type {Feature} from 'geojson';
19
+ import type {Feature, Geometry} from 'geojson';
20
20
 
21
21
  import type {TilejsonResult} from '../sources/types';
22
22
  import {TilejsonPropType, injectAccessToken, mergeBoundaryData} from './utils';
23
+ import {DEFAULT_TILE_SIZE} from '../constants';
23
24
 
24
25
  const defaultProps: DefaultProps<VectorTileLayerProps> = {
25
26
  ...MVTLayer.defaultProps,
26
27
  data: TilejsonPropType,
27
- dataComparator: TilejsonPropType.equal
28
+ dataComparator: TilejsonPropType.equal,
29
+ tileSize: DEFAULT_TILE_SIZE
28
30
  };
29
31
 
30
32
  /** All properties supported by VectorTileLayer. */
31
- export type VectorTileLayerProps = _VectorTileLayerProps & Omit<MVTLayerProps, 'data'>;
33
+ export type VectorTileLayerProps<FeaturePropertiesT = unknown> = _VectorTileLayerProps &
34
+ Omit<MVTLayerProps<FeaturePropertiesT>, 'data'>;
32
35
 
33
36
  /** Properties added by VectorTileLayer. */
34
37
  type _VectorTileLayerProps = {
@@ -36,9 +39,10 @@ type _VectorTileLayerProps = {
36
39
  };
37
40
 
38
41
  // @ts-ignore
39
- export default class VectorTileLayer<ExtraProps extends {} = {}> extends MVTLayer<
40
- Required<_VectorTileLayerProps> & ExtraProps
41
- > {
42
+ export default class VectorTileLayer<
43
+ FeaturePropertiesT = any,
44
+ ExtraProps extends {} = {}
45
+ > extends MVTLayer<FeaturePropertiesT, Required<_VectorTileLayerProps> & ExtraProps> {
42
46
  static layerName = 'VectorTileLayer';
43
47
  static defaultProps = defaultProps;
44
48
 
@@ -46,7 +50,7 @@ export default class VectorTileLayer<ExtraProps extends {} = {}> extends MVTLaye
46
50
  mvt: boolean;
47
51
  };
48
52
 
49
- constructor(...propObjects: VectorTileLayerProps[]) {
53
+ constructor(...propObjects: VectorTileLayerProps<FeaturePropertiesT>[]) {
50
54
  // Force externally visible props type, as it is not possible modify via extension
51
55
  // @ts-ignore
52
56
  super(...propObjects);
@@ -149,7 +153,7 @@ export default class VectorTileLayer<ExtraProps extends {} = {}> extends MVTLaye
149
153
  const {data} = params.sourceLayer!.props;
150
154
  info.object = binaryToGeojson(data as BinaryFeatureCollection, {
151
155
  globalFeatureId: info.index
152
- }) as Feature;
156
+ }) as Feature<Geometry, FeaturePropertiesT>;
153
157
  }
154
158
 
155
159
  return info;
@@ -1,4 +1,5 @@
1
1
  /* eslint-disable camelcase */
2
+ import {DEFAULT_AGGREGATION_RES_LEVEL_H3} from '../constants';
2
3
  import {baseSource} from './base-source';
3
4
  import type {
4
5
  AggregationOptions,
@@ -23,7 +24,7 @@ export const h3QuerySource = async function (
23
24
  ): Promise<TilejsonResult> {
24
25
  const {
25
26
  aggregationExp,
26
- aggregationResLevel = 4,
27
+ aggregationResLevel = DEFAULT_AGGREGATION_RES_LEVEL_H3,
27
28
  sqlQuery,
28
29
  spatialDataColumn = 'h3',
29
30
  queryParameters
@@ -1,4 +1,5 @@
1
1
  /* eslint-disable camelcase */
2
+ import {DEFAULT_AGGREGATION_RES_LEVEL_H3} from '../constants';
2
3
  import {baseSource} from './base-source';
3
4
  import type {
4
5
  AggregationOptions,
@@ -13,7 +14,6 @@ export type H3TableSourceOptions = SourceOptions & TableSourceOptions & Aggregat
13
14
  type UrlParameters = {
14
15
  aggregationExp: string;
15
16
  aggregationResLevel?: string;
16
- columns?: string;
17
17
  spatialDataType: SpatialDataType;
18
18
  spatialDataColumn?: string;
19
19
  name: string;
@@ -24,8 +24,7 @@ export const h3TableSource = async function (
24
24
  ): Promise<TilejsonResult> {
25
25
  const {
26
26
  aggregationExp,
27
- aggregationResLevel = 4,
28
- columns,
27
+ aggregationResLevel = DEFAULT_AGGREGATION_RES_LEVEL_H3,
29
28
  spatialDataColumn = 'h3',
30
29
  tableName
31
30
  } = options;
@@ -39,8 +38,5 @@ export const h3TableSource = async function (
39
38
  if (aggregationResLevel) {
40
39
  urlParameters.aggregationResLevel = String(aggregationResLevel);
41
40
  }
42
- if (columns) {
43
- urlParameters.columns = columns.join(',');
44
- }
45
41
  return baseSource<UrlParameters>('table', options, urlParameters) as Promise<TilejsonResult>;
46
42
  };
@@ -36,3 +36,10 @@ export type {VectorTableSourceOptions} from './vector-table-source';
36
36
 
37
37
  export {vectorTilesetSource} from './vector-tileset-source';
38
38
  export type {VectorTilesetSourceOptions} from './vector-tileset-source';
39
+
40
+ export type {
41
+ SourceOptions,
42
+ QuerySourceOptions,
43
+ TableSourceOptions,
44
+ TilesetSourceOptions
45
+ } from './types';
@@ -1,4 +1,5 @@
1
1
  /* eslint-disable camelcase */
2
+ import {DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN} from '../constants';
2
3
  import {baseSource} from './base-source';
3
4
  import type {
4
5
  AggregationOptions,
@@ -24,7 +25,7 @@ export const quadbinQuerySource = async function (
24
25
  ): Promise<TilejsonResult> {
25
26
  const {
26
27
  aggregationExp,
27
- aggregationResLevel = 6,
28
+ aggregationResLevel = DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN,
28
29
  sqlQuery,
29
30
  spatialDataColumn = 'quadbin',
30
31
  queryParameters
@@ -1,4 +1,5 @@
1
1
  /* eslint-disable camelcase */
2
+ import {DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN} from '../constants';
2
3
  import {baseSource} from './base-source';
3
4
  import type {
4
5
  AggregationOptions,
@@ -13,7 +14,6 @@ export type QuadbinTableSourceOptions = SourceOptions & TableSourceOptions & Agg
13
14
  type UrlParameters = {
14
15
  aggregationExp: string;
15
16
  aggregationResLevel?: string;
16
- columns?: string;
17
17
  spatialDataType: SpatialDataType;
18
18
  spatialDataColumn?: string;
19
19
  name: string;
@@ -24,8 +24,7 @@ export const quadbinTableSource = async function (
24
24
  ): Promise<TilejsonResult> {
25
25
  const {
26
26
  aggregationExp,
27
- aggregationResLevel = 6,
28
- columns,
27
+ aggregationResLevel = DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN,
29
28
  spatialDataColumn = 'quadbin',
30
29
  tableName
31
30
  } = options;
@@ -40,8 +39,5 @@ export const quadbinTableSource = async function (
40
39
  if (aggregationResLevel) {
41
40
  urlParameters.aggregationResLevel = String(aggregationResLevel);
42
41
  }
43
- if (columns) {
44
- urlParameters.columns = columns.join(',');
45
- }
46
42
  return baseSource<UrlParameters>('table', options, urlParameters) as Promise<TilejsonResult>;
47
43
  };
@@ -75,6 +75,21 @@ export type QuerySourceOptions = {
75
75
  /** SQL query. */
76
76
  sqlQuery: string;
77
77
 
78
+ /**
79
+ * Relative resolution of a tile. Higher values increase density and data size. At `tileResolution = 1`, tile geometry is
80
+ * quantized to a 1024x1024 grid. Increasing or decreasing the resolution will increase or decrease the dimensions of
81
+ * the quantization grid proportionately.
82
+ *
83
+ * Supported `tileResolution` values, with corresponding grid sizes:
84
+ *
85
+ * - 0.25: 256x256
86
+ * - 0.5: 512x512
87
+ * - 1: 1024x1024
88
+ * - 2: 2048x2048
89
+ * - 4: 4096x4096
90
+ */
91
+ tileResolution?: TileResolution;
92
+
78
93
  /**
79
94
  * Values for named or positional paramteres in the query.
80
95
  *
@@ -109,18 +124,26 @@ export type TableSourceOptions = {
109
124
  tableName: string;
110
125
 
111
126
  /**
112
- * Columns to retrieve from the table.
127
+ * The column name and the type of geospatial support.
113
128
  *
114
- * If not present, all columns are returned.
129
+ * If not present, defaults to `'geom'` for generic tables, `'quadbin'` for Quadbin sources and `'h3'` for H3 sources.
115
130
  */
116
- columns?: string[];
131
+ spatialDataColumn?: string;
117
132
 
118
133
  /**
119
- * The column name and the type of geospatial support.
134
+ * Relative resolution of a tile. Higher values increase density and data size. At `tileResolution = 1`, tile geometry is
135
+ * quantized to a 1024x1024 grid. Increasing or decreasing the resolution will increase or decrease the dimensions of
136
+ * the quantization grid proportionately.
120
137
  *
121
- * If not present, defaults to `'geom'` for generic tables, `'quadbin'` for Quadbin sources and `'h3'` for H3 sources.
138
+ * Supported `tileResolution` values, with corresponding grid sizes:
139
+ *
140
+ * - 0.25: 256x256
141
+ * - 0.5: 512x512
142
+ * - 1: 1024x1024
143
+ * - 2: 2048x2048
144
+ * - 4: 4096x4096
122
145
  */
123
- spatialDataColumn?: string;
146
+ tileResolution?: TileResolution;
124
147
  };
125
148
 
126
149
  export type TilesetSourceOptions = {
@@ -130,12 +153,23 @@ export type TilesetSourceOptions = {
130
153
  tableName: string;
131
154
  };
132
155
 
156
+ export type ColumnsOption = {
157
+ /**
158
+ * Columns to retrieve from the table.
159
+ *
160
+ * If not present, all columns are returned.
161
+ */
162
+ columns?: string[];
163
+ };
164
+
133
165
  export type SpatialDataType = 'geo' | 'h3' | 'quadbin';
134
166
 
135
167
  export type TilejsonMapInstantiation = MapInstantiation & {
136
168
  tilejson: {url: string[]};
137
169
  };
138
170
 
171
+ export type TileResolution = 0.25 | 0.5 | 1 | 2 | 4;
172
+
139
173
  export interface Tilejson {
140
174
  tilejson: string;
141
175
  name: string;
@@ -153,6 +187,7 @@ export interface Tilejson {
153
187
  center: [number, number, number];
154
188
  vector_layers: VectorLayer[];
155
189
  tilestats: Tilestats;
190
+ tileResolution?: TileResolution;
156
191
  }
157
192
 
158
193
  export interface Tilestats {