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