@deck.gl/carto 8.7.0-alpha.1 → 8.7.0-alpha.2

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 (57) hide show
  1. package/dist/dist.dev.js +52 -91
  2. package/dist/es5/api/index.js +9 -9
  3. package/dist/es5/api/layer-map.js +72 -83
  4. package/dist/es5/api/layer-map.js.map +1 -1
  5. package/dist/es5/api/maps-api-common.js +9 -13
  6. package/dist/es5/api/maps-api-common.js.map +1 -1
  7. package/dist/es5/api/maps-client.js +98 -157
  8. package/dist/es5/api/maps-client.js.map +1 -1
  9. package/dist/es5/api/maps-v3-client.js +312 -521
  10. package/dist/es5/api/maps-v3-client.js.map +1 -1
  11. package/dist/es5/api/parseMap.js +94 -95
  12. package/dist/es5/api/parseMap.js.map +1 -1
  13. package/dist/es5/basemap.js +1 -1
  14. package/dist/es5/basemap.js.map +1 -1
  15. package/dist/es5/config.js +23 -39
  16. package/dist/es5/config.js.map +1 -1
  17. package/dist/es5/index.js +17 -17
  18. package/dist/es5/layers/carto-bqtiler-layer.js +6 -39
  19. package/dist/es5/layers/carto-bqtiler-layer.js.map +1 -1
  20. package/dist/es5/layers/carto-layer.js +130 -211
  21. package/dist/es5/layers/carto-layer.js.map +1 -1
  22. package/dist/es5/layers/carto-sql-layer.js +6 -39
  23. package/dist/es5/layers/carto-sql-layer.js.map +1 -1
  24. package/dist/es5/style/color-bins-style.js +14 -13
  25. package/dist/es5/style/color-bins-style.js.map +1 -1
  26. package/dist/es5/style/color-categories-style.js +16 -39
  27. package/dist/es5/style/color-categories-style.js.map +1 -1
  28. package/dist/es5/style/color-continuous-style.js +14 -13
  29. package/dist/es5/style/color-continuous-style.js.map +1 -1
  30. package/dist/es5/style/palette.js +15 -21
  31. package/dist/es5/style/palette.js.map +1 -1
  32. package/dist/es5/style/utils.js +6 -13
  33. package/dist/es5/style/utils.js.map +1 -1
  34. package/dist/esm/api/layer-map.js +2 -2
  35. package/dist/esm/api/layer-map.js.map +1 -1
  36. package/dist/esm/api/maps-client.js +1 -1
  37. package/dist/esm/api/maps-client.js.map +1 -1
  38. package/dist/esm/api/maps-v3-client.js +16 -6
  39. package/dist/esm/api/maps-v3-client.js.map +1 -1
  40. package/dist/esm/api/parseMap.js +2 -10
  41. package/dist/esm/api/parseMap.js.map +1 -1
  42. package/dist/esm/config.js +11 -26
  43. package/dist/esm/config.js.map +1 -1
  44. package/dist/esm/layers/carto-layer.js +7 -9
  45. package/dist/esm/layers/carto-layer.js.map +1 -1
  46. package/dist/esm/style/color-bins-style.js.map +1 -1
  47. package/dist/esm/style/color-continuous-style.js.map +1 -1
  48. package/dist.min.js +3 -3
  49. package/package.json +2 -2
  50. package/src/api/layer-map.js +2 -2
  51. package/src/api/maps-client.js +3 -7
  52. package/src/api/maps-v3-client.js +18 -7
  53. package/src/api/parseMap.js +16 -26
  54. package/src/config.js +8 -39
  55. package/src/layers/carto-layer.js +3 -5
  56. package/src/style/color-bins-style.js +1 -3
  57. package/src/style/color-continuous-style.js +1 -3
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-alpha.1",
5
+ "version": "8.7.0-alpha.2",
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },
@@ -48,5 +48,5 @@
48
48
  "@deck.gl/layers": "^8.0.0",
49
49
  "@loaders.gl/core": "^3.0.0"
50
50
  },
51
- "gitHead": "dbaa3941a41f3ddceecad4d2d2879515d97d2510"
51
+ "gitHead": "67bc5fe69149ae933a5f203724ad58f58c4a1737"
52
52
  }
@@ -117,7 +117,7 @@ function calculateDomain(data, name, scaleType) {
117
117
  // GeoJSON data type
118
118
  const values = data.features.map(({properties}) => properties[name]);
119
119
  return domainFromValues(values, scaleType);
120
- } else if (Array.isArray(data) && data[0][name]) {
120
+ } else if (Array.isArray(data) && data[0][name] !== undefined) {
121
121
  // JSON data type
122
122
  const values = data.map(properties => properties[name]);
123
123
  return domainFromValues(values, scaleType);
@@ -139,7 +139,7 @@ export function getColorAccessor({name}, scaleType, {colors}, opacity, data) {
139
139
  const scale = SCALE_FUNCS[scaleType]();
140
140
  scale.domain(calculateDomain(data, name, scaleType));
141
141
  scale.range(colors);
142
- const alpha = opacity !== undefined ? 255 * Math.pow(opacity, 1 / 2.2) : 255;
142
+ const alpha = opacity !== undefined ? Math.round(255 * Math.pow(opacity, 1 / 2.2)) : 255;
143
143
 
144
144
  const accessor = properties => {
145
145
  const rgba = rgb(scale(properties[name]));
@@ -56,7 +56,7 @@ export async function getDataV2({type, source, credentials}) {
56
56
 
57
57
  default:
58
58
  throw new Error(
59
- `Invalid maps API version. It shoud be ${API_VERSIONS.V1} or ${API_VERSIONS.V2}`
59
+ `Invalid maps API version. It should be ${API_VERSIONS.V1} or ${API_VERSIONS.V2}`
60
60
  );
61
61
  }
62
62
  }
@@ -95,15 +95,11 @@ function dealWithError({response, json, credentials}) {
95
95
  switch (response.status) {
96
96
  case 401:
97
97
  throw new Error(
98
- `Unauthorized access to Maps API: invalid combination of user ('${
99
- credentials.username
100
- }') and apiKey ('${credentials.apiKey}')`
98
+ `Unauthorized access to Maps API: invalid combination of user ('${credentials.username}') and apiKey ('${credentials.apiKey}')`
101
99
  );
102
100
  case 403:
103
101
  throw new Error(
104
- `Unauthorized access to dataset: the provided apiKey('${
105
- credentials.apiKey
106
- }') doesn't provide access to the requested data`
102
+ `Unauthorized access to dataset: the provided apiKey('${credentials.apiKey}') doesn't provide access to the requested data`
107
103
  );
108
104
 
109
105
  default:
@@ -239,7 +239,7 @@ export async function getData({type, source, connection, credentials, geoColumn,
239
239
  return layerData.data;
240
240
  }
241
241
 
242
- /* global setInterval, URLSearchParams */
242
+ /* global clearInterval, setInterval, URLSearchParams */
243
243
  async function _fetchMapDataset(dataset, accessToken) {
244
244
  // First fetch metadata
245
245
  const {connectionName: connection, source, type} = dataset;
@@ -268,10 +268,14 @@ async function fillInMapDatasets({datasets, publicToken}) {
268
268
  return await Promise.all(promises);
269
269
  }
270
270
 
271
- export async function fetchMap({mapId, credentials, autoRefresh, onNewData}) {
272
- const localCreds = {...getDefaultCredentials(), ...credentials};
271
+ export async function fetchMap({cartoMapId, credentials, autoRefresh, onNewData}) {
272
+ const defaultCredentials = getDefaultCredentials();
273
+ const localCreds = {
274
+ ...(defaultCredentials.apiVersion === API_VERSIONS.V3 && defaultCredentials),
275
+ ...credentials
276
+ };
273
277
 
274
- log.assert(mapId, 'Must define map id');
278
+ log.assert(cartoMapId, `Must define CARTO map id: fetchMap({cartoMapId: 'XXXX-XXXX-XXXX'})`);
275
279
 
276
280
  log.assert(localCreds.apiVersion === API_VERSIONS.V3, 'Method only available for v3');
277
281
  log.assert(localCreds.apiBaseUrl, 'Must define apiBaseUrl');
@@ -285,21 +289,28 @@ export async function fetchMap({mapId, credentials, autoRefresh, onNewData}) {
285
289
  log.assert(autoRefresh > 0, '`autoRefresh` must be a positive number');
286
290
  }
287
291
 
288
- const url = `${localCreds.mapsUrl}/public/${mapId}`;
292
+ const url = `${localCreds.mapsUrl}/public/${cartoMapId}`;
289
293
  const map = await request({url});
290
294
 
291
295
  // Periodically check if the data has changed. Note that this
292
296
  // will not update when a map is published.
297
+ let stopAutoRefresh;
293
298
  if (autoRefresh) {
294
- setInterval(async () => {
299
+ const intervalId = setInterval(async () => {
295
300
  const changed = await fillInMapDatasets(map);
296
301
  if (changed.some(v => v === true)) {
297
302
  onNewData(parseMap(map));
298
303
  }
299
304
  }, autoRefresh * 1000);
305
+ stopAutoRefresh = () => {
306
+ clearInterval(intervalId);
307
+ };
300
308
  }
301
309
 
302
310
  // Mutates map.datasets so that dataset.data contains data
303
311
  await fillInMapDatasets(map);
304
- return parseMap(map);
312
+ return {
313
+ ...parseMap(map),
314
+ ...{stopAutoRefresh}
315
+ };
305
316
  }
@@ -20,7 +20,7 @@ export function parseMap(json) {
20
20
  description: json.description,
21
21
  createdAt: json.createdAt,
22
22
  updatedAt: json.updatedAt,
23
- mapState,
23
+ initialViewState: mapState,
24
24
  mapStyle,
25
25
  layers: extractTextLayers(layers.reverse()).map(({id, type, config, visualChannels}) => {
26
26
  log.assert(type in LAYER_MAP, `Unsupported layer type: ${type}`);
@@ -53,17 +53,19 @@ function extractTextLayers(layers) {
53
53
  {id, config: configRest, ...rest},
54
54
 
55
55
  // One layer per valid text label, with full opacity
56
- ...textLabel.filter(t => t.field).map(t => {
57
- return {
58
- id: `id-label-${t.field.name}`,
59
- config: {
60
- textLabel: t,
61
- ...configRest,
62
- visConfig: {...configRest.visConfig, opacity: 1}
63
- },
64
- ...rest
65
- };
66
- })
56
+ ...textLabel
57
+ .filter(t => t.field)
58
+ .map(t => {
59
+ return {
60
+ id: `${id}-label-${t.field.name}`,
61
+ config: {
62
+ textLabel: t,
63
+ ...configRest,
64
+ visConfig: {...configRest.visConfig, opacity: 1}
65
+ },
66
+ ...rest
67
+ };
68
+ })
67
69
  ];
68
70
  })
69
71
  );
@@ -98,12 +100,6 @@ function createInteractionProps(interactionConfig) {
98
100
  }
99
101
 
100
102
  function mapProps(source, target, mapping) {
101
- if (Array.isArray(source)) {
102
- source = source[0];
103
- }
104
- if (!source) {
105
- return;
106
- }
107
103
  for (const sourceKey in mapping) {
108
104
  const sourceValue = source[sourceKey];
109
105
  const targetKey = mapping[sourceKey];
@@ -129,14 +125,8 @@ function createStyleProps(config, mapping) {
129
125
 
130
126
  /* eslint-disable complexity */
131
127
  function createChannelProps(visualChannels, type, config, data) {
132
- const {
133
- colorField,
134
- colorScale,
135
- sizeField,
136
- sizeScale,
137
- strokeColorField,
138
- strokeColorScale
139
- } = visualChannels;
128
+ const {colorField, colorScale, sizeField, sizeScale, strokeColorField, strokeColorScale} =
129
+ visualChannels;
140
130
  let {heightField, heightScale} = visualChannels;
141
131
  if (type === 'hexagonId') {
142
132
  heightField = sizeField;
package/src/config.js CHANGED
@@ -1,60 +1,29 @@
1
- import {API_VERSIONS, DEFAULT_MAPS_URL_FORMAT} from './api/maps-api-common';
1
+ import {API_VERSIONS} from './api/maps-api-common';
2
2
 
3
3
  export const defaultClassicCredentials = {
4
- username: 'public',
5
4
  apiKey: 'default_public',
6
5
  region: 'us',
7
- mapsUrl: null
6
+ username: 'public'
8
7
  };
9
8
 
10
- const defaultCloudNativeCredentials = {
11
- accessToken: null,
12
- apiBaseUrl: null,
13
- mapsUrl: null
9
+ export const defaultCloudNativeCredentials = {
10
+ apiBaseUrl: 'https://gcp-us-east1.api.carto.com'
14
11
  };
15
12
 
16
13
  let credentials = {};
17
14
 
18
15
  setDefaultCredentials({});
19
16
 
20
- export function setDefaultCredentials(opts) {
21
- const apiVersion = opts.apiVersion || API_VERSIONS.V2;
17
+ export function setDefaultCredentials({apiVersion, ...rest}) {
18
+ apiVersion = apiVersion || API_VERSIONS.V3;
22
19
 
23
20
  switch (apiVersion) {
24
21
  case API_VERSIONS.V1:
25
- opts.mapsUrl = opts.mapsUrl || DEFAULT_MAPS_URL_FORMAT[apiVersion];
26
- credentials = {
27
- apiVersion,
28
- ...defaultClassicCredentials,
29
- ...opts
30
- };
31
- break;
32
-
33
22
  case API_VERSIONS.V2:
34
- opts.mapsUrl = opts.mapsUrl || DEFAULT_MAPS_URL_FORMAT[apiVersion];
35
- credentials = {
36
- apiVersion,
37
- ...defaultClassicCredentials,
38
- ...opts
39
- };
40
-
23
+ credentials = {apiVersion, ...defaultClassicCredentials, ...rest};
41
24
  break;
42
25
  case API_VERSIONS.V3:
43
- if (!opts.apiBaseUrl) {
44
- throw new Error(
45
- `API version ${
46
- API_VERSIONS.V3
47
- } requires to define apiBaseUrl at credentials. Go to https://app.carto.com to get your apiBaseUrl.`
48
- );
49
- }
50
-
51
- const apiBaseUrl = opts.apiBaseUrl || defaultCloudNativeCredentials.apiBaseUrl;
52
- opts.mapsUrl = opts.mapsUrl || buildMapsUrlFromBase(apiBaseUrl);
53
- credentials = {
54
- apiVersion,
55
- ...defaultCloudNativeCredentials,
56
- ...opts
57
- };
26
+ credentials = {apiVersion, ...defaultCloudNativeCredentials, ...rest};
58
27
  break;
59
28
  default:
60
29
  throw new Error(`Invalid API version ${apiVersion}. Use API_VERSIONS enum.`);
@@ -99,7 +99,9 @@ export default class CartoLayer extends CompositeLayer {
99
99
 
100
100
  let data;
101
101
 
102
- if (apiVersion === API_VERSIONS.V3) {
102
+ if (apiVersion === API_VERSIONS.V1 || apiVersion === API_VERSIONS.V2) {
103
+ data = await getDataV2({type, source, credentials});
104
+ } else {
103
105
  data = await getData({
104
106
  type,
105
107
  source,
@@ -108,10 +110,6 @@ export default class CartoLayer extends CompositeLayer {
108
110
  geoColumn,
109
111
  columns
110
112
  });
111
- } else if (apiVersion === API_VERSIONS.V1 || apiVersion === API_VERSIONS.V2) {
112
- data = await getDataV2({type, source, credentials});
113
- } else {
114
- log.assert(`Unknow apiVersion ${apiVersion}. Use API_VERSIONS enum.`);
115
113
  }
116
114
 
117
115
  this.setState({data, apiVersion});
@@ -12,9 +12,7 @@ export default function colorBins({
12
12
 
13
13
  const palette = typeof colors === 'string' ? getPalette(colors, domain.length) : colors;
14
14
 
15
- const color = scaleThreshold()
16
- .domain(domain)
17
- .range(palette);
15
+ const color = scaleThreshold().domain(domain).range(palette);
18
16
 
19
17
  return d => {
20
18
  const value = getAttrValue(attr, d);
@@ -11,9 +11,7 @@ export default function colorContinuous({
11
11
  assert(Array.isArray(domain), 'Expected "domain" to be an array of numbers');
12
12
 
13
13
  const palette = typeof colors === 'string' ? getPalette(colors) : colors;
14
- const color = scaleLinear()
15
- .domain(domain)
16
- .range(palette);
14
+ const color = scaleLinear().domain(domain).range(palette);
17
15
 
18
16
  return d => {
19
17
  const value = getAttrValue(attr, d);