@deck.gl/carto 8.6.3 → 8.6.7
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.
- package/dist/dist.dev.js +396 -207
- package/dist/es5/api/index.js +21 -21
- package/dist/es5/api/maps-api-common.js +14 -10
- package/dist/es5/api/maps-api-common.js.map +1 -1
- package/dist/es5/api/maps-client.js +158 -99
- package/dist/es5/api/maps-client.js.map +1 -1
- package/dist/es5/api/maps-v3-client.js +308 -193
- package/dist/es5/api/maps-v3-client.js.map +1 -1
- package/dist/es5/basemap.js +1 -1
- package/dist/es5/basemap.js.map +1 -1
- package/dist/es5/config.js +25 -23
- package/dist/es5/config.js.map +1 -1
- package/dist/es5/index.js +45 -45
- package/dist/es5/layers/carto-bqtiler-layer.js +41 -6
- package/dist/es5/layers/carto-bqtiler-layer.js.map +1 -1
- package/dist/es5/layers/carto-layer.js +211 -132
- package/dist/es5/layers/carto-layer.js.map +1 -1
- package/dist/es5/layers/carto-sql-layer.js +41 -6
- package/dist/es5/layers/carto-sql-layer.js.map +1 -1
- package/dist/es5/style/color-bins-style.js +16 -11
- package/dist/es5/style/color-bins-style.js.map +1 -1
- package/dist/es5/style/color-categories-style.js +43 -14
- package/dist/es5/style/color-categories-style.js.map +1 -1
- package/dist/es5/style/color-continuous-style.js +16 -11
- package/dist/es5/style/color-continuous-style.js.map +1 -1
- package/dist/es5/style/palette.js +25 -13
- package/dist/es5/style/palette.js.map +1 -1
- package/dist/es5/style/utils.js +14 -7
- package/dist/es5/style/utils.js.map +1 -1
- package/dist/esm/api/maps-client.js +30 -24
- package/dist/esm/api/maps-client.js.map +1 -1
- package/dist/esm/api/maps-v3-client.js +60 -52
- package/dist/esm/api/maps-v3-client.js.map +1 -1
- package/dist/esm/layers/carto-bqtiler-layer.js +2 -2
- package/dist/esm/layers/carto-bqtiler-layer.js.map +1 -1
- package/dist/esm/layers/carto-layer.js +7 -5
- package/dist/esm/layers/carto-layer.js.map +1 -1
- package/dist/esm/layers/carto-sql-layer.js +2 -2
- package/dist/esm/layers/carto-sql-layer.js.map +1 -1
- package/dist/esm/style/color-bins-style.js +7 -6
- package/dist/esm/style/color-bins-style.js.map +1 -1
- package/dist/esm/style/color-categories-style.js +8 -7
- package/dist/esm/style/color-categories-style.js.map +1 -1
- package/dist/esm/style/color-continuous-style.js +7 -6
- package/dist/esm/style/color-continuous-style.js.map +1 -1
- package/dist/esm/style/utils.js +3 -1
- package/dist/esm/style/utils.js.map +1 -1
- package/dist.min.js +1 -1
- package/package.json +7 -7
|
@@ -1,33 +1,62 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
4
6
|
|
|
5
7
|
Object.defineProperty(exports, "__esModule", {
|
|
6
8
|
value: true
|
|
7
9
|
});
|
|
8
10
|
exports.default = colorCategories;
|
|
9
11
|
|
|
12
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
13
|
+
|
|
10
14
|
var _palette = _interopRequireWildcard(require("./palette"));
|
|
11
15
|
|
|
12
16
|
var _utils = require("./utils");
|
|
13
17
|
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
|
+
|
|
20
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
|
+
|
|
22
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
23
|
+
|
|
24
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
25
|
+
|
|
26
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
27
|
+
|
|
28
|
+
function colorCategories(_ref) {
|
|
29
|
+
var attr = _ref.attr,
|
|
30
|
+
domain = _ref.domain,
|
|
31
|
+
_ref$colors = _ref.colors,
|
|
32
|
+
colors = _ref$colors === void 0 ? _palette.DEFAULT_PALETTE : _ref$colors,
|
|
33
|
+
_ref$nullColor = _ref.nullColor,
|
|
34
|
+
nullColor = _ref$nullColor === void 0 ? _palette.NULL_COLOR : _ref$nullColor,
|
|
35
|
+
_ref$othersColor = _ref.othersColor,
|
|
36
|
+
othersColor = _ref$othersColor === void 0 ? _palette.OTHERS_COLOR : _ref$othersColor;
|
|
21
37
|
(0, _utils.assert)(Array.isArray(domain), 'Expected "domain" to be an array of numbers or strings');
|
|
22
|
-
|
|
23
|
-
|
|
38
|
+
var colorsByCategory = {};
|
|
39
|
+
var palette = typeof colors === 'string' ? (0, _palette.default)(colors, domain.length) : colors;
|
|
40
|
+
|
|
41
|
+
var _iterator = _createForOfIteratorHelper(domain.entries()),
|
|
42
|
+
_step;
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
46
|
+
var _step$value = (0, _slicedToArray2.default)(_step.value, 2),
|
|
47
|
+
i = _step$value[0],
|
|
48
|
+
c = _step$value[1];
|
|
24
49
|
|
|
25
|
-
|
|
26
|
-
|
|
50
|
+
colorsByCategory[c] = palette[i];
|
|
51
|
+
}
|
|
52
|
+
} catch (err) {
|
|
53
|
+
_iterator.e(err);
|
|
54
|
+
} finally {
|
|
55
|
+
_iterator.f();
|
|
27
56
|
}
|
|
28
57
|
|
|
29
|
-
return d
|
|
30
|
-
|
|
58
|
+
return function (d) {
|
|
59
|
+
var value = (0, _utils.getAttrValue)(attr, d);
|
|
31
60
|
return Number.isFinite(value) || typeof value === 'string' ? colorsByCategory[value] || othersColor : nullColor;
|
|
32
61
|
};
|
|
33
62
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/style/color-categories-style.js"],"names":["colorCategories","attr","domain","colors","DEFAULT_PALETTE","nullColor","NULL_COLOR","othersColor","OTHERS_COLOR","Array","isArray","colorsByCategory","palette","length","
|
|
1
|
+
{"version":3,"sources":["../../../src/style/color-categories-style.js"],"names":["colorCategories","attr","domain","colors","DEFAULT_PALETTE","nullColor","NULL_COLOR","othersColor","OTHERS_COLOR","Array","isArray","colorsByCategory","palette","length","entries","i","c","d","value","Number","isFinite"],"mappings":";;;;;;;;;;;;;AAAA;;AACA;;;;;;;;;;;;AAEe,SAASA,eAAT,OAMZ;AAAA,MALDC,IAKC,QALDA,IAKC;AAAA,MAJDC,MAIC,QAJDA,MAIC;AAAA,yBAHDC,MAGC;AAAA,MAHDA,MAGC,4BAHQC,wBAGR;AAAA,4BAFDC,SAEC;AAAA,MAFDA,SAEC,+BAFWC,mBAEX;AAAA,8BADDC,WACC;AAAA,MADDA,WACC,iCADaC,qBACb;AACD,qBAAOC,KAAK,CAACC,OAAN,CAAcR,MAAd,CAAP,EAA8B,wDAA9B;AAEA,MAAMS,gBAAgB,GAAG,EAAzB;AACA,MAAMC,OAAO,GAAG,OAAOT,MAAP,KAAkB,QAAlB,GAA6B,sBAAWA,MAAX,EAAmBD,MAAM,CAACW,MAA1B,CAA7B,GAAiEV,MAAjF;;AAJC,6CAMoBD,MAAM,CAACY,OAAP,EANpB;AAAA;;AAAA;AAMD,wDAAuC;AAAA;AAAA,UAA3BC,CAA2B;AAAA,UAAxBC,CAAwB;;AACrCL,MAAAA,gBAAgB,CAACK,CAAD,CAAhB,GAAsBJ,OAAO,CAACG,CAAD,CAA7B;AACD;AARA;AAAA;AAAA;AAAA;AAAA;;AAUD,SAAO,UAAAE,CAAC,EAAI;AACV,QAAMC,KAAK,GAAG,yBAAajB,IAAb,EAAmBgB,CAAnB,CAAd;AACA,WAAOE,MAAM,CAACC,QAAP,CAAgBF,KAAhB,KAA0B,OAAOA,KAAP,KAAiB,QAA3C,GACHP,gBAAgB,CAACO,KAAD,CAAhB,IAA2BX,WADxB,GAEHF,SAFJ;AAGD,GALD;AAMD","sourcesContent":["import getPalette, {DEFAULT_PALETTE, NULL_COLOR, OTHERS_COLOR} from './palette';\nimport {assert, getAttrValue} from './utils';\n\nexport default function colorCategories({\n attr,\n domain,\n colors = DEFAULT_PALETTE,\n nullColor = NULL_COLOR,\n othersColor = OTHERS_COLOR\n}) {\n assert(Array.isArray(domain), 'Expected \"domain\" to be an array of numbers or strings');\n\n const colorsByCategory = {};\n const palette = typeof colors === 'string' ? getPalette(colors, domain.length) : colors;\n\n for (const [i, c] of domain.entries()) {\n colorsByCategory[c] = palette[i];\n }\n\n return d => {\n const value = getAttrValue(attr, d);\n return Number.isFinite(value) || typeof value === 'string'\n ? colorsByCategory[value] || othersColor\n : nullColor;\n };\n}\n"],"file":"color-categories-style.js"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
@@ -13,17 +13,22 @@ var _palette = _interopRequireWildcard(require("./palette"));
|
|
|
13
13
|
|
|
14
14
|
var _utils = require("./utils");
|
|
15
15
|
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
17
|
+
|
|
18
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
19
|
+
|
|
20
|
+
function colorContinuous(_ref) {
|
|
21
|
+
var attr = _ref.attr,
|
|
22
|
+
domain = _ref.domain,
|
|
23
|
+
_ref$colors = _ref.colors,
|
|
24
|
+
colors = _ref$colors === void 0 ? _palette.DEFAULT_PALETTE : _ref$colors,
|
|
25
|
+
_ref$nullColor = _ref.nullColor,
|
|
26
|
+
nullColor = _ref$nullColor === void 0 ? _palette.NULL_COLOR : _ref$nullColor;
|
|
22
27
|
(0, _utils.assert)(Array.isArray(domain), 'Expected "domain" to be an array of numbers');
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return d
|
|
26
|
-
|
|
28
|
+
var palette = typeof colors === 'string' ? (0, _palette.default)(colors) : colors;
|
|
29
|
+
var color = (0, _d3Scale.scaleLinear)().domain(domain).range(palette);
|
|
30
|
+
return function (d) {
|
|
31
|
+
var value = (0, _utils.getAttrValue)(attr, d);
|
|
27
32
|
return Number.isFinite(value) ? color(value) : nullColor;
|
|
28
33
|
};
|
|
29
34
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/style/color-continuous-style.js"],"names":["colorContinuous","attr","domain","colors","DEFAULT_PALETTE","nullColor","NULL_COLOR","Array","isArray","palette","color","range","d","value","Number","isFinite"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA
|
|
1
|
+
{"version":3,"sources":["../../../src/style/color-continuous-style.js"],"names":["colorContinuous","attr","domain","colors","DEFAULT_PALETTE","nullColor","NULL_COLOR","Array","isArray","palette","color","range","d","value","Number","isFinite"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;;;;;AAEe,SAASA,eAAT,OAKZ;AAAA,MAJDC,IAIC,QAJDA,IAIC;AAAA,MAHDC,MAGC,QAHDA,MAGC;AAAA,yBAFDC,MAEC;AAAA,MAFDA,MAEC,4BAFQC,wBAER;AAAA,4BADDC,SACC;AAAA,MADDA,SACC,+BADWC,mBACX;AACD,qBAAOC,KAAK,CAACC,OAAN,CAAcN,MAAd,CAAP,EAA8B,6CAA9B;AAEA,MAAMO,OAAO,GAAG,OAAON,MAAP,KAAkB,QAAlB,GAA6B,sBAAWA,MAAX,CAA7B,GAAkDA,MAAlE;AACA,MAAMO,KAAK,GAAG,4BACXR,MADW,CACJA,MADI,EAEXS,KAFW,CAELF,OAFK,CAAd;AAIA,SAAO,UAAAG,CAAC,EAAI;AACV,QAAMC,KAAK,GAAG,yBAAaZ,IAAb,EAAmBW,CAAnB,CAAd;AACA,WAAOE,MAAM,CAACC,QAAP,CAAgBF,KAAhB,IAAyBH,KAAK,CAACG,KAAD,CAA9B,GAAwCR,SAA/C;AACD,GAHD;AAID","sourcesContent":["import {scaleLinear} from 'd3-scale';\nimport getPalette, {DEFAULT_PALETTE, NULL_COLOR} from './palette';\nimport {assert, getAttrValue} from './utils';\n\nexport default function colorContinuous({\n attr,\n domain,\n colors = DEFAULT_PALETTE,\n nullColor = NULL_COLOR\n}) {\n assert(Array.isArray(domain), 'Expected \"domain\" to be an array of numbers');\n\n const palette = typeof colors === 'string' ? getPalette(colors) : colors;\n const color = scaleLinear()\n .domain(domain)\n .range(palette);\n\n return d => {\n const value = getAttrValue(attr, d);\n return Number.isFinite(value) ? color(value) : nullColor;\n };\n}\n"],"file":"color-continuous-style.js"}
|
|
@@ -1,32 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
4
6
|
|
|
5
7
|
Object.defineProperty(exports, "__esModule", {
|
|
6
8
|
value: true
|
|
7
9
|
});
|
|
10
|
+
exports.OTHERS_COLOR = exports.NULL_COLOR = exports.DEFAULT_PALETTE = void 0;
|
|
8
11
|
exports.default = getPalette;
|
|
9
12
|
exports.hexToRgb = hexToRgb;
|
|
10
|
-
|
|
13
|
+
|
|
14
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
15
|
|
|
12
16
|
var cartoColors = _interopRequireWildcard(require("cartocolor"));
|
|
13
17
|
|
|
14
18
|
var _utils = require("./utils");
|
|
15
19
|
|
|
16
|
-
|
|
20
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
21
|
+
|
|
22
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
23
|
+
|
|
24
|
+
var DEFAULT_PALETTE = 'PurpOr';
|
|
17
25
|
exports.DEFAULT_PALETTE = DEFAULT_PALETTE;
|
|
18
|
-
|
|
26
|
+
var NULL_COLOR = [204, 204, 204];
|
|
19
27
|
exports.NULL_COLOR = NULL_COLOR;
|
|
20
|
-
|
|
28
|
+
var OTHERS_COLOR = [119, 119, 119];
|
|
21
29
|
exports.OTHERS_COLOR = OTHERS_COLOR;
|
|
22
30
|
|
|
23
31
|
function getPalette(name, numCategories) {
|
|
24
|
-
|
|
25
|
-
|
|
32
|
+
var palette = cartoColors[name];
|
|
33
|
+
var paletteIndex = numCategories;
|
|
26
34
|
(0, _utils.assert)(palette, "Palette \"".concat(name, "\" not found. Expected a CARTOColors string"));
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
var palettesColorVariants = Object.keys(palette).filter(function (p) {
|
|
36
|
+
return p !== 'tags';
|
|
37
|
+
}).map(Number);
|
|
38
|
+
var longestPaletteIndex = Math.max.apply(Math, (0, _toConsumableArray2.default)(palettesColorVariants));
|
|
39
|
+
var smallestPaletteIndex = Math.min.apply(Math, (0, _toConsumableArray2.default)(palettesColorVariants));
|
|
30
40
|
|
|
31
41
|
if (!Number.isInteger(numCategories) || numCategories > longestPaletteIndex) {
|
|
32
42
|
paletteIndex = longestPaletteIndex;
|
|
@@ -34,17 +44,19 @@ function getPalette(name, numCategories) {
|
|
|
34
44
|
paletteIndex = smallestPaletteIndex;
|
|
35
45
|
}
|
|
36
46
|
|
|
37
|
-
|
|
47
|
+
var colors = palette[paletteIndex];
|
|
38
48
|
|
|
39
49
|
if (palette.tags && palette.tags.includes('qualitative')) {
|
|
40
50
|
colors = colors.slice(0, -1);
|
|
41
51
|
}
|
|
42
52
|
|
|
43
|
-
return colors.map(
|
|
53
|
+
return colors.map(function (c) {
|
|
54
|
+
return hexToRgb(c);
|
|
55
|
+
});
|
|
44
56
|
}
|
|
45
57
|
|
|
46
58
|
function hexToRgb(hex) {
|
|
47
|
-
|
|
59
|
+
var result = /^#?([a-f\d]{1})([a-f\d]{1})([a-f\d]{1})$/i.exec(hex);
|
|
48
60
|
|
|
49
61
|
if (result) {
|
|
50
62
|
return [parseInt(result[1] + result[1], 16), parseInt(result[2] + result[2], 16), parseInt(result[3] + result[3], 16), 255];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/style/palette.js"],"names":["DEFAULT_PALETTE","NULL_COLOR","OTHERS_COLOR","getPalette","name","numCategories","palette","cartoColors","paletteIndex","palettesColorVariants","Object","keys","filter","p","map","Number","longestPaletteIndex","Math","max","smallestPaletteIndex","min","isInteger","colors","tags","includes","slice","c","hexToRgb","hex","result","exec","parseInt"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/style/palette.js"],"names":["DEFAULT_PALETTE","NULL_COLOR","OTHERS_COLOR","getPalette","name","numCategories","palette","cartoColors","paletteIndex","palettesColorVariants","Object","keys","filter","p","map","Number","longestPaletteIndex","Math","max","smallestPaletteIndex","min","isInteger","colors","tags","includes","slice","c","hexToRgb","hex","result","exec","parseInt"],"mappings":";;;;;;;;;;;;;;;AAAA;;AACA;;;;;;AAEO,IAAMA,eAAe,GAAG,QAAxB;;AACA,IAAMC,UAAU,GAAG,CAAC,GAAD,EAAM,GAAN,EAAW,GAAX,CAAnB;;AACA,IAAMC,YAAY,GAAG,CAAC,GAAD,EAAM,GAAN,EAAW,GAAX,CAArB;;;AAEQ,SAASC,UAAT,CAAoBC,IAApB,EAA0BC,aAA1B,EAAyC;AACtD,MAAMC,OAAO,GAAGC,WAAW,CAACH,IAAD,CAA3B;AACA,MAAII,YAAY,GAAGH,aAAnB;AAEA,qBAAOC,OAAP,sBAA4BF,IAA5B;AAEA,MAAMK,qBAAqB,GAAGC,MAAM,CAACC,IAAP,CAAYL,OAAZ,EAC3BM,MAD2B,CACpB,UAAAC,CAAC;AAAA,WAAIA,CAAC,KAAK,MAAV;AAAA,GADmB,EAE3BC,GAF2B,CAEvBC,MAFuB,CAA9B;AAIA,MAAMC,mBAAmB,GAAGC,IAAI,CAACC,GAAL,OAAAD,IAAI,mCAAQR,qBAAR,EAAhC;AACA,MAAMU,oBAAoB,GA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];\nexport const OTHERS_COLOR = [119, 119, 119];\n\nexport default function getPalette(name, numCategories) {\n const palette = cartoColors[name];\n let paletteIndex = numCategories;\n\n assert(palette, `Palette \"${name}\" not found. Expected a CARTOColors string`);\n\n const palettesColorVariants = Object.keys(palette)\n .filter(p => p !== 'tags')\n .map(Number);\n\n const longestPaletteIndex = Math.max(...palettesColorVariants);\n const smallestPaletteIndex = Math.min(...palettesColorVariants);\n\n if (!Number.isInteger(numCategories) || numCategories > longestPaletteIndex) {\n paletteIndex = longestPaletteIndex;\n } else if (numCategories < smallestPaletteIndex) {\n paletteIndex = smallestPaletteIndex;\n }\n\n let colors = palette[paletteIndex];\n\n if (palette.tags && palette.tags.includes('qualitative')) {\n colors = colors.slice(0, -1);\n }\n\n return colors.map(c => hexToRgb(c));\n}\n\nexport function hexToRgb(hex) {\n // Evaluate #ABC\n let result = /^#?([a-f\\d]{1})([a-f\\d]{1})([a-f\\d]{1})$/i.exec(hex);\n\n if (result) {\n return [\n parseInt(result[1] + result[1], 16),\n parseInt(result[2] + result[2], 16),\n parseInt(result[3] + result[3], 16),\n 255\n ];\n }\n\n // Evaluate #ABCD\n result = /^#?([a-f\\d]{1})([a-f\\d]{1})([a-f\\d]{1})([a-f\\d]{1})$/i.exec(hex);\n\n if (result) {\n return [\n parseInt(result[1] + result[1], 16),\n parseInt(result[2] + result[2], 16),\n parseInt(result[3] + result[3], 16),\n parseInt(result[4] + result[4], 16)\n ];\n }\n\n // Evaluate #ABCDEF\n result = /^#?([a-f\\d]{2})([a-f\\d]{2})([a-f\\d]{2})$/i.exec(hex);\n\n if (result) {\n return [parseInt(result[1], 16), parseInt(result[2], 16), parseInt(result[3], 16), 255];\n }\n\n // Evaluate #ABCDEFAF\n result = /^#?([a-f\\d]{2})([a-f\\d]{2})([a-f\\d]{2})([a-f\\d]{2})$/i.exec(hex);\n\n if (result) {\n return [\n parseInt(result[1], 16),\n parseInt(result[2], 16),\n parseInt(result[3], 16),\n parseInt(result[4], 16)\n ];\n }\n\n assert(result, `Hexadecimal color \"${hex}\" was not parsed correctly`);\n\n return NULL_COLOR;\n}\n"],"file":"palette.js"}
|
package/dist/es5/style/utils.js
CHANGED
|
@@ -1,28 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
6
|
-
exports.getAttrValue = getAttrValue;
|
|
7
8
|
exports.assert = assert;
|
|
8
|
-
|
|
9
|
+
exports.getAttrValue = getAttrValue;
|
|
10
|
+
|
|
11
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
12
|
+
|
|
13
|
+
var ALLOWED_ATTR_TYPES = Object.freeze(['function', 'string']);
|
|
9
14
|
|
|
10
15
|
function getAttrValue(attr, d) {
|
|
11
|
-
assert(
|
|
12
|
-
assert(ALLOWED_ATTR_TYPES.includes(
|
|
16
|
+
assert((0, _typeof2.default)(d) === 'object', 'Expected "data" to be an object');
|
|
17
|
+
assert(ALLOWED_ATTR_TYPES.includes((0, _typeof2.default)(attr)), 'Expected "attr" to be a function or string');
|
|
13
18
|
|
|
14
|
-
if (
|
|
19
|
+
if ((0, _typeof2.default)(attr) === ALLOWED_ATTR_TYPES[0]) {
|
|
15
20
|
return attr(d);
|
|
16
21
|
}
|
|
17
22
|
|
|
18
|
-
if (
|
|
23
|
+
if ((0, _typeof2.default)(attr) === ALLOWED_ATTR_TYPES[1]) {
|
|
19
24
|
return d.properties[attr];
|
|
20
25
|
}
|
|
21
26
|
|
|
22
27
|
return {};
|
|
23
28
|
}
|
|
24
29
|
|
|
25
|
-
function assert(condition
|
|
30
|
+
function assert(condition) {
|
|
31
|
+
var message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
32
|
+
|
|
26
33
|
if (!condition) {
|
|
27
34
|
throw new Error("CARTO style error: ".concat(message));
|
|
28
35
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/style/utils.js"],"names":["ALLOWED_ATTR_TYPES","Object","freeze","getAttrValue","attr","d","assert","includes","properties","condition","message","Error"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/style/utils.js"],"names":["ALLOWED_ATTR_TYPES","Object","freeze","getAttrValue","attr","d","assert","includes","properties","condition","message","Error"],"mappings":";;;;;;;;;;;;AAAA,IAAMA,kBAAkB,GAAGC,MAAM,CAACC,MAAP,CAAc,CAAC,UAAD,EAAa,QAAb,CAAd,CAA3B;;AAEO,SAASC,YAAT,CAAsBC,IAAtB,EAA4BC,CAA5B,EAA+B;AACpCC,EAAAA,MAAM,CAAC,sBAAOD,CAAP,MAAa,QAAd,EAAwB,iCAAxB,CAAN;AACAC,EAAAA,MAAM,CAACN,kBAAkB,CAACO,QAAnB,uBAAmCH,IAAnC,EAAD,EAA2C,4CAA3C,CAAN;;AAGA,MAAI,sBAAOA,IAAP,MAAgBJ,kBAAkB,CAAC,CAAD,CAAtC,EAA2C;AACzC,WAAOI,IAAI,CAACC,CAAD,CAAX;AACD;;AAGD,MAAI,sBAAOD,IAAP,MAAgBJ,kBAAkB,CAAC,CAAD,CAAtC,EAA2C;AACzC,WAAOK,CAAC,CAACG,UAAF,CAAaJ,IAAb,CAAP;AACD;;AAED,SAAO,EAAP;AACD;;AAEM,SAASE,MAAT,CAAgBG,SAAhB,EAAyC;AAAA,MAAdC,OAAc,uEAAJ,EAAI;;AAC9C,MAAI,CAACD,SAAL,EAAgB;AACd,UAAM,IAAIE,KAAJ,8BAAgCD,OAAhC,EAAN;AACD;AACF","sourcesContent":["const ALLOWED_ATTR_TYPES = Object.freeze(['function', 'string']);\n\nexport function getAttrValue(attr, d) {\n assert(typeof d === 'object', 'Expected \"data\" to be an object');\n assert(ALLOWED_ATTR_TYPES.includes(typeof attr), 'Expected \"attr\" to be a function or string');\n\n // Is function\n if (typeof attr === ALLOWED_ATTR_TYPES[0]) {\n return attr(d);\n }\n\n // Is string\n if (typeof attr === ALLOWED_ATTR_TYPES[1]) {\n return d.properties[attr];\n }\n\n return {};\n}\n\nexport function assert(condition, message = '') {\n if (!condition) {\n throw new Error(`CARTO style error: ${message}`);\n }\n}\n"],"file":"utils.js"}
|
|
@@ -6,11 +6,12 @@ export const CONNECTIONS = {
|
|
|
6
6
|
};
|
|
7
7
|
const BUFFER_SIZE = 16;
|
|
8
8
|
const TILE_EXTENT = 4096;
|
|
9
|
-
export async function getDataV2({
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
export async function getDataV2(_ref) {
|
|
10
|
+
let {
|
|
11
|
+
type,
|
|
12
|
+
source,
|
|
13
|
+
credentials
|
|
14
|
+
} = _ref;
|
|
14
15
|
const defaultCredentials = getDefaultCredentials();
|
|
15
16
|
const apiVersion = credentials && credentials.apiVersion || defaultCredentials.apiVersion;
|
|
16
17
|
const localCreds = { ...defaultClassicCredentials,
|
|
@@ -55,10 +56,11 @@ export async function getDataV2({
|
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
async function request({
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
async function request(_ref2) {
|
|
60
|
+
let {
|
|
61
|
+
url,
|
|
62
|
+
credentials
|
|
63
|
+
} = _ref2;
|
|
62
64
|
let response;
|
|
63
65
|
|
|
64
66
|
try {
|
|
@@ -84,11 +86,13 @@ async function request({
|
|
|
84
86
|
return json;
|
|
85
87
|
}
|
|
86
88
|
|
|
87
|
-
function dealWithError({
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
89
|
+
function dealWithError(_ref3) {
|
|
90
|
+
let {
|
|
91
|
+
response,
|
|
92
|
+
json,
|
|
93
|
+
credentials
|
|
94
|
+
} = _ref3;
|
|
95
|
+
|
|
92
96
|
switch (response.status) {
|
|
93
97
|
case 401:
|
|
94
98
|
throw new Error("Unauthorized access to Maps API: invalid combination of user ('".concat(credentials.username, "') and apiKey ('").concat(credentials.apiKey, "')"));
|
|
@@ -108,21 +112,23 @@ function initURLParameters(credentials) {
|
|
|
108
112
|
return [encodedApiKey, encodedClient];
|
|
109
113
|
}
|
|
110
114
|
|
|
111
|
-
function buildURLMapsAPIv1({
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
+
function buildURLMapsAPIv1(_ref4) {
|
|
116
|
+
let {
|
|
117
|
+
mapConfig,
|
|
118
|
+
credentials
|
|
119
|
+
} = _ref4;
|
|
115
120
|
const parameters = initURLParameters(credentials);
|
|
116
121
|
const cfg = JSON.stringify(mapConfig);
|
|
117
122
|
return "".concat(mapsUrl(credentials), "?").concat(parameters.join('&'), "&").concat(encodeParameter('config', cfg));
|
|
118
123
|
}
|
|
119
124
|
|
|
120
|
-
function buildURLMapsAPIv2({
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
125
|
+
function buildURLMapsAPIv2(_ref5) {
|
|
126
|
+
let {
|
|
127
|
+
connection,
|
|
128
|
+
type,
|
|
129
|
+
source,
|
|
130
|
+
credentials
|
|
131
|
+
} = _ref5;
|
|
126
132
|
const parameters = initURLParameters(credentials);
|
|
127
133
|
const mapsApiType = type === MAP_TYPES.QUERY ? 'sql' : type;
|
|
128
134
|
let url = "".concat(mapsUrl(credentials), "/").concat(connection, "/").concat(mapsApiType, "?");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/api/maps-client.js"],"names":["defaultClassicCredentials","getDefaultCredentials","API_VERSIONS","DEFAULT_MAPS_URL_FORMAT","DEFAULT_REGION_COMPONENT_IN_URL","DEFAULT_USER_COMPONENT_IN_URL","encodeParameter","MAP_TYPES","CONNECTIONS","BIGQUERY","CARTO","BUFFER_SIZE","TILE_EXTENT","getDataV2","type","source","credentials","defaultCredentials","apiVersion","localCreds","mapsUrl","url","connection","V1","mapConfig","createMapConfig","buildURLMapsAPIv1","layergroup","request","metadata","tilejson","vector","V2","buildURLMapsAPIv2","Error","response","fetch","headers","Accept","error","json","ok","dealWithError","status","username","apiKey","e","JSON","stringify","errors","initURLParameters","encodedApiKey","encodedClient","parameters","cfg","join","mapsApiType","QUERY","replace","region","sql","version","buffersize","mvt","layers","options","vector_extent"],"mappings":"AAGA,SAAQA,yBAAR,EAAmCC,qBAAnC,QAA+D,WAA/D;AACA,SACEC,YADF,EAEEC,uBAFF,EAGEC,+BAHF,EAIEC,6BAJF,EAKEC,eALF,EAMEC,SANF,QAOO,mBAPP;AASA,OAAO,MAAMC,WAAW,GAAG;AACzBC,EAAAA,QAAQ,EAAE,UADe;AAEzBC,EAAAA,KAAK,EAAE;AAFkB,CAApB;AAKP,MAAMC,WAAW,GAAG,EAApB;AACA,MAAMC,WAAW,GAAG,IAApB;AAKA,OAAO,eAAeC,SAAf,
|
|
1
|
+
{"version":3,"sources":["../../../src/api/maps-client.js"],"names":["defaultClassicCredentials","getDefaultCredentials","API_VERSIONS","DEFAULT_MAPS_URL_FORMAT","DEFAULT_REGION_COMPONENT_IN_URL","DEFAULT_USER_COMPONENT_IN_URL","encodeParameter","MAP_TYPES","CONNECTIONS","BIGQUERY","CARTO","BUFFER_SIZE","TILE_EXTENT","getDataV2","type","source","credentials","defaultCredentials","apiVersion","localCreds","mapsUrl","url","connection","V1","mapConfig","createMapConfig","buildURLMapsAPIv1","layergroup","request","metadata","tilejson","vector","V2","buildURLMapsAPIv2","Error","response","fetch","headers","Accept","error","json","ok","dealWithError","status","username","apiKey","e","JSON","stringify","errors","initURLParameters","encodedApiKey","encodedClient","parameters","cfg","join","mapsApiType","QUERY","replace","region","sql","version","buffersize","mvt","layers","options","vector_extent"],"mappings":"AAGA,SAAQA,yBAAR,EAAmCC,qBAAnC,QAA+D,WAA/D;AACA,SACEC,YADF,EAEEC,uBAFF,EAGEC,+BAHF,EAIEC,6BAJF,EAKEC,eALF,EAMEC,SANF,QAOO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C,MAAP;AACAnC,EAAAA,GAAG,cAAOf,eAAe,CAAC,QAAD,EAAWS,MAAX,CAAtB,8BAA4DsC,UAAU,CAACE,IAAX,CAAgB,GAAhB,CAA5D,CAAH;AACA,SAAOlC,GAAP;AACD;;AAKD,SAASD,OAAT,CAAiBJ,WAAjB,EAA8B;AAC5B,SAAOA,WAAW,CAACI,OAAZ,CACJsC,OADI,CACIrD,6BADJ,EACmCW,WAAW,CAAC4B,QAD/C,EAEJc,OAFI,CAEItD,+BAFJ,EAEqCY,WAAW,CAAC2C,MAFjD,CAAP;AAGD;;AAED,SAASlC,eAAT,CAAyBmC,GAAzB,EAA8B;AAC5B,SAAO;AACLC,IAAAA,OAAO,EAAE,OADJ;AAELC,IAAAA,UAAU,EAAE;AACVC,MAAAA,GAAG,EAAEpD;AADK,KAFP;AAKLqD,IAAAA,MAAM,EAAE,CACN;AACElD,MAAAA,IAAI,EAAE,QADR;AAEEmD,MAAAA,OAAO,EAAE;AACPL,QAAAA,GADO;AAEPM,QAAAA,aAAa,EAAEtD;AAFR;AAFX,KADM;AALH,GAAP;AAeD","sourcesContent":["/**\n * Maps API Client for Maps API v1 and Maps API v2\n */\nimport {defaultClassicCredentials, getDefaultCredentials} from '../config';\nimport {\n API_VERSIONS,\n DEFAULT_MAPS_URL_FORMAT,\n DEFAULT_REGION_COMPONENT_IN_URL,\n DEFAULT_USER_COMPONENT_IN_URL,\n encodeParameter,\n MAP_TYPES\n} from './maps-api-common';\n\nexport const CONNECTIONS = {\n BIGQUERY: 'bigquery',\n CARTO: 'carto'\n};\n\nconst BUFFER_SIZE = 16;\nconst TILE_EXTENT = 4096;\n\n/**\n * Obtain a TileJson from Maps API v1 and v2\n */\nexport async function getDataV2({type, source, credentials}) {\n const defaultCredentials = getDefaultCredentials();\n const apiVersion = (credentials && credentials.apiVersion) || defaultCredentials.apiVersion;\n // Only pick up default credentials if they have been defined for\n // correct API version\n const localCreds = {\n ...defaultClassicCredentials,\n ...(defaultCredentials.apiVersion === apiVersion && defaultCredentials),\n ...credentials\n };\n\n if (!localCreds.mapsUrl) {\n localCreds.mapsUrl = DEFAULT_MAPS_URL_FORMAT[apiVersion];\n }\n\n let url;\n\n const connection = type === 'tileset' ? CONNECTIONS.BIGQUERY : CONNECTIONS.CARTO;\n\n switch (apiVersion) {\n case API_VERSIONS.V1:\n // Maps API v1\n const mapConfig = createMapConfig(source);\n url = buildURLMapsAPIv1({mapConfig, credentials: localCreds});\n const layergroup = await request({url, credentials: localCreds});\n return layergroup.metadata.tilejson.vector;\n\n case API_VERSIONS.V2:\n // Maps API v2\n url = buildURLMapsAPIv2({connection, type, source, credentials: localCreds});\n return await request({url, credentials: localCreds});\n\n default:\n throw new Error(\n `Invalid maps API version. It shoud be ${API_VERSIONS.V1} or ${API_VERSIONS.V2}`\n );\n }\n}\n\n/**\n * Request against Maps API\n */\nasync function request({url, credentials}) {\n let response;\n\n try {\n /* global fetch */\n /* eslint no-undef: \"error\" */\n response = await fetch(url, {\n headers: {\n Accept: 'application/json'\n }\n });\n } catch (error) {\n throw new Error(`Failed to connect to Maps API: ${error}`);\n }\n\n const json = await response.json();\n\n if (!response.ok) {\n dealWithError({response, json, credentials});\n }\n\n return json;\n}\n\n/**\n * Display proper message from Maps API error\n */\nfunction dealWithError({response, json, credentials}) {\n switch (response.status) {\n case 401:\n throw new Error(\n `Unauthorized access to Maps API: invalid combination of user ('${\n credentials.username\n }') and apiKey ('${credentials.apiKey}')`\n );\n case 403:\n throw new Error(\n `Unauthorized access to dataset: the provided apiKey('${\n credentials.apiKey\n }') doesn't provide access to the requested data`\n );\n\n default:\n const e =\n credentials.apiVersion === API_VERSIONS.V1 ? JSON.stringify(json.errors) : json.error;\n throw new Error(e);\n }\n}\n\nfunction initURLParameters(credentials) {\n const encodedApiKey = encodeParameter('api_key', credentials.apiKey);\n const encodedClient = encodeParameter('client', `deck-gl-carto`);\n return [encodedApiKey, encodedClient];\n}\n\n/**\n * Build a URL with all required parameters\n */\nfunction buildURLMapsAPIv1({mapConfig, credentials}) {\n const parameters = initURLParameters(credentials);\n const cfg = JSON.stringify(mapConfig);\n return `${mapsUrl(credentials)}?${parameters.join('&')}&${encodeParameter('config', cfg)}`;\n}\n\nfunction buildURLMapsAPIv2({connection, type, source, credentials}) {\n const parameters = initURLParameters(credentials);\n // Query type is mapped to 'sql' at maps api v1\n const mapsApiType = type === MAP_TYPES.QUERY ? 'sql' : type;\n let url = `${mapsUrl(credentials)}/${connection}/${mapsApiType}?`;\n url += `${encodeParameter('source', source)}&format=tilejson&${parameters.join('&')}`;\n return url;\n}\n\n/**\n * Prepare a url valid for the specified user\n */\nfunction mapsUrl(credentials) {\n return credentials.mapsUrl\n .replace(DEFAULT_USER_COMPONENT_IN_URL, credentials.username)\n .replace(DEFAULT_REGION_COMPONENT_IN_URL, credentials.region);\n}\n\nfunction createMapConfig(sql) {\n return {\n version: '1.3.1',\n buffersize: {\n mvt: BUFFER_SIZE\n },\n layers: [\n {\n type: 'mapnik',\n options: {\n sql,\n vector_extent: TILE_EXTENT\n }\n }\n ]\n };\n}\n"],"file":"maps-client.js"}
|
|
@@ -3,13 +3,14 @@ import { API_VERSIONS, encodeParameter, FORMATS, MAP_TYPES } from './maps-api-co
|
|
|
3
3
|
import { log } from '@deck.gl/core';
|
|
4
4
|
const MAX_GET_LENGTH = 2048;
|
|
5
5
|
|
|
6
|
-
async function request({
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
async function request(_ref) {
|
|
7
|
+
let {
|
|
8
|
+
method,
|
|
9
|
+
url,
|
|
10
|
+
format,
|
|
11
|
+
accessToken,
|
|
12
|
+
body
|
|
13
|
+
} = _ref;
|
|
13
14
|
let response;
|
|
14
15
|
const headers = {
|
|
15
16
|
Accept: 'application/json'
|
|
@@ -49,10 +50,12 @@ async function request({
|
|
|
49
50
|
return json.rows ? json.rows : json;
|
|
50
51
|
}
|
|
51
52
|
|
|
52
|
-
function dealWithError({
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
function dealWithError(_ref2) {
|
|
54
|
+
let {
|
|
55
|
+
response,
|
|
56
|
+
error
|
|
57
|
+
} = _ref2;
|
|
58
|
+
|
|
56
59
|
switch (response.status) {
|
|
57
60
|
case 400:
|
|
58
61
|
throw new Error("Bad request. ".concat(error));
|
|
@@ -66,13 +69,14 @@ function dealWithError({
|
|
|
66
69
|
}
|
|
67
70
|
}
|
|
68
71
|
|
|
69
|
-
function getParameters({
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
function getParameters(_ref3) {
|
|
73
|
+
let {
|
|
74
|
+
type,
|
|
75
|
+
source,
|
|
76
|
+
geoColumn,
|
|
77
|
+
columns,
|
|
78
|
+
schema
|
|
79
|
+
} = _ref3;
|
|
76
80
|
const parameters = [encodeParameter('client', 'deck-gl-carto')];
|
|
77
81
|
|
|
78
82
|
if (schema) {
|
|
@@ -95,15 +99,16 @@ function getParameters({
|
|
|
95
99
|
return parameters.join('&');
|
|
96
100
|
}
|
|
97
101
|
|
|
98
|
-
export async function mapInstantiation({
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
102
|
+
export async function mapInstantiation(_ref4) {
|
|
103
|
+
let {
|
|
104
|
+
type,
|
|
105
|
+
source,
|
|
106
|
+
connection,
|
|
107
|
+
credentials,
|
|
108
|
+
geoColumn,
|
|
109
|
+
columns,
|
|
110
|
+
schema
|
|
111
|
+
} = _ref4;
|
|
107
112
|
const baseUrl = "".concat(credentials.mapsUrl, "/").concat(connection, "/").concat(type);
|
|
108
113
|
const url = "".concat(baseUrl, "?").concat(getParameters({
|
|
109
114
|
type,
|
|
@@ -148,12 +153,13 @@ function getUrlFromMetadata(metadata, format) {
|
|
|
148
153
|
return null;
|
|
149
154
|
}
|
|
150
155
|
|
|
151
|
-
function checkGetLayerDataParameters({
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
156
|
+
function checkGetLayerDataParameters(_ref5) {
|
|
157
|
+
let {
|
|
158
|
+
type,
|
|
159
|
+
source,
|
|
160
|
+
connection,
|
|
161
|
+
localCreds
|
|
162
|
+
} = _ref5;
|
|
157
163
|
log.assert(connection, 'Must define connection');
|
|
158
164
|
log.assert(type, 'Must define a type');
|
|
159
165
|
log.assert(source, 'Must define a source');
|
|
@@ -162,16 +168,17 @@ function checkGetLayerDataParameters({
|
|
|
162
168
|
log.assert(localCreds.accessToken, 'Must define an accessToken');
|
|
163
169
|
}
|
|
164
170
|
|
|
165
|
-
export async function fetchLayerData({
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
171
|
+
export async function fetchLayerData(_ref6) {
|
|
172
|
+
let {
|
|
173
|
+
type,
|
|
174
|
+
source,
|
|
175
|
+
connection,
|
|
176
|
+
credentials,
|
|
177
|
+
geoColumn,
|
|
178
|
+
columns,
|
|
179
|
+
format,
|
|
180
|
+
schema
|
|
181
|
+
} = _ref6;
|
|
175
182
|
const defaultCredentials = getDefaultCredentials();
|
|
176
183
|
const localCreds = { ...(defaultCredentials.apiVersion === API_VERSIONS.V3 && defaultCredentials),
|
|
177
184
|
...credentials
|
|
@@ -235,15 +242,16 @@ export async function fetchLayerData({
|
|
|
235
242
|
|
|
236
243
|
return result;
|
|
237
244
|
}
|
|
238
|
-
export async function getData({
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
245
|
+
export async function getData(_ref7) {
|
|
246
|
+
let {
|
|
247
|
+
type,
|
|
248
|
+
source,
|
|
249
|
+
connection,
|
|
250
|
+
credentials,
|
|
251
|
+
geoColumn,
|
|
252
|
+
columns,
|
|
253
|
+
format
|
|
254
|
+
} = _ref7;
|
|
247
255
|
const layerData = await fetchLayerData({
|
|
248
256
|
type,
|
|
249
257
|
source,
|