@deck.gl/carto 9.0.0-beta.8 → 9.0.0-beta.9

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 (75) 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 +7 -3
  7. package/dist/cartoRasterTile-worker.js +5 -8
  8. package/dist/cartoSpatialTile-worker.js +1 -1
  9. package/dist/cartoVectorTile-worker.js +1 -1
  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 +83 -46
  14. package/dist/index.cjs +70 -43
  15. package/dist/index.cjs.map +4 -4
  16. package/dist/layers/h3-tile-layer.d.ts.map +1 -1
  17. package/dist/layers/h3-tile-layer.js +3 -1
  18. package/dist/layers/quadbin-tile-layer.d.ts.map +1 -1
  19. package/dist/layers/quadbin-tile-layer.js +3 -1
  20. package/dist/layers/raster-layer.d.ts.map +1 -1
  21. package/dist/layers/raster-layer.js +5 -6
  22. package/dist/layers/raster-tile-layer.d.ts.map +1 -1
  23. package/dist/layers/raster-tile-layer.js +3 -1
  24. package/dist/layers/schema/carto-raster-tile-loader.d.ts +2 -2
  25. package/dist/layers/schema/carto-raster-tile-loader.d.ts.map +1 -1
  26. package/dist/layers/schema/carto-raster-tile-loader.js +3 -4
  27. package/dist/layers/schema/carto-raster-tile.d.ts.map +1 -1
  28. package/dist/layers/schema/carto-raster-tile.js +2 -4
  29. package/dist/layers/schema/carto-spatial-tile-loader.js +1 -1
  30. package/dist/layers/schema/carto-vector-tile-loader.js +1 -1
  31. package/dist/layers/spatial-index-tile-layer.d.ts.map +1 -1
  32. package/dist/layers/spatial-index-tile-layer.js +4 -1
  33. package/dist/layers/vector-tile-layer.d.ts +4 -4
  34. package/dist/layers/vector-tile-layer.d.ts.map +1 -1
  35. package/dist/layers/vector-tile-layer.js +3 -1
  36. package/dist/sources/h3-query-source.d.ts.map +1 -1
  37. package/dist/sources/h3-query-source.js +2 -1
  38. package/dist/sources/h3-table-source.d.ts.map +1 -1
  39. package/dist/sources/h3-table-source.js +2 -4
  40. package/dist/sources/quadbin-query-source.d.ts.map +1 -1
  41. package/dist/sources/quadbin-query-source.js +2 -1
  42. package/dist/sources/quadbin-table-source.d.ts.map +1 -1
  43. package/dist/sources/quadbin-table-source.js +2 -4
  44. package/dist/sources/types.d.ts +38 -6
  45. package/dist/sources/types.d.ts.map +1 -1
  46. package/dist/sources/vector-query-source.d.ts +2 -4
  47. package/dist/sources/vector-query-source.d.ts.map +1 -1
  48. package/dist/sources/vector-query-source.js +8 -2
  49. package/dist/sources/vector-table-source.d.ts +2 -2
  50. package/dist/sources/vector-table-source.d.ts.map +1 -1
  51. package/dist/sources/vector-table-source.js +8 -2
  52. package/dist/utils.d.ts.map +1 -1
  53. package/dist/utils.js +5 -1
  54. package/dist.min.js +7 -7
  55. package/package.json +4 -4
  56. package/src/api/common.ts +1 -1
  57. package/src/api/fetch-map.ts +8 -3
  58. package/src/api/request-with-parameters.ts +16 -5
  59. package/src/constants.ts +5 -0
  60. package/src/layers/h3-tile-layer.ts +3 -1
  61. package/src/layers/quadbin-tile-layer.ts +3 -1
  62. package/src/layers/raster-layer.ts +7 -12
  63. package/src/layers/raster-tile-layer.ts +3 -1
  64. package/src/layers/schema/carto-raster-tile-loader.ts +5 -5
  65. package/src/layers/schema/carto-raster-tile.ts +3 -4
  66. package/src/layers/spatial-index-tile-layer.ts +4 -1
  67. package/src/layers/vector-tile-layer.ts +10 -6
  68. package/src/sources/h3-query-source.ts +2 -1
  69. package/src/sources/h3-table-source.ts +2 -6
  70. package/src/sources/quadbin-query-source.ts +2 -1
  71. package/src/sources/quadbin-table-source.ts +2 -6
  72. package/src/sources/types.ts +41 -6
  73. package/src/sources/vector-query-source.ts +22 -6
  74. package/src/sources/vector-table-source.ts +21 -3
  75. 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-beta.9",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
@@ -47,7 +47,7 @@
47
47
  "@loaders.gl/mvt": "^4.2.0-alpha.5",
48
48
  "@loaders.gl/schema": "^4.2.0-alpha.5",
49
49
  "@loaders.gl/tiles": "^4.2.0-alpha.5",
50
- "@luma.gl/constants": "9.0.0-beta.10",
50
+ "@luma.gl/constants": "^9.0.0",
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",
@@ -70,7 +70,7 @@
70
70
  "@deck.gl/geo-layers": "^9.0.0-beta",
71
71
  "@deck.gl/layers": "^9.0.0-beta",
72
72
  "@loaders.gl/core": "^4.2.0-alpha.5",
73
- "@luma.gl/core": "9.0.0-beta.10"
73
+ "@luma.gl/core": "^9.0.0"
74
74
  },
75
- "gitHead": "8867a1047c2693d44e4af9507c296cf7ab61f9e8"
75
+ "gitHead": "44cfc784310d1c6ac7766ff80e0df8c364f97354"
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
  }
@@ -23,17 +23,18 @@ 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
28
  return REQUEST_CACHE.get(key);
29
29
  }
30
30
 
31
31
  let url = baseUrl;
32
32
  if (parameters) {
33
- const allParameters = {...DEFAULT_PARAMETERS, ...parameters};
34
- const encodedParameters = Object.entries(allParameters).map(([key, value]) => {
35
- return encodeParameter(key, value);
36
- });
33
+ const encodedParameters = Object.entries({...DEFAULT_PARAMETERS, ...parameters}).map(
34
+ ([key, value]) => {
35
+ return encodeParameter(key, value);
36
+ }
37
+ );
37
38
  url += `?${encodedParameters.join('&')}`;
38
39
  }
39
40
 
@@ -66,3 +67,13 @@ export async function requestWithParameters<T = any>({
66
67
  throw new CartoAPIError(error as Error, errorContext);
67
68
  }
68
69
  }
70
+
71
+ function createCacheKey(
72
+ baseUrl: string,
73
+ parameters: Record<string, string>,
74
+ headers: Record<string, string>
75
+ ): string {
76
+ const parameterEntries = Object.entries(parameters).sort(([a], [b]) => (a > b ? 1 : -1));
77
+ const headerEntries = Object.entries(headers).sort(([a], [b]) => (a > b ? 1 : -1));
78
+ return JSON.stringify({baseUrl, parameters: parameterEntries, headers: headerEntries});
79
+ }
@@ -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;
@@ -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 &
@@ -20,15 +20,18 @@ import type {Feature} 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);
@@ -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
  };
@@ -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 {
@@ -1,23 +1,26 @@
1
1
  /* eslint-disable camelcase */
2
+ import {DEFAULT_TILE_RESOLUTION} from '../constants';
2
3
  import {baseSource} from './base-source';
3
4
  import type {
4
5
  FilterOptions,
5
6
  SourceOptions,
6
7
  QuerySourceOptions,
7
8
  SpatialDataType,
8
- TilejsonResult
9
+ TilejsonResult,
10
+ ColumnsOption
9
11
  } from './types';
10
12
 
11
13
  export type VectorQuerySourceOptions = SourceOptions &
12
14
  QuerySourceOptions &
13
- FilterOptions & {
14
- columns?: string[];
15
- };
15
+ FilterOptions &
16
+ ColumnsOption;
17
+
16
18
  type UrlParameters = {
17
19
  columns?: string;
18
20
  filters?: string;
19
21
  spatialDataType: SpatialDataType;
20
22
  spatialDataColumn?: string;
23
+ tileResolution?: string;
21
24
  q: string;
22
25
  queryParameters?: string;
23
26
  };
@@ -25,8 +28,21 @@ type UrlParameters = {
25
28
  export const vectorQuerySource = async function (
26
29
  options: VectorQuerySourceOptions
27
30
  ): Promise<TilejsonResult> {
28
- const {columns, filters, spatialDataColumn = 'geom', sqlQuery, queryParameters} = options;
29
- const urlParameters: UrlParameters = {spatialDataColumn, spatialDataType: 'geo', q: sqlQuery};
31
+ const {
32
+ columns,
33
+ filters,
34
+ spatialDataColumn = 'geom',
35
+ sqlQuery,
36
+ tileResolution = DEFAULT_TILE_RESOLUTION,
37
+ queryParameters
38
+ } = options;
39
+
40
+ const urlParameters: UrlParameters = {
41
+ spatialDataColumn,
42
+ spatialDataType: 'geo',
43
+ tileResolution: tileResolution.toString(),
44
+ q: sqlQuery
45
+ };
30
46
 
31
47
  if (columns) {
32
48
  urlParameters.columns = columns.join(',');
@@ -1,27 +1,45 @@
1
1
  /* eslint-disable camelcase */
2
+ import {DEFAULT_TILE_RESOLUTION} from '../constants';
2
3
  import {baseSource} from './base-source';
3
4
  import type {
4
5
  FilterOptions,
6
+ ColumnsOption,
5
7
  SourceOptions,
6
8
  SpatialDataType,
7
9
  TableSourceOptions,
8
10
  TilejsonResult
9
11
  } from './types';
10
12
 
11
- export type VectorTableSourceOptions = SourceOptions & TableSourceOptions & FilterOptions;
13
+ export type VectorTableSourceOptions = SourceOptions &
14
+ TableSourceOptions &
15
+ FilterOptions &
16
+ ColumnsOption;
12
17
  type UrlParameters = {
13
18
  columns?: string;
14
19
  filters?: string;
15
20
  spatialDataType: SpatialDataType;
16
21
  spatialDataColumn?: string;
22
+ tileResolution?: string;
17
23
  name: string;
18
24
  };
19
25
 
20
26
  export const vectorTableSource = async function (
21
27
  options: VectorTableSourceOptions
22
28
  ): Promise<TilejsonResult> {
23
- const {columns, filters, spatialDataColumn = 'geom', tableName} = options;
24
- const urlParameters: UrlParameters = {name: tableName, spatialDataColumn, spatialDataType: 'geo'};
29
+ const {
30
+ columns,
31
+ filters,
32
+ spatialDataColumn = 'geom',
33
+ tableName,
34
+ tileResolution = DEFAULT_TILE_RESOLUTION
35
+ } = options;
36
+
37
+ const urlParameters: UrlParameters = {
38
+ name: tableName,
39
+ spatialDataColumn,
40
+ spatialDataType: 'geo',
41
+ tileResolution: tileResolution.toString()
42
+ };
25
43
 
26
44
  if (columns) {
27
45
  urlParameters.columns = columns.join(',');
package/src/utils.ts CHANGED
@@ -51,7 +51,11 @@ export function scaleIdentity() {
51
51
  return unknown;
52
52
  };
53
53
 
54
- scale.copy = () => scaleIdentity().unknown(unknown);
54
+ scale.copy = () => {
55
+ const scaleCopy = scaleIdentity();
56
+ scaleCopy.unknown(unknown);
57
+ return scaleCopy;
58
+ };
55
59
 
56
60
  return scale;
57
61
  }