@deck.gl/carto 8.7.0-beta.2 → 8.7.0-beta.6

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 (99) hide show
  1. package/dist/dist.dev.js +1425 -306
  2. package/dist/es5/api/index.js +6 -0
  3. package/dist/es5/api/index.js.map +1 -1
  4. package/dist/es5/api/layer-map.js +32 -17
  5. package/dist/es5/api/layer-map.js.map +1 -1
  6. package/dist/es5/api/maps-api-common.js +21 -1
  7. package/dist/es5/api/maps-api-common.js.map +1 -1
  8. package/dist/es5/api/maps-client.js +15 -18
  9. package/dist/es5/api/maps-client.js.map +1 -1
  10. package/dist/es5/api/maps-v3-client.js +241 -181
  11. package/dist/es5/api/maps-v3-client.js.map +1 -1
  12. package/dist/es5/api/parseMap.js +9 -12
  13. package/dist/es5/api/parseMap.js.map +1 -1
  14. package/dist/es5/basemap.js +7 -7
  15. package/dist/es5/basemap.js.map +1 -1
  16. package/dist/es5/config.js.map +1 -1
  17. package/dist/es5/index.js +15 -1
  18. package/dist/es5/index.js.map +1 -1
  19. package/dist/es5/layers/carto-layer.js +27 -16
  20. package/dist/es5/layers/carto-layer.js.map +1 -1
  21. package/dist/es5/layers/{carto-dynamic-tile-layer.js → carto-tile-layer.js} +79 -32
  22. package/dist/es5/layers/carto-tile-layer.js.map +1 -0
  23. package/dist/es5/layers/schema/carto-tile.js +197 -0
  24. package/dist/es5/layers/schema/carto-tile.js.map +1 -0
  25. package/dist/es5/style/color-bins-style.js +1 -1
  26. package/dist/es5/style/color-bins-style.js.map +1 -1
  27. package/dist/es5/style/color-categories-style.js +1 -1
  28. package/dist/es5/style/color-categories-style.js.map +1 -1
  29. package/dist/es5/style/color-continuous-style.js +1 -1
  30. package/dist/es5/style/color-continuous-style.js.map +1 -1
  31. package/dist/es5/style/palette.js +1 -6
  32. package/dist/es5/style/palette.js.map +1 -1
  33. package/dist/es5/style/utils.js +2 -6
  34. package/dist/es5/style/utils.js.map +1 -1
  35. package/dist/es5/utils.js +13 -0
  36. package/dist/es5/utils.js.map +1 -0
  37. package/dist/esm/api/index.js +1 -1
  38. package/dist/esm/api/index.js.map +1 -1
  39. package/dist/esm/api/layer-map.js +28 -12
  40. package/dist/esm/api/layer-map.js.map +1 -1
  41. package/dist/esm/api/maps-api-common.js +19 -0
  42. package/dist/esm/api/maps-api-common.js.map +1 -1
  43. package/dist/esm/api/maps-client.js +6 -10
  44. package/dist/esm/api/maps-client.js.map +1 -1
  45. package/dist/esm/api/maps-v3-client.js +73 -38
  46. package/dist/esm/api/maps-v3-client.js.map +1 -1
  47. package/dist/esm/api/parseMap.js +9 -8
  48. package/dist/esm/api/parseMap.js.map +1 -1
  49. package/dist/esm/basemap.js +7 -7
  50. package/dist/esm/basemap.js.map +1 -1
  51. package/dist/esm/config.js.map +1 -1
  52. package/dist/esm/index.js +3 -2
  53. package/dist/esm/index.js.map +1 -1
  54. package/dist/esm/layers/carto-layer.js +25 -13
  55. package/dist/esm/layers/carto-layer.js.map +1 -1
  56. package/dist/esm/layers/carto-tile-layer.js +141 -0
  57. package/dist/esm/layers/carto-tile-layer.js.map +1 -0
  58. package/dist/esm/layers/schema/carto-tile.js +190 -0
  59. package/dist/esm/layers/schema/carto-tile.js.map +1 -0
  60. package/dist/esm/style/color-bins-style.js +1 -1
  61. package/dist/esm/style/color-bins-style.js.map +1 -1
  62. package/dist/esm/style/color-categories-style.js +1 -1
  63. package/dist/esm/style/color-categories-style.js.map +1 -1
  64. package/dist/esm/style/color-continuous-style.js +1 -1
  65. package/dist/esm/style/color-continuous-style.js.map +1 -1
  66. package/dist/esm/style/palette.js +1 -6
  67. package/dist/esm/style/palette.js.map +1 -1
  68. package/dist/esm/style/utils.js +2 -6
  69. package/dist/esm/style/utils.js.map +1 -1
  70. package/dist/esm/utils.js +5 -0
  71. package/dist/esm/utils.js.map +1 -0
  72. package/dist.min.js +14 -14
  73. package/package.json +10 -3
  74. package/src/api/{index.js → index.ts} +1 -1
  75. package/src/api/{layer-map.js → layer-map.ts} +50 -23
  76. package/src/api/maps-api-common.ts +76 -0
  77. package/src/api/{maps-client.js → maps-client.ts} +55 -20
  78. package/src/api/{maps-v3-client.js → maps-v3-client.ts} +145 -57
  79. package/src/api/{parseMap.js → parseMap.ts} +8 -7
  80. package/src/basemap.ts +10 -0
  81. package/src/{config.js → config.ts} +22 -6
  82. package/src/{index.js → index.ts} +3 -1
  83. package/src/layers/carto-layer.js +30 -19
  84. package/src/layers/carto-tile-layer.js +121 -0
  85. package/src/layers/schema/carto-tile.js +195 -0
  86. package/src/style/color-bins-style.ts +26 -0
  87. package/src/style/{color-categories-style.js → color-categories-style.ts} +10 -4
  88. package/src/style/color-continuous-style.ts +25 -0
  89. package/src/style/{palette.js → palette.ts} +18 -15
  90. package/src/style/{utils.js → utils.ts} +7 -10
  91. package/src/utils.ts +5 -0
  92. package/dist/es5/layers/carto-dynamic-tile-layer.js.map +0 -1
  93. package/dist/esm/layers/carto-dynamic-tile-layer.js +0 -97
  94. package/dist/esm/layers/carto-dynamic-tile-layer.js.map +0 -1
  95. package/src/api/maps-api-common.js +0 -34
  96. package/src/basemap.js +0 -10
  97. package/src/layers/carto-dynamic-tile-layer.js +0 -86
  98. package/src/style/color-bins-style.js +0 -21
  99. package/src/style/color-continuous-style.js +0 -20
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@deck.gl/carto",
3
3
  "description": "CARTO official integration with Deck.gl. Build geospatial applications using CARTO and Deck.gl.",
4
4
  "license": "MIT",
5
- "version": "8.7.0-beta.2",
5
+ "version": "8.7.0-beta.6",
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },
@@ -35,13 +35,20 @@
35
35
  "@loaders.gl/loader-utils": "^3.1.5",
36
36
  "@loaders.gl/mvt": "^3.1.5",
37
37
  "@loaders.gl/tiles": "^3.1.5",
38
+ "@luma.gl/constants": "^8.5.10",
38
39
  "@math.gl/web-mercator": "^3.5.7",
39
40
  "cartocolor": "^4.0.2",
40
41
  "d3-array": "^2.8.0",
41
42
  "d3-color": "^2.0.0",
42
43
  "d3-format": "^2.0.0",
43
44
  "d3-scale": "^3.2.3",
44
- "moment-timezone": "^0.5.33"
45
+ "moment-timezone": "^0.5.33",
46
+ "pbf": "^3.2.1"
47
+ },
48
+ "devDependencies": {
49
+ "@types/d3-array": "^3.0.2",
50
+ "@types/d3-color": "^1.4.2",
51
+ "@types/d3-scale": "^3.0.0"
45
52
  },
46
53
  "peerDependencies": {
47
54
  "@deck.gl/core": "^8.0.0",
@@ -49,5 +56,5 @@
49
56
  "@deck.gl/layers": "^8.0.0",
50
57
  "@loaders.gl/core": "^3.1.5"
51
58
  },
52
- "gitHead": "a507df6d9a5d9d9bba3a97ac93246b6ed0e5dd43"
59
+ "gitHead": "d6eefe2e0992999416b2362340f86402b1f25b33"
53
60
  }
@@ -1,3 +1,3 @@
1
- export {FORMATS, MAP_TYPES, API_VERSIONS} from './maps-api-common';
1
+ export {FORMATS, TILE_FORMATS, MAP_TYPES, API_VERSIONS} from './maps-api-common';
2
2
  export {getDataV2, CONNECTIONS} from './maps-client';
3
3
  export {fetchLayerData, fetchMap, getData, mapInstantiation} from './maps-v3-client';
@@ -11,9 +11,11 @@ import {
11
11
  } from 'd3-scale';
12
12
  import {format as d3Format} from 'd3-format';
13
13
  import moment from 'moment-timezone';
14
- import {log} from '@deck.gl/core';
15
14
  import {H3HexagonLayer, MVTLayer} from '@deck.gl/geo-layers';
16
15
  import {GeoJsonLayer} from '@deck.gl/layers';
16
+ import CartoTileLayer from '../layers/carto-tile-layer';
17
+ import {TILE_FORMATS} from './maps-api-common';
18
+ import {assert} from '../utils';
17
19
 
18
20
  const SCALE_FUNCS = {
19
21
  linear: scaleLinear,
@@ -24,6 +26,7 @@ const SCALE_FUNCS = {
24
26
  quantize: scaleQuantize,
25
27
  sqrt: scaleSqrt
26
28
  };
29
+ export type SCALE_TYPE = keyof typeof SCALE_FUNCS;
27
30
 
28
31
  // Kepler -> Deck.gl
29
32
  const sharedPropMap = {
@@ -63,9 +66,16 @@ function mergePropMaps(a, b) {
63
66
  return {...a, ...b, visConfig: {...a.visConfig, ...b.visConfig}};
64
67
  }
65
68
 
66
- export function getLayer(type, config) {
67
- const hexagonId = config.columns?.hex_id;
69
+ export function getLayer(
70
+ type: string,
71
+ config,
72
+ dataset
73
+ ): {Layer: any; propMap: any; defaultProps: any} {
74
+ if (type === 'mvt' || type === 'tileset') {
75
+ return getTileLayer(dataset);
76
+ }
68
77
 
78
+ const hexagonId = config.columns?.hex_id;
69
79
  const layer = {
70
80
  point: {
71
81
  Layer: GeoJsonLayer,
@@ -85,25 +95,36 @@ export function getLayer(type, config) {
85
95
  visConfig: {coverage: 'coverage', elevationScale: 'elevationScale'}
86
96
  }),
87
97
  defaultProps: {...defaultProps, getHexagon: d => d[hexagonId]}
88
- },
89
- mvt: {
90
- Layer: MVTLayer,
91
- propMap: sharedPropMap,
92
- defaultProps: {
93
- ...defaultProps,
94
- pointRadiusScale: 0.3,
95
- lineWidthScale: 2,
96
- uniqueIdProperty: 'geoid'
97
- }
98
98
  }
99
99
  }[type];
100
100
 
101
- log.assert(layer, `Unsupported layer type: ${type}`);
102
-
101
+ assert(layer, `Unsupported layer type: ${type}`);
103
102
  return layer;
104
103
  }
105
104
 
106
- function domainFromAttribute(attribute, scaleType) {
105
+ function getTileLayer(dataset) {
106
+ const {
107
+ data: {
108
+ tiles: [tileUrl]
109
+ }
110
+ } = dataset;
111
+ /* global URL */
112
+ const formatTiles = new URL(tileUrl).searchParams.get('formatTiles') || TILE_FORMATS.MVT;
113
+
114
+ return {
115
+ Layer: formatTiles === TILE_FORMATS.MVT ? MVTLayer : CartoTileLayer,
116
+ propMap: sharedPropMap,
117
+ defaultProps: {
118
+ ...defaultProps,
119
+ pointRadiusScale: 0.3,
120
+ lineWidthScale: 2,
121
+ uniqueIdProperty: 'geoid',
122
+ formatTiles
123
+ }
124
+ };
125
+ }
126
+
127
+ function domainFromAttribute(attribute, scaleType: SCALE_TYPE) {
107
128
  if (scaleType === 'ordinal' || scaleType === 'point') {
108
129
  return attribute.categories.map(c => c.category).filter(c => c !== undefined && c !== null);
109
130
  }
@@ -115,13 +136,13 @@ function domainFromAttribute(attribute, scaleType) {
115
136
  return [min, attribute.max];
116
137
  }
117
138
 
118
- function domainFromValues(values, scaleType) {
139
+ function domainFromValues(values, scaleType: SCALE_TYPE) {
119
140
  if (scaleType === 'ordinal') {
120
141
  return [...new Set(values)].sort();
121
142
  } else if (scaleType === 'quantile') {
122
143
  return values.sort((a, b) => a - b);
123
144
  } else if (scaleType === 'log') {
124
- const [d0, d1] = extent(values);
145
+ const [d0, d1] = extent(values as number[]);
125
146
  return [d0 === 0 ? 1e-5 : d0, d1];
126
147
  }
127
148
  return extent(values);
@@ -155,8 +176,14 @@ function normalizeAccessor(accessor, data) {
155
176
  return accessor;
156
177
  }
157
178
 
158
- export function getColorAccessor({name}, scaleType, {colors}, opacity, data) {
159
- const scale = SCALE_FUNCS[scaleType]();
179
+ export function getColorAccessor(
180
+ {name},
181
+ scaleType: SCALE_TYPE,
182
+ {colors},
183
+ opacity: number | undefined,
184
+ data: any
185
+ ) {
186
+ const scale = SCALE_FUNCS[scaleType as any]();
160
187
  scale.domain(calculateDomain(data, name, scaleType));
161
188
  scale.range(colors);
162
189
  const alpha = opacity !== undefined ? Math.round(255 * Math.pow(opacity, 1 / 2.2)) : 255;
@@ -168,8 +195,8 @@ export function getColorAccessor({name}, scaleType, {colors}, opacity, data) {
168
195
  return normalizeAccessor(accessor, data);
169
196
  }
170
197
 
171
- export function getSizeAccessor({name}, scaleType, range, data) {
172
- const scale = SCALE_FUNCS[scaleType]();
198
+ export function getSizeAccessor({name}, scaleType: SCALE_TYPE, range: Iterable<Range>, data: any) {
199
+ const scale = SCALE_FUNCS[scaleType as any]();
173
200
  scale.domain(calculateDomain(data, name, scaleType));
174
201
  scale.range(range);
175
202
 
@@ -179,7 +206,7 @@ export function getSizeAccessor({name}, scaleType, range, data) {
179
206
  return normalizeAccessor(accessor, data);
180
207
  }
181
208
 
182
- const FORMATS = {
209
+ const FORMATS: Record<string, (value: any) => string> = {
183
210
  date: s => moment.utc(s).format('MM/DD/YY HH:mm:ssa'),
184
211
  integer: d3Format('i'),
185
212
  float: d3Format('.5f'),
@@ -0,0 +1,76 @@
1
+ export const DEFAULT_USER_COMPONENT_IN_URL = '{user}';
2
+ export const DEFAULT_REGION_COMPONENT_IN_URL = '{region}';
3
+
4
+ export type ValuesOf<T extends {}> = T[keyof T];
5
+ export const API_VERSIONS = {
6
+ V1: 'v1',
7
+ V2: 'v2',
8
+ V3: 'v3'
9
+ } as const;
10
+ export type ApiVersion = ValuesOf<typeof API_VERSIONS>;
11
+
12
+ export const DEFAULT_MAPS_URL_FORMAT = {
13
+ [API_VERSIONS.V1]: `https://${DEFAULT_USER_COMPONENT_IN_URL}.carto.com/api/v1/map`,
14
+ [API_VERSIONS.V2]: `https://maps-api-v2.${DEFAULT_REGION_COMPONENT_IN_URL}.carto.com/user/${DEFAULT_USER_COMPONENT_IN_URL}`
15
+ } as const;
16
+
17
+ export const MAP_TYPES = {
18
+ QUERY: 'query',
19
+ TABLE: 'table',
20
+ TILESET: 'tileset'
21
+ } as const;
22
+ export type MapType = ValuesOf<typeof MAP_TYPES>;
23
+
24
+ // AVAILABLE FORMATS
25
+ export const FORMATS = {
26
+ GEOJSON: 'geojson',
27
+ NDJSON: 'ndjson',
28
+ TILEJSON: 'tilejson',
29
+ JSON: 'json'
30
+ } as const;
31
+ export type Format = ValuesOf<typeof FORMATS>;
32
+
33
+ // AVAILABLE FORMATS FOR TILES
34
+ export const TILE_FORMATS = {
35
+ MVT: 'mvt',
36
+ GEOJSON: 'geojson',
37
+ BINARY: 'binary'
38
+ } as const;
39
+ export type TileFormat = ValuesOf<typeof TILE_FORMATS>;
40
+
41
+ export enum SchemaFieldType {
42
+ Number = 'number',
43
+ Bigint = 'bigint',
44
+ String = 'string',
45
+ Geometry = 'geometry',
46
+ Timestamp = 'timestamp',
47
+ Object = 'object',
48
+ Boolean = 'boolean',
49
+ Variant = 'variant',
50
+ Unknown = 'unknown'
51
+ }
52
+ export interface SchemaField {
53
+ name: string;
54
+ type: SchemaFieldType; // Field type in the CARTO stack, common for all providers
55
+ }
56
+
57
+ export interface MapInstantiation extends MapInstantiationFormats {
58
+ nrows: number;
59
+ size?: number;
60
+ schema?: SchemaField[];
61
+ }
62
+
63
+ type MapInstantiationFormats = Record<
64
+ Format,
65
+ {
66
+ url: string[];
67
+ error?: any;
68
+ }
69
+ >;
70
+
71
+ /**
72
+ * Simple encode parameter
73
+ */
74
+ export function encodeParameter(name: string, value: string | boolean | number): string {
75
+ return `${name}=${encodeURIComponent(value)}`;
76
+ }
@@ -1,13 +1,19 @@
1
1
  /**
2
2
  * Maps API Client for Maps API v1 and Maps API v2
3
3
  */
4
- import {defaultClassicCredentials, getDefaultCredentials} from '../config';
4
+ import {
5
+ ClassicCredentials,
6
+ defaultClassicCredentials,
7
+ defaultCloudNativeCredentials,
8
+ getDefaultCredentials
9
+ } from '../config';
5
10
  import {
6
11
  API_VERSIONS,
7
12
  DEFAULT_MAPS_URL_FORMAT,
8
13
  DEFAULT_REGION_COMPONENT_IN_URL,
9
14
  DEFAULT_USER_COMPONENT_IN_URL,
10
15
  encodeParameter,
16
+ MapType,
11
17
  MAP_TYPES
12
18
  } from './maps-api-common';
13
19
 
@@ -22,24 +28,29 @@ const TILE_EXTENT = 4096;
22
28
  /**
23
29
  * Obtain a TileJson from Maps API v1 and v2
24
30
  */
25
- export async function getDataV2({type, source, credentials}) {
31
+ export async function getDataV2({
32
+ type,
33
+ source,
34
+ credentials
35
+ }: {
36
+ type: MapType;
37
+ source: string;
38
+ credentials?: Partial<ClassicCredentials>;
39
+ }) {
26
40
  const defaultCredentials = getDefaultCredentials();
27
- const apiVersion = (credentials && credentials.apiVersion) || defaultCredentials.apiVersion;
41
+ const apiVersion = credentials?.apiVersion || defaultCredentials.apiVersion;
28
42
  // Only pick up default credentials if they have been defined for
29
43
  // correct API version
30
44
  const localCreds = {
31
- ...defaultClassicCredentials,
45
+ ...(apiVersion === API_VERSIONS.V3 ? defaultCloudNativeCredentials : defaultClassicCredentials),
46
+ mapsUrl: DEFAULT_MAPS_URL_FORMAT[apiVersion],
32
47
  ...(defaultCredentials.apiVersion === apiVersion && defaultCredentials),
33
48
  ...credentials
34
- };
35
-
36
- if (!localCreds.mapsUrl) {
37
- localCreds.mapsUrl = DEFAULT_MAPS_URL_FORMAT[apiVersion];
38
- }
49
+ } as unknown as Required<ClassicCredentials>;
39
50
 
40
- let url;
51
+ let url: string;
41
52
 
42
- const connection = type === 'tileset' ? CONNECTIONS.BIGQUERY : CONNECTIONS.CARTO;
53
+ const connection = type === MAP_TYPES.TILESET ? CONNECTIONS.BIGQUERY : CONNECTIONS.CARTO;
43
54
 
44
55
  switch (apiVersion) {
45
56
  case API_VERSIONS.V1:
@@ -64,12 +75,11 @@ export async function getDataV2({type, source, credentials}) {
64
75
  /**
65
76
  * Request against Maps API
66
77
  */
67
- async function request({url, credentials}) {
78
+ async function request({url, credentials}: {url: string; credentials: ClassicCredentials}) {
68
79
  let response;
69
80
 
70
81
  try {
71
82
  /* global fetch */
72
- /* eslint no-undef: "error" */
73
83
  response = await fetch(url, {
74
84
  headers: {
75
85
  Accept: 'application/json'
@@ -91,7 +101,15 @@ async function request({url, credentials}) {
91
101
  /**
92
102
  * Display proper message from Maps API error
93
103
  */
94
- function dealWithError({response, json, credentials}) {
104
+ function dealWithError({
105
+ response,
106
+ json,
107
+ credentials
108
+ }: {
109
+ response: Response;
110
+ json: any;
111
+ credentials: ClassicCredentials;
112
+ }) {
95
113
  switch (response.status) {
96
114
  case 401:
97
115
  throw new Error(
@@ -109,22 +127,38 @@ function dealWithError({response, json, credentials}) {
109
127
  }
110
128
  }
111
129
 
112
- function initURLParameters(credentials) {
130
+ function initURLParameters(credentials: ClassicCredentials): string[] {
113
131
  const encodedApiKey = encodeParameter('api_key', credentials.apiKey);
114
- const encodedClient = encodeParameter('client', `deck-gl-carto`);
132
+ const encodedClient = encodeParameter('client', 'deck-gl-carto');
115
133
  return [encodedApiKey, encodedClient];
116
134
  }
117
135
 
118
136
  /**
119
137
  * Build a URL with all required parameters
120
138
  */
121
- function buildURLMapsAPIv1({mapConfig, credentials}) {
139
+ function buildURLMapsAPIv1({
140
+ mapConfig,
141
+ credentials
142
+ }: {
143
+ mapConfig: unknown;
144
+ credentials: Required<ClassicCredentials>;
145
+ }): string {
122
146
  const parameters = initURLParameters(credentials);
123
147
  const cfg = JSON.stringify(mapConfig);
124
148
  return `${mapsUrl(credentials)}?${parameters.join('&')}&${encodeParameter('config', cfg)}`;
125
149
  }
126
150
 
127
- function buildURLMapsAPIv2({connection, type, source, credentials}) {
151
+ function buildURLMapsAPIv2({
152
+ connection,
153
+ type,
154
+ source,
155
+ credentials
156
+ }: {
157
+ connection: string;
158
+ type: MapType;
159
+ source: string;
160
+ credentials: Required<ClassicCredentials>;
161
+ }): string {
128
162
  const parameters = initURLParameters(credentials);
129
163
  // Query type is mapped to 'sql' at maps api v1
130
164
  const mapsApiType = type === MAP_TYPES.QUERY ? 'sql' : type;
@@ -136,13 +170,13 @@ function buildURLMapsAPIv2({connection, type, source, credentials}) {
136
170
  /**
137
171
  * Prepare a url valid for the specified user
138
172
  */
139
- function mapsUrl(credentials) {
173
+ function mapsUrl(credentials: Required<ClassicCredentials>) {
140
174
  return credentials.mapsUrl
141
175
  .replace(DEFAULT_USER_COMPONENT_IN_URL, credentials.username)
142
176
  .replace(DEFAULT_REGION_COMPONENT_IN_URL, credentials.region);
143
177
  }
144
178
 
145
- function createMapConfig(sql) {
179
+ function createMapConfig(sql: string) {
146
180
  return {
147
181
  version: '1.3.1',
148
182
  buffersize: {
@@ -153,6 +187,7 @@ function createMapConfig(sql) {
153
187
  type: 'mapnik',
154
188
  options: {
155
189
  sql,
190
+ // eslint-disable-next-line camelcase
156
191
  vector_extent: TILE_EXTENT
157
192
  }
158
193
  }