@deck.gl/carto 8.6.2 → 8.7.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.dev.js +24009 -380
- package/dist/es5/api/index.js +14 -8
- package/dist/es5/api/index.js.map +1 -1
- package/dist/es5/api/layer-map.js +244 -0
- package/dist/es5/api/layer-map.js.map +1 -0
- package/dist/es5/api/maps-api-common.js +9 -13
- package/dist/es5/api/maps-api-common.js.map +1 -1
- package/dist/es5/api/maps-client.js +98 -157
- package/dist/es5/api/maps-client.js.map +1 -1
- package/dist/es5/api/maps-v3-client.js +325 -304
- package/dist/es5/api/maps-v3-client.js.map +1 -1
- package/dist/es5/api/parseMap.js +210 -0
- package/dist/es5/api/parseMap.js.map +1 -0
- package/dist/es5/basemap.js +1 -1
- package/dist/es5/basemap.js.map +1 -1
- package/dist/es5/config.js +23 -39
- package/dist/es5/config.js.map +1 -1
- package/dist/es5/index.js +22 -16
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/layers/carto-bqtiler-layer.js +6 -39
- package/dist/es5/layers/carto-bqtiler-layer.js.map +1 -1
- package/dist/es5/layers/carto-layer.js +130 -211
- package/dist/es5/layers/carto-layer.js.map +1 -1
- package/dist/es5/layers/carto-sql-layer.js +6 -39
- package/dist/es5/layers/carto-sql-layer.js.map +1 -1
- package/dist/es5/style/color-bins-style.js +14 -13
- package/dist/es5/style/color-bins-style.js.map +1 -1
- package/dist/es5/style/color-categories-style.js +16 -39
- package/dist/es5/style/color-categories-style.js.map +1 -1
- package/dist/es5/style/color-continuous-style.js +14 -13
- package/dist/es5/style/color-continuous-style.js.map +1 -1
- package/dist/es5/style/palette.js +15 -21
- package/dist/es5/style/palette.js.map +1 -1
- package/dist/es5/style/utils.js +6 -13
- package/dist/es5/style/utils.js.map +1 -1
- package/dist/esm/api/index.js +1 -1
- package/dist/esm/api/index.js.map +1 -1
- package/dist/esm/api/layer-map.js +219 -0
- package/dist/esm/api/layer-map.js.map +1 -0
- package/dist/esm/api/maps-client.js +1 -1
- package/dist/esm/api/maps-client.js.map +1 -1
- package/dist/esm/api/maps-v3-client.js +145 -16
- package/dist/esm/api/maps-v3-client.js.map +1 -1
- package/dist/esm/api/parseMap.js +194 -0
- package/dist/esm/api/parseMap.js.map +1 -0
- package/dist/esm/config.js +11 -26
- package/dist/esm/config.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/layers/carto-layer.js +7 -9
- package/dist/esm/layers/carto-layer.js.map +1 -1
- package/dist/esm/style/color-bins-style.js.map +1 -1
- package/dist/esm/style/color-continuous-style.js.map +1 -1
- package/dist.min.js +278 -1
- package/package.json +7 -3
- package/src/api/index.js +1 -1
- package/src/api/layer-map.js +194 -0
- package/src/api/maps-client.js +3 -7
- package/src/api/maps-v3-client.js +114 -11
- package/src/api/parseMap.js +182 -0
- package/src/config.js +8 -39
- package/src/index.js +1 -0
- package/src/layers/carto-layer.js +3 -5
- package/src/style/color-bins-style.js +1 -3
- package/src/style/color-continuous-style.js +1 -3
|
@@ -1,112 +1,73 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
8
6
|
exports.mapInstantiation = mapInstantiation;
|
|
9
7
|
exports.fetchLayerData = fetchLayerData;
|
|
10
8
|
exports.getData = getData;
|
|
11
|
-
|
|
12
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
|
-
|
|
14
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
15
|
-
|
|
16
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
9
|
+
exports.fetchMap = fetchMap;
|
|
17
10
|
|
|
18
11
|
var _config = require("../config");
|
|
19
12
|
|
|
20
13
|
var _mapsApiCommon = require("./maps-api-common");
|
|
21
14
|
|
|
15
|
+
var _parseMap = require("./parseMap");
|
|
16
|
+
|
|
22
17
|
var _core = require("@deck.gl/core");
|
|
23
18
|
|
|
24
|
-
|
|
19
|
+
const MAX_GET_LENGTH = 2048;
|
|
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
|
+
}
|
|
25
36
|
|
|
26
|
-
|
|
37
|
+
if (method === 'POST') {
|
|
38
|
+
headers['Content-Type'] = 'application/json';
|
|
39
|
+
}
|
|
27
40
|
|
|
28
|
-
|
|
41
|
+
try {
|
|
42
|
+
response = await fetch(url, {
|
|
43
|
+
method,
|
|
44
|
+
headers,
|
|
45
|
+
body
|
|
46
|
+
});
|
|
47
|
+
} catch (error) {
|
|
48
|
+
throw new Error("Failed to connect to Maps API: ".concat(error));
|
|
49
|
+
}
|
|
29
50
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
51
|
+
if (format === _mapsApiCommon.FORMATS.NDJSON) {
|
|
52
|
+
return response;
|
|
53
|
+
}
|
|
33
54
|
|
|
34
|
-
|
|
35
|
-
_request = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(_ref) {
|
|
36
|
-
var method, url, format, accessToken, body, response, headers, json;
|
|
37
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
38
|
-
while (1) {
|
|
39
|
-
switch (_context.prev = _context.next) {
|
|
40
|
-
case 0:
|
|
41
|
-
method = _ref.method, url = _ref.url, format = _ref.format, accessToken = _ref.accessToken, body = _ref.body;
|
|
42
|
-
headers = {
|
|
43
|
-
Accept: 'application/json'
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
if (accessToken) {
|
|
47
|
-
headers.Authorization = "Bearer ".concat(accessToken);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (method === 'POST') {
|
|
51
|
-
headers['Content-Type'] = 'application/json';
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
_context.prev = 4;
|
|
55
|
-
_context.next = 7;
|
|
56
|
-
return fetch(url, {
|
|
57
|
-
method: method,
|
|
58
|
-
headers: headers,
|
|
59
|
-
body: body
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
case 7:
|
|
63
|
-
response = _context.sent;
|
|
64
|
-
_context.next = 13;
|
|
65
|
-
break;
|
|
66
|
-
|
|
67
|
-
case 10:
|
|
68
|
-
_context.prev = 10;
|
|
69
|
-
_context.t0 = _context["catch"](4);
|
|
70
|
-
throw new Error("Failed to connect to Maps API: ".concat(_context.t0));
|
|
71
|
-
|
|
72
|
-
case 13:
|
|
73
|
-
if (!(format === _mapsApiCommon.FORMATS.NDJSON)) {
|
|
74
|
-
_context.next = 15;
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return _context.abrupt("return", response);
|
|
79
|
-
|
|
80
|
-
case 15:
|
|
81
|
-
_context.next = 17;
|
|
82
|
-
return response.json();
|
|
83
|
-
|
|
84
|
-
case 17:
|
|
85
|
-
json = _context.sent;
|
|
86
|
-
|
|
87
|
-
if (!response.ok) {
|
|
88
|
-
dealWithError({
|
|
89
|
-
response: response,
|
|
90
|
-
error: json.error
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return _context.abrupt("return", json.rows ? json.rows : json);
|
|
95
|
-
|
|
96
|
-
case 20:
|
|
97
|
-
case "end":
|
|
98
|
-
return _context.stop();
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}, _callee, null, [[4, 10]]);
|
|
102
|
-
}));
|
|
103
|
-
return _request.apply(this, arguments);
|
|
104
|
-
}
|
|
55
|
+
const json = await response.json();
|
|
105
56
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
57
|
+
if (!response.ok) {
|
|
58
|
+
dealWithError({
|
|
59
|
+
response,
|
|
60
|
+
error: json.error
|
|
61
|
+
});
|
|
62
|
+
}
|
|
109
63
|
|
|
64
|
+
return json.rows ? json.rows : json;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function dealWithError({
|
|
68
|
+
response,
|
|
69
|
+
error
|
|
70
|
+
}) {
|
|
110
71
|
switch (response.status) {
|
|
111
72
|
case 400:
|
|
112
73
|
throw new Error("Bad request. ".concat(error));
|
|
@@ -120,19 +81,20 @@ function dealWithError(_ref2) {
|
|
|
120
81
|
}
|
|
121
82
|
}
|
|
122
83
|
|
|
123
|
-
function getParameters(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
84
|
+
function getParameters({
|
|
85
|
+
type,
|
|
86
|
+
source,
|
|
87
|
+
geoColumn,
|
|
88
|
+
columns,
|
|
89
|
+
schema
|
|
90
|
+
}) {
|
|
91
|
+
const parameters = [(0, _mapsApiCommon.encodeParameter)('client', 'deck-gl-carto')];
|
|
130
92
|
|
|
131
93
|
if (schema) {
|
|
132
94
|
parameters.push((0, _mapsApiCommon.encodeParameter)('schema', true));
|
|
133
95
|
}
|
|
134
96
|
|
|
135
|
-
|
|
97
|
+
const sourceName = type === _mapsApiCommon.MAP_TYPES.QUERY ? 'q' : 'name';
|
|
136
98
|
parameters.push((0, _mapsApiCommon.encodeParameter)(sourceName, source));
|
|
137
99
|
|
|
138
100
|
if (type === _mapsApiCommon.MAP_TYPES.TABLE) {
|
|
@@ -148,73 +110,51 @@ function getParameters(_ref3) {
|
|
|
148
110
|
return parameters.join('&');
|
|
149
111
|
}
|
|
150
112
|
|
|
151
|
-
function mapInstantiation(
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
geoColumn: geoColumn,
|
|
168
|
-
columns: columns,
|
|
169
|
-
schema: schema
|
|
170
|
-
}));
|
|
171
|
-
accessToken = credentials.accessToken;
|
|
172
|
-
format = 'json';
|
|
173
|
-
|
|
174
|
-
if (!(url.length > MAX_GET_LENGTH && type === _mapsApiCommon.MAP_TYPES.QUERY)) {
|
|
175
|
-
_context2.next = 10;
|
|
176
|
-
break;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
body = JSON.stringify({
|
|
180
|
-
q: source,
|
|
181
|
-
client: 'deck-gl-carto'
|
|
182
|
-
});
|
|
183
|
-
_context2.next = 9;
|
|
184
|
-
return request({
|
|
185
|
-
method: 'POST',
|
|
186
|
-
url: baseUrl,
|
|
187
|
-
format: format,
|
|
188
|
-
accessToken: accessToken,
|
|
189
|
-
body: body
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
case 9:
|
|
193
|
-
return _context2.abrupt("return", _context2.sent);
|
|
194
|
-
|
|
195
|
-
case 10:
|
|
196
|
-
_context2.next = 12;
|
|
197
|
-
return request({
|
|
198
|
-
url: url,
|
|
199
|
-
format: format,
|
|
200
|
-
accessToken: accessToken
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
case 12:
|
|
204
|
-
return _context2.abrupt("return", _context2.sent);
|
|
205
|
-
|
|
206
|
-
case 13:
|
|
207
|
-
case "end":
|
|
208
|
-
return _context2.stop();
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}, _callee2);
|
|
113
|
+
async function mapInstantiation({
|
|
114
|
+
type,
|
|
115
|
+
source,
|
|
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
|
|
212
129
|
}));
|
|
213
|
-
|
|
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
|
+
}
|
|
148
|
+
|
|
149
|
+
return await request({
|
|
150
|
+
url,
|
|
151
|
+
format,
|
|
152
|
+
accessToken
|
|
153
|
+
});
|
|
214
154
|
}
|
|
215
155
|
|
|
216
156
|
function getUrlFromMetadata(metadata, format) {
|
|
217
|
-
|
|
157
|
+
const m = metadata[format];
|
|
218
158
|
|
|
219
159
|
if (m && !m.error && m.url) {
|
|
220
160
|
return m.url[0];
|
|
@@ -223,12 +163,12 @@ function getUrlFromMetadata(metadata, format) {
|
|
|
223
163
|
return null;
|
|
224
164
|
}
|
|
225
165
|
|
|
226
|
-
function
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
166
|
+
function checkFetchLayerDataParameters({
|
|
167
|
+
type,
|
|
168
|
+
source,
|
|
169
|
+
connection,
|
|
170
|
+
localCreds
|
|
171
|
+
}) {
|
|
232
172
|
_core.log.assert(connection, 'Must define connection');
|
|
233
173
|
|
|
234
174
|
_core.log.assert(type, 'Must define a type');
|
|
@@ -242,152 +182,233 @@ function checkGetLayerDataParameters(_ref5) {
|
|
|
242
182
|
_core.log.assert(localCreds.accessToken, 'Must define an accessToken');
|
|
243
183
|
}
|
|
244
184
|
|
|
245
|
-
function fetchLayerData(
|
|
246
|
-
|
|
185
|
+
async function fetchLayerData({
|
|
186
|
+
type,
|
|
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;
|
|
247
225
|
}
|
|
248
226
|
|
|
249
|
-
function
|
|
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
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
_i = 0, _prioritizedFormats = prioritizedFormats;
|
|
301
|
-
|
|
302
|
-
case 16:
|
|
303
|
-
if (!(_i < _prioritizedFormats.length)) {
|
|
304
|
-
_context3.next = 25;
|
|
305
|
-
break;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
f = _prioritizedFormats[_i];
|
|
309
|
-
url = getUrlFromMetadata(metadata, f);
|
|
310
|
-
|
|
311
|
-
if (!url) {
|
|
312
|
-
_context3.next = 22;
|
|
313
|
-
break;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
mapFormat = f;
|
|
317
|
-
return _context3.abrupt("break", 25);
|
|
318
|
-
|
|
319
|
-
case 22:
|
|
320
|
-
_i++;
|
|
321
|
-
_context3.next = 16;
|
|
322
|
-
break;
|
|
323
|
-
|
|
324
|
-
case 25:
|
|
325
|
-
accessToken = localCreds.accessToken;
|
|
326
|
-
_context3.next = 28;
|
|
327
|
-
return request({
|
|
328
|
-
url: url,
|
|
329
|
-
format: mapFormat,
|
|
330
|
-
accessToken: accessToken
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
case 28:
|
|
334
|
-
data = _context3.sent;
|
|
335
|
-
result = {
|
|
336
|
-
data: data,
|
|
337
|
-
format: mapFormat
|
|
338
|
-
};
|
|
339
|
-
|
|
340
|
-
if (schema) {
|
|
341
|
-
result.schema = metadata.schema;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
return _context3.abrupt("return", result);
|
|
345
|
-
|
|
346
|
-
case 32:
|
|
347
|
-
case "end":
|
|
348
|
-
return _context3.stop();
|
|
349
|
-
}
|
|
227
|
+
async function _fetchDataUrl({
|
|
228
|
+
type,
|
|
229
|
+
source,
|
|
230
|
+
connection,
|
|
231
|
+
credentials,
|
|
232
|
+
geoColumn,
|
|
233
|
+
columns,
|
|
234
|
+
format,
|
|
235
|
+
schema
|
|
236
|
+
}) {
|
|
237
|
+
const defaultCredentials = (0, _config.getDefaultCredentials)();
|
|
238
|
+
const localCreds = { ...(defaultCredentials.apiVersion === _mapsApiCommon.API_VERSIONS.V3 && defaultCredentials),
|
|
239
|
+
...credentials
|
|
240
|
+
};
|
|
241
|
+
checkFetchLayerDataParameters({
|
|
242
|
+
type,
|
|
243
|
+
source,
|
|
244
|
+
connection,
|
|
245
|
+
localCreds
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
if (!localCreds.mapsUrl) {
|
|
249
|
+
localCreds.mapsUrl = (0, _config.buildMapsUrlFromBase)(localCreds.apiBaseUrl);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const metadata = await mapInstantiation({
|
|
253
|
+
type,
|
|
254
|
+
source,
|
|
255
|
+
connection,
|
|
256
|
+
credentials: localCreds,
|
|
257
|
+
geoColumn,
|
|
258
|
+
columns,
|
|
259
|
+
schema
|
|
260
|
+
});
|
|
261
|
+
let url;
|
|
262
|
+
let mapFormat;
|
|
263
|
+
|
|
264
|
+
if (format) {
|
|
265
|
+
mapFormat = format;
|
|
266
|
+
url = getUrlFromMetadata(metadata, format);
|
|
267
|
+
|
|
268
|
+
_core.log.assert(url, "Format ".concat(format, " not available"));
|
|
269
|
+
} else {
|
|
270
|
+
const prioritizedFormats = [_mapsApiCommon.FORMATS.GEOJSON, _mapsApiCommon.FORMATS.JSON, _mapsApiCommon.FORMATS.NDJSON, _mapsApiCommon.FORMATS.TILEJSON];
|
|
271
|
+
|
|
272
|
+
for (const f of prioritizedFormats) {
|
|
273
|
+
url = getUrlFromMetadata(metadata, f);
|
|
274
|
+
|
|
275
|
+
if (url) {
|
|
276
|
+
mapFormat = f;
|
|
277
|
+
break;
|
|
350
278
|
}
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const {
|
|
283
|
+
accessToken
|
|
284
|
+
} = localCreds;
|
|
285
|
+
return {
|
|
286
|
+
url,
|
|
287
|
+
accessToken,
|
|
288
|
+
mapFormat,
|
|
289
|
+
metadata
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
async function getData({
|
|
294
|
+
type,
|
|
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;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
async function _fetchMapDataset(dataset, accessToken) {
|
|
318
|
+
const {
|
|
319
|
+
connectionName: connection,
|
|
320
|
+
source,
|
|
321
|
+
type
|
|
322
|
+
} = dataset;
|
|
323
|
+
const {
|
|
324
|
+
url,
|
|
325
|
+
mapFormat
|
|
326
|
+
} = await _fetchDataUrl({
|
|
327
|
+
credentials: {
|
|
328
|
+
accessToken
|
|
329
|
+
},
|
|
330
|
+
connection,
|
|
331
|
+
source,
|
|
332
|
+
type
|
|
333
|
+
});
|
|
334
|
+
const cache = parseInt(new URLSearchParams(url).get('cache'), 10);
|
|
335
|
+
|
|
336
|
+
if (cache && dataset.cache === cache) {
|
|
337
|
+
return false;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
dataset.cache = cache;
|
|
341
|
+
const data = await request({
|
|
342
|
+
url,
|
|
343
|
+
format: mapFormat,
|
|
344
|
+
accessToken
|
|
345
|
+
});
|
|
346
|
+
dataset.data = data;
|
|
347
|
+
return true;
|
|
354
348
|
}
|
|
355
349
|
|
|
356
|
-
function
|
|
357
|
-
|
|
350
|
+
async function fillInMapDatasets({
|
|
351
|
+
datasets,
|
|
352
|
+
publicToken
|
|
353
|
+
}) {
|
|
354
|
+
const promises = datasets.map(dataset => _fetchMapDataset(dataset, publicToken));
|
|
355
|
+
return await Promise.all(promises);
|
|
358
356
|
}
|
|
359
357
|
|
|
360
|
-
function
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
358
|
+
async function fetchMap({
|
|
359
|
+
cartoMapId,
|
|
360
|
+
credentials,
|
|
361
|
+
autoRefresh,
|
|
362
|
+
onNewData
|
|
363
|
+
}) {
|
|
364
|
+
const defaultCredentials = (0, _config.getDefaultCredentials)();
|
|
365
|
+
const localCreds = { ...(defaultCredentials.apiVersion === _mapsApiCommon.API_VERSIONS.V3 && defaultCredentials),
|
|
366
|
+
...credentials
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
_core.log.assert(cartoMapId, "Must define CARTO map id: fetchMap({cartoMapId: 'XXXX-XXXX-XXXX'})");
|
|
370
|
+
|
|
371
|
+
_core.log.assert(localCreds.apiVersion === _mapsApiCommon.API_VERSIONS.V3, 'Method only available for v3');
|
|
372
|
+
|
|
373
|
+
_core.log.assert(localCreds.apiBaseUrl, 'Must define apiBaseUrl');
|
|
374
|
+
|
|
375
|
+
if (!localCreds.mapsUrl) {
|
|
376
|
+
localCreds.mapsUrl = (0, _config.buildMapsUrlFromBase)(localCreds.apiBaseUrl);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
if (autoRefresh || onNewData) {
|
|
380
|
+
_core.log.assert(onNewData, 'Must define `onNewData` when using autoRefresh');
|
|
381
|
+
|
|
382
|
+
_core.log.assert(typeof onNewData === 'function', '`onNewData` must be a function');
|
|
383
|
+
|
|
384
|
+
_core.log.assert(autoRefresh > 0, '`autoRefresh` must be a positive number');
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
const url = "".concat(localCreds.mapsUrl, "/public/").concat(cartoMapId);
|
|
388
|
+
const map = await request({
|
|
389
|
+
url
|
|
390
|
+
});
|
|
391
|
+
let stopAutoRefresh;
|
|
392
|
+
|
|
393
|
+
if (autoRefresh) {
|
|
394
|
+
const intervalId = setInterval(async () => {
|
|
395
|
+
const changed = await fillInMapDatasets(map);
|
|
396
|
+
|
|
397
|
+
if (changed.some(v => v === true)) {
|
|
398
|
+
onNewData((0, _parseMap.parseMap)(map));
|
|
388
399
|
}
|
|
389
|
-
},
|
|
390
|
-
|
|
391
|
-
|
|
400
|
+
}, autoRefresh * 1000);
|
|
401
|
+
|
|
402
|
+
stopAutoRefresh = () => {
|
|
403
|
+
clearInterval(intervalId);
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
await fillInMapDatasets(map);
|
|
408
|
+
return { ...(0, _parseMap.parseMap)(map),
|
|
409
|
+
...{
|
|
410
|
+
stopAutoRefresh
|
|
411
|
+
}
|
|
412
|
+
};
|
|
392
413
|
}
|
|
393
414
|
//# sourceMappingURL=maps-v3-client.js.map
|