@deck.gl/carto 8.10.0-alpha.2 → 8.10.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 (249) hide show
  1. package/LICENSE +1 -1
  2. package/dist/cartoRasterTile-worker.js +1084 -0
  3. package/dist/cartoSpatialTile-worker.js +1469 -0
  4. package/dist/cartoVectorTile-worker.js +1727 -0
  5. package/dist/dist.dev.js +1733 -881
  6. package/dist/es5/api/layer-map.js +3 -7
  7. package/dist/es5/api/layer-map.js.map +1 -1
  8. package/dist/es5/api/maps-api-common.js +0 -1
  9. package/dist/es5/api/maps-api-common.js.map +1 -1
  10. package/dist/es5/api/maps-v3-client.js +5 -20
  11. package/dist/es5/api/maps-v3-client.js.map +1 -1
  12. package/dist/es5/index.js +74 -6
  13. package/dist/es5/index.js.map +1 -1
  14. package/dist/es5/layers/h3-tile-layer.js +23 -41
  15. package/dist/es5/layers/h3-tile-layer.js.map +1 -1
  16. package/dist/es5/layers/quadbin-tile-layer.js +21 -42
  17. package/dist/es5/layers/quadbin-tile-layer.js.map +1 -1
  18. package/dist/es5/layers/raster-tile-layer.js +23 -39
  19. package/dist/es5/layers/raster-tile-layer.js.map +1 -1
  20. package/dist/es5/layers/schema/carto-raster-tile-loader.js +13 -4
  21. package/dist/es5/layers/schema/carto-raster-tile-loader.js.map +1 -1
  22. package/dist/es5/layers/schema/carto-spatial-tile-loader.js +14 -8
  23. package/dist/es5/layers/schema/carto-spatial-tile-loader.js.map +1 -1
  24. package/dist/es5/layers/schema/carto-tile.js +1 -1
  25. package/dist/es5/layers/schema/carto-tile.js.map +1 -1
  26. package/dist/es5/layers/schema/carto-vector-tile-loader.js +64 -4
  27. package/dist/es5/layers/schema/carto-vector-tile-loader.js.map +1 -1
  28. package/dist/es5/layers/utils.js +29 -0
  29. package/dist/es5/layers/utils.js.map +1 -0
  30. package/dist/es5/layers/{carto-tile-layer.js → vector-tile-layer.js} +49 -24
  31. package/dist/es5/layers/vector-tile-layer.js.map +1 -0
  32. package/dist/es5/sources/base-source.js +100 -0
  33. package/dist/es5/sources/base-source.js.map +1 -0
  34. package/dist/es5/sources/common.js +48 -0
  35. package/dist/es5/sources/common.js.map +1 -0
  36. package/dist/es5/sources/h3-query-source.js +58 -0
  37. package/dist/es5/sources/h3-query-source.js.map +1 -0
  38. package/dist/es5/sources/h3-table-source.js +58 -0
  39. package/dist/es5/sources/h3-table-source.js.map +1 -0
  40. package/dist/es5/sources/h3-tileset-source.js +43 -0
  41. package/dist/es5/sources/h3-tileset-source.js.map +1 -0
  42. package/dist/es5/sources/index.js +94 -0
  43. package/dist/es5/sources/index.js.map +1 -0
  44. package/dist/es5/sources/quadbin-query-source.js +58 -0
  45. package/dist/es5/sources/quadbin-query-source.js.map +1 -0
  46. package/dist/es5/sources/quadbin-table-source.js +58 -0
  47. package/dist/es5/sources/quadbin-table-source.js.map +1 -0
  48. package/dist/es5/sources/quadbin-tileset-source.js +43 -0
  49. package/dist/es5/sources/quadbin-tileset-source.js.map +1 -0
  50. package/dist/es5/sources/raster-source.js +43 -0
  51. package/dist/es5/sources/raster-source.js.map +1 -0
  52. package/dist/es5/sources/utils.js +136 -0
  53. package/dist/es5/sources/utils.js.map +1 -0
  54. package/dist/es5/sources/vector-query-source.js +52 -0
  55. package/dist/es5/sources/vector-query-source.js.map +1 -0
  56. package/dist/es5/sources/vector-table-source.js +52 -0
  57. package/dist/es5/sources/vector-table-source.js.map +1 -0
  58. package/dist/es5/sources/vector-tileset-source.js +43 -0
  59. package/dist/es5/sources/vector-tileset-source.js.map +1 -0
  60. package/dist/es5/utils.js +5 -0
  61. package/dist/es5/utils.js.map +1 -1
  62. package/dist/es5/workers/cartoRasterTile.js +10 -0
  63. package/dist/es5/workers/cartoRasterTile.js.map +1 -0
  64. package/dist/es5/workers/cartoSpatialTile.js +10 -0
  65. package/dist/es5/workers/cartoSpatialTile.js.map +1 -0
  66. package/dist/es5/workers/cartoVectorTile.js +10 -0
  67. package/dist/es5/workers/cartoVectorTile.js.map +1 -0
  68. package/dist/esm/api/layer-map.js +3 -7
  69. package/dist/esm/api/layer-map.js.map +1 -1
  70. package/dist/esm/api/maps-api-common.js +0 -1
  71. package/dist/esm/api/maps-api-common.js.map +1 -1
  72. package/dist/esm/api/maps-v3-client.js +2 -12
  73. package/dist/esm/api/maps-v3-client.js.map +1 -1
  74. package/dist/esm/index.js +5 -4
  75. package/dist/esm/index.js.map +1 -1
  76. package/dist/esm/layers/h3-tile-layer.js +21 -37
  77. package/dist/esm/layers/h3-tile-layer.js.map +1 -1
  78. package/dist/esm/layers/quadbin-tile-layer.js +18 -38
  79. package/dist/esm/layers/quadbin-tile-layer.js.map +1 -1
  80. package/dist/esm/layers/raster-tile-layer.js +19 -34
  81. package/dist/esm/layers/raster-tile-layer.js.map +1 -1
  82. package/dist/esm/layers/schema/carto-raster-tile-loader.js +12 -4
  83. package/dist/esm/layers/schema/carto-raster-tile-loader.js.map +1 -1
  84. package/dist/esm/layers/schema/carto-spatial-tile-loader.js +13 -8
  85. package/dist/esm/layers/schema/carto-spatial-tile-loader.js.map +1 -1
  86. package/dist/esm/layers/schema/carto-tile.js +1 -1
  87. package/dist/esm/layers/schema/carto-tile.js.map +1 -1
  88. package/dist/esm/layers/schema/carto-vector-tile-loader.js +63 -4
  89. package/dist/esm/layers/schema/carto-vector-tile-loader.js.map +1 -1
  90. package/dist/esm/layers/utils.js +14 -0
  91. package/dist/esm/layers/utils.js.map +1 -0
  92. package/dist/esm/layers/{carto-tile-layer.js → vector-tile-layer.js} +39 -15
  93. package/dist/esm/layers/vector-tile-layer.js.map +1 -0
  94. package/dist/esm/sources/base-source.js +49 -0
  95. package/dist/esm/sources/base-source.js.map +1 -0
  96. package/dist/esm/sources/common.js +26 -0
  97. package/dist/esm/sources/common.js.map +1 -0
  98. package/dist/esm/sources/h3-query-source.js +32 -0
  99. package/dist/esm/sources/h3-query-source.js.map +1 -0
  100. package/dist/esm/sources/h3-table-source.js +32 -0
  101. package/dist/esm/sources/h3-table-source.js.map +1 -0
  102. package/dist/esm/sources/h3-tileset-source.js +14 -0
  103. package/dist/esm/sources/h3-tileset-source.js.map +1 -0
  104. package/dist/esm/sources/index.js +12 -0
  105. package/dist/esm/sources/index.js.map +1 -0
  106. package/dist/esm/sources/quadbin-query-source.js +32 -0
  107. package/dist/esm/sources/quadbin-query-source.js.map +1 -0
  108. package/dist/esm/sources/quadbin-table-source.js +32 -0
  109. package/dist/esm/sources/quadbin-table-source.js.map +1 -0
  110. package/dist/esm/sources/quadbin-tileset-source.js +14 -0
  111. package/dist/esm/sources/quadbin-tileset-source.js.map +1 -0
  112. package/dist/esm/sources/raster-source.js +14 -0
  113. package/dist/esm/sources/raster-source.js.map +1 -0
  114. package/dist/esm/sources/utils.js +69 -0
  115. package/dist/esm/sources/utils.js.map +1 -0
  116. package/dist/esm/sources/vector-query-source.js +25 -0
  117. package/dist/esm/sources/vector-query-source.js.map +1 -0
  118. package/dist/esm/sources/vector-table-source.js +25 -0
  119. package/dist/esm/sources/vector-table-source.js.map +1 -0
  120. package/dist/esm/sources/vector-tileset-source.js +14 -0
  121. package/dist/esm/sources/vector-tileset-source.js.map +1 -0
  122. package/dist/esm/utils.js +3 -0
  123. package/dist/esm/utils.js.map +1 -1
  124. package/dist/esm/workers/cartoRasterTile.js +4 -0
  125. package/dist/esm/workers/cartoRasterTile.js.map +1 -0
  126. package/dist/esm/workers/cartoSpatialTile.js +4 -0
  127. package/dist/esm/workers/cartoSpatialTile.js.map +1 -0
  128. package/dist/esm/workers/cartoVectorTile.js +4 -0
  129. package/dist/esm/workers/cartoVectorTile.js.map +1 -0
  130. package/dist.min.js +25 -25
  131. package/package.json +11 -9
  132. package/src/api/layer-map.ts +4 -8
  133. package/src/api/maps-api-common.ts +0 -1
  134. package/src/api/maps-v3-client.ts +6 -5
  135. package/src/index.ts +34 -5
  136. package/src/layers/h3-tile-layer.ts +22 -35
  137. package/src/layers/quadbin-tile-layer.ts +19 -33
  138. package/src/layers/raster-tile-layer.ts +22 -26
  139. package/src/layers/schema/carto-raster-tile-loader.ts +26 -6
  140. package/src/layers/schema/carto-spatial-tile-loader.ts +25 -11
  141. package/src/layers/schema/carto-tile.ts +1 -1
  142. package/src/layers/schema/carto-vector-tile-loader.ts +79 -9
  143. package/src/layers/utils.ts +11 -0
  144. package/src/layers/{carto-tile-layer.ts → vector-tile-layer.ts} +40 -21
  145. package/src/sources/base-source.ts +55 -0
  146. package/src/sources/common.ts +132 -0
  147. package/src/sources/h3-query-source.ts +45 -0
  148. package/src/sources/h3-table-source.ts +46 -0
  149. package/src/sources/h3-tileset-source.ts +16 -0
  150. package/src/sources/index.ts +32 -0
  151. package/src/sources/quadbin-query-source.ts +46 -0
  152. package/src/sources/quadbin-table-source.ts +46 -0
  153. package/src/sources/quadbin-tileset-source.ts +16 -0
  154. package/src/sources/raster-source.ts +16 -0
  155. package/src/sources/utils.ts +63 -0
  156. package/src/sources/vector-query-source.ts +23 -0
  157. package/src/sources/vector-table-source.ts +23 -0
  158. package/src/sources/vector-tileset-source.ts +16 -0
  159. package/src/utils.ts +6 -0
  160. package/src/workers/cartoRasterTile.ts +4 -0
  161. package/src/workers/cartoSpatialTile.ts +4 -0
  162. package/src/workers/cartoVectorTile.ts +4 -0
  163. package/typed/api/layer-map.d.ts +2 -3
  164. package/typed/api/layer-map.d.ts.map +1 -1
  165. package/typed/api/maps-api-common.d.ts +0 -1
  166. package/typed/api/maps-api-common.d.ts.map +1 -1
  167. package/typed/api/maps-v3-client.d.ts +0 -3
  168. package/typed/api/maps-v3-client.d.ts.map +1 -1
  169. package/typed/index.d.ts +6 -4
  170. package/typed/index.d.ts.map +1 -1
  171. package/typed/layers/h3-tile-layer.d.ts +5 -8
  172. package/typed/layers/h3-tile-layer.d.ts.map +1 -1
  173. package/typed/layers/quadbin-tile-layer.d.ts +5 -9
  174. package/typed/layers/quadbin-tile-layer.d.ts.map +1 -1
  175. package/typed/layers/raster-tile-layer.d.ts +6 -10
  176. package/typed/layers/raster-tile-layer.d.ts.map +1 -1
  177. package/typed/layers/schema/carto-raster-tile-loader.d.ts.map +1 -1
  178. package/typed/layers/schema/carto-spatial-tile-loader.d.ts.map +1 -1
  179. package/typed/layers/schema/carto-vector-tile-loader.d.ts.map +1 -1
  180. package/typed/layers/utils.d.ts +5 -0
  181. package/typed/layers/utils.d.ts.map +1 -0
  182. package/typed/layers/{carto-tile-layer.d.ts → vector-tile-layer.d.ts} +11 -7
  183. package/typed/layers/vector-tile-layer.d.ts.map +1 -0
  184. package/typed/sources/base-source.d.ts +4 -0
  185. package/typed/sources/base-source.d.ts.map +1 -0
  186. package/typed/sources/common.d.ts +116 -0
  187. package/typed/sources/common.d.ts.map +1 -0
  188. package/typed/sources/h3-query-source.d.ts +5 -0
  189. package/typed/sources/h3-query-source.d.ts.map +1 -0
  190. package/typed/sources/h3-table-source.d.ts +5 -0
  191. package/typed/sources/h3-table-source.d.ts.map +1 -0
  192. package/typed/sources/h3-tileset-source.d.ts +5 -0
  193. package/typed/sources/h3-tileset-source.d.ts.map +1 -0
  194. package/typed/sources/index.d.ts +23 -0
  195. package/typed/sources/index.d.ts.map +1 -0
  196. package/typed/sources/quadbin-query-source.d.ts +5 -0
  197. package/typed/sources/quadbin-query-source.d.ts.map +1 -0
  198. package/typed/sources/quadbin-table-source.d.ts +5 -0
  199. package/typed/sources/quadbin-table-source.d.ts.map +1 -0
  200. package/typed/sources/quadbin-tileset-source.d.ts +5 -0
  201. package/typed/sources/quadbin-tileset-source.d.ts.map +1 -0
  202. package/typed/sources/raster-source.d.ts +5 -0
  203. package/typed/sources/raster-source.d.ts.map +1 -0
  204. package/typed/sources/utils.d.ts +15 -0
  205. package/typed/sources/utils.d.ts.map +1 -0
  206. package/typed/sources/vector-query-source.d.ts +5 -0
  207. package/typed/sources/vector-query-source.d.ts.map +1 -0
  208. package/typed/sources/vector-table-source.d.ts +5 -0
  209. package/typed/sources/vector-table-source.d.ts.map +1 -0
  210. package/typed/sources/vector-tileset-source.d.ts +5 -0
  211. package/typed/sources/vector-tileset-source.d.ts.map +1 -0
  212. package/typed/utils.d.ts +1 -0
  213. package/typed/utils.d.ts.map +1 -1
  214. package/typed/workers/cartoRasterTile.d.ts +2 -0
  215. package/typed/workers/cartoRasterTile.d.ts.map +1 -0
  216. package/typed/workers/cartoSpatialTile.d.ts +2 -0
  217. package/typed/workers/cartoSpatialTile.d.ts.map +1 -0
  218. package/typed/workers/cartoVectorTile.d.ts +2 -0
  219. package/typed/workers/cartoVectorTile.d.ts.map +1 -0
  220. package/dist/es5/layers/carto-tile-layer.js.map +0 -1
  221. package/dist/esm/layers/carto-tile-layer.js.map +0 -1
  222. package/typed/api/index.js +0 -3
  223. package/typed/api/layer-map.js +0 -264
  224. package/typed/api/maps-api-common.js +0 -50
  225. package/typed/api/maps-client.js +0 -125
  226. package/typed/api/maps-v3-client.js +0 -304
  227. package/typed/api/parseMap.js +0 -178
  228. package/typed/basemap.js +0 -9
  229. package/typed/config.js +0 -35
  230. package/typed/index.js +0 -10
  231. package/typed/layers/carto-layer.js +0 -173
  232. package/typed/layers/carto-tile-layer.d.ts.map +0 -1
  233. package/typed/layers/carto-tile-layer.js +0 -105
  234. package/typed/layers/h3-tile-layer.js +0 -47
  235. package/typed/layers/h3-tileset-2d.js +0 -85
  236. package/typed/layers/quadkey-tile-layer.d.ts +0 -21
  237. package/typed/layers/quadkey-tile-layer.d.ts.map +0 -1
  238. package/typed/layers/quadkey-tile-layer.js +0 -42
  239. package/typed/layers/quadkey-tileset-2d.d.ts +0 -15
  240. package/typed/layers/quadkey-tileset-2d.d.ts.map +0 -1
  241. package/typed/layers/quadkey-tileset-2d.js +0 -36
  242. package/typed/layers/schema/carto-tile.js +0 -161
  243. package/typed/layers/spatial-index-tile-layer.js +0 -40
  244. package/typed/style/color-bins-style.js +0 -12
  245. package/typed/style/color-categories-style.js +0 -16
  246. package/typed/style/color-continuous-style.js +0 -12
  247. package/typed/style/palette.js +0 -62
  248. package/typed/style/utils.js +0 -15
  249. package/typed/utils.js +0 -4
@@ -1,32 +1,102 @@
1
+ import earcut from 'earcut';
1
2
  import {LoaderOptions, LoaderWithParser} from '@loaders.gl/loader-utils';
2
- import type {BinaryFeatures} from '@loaders.gl/schema';
3
+ import type {BinaryFeatures, BinaryPolygonFeatures, TypedArray} from '@loaders.gl/schema';
3
4
 
4
5
  import {TileReader} from './carto-tile';
5
6
  import {parsePbf} from './tile-loader-utils';
7
+ import {getWorkerUrl} from '../../utils';
8
+
9
+ const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
10
+ const id = 'cartoVectorTile';
11
+
12
+ type CartoVectorTileLoaderOptions = LoaderOptions & {
13
+ cartoVectorTile?: {
14
+ workerUrl: string;
15
+ };
16
+ };
17
+
18
+ const DEFAULT_OPTIONS: CartoVectorTileLoaderOptions = {
19
+ cartoVectorTile: {
20
+ workerUrl: getWorkerUrl(id, VERSION)
21
+ }
22
+ };
6
23
 
7
24
  const CartoVectorTileLoader: LoaderWithParser = {
8
25
  name: 'CARTO Vector Tile',
9
- version: '1',
10
- id: 'cartoVectorTile',
26
+ version: VERSION,
27
+ id,
11
28
  module: 'carto',
12
29
  extensions: ['pbf'],
13
30
  mimeTypes: ['application/vnd.carto-vector-tile'],
14
31
  category: 'geometry',
15
- worker: false,
16
- parse: async (arrayBuffer, options) => parseCartoVectorTile(arrayBuffer, options),
32
+ parse: async (arrayBuffer, options?: CartoVectorTileLoaderOptions) =>
33
+ parseCartoVectorTile(arrayBuffer, options),
17
34
  parseSync: parseCartoVectorTile,
18
- options: {}
35
+ worker: true,
36
+ options: DEFAULT_OPTIONS
19
37
  };
20
38
 
39
+ function triangulatePolygon(
40
+ polygons: BinaryPolygonFeatures,
41
+ target: number[],
42
+ {
43
+ startPosition,
44
+ endPosition,
45
+ indices
46
+ }: {startPosition: number; endPosition: number; indices: TypedArray}
47
+ ): void {
48
+ const coordLength = polygons.positions.size;
49
+ const start = startPosition * coordLength;
50
+ const end = endPosition * coordLength;
51
+
52
+ // Extract positions and holes for just this polygon
53
+ const polygonPositions = polygons.positions.value.subarray(start, end);
54
+
55
+ // Holes are referenced relative to outer polygon
56
+ const holes = indices.slice(1).map((n: number) => n - startPosition);
57
+
58
+ // Compute triangulation
59
+ const triangles = earcut(polygonPositions, holes, coordLength);
60
+
61
+ // Indices returned by triangulation are relative to start
62
+ // of polygon, so we need to offset
63
+ for (let t = 0, tl = triangles.length; t < tl; ++t) {
64
+ target.push(startPosition + triangles[t]);
65
+ }
66
+ }
67
+
68
+ function triangulate(polygons: BinaryPolygonFeatures) {
69
+ const {polygonIndices, positions, primitivePolygonIndices} = polygons;
70
+ const triangles = [];
71
+
72
+ let rangeStart = 0;
73
+ for (let i = 0; i < polygonIndices.value.length - 1; i++) {
74
+ const startPosition = polygonIndices.value[i];
75
+ const endPosition = polygonIndices.value[i + 1];
76
+
77
+ // Extract hole indices between start & end position
78
+ const rangeEnd = primitivePolygonIndices.value.indexOf(endPosition);
79
+ const indices = primitivePolygonIndices.value.subarray(rangeStart, rangeEnd);
80
+ rangeStart = rangeEnd;
81
+
82
+ triangulatePolygon(polygons, triangles, {startPosition, endPosition, indices});
83
+ }
84
+
85
+ polygons.triangles = {value: new Uint32Array(triangles), size: 1};
86
+ }
87
+
21
88
  function parseCartoVectorTile(
22
89
  arrayBuffer: ArrayBuffer,
23
- options?: LoaderOptions
90
+ options?: CartoVectorTileLoaderOptions
24
91
  ): BinaryFeatures | null {
25
92
  if (!arrayBuffer) return null;
26
93
  const tile = parsePbf(arrayBuffer, TileReader);
27
94
 
28
- // Note: there is slight, difference in `numericProps` type, however geojson/mvtlayer can cope with this
29
- return tile as unknown as BinaryFeatures;
95
+ if (tile.polygons && !tile.polygons.triangles) {
96
+ triangulate(tile.polygons);
97
+ }
98
+
99
+ return tile;
30
100
  }
31
101
 
32
102
  export default CartoVectorTileLoader;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Adds access token to Authorization header in loadOptions
3
+ */
4
+ export function injectAccessToken(loadOptions: any, accessToken: string): void {
5
+ if (!loadOptions?.fetch?.headers?.Authorization) {
6
+ loadOptions.fetch = {
7
+ ...loadOptions.fetch,
8
+ headers: {...loadOptions.fetch?.headers, Authorization: `Bearer ${accessToken}`}
9
+ };
10
+ }
11
+ }
@@ -17,19 +17,23 @@ import {binaryToGeojson} from '@loaders.gl/gis';
17
17
  import type {BinaryFeatures} from '@loaders.gl/schema';
18
18
  import {TileFormat, TILE_FORMATS} from '../api/maps-api-common';
19
19
  import type {Feature} from 'geojson';
20
+ import {TilejsonPropType, CartoTilejsonResult} from '../sources/common';
21
+ import {injectAccessToken} from './utils';
20
22
 
21
23
  const defaultTileFormat = TILE_FORMATS.BINARY;
22
24
 
23
- const defaultProps: DefaultProps<CartoTileLayerProps> = {
25
+ const defaultProps: DefaultProps<VectorTileLayerProps> = {
24
26
  ...MVTLayer.defaultProps,
27
+ data: TilejsonPropType,
25
28
  formatTiles: defaultTileFormat
26
29
  };
27
30
 
28
- /** All properties supported by CartoTileLayer. */
29
- export type CartoTileLayerProps = _CartoTileLayerProps & MVTLayerProps;
31
+ /** All properties supported by VectorTileLayer. */
32
+ export type VectorTileLayerProps = _VectorTileLayerProps & Omit<MVTLayerProps, 'data'>;
30
33
 
31
- /** Properties added by CartoTileLayer. */
32
- type _CartoTileLayerProps = {
34
+ /** Properties added by VectorTileLayer. */
35
+ type _VectorTileLayerProps = {
36
+ data: null | CartoTilejsonResult | Promise<CartoTilejsonResult>;
33
37
  /** Use to override the default tile data format.
34
38
  *
35
39
  * Possible values are: `TILE_FORMATS.BINARY`, `TILE_FORMATS.GEOJSON` and `TILE_FORMATS.MVT`.
@@ -39,37 +43,48 @@ type _CartoTileLayerProps = {
39
43
  formatTiles?: TileFormat;
40
44
  };
41
45
 
42
- export default class CartoTileLayer<ExtraProps extends {} = {}> extends MVTLayer<
43
- Required<_CartoTileLayerProps> & ExtraProps
46
+ // TODO Perhaps we can't subclass MVTLayer and keep types. Better to subclass TileLayer instead?
47
+ // @ts-ignore
48
+ export default class VectorTileLayer<ExtraProps extends {} = {}> extends MVTLayer<
49
+ Required<_VectorTileLayerProps> & ExtraProps
44
50
  > {
45
- static layerName = 'CartoTileLayer';
51
+ static layerName = 'VectorTileLayer';
46
52
  static defaultProps = defaultProps;
47
53
 
48
54
  initializeState(): void {
49
55
  super.initializeState();
50
- const binary = this.props.formatTiles === TILE_FORMATS.BINARY;
56
+ const binary = this.props.formatTiles === TILE_FORMATS.BINARY || TILE_FORMATS.MVT;
51
57
  this.setState({binary});
52
58
  }
53
59
 
60
+ updateState(parameters) {
61
+ const {props} = parameters;
62
+ if (props.data) {
63
+ super.updateState(parameters);
64
+
65
+ const formatTiles = new URL(props.data.tiles[0]).searchParams.get('formatTiles');
66
+ const mvt = formatTiles === TILE_FORMATS.MVT;
67
+ this.setState({mvt});
68
+ }
69
+ }
70
+
71
+ getLoadOptions(): any {
72
+ const loadOptions = super.getLoadOptions() || {};
73
+ const tileJSON = this.props.data as CartoTilejsonResult;
74
+ injectAccessToken(loadOptions, tileJSON.accessToken);
75
+ loadOptions.gis = {format: 'binary'}; // Use binary for MVT loading
76
+ return loadOptions;
77
+ }
78
+
54
79
  getTileData(tile: TileLoadProps) {
55
80
  const url = _getURLFromTemplate(this.state.data, tile);
56
81
  if (!url) {
57
82
  return Promise.reject('Invalid URL');
58
83
  }
59
84
 
60
- let loadOptions = this.getLoadOptions();
61
- const {fetch, formatTiles} = this.props;
85
+ const loadOptions = this.getLoadOptions();
86
+ const {fetch} = this.props;
62
87
  const {signal} = tile;
63
-
64
- // The backend doesn't yet support our custom mime-type, so force it here
65
- // TODO remove once backend sends the correct mime-type
66
- if (formatTiles === TILE_FORMATS.BINARY) {
67
- loadOptions = {
68
- ...loadOptions,
69
- mimeType: 'application/vnd.carto-vector-tile'
70
- };
71
- }
72
-
73
88
  return fetch(url, {propName: 'data', layer: this, loadOptions, signal});
74
89
  }
75
90
 
@@ -85,6 +100,10 @@ export default class CartoTileLayer<ExtraProps extends {} = {}> extends MVTLayer
85
100
  return null;
86
101
  }
87
102
 
103
+ if (this.state.mvt) {
104
+ return super.renderSubLayers(props) as GeoJsonLayer;
105
+ }
106
+
88
107
  const tileBbox = props.tile.bbox as any;
89
108
  const {west, south, east, north} = tileBbox;
90
109
 
@@ -0,0 +1,55 @@
1
+ import type {MapType} from '../api/maps-api-common';
2
+ import {APIErrorContext} from '../api/carto-api-error';
3
+ import {
4
+ CartoSourceOptionalOptions,
5
+ CartoSourceRequiredOptions,
6
+ CartoTilejsonResult,
7
+ GeojsonResult,
8
+ JsonResult,
9
+ SOURCE_DEFAULTS,
10
+ Tilejson,
11
+ TilejsonMapInstantiation
12
+ } from './common';
13
+ import {buildApiEndpoint, requestWithParameters} from './utils';
14
+
15
+ export async function cartoBaseSource<UrlParameters extends Record<string, string>>(
16
+ endpoint: MapType,
17
+ options: Partial<CartoSourceOptionalOptions> & CartoSourceRequiredOptions,
18
+ urlParameters: UrlParameters
19
+ ): Promise<CartoTilejsonResult | GeojsonResult | JsonResult> {
20
+ const mergedOptions = {...SOURCE_DEFAULTS, ...options, endpoint};
21
+ const baseUrl = buildApiEndpoint(mergedOptions);
22
+ const {accessToken, format} = mergedOptions;
23
+ const headers = {Authorization: `Bearer ${options.accessToken}`, ...options.headers};
24
+
25
+ const errorContext: APIErrorContext = {
26
+ requestType: 'Map instantiation',
27
+ connection: options.connectionName,
28
+ type: endpoint,
29
+ source: JSON.stringify(urlParameters, undefined, 2)
30
+ };
31
+ const mapInstantiation = await requestWithParameters<TilejsonMapInstantiation>({
32
+ baseUrl,
33
+ parameters: urlParameters,
34
+ headers,
35
+ errorContext
36
+ });
37
+
38
+ const dataUrl = mapInstantiation[format].url[0];
39
+ errorContext.requestType = 'Map data';
40
+
41
+ if (format === 'tilejson') {
42
+ const tilejson = await requestWithParameters<Tilejson>({
43
+ baseUrl: dataUrl,
44
+ headers,
45
+ errorContext
46
+ });
47
+ return {...tilejson, accessToken};
48
+ }
49
+
50
+ return await requestWithParameters<GeojsonResult | JsonResult>({
51
+ baseUrl: dataUrl,
52
+ headers,
53
+ errorContext
54
+ });
55
+ }
@@ -0,0 +1,132 @@
1
+ /* eslint-disable camelcase */
2
+ import type {Feature} from 'geojson';
3
+ import {Format, MapInstantiation, TileFormat, QueryParameters} from '../api/maps-api-common';
4
+
5
+ export type CartoSourceRequiredOptions = {
6
+ accessToken: string;
7
+ connectionName: string;
8
+ };
9
+
10
+ export type CartoSourceOptionalOptions = {
11
+ apiBaseUrl: string;
12
+ clientId: string;
13
+ format: Format;
14
+ formatTiles: TileFormat;
15
+ headers: Record<string, string>;
16
+ mapsUrl?: string;
17
+ };
18
+
19
+ export type CartoSourceOptions = CartoSourceRequiredOptions & Partial<CartoSourceOptionalOptions>;
20
+
21
+ export type CartoAggregationOptions = {
22
+ aggregationExp: string;
23
+ aggregationResLevel?: number;
24
+ };
25
+
26
+ export type CartoQuerySourceOptions = {
27
+ spatialDataColumn?: string;
28
+ sqlQuery: string;
29
+ queryParameters?: QueryParameters;
30
+ };
31
+
32
+ export type CartoTableSourceOptions = {
33
+ columns?: string[];
34
+ spatialDataColumn?: string;
35
+ tableName: string;
36
+ };
37
+
38
+ export type CartoTilesetSourceOptions = {
39
+ tableName: string;
40
+ };
41
+
42
+ export const SOURCE_DEFAULTS: CartoSourceOptionalOptions = {
43
+ apiBaseUrl: 'https://gcp-us-east1.api.carto.com',
44
+ clientId: 'deck-gl-carto',
45
+ format: 'tilejson',
46
+ formatTiles: 'binary',
47
+ headers: {}
48
+ };
49
+
50
+ export type TilejsonMapInstantiation = MapInstantiation & {
51
+ tilejson: {url: string[]};
52
+ };
53
+
54
+ export interface Tilejson {
55
+ tilejson: string;
56
+ name: string;
57
+ description: string;
58
+ version: string;
59
+ attribution: string;
60
+ scheme: string;
61
+ tiles: string[];
62
+ properties_tiles: string[];
63
+ minresolution: number;
64
+ maxresolution: number;
65
+ minzoom: number;
66
+ maxzoom: number;
67
+ bounds: [number, number, number, number];
68
+ center: [number, number, number];
69
+ vector_layers: VectorLayer[];
70
+ tilestats: Tilestats;
71
+ }
72
+
73
+ export interface Tilestats {
74
+ layerCount: number;
75
+ layers: Layer[];
76
+ }
77
+
78
+ export interface Layer {
79
+ layer: string;
80
+ count: number;
81
+ attributeCount: number;
82
+ attributes: Attribute[];
83
+ }
84
+
85
+ export interface Attribute {
86
+ attribute: string;
87
+ type: string;
88
+ }
89
+
90
+ export interface VectorLayer {
91
+ id: string;
92
+ minzoom: number;
93
+ maxzoom: number;
94
+ fields: Record<string, string>;
95
+ }
96
+
97
+ export type CartoTilejsonResult = Tilejson & {accessToken: string};
98
+ export type GeojsonResult = {type: 'FeatureCollection'; features: Feature[]};
99
+ export type JsonResult = any[];
100
+ export interface TilejsonSource<T> {
101
+ (options: T & {format?: 'tilejson'}): Promise<CartoTilejsonResult>;
102
+ }
103
+ export interface TypedSource<T> extends TilejsonSource<T> {
104
+ (options: T & {format: 'geojson'}): Promise<GeojsonResult>;
105
+ (options: T & {format: 'json'}): Promise<JsonResult>;
106
+ }
107
+
108
+ export const DEFAULT_CLIENT = 'deck-gl-carto';
109
+ export const V3_MINOR_VERSION = '3.2';
110
+ export const MAX_GET_LENGTH = 8192;
111
+
112
+ export const DEFAULT_PARAMETERS = {
113
+ client: DEFAULT_CLIENT,
114
+ v: V3_MINOR_VERSION
115
+ };
116
+
117
+ export const DEFAULT_HEADERS = {
118
+ Accept: 'application/json',
119
+ 'Content-Type': 'application/json'
120
+ };
121
+
122
+ export const TilejsonPropType = {
123
+ type: 'object' as const,
124
+ value: null as null | CartoTilejsonResult,
125
+ validate: (value: CartoTilejsonResult, propType) =>
126
+ (propType.optional && value === null) ||
127
+ (typeof value === 'object' &&
128
+ Array.isArray(value.tiles) &&
129
+ value.tiles.every(url => typeof url === 'string')),
130
+ compare: 2,
131
+ async: true
132
+ };
@@ -0,0 +1,45 @@
1
+ /* eslint-disable camelcase */
2
+ import {cartoBaseSource} from './base-source';
3
+ import {
4
+ CartoAggregationOptions,
5
+ CartoQuerySourceOptions,
6
+ CartoSourceOptions,
7
+ TilejsonSource
8
+ } from './common';
9
+
10
+ export type CartoH3QuerySourceOptions = CartoSourceOptions &
11
+ CartoQuerySourceOptions &
12
+ CartoAggregationOptions;
13
+ type UrlParameters = {
14
+ aggregationExp: string;
15
+ aggregationResLevel?: string;
16
+ geo_column?: string;
17
+ q: string;
18
+ queryParameters?: string;
19
+ };
20
+
21
+ const cartoH3QuerySource: TilejsonSource<CartoH3QuerySourceOptions> = async function (
22
+ options: CartoH3QuerySourceOptions
23
+ ): Promise<any> {
24
+ const {
25
+ aggregationExp,
26
+ aggregationResLevel = 4,
27
+ sqlQuery,
28
+ spatialDataColumn = 'h3:h3',
29
+ queryParameters
30
+ } = options;
31
+ const urlParameters: UrlParameters = {aggregationExp, q: sqlQuery};
32
+
33
+ if (aggregationResLevel) {
34
+ urlParameters.aggregationResLevel = String(aggregationResLevel);
35
+ }
36
+ if (spatialDataColumn) {
37
+ urlParameters.geo_column = spatialDataColumn;
38
+ }
39
+ if (queryParameters) {
40
+ urlParameters.queryParameters = JSON.stringify(queryParameters);
41
+ }
42
+ return cartoBaseSource<UrlParameters>('query', options, urlParameters);
43
+ };
44
+
45
+ export {cartoH3QuerySource};
@@ -0,0 +1,46 @@
1
+ /* eslint-disable camelcase */
2
+ import {cartoBaseSource} from './base-source';
3
+ import {
4
+ CartoAggregationOptions,
5
+ CartoSourceOptions,
6
+ CartoTableSourceOptions,
7
+ TilejsonSource
8
+ } from './common';
9
+
10
+ export type CartoH3TableSourceOptions = CartoSourceOptions &
11
+ CartoTableSourceOptions &
12
+ CartoAggregationOptions;
13
+
14
+ type UrlParameters = {
15
+ aggregationExp: string;
16
+ aggregationResLevel?: string;
17
+ columns?: string;
18
+ geo_column?: string;
19
+ name: string;
20
+ };
21
+
22
+ const cartoH3TableSource: TilejsonSource<CartoH3TableSourceOptions> = async function (
23
+ options: CartoH3TableSourceOptions
24
+ ): Promise<any> {
25
+ const {
26
+ aggregationExp,
27
+ aggregationResLevel = 4,
28
+ columns,
29
+ spatialDataColumn = 'h3:h3',
30
+ tableName
31
+ } = options;
32
+ const urlParameters: UrlParameters = {aggregationExp, name: tableName};
33
+
34
+ if (aggregationResLevel) {
35
+ urlParameters.aggregationResLevel = String(aggregationResLevel);
36
+ }
37
+ if (columns) {
38
+ urlParameters.columns = columns.join(',');
39
+ }
40
+ if (spatialDataColumn) {
41
+ urlParameters.geo_column = spatialDataColumn;
42
+ }
43
+ return cartoBaseSource<UrlParameters>('table', options, urlParameters);
44
+ };
45
+
46
+ export {cartoH3TableSource};
@@ -0,0 +1,16 @@
1
+ import {cartoBaseSource} from './base-source';
2
+ import {CartoSourceOptions, CartoTilesetSourceOptions, TilejsonSource} from './common';
3
+
4
+ export type CartoH3TilesetSourceOptions = CartoSourceOptions & CartoTilesetSourceOptions;
5
+ type UrlParameters = {name: string};
6
+
7
+ const cartoH3TilesetSource: TilejsonSource<CartoH3TilesetSourceOptions> = async function (
8
+ options: CartoH3TilesetSourceOptions
9
+ ): Promise<any> {
10
+ const {tableName} = options;
11
+ const urlParameters: UrlParameters = {name: tableName};
12
+
13
+ return cartoBaseSource<UrlParameters>('tileset', options, urlParameters);
14
+ };
15
+
16
+ export {cartoH3TilesetSource};
@@ -0,0 +1,32 @@
1
+ export {SOURCE_DEFAULTS} from './common';
2
+ export type {CartoTilejsonResult, GeojsonResult, JsonResult} from './common';
3
+
4
+ export {cartoH3QuerySource} from './h3-query-source';
5
+ export type {CartoH3QuerySourceOptions} from './h3-query-source';
6
+
7
+ export {cartoH3TableSource} from './h3-table-source';
8
+ export type {CartoH3TableSourceOptions} from './h3-table-source';
9
+
10
+ export {cartoH3TilesetSource} from './h3-tileset-source';
11
+ export type {CartoH3TilesetSourceOptions} from './h3-tileset-source';
12
+
13
+ export {cartoRasterSource} from './raster-source';
14
+ export type {CartoRasterSourceOptions} from './raster-source';
15
+
16
+ export {cartoQuadbinQuerySource} from './quadbin-query-source';
17
+ export type {CartoQuadbinQuerySourceOptions} from './quadbin-query-source';
18
+
19
+ export {cartoQuadbinTableSource} from './quadbin-table-source';
20
+ export type {CartoQuadbinTableSourceOptions} from './quadbin-table-source';
21
+
22
+ export {cartoQuadbinTilesetSource} from './quadbin-tileset-source';
23
+ export type {CartoQuadbinTilesetSourceOptions} from './quadbin-tileset-source';
24
+
25
+ export {cartoVectorQuerySource} from './vector-query-source';
26
+ export type {CartoVectorQuerySourceOptions} from './vector-query-source';
27
+
28
+ export {cartoVectorTableSource} from './vector-table-source';
29
+ export type {CartoVectorTableSourceOptions} from './vector-table-source';
30
+
31
+ export {cartoVectorTilesetSource} from './vector-tileset-source';
32
+ export type {CartoVectorTilesetSourceOptions} from './vector-tileset-source';
@@ -0,0 +1,46 @@
1
+ /* eslint-disable camelcase */
2
+ import {cartoBaseSource} from './base-source';
3
+ import {
4
+ CartoAggregationOptions,
5
+ CartoQuerySourceOptions,
6
+ CartoSourceOptions,
7
+ TilejsonSource
8
+ } from './common';
9
+
10
+ export type CartoQuadbinQuerySourceOptions = CartoSourceOptions &
11
+ CartoQuerySourceOptions &
12
+ CartoAggregationOptions;
13
+
14
+ type UrlParameters = {
15
+ aggregationExp: string;
16
+ aggregationResLevel?: string;
17
+ geo_column?: string;
18
+ q: string;
19
+ queryParameters?: string;
20
+ };
21
+
22
+ const cartoQuadbinQuerySource: TilejsonSource<CartoQuadbinQuerySourceOptions> = async function (
23
+ options: CartoQuadbinQuerySourceOptions
24
+ ): Promise<any> {
25
+ const {
26
+ aggregationExp,
27
+ aggregationResLevel = 6,
28
+ sqlQuery,
29
+ spatialDataColumn = 'quadbin:quadbin',
30
+ queryParameters
31
+ } = options;
32
+ const urlParameters: UrlParameters = {aggregationExp, q: sqlQuery};
33
+
34
+ if (aggregationResLevel) {
35
+ urlParameters.aggregationResLevel = String(aggregationResLevel);
36
+ }
37
+ if (spatialDataColumn) {
38
+ urlParameters.geo_column = spatialDataColumn;
39
+ }
40
+ if (queryParameters) {
41
+ urlParameters.queryParameters = JSON.stringify(queryParameters);
42
+ }
43
+ return cartoBaseSource<UrlParameters>('query', options, urlParameters);
44
+ };
45
+
46
+ export {cartoQuadbinQuerySource};
@@ -0,0 +1,46 @@
1
+ /* eslint-disable camelcase */
2
+ import {cartoBaseSource} from './base-source';
3
+ import {
4
+ CartoAggregationOptions,
5
+ CartoSourceOptions,
6
+ CartoTableSourceOptions,
7
+ TilejsonSource
8
+ } from './common';
9
+
10
+ export type CartoQuadbinTableSourceOptions = CartoSourceOptions &
11
+ CartoTableSourceOptions &
12
+ CartoAggregationOptions;
13
+
14
+ type UrlParameters = {
15
+ aggregationExp: string;
16
+ aggregationResLevel?: string;
17
+ columns?: string;
18
+ geo_column?: string;
19
+ name: string;
20
+ };
21
+
22
+ const cartoQuadbinTableSource: TilejsonSource<CartoQuadbinTableSourceOptions> = async function (
23
+ options: CartoQuadbinTableSourceOptions
24
+ ): Promise<any> {
25
+ const {
26
+ aggregationExp,
27
+ aggregationResLevel = 6,
28
+ columns,
29
+ spatialDataColumn = 'quadbin:quadbin',
30
+ tableName
31
+ } = options;
32
+ const urlParameters: UrlParameters = {aggregationExp, name: tableName};
33
+
34
+ if (aggregationResLevel) {
35
+ urlParameters.aggregationResLevel = String(aggregationResLevel);
36
+ }
37
+ if (columns) {
38
+ urlParameters.columns = columns.join(',');
39
+ }
40
+ if (spatialDataColumn) {
41
+ urlParameters.geo_column = spatialDataColumn;
42
+ }
43
+ return cartoBaseSource<UrlParameters>('table', options, urlParameters);
44
+ };
45
+
46
+ export {cartoQuadbinTableSource};
@@ -0,0 +1,16 @@
1
+ import {cartoBaseSource} from './base-source';
2
+ import {CartoSourceOptions, CartoTilesetSourceOptions, TilejsonSource} from './common';
3
+
4
+ export type CartoQuadbinTilesetSourceOptions = CartoSourceOptions & CartoTilesetSourceOptions;
5
+ type UrlParameters = {name: string};
6
+
7
+ const cartoQuadbinTilesetSource: TilejsonSource<CartoQuadbinTilesetSourceOptions> = async function (
8
+ options: CartoQuadbinTilesetSourceOptions
9
+ ): Promise<any> {
10
+ const {tableName} = options;
11
+ const urlParameters: UrlParameters = {name: tableName};
12
+
13
+ return cartoBaseSource<UrlParameters>('tileset', options, urlParameters);
14
+ };
15
+
16
+ export {cartoQuadbinTilesetSource};
@@ -0,0 +1,16 @@
1
+ import {cartoBaseSource} from './base-source';
2
+ import {CartoSourceOptions, CartoTilesetSourceOptions, TypedSource} from './common';
3
+
4
+ export type CartoRasterSourceOptions = CartoSourceOptions & CartoTilesetSourceOptions;
5
+ type UrlParameters = {name: string};
6
+
7
+ const cartoRasterSource: TypedSource<CartoRasterSourceOptions> = async function (
8
+ options: CartoRasterSourceOptions
9
+ ): Promise<any> {
10
+ const {tableName} = options;
11
+ const urlParameters: UrlParameters = {name: tableName};
12
+
13
+ return cartoBaseSource<UrlParameters>('raster', options, urlParameters);
14
+ };
15
+
16
+ export {cartoRasterSource};