@deck.gl/carto 8.7.10 → 8.8.0-alpha.4

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 (58) hide show
  1. package/dist/dist.dev.js +33337 -40143
  2. package/dist/es5/api/layer-map.js +17 -5
  3. package/dist/es5/api/layer-map.js.map +1 -1
  4. package/dist/es5/api/maps-api-common.js +1 -0
  5. package/dist/es5/api/maps-api-common.js.map +1 -1
  6. package/dist/es5/api/maps-v3-client.js +9 -23
  7. package/dist/es5/api/maps-v3-client.js.map +1 -1
  8. package/dist/es5/api/parseMap.js +14 -3
  9. package/dist/es5/api/parseMap.js.map +1 -1
  10. package/dist/es5/index.js +16 -0
  11. package/dist/es5/index.js.map +1 -1
  12. package/dist/es5/layers/carto-layer.js +38 -13
  13. package/dist/es5/layers/carto-layer.js.map +1 -1
  14. package/dist/es5/layers/h3-tile-layer.js +107 -0
  15. package/dist/es5/layers/h3-tile-layer.js.map +1 -0
  16. package/dist/es5/layers/h3-tileset-2d.js +175 -0
  17. package/dist/es5/layers/h3-tileset-2d.js.map +1 -0
  18. package/dist/es5/layers/quadkey-tile-layer.js +103 -0
  19. package/dist/es5/layers/quadkey-tile-layer.js.map +1 -0
  20. package/dist/es5/layers/quadkey-tileset-2d.js +89 -0
  21. package/dist/es5/layers/quadkey-tileset-2d.js.map +1 -0
  22. package/dist/es5/layers/spatial-index-tile-layer.js +92 -0
  23. package/dist/es5/layers/spatial-index-tile-layer.js.map +1 -0
  24. package/dist/esm/api/layer-map.js +12 -4
  25. package/dist/esm/api/layer-map.js.map +1 -1
  26. package/dist/esm/api/maps-api-common.js +1 -0
  27. package/dist/esm/api/maps-api-common.js.map +1 -1
  28. package/dist/esm/api/maps-v3-client.js +2 -19
  29. package/dist/esm/api/maps-v3-client.js.map +1 -1
  30. package/dist/esm/api/parseMap.js +15 -4
  31. package/dist/esm/api/parseMap.js.map +1 -1
  32. package/dist/esm/index.js +2 -0
  33. package/dist/esm/index.js.map +1 -1
  34. package/dist/esm/layers/carto-layer.js +37 -8
  35. package/dist/esm/layers/carto-layer.js.map +1 -1
  36. package/dist/esm/layers/h3-tile-layer.js +69 -0
  37. package/dist/esm/layers/h3-tile-layer.js.map +1 -0
  38. package/dist/esm/layers/h3-tileset-2d.js +118 -0
  39. package/dist/esm/layers/h3-tileset-2d.js.map +1 -0
  40. package/dist/esm/layers/quadkey-tile-layer.js +63 -0
  41. package/dist/esm/layers/quadkey-tile-layer.js.map +1 -0
  42. package/dist/esm/layers/quadkey-tileset-2d.js +48 -0
  43. package/dist/esm/layers/quadkey-tileset-2d.js.map +1 -0
  44. package/dist/esm/layers/spatial-index-tile-layer.js +57 -0
  45. package/dist/esm/layers/spatial-index-tile-layer.js.map +1 -0
  46. package/dist.min.js +14 -14
  47. package/package.json +9 -8
  48. package/src/api/layer-map.ts +14 -4
  49. package/src/api/maps-api-common.ts +4 -3
  50. package/src/api/maps-v3-client.ts +3 -19
  51. package/src/api/parseMap.ts +20 -5
  52. package/src/index.ts +4 -0
  53. package/src/layers/{carto-layer.js → carto-layer.ts} +162 -23
  54. package/src/layers/h3-tile-layer.js +52 -0
  55. package/src/layers/h3-tileset-2d.js +108 -0
  56. package/src/layers/quadkey-tile-layer.js +47 -0
  57. package/src/layers/quadkey-tileset-2d.js +36 -0
  58. package/src/layers/spatial-index-tile-layer.js +48 -0
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@deck.gl/carto",
3
3
  "description": "CARTO official integration with Deck.gl. Build geospatial applications using CARTO and Deck.gl.",
4
4
  "license": "MIT",
5
- "version": "8.7.10",
5
+ "version": "8.8.0-alpha.4",
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },
@@ -31,12 +31,12 @@
31
31
  "prepublishOnly": "npm run build-bundle && npm run build-bundle -- --env.dev"
32
32
  },
33
33
  "dependencies": {
34
- "@loaders.gl/gis": "^3.1.5",
35
- "@loaders.gl/loader-utils": "^3.1.5",
36
- "@loaders.gl/mvt": "^3.1.5",
37
- "@loaders.gl/tiles": "^3.1.5",
34
+ "@loaders.gl/gis": "^3.2.0-alpha.4",
35
+ "@loaders.gl/loader-utils": "^3.2.0-alpha.4",
36
+ "@loaders.gl/mvt": "^3.2.0-alpha.4",
37
+ "@loaders.gl/tiles": "^3.2.0-alpha.4",
38
38
  "@luma.gl/constants": "^8.5.10",
39
- "@math.gl/web-mercator": "^3.5.7",
39
+ "@math.gl/web-mercator": "3.6.0-alpha.5",
40
40
  "cartocolor": "^4.0.2",
41
41
  "d3-array": "^2.8.0",
42
42
  "d3-color": "^2.0.0",
@@ -53,9 +53,10 @@
53
53
  "peerDependencies": {
54
54
  "@deck.gl/aggregation-layers": "^8.0.0",
55
55
  "@deck.gl/core": "^8.0.0",
56
+ "@deck.gl/extensions": "^8.0.0",
56
57
  "@deck.gl/geo-layers": "^8.0.0",
57
58
  "@deck.gl/layers": "^8.0.0",
58
- "@loaders.gl/core": "^3.1.5"
59
+ "@loaders.gl/core": "^3.0.0"
59
60
  },
60
- "gitHead": "0d3e70aefb845cd7b37ce030a67d8a6540420c5c"
61
+ "gitHead": "608c74fff3c955142c4e1f5e77b9e21ebbf690f7"
61
62
  }
@@ -42,6 +42,12 @@ export const AGGREGATION = {
42
42
  sum: 'SUM'
43
43
  };
44
44
 
45
+ export const OPACITY_MAP = {
46
+ getFillColor: 'opacity',
47
+ getLineColor: 'strokeOpacity',
48
+ getTextColor: 'opacity'
49
+ };
50
+
45
51
  const AGGREGATION_FUNC = {
46
52
  'count unique': (values, accessor) => groupSort(values, v => v.length, accessor).length,
47
53
  median,
@@ -71,7 +77,6 @@ const sharedPropMap = {
71
77
  enable3d: 'extruded',
72
78
  elevationScale: 'elevationScale',
73
79
  filled: 'filled',
74
- opacity: 'opacity',
75
80
  strokeColor: 'getLineColor',
76
81
  stroked: 'stroked',
77
82
  thickness: 'getLineWidth',
@@ -225,6 +230,10 @@ function normalizeAccessor(accessor, data) {
225
230
  return accessor;
226
231
  }
227
232
 
233
+ export function opacityToAlpha(opacity) {
234
+ return opacity !== undefined ? Math.round(255 * Math.pow(opacity, 1 / 2.2)) : 255;
235
+ }
236
+
228
237
  export function getColorValueAccessor({name}, colorAggregation, data: any) {
229
238
  const aggregator = AGGREGATION_FUNC[colorAggregation];
230
239
  const accessor = values => aggregator(values, p => p[name]);
@@ -259,11 +268,12 @@ export function getColorAccessor(
259
268
  scale.domain(domain);
260
269
  scale.range(scaleColor);
261
270
  scale.unknown(UNKNOWN_COLOR);
262
- const alpha = opacity !== undefined ? Math.round(255 * Math.pow(opacity, 1 / 2.2)) : 255;
271
+ const alpha = opacityToAlpha(opacity);
263
272
 
264
273
  const accessor = properties => {
265
- const {r, g, b} = rgb(scale(properties[name]));
266
- return [r, g, b, alpha];
274
+ const propertyValue = properties[name];
275
+ const {r, g, b} = rgb(scale(propertyValue));
276
+ return [r, g, b, propertyValue === null ? 0 : alpha];
267
277
  };
268
278
  return normalizeAccessor(accessor, data);
269
279
  }
@@ -20,8 +20,8 @@ export const MAP_TYPES = {
20
20
  TILESET: 'tileset'
21
21
  } as const;
22
22
  export type MapType = ValuesOf<typeof MAP_TYPES>;
23
- export const COLUMNS_SUPPORT = [MAP_TYPES.TABLE];
24
- export const GEO_COLUMN_SUPPORT = [MAP_TYPES.QUERY, MAP_TYPES.TABLE];
23
+ export const COLUMNS_SUPPORT: MapType[] = [MAP_TYPES.TABLE];
24
+ export const GEO_COLUMN_SUPPORT: MapType[] = [MAP_TYPES.QUERY, MAP_TYPES.TABLE];
25
25
 
26
26
  // AVAILABLE FORMATS
27
27
  export const FORMATS = {
@@ -35,6 +35,7 @@ export type Format = ValuesOf<typeof FORMATS>;
35
35
  // AVAILABLE FORMATS FOR TILES
36
36
  export const TILE_FORMATS = {
37
37
  MVT: 'mvt',
38
+ JSON: 'json',
38
39
  GEOJSON: 'geojson',
39
40
  BINARY: 'binary'
40
41
  } as const;
@@ -59,7 +60,7 @@ export interface SchemaField {
59
60
  export interface MapInstantiation extends MapInstantiationFormats {
60
61
  nrows: number;
61
62
  size?: number;
62
- schema?: SchemaField[];
63
+ schema: SchemaField[];
63
64
  }
64
65
 
65
66
  type MapInstantiationFormats = Record<
@@ -112,7 +112,6 @@ type FetchLayerDataParams = {
112
112
  credentials: CloudNativeCredentials;
113
113
  geoColumn?: string;
114
114
  columns?: string[];
115
- schema?: boolean;
116
115
  clientId?: string;
117
116
  format?: Format;
118
117
  formatTiles?: TileFormat;
@@ -128,15 +127,11 @@ function getParameters({
128
127
  source,
129
128
  geoColumn,
130
129
  columns,
131
- schema,
132
130
  clientId,
133
131
  aggregationExp,
134
132
  aggregationResLevel
135
133
  }: Omit<FetchLayerDataParams, 'connection' | 'credentials'>) {
136
134
  const parameters = [encodeParameter('client', clientId || DEFAULT_CLIENT)];
137
- if (schema) {
138
- parameters.push(encodeParameter('schema', true));
139
- }
140
135
 
141
136
  const sourceName = type === MAP_TYPES.QUERY ? 'q' : 'name';
142
137
  parameters.push(encodeParameter(sourceName, source));
@@ -164,7 +159,6 @@ export async function mapInstantiation({
164
159
  credentials,
165
160
  geoColumn,
166
161
  columns,
167
- schema,
168
162
  clientId,
169
163
  aggregationExp,
170
164
  aggregationResLevel
@@ -175,7 +169,6 @@ export async function mapInstantiation({
175
169
  source,
176
170
  geoColumn,
177
171
  columns,
178
- schema,
179
172
  clientId,
180
173
  aggregationExp,
181
174
  aggregationResLevel
@@ -248,8 +241,8 @@ function checkFetchLayerDataParameters({
248
241
 
249
242
  export interface FetchLayerDataResult {
250
243
  data: any;
251
- format: Format;
252
- schema?: SchemaField[];
244
+ format?: Format;
245
+ schema: SchemaField[];
253
246
  }
254
247
  export async function fetchLayerData({
255
248
  type,
@@ -260,7 +253,6 @@ export async function fetchLayerData({
260
253
  columns,
261
254
  format,
262
255
  formatTiles,
263
- schema,
264
256
  clientId,
265
257
  aggregationExp,
266
258
  aggregationResLevel
@@ -276,18 +268,13 @@ export async function fetchLayerData({
276
268
  columns,
277
269
  format,
278
270
  formatTiles,
279
- schema,
280
271
  clientId,
281
272
  aggregationExp,
282
273
  aggregationResLevel
283
274
  });
284
275
 
285
276
  const data = await requestData({url, format: mapFormat, accessToken});
286
- const result: FetchLayerDataResult = {data, format: mapFormat};
287
- if (schema) {
288
- result.schema = metadata.schema;
289
- }
290
-
277
+ const result: FetchLayerDataResult = {data, format: mapFormat, schema: metadata.schema};
291
278
  return result;
292
279
  }
293
280
 
@@ -300,7 +287,6 @@ async function _fetchDataUrl({
300
287
  columns,
301
288
  format,
302
289
  formatTiles,
303
- schema,
304
290
  clientId,
305
291
  aggregationExp,
306
292
  aggregationResLevel
@@ -334,7 +320,6 @@ async function _fetchDataUrl({
334
320
  credentials: localCreds,
335
321
  geoColumn,
336
322
  columns,
337
- schema,
338
323
  clientId,
339
324
  aggregationExp,
340
325
  aggregationResLevel
@@ -390,7 +375,6 @@ export async function getData({
390
375
  geoColumn,
391
376
  columns,
392
377
  format,
393
- schema: false,
394
378
  clientId
395
379
  });
396
380
  return layerData.data;
@@ -6,7 +6,9 @@ import {
6
6
  getColorValueAccessor,
7
7
  getSizeAccessor,
8
8
  getTextAccessor,
9
- getTextPixelOffsetAccessor
9
+ getTextPixelOffsetAccessor,
10
+ OPACITY_MAP,
11
+ opacityToAlpha
10
12
  } from './layer-map';
11
13
  import {_flatten as flatten, log} from '@deck.gl/core';
12
14
  import {assert} from '../utils';
@@ -131,10 +133,21 @@ function createStyleProps(config, mapping) {
131
133
  mapProps(config, result, mapping);
132
134
 
133
135
  // Kepler format sometimes omits strokeColor. TODO: remove once we can rely on
134
- // `strokeColor` always being sert when `stroke: true`.
136
+ // `strokeColor` always being set when `stroke: true`.
135
137
  if (result.stroked && !result.getLineColor) {
136
138
  result.getLineColor = result.getFillColor;
137
139
  }
140
+
141
+ for (const colorAccessor in OPACITY_MAP) {
142
+ if (Array.isArray(result[colorAccessor])) {
143
+ const color = [...result[colorAccessor]];
144
+ const opacityKey = OPACITY_MAP[colorAccessor];
145
+ const opacity = config.visConfig[opacityKey];
146
+ color[3] = opacityToAlpha(opacity);
147
+ result[colorAccessor] = color;
148
+ }
149
+ }
150
+
138
151
  result.highlightColor = config.visConfig.enable3d ? [255, 255, 255, 60] : [252, 242, 26, 255];
139
152
  return result;
140
153
  }
@@ -159,7 +172,7 @@ function createChannelProps(visualChannels, type, config, data) {
159
172
  if (!AGGREGATION[colorAggregation]) {
160
173
  result.getColorValue = getColorValueAccessor(colorField, colorAggregation, data);
161
174
  } else {
162
- result.getColorWeight = d => [colorField.name];
175
+ result.getColorWeight = d => d[colorField.name];
163
176
  }
164
177
  }
165
178
  } else if (colorField) {
@@ -167,13 +180,15 @@ function createChannelProps(visualChannels, type, config, data) {
167
180
  colorField,
168
181
  colorScale,
169
182
  visConfig.colorRange,
170
- 1, // Rely on layer opacity
183
+ visConfig.opacity,
171
184
  data
172
185
  );
173
186
  }
174
187
 
175
188
  if (strokeColorField) {
176
- const opacity = visConfig.strokeOpacity !== undefined ? visConfig.strokeOpacity : 1;
189
+ const fallbackOpacity = type === 'point' ? visConfig.opacity : 1;
190
+ const opacity =
191
+ visConfig.strokeOpacity !== undefined ? visConfig.strokeOpacity : fallbackOpacity;
177
192
  result.getLineColor = getColorAccessor(
178
193
  strokeColorField,
179
194
  strokeColorScale,
package/src/index.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  export {getDefaultCredentials, setDefaultCredentials} from './config';
2
2
  export {default as CartoLayer} from './layers/carto-layer';
3
3
  export {default as _CartoTileLayer} from './layers/carto-tile-layer';
4
+ export {default as _H3TileLayer} from './layers/h3-tile-layer';
5
+ export {default as _QuadkeyTileLayer} from './layers/quadkey-tile-layer';
4
6
  export {default as BASEMAP} from './basemap';
5
7
  export {default as colorBins} from './style/color-bins-style';
6
8
  export {default as colorCategories} from './style/color-categories-style';
@@ -16,3 +18,5 @@ export {
16
18
  getData,
17
19
  mapInstantiation as _mapInstantiation
18
20
  } from './api';
21
+
22
+ export type {CartoLayerProps} from './layers/carto-layer';
@@ -1,16 +1,30 @@
1
- import {CompositeLayer, log} from '@deck.gl/core';
1
+ import {CompositeLayer, Layer, log} from '@deck.gl/core';
2
2
  import CartoTileLayer from './carto-tile-layer';
3
+ import H3TileLayer from './h3-tile-layer';
4
+ import QuadkeyTileLayer from './quadkey-tile-layer';
3
5
  import {MVTLayer} from '@deck.gl/geo-layers';
4
6
  import {GeoJsonLayer} from '@deck.gl/layers';
5
7
  import {fetchLayerData, getDataV2, API_VERSIONS} from '../api';
6
8
  import {
7
9
  COLUMNS_SUPPORT,
10
+ Format,
8
11
  FORMATS,
9
12
  GEO_COLUMN_SUPPORT,
13
+ MapType,
10
14
  MAP_TYPES,
15
+ TileFormat,
11
16
  TILE_FORMATS
12
17
  } from '../api/maps-api-common';
13
- import {getDefaultCredentials} from '../config';
18
+ import {
19
+ ClassicCredentials,
20
+ CloudNativeCredentials,
21
+ Credentials,
22
+ getDefaultCredentials
23
+ } from '../config';
24
+ import {CompositeLayerProps, LayerProps} from 'modules/core/src/types/layer-props';
25
+ import {ChangeFlags} from 'modules/core/src/lib/layer-state';
26
+ import {FetchLayerDataResult} from '../api/maps-v3-client';
27
+ import {assert} from '../utils';
14
28
 
15
29
  const defaultProps = {
16
30
  // (String, required): data resource to load. table name, sql query or tileset name.
@@ -43,22 +57,114 @@ const defaultProps = {
43
57
  geoColumn: null,
44
58
 
45
59
  // (Array<String>, optional): names of columns to fetch. By default, all columns are fetched.
46
- columns: {type: 'array', value: null}
60
+ columns: {type: 'array', value: null},
61
+
62
+ // (String, optional): aggregration SQL expression. Only used for spatial index datasets
63
+ aggregationExp: null,
64
+
65
+ // (Number, optional): aggregration resolution level. Only used for spatial index datasets, defaults to 6 for quadkeys, 4 for h3
66
+ aggregationResLevel: null
47
67
  };
48
68
 
49
- export default class CartoLayer extends CompositeLayer {
50
- initializeState() {
69
+ export interface CartoLayerProps<DataT = any> extends CompositeLayerProps<DataT> {
70
+ /**
71
+ * Either a SQL query or a name of dataset/tileset.
72
+ */
73
+ data: string;
74
+
75
+ /**
76
+ * Data type.
77
+ *
78
+ * Possible values are:
79
+ * * `MAP_TYPES.QUERY`, if data is a SQL query.
80
+ * * `MAP_TYPES.TILESET`, if data is a tileset name.
81
+ * * `MAP_TYPES.TABLE`, if data is a dataset name. Only supported with API v3.
82
+ */
83
+ type: MapType;
84
+
85
+ /**
86
+ * Name of the connection registered in the CARTO workspace.
87
+ *
88
+ * Required when apiVersion is `API_VERSIONS.V3`.
89
+ */
90
+ connection?: string;
91
+
92
+ /**
93
+ * Use to override the default data format.
94
+ *
95
+ * Only supported when apiVersion is `API_VERSIONS.V3`.
96
+ *
97
+ * Possible values are: `FORMATS.GEOJSON`, `FORMATS.JSON` and `FORMATS.TILEJSON`.
98
+ */
99
+ format?: Format;
100
+
101
+ /**
102
+ * Use to override the default tile data format.
103
+ *
104
+ * Only supported when apiVersion is `API_VERSIONS.V3` and format is `FORMATS.TILEJSON`.
105
+ *
106
+ * Possible values are: `TILE_FORMATS.BINARY`, `TILE_FORMATS.GEOJSON` and `TILE_FORMATS.MVT`.
107
+ */
108
+ formatTiles?: TileFormat;
109
+
110
+ /**
111
+ * Name of the geo_column in the CARTO platform.
112
+ *
113
+ * Use this override the default column (`'geom'`), from which the geometry information should be fetched.
114
+ *
115
+ * Only supported when apiVersion is `API_VERSIONS.V3` and type is `MAP_TYPES.TABLE`.
116
+ */
117
+ geoColumn?: string;
118
+
119
+ /**
120
+ * Names of columns to fetch.
121
+ *
122
+ * By default, all columns are fetched
123
+ *
124
+ * Only supported when apiVersion is `API_VERSIONS.V3` and type is `MAP_TYPES.TABLE`.
125
+ */
126
+ columns?: string[];
127
+
128
+ /**
129
+ * A string pointing to a unique attribute at the result of the query.
130
+ *
131
+ * A unique attribute is needed for highlighting with vector tiles when a feature is split across two or more tiles.
132
+ */
133
+ uniqueIdProperty?: string;
134
+
135
+ /**
136
+ * Optional. Overrides the configuration to connect with CARTO.
137
+ *
138
+ * @see Credentials
139
+ */
140
+ credentials?: Credentials;
141
+
142
+ /**
143
+ * Called when the request to the CARTO Maps API failed.
144
+ *
145
+ * By default the Error is thrown.
146
+ */
147
+ onDataError?: (err: unknown) => void;
148
+
149
+ clientId?: string;
150
+ }
151
+
152
+ export default class CartoLayer<DataT = any> extends CompositeLayer<CartoLayerProps<DataT>> {
153
+ static layerName = 'CartoLayer';
154
+ static defaultProps = defaultProps as any;
155
+
156
+ initializeState(): void {
51
157
  this.state = {
52
158
  data: null,
53
159
  apiVersion: null
54
160
  };
55
161
  }
56
162
 
57
- get isLoaded() {
163
+ get isLoaded(): boolean {
58
164
  return this.getSubLayers().length > 0 && super.isLoaded;
59
165
  }
60
166
 
61
- _checkProps(props) {
167
+ _checkProps(props: CartoLayerProps): void {
62
168
  const {type, credentials, connection, geoColumn, columns} = props;
63
169
  const localCreds = {...getDefaultCredentials(), ...credentials};
64
170
  const {apiVersion} = localCreds;
@@ -97,7 +203,16 @@ export default class CartoLayer extends CompositeLayer {
97
203
  }
98
204
  }
99
205
 
100
- updateState({props, oldProps, changeFlags}) {
206
+ updateState({
207
+ props,
208
+ oldProps,
209
+ changeFlags
210
+ }: {
211
+ props: CartoLayerProps;
212
+ oldProps: CartoLayerProps;
213
+ context: any;
214
+ changeFlags: ChangeFlags;
215
+ }): void {
101
216
  this._checkProps(props);
102
217
  const shouldUpdateData =
103
218
  changeFlags.dataChanged ||
@@ -111,40 +226,57 @@ export default class CartoLayer extends CompositeLayer {
111
226
 
112
227
  if (shouldUpdateData) {
113
228
  this.setState({data: null, apiVersion: null});
229
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
114
230
  this._updateData();
115
231
  }
116
232
  }
117
233
 
118
- async _updateData() {
234
+ async _updateData(): Promise<void> {
119
235
  try {
120
- const {type, data: source, clientId, credentials, ...rest} = this.props;
236
+ const {type, data: source, clientId, credentials, connection, ...rest} = this.props;
121
237
  const localConfig = {...getDefaultCredentials(), ...credentials};
122
238
  const {apiVersion} = localConfig;
123
239
 
124
- let result;
240
+ let result: FetchLayerDataResult;
125
241
  if (apiVersion === API_VERSIONS.V1 || apiVersion === API_VERSIONS.V2) {
126
- result = {data: await getDataV2({type, source, credentials})};
242
+ result = {
243
+ data: await getDataV2({type, source, credentials: credentials as ClassicCredentials})
244
+ };
127
245
  } else {
128
- result = await fetchLayerData({type, source, clientId, credentials, ...rest});
246
+ result = await fetchLayerData({
247
+ type,
248
+ source,
249
+ clientId,
250
+ credentials: credentials as CloudNativeCredentials,
251
+ connection,
252
+ ...rest
253
+ });
129
254
  }
130
255
 
131
256
  this.setState({...result, apiVersion});
132
- this.props.onDataLoad(result.data);
257
+
258
+ this.props.onDataLoad?.(result.data, {
259
+ propName: 'data',
260
+ layer: this
261
+ });
133
262
  } catch (err) {
134
263
  if (this.props.onDataError) {
135
- this.props.onDataError(err);
264
+ this.props.onDataError(err as Error);
136
265
  } else {
137
266
  throw err;
138
267
  }
139
268
  }
140
269
  }
141
270
 
142
- _getSubLayerAndProps() {
271
+ _getSubLayerAndProps(): [any, LayerProps] {
272
+ assert(this.state);
273
+
143
274
  const {data, format, apiVersion} = this.state;
144
275
 
145
276
  const {uniqueIdProperty} = defaultProps;
146
- const props = {uniqueIdProperty, ...this.props};
147
- delete props.data;
277
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
278
+ const {data: _notUsed, ...propsNoData} = this.props;
279
+ const props = {uniqueIdProperty, ...propsNoData};
148
280
 
149
281
  if (apiVersion === API_VERSIONS.V1 || apiVersion === API_VERSIONS.V2) {
150
282
  return [MVTLayer, props];
@@ -155,8 +287,16 @@ export default class CartoLayer extends CompositeLayer {
155
287
  const tileUrl = new URL(data.tiles[0]);
156
288
 
157
289
  props.formatTiles =
158
- props.formatTiles || tileUrl.searchParams.get('formatTiles') || TILE_FORMATS.MVT;
290
+ props.formatTiles ||
291
+ (tileUrl.searchParams.get('formatTiles') as TileFormat) ||
292
+ TILE_FORMATS.MVT;
159
293
 
294
+ if (data.scheme === 'h3') {
295
+ return [H3TileLayer, props];
296
+ }
297
+ if (data.scheme === 'quadkey') {
298
+ return [QuadkeyTileLayer, props];
299
+ }
160
300
  return props.formatTiles === TILE_FORMATS.MVT ? [MVTLayer, props] : [CartoTileLayer, props];
161
301
  }
162
302
 
@@ -164,7 +304,9 @@ export default class CartoLayer extends CompositeLayer {
164
304
  return [GeoJsonLayer, props];
165
305
  }
166
306
 
167
- renderLayers() {
307
+ renderLayers(): Layer | null {
308
+ assert(this.state);
309
+
168
310
  const {data} = this.state;
169
311
 
170
312
  if (!data) return null;
@@ -184,6 +326,3 @@ export default class CartoLayer extends CompositeLayer {
184
326
  );
185
327
  }
186
328
  }
187
-
188
- CartoLayer.layerName = 'CartoLayer';
189
- CartoLayer.defaultProps = defaultProps;
@@ -0,0 +1,52 @@
1
+ import {CompositeLayer} from '@deck.gl/core';
2
+ import {H3HexagonLayer} from '@deck.gl/geo-layers';
3
+ import H3Tileset2D from './h3-tileset-2d';
4
+ import SpatialIndexTileLayer from './spatial-index-tile-layer';
5
+
6
+ const renderSubLayers = props => {
7
+ const {data} = props;
8
+ const {index} = props.tile;
9
+ if (!data || !data.length) return null;
10
+
11
+ return new H3HexagonLayer(props, {
12
+ centerHexagon: index,
13
+ highPrecision: true
14
+ });
15
+ };
16
+
17
+ const defaultProps = {
18
+ aggregationResLevel: 4
19
+ };
20
+
21
+ export default class H3TileLayer extends CompositeLayer {
22
+ initializeState() {
23
+ this.setState({data: null, tileJSON: null});
24
+ }
25
+
26
+ updateState({props, oldProps, context, changeFlags}) {
27
+ if (changeFlags.dataChanged) {
28
+ let {data} = this.props;
29
+ const tileJSON = data;
30
+ data = tileJSON.tiles;
31
+ this.setState({data, tileJSON});
32
+ }
33
+ }
34
+
35
+ renderLayers() {
36
+ const {data, tileJSON} = this.state;
37
+ const maxZoom = parseInt(tileJSON.maxresolution);
38
+ return [
39
+ new SpatialIndexTileLayer(this.props, {
40
+ id: 'h3-tile-layer',
41
+ data,
42
+ getHexagon: d => d.id,
43
+ TilesetClass: H3Tileset2D,
44
+ renderSubLayers,
45
+ maxZoom
46
+ })
47
+ ];
48
+ }
49
+ }
50
+
51
+ H3TileLayer.layerName = 'H3TileLayer';
52
+ H3TileLayer.defaultProps = defaultProps;