@deck.gl/carto 8.9.0-alpha.2 → 8.9.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 (149) hide show
  1. package/dist/dist.dev.js +1940 -1675
  2. package/dist/es5/api/layer-map.js +117 -18
  3. package/dist/es5/api/layer-map.js.map +1 -1
  4. package/dist/es5/api/maps-v3-client.js +10 -8
  5. package/dist/es5/api/maps-v3-client.js.map +1 -1
  6. package/dist/es5/api/parseMap.js +62 -7
  7. package/dist/es5/api/parseMap.js.map +1 -1
  8. package/dist/es5/api/types.js +2 -0
  9. package/dist/es5/api/types.js.map +1 -0
  10. package/dist/es5/index.js +0 -20
  11. package/dist/es5/index.js.map +1 -1
  12. package/dist/es5/layers/carto-layer.js +19 -2
  13. package/dist/es5/layers/carto-layer.js.map +1 -1
  14. package/dist/es5/layers/carto-tile-layer.js +33 -107
  15. package/dist/es5/layers/carto-tile-layer.js.map +1 -1
  16. package/dist/es5/layers/h3-tile-layer.js +10 -1
  17. package/dist/es5/layers/h3-tile-layer.js.map +1 -1
  18. package/dist/es5/layers/quadbin-layer.js.map +1 -1
  19. package/dist/es5/layers/quadbin-tile-layer.js +10 -1
  20. package/dist/es5/layers/quadbin-tile-layer.js.map +1 -1
  21. package/dist/es5/layers/quadbin-tileset-2d.js +13 -11
  22. package/dist/es5/layers/quadbin-tileset-2d.js.map +1 -1
  23. package/dist/es5/layers/quadbin-utils.js +6 -82
  24. package/dist/es5/layers/quadbin-utils.js.map +1 -1
  25. package/dist/es5/layers/schema/carto-spatial-tile-loader.js +16 -32
  26. package/dist/es5/layers/schema/carto-spatial-tile-loader.js.map +1 -1
  27. package/dist/es5/layers/schema/carto-tile.js +30 -6
  28. package/dist/es5/layers/schema/carto-tile.js.map +1 -1
  29. package/dist/es5/layers/schema/carto-vector-tile-loader.js +81 -0
  30. package/dist/es5/layers/schema/carto-vector-tile-loader.js.map +1 -0
  31. package/dist/es5/layers/schema/spatialjson-utils.js +4 -3
  32. package/dist/es5/layers/schema/spatialjson-utils.js.map +1 -1
  33. package/dist/es5/layers/schema/tile-loader-utils.js +34 -0
  34. package/dist/es5/layers/schema/tile-loader-utils.js.map +1 -0
  35. package/dist/es5/layers/spatial-index-tile-layer.js +40 -0
  36. package/dist/es5/layers/spatial-index-tile-layer.js.map +1 -1
  37. package/dist/esm/api/layer-map.js +89 -9
  38. package/dist/esm/api/layer-map.js.map +1 -1
  39. package/dist/esm/api/maps-v3-client.js +5 -2
  40. package/dist/esm/api/maps-v3-client.js.map +1 -1
  41. package/dist/esm/api/parseMap.js +67 -7
  42. package/dist/esm/api/parseMap.js.map +1 -1
  43. package/dist/esm/api/types.js +2 -0
  44. package/dist/esm/api/types.js.map +1 -0
  45. package/dist/esm/index.js +0 -1
  46. package/dist/esm/index.js.map +1 -1
  47. package/dist/esm/layers/carto-layer.js +18 -0
  48. package/dist/esm/layers/carto-layer.js.map +1 -1
  49. package/dist/esm/layers/carto-tile-layer.js +31 -82
  50. package/dist/esm/layers/carto-tile-layer.js.map +1 -1
  51. package/dist/esm/layers/h3-tile-layer.js +6 -1
  52. package/dist/esm/layers/h3-tile-layer.js.map +1 -1
  53. package/dist/esm/layers/quadbin-layer.js.map +1 -1
  54. package/dist/esm/layers/quadbin-tile-layer.js +6 -1
  55. package/dist/esm/layers/quadbin-tile-layer.js.map +1 -1
  56. package/dist/esm/layers/quadbin-tileset-2d.js +12 -10
  57. package/dist/esm/layers/quadbin-tileset-2d.js.map +1 -1
  58. package/dist/esm/layers/quadbin-utils.js +2 -67
  59. package/dist/esm/layers/quadbin-utils.js.map +1 -1
  60. package/dist/esm/layers/schema/carto-spatial-tile-loader.js +14 -29
  61. package/dist/esm/layers/schema/carto-spatial-tile-loader.js.map +1 -1
  62. package/dist/esm/layers/schema/carto-tile.js +22 -6
  63. package/dist/esm/layers/schema/carto-tile.js.map +1 -1
  64. package/dist/esm/layers/schema/carto-vector-tile-loader.js +40 -0
  65. package/dist/esm/layers/schema/carto-vector-tile-loader.js.map +1 -0
  66. package/dist/esm/layers/schema/spatialjson-utils.js +4 -3
  67. package/dist/esm/layers/schema/spatialjson-utils.js.map +1 -1
  68. package/dist/esm/layers/schema/tile-loader-utils.js +23 -0
  69. package/dist/esm/layers/schema/tile-loader-utils.js.map +1 -0
  70. package/dist/esm/layers/spatial-index-tile-layer.js +40 -1
  71. package/dist/esm/layers/spatial-index-tile-layer.js.map +1 -1
  72. package/dist.min.js +4 -4
  73. package/package.json +4 -3
  74. package/src/api/layer-map.ts +102 -17
  75. package/src/api/maps-v3-client.ts +5 -3
  76. package/src/api/parseMap.ts +91 -17
  77. package/src/api/types.ts +108 -0
  78. package/src/index.ts +0 -5
  79. package/src/layers/carto-layer.ts +9 -2
  80. package/src/layers/carto-tile-layer.ts +32 -82
  81. package/src/layers/h3-tile-layer.ts +7 -1
  82. package/src/layers/quadbin-layer.ts +1 -1
  83. package/src/layers/quadbin-tile-layer.ts +7 -1
  84. package/src/layers/quadbin-tileset-2d.ts +14 -12
  85. package/src/layers/quadbin-utils.ts +4 -85
  86. package/src/layers/schema/carto-spatial-tile-loader.ts +12 -29
  87. package/src/layers/schema/carto-tile.ts +31 -6
  88. package/src/layers/schema/carto-vector-tile-loader.ts +39 -0
  89. package/src/layers/schema/spatialjson-utils.ts +4 -4
  90. package/src/layers/schema/tile-loader-utils.ts +22 -0
  91. package/src/layers/spatial-index-tile-layer.ts +37 -1
  92. package/typed/api/layer-map.d.ts +14 -13
  93. package/typed/api/layer-map.d.ts.map +1 -1
  94. package/typed/api/maps-v3-client.d.ts +1 -0
  95. package/typed/api/maps-v3-client.d.ts.map +1 -1
  96. package/typed/api/parseMap.d.ts +1 -0
  97. package/typed/api/parseMap.d.ts.map +1 -1
  98. package/typed/api/types.d.ts +87 -0
  99. package/typed/api/types.d.ts.map +1 -0
  100. package/typed/index.d.ts +0 -1
  101. package/typed/index.d.ts.map +1 -1
  102. package/typed/layers/carto-layer.d.ts.map +1 -1
  103. package/typed/layers/carto-tile-layer.d.ts +2 -0
  104. package/typed/layers/carto-tile-layer.d.ts.map +1 -1
  105. package/typed/layers/h3-tile-layer.d.ts.map +1 -1
  106. package/typed/layers/quadbin-layer.d.ts +1 -1
  107. package/typed/layers/quadbin-tile-layer.d.ts.map +1 -1
  108. package/typed/layers/quadbin-tileset-2d.d.ts +6 -5
  109. package/typed/layers/quadbin-tileset-2d.d.ts.map +1 -1
  110. package/typed/layers/quadbin-utils.d.ts +2 -12
  111. package/typed/layers/quadbin-utils.d.ts.map +1 -1
  112. package/typed/layers/schema/carto-spatial-tile-loader.d.ts.map +1 -1
  113. package/typed/layers/schema/carto-tile.d.ts +4 -0
  114. package/typed/layers/schema/carto-tile.d.ts.map +1 -1
  115. package/typed/layers/schema/carto-vector-tile-loader.d.ts +4 -0
  116. package/typed/layers/schema/carto-vector-tile-loader.d.ts.map +1 -0
  117. package/typed/layers/schema/spatialjson-utils.d.ts +1 -1
  118. package/typed/layers/schema/spatialjson-utils.d.ts.map +1 -1
  119. package/typed/layers/schema/tile-loader-utils.d.ts +5 -0
  120. package/typed/layers/schema/tile-loader-utils.d.ts.map +1 -0
  121. package/typed/layers/spatial-index-tile-layer.d.ts +2 -1
  122. package/typed/layers/spatial-index-tile-layer.d.ts.map +1 -1
  123. package/typed/api/index.js +0 -3
  124. package/typed/api/layer-map.js +0 -264
  125. package/typed/api/maps-api-common.js +0 -50
  126. package/typed/api/maps-client.js +0 -125
  127. package/typed/api/maps-v3-client.js +0 -304
  128. package/typed/api/parseMap.js +0 -178
  129. package/typed/basemap.js +0 -9
  130. package/typed/config.js +0 -35
  131. package/typed/index.js +0 -10
  132. package/typed/layers/carto-layer.js +0 -173
  133. package/typed/layers/carto-tile-layer.js +0 -105
  134. package/typed/layers/h3-tile-layer.js +0 -47
  135. package/typed/layers/h3-tileset-2d.js +0 -85
  136. package/typed/layers/quadkey-tile-layer.d.ts +0 -21
  137. package/typed/layers/quadkey-tile-layer.d.ts.map +0 -1
  138. package/typed/layers/quadkey-tile-layer.js +0 -42
  139. package/typed/layers/quadkey-tileset-2d.d.ts +0 -15
  140. package/typed/layers/quadkey-tileset-2d.d.ts.map +0 -1
  141. package/typed/layers/quadkey-tileset-2d.js +0 -36
  142. package/typed/layers/schema/carto-tile.js +0 -161
  143. package/typed/layers/spatial-index-tile-layer.js +0 -40
  144. package/typed/style/color-bins-style.js +0 -12
  145. package/typed/style/color-categories-style.js +0 -16
  146. package/typed/style/color-continuous-style.js +0 -12
  147. package/typed/style/palette.js +0 -62
  148. package/typed/style/utils.js +0 -15
  149. package/typed/utils.js +0 -4
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.9.0-alpha.2",
5
+ "version": "8.9.0-alpha.4",
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },
@@ -45,7 +45,8 @@
45
45
  "d3-scale": "^3.2.3",
46
46
  "h3-js": "^3.7.0",
47
47
  "moment-timezone": "^0.5.33",
48
- "pbf": "^3.2.1"
48
+ "pbf": "^3.2.1",
49
+ "quadbin": "^0.1.2"
49
50
  },
50
51
  "devDependencies": {
51
52
  "@loaders.gl/schema": "^3.2.5",
@@ -61,5 +62,5 @@
61
62
  "@deck.gl/layers": "^8.0.0",
62
63
  "@loaders.gl/core": "^3.0.0"
63
64
  },
64
- "gitHead": "9d9d51e600b437ce1933d42b4289a3e67db61349"
65
+ "gitHead": "f34f77e2b050306ade160a5628ea2844a4ceabc2"
65
66
  }
@@ -13,7 +13,7 @@ import {
13
13
  import {format as d3Format} from 'd3-format';
14
14
  import moment from 'moment-timezone';
15
15
 
16
- import {Layer, _ConstructorOf as ConstructorOf} from '@deck.gl/core';
16
+ import {Accessor, Layer, _ConstructorOf as ConstructorOf} from '@deck.gl/core';
17
17
  import {CPUGridLayer, HeatmapLayer, HexagonLayer} from '@deck.gl/aggregation-layers';
18
18
  import {GeoJsonLayer} from '@deck.gl/layers';
19
19
  import {H3HexagonLayer, MVTLayer} from '@deck.gl/geo-layers';
@@ -23,6 +23,15 @@ import H3TileLayer from '../layers/h3-tile-layer';
23
23
  import QuadbinTileLayer from '../layers/quadbin-tile-layer';
24
24
  import {TILE_FORMATS} from './maps-api-common';
25
25
  import {assert} from '../utils';
26
+ import {
27
+ CustomMarkersRange,
28
+ MapDataset,
29
+ MapTextSubLayerConfig,
30
+ TextLabel,
31
+ VisConfig,
32
+ VisualChannelField,
33
+ VisualChannels
34
+ } from './types';
26
35
 
27
36
  const SCALE_FUNCS = {
28
37
  linear: scaleLinear,
@@ -36,6 +45,10 @@ const SCALE_FUNCS = {
36
45
  };
37
46
  export type SCALE_TYPE = keyof typeof SCALE_FUNCS;
38
47
 
48
+ function identity<T>(v: T): T {
49
+ return v;
50
+ }
51
+
39
52
  const UNKNOWN_COLOR = '#868d91';
40
53
 
41
54
  export const AGGREGATION = {
@@ -88,6 +101,13 @@ const sharedPropMap = {
88
101
  }
89
102
  };
90
103
 
104
+ const customMarkersPropsMap = {
105
+ color: 'getIconColor',
106
+ visConfig: {
107
+ radius: 'getIconSize'
108
+ }
109
+ };
110
+
91
111
  const aggregationVisConfig = {
92
112
  colorAggregation: x => ({colorAggregation: AGGREGATION[x] || AGGREGATION.sum}),
93
113
  colorRange: x => ({colorRange: x.colors.map(hexToRGBA)}),
@@ -110,11 +130,16 @@ function mergePropMaps(a: Record<string, any> = {}, b: Record<string, any> = {})
110
130
 
111
131
  export function getLayer(
112
132
  type: string,
113
- config,
114
- dataset
133
+ config: MapTextSubLayerConfig,
134
+ dataset: MapDataset
115
135
  ): {Layer: ConstructorOf<Layer>; propMap: any; defaultProps: any} {
136
+ let basePropMap: any = sharedPropMap;
137
+
138
+ if (config.visConfig?.customMarkers && !config.textLabel) {
139
+ basePropMap = mergePropMaps(sharedPropMap, customMarkersPropsMap);
140
+ }
116
141
  if (type === 'mvt' || type === 'tileset' || type === 'h3' || type === 'quadbin') {
117
- return getTileLayer(dataset);
142
+ return getTileLayer(dataset, basePropMap);
118
143
  }
119
144
 
120
145
  const geoColumn = dataset?.geoColumn;
@@ -160,7 +185,7 @@ export function getLayer(
160
185
  assert(layer, `Unsupported layer type: ${type}`);
161
186
  return {
162
187
  ...layer,
163
- propMap: mergePropMaps(sharedPropMap, layer.propMap),
188
+ propMap: mergePropMaps(basePropMap, layer.propMap),
164
189
  defaultProps: {...defaultProps, ...layer.defaultProps}
165
190
  };
166
191
  }
@@ -183,7 +208,7 @@ export function layerFromTileDataset(
183
208
  return CartoTileLayer;
184
209
  }
185
210
 
186
- function getTileLayer(dataset) {
211
+ function getTileLayer(dataset: MapDataset, basePropMap) {
187
212
  const {
188
213
  aggregationExp,
189
214
  aggregationResLevel,
@@ -197,7 +222,7 @@ function getTileLayer(dataset) {
197
222
 
198
223
  return {
199
224
  Layer: layerFromTileDataset(formatTiles, scheme),
200
- propMap: sharedPropMap,
225
+ propMap: basePropMap,
201
226
  defaultProps: {
202
227
  ...defaultProps,
203
228
  ...(aggregationExp && {aggregationExp}),
@@ -225,7 +250,7 @@ function domainFromAttribute(attribute, scaleType: SCALE_TYPE, scaleLength: numb
225
250
  }
226
251
 
227
252
  function domainFromValues(values, scaleType: SCALE_TYPE) {
228
- if (scaleType === 'ordinal') {
253
+ if (scaleType === 'ordinal' || scaleType === 'point') {
229
254
  return groupSort(
230
255
  values,
231
256
  g => -g.length,
@@ -268,7 +293,7 @@ function normalizeAccessor(accessor, data) {
268
293
  return accessor;
269
294
  }
270
295
 
271
- export function opacityToAlpha(opacity) {
296
+ export function opacityToAlpha(opacity?: number) {
272
297
  return opacity !== undefined ? Math.round(255 * Math.pow(opacity, 1 / 2.2)) : 255;
273
298
  }
274
299
 
@@ -339,16 +364,70 @@ export function getColorAccessor(
339
364
  return normalizeAccessor(accessor, data);
340
365
  }
341
366
 
367
+ const FALLBACK_ICON =
368
+ 'data:image/svg+xml;charset=utf-8;base64,PHN2ZyB2aWV3Qm94PSIwIDAgMTAwIDEwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4NCiAgPGNpcmNsZSBjeD0iNTAiIGN5PSI1MCIgcj0iNTAiLz4NCjwvc3ZnPg==';
369
+
370
+ export function getIconUrlAccessor(
371
+ field: VisualChannelField | null | undefined,
372
+ range: CustomMarkersRange | null | undefined,
373
+ {fallbackUrl, maxIconSize, useMaskedIcons},
374
+ data: any
375
+ ) {
376
+ const urlToUnpackedIcon = (url: string) => ({
377
+ id: `${url}@@${maxIconSize}`,
378
+ url,
379
+ width: maxIconSize,
380
+ height: maxIconSize,
381
+ mask: useMaskedIcons
382
+ });
383
+ let unknownValue = fallbackUrl || FALLBACK_ICON;
384
+
385
+ if (range?.othersMarker) {
386
+ unknownValue = range.othersMarker;
387
+ }
388
+
389
+ const unknownIcon = urlToUnpackedIcon(unknownValue);
390
+ if (!range || !field) {
391
+ return () => unknownIcon;
392
+ }
393
+
394
+ const mapping: Record<string, any> = {};
395
+ for (const {value, markerUrl} of range.markerMap) {
396
+ if (markerUrl) {
397
+ mapping[value] = urlToUnpackedIcon(markerUrl);
398
+ }
399
+ }
400
+
401
+ const accessor = properties => {
402
+ const propertyValue = properties[field.name];
403
+ return mapping[propertyValue] || unknownIcon;
404
+ };
405
+ return normalizeAccessor(accessor, data);
406
+ }
407
+
408
+ export function getMaxMarkerSize(visConfig: VisConfig, visualChannels: VisualChannels): number {
409
+ const {radiusRange, radius} = visConfig;
410
+ const {radiusField, sizeField} = visualChannels;
411
+ const field = radiusField || sizeField;
412
+ return Math.ceil(radiusRange && field ? radiusRange[1] : radius);
413
+ }
414
+
415
+ export function negateAccessor<T>(accessor: Accessor<T, number>): Accessor<T, number> {
416
+ return typeof accessor === 'function' ? (d, i) => -accessor(d, i) : -accessor;
417
+ }
418
+
342
419
  export function getSizeAccessor(
343
420
  {name},
344
- scaleType: SCALE_TYPE,
421
+ scaleType: SCALE_TYPE | undefined,
345
422
  aggregation,
346
- range: Iterable<Range>,
423
+ range: Iterable<Range> | undefined,
347
424
  data: any
348
425
  ) {
349
- const scale = SCALE_FUNCS[scaleType as any]();
350
- scale.domain(calculateDomain(data, name, scaleType));
351
- scale.range(range);
426
+ const scale = scaleType ? SCALE_FUNCS[scaleType as any]() : identity;
427
+ if (scaleType) {
428
+ scale.domain(calculateDomain(data, name, scaleType));
429
+ scale.range(range);
430
+ }
352
431
 
353
432
  let accessorKeys = getAccessorKeys(name, aggregation);
354
433
  const accessor = properties => {
@@ -369,7 +448,7 @@ const FORMATS: Record<string, (value: any) => string> = {
369
448
  default: String
370
449
  };
371
450
 
372
- export function getTextAccessor({name, type}, data) {
451
+ export function getTextAccessor({name, type}: VisualChannelField, data) {
373
452
  const format = FORMATS[type] || FORMATS.default;
374
453
  const accessor = properties => {
375
454
  return format(properties[name]);
@@ -377,13 +456,19 @@ export function getTextAccessor({name, type}, data) {
377
456
  return normalizeAccessor(accessor, data);
378
457
  }
379
458
 
380
- export function getTextPixelOffsetAccessor({alignment, anchor, size}, radius) {
459
+ export function getTextPixelOffsetAccessor(
460
+ {alignment, anchor, size}: TextLabel,
461
+ radius
462
+ ): Accessor<unknown, [number, number]> {
381
463
  const padding = 20;
382
464
  const signX = anchor === 'middle' ? 0 : anchor === 'start' ? 1 : -1;
383
465
  const signY = alignment === 'center' ? 0 : alignment === 'bottom' ? 1 : -1;
384
466
  const sizeOffset = alignment === 'center' ? 0 : size;
385
467
 
386
- const calculateOffset = r => [signX * (r + padding), signY * (r + padding + sizeOffset)];
468
+ const calculateOffset = (r: number): [number, number] => [
469
+ signX * (r + padding),
470
+ signY * (r + padding + sizeOffset)
471
+ ];
387
472
 
388
473
  return typeof radius === 'function'
389
474
  ? d => {
@@ -28,6 +28,7 @@ import {assert} from '../utils';
28
28
 
29
29
  const MAX_GET_LENGTH = 2048;
30
30
  const DEFAULT_CLIENT = 'deck-gl-carto';
31
+ const V3_MINOR_VERSION = '3.1';
31
32
 
32
33
  export type Headers = Record<string, string>;
33
34
  interface RequestParams {
@@ -151,6 +152,7 @@ function getParameters({
151
152
  queryParameters
152
153
  }: Omit<FetchLayerDataParams, 'connection' | 'credentials'>) {
153
154
  const parameters = [encodeParameter('client', clientId || DEFAULT_CLIENT)];
155
+ parameters.push(encodeParameter('v', V3_MINOR_VERSION));
154
156
 
155
157
  const sourceName = type === MAP_TYPES.QUERY ? 'q' : 'name';
156
158
  parameters.push(encodeParameter(sourceName, source));
@@ -405,8 +407,7 @@ async function _fetchMapDataset(
405
407
  accessToken: string,
406
408
  credentials: CloudNativeCredentials,
407
409
  clientId?: string,
408
- headers?: Headers,
409
- queryParameters?: QueryParameters
410
+ headers?: Headers
410
411
  ) {
411
412
  const {
412
413
  aggregationExp,
@@ -416,7 +417,8 @@ async function _fetchMapDataset(
416
417
  format,
417
418
  geoColumn,
418
419
  source,
419
- type
420
+ type,
421
+ queryParameters
420
422
  } = dataset;
421
423
  // First fetch metadata
422
424
  const {url, mapFormat} = await _fetchDataUrl({
@@ -8,13 +8,17 @@ import {
8
8
  getTextAccessor,
9
9
  getTextPixelOffsetAccessor,
10
10
  OPACITY_MAP,
11
- opacityToAlpha
11
+ opacityToAlpha,
12
+ getIconUrlAccessor,
13
+ negateAccessor,
14
+ getMaxMarkerSize
12
15
  } from './layer-map';
13
16
  import {_flatten as flatten, log} from '@deck.gl/core';
14
17
  import {assert} from '../utils';
18
+ import {MapDataset, MapTextSubLayerConfig, VisualChannels} from './types';
15
19
 
16
20
  export function parseMap(json) {
17
- const {keplerMapConfig, datasets} = json;
21
+ const {keplerMapConfig, datasets, token} = json;
18
22
  assert(keplerMapConfig.version === 'v1', 'Only support Kepler v1');
19
23
  const {mapState, mapStyle} = keplerMapConfig.config;
20
24
  const {layers, layerBlending, interactionConfig} = keplerMapConfig.config.visState;
@@ -27,10 +31,11 @@ export function parseMap(json) {
27
31
  updatedAt: json.updatedAt,
28
32
  initialViewState: mapState,
29
33
  mapStyle,
34
+ token,
30
35
  layers: extractTextLayers(layers.reverse()).map(({id, type, config, visualChannels}) => {
31
36
  try {
32
37
  const {dataId} = config;
33
- const dataset = datasets.find(d => d.id === dataId);
38
+ const dataset: MapDataset | null = datasets.find(d => d.id === dataId);
34
39
  assert(dataset, `No dataset matching dataId: ${dataId}`);
35
40
  const {data} = dataset;
36
41
  assert(data, `No data loaded for dataId: ${dataId}`);
@@ -42,7 +47,8 @@ export function parseMap(json) {
42
47
  ...createBlendingProps(layerBlending),
43
48
  ...(!config.textLabel && createInteractionProps(interactionConfig)),
44
49
  ...createStyleProps(config, propMap),
45
- ...createChannelProps(visualChannels, type, config, data) // Must come after style
50
+ ...createChannelProps(visualChannels, type, config, data), // Must come after style
51
+ ...createLoadOptions(token)
46
52
  });
47
53
  } catch (e: any) {
48
54
  log.error(e.message)();
@@ -128,7 +134,7 @@ function mapProps(source, target, mapping) {
128
134
  }
129
135
  }
130
136
 
131
- function createStyleProps(config, mapping) {
137
+ function createStyleProps(config: MapTextSubLayerConfig, mapping) {
132
138
  const result: Record<string, any> = {};
133
139
  mapProps(config, result, mapping);
134
140
 
@@ -153,9 +159,22 @@ function createStyleProps(config, mapping) {
153
159
  }
154
160
 
155
161
  /* eslint-disable complexity, max-statements */
156
- function createChannelProps(visualChannels, type, config, data) {
157
- const {colorField, colorScale, sizeField, sizeScale, strokeColorField, strokeColorScale} =
158
- visualChannels;
162
+ function createChannelProps(
163
+ visualChannels: VisualChannels,
164
+ type: string,
165
+ config: MapTextSubLayerConfig,
166
+ data
167
+ ) {
168
+ const {
169
+ colorField,
170
+ colorScale,
171
+ radiusField,
172
+ radiusScale,
173
+ sizeField,
174
+ sizeScale,
175
+ strokeColorField,
176
+ strokeColorScale
177
+ } = visualChannels;
159
178
  let {heightField, heightScale} = visualChannels;
160
179
  if (type === 'hexagonId') {
161
180
  heightField = sizeField;
@@ -179,6 +198,7 @@ function createChannelProps(visualChannels, type, config, data) {
179
198
  const {colorAggregation: aggregation, colorRange: range} = visConfig;
180
199
  result.getFillColor = getColorAccessor(
181
200
  colorField,
201
+ // @ts-ignore
182
202
  colorScale,
183
203
  {aggregation, range},
184
204
  visConfig.opacity,
@@ -186,6 +206,18 @@ function createChannelProps(visualChannels, type, config, data) {
186
206
  );
187
207
  }
188
208
 
209
+ if (radiusField || sizeField) {
210
+ result.getPointRadius = getSizeAccessor(
211
+ // @ts-ignore
212
+ radiusField || sizeField,
213
+ // @ts-ignore
214
+ radiusScale || sizeScale,
215
+ visConfig.sizeAggregation,
216
+ visConfig.radiusRange || visConfig.sizeRange,
217
+ data
218
+ );
219
+ }
220
+
189
221
  if (strokeColorField) {
190
222
  const fallbackOpacity = type === 'point' ? visConfig.opacity : 1;
191
223
  const opacity =
@@ -193,36 +225,78 @@ function createChannelProps(visualChannels, type, config, data) {
193
225
  const {strokeColorAggregation: aggregation, strokeColorRange: range} = visConfig;
194
226
  result.getLineColor = getColorAccessor(
195
227
  strokeColorField,
228
+ // @ts-ignore
196
229
  strokeColorScale,
230
+ // @ts-ignore
197
231
  {aggregation, range},
198
232
  opacity,
199
233
  data
200
234
  );
201
235
  }
236
+
202
237
  if (heightField) {
203
238
  result.getElevation = getSizeAccessor(
204
239
  heightField,
240
+ // @ts-ignore
205
241
  heightScale,
206
242
  visConfig.heightAggregation,
207
243
  visConfig.heightRange || visConfig.sizeRange,
208
244
  data
209
245
  );
210
246
  }
211
- if (sizeField) {
212
- result.getPointRadius = getSizeAccessor(
213
- sizeField,
214
- sizeScale,
215
- visConfig.sizeAggregation,
216
- visConfig.radiusRange || visConfig.sizeRange,
217
- data
218
- );
219
- }
247
+
220
248
  if (textLabelField) {
221
249
  result.getText = getTextAccessor(textLabelField, data);
222
250
  result.pointType = 'text';
223
251
  const radius = result.getPointRadius || visConfig.radius;
224
252
  result.getTextPixelOffset = getTextPixelOffsetAccessor(textLabel, radius);
253
+ } else if (visConfig.customMarkers) {
254
+ const maxIconSize = getMaxMarkerSize(visConfig, visualChannels);
255
+ const {getPointRadius, getFillColor} = result;
256
+ const {customMarkersUrl, customMarkersRange, filled: useMaskedIcons} = visConfig;
257
+
258
+ result.pointType = 'icon';
259
+ result.getIcon = getIconUrlAccessor(
260
+ visualChannels.customMarkersField,
261
+ customMarkersRange,
262
+ {fallbackUrl: customMarkersUrl, maxIconSize, useMaskedIcons},
263
+ data
264
+ );
265
+ result._subLayerProps = {
266
+ 'points-icon': {
267
+ loadOptions: {
268
+ image: {
269
+ type: 'imagebitmap'
270
+ },
271
+ imagebitmap: {
272
+ resizeWidth: maxIconSize,
273
+ resizeHeight: maxIconSize,
274
+ resizeQuality: 'high'
275
+ }
276
+ }
277
+ }
278
+ };
279
+
280
+ if (getFillColor && useMaskedIcons) {
281
+ result.getIconColor = getFillColor;
282
+ }
283
+
284
+ if (getPointRadius) {
285
+ result.getIconSize = getPointRadius;
286
+ }
287
+
288
+ if (visualChannels.rotationField) {
289
+ result.getIconAngle = negateAccessor(
290
+ getSizeAccessor(visualChannels.rotationField, undefined, null, undefined, data)
291
+ );
292
+ }
225
293
  }
226
294
 
227
295
  return result;
228
296
  }
297
+
298
+ function createLoadOptions(accessToken: string) {
299
+ return {
300
+ loadOptions: {fetch: {headers: {Authorization: `Bearer ${accessToken}`}}}
301
+ };
302
+ }
@@ -0,0 +1,108 @@
1
+ import {SCALE_TYPE} from './layer-map';
2
+
3
+ export type VisualChannelField = {
4
+ name: string;
5
+ type: string;
6
+ };
7
+
8
+ export type VisualChannels = {
9
+ colorField?: VisualChannelField;
10
+ colorScale?: SCALE_TYPE;
11
+
12
+ customMarkersField?: VisualChannelField;
13
+ customMarkersScale?: SCALE_TYPE;
14
+
15
+ radiusField?: VisualChannelField;
16
+ radiusScale?: SCALE_TYPE;
17
+
18
+ rotationScale?: SCALE_TYPE;
19
+ rotationField?: VisualChannelField;
20
+
21
+ sizeField?: VisualChannelField;
22
+ sizeScale?: SCALE_TYPE;
23
+
24
+ strokeColorField?: VisualChannelField;
25
+ strokeColorScale?: SCALE_TYPE;
26
+
27
+ heightField?: VisualChannelField;
28
+ heightScale?: SCALE_TYPE;
29
+ };
30
+
31
+ export type ColorRange = {
32
+ category: string;
33
+ colors: string[];
34
+ colorMap: string[][] | undefined;
35
+ name: string;
36
+ type: string;
37
+ };
38
+
39
+ export type CustomMarkersRange = {
40
+ markerMap: {
41
+ value: string;
42
+ markerUrl?: string;
43
+ }[];
44
+ othersMarker?: string;
45
+ };
46
+
47
+ export type VisConfig = {
48
+ filled?: boolean;
49
+ opacity?: number;
50
+ enable3d?: boolean;
51
+
52
+ colorAggregation?: any;
53
+ colorRange: ColorRange;
54
+
55
+ customMarkers?: boolean;
56
+ customMarkersRange?: CustomMarkersRange | null;
57
+ customMarkersUrl?: string | null;
58
+
59
+ radius: number;
60
+ radiusRange?: number[];
61
+
62
+ sizeAggregation?: any;
63
+ sizeRange?: any;
64
+
65
+ strokeColorAggregation?: any;
66
+ strokeOpacity?: number;
67
+ strokeColorRange?: ColorRange;
68
+
69
+ heightRange?: any;
70
+ heightAggregation?: any;
71
+ };
72
+
73
+ export type TextLabel = {
74
+ field: VisualChannelField | null | undefined;
75
+ alignment?: 'center' | 'bottom' | 'top';
76
+ anchor?: 'middle' | 'start' | 'end';
77
+ size: number;
78
+ color?: number[];
79
+ offset?: [number, number];
80
+ };
81
+
82
+ export type MapLayerConfig = {
83
+ columns?: Record<string, any>;
84
+ color?: number[];
85
+ label?: string;
86
+ dataId: string;
87
+ textLabel: TextLabel[];
88
+ visConfig: VisConfig;
89
+ };
90
+
91
+ export type MapTextSubLayerConfig = Omit<MapLayerConfig, 'textLabel'> & {
92
+ textLabel?: TextLabel;
93
+ };
94
+
95
+ export type MapConfigLayer = {
96
+ type: string;
97
+ id: string;
98
+ config: MapLayerConfig;
99
+ visualChannels: VisualChannels;
100
+ };
101
+
102
+ export type MapDataset = {
103
+ id: string;
104
+ data: any;
105
+ aggregationExp: string | null;
106
+ aggregationResLevel: number | null;
107
+ geoColumn: string;
108
+ };
package/src/index.ts CHANGED
@@ -3,11 +3,6 @@ export {default as CartoLayer} from './layers/carto-layer';
3
3
  export {default as _CartoTileLayer} from './layers/carto-tile-layer';
4
4
  export {default as _H3TileLayer} from './layers/h3-tile-layer';
5
5
  export {default as _QuadbinTileLayer} from './layers/quadbin-tile-layer';
6
- export {
7
- tileToQuadbin as _tileToQuadbin,
8
- quadbinToTile as _quadbinToTile,
9
- quadbinZoom as _quadbinZoom
10
- } from './layers/quadbin-utils';
11
6
  export {default as BASEMAP} from './basemap';
12
7
  export {default as colorBins} from './style/color-bins-style';
13
8
  export {default as colorCategories} from './style/color-categories-style';
@@ -305,11 +305,17 @@ export default class CartoLayer<ExtraProps = {}> extends CompositeLayer<
305
305
  renderLayers(): Layer | null {
306
306
  assert(this.state);
307
307
 
308
- const {data} = this.state;
308
+ const {apiVersion, data} = this.state;
309
309
 
310
310
  if (!data) return null;
311
311
 
312
- const {updateTriggers} = this.props;
312
+ const {credentials, updateTriggers} = this.props;
313
+ const loadOptions: any = {};
314
+ if (apiVersion === API_VERSIONS.V3) {
315
+ const localConfig = {...getDefaultCredentials(), ...credentials} as CloudNativeCredentials;
316
+ const {accessToken} = localConfig;
317
+ loadOptions.fetch = {headers: {Authorization: `Bearer ${accessToken}`}};
318
+ }
313
319
 
314
320
  const [layer, props] = this._getSubLayerAndProps();
315
321
 
@@ -319,6 +325,7 @@ export default class CartoLayer<ExtraProps = {}> extends CompositeLayer<
319
325
  this.getSubLayerProps({
320
326
  id: `carto-${layer.layerName}`,
321
327
  data,
328
+ loadOptions,
322
329
  updateTriggers
323
330
  })
324
331
  );