@deck.gl/carto 8.6.3 → 8.7.0-alpha.10
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 +51866 -6683
- package/dist/es5/api/index.js +14 -8
- package/dist/es5/api/index.js.map +1 -1
- package/dist/es5/api/layer-map.js +256 -0
- package/dist/es5/api/layer-map.js.map +1 -0
- 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 +549 -190
- package/dist/es5/api/maps-v3-client.js.map +1 -1
- package/dist/es5/api/parseMap.js +207 -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 +30 -37
- package/dist/es5/config.js.map +1 -1
- package/dist/es5/index.js +20 -30
- 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 +217 -131
- package/dist/es5/layers/carto-layer.js.map +1 -1
- package/dist/es5/style/color-bins-style.js +16 -11
- package/dist/es5/style/color-bins-style.js.map +1 -1
- package/dist/es5/style/color-categories-style.js +43 -14
- package/dist/es5/style/color-categories-style.js.map +1 -1
- package/dist/es5/style/color-continuous-style.js +16 -11
- package/dist/es5/style/color-continuous-style.js.map +1 -1
- package/dist/es5/style/palette.js +24 -12
- 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/index.js +1 -1
- package/dist/esm/api/index.js.map +1 -1
- package/dist/esm/api/layer-map.js +220 -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 +166 -25
- package/dist/esm/api/maps-v3-client.js.map +1 -1
- package/dist/esm/api/parseMap.js +195 -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 -3
- 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 +35 -28
- 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 +278 -1
- package/package.json +13 -8
- package/src/api/index.js +1 -1
- package/src/api/layer-map.js +195 -0
- package/src/api/maps-client.js +3 -7
- package/src/api/maps-v3-client.js +140 -20
- package/src/api/parseMap.js +183 -0
- package/src/config.js +8 -39
- package/src/index.js +1 -2
- package/src/layers/carto-dynamic-tile-layer.js +87 -0
- package/src/layers/carto-layer.js +25 -25
- package/src/style/color-bins-style.js +2 -4
- package/src/style/color-continuous-style.js +2 -4
- 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,70 +1,116 @@
|
|
|
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.mapInstantiation = mapInstantiation;
|
|
7
9
|
exports.fetchLayerData = fetchLayerData;
|
|
8
10
|
exports.getData = getData;
|
|
11
|
+
exports.fetchMap = fetchMap;
|
|
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"));
|
|
9
18
|
|
|
10
19
|
var _config = require("../config");
|
|
11
20
|
|
|
12
21
|
var _mapsApiCommon = require("./maps-api-common");
|
|
13
22
|
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
const MAX_GET_LENGTH = 2048;
|
|
17
|
-
|
|
18
|
-
async function request({
|
|
19
|
-
method,
|
|
20
|
-
url,
|
|
21
|
-
format,
|
|
22
|
-
accessToken,
|
|
23
|
-
body
|
|
24
|
-
}) {
|
|
25
|
-
let response;
|
|
26
|
-
const headers = {
|
|
27
|
-
Accept: 'application/json'
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
if (accessToken) {
|
|
31
|
-
headers.Authorization = "Bearer ".concat(accessToken);
|
|
32
|
-
}
|
|
23
|
+
var _parseMap = require("./parseMap");
|
|
33
24
|
|
|
34
|
-
|
|
35
|
-
headers['Content-Type'] = 'application/json';
|
|
36
|
-
}
|
|
25
|
+
var _core = require("@deck.gl/core");
|
|
37
26
|
|
|
38
|
-
|
|
39
|
-
response = await fetch(url, {
|
|
40
|
-
method,
|
|
41
|
-
headers,
|
|
42
|
-
body
|
|
43
|
-
});
|
|
44
|
-
} catch (error) {
|
|
45
|
-
throw new Error("Failed to connect to Maps API: ".concat(error));
|
|
46
|
-
}
|
|
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; }
|
|
47
28
|
|
|
48
|
-
|
|
49
|
-
return response;
|
|
50
|
-
}
|
|
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; }
|
|
51
30
|
|
|
52
|
-
|
|
31
|
+
var MAX_GET_LENGTH = 2048;
|
|
32
|
+
var DEFAULT_CLIENT = 'deck-gl-carto';
|
|
53
33
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
error: json.error
|
|
58
|
-
});
|
|
59
|
-
}
|
|
34
|
+
function request(_x) {
|
|
35
|
+
return _request.apply(this, arguments);
|
|
36
|
+
}
|
|
60
37
|
|
|
61
|
-
|
|
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);
|
|
62
108
|
}
|
|
63
109
|
|
|
64
|
-
function dealWithError({
|
|
65
|
-
response,
|
|
66
|
-
|
|
67
|
-
|
|
110
|
+
function dealWithError(_ref2) {
|
|
111
|
+
var response = _ref2.response,
|
|
112
|
+
error = _ref2.error;
|
|
113
|
+
|
|
68
114
|
switch (response.status) {
|
|
69
115
|
case 400:
|
|
70
116
|
throw new Error("Bad request. ".concat(error));
|
|
@@ -78,20 +124,20 @@ function dealWithError({
|
|
|
78
124
|
}
|
|
79
125
|
}
|
|
80
126
|
|
|
81
|
-
function getParameters({
|
|
82
|
-
type,
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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)];
|
|
89
135
|
|
|
90
136
|
if (schema) {
|
|
91
137
|
parameters.push((0, _mapsApiCommon.encodeParameter)('schema', true));
|
|
92
138
|
}
|
|
93
139
|
|
|
94
|
-
|
|
140
|
+
var sourceName = type === _mapsApiCommon.MAP_TYPES.QUERY ? 'q' : 'name';
|
|
95
141
|
parameters.push((0, _mapsApiCommon.encodeParameter)(sourceName, source));
|
|
96
142
|
|
|
97
143
|
if (type === _mapsApiCommon.MAP_TYPES.TABLE) {
|
|
@@ -107,51 +153,74 @@ function getParameters({
|
|
|
107
153
|
return parameters.join('&');
|
|
108
154
|
}
|
|
109
155
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
connection,
|
|
114
|
-
credentials,
|
|
115
|
-
geoColumn,
|
|
116
|
-
columns,
|
|
117
|
-
schema
|
|
118
|
-
}) {
|
|
119
|
-
const baseUrl = "".concat(credentials.mapsUrl, "/").concat(connection, "/").concat(type);
|
|
120
|
-
const url = "".concat(baseUrl, "?").concat(getParameters({
|
|
121
|
-
type,
|
|
122
|
-
source,
|
|
123
|
-
geoColumn,
|
|
124
|
-
columns,
|
|
125
|
-
schema
|
|
126
|
-
}));
|
|
127
|
-
const {
|
|
128
|
-
accessToken
|
|
129
|
-
} = credentials;
|
|
130
|
-
const format = 'json';
|
|
131
|
-
|
|
132
|
-
if (url.length > MAX_GET_LENGTH && type === _mapsApiCommon.MAP_TYPES.QUERY) {
|
|
133
|
-
const body = JSON.stringify({
|
|
134
|
-
q: source,
|
|
135
|
-
client: 'deck-gl-carto'
|
|
136
|
-
});
|
|
137
|
-
return await request({
|
|
138
|
-
method: 'POST',
|
|
139
|
-
url: baseUrl,
|
|
140
|
-
format,
|
|
141
|
-
accessToken,
|
|
142
|
-
body
|
|
143
|
-
});
|
|
144
|
-
}
|
|
156
|
+
function mapInstantiation(_x2) {
|
|
157
|
+
return _mapInstantiation.apply(this, arguments);
|
|
158
|
+
}
|
|
145
159
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
format,
|
|
149
|
-
|
|
150
|
-
|
|
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);
|
|
151
220
|
}
|
|
152
221
|
|
|
153
222
|
function getUrlFromMetadata(metadata, format) {
|
|
154
|
-
|
|
223
|
+
var m = metadata[format];
|
|
155
224
|
|
|
156
225
|
if (m && !m.error && m.url) {
|
|
157
226
|
return m.url[0];
|
|
@@ -160,12 +229,12 @@ function getUrlFromMetadata(metadata, format) {
|
|
|
160
229
|
return null;
|
|
161
230
|
}
|
|
162
231
|
|
|
163
|
-
function
|
|
164
|
-
type,
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
232
|
+
function checkFetchLayerDataParameters(_ref5) {
|
|
233
|
+
var type = _ref5.type,
|
|
234
|
+
source = _ref5.source,
|
|
235
|
+
connection = _ref5.connection,
|
|
236
|
+
localCreds = _ref5.localCreds;
|
|
237
|
+
|
|
169
238
|
_core.log.assert(connection, 'Must define connection');
|
|
170
239
|
|
|
171
240
|
_core.log.assert(type, 'Must define a type');
|
|
@@ -179,100 +248,390 @@ function checkGetLayerDataParameters({
|
|
|
179
248
|
_core.log.assert(localCreds.accessToken, 'Must define an accessToken');
|
|
180
249
|
}
|
|
181
250
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
connection,
|
|
186
|
-
credentials,
|
|
187
|
-
geoColumn,
|
|
188
|
-
columns,
|
|
189
|
-
format,
|
|
190
|
-
schema
|
|
191
|
-
}) {
|
|
192
|
-
const defaultCredentials = (0, _config.getDefaultCredentials)();
|
|
193
|
-
const localCreds = { ...(defaultCredentials.apiVersion === _mapsApiCommon.API_VERSIONS.V3 && defaultCredentials),
|
|
194
|
-
...credentials
|
|
195
|
-
};
|
|
196
|
-
checkGetLayerDataParameters({
|
|
197
|
-
type,
|
|
198
|
-
source,
|
|
199
|
-
connection,
|
|
200
|
-
localCreds
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
if (!localCreds.mapsUrl) {
|
|
204
|
-
localCreds.mapsUrl = (0, _config.buildMapsUrlFromBase)(localCreds.apiBaseUrl);
|
|
205
|
-
}
|
|
251
|
+
function fetchLayerData(_x3) {
|
|
252
|
+
return _fetchLayerData.apply(this, arguments);
|
|
253
|
+
}
|
|
206
254
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
source,
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
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
|
+
}
|
|
233
307
|
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
308
|
+
}, _callee3);
|
|
309
|
+
}));
|
|
310
|
+
return _fetchLayerData.apply(this, arguments);
|
|
311
|
+
}
|
|
236
312
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
const data = await request({
|
|
241
|
-
url,
|
|
242
|
-
format: mapFormat,
|
|
243
|
-
accessToken
|
|
244
|
-
});
|
|
245
|
-
const result = {
|
|
246
|
-
data,
|
|
247
|
-
format: mapFormat
|
|
248
|
-
};
|
|
313
|
+
function _fetchDataUrl(_x4) {
|
|
314
|
+
return _fetchDataUrl2.apply(this, arguments);
|
|
315
|
+
}
|
|
249
316
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
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);
|
|
410
|
+
}
|
|
253
411
|
|
|
254
|
-
|
|
412
|
+
function getData(_x5) {
|
|
413
|
+
return _getData.apply(this, arguments);
|
|
255
414
|
}
|
|
256
415
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
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
|
+
}
|
|
453
|
+
|
|
454
|
+
function _fetchMapDataset(_x6, _x7, _x8, _x9) {
|
|
455
|
+
return _fetchMapDataset2.apply(this, arguments);
|
|
456
|
+
}
|
|
457
|
+
|
|
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
|
+
}
|
|
514
|
+
|
|
515
|
+
function fillInMapDatasets(_x10, _x11, _x12) {
|
|
516
|
+
return _fillInMapDatasets.apply(this, arguments);
|
|
517
|
+
}
|
|
518
|
+
|
|
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
|
+
}
|
|
540
|
+
}
|
|
541
|
+
}, _callee7);
|
|
542
|
+
}));
|
|
543
|
+
return _fillInMapDatasets.apply(this, arguments);
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
function fetchMap(_x13) {
|
|
547
|
+
return _fetchMap.apply(this, arguments);
|
|
548
|
+
}
|
|
549
|
+
|
|
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);
|
|
277
636
|
}
|
|
278
637
|
//# sourceMappingURL=maps-v3-client.js.map
|