@deck.gl/carto 8.9.7 → 8.9.8

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 (150) hide show
  1. package/dist/dist.dev.js +774 -114
  2. package/dist/es5/api/layer-map.js +9 -15
  3. package/dist/es5/api/layer-map.js.map +1 -1
  4. package/dist/es5/api/maps-api-common.js +2 -1
  5. package/dist/es5/api/maps-api-common.js.map +1 -1
  6. package/dist/es5/api/maps-v3-client.js +17 -6
  7. package/dist/es5/api/maps-v3-client.js.map +1 -1
  8. package/dist/es5/api/parseMap.js +1 -1
  9. package/dist/es5/api/parseMap.js.map +1 -1
  10. package/dist/es5/index.js +8 -0
  11. package/dist/es5/index.js.map +1 -1
  12. package/dist/es5/layers/carto-layer.js +1 -1
  13. package/dist/es5/layers/carto-layer.js.map +1 -1
  14. package/dist/es5/layers/h3-tile-layer.js +2 -1
  15. package/dist/es5/layers/h3-tile-layer.js.map +1 -1
  16. package/dist/es5/layers/quadbin-tile-layer.js +2 -1
  17. package/dist/es5/layers/quadbin-tile-layer.js.map +1 -1
  18. package/dist/es5/layers/quadbin-utils.js +14 -4
  19. package/dist/es5/layers/quadbin-utils.js.map +1 -1
  20. package/dist/es5/layers/raster-layer-vertex.glsl.js +9 -0
  21. package/dist/es5/layers/raster-layer-vertex.glsl.js.map +1 -0
  22. package/dist/es5/layers/raster-layer.js +176 -0
  23. package/dist/es5/layers/raster-layer.js.map +1 -0
  24. package/dist/es5/layers/raster-tile-layer.js +114 -0
  25. package/dist/es5/layers/raster-tile-layer.js.map +1 -0
  26. package/dist/es5/layers/schema/carto-raster-tile-loader.js +80 -0
  27. package/dist/es5/layers/schema/carto-raster-tile-loader.js.map +1 -0
  28. package/dist/es5/layers/schema/carto-raster-tile.js +87 -0
  29. package/dist/es5/layers/schema/carto-raster-tile.js.map +1 -0
  30. package/dist/es5/layers/schema/carto-spatial-tile.js +1 -1
  31. package/dist/es5/layers/schema/carto-spatial-tile.js.map +1 -1
  32. package/dist/es5/layers/schema/carto-tile.js +2 -2
  33. package/dist/es5/layers/schema/carto-tile.js.map +1 -1
  34. package/dist/es5/layers/schema/fast-pbf.js +3 -11
  35. package/dist/es5/layers/schema/fast-pbf.js.map +1 -1
  36. package/dist/es5/layers/spatial-index-tile-layer.js +3 -41
  37. package/dist/es5/layers/spatial-index-tile-layer.js.map +1 -1
  38. package/dist/es5/utils.js +18 -0
  39. package/dist/es5/utils.js.map +1 -1
  40. package/dist/esm/api/layer-map.js +9 -21
  41. package/dist/esm/api/layer-map.js.map +1 -1
  42. package/dist/esm/api/maps-api-common.js +2 -1
  43. package/dist/esm/api/maps-api-common.js.map +1 -1
  44. package/dist/esm/api/maps-v3-client.js +9 -1
  45. package/dist/esm/api/maps-v3-client.js.map +1 -1
  46. package/dist/esm/api/parseMap.js +1 -1
  47. package/dist/esm/api/parseMap.js.map +1 -1
  48. package/dist/esm/index.js +1 -0
  49. package/dist/esm/index.js.map +1 -1
  50. package/dist/esm/layers/carto-layer.js +1 -1
  51. package/dist/esm/layers/carto-layer.js.map +1 -1
  52. package/dist/esm/layers/h3-tile-layer.js +2 -1
  53. package/dist/esm/layers/h3-tile-layer.js.map +1 -1
  54. package/dist/esm/layers/quadbin-tile-layer.js +2 -1
  55. package/dist/esm/layers/quadbin-tile-layer.js.map +1 -1
  56. package/dist/esm/layers/quadbin-utils.js +7 -4
  57. package/dist/esm/layers/quadbin-utils.js.map +1 -1
  58. package/dist/esm/layers/raster-layer-vertex.glsl.js +2 -0
  59. package/dist/esm/layers/raster-layer-vertex.glsl.js.map +1 -0
  60. package/dist/esm/layers/raster-layer.js +111 -0
  61. package/dist/esm/layers/raster-layer.js.map +1 -0
  62. package/dist/esm/layers/raster-tile-layer.js +67 -0
  63. package/dist/esm/layers/raster-tile-layer.js.map +1 -0
  64. package/dist/esm/layers/schema/carto-raster-tile-loader.js +46 -0
  65. package/dist/esm/layers/schema/carto-raster-tile-loader.js.map +1 -0
  66. package/dist/esm/layers/schema/carto-raster-tile.js +51 -0
  67. package/dist/esm/layers/schema/carto-raster-tile.js.map +1 -0
  68. package/dist/esm/layers/schema/carto-spatial-tile.js +2 -2
  69. package/dist/esm/layers/schema/carto-spatial-tile.js.map +1 -1
  70. package/dist/esm/layers/schema/carto-tile.js +3 -3
  71. package/dist/esm/layers/schema/carto-tile.js.map +1 -1
  72. package/dist/esm/layers/schema/fast-pbf.js +2 -8
  73. package/dist/esm/layers/schema/fast-pbf.js.map +1 -1
  74. package/dist/esm/layers/spatial-index-tile-layer.js +3 -41
  75. package/dist/esm/layers/spatial-index-tile-layer.js.map +1 -1
  76. package/dist/esm/utils.js +20 -0
  77. package/dist/esm/utils.js.map +1 -1
  78. package/dist.min.js +100 -23
  79. package/package.json +3 -3
  80. package/src/api/layer-map.ts +12 -19
  81. package/src/api/maps-api-common.ts +2 -1
  82. package/src/api/maps-v3-client.ts +6 -1
  83. package/src/api/parseMap.ts +1 -1
  84. package/src/index.ts +1 -0
  85. package/src/layers/carto-layer.ts +1 -1
  86. package/src/layers/h3-tile-layer.ts +2 -3
  87. package/src/layers/quadbin-tile-layer.ts +2 -3
  88. package/src/layers/quadbin-utils.ts +9 -5
  89. package/src/layers/raster-layer-vertex.glsl.ts +98 -0
  90. package/src/layers/raster-layer.ts +146 -0
  91. package/src/layers/raster-tile-layer.ts +63 -0
  92. package/src/layers/schema/carto-raster-tile-loader.ts +42 -0
  93. package/src/layers/schema/carto-raster-tile.ts +46 -0
  94. package/src/layers/schema/carto-spatial-tile.ts +2 -2
  95. package/src/layers/schema/carto-tile.ts +3 -3
  96. package/src/layers/schema/fast-pbf.ts +3 -9
  97. package/src/layers/spatial-index-tile-layer.ts +3 -38
  98. package/src/utils.ts +22 -0
  99. package/typed/api/layer-map.d.ts +2 -1
  100. package/typed/api/layer-map.d.ts.map +1 -1
  101. package/typed/api/maps-api-common.d.ts +1 -0
  102. package/typed/api/maps-api-common.d.ts.map +1 -1
  103. package/typed/api/maps-v3-client.d.ts.map +1 -1
  104. package/typed/index.d.ts +1 -0
  105. package/typed/index.d.ts.map +1 -1
  106. package/typed/layers/h3-tile-layer.d.ts.map +1 -1
  107. package/typed/layers/quadbin-tile-layer.d.ts.map +1 -1
  108. package/typed/layers/quadbin-utils.d.ts +1 -0
  109. package/typed/layers/quadbin-utils.d.ts.map +1 -1
  110. package/typed/layers/raster-layer-vertex.glsl.d.ts +3 -0
  111. package/typed/layers/raster-layer-vertex.glsl.d.ts.map +1 -0
  112. package/typed/layers/raster-layer.d.ts +19 -0
  113. package/typed/layers/raster-layer.d.ts.map +1 -0
  114. package/typed/layers/raster-tile-layer.d.ts +24 -0
  115. package/typed/layers/raster-tile-layer.d.ts.map +1 -0
  116. package/typed/layers/schema/carto-raster-tile-loader.d.ts +13 -0
  117. package/typed/layers/schema/carto-raster-tile-loader.d.ts.map +1 -0
  118. package/typed/layers/schema/carto-raster-tile.d.ts +9 -0
  119. package/typed/layers/schema/carto-raster-tile.d.ts.map +1 -0
  120. package/typed/layers/schema/carto-spa-tile.d.ts +57 -0
  121. package/typed/layers/schema/carto-spa-tile.d.ts.map +1 -0
  122. package/typed/layers/schema/fast-pbf.d.ts +1 -2
  123. package/typed/layers/schema/fast-pbf.d.ts.map +1 -1
  124. package/typed/layers/spatial-index-tile-layer.d.ts +1 -2
  125. package/typed/layers/spatial-index-tile-layer.d.ts.map +1 -1
  126. package/typed/utils.d.ts +5 -0
  127. package/typed/utils.d.ts.map +1 -1
  128. package/typed/api/index.js +0 -3
  129. package/typed/api/layer-map.js +0 -264
  130. package/typed/api/maps-api-common.js +0 -50
  131. package/typed/api/maps-client.js +0 -125
  132. package/typed/api/maps-v3-client.js +0 -304
  133. package/typed/api/parseMap.js +0 -178
  134. package/typed/basemap.js +0 -9
  135. package/typed/config.js +0 -35
  136. package/typed/index.js +0 -10
  137. package/typed/layers/carto-layer.js +0 -173
  138. package/typed/layers/carto-tile-layer.js +0 -105
  139. package/typed/layers/h3-tile-layer.js +0 -47
  140. package/typed/layers/h3-tileset-2d.js +0 -85
  141. package/typed/layers/quadkey-tile-layer.js +0 -42
  142. package/typed/layers/quadkey-tileset-2d.js +0 -36
  143. package/typed/layers/schema/carto-tile.js +0 -161
  144. package/typed/layers/spatial-index-tile-layer.js +0 -40
  145. package/typed/style/color-bins-style.js +0 -12
  146. package/typed/style/color-categories-style.js +0 -16
  147. package/typed/style/color-continuous-style.js +0 -12
  148. package/typed/style/palette.js +0 -62
  149. package/typed/style/utils.js +0 -15
  150. 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.7",
5
+ "version": "8.9.8",
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },
@@ -46,7 +46,7 @@
46
46
  "h3-js": "^3.7.0",
47
47
  "moment-timezone": "^0.5.33",
48
48
  "pbf": "^3.2.1",
49
- "quadbin": "^0.1.2"
49
+ "quadbin": "^0.1.9"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@loaders.gl/schema": "^3.3.1",
@@ -62,5 +62,5 @@
62
62
  "@deck.gl/layers": "^8.0.0",
63
63
  "@loaders.gl/core": "^3.0.0"
64
64
  },
65
- "gitHead": "63e09fa6f5dbfc9111fb8b343444e8c3a7a0702b"
65
+ "gitHead": "2d98c0893324e1f01c4b5afacc0de800510c15cb"
66
66
  }
@@ -21,8 +21,9 @@ import {H3HexagonLayer, MVTLayer} from '@deck.gl/geo-layers';
21
21
  import CartoTileLayer from '../layers/carto-tile-layer';
22
22
  import H3TileLayer from '../layers/h3-tile-layer';
23
23
  import QuadbinTileLayer from '../layers/quadbin-tile-layer';
24
- import {TILE_FORMATS} from './maps-api-common';
25
- import {assert} from '../utils';
24
+ import RasterTileLayer from '../layers/raster-tile-layer';
25
+ import {MapType, TILE_FORMATS, TileFormat} from './maps-api-common';
26
+ import {assert, createBinaryProxy} from '../utils';
26
27
  import {
27
28
  CustomMarkersRange,
28
29
  MapDataset,
@@ -200,16 +201,20 @@ export function getLayer(
200
201
  }
201
202
 
202
203
  export function layerFromTileDataset(
203
- formatTiles: string | null = TILE_FORMATS.MVT,
204
- scheme: string
204
+ formatTiles: TileFormat | null = TILE_FORMATS.MVT,
205
+ scheme: string,
206
+ type?: MapType
205
207
  ): typeof CartoTileLayer | typeof H3TileLayer | typeof MVTLayer | typeof QuadbinTileLayer {
208
+ if (type === 'raster') {
209
+ return RasterTileLayer;
210
+ }
206
211
  if (scheme === 'h3') {
207
212
  return H3TileLayer;
208
213
  }
209
214
  if (scheme === 'quadbin') {
210
215
  return QuadbinTileLayer;
211
216
  }
212
- if (formatTiles === TILE_FORMATS.MVT) {
217
+ if (formatTiles === 'mvt') {
213
218
  return MVTLayer;
214
219
  }
215
220
 
@@ -227,7 +232,7 @@ function getTileLayer(dataset: MapDataset, basePropMap) {
227
232
  }
228
233
  } = dataset;
229
234
  /* global URL */
230
- const formatTiles = new URL(tileUrl).searchParams.get('formatTiles');
235
+ const formatTiles = new URL(tileUrl).searchParams.get('formatTiles') as TileFormat;
231
236
 
232
237
  return {
233
238
  Layer: layerFromTileDataset(formatTiles, scheme),
@@ -301,19 +306,7 @@ function normalizeAccessor(accessor, data) {
301
306
  }
302
307
 
303
308
  const {data, index} = info;
304
- const {properties, numericProps} = data;
305
- const proxy = new Proxy(properties[index] || {}, {
306
- get(target, property, receiver) {
307
- if (property in numericProps) {
308
- return numericProps[property as string].value[index];
309
- }
310
- return target[property as string];
311
- },
312
-
313
- has(target, property) {
314
- return property in numericProps || property in target;
315
- }
316
- });
309
+ const proxy = createBinaryProxy(data, index);
317
310
  return accessor(proxy);
318
311
  };
319
312
  }
@@ -17,7 +17,8 @@ export const DEFAULT_MAPS_URL_FORMAT = {
17
17
  export const MAP_TYPES = {
18
18
  QUERY: 'query',
19
19
  TABLE: 'table',
20
- TILESET: 'tileset'
20
+ TILESET: 'tileset',
21
+ RASTER: 'raster'
21
22
  } as const;
22
23
  export type MapType = ValuesOf<typeof MAP_TYPES>;
23
24
  export const COLUMNS_SUPPORT: MapType[] = [MAP_TYPES.TABLE];
@@ -89,7 +89,12 @@ async function requestJson<T = unknown>({
89
89
  errorContext
90
90
  }: RequestParams): Promise<T> {
91
91
  const response = await request({method, url, headers, accessToken, body, errorContext});
92
- const json = await response.json();
92
+ let json;
93
+ try {
94
+ json = await response.json();
95
+ } catch (error) {
96
+ json = {error: ''};
97
+ }
93
98
 
94
99
  if (!response.ok) {
95
100
  throw new CartoAPIError(json.error, errorContext, response);
@@ -217,7 +217,7 @@ function createChannelProps(
217
217
  );
218
218
  }
219
219
 
220
- if (heightField) {
220
+ if (heightField && visConfig.enable3d) {
221
221
  result.getElevation = getSizeAccessor(
222
222
  heightField,
223
223
  // @ts-ignore
package/src/index.ts CHANGED
@@ -4,6 +4,7 @@ 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 _PointLabelLayer} from './layers/point-label-layer';
6
6
  export {default as _QuadbinTileLayer} from './layers/quadbin-tile-layer';
7
+ export {default as _RasterTileLayer} from './layers/raster-tile-layer';
7
8
  export {default as BASEMAP} from './basemap';
8
9
  export {default as colorBins} from './style/color-bins-style';
9
10
  export {default as colorCategories} from './style/color-categories-style';
@@ -300,7 +300,7 @@ export default class CartoLayer<ExtraProps extends {} = {}> extends CompositeLay
300
300
  props.formatTiles =
301
301
  props.formatTiles || (tileUrl.searchParams.get('formatTiles') as TileFormat);
302
302
 
303
- return [layerFromTileDataset(props.formatTiles, data.scheme), props];
303
+ return [layerFromTileDataset(props.formatTiles, data.scheme, props.type), props];
304
304
  }
305
305
 
306
306
  renderLayers(): Layer | null {
@@ -98,9 +98,8 @@ export default class H3TileLayer<DataT = any, ExtraPropsT extends {} = {}> exten
98
98
  maxZoom: maxresolution,
99
99
  loadOptions: {
100
100
  ...this.getLoadOptions(),
101
- cartoSpatialTile: {
102
- scheme: 'h3'
103
- }
101
+ cartoSpatialTile: {scheme: 'h3'},
102
+ mimeType: 'application/vnd.carto-spatial-tile'
104
103
  }
105
104
  })
106
105
  ];
@@ -71,9 +71,8 @@ export default class QuadbinTileLayer<
71
71
  maxZoom,
72
72
  loadOptions: {
73
73
  ...this.getLoadOptions(),
74
- cartoSpatialTile: {
75
- scheme: 'quadbin'
76
- }
74
+ cartoSpatialTile: {scheme: 'quadbin'},
75
+ mimeType: 'application/vnd.carto-spatial-tile'
77
76
  }
78
77
  })
79
78
  ];
@@ -3,13 +3,17 @@ import {cellToTile} from 'quadbin';
3
3
 
4
4
  const TILE_SIZE = 512;
5
5
 
6
- export function quadbinToWorldBounds(quadbin: bigint, coverage: number): [number[], number[]] {
6
+ export function quadbinToOffset(quadbin: bigint): [number, number, number] {
7
7
  const {x, y, z} = cellToTile(quadbin);
8
- const mask = 1 << z;
9
- const scale = mask / TILE_SIZE;
8
+ const scale = TILE_SIZE / (1 << z);
9
+ return [x * scale, TILE_SIZE - y * scale, scale];
10
+ }
11
+
12
+ export function quadbinToWorldBounds(quadbin: bigint, coverage: number): [number[], number[]] {
13
+ const [xOffset, yOffset, scale] = quadbinToOffset(quadbin);
10
14
  return [
11
- [x / scale, TILE_SIZE - y / scale],
12
- [(x + coverage) / scale, TILE_SIZE - (y + coverage) / scale]
15
+ [xOffset, yOffset],
16
+ [xOffset + coverage * scale, yOffset - coverage * scale]
13
17
  ];
14
18
  }
15
19
 
@@ -0,0 +1,98 @@
1
+ export default `\
2
+ #version 300 es
3
+ #define SHADER_NAME raster-layer-vertex-shader
4
+
5
+ in vec3 positions;
6
+ in vec3 normals;
7
+
8
+ in float instanceElevations;
9
+ in vec4 instanceFillColors;
10
+ in vec4 instanceLineColors;
11
+
12
+ in vec3 instancePickingColors;
13
+
14
+ // Custom uniforms
15
+ uniform float opacity;
16
+ uniform bool extruded;
17
+ uniform bool stroked;
18
+ uniform bool isStroke;
19
+ uniform float coverage;
20
+ uniform float elevationScale;
21
+ uniform float widthScale;
22
+ uniform vec3 offset;
23
+
24
+ // Result
25
+ out vec4 vColor;
26
+ #ifdef FLAT_SHADING
27
+ out vec4 position_commonspace;
28
+ #endif
29
+
30
+ void main(void) {
31
+ // Rather than positioning using attribute, layout pixel grid using gl_InstanceID
32
+ vec2 common_position = offset.xy;
33
+ float scale = offset.z;
34
+
35
+ int yIndex = - (gl_InstanceID / 256);
36
+ int xIndex = gl_InstanceID + (yIndex * 256);
37
+ common_position += scale * vec2(float(xIndex), float(yIndex));
38
+
39
+ vec4 color = isStroke ? instanceLineColors : instanceFillColors;
40
+
41
+ // if alpha == 0.0 or z < 0.0, do not render element
42
+ float shouldRender = float(color.a > 0.0 && instanceElevations >= 0.0);
43
+ float cellWidth = coverage * scale;
44
+
45
+ // Get position directly from quadbin, rather than projecting
46
+ // Important to set geometry.position before using project_ methods below
47
+ // as geometry.worldPosition is not set (we don't know our lat/long)
48
+ geometry.position = vec4(common_position, 0.0, 1.0);
49
+ if (project_uProjectionMode == PROJECTION_MODE_WEB_MERCATOR_AUTO_OFFSET) {
50
+ geometry.position.xyz -= project_uCommonOrigin;
51
+ }
52
+
53
+ // calculate elevation, if 3d not enabled set to 0
54
+ // cylindar geometry height are between -1.0 to 1.0, transform it to between 0, 1
55
+ float elevation = 0.0;
56
+ // calculate stroke offset
57
+ float strokeOffsetRatio = 1.0;
58
+
59
+ if (extruded) {
60
+ elevation = instanceElevations * (positions.z + 1.0) / 2.0 * elevationScale;
61
+ } else if (stroked) {
62
+ float halfOffset = project_pixel_size(widthScale) / cellWidth;
63
+ if (isStroke) {
64
+ strokeOffsetRatio -= sign(positions.z) * halfOffset;
65
+ } else {
66
+ strokeOffsetRatio -= halfOffset;
67
+ }
68
+ }
69
+
70
+ geometry.pickingColor = instancePickingColors;
71
+
72
+ // project center of column
73
+ vec2 offset = (vec2(0.5) + positions.xy * strokeOffsetRatio) * cellWidth * shouldRender;
74
+ vec3 pos = vec3(offset, project_size(elevation));
75
+ DECKGL_FILTER_SIZE(pos, geometry);
76
+
77
+ geometry.position.xyz += pos;
78
+ gl_Position = project_common_position_to_clipspace(geometry.position);
79
+
80
+ geometry.normal = project_normal(normals);
81
+ DECKGL_FILTER_GL_POSITION(gl_Position, geometry);
82
+
83
+ // Light calculations
84
+ if (extruded && !isStroke) {
85
+ #ifdef FLAT_SHADING
86
+ position_commonspace = geometry.position;
87
+ vColor = vec4(color.rgb, color.a * opacity);
88
+ #else
89
+ vec3 lightColor = lighting_getLightColor(color.rgb, project_uCameraPosition, geometry.position.xyz, geometry.normal);
90
+ vColor = vec4(lightColor, color.a * opacity);
91
+ #endif
92
+ } else {
93
+ vColor = vec4(color.rgb, color.a * opacity);
94
+ }
95
+
96
+ DECKGL_FILTER_COLOR(vColor, geometry);
97
+ }
98
+ `;
@@ -0,0 +1,146 @@
1
+ import GL from '@luma.gl/constants';
2
+ import {
3
+ Accessor,
4
+ CompositeLayer,
5
+ CompositeLayerProps,
6
+ Layer,
7
+ LayersList,
8
+ DefaultProps
9
+ } from '@deck.gl/core';
10
+ import {ColumnLayer, ColumnLayerProps} from '@deck.gl/layers';
11
+ import {quadbinToOffset} from './quadbin-utils';
12
+ import {Raster} from './schema/carto-raster-tile-loader';
13
+ import vs from './raster-layer-vertex.glsl';
14
+ import {assert, createBinaryProxy} from '../utils';
15
+
16
+ const defaultProps: DefaultProps<RasterLayerProps> = {
17
+ ...ColumnLayer.defaultProps,
18
+ extruded: false,
19
+ diskResolution: 4,
20
+ vertices: [
21
+ [-0.5, -0.5],
22
+ [0.5, -0.5],
23
+ [0.5, 0.5],
24
+ [-0.5, 0.5]
25
+ ]
26
+ };
27
+
28
+ // Modified ColumnLayer with custom vertex shader
29
+ class RasterColumnLayer extends ColumnLayer {
30
+ static layerName = 'RasterColumnLayer';
31
+
32
+ getShaders() {
33
+ const shaders = super.getShaders();
34
+ return {...shaders, vs};
35
+ }
36
+
37
+ initializeState() {
38
+ // Only add attributes needed by shader
39
+ const attributeManager = this.getAttributeManager()!;
40
+ /* eslint-disable max-len */
41
+ attributeManager.addInstanced({
42
+ instanceElevations: {
43
+ size: 1,
44
+ transition: true,
45
+ accessor: 'getElevation'
46
+ },
47
+ instanceFillColors: {
48
+ size: this.props.colorFormat.length,
49
+ type: GL.UNSIGNED_BYTE,
50
+ normalized: true,
51
+ transition: true,
52
+ accessor: 'getFillColor',
53
+ defaultValue: [0, 0, 0, 255]
54
+ },
55
+ instanceLineColors: {
56
+ size: this.props.colorFormat.length,
57
+ type: GL.UNSIGNED_BYTE,
58
+ normalized: true,
59
+ transition: true,
60
+ accessor: 'getLineColor',
61
+ defaultValue: [255, 255, 255, 255]
62
+ }
63
+ });
64
+ }
65
+ }
66
+
67
+ /** All properties supported by RasterLayer. */
68
+ export type RasterLayerProps<DataT = any> = _RasterLayerProps &
69
+ ColumnLayerProps<DataT> &
70
+ CompositeLayerProps;
71
+
72
+ /** Properties added by RasterLayer. */
73
+ type _RasterLayerProps = {
74
+ /**
75
+ * Quadbin index of tile
76
+ */
77
+ tileIndex: bigint;
78
+ };
79
+
80
+ // Adapter layer around RasterColumnLayer that converts data & accessors into correct format
81
+ export default class RasterLayer<DataT = any, ExtraProps = {}> extends CompositeLayer<
82
+ Required<RasterLayerProps<DataT>> & ExtraProps
83
+ > {
84
+ static layerName = 'RasterLayer';
85
+ static defaultProps = defaultProps;
86
+
87
+ renderLayers(): Layer | null | LayersList {
88
+ // Rendering props underlying layer
89
+ const {
90
+ data,
91
+ getElevation,
92
+ getFillColor,
93
+ getLineColor,
94
+ getLineWidth,
95
+ tileIndex,
96
+ updateTriggers
97
+ } = this.props;
98
+ if (!data || !tileIndex) return null;
99
+
100
+ const {blockWidth, blockHeight} = data as unknown as Raster;
101
+ assert(
102
+ blockWidth === blockHeight,
103
+ `blockWidth (${blockWidth}) must equal blockHeight (${blockHeight})`
104
+ );
105
+
106
+ const [xOffset, yOffset, scale] = quadbinToOffset(tileIndex);
107
+ const offset = [xOffset, yOffset, scale / blockWidth];
108
+
109
+ // Filled Column Layer
110
+ const CellLayer = this.getSubLayerClass('column', RasterColumnLayer);
111
+ return new CellLayer(
112
+ this.props,
113
+ this.getSubLayerProps({
114
+ id: 'cell',
115
+ updateTriggers,
116
+
117
+ getElevation: this.getSubLayerAccessor(getElevation),
118
+ getFillColor: this.getSubLayerAccessor(getFillColor),
119
+ getLineColor: this.getSubLayerAccessor(getLineColor),
120
+ getLineWidth: this.getSubLayerAccessor(getLineWidth)
121
+ }),
122
+ {
123
+ data: {
124
+ data, // Pass through data for getSubLayerAccessor()
125
+ length: blockWidth * blockHeight
126
+ },
127
+ offset
128
+ }
129
+ );
130
+ }
131
+
132
+ protected getSubLayerAccessor<In, Out>(accessor: Accessor<In, Out>): Accessor<In, Out> {
133
+ if (typeof accessor !== 'function') {
134
+ return super.getSubLayerAccessor(accessor);
135
+ }
136
+
137
+ // Proxy values back in standard feature format
138
+ return (object, info) => {
139
+ const {data, index} = info;
140
+ const binaryData = (data as unknown as {data: Raster}).data;
141
+ const proxy = createBinaryProxy(binaryData.cells, index);
142
+ // @ts-ignore (TS2349) accessor is always function
143
+ return accessor({properties: proxy}, info);
144
+ };
145
+ }
146
+ }
@@ -0,0 +1,63 @@
1
+ import {
2
+ CompositeLayer,
3
+ CompositeLayerProps,
4
+ Layer,
5
+ LayersList,
6
+ UpdateParameters
7
+ } from '@deck.gl/core';
8
+ import RasterLayer, {RasterLayerProps} from './raster-layer';
9
+ import QuadbinTileset2D from './quadbin-tileset-2d';
10
+ import SpatialIndexTileLayer from './spatial-index-tile-layer';
11
+
12
+ export const renderSubLayers = props => {
13
+ const tileIndex = props.tile?.index?.q;
14
+ if (!tileIndex) return null;
15
+ return new RasterLayer(props, {tileIndex});
16
+ };
17
+
18
+ /** All properties supported by RasterTileLayer. */
19
+ export type RasterTileLayerProps<DataT = any> = _RasterTileLayerProps<DataT> & CompositeLayerProps;
20
+
21
+ /** Properties added by RasterTileLayer. */
22
+ type _RasterTileLayerProps<DataT> = RasterLayerProps<DataT> & {
23
+ data: string;
24
+ };
25
+
26
+ export default class RasterTileLayer<
27
+ DataT = any,
28
+ ExtraProps extends {} = {}
29
+ > extends CompositeLayer<ExtraProps & Required<_RasterTileLayerProps<DataT>>> {
30
+ static layerName = 'RasterTileLayer';
31
+ static defaultProps = {};
32
+
33
+ state!: {tileJSON: any; data: any};
34
+ initializeState(): void {
35
+ this.setState({data: null, tileJSON: null});
36
+ }
37
+
38
+ updateState({changeFlags}: UpdateParameters<this>): void {
39
+ if (changeFlags.dataChanged) {
40
+ let {data} = this.props;
41
+ const tileJSON = data;
42
+ data = (tileJSON as any).tiles;
43
+ this.setState({data, tileJSON});
44
+ }
45
+ }
46
+
47
+ renderLayers(): Layer | null | LayersList {
48
+ const {data, tileJSON} = this.state;
49
+ const minZoom = parseInt(tileJSON?.minzoom);
50
+ const maxZoom = parseInt(tileJSON?.maxzoom);
51
+ return [
52
+ new SpatialIndexTileLayer(this.props, {
53
+ id: `raster-tile-layer-${this.props.id}`,
54
+ data,
55
+ // TODO: Tileset2D should be generic over TileIndex type
56
+ TilesetClass: QuadbinTileset2D as any,
57
+ renderSubLayers,
58
+ minZoom,
59
+ maxZoom
60
+ })
61
+ ];
62
+ }
63
+ }
@@ -0,0 +1,42 @@
1
+ import {LoaderOptions, LoaderWithParser} from '@loaders.gl/loader-utils';
2
+
3
+ import {TileReader} from './carto-raster-tile';
4
+ import {parsePbf} from './tile-loader-utils';
5
+ import {NumericProps, Properties} from './spatialjson-utils';
6
+
7
+ const CartoRasterTileLoader: LoaderWithParser = {
8
+ name: 'CARTO Raster Tile',
9
+ version: '1',
10
+ id: 'cartoRasterTile',
11
+ module: 'carto',
12
+ extensions: ['pbf'],
13
+ mimeTypes: ['application/vnd.carto-raster-tile'],
14
+ category: 'geometry',
15
+ worker: false,
16
+ parse: async (arrayBuffer, options) => parseCartoRasterTile(arrayBuffer, options),
17
+ parseSync: parseCartoRasterTile,
18
+ options: {}
19
+ };
20
+
21
+ export type Raster = {
22
+ blockWidth: number;
23
+ blockHeight: number;
24
+ cells: {
25
+ numericProps: NumericProps;
26
+ properties: Properties[];
27
+ };
28
+ };
29
+
30
+ function parseCartoRasterTile(arrayBuffer: ArrayBuffer, options?: LoaderOptions): Raster | null {
31
+ if (!arrayBuffer) return null;
32
+ const tile = parsePbf(arrayBuffer, TileReader);
33
+ const {bands, blockHeight, blockWidth} = tile;
34
+ const numericProps = {};
35
+ for (let i = 0; i < bands.length; i++) {
36
+ const {name, data} = bands[i];
37
+ numericProps[name] = data;
38
+ }
39
+ return {blockWidth, blockHeight, cells: {numericProps, properties: []}};
40
+ }
41
+
42
+ export default CartoRasterTileLoader;
@@ -0,0 +1,46 @@
1
+ import {readPackedTypedArray} from './fast-pbf';
2
+
3
+ const ARRAY_TYPES = {
4
+ uint8: Uint8Array,
5
+ uint16: Uint16Array,
6
+ uint32: Uint32Array,
7
+ uint64: BigUint64Array,
8
+ int8: Int8Array,
9
+ int16: Int16Array,
10
+ int32: Int32Array,
11
+ int64: BigInt64Array,
12
+ float32: Float32Array,
13
+ float64: Float64Array
14
+ };
15
+
16
+ // Band ========================================
17
+
18
+ export class BandReader {
19
+ static read(pbf, end?: number) {
20
+ return pbf.readFields(BandReader._readField, {name: '', type: '', data: null}, end);
21
+ }
22
+
23
+ static _readField(this: void, tag, obj, pbf) {
24
+ if (tag === 1) obj.name = pbf.readString();
25
+ else if (tag === 2) obj.type = pbf.readString();
26
+ else if (tag === 3) {
27
+ const TypedArray = ARRAY_TYPES[obj.type];
28
+ if (!TypedArray) {
29
+ throw Error(`Invalid data type: ${obj.type}`);
30
+ }
31
+ obj.data = {};
32
+ readPackedTypedArray(TypedArray, pbf, obj.data);
33
+ }
34
+ }
35
+ }
36
+
37
+ export class TileReader {
38
+ static read(pbf, end) {
39
+ return pbf.readFields(TileReader._readField, {blockWidth: 0, blockHeight: 0, bands: []}, end);
40
+ }
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));
45
+ }
46
+ }
@@ -1,4 +1,4 @@
1
- import {readPackedFixed64} from './fast-pbf';
1
+ import {readPackedTypedArray} from './fast-pbf';
2
2
  import {Indices, IndexScheme} from './spatialjson-utils';
3
3
  import {NumericProp, NumericPropKeyValueReader, PropertiesReader} from './carto-tile';
4
4
 
@@ -9,7 +9,7 @@ export class IndicesReader {
9
9
  return pbf.readFields(IndicesReader._readField, {value: []}, end);
10
10
  }
11
11
  static _readField(this: void, tag: number, obj, pbf) {
12
- if (tag === 1) readPackedFixed64(pbf, obj);
12
+ if (tag === 1) readPackedTypedArray(BigUint64Array, pbf, obj);
13
13
  }
14
14
  }
15
15
 
@@ -1,4 +1,4 @@
1
- import {readPackedDouble} from './fast-pbf';
1
+ import {readPackedTypedArray} from './fast-pbf';
2
2
 
3
3
  // KeyValueObject ========================================
4
4
  interface KeyValueObject {
@@ -43,7 +43,7 @@ class DoublesReader {
43
43
  return {value: new Float32Array(value), size};
44
44
  }
45
45
  static _readField(this: void, tag: number, obj, pbf) {
46
- if (tag === 1) readPackedDouble(pbf, obj);
46
+ if (tag === 1) readPackedTypedArray(Float64Array, pbf, obj);
47
47
  else if (tag === 2) obj.size = pbf.readVarint(true);
48
48
  }
49
49
  }
@@ -92,7 +92,7 @@ class NumericPropReader {
92
92
  return pbf.readFields(NumericPropReader._readField, {value: []}, end);
93
93
  }
94
94
  static _readField(this: void, tag: number, obj: NumericProp, pbf) {
95
- if (tag === 1) readPackedDouble(pbf, obj);
95
+ if (tag === 1) readPackedTypedArray(Float64Array, pbf, obj);
96
96
  }
97
97
  }
98
98
 
@@ -1,13 +1,7 @@
1
- // Optimized (100X speed improvement) reading functions for binary data
2
- export function readPackedDouble(pbf, obj) {
1
+ // Optimized (100X speed improvement) reading function for binary data
2
+ export function readPackedTypedArray(TypedArray, pbf, obj) {
3
3
  const end = pbf.type === 2 ? pbf.readVarint() + pbf.pos : pbf.pos + 1;
4
- obj.value = new Float64Array(pbf.buf.buffer.slice(pbf.pos, end));
5
- pbf.pos = end;
6
- return obj.value;
7
- }
8
- export function readPackedFixed64(pbf, obj) {
9
- const end = pbf.type === 2 ? pbf.readVarint() + pbf.pos : pbf.pos + 1;
10
- obj.value = new BigUint64Array(pbf.buf.buffer.slice(pbf.pos, end));
4
+ obj.value = new TypedArray(pbf.buf.buffer.slice(pbf.pos, end));
11
5
  pbf.pos = end;
12
6
  return obj.value;
13
7
  }