@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,5 +1,7 @@
|
|
|
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
|
});
|
|
@@ -8,6 +10,12 @@ exports.fetchLayerData = fetchLayerData;
|
|
|
8
10
|
exports.getData = getData;
|
|
9
11
|
exports.fetchMap = fetchMap;
|
|
10
12
|
|
|
13
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
14
|
+
|
|
15
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
16
|
+
|
|
17
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
18
|
+
|
|
11
19
|
var _config = require("../config");
|
|
12
20
|
|
|
13
21
|
var _mapsApiCommon = require("./maps-api-common");
|
|
@@ -16,58 +24,93 @@ var _parseMap = require("./parseMap");
|
|
|
16
24
|
|
|
17
25
|
var _core = require("@deck.gl/core");
|
|
18
26
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
async function request({
|
|
22
|
-
method,
|
|
23
|
-
url,
|
|
24
|
-
format,
|
|
25
|
-
accessToken,
|
|
26
|
-
body
|
|
27
|
-
}) {
|
|
28
|
-
let response;
|
|
29
|
-
const headers = {
|
|
30
|
-
Accept: 'application/json'
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
if (accessToken) {
|
|
34
|
-
headers.Authorization = "Bearer ".concat(accessToken);
|
|
35
|
-
}
|
|
27
|
+
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; }
|
|
36
28
|
|
|
37
|
-
|
|
38
|
-
headers['Content-Type'] = 'application/json';
|
|
39
|
-
}
|
|
29
|
+
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; }
|
|
40
30
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
method,
|
|
44
|
-
headers,
|
|
45
|
-
body
|
|
46
|
-
});
|
|
47
|
-
} catch (error) {
|
|
48
|
-
throw new Error("Failed to connect to Maps API: ".concat(error));
|
|
49
|
-
}
|
|
31
|
+
var MAX_GET_LENGTH = 2048;
|
|
32
|
+
var DEFAULT_CLIENT = 'deck-gl-carto';
|
|
50
33
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const json = await response.json();
|
|
56
|
-
|
|
57
|
-
if (!response.ok) {
|
|
58
|
-
dealWithError({
|
|
59
|
-
response,
|
|
60
|
-
error: json.error
|
|
61
|
-
});
|
|
62
|
-
}
|
|
34
|
+
function request(_x) {
|
|
35
|
+
return _request.apply(this, arguments);
|
|
36
|
+
}
|
|
63
37
|
|
|
64
|
-
|
|
38
|
+
function _request() {
|
|
39
|
+
_request = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(_ref) {
|
|
40
|
+
var method, url, format, accessToken, body, response, headers, json;
|
|
41
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
42
|
+
while (1) {
|
|
43
|
+
switch (_context.prev = _context.next) {
|
|
44
|
+
case 0:
|
|
45
|
+
method = _ref.method, url = _ref.url, format = _ref.format, accessToken = _ref.accessToken, body = _ref.body;
|
|
46
|
+
headers = {
|
|
47
|
+
Accept: 'application/json'
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
if (accessToken) {
|
|
51
|
+
headers.Authorization = "Bearer ".concat(accessToken);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (method === 'POST') {
|
|
55
|
+
headers['Content-Type'] = 'application/json';
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
_context.prev = 4;
|
|
59
|
+
_context.next = 7;
|
|
60
|
+
return fetch(url, {
|
|
61
|
+
method: method,
|
|
62
|
+
headers: headers,
|
|
63
|
+
body: body
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
case 7:
|
|
67
|
+
response = _context.sent;
|
|
68
|
+
_context.next = 13;
|
|
69
|
+
break;
|
|
70
|
+
|
|
71
|
+
case 10:
|
|
72
|
+
_context.prev = 10;
|
|
73
|
+
_context.t0 = _context["catch"](4);
|
|
74
|
+
throw new Error("Failed to connect to Maps API: ".concat(_context.t0));
|
|
75
|
+
|
|
76
|
+
case 13:
|
|
77
|
+
if (!(format === _mapsApiCommon.FORMATS.NDJSON)) {
|
|
78
|
+
_context.next = 15;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return _context.abrupt("return", response);
|
|
83
|
+
|
|
84
|
+
case 15:
|
|
85
|
+
_context.next = 17;
|
|
86
|
+
return response.json();
|
|
87
|
+
|
|
88
|
+
case 17:
|
|
89
|
+
json = _context.sent;
|
|
90
|
+
|
|
91
|
+
if (!response.ok) {
|
|
92
|
+
dealWithError({
|
|
93
|
+
response: response,
|
|
94
|
+
error: json.error
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return _context.abrupt("return", json.rows ? json.rows : json);
|
|
99
|
+
|
|
100
|
+
case 20:
|
|
101
|
+
case "end":
|
|
102
|
+
return _context.stop();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}, _callee, null, [[4, 10]]);
|
|
106
|
+
}));
|
|
107
|
+
return _request.apply(this, arguments);
|
|
65
108
|
}
|
|
66
109
|
|
|
67
|
-
function dealWithError({
|
|
68
|
-
response,
|
|
69
|
-
|
|
70
|
-
|
|
110
|
+
function dealWithError(_ref2) {
|
|
111
|
+
var response = _ref2.response,
|
|
112
|
+
error = _ref2.error;
|
|
113
|
+
|
|
71
114
|
switch (response.status) {
|
|
72
115
|
case 400:
|
|
73
116
|
throw new Error("Bad request. ".concat(error));
|
|
@@ -81,20 +124,20 @@ function dealWithError({
|
|
|
81
124
|
}
|
|
82
125
|
}
|
|
83
126
|
|
|
84
|
-
function getParameters({
|
|
85
|
-
type,
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
127
|
+
function getParameters(_ref3) {
|
|
128
|
+
var type = _ref3.type,
|
|
129
|
+
source = _ref3.source,
|
|
130
|
+
geoColumn = _ref3.geoColumn,
|
|
131
|
+
columns = _ref3.columns,
|
|
132
|
+
schema = _ref3.schema,
|
|
133
|
+
clientId = _ref3.clientId;
|
|
134
|
+
var parameters = [(0, _mapsApiCommon.encodeParameter)('client', clientId || DEFAULT_CLIENT)];
|
|
92
135
|
|
|
93
136
|
if (schema) {
|
|
94
137
|
parameters.push((0, _mapsApiCommon.encodeParameter)('schema', true));
|
|
95
138
|
}
|
|
96
139
|
|
|
97
|
-
|
|
140
|
+
var sourceName = type === _mapsApiCommon.MAP_TYPES.QUERY ? 'q' : 'name';
|
|
98
141
|
parameters.push((0, _mapsApiCommon.encodeParameter)(sourceName, source));
|
|
99
142
|
|
|
100
143
|
if (type === _mapsApiCommon.MAP_TYPES.TABLE) {
|
|
@@ -110,51 +153,74 @@ function getParameters({
|
|
|
110
153
|
return parameters.join('&');
|
|
111
154
|
}
|
|
112
155
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
connection,
|
|
117
|
-
credentials,
|
|
118
|
-
geoColumn,
|
|
119
|
-
columns,
|
|
120
|
-
schema
|
|
121
|
-
}) {
|
|
122
|
-
const baseUrl = "".concat(credentials.mapsUrl, "/").concat(connection, "/").concat(type);
|
|
123
|
-
const url = "".concat(baseUrl, "?").concat(getParameters({
|
|
124
|
-
type,
|
|
125
|
-
source,
|
|
126
|
-
geoColumn,
|
|
127
|
-
columns,
|
|
128
|
-
schema
|
|
129
|
-
}));
|
|
130
|
-
const {
|
|
131
|
-
accessToken
|
|
132
|
-
} = credentials;
|
|
133
|
-
const format = 'json';
|
|
134
|
-
|
|
135
|
-
if (url.length > MAX_GET_LENGTH && type === _mapsApiCommon.MAP_TYPES.QUERY) {
|
|
136
|
-
const body = JSON.stringify({
|
|
137
|
-
q: source,
|
|
138
|
-
client: 'deck-gl-carto'
|
|
139
|
-
});
|
|
140
|
-
return await request({
|
|
141
|
-
method: 'POST',
|
|
142
|
-
url: baseUrl,
|
|
143
|
-
format,
|
|
144
|
-
accessToken,
|
|
145
|
-
body
|
|
146
|
-
});
|
|
147
|
-
}
|
|
156
|
+
function mapInstantiation(_x2) {
|
|
157
|
+
return _mapInstantiation.apply(this, arguments);
|
|
158
|
+
}
|
|
148
159
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
format,
|
|
152
|
-
|
|
153
|
-
|
|
160
|
+
function _mapInstantiation() {
|
|
161
|
+
_mapInstantiation = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee2(_ref4) {
|
|
162
|
+
var type, source, connection, credentials, geoColumn, columns, schema, clientId, baseUrl, url, accessToken, format, body;
|
|
163
|
+
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
164
|
+
while (1) {
|
|
165
|
+
switch (_context2.prev = _context2.next) {
|
|
166
|
+
case 0:
|
|
167
|
+
type = _ref4.type, source = _ref4.source, connection = _ref4.connection, credentials = _ref4.credentials, geoColumn = _ref4.geoColumn, columns = _ref4.columns, schema = _ref4.schema, clientId = _ref4.clientId;
|
|
168
|
+
baseUrl = "".concat(credentials.mapsUrl, "/").concat(connection, "/").concat(type);
|
|
169
|
+
url = "".concat(baseUrl, "?").concat(getParameters({
|
|
170
|
+
type: type,
|
|
171
|
+
source: source,
|
|
172
|
+
geoColumn: geoColumn,
|
|
173
|
+
columns: columns,
|
|
174
|
+
schema: schema,
|
|
175
|
+
clientId: clientId
|
|
176
|
+
}));
|
|
177
|
+
accessToken = credentials.accessToken;
|
|
178
|
+
format = 'json';
|
|
179
|
+
|
|
180
|
+
if (!(url.length > MAX_GET_LENGTH && type === _mapsApiCommon.MAP_TYPES.QUERY)) {
|
|
181
|
+
_context2.next = 10;
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
body = JSON.stringify({
|
|
186
|
+
q: source,
|
|
187
|
+
client: clientId || DEFAULT_CLIENT
|
|
188
|
+
});
|
|
189
|
+
_context2.next = 9;
|
|
190
|
+
return request({
|
|
191
|
+
method: 'POST',
|
|
192
|
+
url: baseUrl,
|
|
193
|
+
format: format,
|
|
194
|
+
accessToken: accessToken,
|
|
195
|
+
body: body
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
case 9:
|
|
199
|
+
return _context2.abrupt("return", _context2.sent);
|
|
200
|
+
|
|
201
|
+
case 10:
|
|
202
|
+
_context2.next = 12;
|
|
203
|
+
return request({
|
|
204
|
+
url: url,
|
|
205
|
+
format: format,
|
|
206
|
+
accessToken: accessToken
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
case 12:
|
|
210
|
+
return _context2.abrupt("return", _context2.sent);
|
|
211
|
+
|
|
212
|
+
case 13:
|
|
213
|
+
case "end":
|
|
214
|
+
return _context2.stop();
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}, _callee2);
|
|
218
|
+
}));
|
|
219
|
+
return _mapInstantiation.apply(this, arguments);
|
|
154
220
|
}
|
|
155
221
|
|
|
156
222
|
function getUrlFromMetadata(metadata, format) {
|
|
157
|
-
|
|
223
|
+
var m = metadata[format];
|
|
158
224
|
|
|
159
225
|
if (m && !m.error && m.url) {
|
|
160
226
|
return m.url[0];
|
|
@@ -163,12 +229,12 @@ function getUrlFromMetadata(metadata, format) {
|
|
|
163
229
|
return null;
|
|
164
230
|
}
|
|
165
231
|
|
|
166
|
-
function checkFetchLayerDataParameters({
|
|
167
|
-
type,
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
232
|
+
function checkFetchLayerDataParameters(_ref5) {
|
|
233
|
+
var type = _ref5.type,
|
|
234
|
+
source = _ref5.source,
|
|
235
|
+
connection = _ref5.connection,
|
|
236
|
+
localCreds = _ref5.localCreds;
|
|
237
|
+
|
|
172
238
|
_core.log.assert(connection, 'Must define connection');
|
|
173
239
|
|
|
174
240
|
_core.log.assert(type, 'Must define a type');
|
|
@@ -182,233 +248,390 @@ function checkFetchLayerDataParameters({
|
|
|
182
248
|
_core.log.assert(localCreds.accessToken, 'Must define an accessToken');
|
|
183
249
|
}
|
|
184
250
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
source,
|
|
188
|
-
connection,
|
|
189
|
-
credentials,
|
|
190
|
-
geoColumn,
|
|
191
|
-
columns,
|
|
192
|
-
format,
|
|
193
|
-
schema
|
|
194
|
-
}) {
|
|
195
|
-
const {
|
|
196
|
-
url,
|
|
197
|
-
accessToken,
|
|
198
|
-
mapFormat,
|
|
199
|
-
metadata
|
|
200
|
-
} = await _fetchDataUrl({
|
|
201
|
-
type,
|
|
202
|
-
source,
|
|
203
|
-
connection,
|
|
204
|
-
credentials,
|
|
205
|
-
geoColumn,
|
|
206
|
-
columns,
|
|
207
|
-
format,
|
|
208
|
-
schema
|
|
209
|
-
});
|
|
210
|
-
const data = await request({
|
|
211
|
-
url,
|
|
212
|
-
format: mapFormat,
|
|
213
|
-
accessToken
|
|
214
|
-
});
|
|
215
|
-
const result = {
|
|
216
|
-
data,
|
|
217
|
-
format: mapFormat
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
if (schema) {
|
|
221
|
-
result.schema = metadata.schema;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
return result;
|
|
251
|
+
function fetchLayerData(_x3) {
|
|
252
|
+
return _fetchLayerData.apply(this, arguments);
|
|
225
253
|
}
|
|
226
254
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
255
|
+
function _fetchLayerData() {
|
|
256
|
+
_fetchLayerData = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee3(_ref6) {
|
|
257
|
+
var type, source, connection, credentials, geoColumn, columns, format, schema, clientId, _yield$_fetchDataUrl, url, accessToken, mapFormat, metadata, data, result;
|
|
258
|
+
|
|
259
|
+
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
260
|
+
while (1) {
|
|
261
|
+
switch (_context3.prev = _context3.next) {
|
|
262
|
+
case 0:
|
|
263
|
+
type = _ref6.type, source = _ref6.source, connection = _ref6.connection, credentials = _ref6.credentials, geoColumn = _ref6.geoColumn, columns = _ref6.columns, format = _ref6.format, schema = _ref6.schema, clientId = _ref6.clientId;
|
|
264
|
+
_context3.next = 3;
|
|
265
|
+
return _fetchDataUrl({
|
|
266
|
+
type: type,
|
|
267
|
+
source: source,
|
|
268
|
+
connection: connection,
|
|
269
|
+
credentials: credentials,
|
|
270
|
+
geoColumn: geoColumn,
|
|
271
|
+
columns: columns,
|
|
272
|
+
format: format,
|
|
273
|
+
schema: schema,
|
|
274
|
+
clientId: clientId
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
case 3:
|
|
278
|
+
_yield$_fetchDataUrl = _context3.sent;
|
|
279
|
+
url = _yield$_fetchDataUrl.url;
|
|
280
|
+
accessToken = _yield$_fetchDataUrl.accessToken;
|
|
281
|
+
mapFormat = _yield$_fetchDataUrl.mapFormat;
|
|
282
|
+
metadata = _yield$_fetchDataUrl.metadata;
|
|
283
|
+
_context3.next = 10;
|
|
284
|
+
return request({
|
|
285
|
+
url: url,
|
|
286
|
+
format: mapFormat,
|
|
287
|
+
accessToken: accessToken
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
case 10:
|
|
291
|
+
data = _context3.sent;
|
|
292
|
+
result = {
|
|
293
|
+
data: data,
|
|
294
|
+
format: mapFormat
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
if (schema) {
|
|
298
|
+
result.schema = metadata.schema;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
return _context3.abrupt("return", result);
|
|
302
|
+
|
|
303
|
+
case 14:
|
|
304
|
+
case "end":
|
|
305
|
+
return _context3.stop();
|
|
306
|
+
}
|
|
278
307
|
}
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
const {
|
|
283
|
-
accessToken
|
|
284
|
-
} = localCreds;
|
|
285
|
-
return {
|
|
286
|
-
url,
|
|
287
|
-
accessToken,
|
|
288
|
-
mapFormat,
|
|
289
|
-
metadata
|
|
290
|
-
};
|
|
308
|
+
}, _callee3);
|
|
309
|
+
}));
|
|
310
|
+
return _fetchLayerData.apply(this, arguments);
|
|
291
311
|
}
|
|
292
312
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
source,
|
|
296
|
-
connection,
|
|
297
|
-
credentials,
|
|
298
|
-
geoColumn,
|
|
299
|
-
columns,
|
|
300
|
-
format
|
|
301
|
-
}) {
|
|
302
|
-
_core.log.deprecated('getData', 'fetchLayerData')();
|
|
303
|
-
|
|
304
|
-
const layerData = await fetchLayerData({
|
|
305
|
-
type,
|
|
306
|
-
source,
|
|
307
|
-
connection,
|
|
308
|
-
credentials,
|
|
309
|
-
geoColumn,
|
|
310
|
-
columns,
|
|
311
|
-
format,
|
|
312
|
-
schema: false
|
|
313
|
-
});
|
|
314
|
-
return layerData.data;
|
|
313
|
+
function _fetchDataUrl(_x4) {
|
|
314
|
+
return _fetchDataUrl2.apply(this, arguments);
|
|
315
315
|
}
|
|
316
316
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
317
|
+
function _fetchDataUrl2() {
|
|
318
|
+
_fetchDataUrl2 = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee4(_ref7) {
|
|
319
|
+
var type, source, connection, credentials, geoColumn, columns, format, schema, clientId, defaultCredentials, localCreds, metadata, url, mapFormat, prioritizedFormats, _i, _prioritizedFormats, f, accessToken;
|
|
320
|
+
|
|
321
|
+
return _regenerator.default.wrap(function _callee4$(_context4) {
|
|
322
|
+
while (1) {
|
|
323
|
+
switch (_context4.prev = _context4.next) {
|
|
324
|
+
case 0:
|
|
325
|
+
type = _ref7.type, source = _ref7.source, connection = _ref7.connection, credentials = _ref7.credentials, geoColumn = _ref7.geoColumn, columns = _ref7.columns, format = _ref7.format, schema = _ref7.schema, clientId = _ref7.clientId;
|
|
326
|
+
defaultCredentials = (0, _config.getDefaultCredentials)();
|
|
327
|
+
localCreds = _objectSpread(_objectSpread({}, defaultCredentials.apiVersion === _mapsApiCommon.API_VERSIONS.V3 && defaultCredentials), credentials);
|
|
328
|
+
checkFetchLayerDataParameters({
|
|
329
|
+
type: type,
|
|
330
|
+
source: source,
|
|
331
|
+
connection: connection,
|
|
332
|
+
localCreds: localCreds
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
if (!localCreds.mapsUrl) {
|
|
336
|
+
localCreds.mapsUrl = (0, _config.buildMapsUrlFromBase)(localCreds.apiBaseUrl);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
_context4.next = 7;
|
|
340
|
+
return mapInstantiation({
|
|
341
|
+
type: type,
|
|
342
|
+
source: source,
|
|
343
|
+
connection: connection,
|
|
344
|
+
credentials: localCreds,
|
|
345
|
+
geoColumn: geoColumn,
|
|
346
|
+
columns: columns,
|
|
347
|
+
schema: schema,
|
|
348
|
+
clientId: clientId
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
case 7:
|
|
352
|
+
metadata = _context4.sent;
|
|
353
|
+
|
|
354
|
+
if (!format) {
|
|
355
|
+
_context4.next = 14;
|
|
356
|
+
break;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
mapFormat = format;
|
|
360
|
+
url = getUrlFromMetadata(metadata, format);
|
|
361
|
+
|
|
362
|
+
_core.log.assert(url, "Format ".concat(format, " not available"));
|
|
363
|
+
|
|
364
|
+
_context4.next = 25;
|
|
365
|
+
break;
|
|
366
|
+
|
|
367
|
+
case 14:
|
|
368
|
+
prioritizedFormats = [_mapsApiCommon.FORMATS.GEOJSON, _mapsApiCommon.FORMATS.JSON, _mapsApiCommon.FORMATS.NDJSON, _mapsApiCommon.FORMATS.TILEJSON];
|
|
369
|
+
_i = 0, _prioritizedFormats = prioritizedFormats;
|
|
370
|
+
|
|
371
|
+
case 16:
|
|
372
|
+
if (!(_i < _prioritizedFormats.length)) {
|
|
373
|
+
_context4.next = 25;
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
f = _prioritizedFormats[_i];
|
|
378
|
+
url = getUrlFromMetadata(metadata, f);
|
|
379
|
+
|
|
380
|
+
if (!url) {
|
|
381
|
+
_context4.next = 22;
|
|
382
|
+
break;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
mapFormat = f;
|
|
386
|
+
return _context4.abrupt("break", 25);
|
|
387
|
+
|
|
388
|
+
case 22:
|
|
389
|
+
_i++;
|
|
390
|
+
_context4.next = 16;
|
|
391
|
+
break;
|
|
392
|
+
|
|
393
|
+
case 25:
|
|
394
|
+
accessToken = localCreds.accessToken;
|
|
395
|
+
return _context4.abrupt("return", {
|
|
396
|
+
url: url,
|
|
397
|
+
accessToken: accessToken,
|
|
398
|
+
mapFormat: mapFormat,
|
|
399
|
+
metadata: metadata
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
case 27:
|
|
403
|
+
case "end":
|
|
404
|
+
return _context4.stop();
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
}, _callee4);
|
|
408
|
+
}));
|
|
409
|
+
return _fetchDataUrl2.apply(this, arguments);
|
|
348
410
|
}
|
|
349
411
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
token
|
|
353
|
-
}, credentials) {
|
|
354
|
-
const promises = datasets.map(dataset => _fetchMapDataset(dataset, token, credentials));
|
|
355
|
-
return await Promise.all(promises);
|
|
412
|
+
function getData(_x5) {
|
|
413
|
+
return _getData.apply(this, arguments);
|
|
356
414
|
}
|
|
357
415
|
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
416
|
+
function _getData() {
|
|
417
|
+
_getData = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee5(_ref8) {
|
|
418
|
+
var type, source, connection, credentials, geoColumn, columns, format, clientId, layerData;
|
|
419
|
+
return _regenerator.default.wrap(function _callee5$(_context5) {
|
|
420
|
+
while (1) {
|
|
421
|
+
switch (_context5.prev = _context5.next) {
|
|
422
|
+
case 0:
|
|
423
|
+
type = _ref8.type, source = _ref8.source, connection = _ref8.connection, credentials = _ref8.credentials, geoColumn = _ref8.geoColumn, columns = _ref8.columns, format = _ref8.format, clientId = _ref8.clientId;
|
|
424
|
+
|
|
425
|
+
_core.log.deprecated('getData', 'fetchLayerData')();
|
|
426
|
+
|
|
427
|
+
_context5.next = 4;
|
|
428
|
+
return fetchLayerData({
|
|
429
|
+
type: type,
|
|
430
|
+
source: source,
|
|
431
|
+
connection: connection,
|
|
432
|
+
credentials: credentials,
|
|
433
|
+
geoColumn: geoColumn,
|
|
434
|
+
columns: columns,
|
|
435
|
+
format: format,
|
|
436
|
+
schema: false,
|
|
437
|
+
clientId: clientId
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
case 4:
|
|
441
|
+
layerData = _context5.sent;
|
|
442
|
+
return _context5.abrupt("return", layerData.data);
|
|
443
|
+
|
|
444
|
+
case 6:
|
|
445
|
+
case "end":
|
|
446
|
+
return _context5.stop();
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}, _callee5);
|
|
450
|
+
}));
|
|
451
|
+
return _getData.apply(this, arguments);
|
|
452
|
+
}
|
|
383
453
|
|
|
384
|
-
|
|
385
|
-
|
|
454
|
+
function _fetchMapDataset(_x6, _x7, _x8, _x9) {
|
|
455
|
+
return _fetchMapDataset2.apply(this, arguments);
|
|
456
|
+
}
|
|
386
457
|
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
url
|
|
390
|
-
|
|
391
|
-
|
|
458
|
+
function _fetchMapDataset2() {
|
|
459
|
+
_fetchMapDataset2 = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee6(dataset, accessToken, credentials, clientId) {
|
|
460
|
+
var connection, source, type, _yield$_fetchDataUrl2, url, mapFormat, cache, data;
|
|
461
|
+
|
|
462
|
+
return _regenerator.default.wrap(function _callee6$(_context6) {
|
|
463
|
+
while (1) {
|
|
464
|
+
switch (_context6.prev = _context6.next) {
|
|
465
|
+
case 0:
|
|
466
|
+
connection = dataset.connectionName, source = dataset.source, type = dataset.type;
|
|
467
|
+
_context6.next = 3;
|
|
468
|
+
return _fetchDataUrl({
|
|
469
|
+
credentials: _objectSpread(_objectSpread({}, credentials), {}, {
|
|
470
|
+
accessToken: accessToken
|
|
471
|
+
}),
|
|
472
|
+
connection: connection,
|
|
473
|
+
source: source,
|
|
474
|
+
type: type,
|
|
475
|
+
clientId: clientId
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
case 3:
|
|
479
|
+
_yield$_fetchDataUrl2 = _context6.sent;
|
|
480
|
+
url = _yield$_fetchDataUrl2.url;
|
|
481
|
+
mapFormat = _yield$_fetchDataUrl2.mapFormat;
|
|
482
|
+
cache = parseInt(new URLSearchParams(url).get('cache'), 10);
|
|
483
|
+
|
|
484
|
+
if (!(cache && dataset.cache === cache)) {
|
|
485
|
+
_context6.next = 9;
|
|
486
|
+
break;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
return _context6.abrupt("return", false);
|
|
490
|
+
|
|
491
|
+
case 9:
|
|
492
|
+
dataset.cache = cache;
|
|
493
|
+
_context6.next = 12;
|
|
494
|
+
return request({
|
|
495
|
+
url: url,
|
|
496
|
+
format: mapFormat,
|
|
497
|
+
accessToken: accessToken
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
case 12:
|
|
501
|
+
data = _context6.sent;
|
|
502
|
+
dataset.data = data;
|
|
503
|
+
return _context6.abrupt("return", true);
|
|
504
|
+
|
|
505
|
+
case 15:
|
|
506
|
+
case "end":
|
|
507
|
+
return _context6.stop();
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
}, _callee6);
|
|
511
|
+
}));
|
|
512
|
+
return _fetchMapDataset2.apply(this, arguments);
|
|
513
|
+
}
|
|
392
514
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
515
|
+
function fillInMapDatasets(_x10, _x11, _x12) {
|
|
516
|
+
return _fillInMapDatasets.apply(this, arguments);
|
|
517
|
+
}
|
|
396
518
|
|
|
397
|
-
|
|
398
|
-
|
|
519
|
+
function _fillInMapDatasets() {
|
|
520
|
+
_fillInMapDatasets = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee7(_ref9, clientId, credentials) {
|
|
521
|
+
var datasets, token, promises;
|
|
522
|
+
return _regenerator.default.wrap(function _callee7$(_context7) {
|
|
523
|
+
while (1) {
|
|
524
|
+
switch (_context7.prev = _context7.next) {
|
|
525
|
+
case 0:
|
|
526
|
+
datasets = _ref9.datasets, token = _ref9.token;
|
|
527
|
+
promises = datasets.map(function (dataset) {
|
|
528
|
+
return _fetchMapDataset(dataset, token, credentials, clientId);
|
|
529
|
+
});
|
|
530
|
+
_context7.next = 4;
|
|
531
|
+
return Promise.all(promises);
|
|
532
|
+
|
|
533
|
+
case 4:
|
|
534
|
+
return _context7.abrupt("return", _context7.sent);
|
|
535
|
+
|
|
536
|
+
case 5:
|
|
537
|
+
case "end":
|
|
538
|
+
return _context7.stop();
|
|
539
|
+
}
|
|
399
540
|
}
|
|
400
|
-
},
|
|
541
|
+
}, _callee7);
|
|
542
|
+
}));
|
|
543
|
+
return _fillInMapDatasets.apply(this, arguments);
|
|
544
|
+
}
|
|
401
545
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
}
|
|
546
|
+
function fetchMap(_x13) {
|
|
547
|
+
return _fetchMap.apply(this, arguments);
|
|
548
|
+
}
|
|
406
549
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
550
|
+
function _fetchMap() {
|
|
551
|
+
_fetchMap = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee9(_ref10) {
|
|
552
|
+
var cartoMapId, clientId, credentials, autoRefresh, onNewData, defaultCredentials, localCreds, url, map, stopAutoRefresh, intervalId;
|
|
553
|
+
return _regenerator.default.wrap(function _callee9$(_context9) {
|
|
554
|
+
while (1) {
|
|
555
|
+
switch (_context9.prev = _context9.next) {
|
|
556
|
+
case 0:
|
|
557
|
+
cartoMapId = _ref10.cartoMapId, clientId = _ref10.clientId, credentials = _ref10.credentials, autoRefresh = _ref10.autoRefresh, onNewData = _ref10.onNewData;
|
|
558
|
+
defaultCredentials = (0, _config.getDefaultCredentials)();
|
|
559
|
+
localCreds = _objectSpread(_objectSpread({}, defaultCredentials.apiVersion === _mapsApiCommon.API_VERSIONS.V3 && defaultCredentials), credentials);
|
|
560
|
+
|
|
561
|
+
_core.log.assert(cartoMapId, "Must define CARTO map id: fetchMap({cartoMapId: 'XXXX-XXXX-XXXX'})");
|
|
562
|
+
|
|
563
|
+
_core.log.assert(localCreds.apiVersion === _mapsApiCommon.API_VERSIONS.V3, 'Method only available for v3');
|
|
564
|
+
|
|
565
|
+
_core.log.assert(localCreds.apiBaseUrl, 'Must define apiBaseUrl');
|
|
566
|
+
|
|
567
|
+
if (!localCreds.mapsUrl) {
|
|
568
|
+
localCreds.mapsUrl = (0, _config.buildMapsUrlFromBase)(localCreds.apiBaseUrl);
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
if (autoRefresh || onNewData) {
|
|
572
|
+
_core.log.assert(onNewData, 'Must define `onNewData` when using autoRefresh');
|
|
573
|
+
|
|
574
|
+
_core.log.assert(typeof onNewData === 'function', '`onNewData` must be a function');
|
|
575
|
+
|
|
576
|
+
_core.log.assert(autoRefresh > 0, '`autoRefresh` must be a positive number');
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
url = "".concat(localCreds.mapsUrl, "/public/").concat(cartoMapId);
|
|
580
|
+
_context9.next = 11;
|
|
581
|
+
return request({
|
|
582
|
+
url: url
|
|
583
|
+
});
|
|
584
|
+
|
|
585
|
+
case 11:
|
|
586
|
+
map = _context9.sent;
|
|
587
|
+
|
|
588
|
+
if (autoRefresh) {
|
|
589
|
+
intervalId = setInterval((0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee8() {
|
|
590
|
+
var changed;
|
|
591
|
+
return _regenerator.default.wrap(function _callee8$(_context8) {
|
|
592
|
+
while (1) {
|
|
593
|
+
switch (_context8.prev = _context8.next) {
|
|
594
|
+
case 0:
|
|
595
|
+
_context8.next = 2;
|
|
596
|
+
return fillInMapDatasets(map, clientId, credentials);
|
|
597
|
+
|
|
598
|
+
case 2:
|
|
599
|
+
changed = _context8.sent;
|
|
600
|
+
|
|
601
|
+
if (changed.some(function (v) {
|
|
602
|
+
return v === true;
|
|
603
|
+
})) {
|
|
604
|
+
onNewData((0, _parseMap.parseMap)(map));
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
case 4:
|
|
608
|
+
case "end":
|
|
609
|
+
return _context8.stop();
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
}, _callee8);
|
|
613
|
+
})), autoRefresh * 1000);
|
|
614
|
+
|
|
615
|
+
stopAutoRefresh = function stopAutoRefresh() {
|
|
616
|
+
clearInterval(intervalId);
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
_context9.next = 15;
|
|
621
|
+
return fillInMapDatasets(map, clientId, credentials);
|
|
622
|
+
|
|
623
|
+
case 15:
|
|
624
|
+
return _context9.abrupt("return", _objectSpread(_objectSpread({}, (0, _parseMap.parseMap)(map)), {
|
|
625
|
+
stopAutoRefresh: stopAutoRefresh
|
|
626
|
+
}));
|
|
627
|
+
|
|
628
|
+
case 16:
|
|
629
|
+
case "end":
|
|
630
|
+
return _context9.stop();
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
}, _callee9);
|
|
634
|
+
}));
|
|
635
|
+
return _fetchMap.apply(this, arguments);
|
|
413
636
|
}
|
|
414
637
|
//# sourceMappingURL=maps-v3-client.js.map
|