@deck.gl/carto 8.6.2 → 8.6.3
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 +465 -465
- package/dist/es5/api/index.js +8 -8
- 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 +192 -307
- package/dist/es5/api/maps-v3-client.js.map +1 -1
- package/dist/es5/basemap.js +1 -1
- package/dist/es5/basemap.js.map +1 -1
- package/dist/es5/config.js +21 -23
- package/dist/es5/config.js.map +1 -1
- package/dist/es5/index.js +16 -16
- 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 +132 -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 +10 -11
- package/dist/es5/style/color-bins-style.js.map +1 -1
- package/dist/es5/style/color-categories-style.js +13 -38
- package/dist/es5/style/color-categories-style.js.map +1 -1
- package/dist/es5/style/color-continuous-style.js +10 -11
- package/dist/es5/style/color-continuous-style.js.map +1 -1
- package/dist/es5/style/palette.js +11 -19
- 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/package.json +2 -2
package/dist/es5/api/index.js
CHANGED
|
@@ -5,49 +5,49 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
Object.defineProperty(exports, "FORMATS", {
|
|
7
7
|
enumerable: true,
|
|
8
|
-
get: function
|
|
8
|
+
get: function () {
|
|
9
9
|
return _mapsApiCommon.FORMATS;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "MAP_TYPES", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function
|
|
14
|
+
get: function () {
|
|
15
15
|
return _mapsApiCommon.MAP_TYPES;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
Object.defineProperty(exports, "API_VERSIONS", {
|
|
19
19
|
enumerable: true,
|
|
20
|
-
get: function
|
|
20
|
+
get: function () {
|
|
21
21
|
return _mapsApiCommon.API_VERSIONS;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
24
|
Object.defineProperty(exports, "getDataV2", {
|
|
25
25
|
enumerable: true,
|
|
26
|
-
get: function
|
|
26
|
+
get: function () {
|
|
27
27
|
return _mapsClient.getDataV2;
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
30
|
Object.defineProperty(exports, "CONNECTIONS", {
|
|
31
31
|
enumerable: true,
|
|
32
|
-
get: function
|
|
32
|
+
get: function () {
|
|
33
33
|
return _mapsClient.CONNECTIONS;
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
36
|
Object.defineProperty(exports, "fetchLayerData", {
|
|
37
37
|
enumerable: true,
|
|
38
|
-
get: function
|
|
38
|
+
get: function () {
|
|
39
39
|
return _mapsV3Client.fetchLayerData;
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
42
|
Object.defineProperty(exports, "getData", {
|
|
43
43
|
enumerable: true,
|
|
44
|
-
get: function
|
|
44
|
+
get: function () {
|
|
45
45
|
return _mapsV3Client.getData;
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
48
|
Object.defineProperty(exports, "mapInstantiation", {
|
|
49
49
|
enumerable: true,
|
|
50
|
-
get: function
|
|
50
|
+
get: function () {
|
|
51
51
|
return _mapsV3Client.mapInstantiation;
|
|
52
52
|
}
|
|
53
53
|
});
|
|
@@ -1,36 +1,32 @@
|
|
|
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.encodeParameter = encodeParameter;
|
|
9
7
|
exports.FORMATS = exports.MAP_TYPES = exports.DEFAULT_MAPS_URL_FORMAT = exports.API_VERSIONS = exports.DEFAULT_REGION_COMPONENT_IN_URL = exports.DEFAULT_USER_COMPONENT_IN_URL = void 0;
|
|
10
|
-
|
|
11
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
12
|
-
|
|
13
|
-
var _DEFAULT_MAPS_URL_FOR;
|
|
14
|
-
|
|
15
|
-
var DEFAULT_USER_COMPONENT_IN_URL = '{user}';
|
|
8
|
+
const DEFAULT_USER_COMPONENT_IN_URL = '{user}';
|
|
16
9
|
exports.DEFAULT_USER_COMPONENT_IN_URL = DEFAULT_USER_COMPONENT_IN_URL;
|
|
17
|
-
|
|
10
|
+
const DEFAULT_REGION_COMPONENT_IN_URL = '{region}';
|
|
18
11
|
exports.DEFAULT_REGION_COMPONENT_IN_URL = DEFAULT_REGION_COMPONENT_IN_URL;
|
|
19
|
-
|
|
12
|
+
const API_VERSIONS = {
|
|
20
13
|
V1: 'v1',
|
|
21
14
|
V2: 'v2',
|
|
22
15
|
V3: 'v3'
|
|
23
16
|
};
|
|
24
17
|
exports.API_VERSIONS = API_VERSIONS;
|
|
25
|
-
|
|
18
|
+
const DEFAULT_MAPS_URL_FORMAT = {
|
|
19
|
+
[API_VERSIONS.V1]: "https://".concat(DEFAULT_USER_COMPONENT_IN_URL, ".carto.com/api/v1/map"),
|
|
20
|
+
[API_VERSIONS.V2]: "https://maps-api-v2.".concat(DEFAULT_REGION_COMPONENT_IN_URL, ".carto.com/user/").concat(DEFAULT_USER_COMPONENT_IN_URL)
|
|
21
|
+
};
|
|
26
22
|
exports.DEFAULT_MAPS_URL_FORMAT = DEFAULT_MAPS_URL_FORMAT;
|
|
27
|
-
|
|
23
|
+
const MAP_TYPES = {
|
|
28
24
|
QUERY: 'query',
|
|
29
25
|
TABLE: 'table',
|
|
30
26
|
TILESET: 'tileset'
|
|
31
27
|
};
|
|
32
28
|
exports.MAP_TYPES = MAP_TYPES;
|
|
33
|
-
|
|
29
|
+
const FORMATS = {
|
|
34
30
|
GEOJSON: 'geojson',
|
|
35
31
|
NDJSON: 'ndjson',
|
|
36
32
|
TILEJSON: 'tilejson',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/api/maps-api-common.js"],"names":["DEFAULT_USER_COMPONENT_IN_URL","DEFAULT_REGION_COMPONENT_IN_URL","API_VERSIONS","V1","V2","V3","DEFAULT_MAPS_URL_FORMAT","MAP_TYPES","QUERY","TABLE","TILESET","FORMATS","GEOJSON","NDJSON","TILEJSON","JSON","encodeParameter","name","value","encodeURIComponent"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/api/maps-api-common.js"],"names":["DEFAULT_USER_COMPONENT_IN_URL","DEFAULT_REGION_COMPONENT_IN_URL","API_VERSIONS","V1","V2","V3","DEFAULT_MAPS_URL_FORMAT","MAP_TYPES","QUERY","TABLE","TILESET","FORMATS","GEOJSON","NDJSON","TILEJSON","JSON","encodeParameter","name","value","encodeURIComponent"],"mappings":";;;;;;;AAAO,MAAMA,6BAA6B,GAAG,QAAtC;;AACA,MAAMC,+BAA+B,GAAG,UAAxC;;AAEA,MAAMC,YAAY,GAAG;AAC1BC,EAAAA,EAAE,EAAE,IADsB;AAE1BC,EAAAA,EAAE,EAAE,IAFsB;AAG1BC,EAAAA,EAAE,EAAE;AAHsB,CAArB;;AAMA,MAAMC,uBAAuB,GAAG;AACrC,GAACJ,YAAY,CAACC,EAAd,qBAA8BH,6BAA9B,0BADqC;AAErC,GAACE,YAAY,CAACE,EAAd,iCAA0CH,+BAA1C,6BAA4FD,6BAA5F;AAFqC,CAAhC;;AAKA,MAAMO,SAAS,GAAG;AACvBC,EAAAA,KAAK,EAAE,OADgB;AAEvBC,EAAAA,KAAK,EAAE,OAFgB;AAGvBC,EAAAA,OAAO,EAAE;AAHc,CAAlB;;AAOA,MAAMC,OAAO,GAAG;AACrBC,EAAAA,OAAO,EAAE,SADY;AAErBC,EAAAA,MAAM,EAAE,QAFa;AAGrBC,EAAAA,QAAQ,EAAE,UAHW;AAIrBC,EAAAA,IAAI,EAAE;AAJe,CAAhB;;;AAUA,SAASC,eAAT,CAAyBC,IAAzB,EAA+BC,KAA/B,EAAsC;AAC3C,mBAAUD,IAAV,cAAkBE,kBAAkB,CAACD,KAAD,CAApC;AACD","sourcesContent":["export const DEFAULT_USER_COMPONENT_IN_URL = '{user}';\nexport const DEFAULT_REGION_COMPONENT_IN_URL = '{region}';\n\nexport const API_VERSIONS = {\n V1: 'v1',\n V2: 'v2',\n V3: 'v3'\n};\n\nexport const DEFAULT_MAPS_URL_FORMAT = {\n [API_VERSIONS.V1]: `https://${DEFAULT_USER_COMPONENT_IN_URL}.carto.com/api/v1/map`,\n [API_VERSIONS.V2]: `https://maps-api-v2.${DEFAULT_REGION_COMPONENT_IN_URL}.carto.com/user/${DEFAULT_USER_COMPONENT_IN_URL}`\n};\n\nexport const MAP_TYPES = {\n QUERY: 'query',\n TABLE: 'table',\n TILESET: 'tileset'\n};\n\n// AVAILABLE FORMATS\nexport const FORMATS = {\n GEOJSON: 'geojson',\n NDJSON: 'ndjson',\n TILEJSON: 'tilejson',\n JSON: 'json'\n};\n\n/**\n * Simple encode parameter\n */\nexport function encodeParameter(name, value) {\n return `${name}=${encodeURIComponent(value)}`;\n}\n"],"file":"maps-api-common.js"}
|
|
@@ -1,167 +1,106 @@
|
|
|
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.getDataV2 = getDataV2;
|
|
9
7
|
exports.CONNECTIONS = void 0;
|
|
10
8
|
|
|
11
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
12
|
-
|
|
13
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
14
|
-
|
|
15
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
16
|
-
|
|
17
9
|
var _config = require("../config");
|
|
18
10
|
|
|
19
11
|
var _mapsApiCommon = require("./maps-api-common");
|
|
20
12
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
24
|
-
|
|
25
|
-
var CONNECTIONS = {
|
|
13
|
+
const CONNECTIONS = {
|
|
26
14
|
BIGQUERY: 'bigquery',
|
|
27
15
|
CARTO: 'carto'
|
|
28
16
|
};
|
|
29
17
|
exports.CONNECTIONS = CONNECTIONS;
|
|
30
|
-
|
|
31
|
-
|
|
18
|
+
const BUFFER_SIZE = 16;
|
|
19
|
+
const TILE_EXTENT = 4096;
|
|
20
|
+
|
|
21
|
+
async function getDataV2({
|
|
22
|
+
type,
|
|
23
|
+
source,
|
|
24
|
+
credentials
|
|
25
|
+
}) {
|
|
26
|
+
const defaultCredentials = (0, _config.getDefaultCredentials)();
|
|
27
|
+
const apiVersion = credentials && credentials.apiVersion || defaultCredentials.apiVersion;
|
|
28
|
+
const localCreds = { ..._config.defaultClassicCredentials,
|
|
29
|
+
...(defaultCredentials.apiVersion === apiVersion && defaultCredentials),
|
|
30
|
+
...credentials
|
|
31
|
+
};
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
33
|
+
if (!localCreds.mapsUrl) {
|
|
34
|
+
localCreds.mapsUrl = _mapsApiCommon.DEFAULT_MAPS_URL_FORMAT[apiVersion];
|
|
35
|
+
}
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
_context.next = 13;
|
|
65
|
-
return request({
|
|
66
|
-
url: url,
|
|
67
|
-
credentials: localCreds
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
case 13:
|
|
71
|
-
layergroup = _context.sent;
|
|
72
|
-
return _context.abrupt("return", layergroup.metadata.tilejson.vector);
|
|
73
|
-
|
|
74
|
-
case 15:
|
|
75
|
-
url = buildURLMapsAPIv2({
|
|
76
|
-
connection: connection,
|
|
77
|
-
type: type,
|
|
78
|
-
source: source,
|
|
79
|
-
credentials: localCreds
|
|
80
|
-
});
|
|
81
|
-
_context.next = 18;
|
|
82
|
-
return request({
|
|
83
|
-
url: url,
|
|
84
|
-
credentials: localCreds
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
case 18:
|
|
88
|
-
return _context.abrupt("return", _context.sent);
|
|
89
|
-
|
|
90
|
-
case 19:
|
|
91
|
-
throw new Error("Invalid maps API version. It shoud be ".concat(_mapsApiCommon.API_VERSIONS.V1, " or ").concat(_mapsApiCommon.API_VERSIONS.V2));
|
|
92
|
-
|
|
93
|
-
case 20:
|
|
94
|
-
case "end":
|
|
95
|
-
return _context.stop();
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}, _callee);
|
|
99
|
-
}));
|
|
100
|
-
return _getDataV.apply(this, arguments);
|
|
101
|
-
}
|
|
37
|
+
let url;
|
|
38
|
+
const connection = type === 'tileset' ? CONNECTIONS.BIGQUERY : CONNECTIONS.CARTO;
|
|
39
|
+
|
|
40
|
+
switch (apiVersion) {
|
|
41
|
+
case _mapsApiCommon.API_VERSIONS.V1:
|
|
42
|
+
const mapConfig = createMapConfig(source);
|
|
43
|
+
url = buildURLMapsAPIv1({
|
|
44
|
+
mapConfig,
|
|
45
|
+
credentials: localCreds
|
|
46
|
+
});
|
|
47
|
+
const layergroup = await request({
|
|
48
|
+
url,
|
|
49
|
+
credentials: localCreds
|
|
50
|
+
});
|
|
51
|
+
return layergroup.metadata.tilejson.vector;
|
|
52
|
+
|
|
53
|
+
case _mapsApiCommon.API_VERSIONS.V2:
|
|
54
|
+
url = buildURLMapsAPIv2({
|
|
55
|
+
connection,
|
|
56
|
+
type,
|
|
57
|
+
source,
|
|
58
|
+
credentials: localCreds
|
|
59
|
+
});
|
|
60
|
+
return await request({
|
|
61
|
+
url,
|
|
62
|
+
credentials: localCreds
|
|
63
|
+
});
|
|
102
64
|
|
|
103
|
-
|
|
104
|
-
|
|
65
|
+
default:
|
|
66
|
+
throw new Error("Invalid maps API version. It shoud be ".concat(_mapsApiCommon.API_VERSIONS.V1, " or ").concat(_mapsApiCommon.API_VERSIONS.V2));
|
|
67
|
+
}
|
|
105
68
|
}
|
|
106
69
|
|
|
107
|
-
function
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
return fetch(url, {
|
|
118
|
-
headers: {
|
|
119
|
-
Accept: 'application/json'
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
case 4:
|
|
124
|
-
response = _context2.sent;
|
|
125
|
-
_context2.next = 10;
|
|
126
|
-
break;
|
|
127
|
-
|
|
128
|
-
case 7:
|
|
129
|
-
_context2.prev = 7;
|
|
130
|
-
_context2.t0 = _context2["catch"](1);
|
|
131
|
-
throw new Error("Failed to connect to Maps API: ".concat(_context2.t0));
|
|
132
|
-
|
|
133
|
-
case 10:
|
|
134
|
-
_context2.next = 12;
|
|
135
|
-
return response.json();
|
|
136
|
-
|
|
137
|
-
case 12:
|
|
138
|
-
json = _context2.sent;
|
|
139
|
-
|
|
140
|
-
if (!response.ok) {
|
|
141
|
-
dealWithError({
|
|
142
|
-
response: response,
|
|
143
|
-
json: json,
|
|
144
|
-
credentials: credentials
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return _context2.abrupt("return", json);
|
|
149
|
-
|
|
150
|
-
case 15:
|
|
151
|
-
case "end":
|
|
152
|
-
return _context2.stop();
|
|
153
|
-
}
|
|
70
|
+
async function request({
|
|
71
|
+
url,
|
|
72
|
+
credentials
|
|
73
|
+
}) {
|
|
74
|
+
let response;
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
response = await fetch(url, {
|
|
78
|
+
headers: {
|
|
79
|
+
Accept: 'application/json'
|
|
154
80
|
}
|
|
155
|
-
}
|
|
156
|
-
})
|
|
157
|
-
|
|
158
|
-
}
|
|
81
|
+
});
|
|
82
|
+
} catch (error) {
|
|
83
|
+
throw new Error("Failed to connect to Maps API: ".concat(error));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const json = await response.json();
|
|
159
87
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
88
|
+
if (!response.ok) {
|
|
89
|
+
dealWithError({
|
|
90
|
+
response,
|
|
91
|
+
json,
|
|
92
|
+
credentials
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return json;
|
|
97
|
+
}
|
|
164
98
|
|
|
99
|
+
function dealWithError({
|
|
100
|
+
response,
|
|
101
|
+
json,
|
|
102
|
+
credentials
|
|
103
|
+
}) {
|
|
165
104
|
switch (response.status) {
|
|
166
105
|
case 401:
|
|
167
106
|
throw new Error("Unauthorized access to Maps API: invalid combination of user ('".concat(credentials.username, "') and apiKey ('").concat(credentials.apiKey, "')"));
|
|
@@ -170,33 +109,35 @@ function dealWithError(_ref3) {
|
|
|
170
109
|
throw new Error("Unauthorized access to dataset: the provided apiKey('".concat(credentials.apiKey, "') doesn't provide access to the requested data"));
|
|
171
110
|
|
|
172
111
|
default:
|
|
173
|
-
|
|
112
|
+
const e = credentials.apiVersion === _mapsApiCommon.API_VERSIONS.V1 ? JSON.stringify(json.errors) : json.error;
|
|
174
113
|
throw new Error(e);
|
|
175
114
|
}
|
|
176
115
|
}
|
|
177
116
|
|
|
178
117
|
function initURLParameters(credentials) {
|
|
179
|
-
|
|
180
|
-
|
|
118
|
+
const encodedApiKey = (0, _mapsApiCommon.encodeParameter)('api_key', credentials.apiKey);
|
|
119
|
+
const encodedClient = (0, _mapsApiCommon.encodeParameter)('client', "deck-gl-carto");
|
|
181
120
|
return [encodedApiKey, encodedClient];
|
|
182
121
|
}
|
|
183
122
|
|
|
184
|
-
function buildURLMapsAPIv1(
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
123
|
+
function buildURLMapsAPIv1({
|
|
124
|
+
mapConfig,
|
|
125
|
+
credentials
|
|
126
|
+
}) {
|
|
127
|
+
const parameters = initURLParameters(credentials);
|
|
128
|
+
const cfg = JSON.stringify(mapConfig);
|
|
189
129
|
return "".concat(mapsUrl(credentials), "?").concat(parameters.join('&'), "&").concat((0, _mapsApiCommon.encodeParameter)('config', cfg));
|
|
190
130
|
}
|
|
191
131
|
|
|
192
|
-
function buildURLMapsAPIv2(
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
132
|
+
function buildURLMapsAPIv2({
|
|
133
|
+
connection,
|
|
134
|
+
type,
|
|
135
|
+
source,
|
|
136
|
+
credentials
|
|
137
|
+
}) {
|
|
138
|
+
const parameters = initURLParameters(credentials);
|
|
139
|
+
const mapsApiType = type === _mapsApiCommon.MAP_TYPES.QUERY ? 'sql' : type;
|
|
140
|
+
let url = "".concat(mapsUrl(credentials), "/").concat(connection, "/").concat(mapsApiType, "?");
|
|
200
141
|
url += "".concat((0, _mapsApiCommon.encodeParameter)('source', source), "&format=tilejson&").concat(parameters.join('&'));
|
|
201
142
|
return url;
|
|
202
143
|
}
|
|
@@ -214,7 +155,7 @@ function createMapConfig(sql) {
|
|
|
214
155
|
layers: [{
|
|
215
156
|
type: 'mapnik',
|
|
216
157
|
options: {
|
|
217
|
-
sql
|
|
158
|
+
sql,
|
|
218
159
|
vector_extent: TILE_EXTENT
|
|
219
160
|
}
|
|
220
161
|
}]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/api/maps-client.js"],"names":["CONNECTIONS","BIGQUERY","CARTO","BUFFER_SIZE","TILE_EXTENT","getDataV2","type","source","credentials","defaultCredentials","apiVersion","localCreds","defaultClassicCredentials","mapsUrl","DEFAULT_MAPS_URL_FORMAT","connection","API_VERSIONS","V1","
|
|
1
|
+
{"version":3,"sources":["../../../src/api/maps-client.js"],"names":["CONNECTIONS","BIGQUERY","CARTO","BUFFER_SIZE","TILE_EXTENT","getDataV2","type","source","credentials","defaultCredentials","apiVersion","localCreds","defaultClassicCredentials","mapsUrl","DEFAULT_MAPS_URL_FORMAT","url","connection","API_VERSIONS","V1","mapConfig","createMapConfig","buildURLMapsAPIv1","layergroup","request","metadata","tilejson","vector","V2","buildURLMapsAPIv2","Error","response","fetch","headers","Accept","error","json","ok","dealWithError","status","username","apiKey","e","JSON","stringify","errors","initURLParameters","encodedApiKey","encodedClient","parameters","cfg","join","mapsApiType","MAP_TYPES","QUERY","replace","DEFAULT_USER_COMPONENT_IN_URL","DEFAULT_REGION_COMPONENT_IN_URL","region","sql","version","buffersize","mvt","layers","options","vector_extent"],"mappings":";;;;;;;;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IAAX,CAAgB,GAAhB,CAA5D,CAAH;AACA,SAAOnC,GAAP;AACD;;AAKD,SAASF,OAAT,CAAiBL,WAAjB,EAA8B;AAC5B,SAAOA,WAAW,CAACK,OAAZ,CACJyC,OADI,CACIC,4CADJ,EACmC/C,WAAW,CAAC+B,QAD/C,EAEJe,OAFI,CAEIE,8CAFJ,EAEqChD,WAAW,CAACiD,MAFjD,CAAP;AAGD;;AAED,SAASrC,eAAT,CAAyBsC,GAAzB,EAA8B;AAC5B,SAAO;AACLC,IAAAA,OAAO,EAAE,OADJ;AAELC,IAAAA,UAAU,EAAE;AACVC,MAAAA,GAAG,EAAE1D;AADK,KAFP;AAKL2D,IAAAA,MAAM,EAAE,CACN;AACExD,MAAAA,IAAI,EAAE,QADR;AAEEyD,MAAAA,OAAO,EAAE;AACPL,QAAAA,GADO;AAEPM,QAAAA,aAAa,EAAE5D;AAFR;AAFX,KADM;AALH,GAAP;AAeD","sourcesContent":["/**\n * Maps API Client for Maps API v1 and Maps API v2\n */\nimport {defaultClassicCredentials, getDefaultCredentials} from '../config';\nimport {\n API_VERSIONS,\n DEFAULT_MAPS_URL_FORMAT,\n DEFAULT_REGION_COMPONENT_IN_URL,\n DEFAULT_USER_COMPONENT_IN_URL,\n encodeParameter,\n MAP_TYPES\n} from './maps-api-common';\n\nexport const CONNECTIONS = {\n BIGQUERY: 'bigquery',\n CARTO: 'carto'\n};\n\nconst BUFFER_SIZE = 16;\nconst TILE_EXTENT = 4096;\n\n/**\n * Obtain a TileJson from Maps API v1 and v2\n */\nexport async function getDataV2({type, source, credentials}) {\n const defaultCredentials = getDefaultCredentials();\n const apiVersion = (credentials && credentials.apiVersion) || defaultCredentials.apiVersion;\n // Only pick up default credentials if they have been defined for\n // correct API version\n const localCreds = {\n ...defaultClassicCredentials,\n ...(defaultCredentials.apiVersion === apiVersion && defaultCredentials),\n ...credentials\n };\n\n if (!localCreds.mapsUrl) {\n localCreds.mapsUrl = DEFAULT_MAPS_URL_FORMAT[apiVersion];\n }\n\n let url;\n\n const connection = type === 'tileset' ? CONNECTIONS.BIGQUERY : CONNECTIONS.CARTO;\n\n switch (apiVersion) {\n case API_VERSIONS.V1:\n // Maps API v1\n const mapConfig = createMapConfig(source);\n url = buildURLMapsAPIv1({mapConfig, credentials: localCreds});\n const layergroup = await request({url, credentials: localCreds});\n return layergroup.metadata.tilejson.vector;\n\n case API_VERSIONS.V2:\n // Maps API v2\n url = buildURLMapsAPIv2({connection, type, source, credentials: localCreds});\n return await request({url, credentials: localCreds});\n\n default:\n throw new Error(\n `Invalid maps API version. It shoud be ${API_VERSIONS.V1} or ${API_VERSIONS.V2}`\n );\n }\n}\n\n/**\n * Request against Maps API\n */\nasync function request({url, credentials}) {\n let response;\n\n try {\n /* global fetch */\n /* eslint no-undef: \"error\" */\n response = await fetch(url, {\n headers: {\n Accept: 'application/json'\n }\n });\n } catch (error) {\n throw new Error(`Failed to connect to Maps API: ${error}`);\n }\n\n const json = await response.json();\n\n if (!response.ok) {\n dealWithError({response, json, credentials});\n }\n\n return json;\n}\n\n/**\n * Display proper message from Maps API error\n */\nfunction dealWithError({response, json, credentials}) {\n switch (response.status) {\n case 401:\n throw new Error(\n `Unauthorized access to Maps API: invalid combination of user ('${\n credentials.username\n }') and apiKey ('${credentials.apiKey}')`\n );\n case 403:\n throw new Error(\n `Unauthorized access to dataset: the provided apiKey('${\n credentials.apiKey\n }') doesn't provide access to the requested data`\n );\n\n default:\n const e =\n credentials.apiVersion === API_VERSIONS.V1 ? JSON.stringify(json.errors) : json.error;\n throw new Error(e);\n }\n}\n\nfunction initURLParameters(credentials) {\n const encodedApiKey = encodeParameter('api_key', credentials.apiKey);\n const encodedClient = encodeParameter('client', `deck-gl-carto`);\n return [encodedApiKey, encodedClient];\n}\n\n/**\n * Build a URL with all required parameters\n */\nfunction buildURLMapsAPIv1({mapConfig, credentials}) {\n const parameters = initURLParameters(credentials);\n const cfg = JSON.stringify(mapConfig);\n return `${mapsUrl(credentials)}?${parameters.join('&')}&${encodeParameter('config', cfg)}`;\n}\n\nfunction buildURLMapsAPIv2({connection, type, source, credentials}) {\n const parameters = initURLParameters(credentials);\n // Query type is mapped to 'sql' at maps api v1\n const mapsApiType = type === MAP_TYPES.QUERY ? 'sql' : type;\n let url = `${mapsUrl(credentials)}/${connection}/${mapsApiType}?`;\n url += `${encodeParameter('source', source)}&format=tilejson&${parameters.join('&')}`;\n return url;\n}\n\n/**\n * Prepare a url valid for the specified user\n */\nfunction mapsUrl(credentials) {\n return credentials.mapsUrl\n .replace(DEFAULT_USER_COMPONENT_IN_URL, credentials.username)\n .replace(DEFAULT_REGION_COMPONENT_IN_URL, credentials.region);\n}\n\nfunction createMapConfig(sql) {\n return {\n version: '1.3.1',\n buffersize: {\n mvt: BUFFER_SIZE\n },\n layers: [\n {\n type: 'mapnik',\n options: {\n sql,\n vector_extent: TILE_EXTENT\n }\n }\n ]\n };\n}\n"],"file":"maps-client.js"}
|