@deck.gl/carto 8.7.0-alpha.3 → 8.7.0-beta.1
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 +29663 -10643
- package/dist/es5/api/index.js +9 -9
- package/dist/es5/api/layer-map.js +98 -72
- package/dist/es5/api/layer-map.js.map +1 -1
- package/dist/es5/api/maps-api-common.js +13 -9
- package/dist/es5/api/maps-api-common.js.map +1 -1
- package/dist/es5/api/maps-client.js +157 -98
- package/dist/es5/api/maps-client.js.map +1 -1
- package/dist/es5/api/maps-v3-client.js +535 -312
- package/dist/es5/api/maps-v3-client.js.map +1 -1
- package/dist/es5/api/parseMap.js +103 -101
- package/dist/es5/api/parseMap.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 -18
- package/dist/es5/config.js.map +1 -1
- package/dist/es5/index.js +15 -15
- package/dist/es5/layers/carto-dynamic-tile-layer.js +166 -0
- package/dist/es5/layers/carto-dynamic-tile-layer.js.map +1 -0
- package/dist/es5/layers/carto-layer.js +215 -129
- package/dist/es5/layers/carto-layer.js.map +1 -1
- package/dist/es5/style/color-bins-style.js +15 -12
- package/dist/es5/style/color-bins-style.js.map +1 -1
- package/dist/es5/style/color-categories-style.js +43 -16
- package/dist/es5/style/color-categories-style.js.map +1 -1
- package/dist/es5/style/color-continuous-style.js +15 -12
- package/dist/es5/style/color-continuous-style.js.map +1 -1
- package/dist/es5/style/palette.js +23 -13
- package/dist/es5/style/palette.js.map +1 -1
- package/dist/es5/style/utils.js +13 -6
- package/dist/es5/style/utils.js.map +1 -1
- package/dist/esm/api/layer-map.js +8 -1
- package/dist/esm/api/layer-map.js.map +1 -1
- package/dist/esm/api/maps-v3-client.js +29 -17
- package/dist/esm/api/maps-v3-client.js.map +1 -1
- package/dist/esm/api/parseMap.js +31 -26
- package/dist/esm/api/parseMap.js.map +1 -1
- package/dist/esm/layers/carto-dynamic-tile-layer.js +97 -0
- package/dist/esm/layers/carto-dynamic-tile-layer.js.map +1 -0
- package/dist/esm/layers/carto-layer.js +8 -1
- package/dist/esm/layers/carto-layer.js.map +1 -1
- package/dist/esm/style/color-bins-style.js +1 -1
- package/dist/esm/style/color-bins-style.js.map +1 -1
- package/dist/esm/style/color-continuous-style.js +1 -1
- package/dist/esm/style/color-continuous-style.js.map +1 -1
- package/dist.min.js +4 -4
- package/package.json +8 -7
- package/src/api/layer-map.js +13 -1
- package/src/api/maps-v3-client.js +35 -18
- package/src/api/parseMap.js +23 -19
- package/src/layers/carto-dynamic-tile-layer.js +86 -0
- package/src/layers/carto-layer.js +10 -4
- package/src/style/color-bins-style.js +1 -1
- package/src/style/color-continuous-style.js +1 -1
|
@@ -1,106 +1,167 @@
|
|
|
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
8
|
exports.getDataV2 = getDataV2;
|
|
7
9
|
exports.CONNECTIONS = void 0;
|
|
8
10
|
|
|
11
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
12
|
+
|
|
13
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
14
|
+
|
|
15
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
16
|
+
|
|
9
17
|
var _config = require("../config");
|
|
10
18
|
|
|
11
19
|
var _mapsApiCommon = require("./maps-api-common");
|
|
12
20
|
|
|
13
|
-
|
|
21
|
+
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; }
|
|
22
|
+
|
|
23
|
+
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; }
|
|
24
|
+
|
|
25
|
+
var CONNECTIONS = {
|
|
14
26
|
BIGQUERY: 'bigquery',
|
|
15
27
|
CARTO: 'carto'
|
|
16
28
|
};
|
|
17
29
|
exports.CONNECTIONS = CONNECTIONS;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
async function getDataV2({
|
|
22
|
-
type,
|
|
23
|
-
source,
|
|
24
|
-
credentials
|
|
25
|
-
}) {
|
|
26
|
-
const defaultCredentials = (0, _config.getDefaultCredentials)();
|
|
27
|
-
const apiVersion = credentials && credentials.apiVersion || defaultCredentials.apiVersion;
|
|
28
|
-
const localCreds = { ..._config.defaultClassicCredentials,
|
|
29
|
-
...(defaultCredentials.apiVersion === apiVersion && defaultCredentials),
|
|
30
|
-
...credentials
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
if (!localCreds.mapsUrl) {
|
|
34
|
-
localCreds.mapsUrl = _mapsApiCommon.DEFAULT_MAPS_URL_FORMAT[apiVersion];
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
let url;
|
|
38
|
-
const connection = type === 'tileset' ? CONNECTIONS.BIGQUERY : CONNECTIONS.CARTO;
|
|
39
|
-
|
|
40
|
-
switch (apiVersion) {
|
|
41
|
-
case _mapsApiCommon.API_VERSIONS.V1:
|
|
42
|
-
const mapConfig = createMapConfig(source);
|
|
43
|
-
url = buildURLMapsAPIv1({
|
|
44
|
-
mapConfig,
|
|
45
|
-
credentials: localCreds
|
|
46
|
-
});
|
|
47
|
-
const layergroup = await request({
|
|
48
|
-
url,
|
|
49
|
-
credentials: localCreds
|
|
50
|
-
});
|
|
51
|
-
return layergroup.metadata.tilejson.vector;
|
|
52
|
-
|
|
53
|
-
case _mapsApiCommon.API_VERSIONS.V2:
|
|
54
|
-
url = buildURLMapsAPIv2({
|
|
55
|
-
connection,
|
|
56
|
-
type,
|
|
57
|
-
source,
|
|
58
|
-
credentials: localCreds
|
|
59
|
-
});
|
|
60
|
-
return await request({
|
|
61
|
-
url,
|
|
62
|
-
credentials: localCreds
|
|
63
|
-
});
|
|
30
|
+
var BUFFER_SIZE = 16;
|
|
31
|
+
var TILE_EXTENT = 4096;
|
|
64
32
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
33
|
+
function getDataV2(_x) {
|
|
34
|
+
return _getDataV.apply(this, arguments);
|
|
68
35
|
}
|
|
69
36
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
37
|
+
function _getDataV() {
|
|
38
|
+
_getDataV = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(_ref) {
|
|
39
|
+
var type, source, credentials, defaultCredentials, apiVersion, localCreds, url, connection, mapConfig, layergroup;
|
|
40
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
41
|
+
while (1) {
|
|
42
|
+
switch (_context.prev = _context.next) {
|
|
43
|
+
case 0:
|
|
44
|
+
type = _ref.type, source = _ref.source, credentials = _ref.credentials;
|
|
45
|
+
defaultCredentials = (0, _config.getDefaultCredentials)();
|
|
46
|
+
apiVersion = credentials && credentials.apiVersion || defaultCredentials.apiVersion;
|
|
47
|
+
localCreds = _objectSpread(_objectSpread(_objectSpread({}, _config.defaultClassicCredentials), defaultCredentials.apiVersion === apiVersion && defaultCredentials), credentials);
|
|
48
|
+
|
|
49
|
+
if (!localCreds.mapsUrl) {
|
|
50
|
+
localCreds.mapsUrl = _mapsApiCommon.DEFAULT_MAPS_URL_FORMAT[apiVersion];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
connection = type === 'tileset' ? CONNECTIONS.BIGQUERY : CONNECTIONS.CARTO;
|
|
54
|
+
_context.t0 = apiVersion;
|
|
55
|
+
_context.next = _context.t0 === _mapsApiCommon.API_VERSIONS.V1 ? 9 : _context.t0 === _mapsApiCommon.API_VERSIONS.V2 ? 15 : 19;
|
|
56
|
+
break;
|
|
57
|
+
|
|
58
|
+
case 9:
|
|
59
|
+
mapConfig = createMapConfig(source);
|
|
60
|
+
url = buildURLMapsAPIv1({
|
|
61
|
+
mapConfig: mapConfig,
|
|
62
|
+
credentials: localCreds
|
|
63
|
+
});
|
|
64
|
+
_context.next = 13;
|
|
65
|
+
return request({
|
|
66
|
+
url: url,
|
|
67
|
+
credentials: localCreds
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
case 13:
|
|
71
|
+
layergroup = _context.sent;
|
|
72
|
+
return _context.abrupt("return", layergroup.metadata.tilejson.vector);
|
|
73
|
+
|
|
74
|
+
case 15:
|
|
75
|
+
url = buildURLMapsAPIv2({
|
|
76
|
+
connection: connection,
|
|
77
|
+
type: type,
|
|
78
|
+
source: source,
|
|
79
|
+
credentials: localCreds
|
|
80
|
+
});
|
|
81
|
+
_context.next = 18;
|
|
82
|
+
return request({
|
|
83
|
+
url: url,
|
|
84
|
+
credentials: localCreds
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
case 18:
|
|
88
|
+
return _context.abrupt("return", _context.sent);
|
|
89
|
+
|
|
90
|
+
case 19:
|
|
91
|
+
throw new Error("Invalid maps API version. It should be ".concat(_mapsApiCommon.API_VERSIONS.V1, " or ").concat(_mapsApiCommon.API_VERSIONS.V2));
|
|
92
|
+
|
|
93
|
+
case 20:
|
|
94
|
+
case "end":
|
|
95
|
+
return _context.stop();
|
|
96
|
+
}
|
|
80
97
|
}
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const json = await response.json();
|
|
98
|
+
}, _callee);
|
|
99
|
+
}));
|
|
100
|
+
return _getDataV.apply(this, arguments);
|
|
101
|
+
}
|
|
87
102
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
json,
|
|
92
|
-
credentials
|
|
93
|
-
});
|
|
94
|
-
}
|
|
103
|
+
function request(_x2) {
|
|
104
|
+
return _request.apply(this, arguments);
|
|
105
|
+
}
|
|
95
106
|
|
|
96
|
-
|
|
107
|
+
function _request() {
|
|
108
|
+
_request = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee2(_ref2) {
|
|
109
|
+
var url, credentials, response, json;
|
|
110
|
+
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
111
|
+
while (1) {
|
|
112
|
+
switch (_context2.prev = _context2.next) {
|
|
113
|
+
case 0:
|
|
114
|
+
url = _ref2.url, credentials = _ref2.credentials;
|
|
115
|
+
_context2.prev = 1;
|
|
116
|
+
_context2.next = 4;
|
|
117
|
+
return fetch(url, {
|
|
118
|
+
headers: {
|
|
119
|
+
Accept: 'application/json'
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
case 4:
|
|
124
|
+
response = _context2.sent;
|
|
125
|
+
_context2.next = 10;
|
|
126
|
+
break;
|
|
127
|
+
|
|
128
|
+
case 7:
|
|
129
|
+
_context2.prev = 7;
|
|
130
|
+
_context2.t0 = _context2["catch"](1);
|
|
131
|
+
throw new Error("Failed to connect to Maps API: ".concat(_context2.t0));
|
|
132
|
+
|
|
133
|
+
case 10:
|
|
134
|
+
_context2.next = 12;
|
|
135
|
+
return response.json();
|
|
136
|
+
|
|
137
|
+
case 12:
|
|
138
|
+
json = _context2.sent;
|
|
139
|
+
|
|
140
|
+
if (!response.ok) {
|
|
141
|
+
dealWithError({
|
|
142
|
+
response: response,
|
|
143
|
+
json: json,
|
|
144
|
+
credentials: credentials
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return _context2.abrupt("return", json);
|
|
149
|
+
|
|
150
|
+
case 15:
|
|
151
|
+
case "end":
|
|
152
|
+
return _context2.stop();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}, _callee2, null, [[1, 7]]);
|
|
156
|
+
}));
|
|
157
|
+
return _request.apply(this, arguments);
|
|
97
158
|
}
|
|
98
159
|
|
|
99
|
-
function dealWithError({
|
|
100
|
-
response,
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
160
|
+
function dealWithError(_ref3) {
|
|
161
|
+
var response = _ref3.response,
|
|
162
|
+
json = _ref3.json,
|
|
163
|
+
credentials = _ref3.credentials;
|
|
164
|
+
|
|
104
165
|
switch (response.status) {
|
|
105
166
|
case 401:
|
|
106
167
|
throw new Error("Unauthorized access to Maps API: invalid combination of user ('".concat(credentials.username, "') and apiKey ('").concat(credentials.apiKey, "')"));
|
|
@@ -109,35 +170,33 @@ function dealWithError({
|
|
|
109
170
|
throw new Error("Unauthorized access to dataset: the provided apiKey('".concat(credentials.apiKey, "') doesn't provide access to the requested data"));
|
|
110
171
|
|
|
111
172
|
default:
|
|
112
|
-
|
|
173
|
+
var e = credentials.apiVersion === _mapsApiCommon.API_VERSIONS.V1 ? JSON.stringify(json.errors) : json.error;
|
|
113
174
|
throw new Error(e);
|
|
114
175
|
}
|
|
115
176
|
}
|
|
116
177
|
|
|
117
178
|
function initURLParameters(credentials) {
|
|
118
|
-
|
|
119
|
-
|
|
179
|
+
var encodedApiKey = (0, _mapsApiCommon.encodeParameter)('api_key', credentials.apiKey);
|
|
180
|
+
var encodedClient = (0, _mapsApiCommon.encodeParameter)('client', "deck-gl-carto");
|
|
120
181
|
return [encodedApiKey, encodedClient];
|
|
121
182
|
}
|
|
122
183
|
|
|
123
|
-
function buildURLMapsAPIv1({
|
|
124
|
-
mapConfig,
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
const cfg = JSON.stringify(mapConfig);
|
|
184
|
+
function buildURLMapsAPIv1(_ref4) {
|
|
185
|
+
var mapConfig = _ref4.mapConfig,
|
|
186
|
+
credentials = _ref4.credentials;
|
|
187
|
+
var parameters = initURLParameters(credentials);
|
|
188
|
+
var cfg = JSON.stringify(mapConfig);
|
|
129
189
|
return "".concat(mapsUrl(credentials), "?").concat(parameters.join('&'), "&").concat((0, _mapsApiCommon.encodeParameter)('config', cfg));
|
|
130
190
|
}
|
|
131
191
|
|
|
132
|
-
function buildURLMapsAPIv2({
|
|
133
|
-
connection,
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
let url = "".concat(mapsUrl(credentials), "/").concat(connection, "/").concat(mapsApiType, "?");
|
|
192
|
+
function buildURLMapsAPIv2(_ref5) {
|
|
193
|
+
var connection = _ref5.connection,
|
|
194
|
+
type = _ref5.type,
|
|
195
|
+
source = _ref5.source,
|
|
196
|
+
credentials = _ref5.credentials;
|
|
197
|
+
var parameters = initURLParameters(credentials);
|
|
198
|
+
var mapsApiType = type === _mapsApiCommon.MAP_TYPES.QUERY ? 'sql' : type;
|
|
199
|
+
var url = "".concat(mapsUrl(credentials), "/").concat(connection, "/").concat(mapsApiType, "?");
|
|
141
200
|
url += "".concat((0, _mapsApiCommon.encodeParameter)('source', source), "&format=tilejson&").concat(parameters.join('&'));
|
|
142
201
|
return url;
|
|
143
202
|
}
|
|
@@ -155,7 +214,7 @@ function createMapConfig(sql) {
|
|
|
155
214
|
layers: [{
|
|
156
215
|
type: 'mapnik',
|
|
157
216
|
options: {
|
|
158
|
-
sql,
|
|
217
|
+
sql: sql,
|
|
159
218
|
vector_extent: TILE_EXTENT
|
|
160
219
|
}
|
|
161
220
|
}]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/api/maps-client.js"],"names":["CONNECTIONS","BIGQUERY","CARTO","BUFFER_SIZE","TILE_EXTENT","getDataV2","type","source","credentials","defaultCredentials","apiVersion","localCreds","defaultClassicCredentials","mapsUrl","DEFAULT_MAPS_URL_FORMAT","
|
|
1
|
+
{"version":3,"sources":["../../../src/api/maps-client.js"],"names":["CONNECTIONS","BIGQUERY","CARTO","BUFFER_SIZE","TILE_EXTENT","getDataV2","type","source","credentials","defaultCredentials","apiVersion","localCreds","defaultClassicCredentials","mapsUrl","DEFAULT_MAPS_URL_FORMAT","connection","API_VERSIONS","V1","V2","mapConfig","createMapConfig","url","buildURLMapsAPIv1","request","layergroup","metadata","tilejson","vector","buildURLMapsAPIv2","Error","fetch","headers","Accept","response","json","ok","dealWithError","status","username","apiKey","e","JSON","stringify","errors","error","initURLParameters","encodedApiKey","encodedClient","parameters","cfg","join","mapsApiType","MAP_TYPES","QUERY","replace","DEFAULT_USER_COMPONENT_IN_URL","DEFAULT_REGION_COMPONENT_IN_URL","region","sql","version","buffersize","mvt","layers","options","vector_extent"],"mappings":";;;;;;;;;;;;;;;;AAGA;;AACA;;;;;;AASO,IAAMA,WAAW,GAAG;AACzBC,EAAAA,QAAQ,EAAE,UADe;AAEzBC,EAAAA,KAAK,EAAE;AAFkB,CAApB;;AAKP,IAAMC,WAAW,GAAG,EAApB;AACA,IAAMC,WAAW,GAAG,IAApB;;SAKsBC,S;;;;;wEAAf;AAAA;AAAA;AAAA;AAAA;AAAA;AAA0BC,YAAAA,IAA1B,QAA0BA,IAA1B,EAAgCC,MAAhC,QAAgCA,MAAhC,EAAwCC,WAAxC,QAAwCA,WAAxC;AACCC,YAAAA,kBADD,GACsB,oCADtB;AAECC,YAAAA,UAFD,GAEeF,WAAW,IAAIA,WAAW,CAACE,UAA5B,IAA2CD,kBAAkB,CAACC,UAF5E;AAKCC,YAAAA,UALD,iDAMAC,iCANA,GAOCH,kBAAkB,CAACC,UAAnB,KAAkCA,UAAlC,IAAgDD,kBAPjD,GAQAD,WARA;;AAWL,gBAAI,CAACG,UAAU,CAACE,OAAhB,EAA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,OAFI,CAEIE,8CAFJ,EAEqChD,WAAW,CAACiD,MAFjD,CAAP;AAGD;;AAED,SAASrC,eAAT,CAAyBsC,GAAzB,EAA8B;AAC5B,SAAO;AACLC,IAAAA,OAAO,EAAE,OADJ;AAELC,IAAAA,UAAU,EAAE;AACVC,MAAAA,GAAG,EAAE1D;AADK,KAFP;AAKL2D,IAAAA,MAAM,EAAE,CACN;AACExD,MAAAA,IAAI,EAAE,QADR;AAEEyD,MAAAA,OAAO,EAAE;AACPL,QAAAA,GAAG,EAAHA,GADO;AAEPM,QAAAA,aAAa,EAAE5D;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 should 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 ('${credentials.username}') and apiKey ('${credentials.apiKey}')`\n );\n case 403:\n throw new Error(\n `Unauthorized access to dataset: the provided apiKey('${credentials.apiKey}') 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"}
|