@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/dist/dist.dev.js CHANGED
@@ -33576,7 +33576,7 @@ function calculateDomain(data, name, scaleType) {
33576
33576
  // GeoJSON data type
33577
33577
  const values = data.features.map(({properties}) => properties[name]);
33578
33578
  return domainFromValues(values, scaleType);
33579
- } else if (Array.isArray(data) && data[0][name]) {
33579
+ } else if (Array.isArray(data) && data[0][name] !== undefined) {
33580
33580
  // JSON data type
33581
33581
  const values = data.map(properties => properties[name]);
33582
33582
  return domainFromValues(values, scaleType);
@@ -33598,7 +33598,7 @@ function getColorAccessor({name}, scaleType, {colors}, opacity, data) {
33598
33598
  const scale = SCALE_FUNCS[scaleType]();
33599
33599
  scale.domain(calculateDomain(data, name, scaleType));
33600
33600
  scale.range(colors);
33601
- const alpha = opacity !== undefined ? 255 * Math.pow(opacity, 1 / 2.2) : 255;
33601
+ const alpha = opacity !== undefined ? Math.round(255 * Math.pow(opacity, 1 / 2.2)) : 255;
33602
33602
 
33603
33603
  const accessor = properties => {
33604
33604
  const rgba = Object(d3_color__WEBPACK_IMPORTED_MODULE_1__["rgb"])(scale(properties[name]));
@@ -33773,7 +33773,7 @@ async function getDataV2({type, source, credentials}) {
33773
33773
 
33774
33774
  default:
33775
33775
  throw new Error(
33776
- `Invalid maps API version. It shoud be ${_maps_api_common__WEBPACK_IMPORTED_MODULE_1__["API_VERSIONS"].V1} or ${_maps_api_common__WEBPACK_IMPORTED_MODULE_1__["API_VERSIONS"].V2}`
33776
+ `Invalid maps API version. It should be ${_maps_api_common__WEBPACK_IMPORTED_MODULE_1__["API_VERSIONS"].V1} or ${_maps_api_common__WEBPACK_IMPORTED_MODULE_1__["API_VERSIONS"].V2}`
33777
33777
  );
33778
33778
  }
33779
33779
  }
@@ -33812,15 +33812,11 @@ function dealWithError({response, json, credentials}) {
33812
33812
  switch (response.status) {
33813
33813
  case 401:
33814
33814
  throw new Error(
33815
- `Unauthorized access to Maps API: invalid combination of user ('${
33816
- credentials.username
33817
- }') and apiKey ('${credentials.apiKey}')`
33815
+ `Unauthorized access to Maps API: invalid combination of user ('${credentials.username}') and apiKey ('${credentials.apiKey}')`
33818
33816
  );
33819
33817
  case 403:
33820
33818
  throw new Error(
33821
- `Unauthorized access to dataset: the provided apiKey('${
33822
- credentials.apiKey
33823
- }') doesn't provide access to the requested data`
33819
+ `Unauthorized access to dataset: the provided apiKey('${credentials.apiKey}') doesn't provide access to the requested data`
33824
33820
  );
33825
33821
 
33826
33822
  default:
@@ -34143,7 +34139,7 @@ async function getData({type, source, connection, credentials, geoColumn, column
34143
34139
  return layerData.data;
34144
34140
  }
34145
34141
 
34146
- /* global setInterval, URLSearchParams */
34142
+ /* global clearInterval, setInterval, URLSearchParams */
34147
34143
  async function _fetchMapDataset(dataset, accessToken) {
34148
34144
  // First fetch metadata
34149
34145
  const {connectionName: connection, source, type} = dataset;
@@ -34172,10 +34168,14 @@ async function fillInMapDatasets({datasets, publicToken}) {
34172
34168
  return await Promise.all(promises);
34173
34169
  }
34174
34170
 
34175
- async function fetchMap({mapId, credentials, autoRefresh, onNewData}) {
34176
- const localCreds = {...Object(_config__WEBPACK_IMPORTED_MODULE_0__["getDefaultCredentials"])(), ...credentials};
34171
+ async function fetchMap({cartoMapId, credentials, autoRefresh, onNewData}) {
34172
+ const defaultCredentials = Object(_config__WEBPACK_IMPORTED_MODULE_0__["getDefaultCredentials"])();
34173
+ const localCreds = {
34174
+ ...(defaultCredentials.apiVersion === _maps_api_common__WEBPACK_IMPORTED_MODULE_1__["API_VERSIONS"].V3 && defaultCredentials),
34175
+ ...credentials
34176
+ };
34177
34177
 
34178
- _deck_gl_core__WEBPACK_IMPORTED_MODULE_3__["log"].assert(mapId, 'Must define map id');
34178
+ _deck_gl_core__WEBPACK_IMPORTED_MODULE_3__["log"].assert(cartoMapId, `Must define CARTO map id: fetchMap({cartoMapId: 'XXXX-XXXX-XXXX'})`);
34179
34179
 
34180
34180
  _deck_gl_core__WEBPACK_IMPORTED_MODULE_3__["log"].assert(localCreds.apiVersion === _maps_api_common__WEBPACK_IMPORTED_MODULE_1__["API_VERSIONS"].V3, 'Method only available for v3');
34181
34181
  _deck_gl_core__WEBPACK_IMPORTED_MODULE_3__["log"].assert(localCreds.apiBaseUrl, 'Must define apiBaseUrl');
@@ -34189,23 +34189,30 @@ async function fetchMap({mapId, credentials, autoRefresh, onNewData}) {
34189
34189
  _deck_gl_core__WEBPACK_IMPORTED_MODULE_3__["log"].assert(autoRefresh > 0, '`autoRefresh` must be a positive number');
34190
34190
  }
34191
34191
 
34192
- const url = `${localCreds.mapsUrl}/public/${mapId}`;
34192
+ const url = `${localCreds.mapsUrl}/public/${cartoMapId}`;
34193
34193
  const map = await request({url});
34194
34194
 
34195
34195
  // Periodically check if the data has changed. Note that this
34196
34196
  // will not update when a map is published.
34197
+ let stopAutoRefresh;
34197
34198
  if (autoRefresh) {
34198
- setInterval(async () => {
34199
+ const intervalId = setInterval(async () => {
34199
34200
  const changed = await fillInMapDatasets(map);
34200
34201
  if (changed.some(v => v === true)) {
34201
34202
  onNewData(Object(_parseMap__WEBPACK_IMPORTED_MODULE_2__["parseMap"])(map));
34202
34203
  }
34203
34204
  }, autoRefresh * 1000);
34205
+ stopAutoRefresh = () => {
34206
+ clearInterval(intervalId);
34207
+ };
34204
34208
  }
34205
34209
 
34206
34210
  // Mutates map.datasets so that dataset.data contains data
34207
34211
  await fillInMapDatasets(map);
34208
- return Object(_parseMap__WEBPACK_IMPORTED_MODULE_2__["parseMap"])(map);
34212
+ return {
34213
+ ...Object(_parseMap__WEBPACK_IMPORTED_MODULE_2__["parseMap"])(map),
34214
+ ...{stopAutoRefresh}
34215
+ };
34209
34216
  }
34210
34217
 
34211
34218
 
@@ -34241,7 +34248,7 @@ function parseMap(json) {
34241
34248
  description: json.description,
34242
34249
  createdAt: json.createdAt,
34243
34250
  updatedAt: json.updatedAt,
34244
- mapState,
34251
+ initialViewState: mapState,
34245
34252
  mapStyle,
34246
34253
  layers: extractTextLayers(layers.reverse()).map(({id, type, config, visualChannels}) => {
34247
34254
  _deck_gl_core__WEBPACK_IMPORTED_MODULE_2__["log"].assert(type in _layer_map__WEBPACK_IMPORTED_MODULE_1__["LAYER_MAP"], `Unsupported layer type: ${type}`);
@@ -34274,17 +34281,19 @@ function extractTextLayers(layers) {
34274
34281
  {id, config: configRest, ...rest},
34275
34282
 
34276
34283
  // One layer per valid text label, with full opacity
34277
- ...textLabel.filter(t => t.field).map(t => {
34278
- return {
34279
- id: `id-label-${t.field.name}`,
34280
- config: {
34281
- textLabel: t,
34282
- ...configRest,
34283
- visConfig: {...configRest.visConfig, opacity: 1}
34284
- },
34285
- ...rest
34286
- };
34287
- })
34284
+ ...textLabel
34285
+ .filter(t => t.field)
34286
+ .map(t => {
34287
+ return {
34288
+ id: `${id}-label-${t.field.name}`,
34289
+ config: {
34290
+ textLabel: t,
34291
+ ...configRest,
34292
+ visConfig: {...configRest.visConfig, opacity: 1}
34293
+ },
34294
+ ...rest
34295
+ };
34296
+ })
34288
34297
  ];
34289
34298
  })
34290
34299
  );
@@ -34319,12 +34328,6 @@ function createInteractionProps(interactionConfig) {
34319
34328
  }
34320
34329
 
34321
34330
  function mapProps(source, target, mapping) {
34322
- if (Array.isArray(source)) {
34323
- source = source[0];
34324
- }
34325
- if (!source) {
34326
- return;
34327
- }
34328
34331
  for (const sourceKey in mapping) {
34329
34332
  const sourceValue = source[sourceKey];
34330
34333
  const targetKey = mapping[sourceKey];
@@ -34350,14 +34353,8 @@ function createStyleProps(config, mapping) {
34350
34353
 
34351
34354
  /* eslint-disable complexity */
34352
34355
  function createChannelProps(visualChannels, type, config, data) {
34353
- const {
34354
- colorField,
34355
- colorScale,
34356
- sizeField,
34357
- sizeScale,
34358
- strokeColorField,
34359
- strokeColorScale
34360
- } = visualChannels;
34356
+ const {colorField, colorScale, sizeField, sizeScale, strokeColorField, strokeColorScale} =
34357
+ visualChannels;
34361
34358
  let {heightField, heightScale} = visualChannels;
34362
34359
  if (type === 'hexagonId') {
34363
34360
  heightField = sizeField;
@@ -34442,12 +34439,13 @@ const base_url = 'https://basemaps.cartocdn.com/gl/{basemap}-gl-style/style.json
34442
34439
  /*!***********************!*\
34443
34440
  !*** ./src/config.js ***!
34444
34441
  \***********************/
34445
- /*! exports provided: defaultClassicCredentials, setDefaultCredentials, getDefaultCredentials, buildMapsUrlFromBase */
34442
+ /*! exports provided: defaultClassicCredentials, defaultCloudNativeCredentials, setDefaultCredentials, getDefaultCredentials, buildMapsUrlFromBase */
34446
34443
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
34447
34444
 
34448
34445
  "use strict";
34449
34446
  __webpack_require__.r(__webpack_exports__);
34450
34447
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "defaultClassicCredentials", function() { return defaultClassicCredentials; });
34448
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "defaultCloudNativeCredentials", function() { return defaultCloudNativeCredentials; });
34451
34449
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setDefaultCredentials", function() { return setDefaultCredentials; });
34452
34450
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getDefaultCredentials", function() { return getDefaultCredentials; });
34453
34451
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "buildMapsUrlFromBase", function() { return buildMapsUrlFromBase; });
@@ -34455,60 +34453,29 @@ __webpack_require__.r(__webpack_exports__);
34455
34453
 
34456
34454
 
34457
34455
  const defaultClassicCredentials = {
34458
- username: 'public',
34459
34456
  apiKey: 'default_public',
34460
34457
  region: 'us',
34461
- mapsUrl: null
34458
+ username: 'public'
34462
34459
  };
34463
34460
 
34464
34461
  const defaultCloudNativeCredentials = {
34465
- accessToken: null,
34466
- apiBaseUrl: null,
34467
- mapsUrl: null
34462
+ apiBaseUrl: 'https://gcp-us-east1.api.carto.com'
34468
34463
  };
34469
34464
 
34470
34465
  let credentials = {};
34471
34466
 
34472
34467
  setDefaultCredentials({});
34473
34468
 
34474
- function setDefaultCredentials(opts) {
34475
- const apiVersion = opts.apiVersion || _api_maps_api_common__WEBPACK_IMPORTED_MODULE_0__["API_VERSIONS"].V2;
34469
+ function setDefaultCredentials({apiVersion, ...rest}) {
34470
+ apiVersion = apiVersion || _api_maps_api_common__WEBPACK_IMPORTED_MODULE_0__["API_VERSIONS"].V3;
34476
34471
 
34477
34472
  switch (apiVersion) {
34478
34473
  case _api_maps_api_common__WEBPACK_IMPORTED_MODULE_0__["API_VERSIONS"].V1:
34479
- opts.mapsUrl = opts.mapsUrl || _api_maps_api_common__WEBPACK_IMPORTED_MODULE_0__["DEFAULT_MAPS_URL_FORMAT"][apiVersion];
34480
- credentials = {
34481
- apiVersion,
34482
- ...defaultClassicCredentials,
34483
- ...opts
34484
- };
34485
- break;
34486
-
34487
34474
  case _api_maps_api_common__WEBPACK_IMPORTED_MODULE_0__["API_VERSIONS"].V2:
34488
- opts.mapsUrl = opts.mapsUrl || _api_maps_api_common__WEBPACK_IMPORTED_MODULE_0__["DEFAULT_MAPS_URL_FORMAT"][apiVersion];
34489
- credentials = {
34490
- apiVersion,
34491
- ...defaultClassicCredentials,
34492
- ...opts
34493
- };
34494
-
34475
+ credentials = {apiVersion, ...defaultClassicCredentials, ...rest};
34495
34476
  break;
34496
34477
  case _api_maps_api_common__WEBPACK_IMPORTED_MODULE_0__["API_VERSIONS"].V3:
34497
- if (!opts.apiBaseUrl) {
34498
- throw new Error(
34499
- `API version ${
34500
- _api_maps_api_common__WEBPACK_IMPORTED_MODULE_0__["API_VERSIONS"].V3
34501
- } requires to define apiBaseUrl at credentials. Go to https://app.carto.com to get your apiBaseUrl.`
34502
- );
34503
- }
34504
-
34505
- const apiBaseUrl = opts.apiBaseUrl || defaultCloudNativeCredentials.apiBaseUrl;
34506
- opts.mapsUrl = opts.mapsUrl || buildMapsUrlFromBase(apiBaseUrl);
34507
- credentials = {
34508
- apiVersion,
34509
- ...defaultCloudNativeCredentials,
34510
- ...opts
34511
- };
34478
+ credentials = {apiVersion, ...defaultCloudNativeCredentials, ...rest};
34512
34479
  break;
34513
34480
  default:
34514
34481
  throw new Error(`Invalid API version ${apiVersion}. Use API_VERSIONS enum.`);
@@ -34751,7 +34718,9 @@ class CartoLayer extends _deck_gl_core__WEBPACK_IMPORTED_MODULE_0__["CompositeLa
34751
34718
 
34752
34719
  let data;
34753
34720
 
34754
- if (apiVersion === _api__WEBPACK_IMPORTED_MODULE_1__["API_VERSIONS"].V3) {
34721
+ if (apiVersion === _api__WEBPACK_IMPORTED_MODULE_1__["API_VERSIONS"].V1 || apiVersion === _api__WEBPACK_IMPORTED_MODULE_1__["API_VERSIONS"].V2) {
34722
+ data = await Object(_api__WEBPACK_IMPORTED_MODULE_1__["getDataV2"])({type, source, credentials});
34723
+ } else {
34755
34724
  data = await Object(_api__WEBPACK_IMPORTED_MODULE_1__["getData"])({
34756
34725
  type,
34757
34726
  source,
@@ -34760,10 +34729,6 @@ class CartoLayer extends _deck_gl_core__WEBPACK_IMPORTED_MODULE_0__["CompositeLa
34760
34729
  geoColumn,
34761
34730
  columns
34762
34731
  });
34763
- } else if (apiVersion === _api__WEBPACK_IMPORTED_MODULE_1__["API_VERSIONS"].V1 || apiVersion === _api__WEBPACK_IMPORTED_MODULE_1__["API_VERSIONS"].V2) {
34764
- data = await Object(_api__WEBPACK_IMPORTED_MODULE_1__["getDataV2"])({type, source, credentials});
34765
- } else {
34766
- _deck_gl_core__WEBPACK_IMPORTED_MODULE_0__["log"].assert(`Unknow apiVersion ${apiVersion}. Use API_VERSIONS enum.`);
34767
34732
  }
34768
34733
 
34769
34734
  this.setState({data, apiVersion});
@@ -34885,9 +34850,7 @@ function colorBins({
34885
34850
 
34886
34851
  const palette = typeof colors === 'string' ? Object(_palette__WEBPACK_IMPORTED_MODULE_1__["default"])(colors, domain.length) : colors;
34887
34852
 
34888
- const color = Object(d3_scale__WEBPACK_IMPORTED_MODULE_0__["scaleThreshold"])()
34889
- .domain(domain)
34890
- .range(palette);
34853
+ const color = Object(d3_scale__WEBPACK_IMPORTED_MODULE_0__["scaleThreshold"])().domain(domain).range(palette);
34891
34854
 
34892
34855
  return d => {
34893
34856
  const value = Object(_utils__WEBPACK_IMPORTED_MODULE_2__["getAttrValue"])(attr, d);
@@ -34966,9 +34929,7 @@ function colorContinuous({
34966
34929
  Object(_utils__WEBPACK_IMPORTED_MODULE_2__["assert"])(Array.isArray(domain), 'Expected "domain" to be an array of numbers');
34967
34930
 
34968
34931
  const palette = typeof colors === 'string' ? Object(_palette__WEBPACK_IMPORTED_MODULE_1__["default"])(colors) : colors;
34969
- const color = Object(d3_scale__WEBPACK_IMPORTED_MODULE_0__["scaleLinear"])()
34970
- .domain(domain)
34971
- .range(palette);
34932
+ const color = Object(d3_scale__WEBPACK_IMPORTED_MODULE_0__["scaleLinear"])().domain(domain).range(palette);
34972
34933
 
34973
34934
  return d => {
34974
34935
  const value = Object(_utils__WEBPACK_IMPORTED_MODULE_2__["getAttrValue"])(attr, d);
@@ -5,55 +5,55 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  Object.defineProperty(exports, "FORMATS", {
7
7
  enumerable: true,
8
- get: function get() {
8
+ get: function () {
9
9
  return _mapsApiCommon.FORMATS;
10
10
  }
11
11
  });
12
12
  Object.defineProperty(exports, "MAP_TYPES", {
13
13
  enumerable: true,
14
- get: function get() {
14
+ get: function () {
15
15
  return _mapsApiCommon.MAP_TYPES;
16
16
  }
17
17
  });
18
18
  Object.defineProperty(exports, "API_VERSIONS", {
19
19
  enumerable: true,
20
- get: function get() {
20
+ get: function () {
21
21
  return _mapsApiCommon.API_VERSIONS;
22
22
  }
23
23
  });
24
24
  Object.defineProperty(exports, "getDataV2", {
25
25
  enumerable: true,
26
- get: function get() {
26
+ get: function () {
27
27
  return _mapsClient.getDataV2;
28
28
  }
29
29
  });
30
30
  Object.defineProperty(exports, "CONNECTIONS", {
31
31
  enumerable: true,
32
- get: function get() {
32
+ get: function () {
33
33
  return _mapsClient.CONNECTIONS;
34
34
  }
35
35
  });
36
36
  Object.defineProperty(exports, "fetchLayerData", {
37
37
  enumerable: true,
38
- get: function get() {
38
+ get: function () {
39
39
  return _mapsV3Client.fetchLayerData;
40
40
  }
41
41
  });
42
42
  Object.defineProperty(exports, "fetchMap", {
43
43
  enumerable: true,
44
- get: function get() {
44
+ get: function () {
45
45
  return _mapsV3Client.fetchMap;
46
46
  }
47
47
  });
48
48
  Object.defineProperty(exports, "getData", {
49
49
  enumerable: true,
50
- get: function get() {
50
+ get: function () {
51
51
  return _mapsV3Client.getData;
52
52
  }
53
53
  });
54
54
  Object.defineProperty(exports, "mapInstantiation", {
55
55
  enumerable: true,
56
- get: function get() {
56
+ get: function () {
57
57
  return _mapsV3Client.mapInstantiation;
58
58
  }
59
59
  });
@@ -11,10 +11,6 @@ exports.getTextAccessor = getTextAccessor;
11
11
  exports.getTextPixelOffsetAccessor = getTextPixelOffsetAccessor;
12
12
  exports.LAYER_MAP = void 0;
13
13
 
14
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
15
-
16
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
17
-
18
14
  var _d3Array = require("d3-array");
19
15
 
20
16
  var _d3Color = require("d3-color");
@@ -29,11 +25,7 @@ var _geoLayers = require("@deck.gl/geo-layers");
29
25
 
30
26
  var _layers = require("@deck.gl/layers");
31
27
 
32
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
33
-
34
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
35
-
36
- var SCALE_FUNCS = {
28
+ const SCALE_FUNCS = {
37
29
  linear: _d3Scale.scaleLinear,
38
30
  ordinal: _d3Scale.scaleOrdinal,
39
31
  log: _d3Scale.scaleLog,
@@ -42,7 +34,7 @@ var SCALE_FUNCS = {
42
34
  quantize: _d3Scale.scaleQuantize,
43
35
  sqrt: _d3Scale.scaleSqrt
44
36
  };
45
- var sharedPropMap = {
37
+ const sharedPropMap = {
46
38
  color: 'getFillColor',
47
39
  isVisible: 'visible',
48
40
  textLabel: {
@@ -62,8 +54,8 @@ var sharedPropMap = {
62
54
  wireframe: 'wireframe'
63
55
  }
64
56
  };
65
- var RADIUS_DOWNSCALE = 0.2;
66
- var defaultProps = {
57
+ const RADIUS_DOWNSCALE = 0.2;
58
+ const defaultProps = {
67
59
  lineMiterLimit: 2,
68
60
  lineWidthUnits: 'pixels',
69
61
  pointRadiusScale: RADIUS_DOWNSCALE,
@@ -73,12 +65,15 @@ var defaultProps = {
73
65
  };
74
66
 
75
67
  function mergePropMaps(a, b) {
76
- return _objectSpread(_objectSpread(_objectSpread({}, a), b), {}, {
77
- visConfig: _objectSpread(_objectSpread({}, a.visConfig), b.visConfig)
78
- });
68
+ return { ...a,
69
+ ...b,
70
+ visConfig: { ...a.visConfig,
71
+ ...b.visConfig
72
+ }
73
+ };
79
74
  }
80
75
 
81
- var LAYER_MAP = {
76
+ const LAYER_MAP = {
82
77
  point: {
83
78
  Layer: _layers.GeoJsonLayer,
84
79
  propMap: mergePropMaps(sharedPropMap, {
@@ -86,14 +81,14 @@ var LAYER_MAP = {
86
81
  outline: 'stroked'
87
82
  }
88
83
  }),
89
- defaultProps: defaultProps
84
+ defaultProps
90
85
  },
91
86
  geojson: {
92
87
  Layer: _layers.GeoJsonLayer,
93
88
  propMap: sharedPropMap,
94
- defaultProps: _objectSpread(_objectSpread({}, defaultProps), {}, {
89
+ defaultProps: { ...defaultProps,
95
90
  lineWidthScale: 2
96
- })
91
+ }
97
92
  },
98
93
  hexagonId: {
99
94
  Layer: _geoLayers.H3HexagonLayer,
@@ -103,33 +98,29 @@ var LAYER_MAP = {
103
98
  elevationScale: 'elevationScale'
104
99
  }
105
100
  }),
106
- defaultProps: _objectSpread(_objectSpread({}, defaultProps), {}, {
107
- getHexagon: function getHexagon(d) {
108
- return d.h3;
109
- }
110
- })
101
+ defaultProps: { ...defaultProps,
102
+ getHexagon: d => d.h3
103
+ }
111
104
  },
112
105
  mvt: {
113
106
  Layer: _geoLayers.MVTLayer,
114
107
  propMap: sharedPropMap,
115
- defaultProps: _objectSpread(_objectSpread({}, defaultProps), {}, {
108
+ defaultProps: { ...defaultProps,
116
109
  pointRadiusScale: 0.3,
117
110
  lineWidthScale: 2
118
- })
111
+ }
119
112
  }
120
113
  };
121
114
  exports.LAYER_MAP = LAYER_MAP;
122
115
 
123
116
  function domainFromAttribute(attribute, scaleType) {
124
117
  if (scaleType === 'ordinal' || scaleType === 'point') {
125
- return attribute.categories.map(function (c) {
126
- return c.category;
127
- }).filter(function (c) {
128
- return c !== undefined && c !== null;
129
- });
118
+ return attribute.categories.map(c => c.category).filter(c => c !== undefined && c !== null);
130
119
  }
131
120
 
132
- var min = attribute.min;
121
+ let {
122
+ min
123
+ } = attribute;
133
124
 
134
125
  if (scaleType === 'log' && min === 0) {
135
126
  min = 1e-5;
@@ -140,7 +131,7 @@ function domainFromAttribute(attribute, scaleType) {
140
131
 
141
132
  function domainFromValues(values, scaleType) {
142
133
  if (scaleType === 'ordinal') {
143
- return (0, _toConsumableArray2.default)(new Set(values)).sort();
134
+ return [...new Set(values)].sort();
144
135
  }
145
136
 
146
137
  return (0, _d3Array.extent)(values);
@@ -148,23 +139,19 @@ function domainFromValues(values, scaleType) {
148
139
 
149
140
  function calculateDomain(data, name, scaleType) {
150
141
  if (data.tilestats) {
151
- var attributes = data.tilestats.layers[0].attributes;
152
- var attribute = attributes.find(function (a) {
153
- return a.attribute === name;
154
- });
142
+ const {
143
+ attributes
144
+ } = data.tilestats.layers[0];
145
+ const attribute = attributes.find(a => a.attribute === name);
155
146
  return domainFromAttribute(attribute, scaleType);
156
147
  } else if (data.features) {
157
- var values = data.features.map(function (_ref) {
158
- var properties = _ref.properties;
159
- return properties[name];
160
- });
148
+ const values = data.features.map(({
149
+ properties
150
+ }) => properties[name]);
151
+ return domainFromValues(values, scaleType);
152
+ } else if (Array.isArray(data) && data[0][name] !== undefined) {
153
+ const values = data.map(properties => properties[name]);
161
154
  return domainFromValues(values, scaleType);
162
- } else if (Array.isArray(data) && data[0][name]) {
163
- var _values = data.map(function (properties) {
164
- return properties[name];
165
- });
166
-
167
- return domainFromValues(_values, scaleType);
168
155
  }
169
156
 
170
157
  return [0, 1];
@@ -172,8 +159,9 @@ function calculateDomain(data, name, scaleType) {
172
159
 
173
160
  function normalizeAccessor(accessor, data) {
174
161
  if (data.features || data.tilestats) {
175
- return function (_ref2) {
176
- var properties = _ref2.properties;
162
+ return ({
163
+ properties
164
+ }) => {
177
165
  return accessor(properties);
178
166
  };
179
167
  }
@@ -181,74 +169,75 @@ function normalizeAccessor(accessor, data) {
181
169
  return accessor;
182
170
  }
183
171
 
184
- function getColorAccessor(_ref3, scaleType, _ref4, opacity, data) {
185
- var name = _ref3.name;
186
- var colors = _ref4.colors;
187
- var scale = SCALE_FUNCS[scaleType]();
172
+ function getColorAccessor({
173
+ name
174
+ }, scaleType, {
175
+ colors
176
+ }, opacity, data) {
177
+ const scale = SCALE_FUNCS[scaleType]();
188
178
  scale.domain(calculateDomain(data, name, scaleType));
189
179
  scale.range(colors);
190
- var alpha = opacity !== undefined ? 255 * Math.pow(opacity, 1 / 2.2) : 255;
180
+ const alpha = opacity !== undefined ? Math.round(255 * Math.pow(opacity, 1 / 2.2)) : 255;
191
181
 
192
- var accessor = function accessor(properties) {
193
- var rgba = (0, _d3Color.rgb)(scale(properties[name]));
182
+ const accessor = properties => {
183
+ const rgba = (0, _d3Color.rgb)(scale(properties[name]));
194
184
  return [rgba.r, rgba.g, rgba.b, alpha];
195
185
  };
196
186
 
197
187
  return normalizeAccessor(accessor, data);
198
188
  }
199
189
 
200
- function getSizeAccessor(_ref5, scaleType, range, data) {
201
- var name = _ref5.name;
202
- var scale = SCALE_FUNCS[scaleType]();
190
+ function getSizeAccessor({
191
+ name
192
+ }, scaleType, range, data) {
193
+ const scale = SCALE_FUNCS[scaleType]();
203
194
  scale.domain(calculateDomain(data, name, scaleType));
204
195
  scale.range(range);
205
196
 
206
- var accessor = function accessor(properties) {
197
+ const accessor = properties => {
207
198
  return scale(properties[name]);
208
199
  };
209
200
 
210
201
  return normalizeAccessor(accessor, data);
211
202
  }
212
203
 
213
- var FORMATS = {
214
- date: function date(s) {
215
- return _momentTimezone.default.utc(s).format('MM/DD/YY HH:mm:ssa');
216
- },
204
+ const FORMATS = {
205
+ date: s => _momentTimezone.default.utc(s).format('MM/DD/YY HH:mm:ssa'),
217
206
  integer: (0, _d3Format.format)('i'),
218
207
  float: (0, _d3Format.format)('.5f'),
219
- timestamp: function timestamp(s) {
220
- return _momentTimezone.default.utc(s).format('X');
221
- },
208
+ timestamp: s => _momentTimezone.default.utc(s).format('X'),
222
209
  default: String
223
210
  };
224
211
 
225
- function getTextAccessor(_ref6, data) {
226
- var name = _ref6.name,
227
- type = _ref6.type;
228
- var format = FORMATS[type] || FORMATS.default;
212
+ function getTextAccessor({
213
+ name,
214
+ type
215
+ }, data) {
216
+ const format = FORMATS[type] || FORMATS.default;
229
217
 
230
- var accessor = function accessor(properties) {
218
+ const accessor = properties => {
231
219
  return format(properties[name]);
232
220
  };
233
221
 
234
222
  return normalizeAccessor(accessor, data);
235
223
  }
236
224
 
237
- function getTextPixelOffsetAccessor(_ref7, radius) {
238
- var alignment = _ref7.alignment,
239
- anchor = _ref7.anchor,
240
- size = _ref7.size;
241
- var padding = 20;
242
- var signX = anchor === 'middle' ? 0 : anchor === 'start' ? 1 : -1;
243
- var signY = alignment === 'center' ? 0 : alignment === 'bottom' ? 1 : -1;
244
- var sizeOffset = alignment === 'center' ? 0 : size;
245
-
246
- var calculateOffset = function calculateOffset(r) {
225
+ function getTextPixelOffsetAccessor({
226
+ alignment,
227
+ anchor,
228
+ size
229
+ }, radius) {
230
+ const padding = 20;
231
+ const signX = anchor === 'middle' ? 0 : anchor === 'start' ? 1 : -1;
232
+ const signY = alignment === 'center' ? 0 : alignment === 'bottom' ? 1 : -1;
233
+ const sizeOffset = alignment === 'center' ? 0 : size;
234
+
235
+ const calculateOffset = r => {
247
236
  r = RADIUS_DOWNSCALE * r;
248
237
  return [signX * (r + padding), signY * (r + padding + sizeOffset)];
249
238
  };
250
239
 
251
- return typeof radius === 'function' ? function (d) {
240
+ return typeof radius === 'function' ? d => {
252
241
  return calculateOffset(radius(d));
253
242
  } : calculateOffset(radius);
254
243
  }