@deck.gl/carto 8.10.0-alpha.4 → 8.10.0-alpha.6
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/cartoRasterTile-worker.js +1 -1
- package/dist/cartoSpatialTile-worker.js +1 -1
- package/dist/cartoVectorTile-worker.js +1 -1
- package/dist/dist.dev.js +64 -715
- package/dist/es5/api/carto-api-error.js +3 -7
- package/dist/es5/api/carto-api-error.js.map +1 -1
- package/dist/es5/layers/carto-layer.js +196 -200
- package/dist/es5/layers/carto-layer.js.map +1 -1
- package/dist/es5/layers/h3-tile-layer.js +50 -54
- package/dist/es5/layers/h3-tile-layer.js.map +1 -1
- package/dist/es5/layers/h3-tileset-2d.js +62 -68
- package/dist/es5/layers/h3-tileset-2d.js.map +1 -1
- package/dist/es5/layers/point-label-layer.js +160 -165
- package/dist/es5/layers/point-label-layer.js.map +1 -1
- package/dist/es5/layers/quadbin-layer.js +23 -27
- package/dist/es5/layers/quadbin-layer.js.map +1 -1
- package/dist/es5/layers/quadbin-tile-layer.js +31 -34
- package/dist/es5/layers/quadbin-tile-layer.js.map +1 -1
- package/dist/es5/layers/quadbin-tileset-2d.js +32 -38
- package/dist/es5/layers/quadbin-tileset-2d.js.map +1 -1
- package/dist/es5/layers/raster-layer.js +94 -98
- package/dist/es5/layers/raster-layer.js.map +1 -1
- package/dist/es5/layers/raster-tile-layer.js +28 -33
- package/dist/es5/layers/raster-tile-layer.js.map +1 -1
- package/dist/es5/layers/schema/carto-raster-tile-loader.js +1 -1
- package/dist/es5/layers/schema/carto-raster-tile.js +31 -39
- package/dist/es5/layers/schema/carto-raster-tile.js.map +1 -1
- package/dist/es5/layers/schema/carto-spatial-tile-loader.js +1 -1
- package/dist/es5/layers/schema/carto-spatial-tile.js +36 -47
- package/dist/es5/layers/schema/carto-spatial-tile.js.map +1 -1
- package/dist/es5/layers/schema/carto-tile.js +161 -196
- package/dist/es5/layers/schema/carto-tile.js.map +1 -1
- package/dist/es5/layers/schema/carto-vector-tile-loader.js +1 -1
- package/dist/es5/layers/spatial-index-tile-layer.js +67 -73
- package/dist/es5/layers/spatial-index-tile-layer.js.map +1 -1
- package/dist/es5/layers/vector-tile-layer.js +83 -90
- package/dist/es5/layers/vector-tile-layer.js.map +1 -1
- package/dist/esm/api/carto-api-error.js +8 -13
- package/dist/esm/api/carto-api-error.js.map +1 -1
- package/dist/esm/api/layer-map.js +4 -4
- package/dist/esm/api/layer-map.js.map +1 -1
- package/dist/esm/api/maps-api-common.js +3 -3
- package/dist/esm/api/maps-api-common.js.map +1 -1
- package/dist/esm/api/maps-client.js +7 -7
- package/dist/esm/api/maps-client.js.map +1 -1
- package/dist/esm/api/maps-v3-client.js +12 -12
- package/dist/esm/api/maps-v3-client.js.map +1 -1
- package/dist/esm/api/parseMap.js +4 -4
- package/dist/esm/api/parseMap.js.map +1 -1
- package/dist/esm/config.js +3 -3
- package/dist/esm/config.js.map +1 -1
- package/dist/esm/layers/carto-layer.js +12 -15
- package/dist/esm/layers/carto-layer.js.map +1 -1
- package/dist/esm/layers/h3-tile-layer.js +3 -6
- package/dist/esm/layers/h3-tile-layer.js.map +1 -1
- package/dist/esm/layers/point-label-layer.js +6 -10
- package/dist/esm/layers/point-label-layer.js.map +1 -1
- package/dist/esm/layers/quadbin-layer.js +2 -5
- package/dist/esm/layers/quadbin-layer.js.map +1 -1
- package/dist/esm/layers/quadbin-tile-layer.js +3 -6
- package/dist/esm/layers/quadbin-tile-layer.js.map +1 -1
- package/dist/esm/layers/raster-layer-vertex.glsl.js +98 -1
- package/dist/esm/layers/raster-layer-vertex.glsl.js.map +1 -1
- package/dist/esm/layers/raster-layer.js +4 -8
- package/dist/esm/layers/raster-layer.js.map +1 -1
- package/dist/esm/layers/raster-tile-layer.js +3 -6
- package/dist/esm/layers/raster-tile-layer.js.map +1 -1
- package/dist/esm/layers/schema/carto-raster-tile-loader.js +1 -1
- package/dist/esm/layers/schema/carto-raster-tile.js +1 -1
- package/dist/esm/layers/schema/carto-raster-tile.js.map +1 -1
- package/dist/esm/layers/schema/carto-spatial-tile-loader.js +1 -1
- package/dist/esm/layers/schema/carto-vector-tile-loader.js +1 -1
- package/dist/esm/layers/spatial-index-tile-layer.js +2 -5
- package/dist/esm/layers/spatial-index-tile-layer.js.map +1 -1
- package/dist/esm/layers/utils.js +1 -1
- package/dist/esm/layers/utils.js.map +1 -1
- package/dist/esm/layers/vector-tile-layer.js +2 -5
- package/dist/esm/layers/vector-tile-layer.js.map +1 -1
- package/dist/esm/sources/base-source.js +1 -1
- package/dist/esm/sources/base-source.js.map +1 -1
- package/dist/esm/sources/utils.js +2 -2
- package/dist/esm/sources/utils.js.map +1 -1
- package/dist/esm/style/palette.js +2 -2
- package/dist/esm/style/palette.js.map +1 -1
- package/dist/esm/style/utils.js +1 -1
- package/dist/esm/style/utils.js.map +1 -1
- package/dist/esm/utils.js +1 -1
- package/dist/esm/utils.js.map +1 -1
- package/dist.min.js +46 -25
- package/package.json +2 -2
|
@@ -9,8 +9,6 @@ exports.CartoAPIError = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
11
|
|
|
12
|
-
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
13
|
-
|
|
14
12
|
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
15
13
|
|
|
16
14
|
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
@@ -19,8 +17,6 @@ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/ge
|
|
|
19
17
|
|
|
20
18
|
var _wrapNativeSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapNativeSuper"));
|
|
21
19
|
|
|
22
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
23
|
-
|
|
24
20
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
25
21
|
|
|
26
22
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
@@ -64,9 +60,9 @@ var CartoAPIError = function (_Error) {
|
|
|
64
60
|
|
|
65
61
|
message += '\n';
|
|
66
62
|
_this = _super.call(this, message);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
63
|
+
_this.error = void 0;
|
|
64
|
+
_this.errorContext = void 0;
|
|
65
|
+
_this.response = void 0;
|
|
70
66
|
_this.name = 'CartoAPIError';
|
|
71
67
|
_this.response = response;
|
|
72
68
|
_this.error = error;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/api/carto-api-error.ts"],"names":["CartoAPIError","error","errorContext","response","responseString","status","message","requestType","Object","keys","key","formatErrorKey","name","Error","replace","s","toUpperCase"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/api/carto-api-error.ts"],"names":["CartoAPIError","error","errorContext","response","responseString","status","message","requestType","Object","keys","key","formatErrorKey","name","Error","replace","s","toUpperCase"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;IAgBaA,a;;;;;AAUX,yBAAYC,KAAZ,EAA0BC,YAA1B,EAAyDC,QAAzD,EAA8E;AAAA;;AAAA;AAC5E,QAAIC,cAAc,GAAG,mBAArB;;AACA,QAAID,QAAJ,EAAc;AACZC,MAAAA,cAAc,GAAG,mBAAjB;;AACA,UAAID,QAAQ,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IAAvC,EAA6C,UAAAC,CAAC;AAAA,WAAIA,CAAC,CAACC,WAAF,EAAJ;AAAA,GAA9C,CAAP;AACD","sourcesContent":["import {MapType, RequestType} from './maps-api-common';\n\nexport type APIErrorContext = {\n requestType: RequestType;\n mapId?: string;\n connection?: string;\n source?: string;\n type?: MapType;\n};\n\n/**\n *\n * Custom error for reported errors in CARTO Maps API.\n * Provides useful debugging information in console and context for applications.\n *\n */\nexport class CartoAPIError extends Error {\n /** Source error from server */\n error: Error;\n\n /** Context (API call & parameters) in which error occured */\n errorContext: APIErrorContext;\n\n /** Response from server */\n response?: Response;\n\n constructor(error: Error, errorContext: APIErrorContext, response?: Response) {\n let responseString = 'Failed to connect';\n if (response) {\n responseString = 'Server returned: ';\n if (response.status === 400) {\n responseString += 'Bad request';\n } else if (response.status === 401 || response.status === 403) {\n responseString += 'Unauthorized access';\n } else if (response.status === 404) {\n responseString += 'Not found';\n } else {\n responseString += 'Error';\n }\n\n responseString += ` (${response.status}):`;\n }\n responseString += ` ${error.message || error}`;\n\n let message = `${errorContext.requestType} API request failed`;\n message += `\\n${responseString}`;\n for (const key of Object.keys(errorContext)) {\n if (key === 'requestType') continue; // eslint-disable-line no-continue\n message += `\\n${formatErrorKey(key)}: ${errorContext[key]}`;\n }\n message += '\\n';\n\n super(message);\n\n this.name = 'CartoAPIError';\n this.response = response;\n this.error = error;\n this.errorContext = errorContext;\n }\n}\n\n/**\n * Converts camelCase to Camel Case\n */\nfunction formatErrorKey(key) {\n return key.replace(/([A-Z])/g, ' $1').replace(/^./, s => s.toUpperCase());\n}\n"],"file":"carto-api-error.js"}
|
|
@@ -15,6 +15,8 @@ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/h
|
|
|
15
15
|
|
|
16
16
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
17
17
|
|
|
18
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
19
|
+
|
|
18
20
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
19
21
|
|
|
20
22
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
@@ -27,8 +29,6 @@ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime
|
|
|
27
29
|
|
|
28
30
|
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
29
31
|
|
|
30
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
31
|
-
|
|
32
32
|
var _core = require("@deck.gl/core");
|
|
33
33
|
|
|
34
34
|
var _geoLayers = require("@deck.gl/geo-layers");
|
|
@@ -97,237 +97,233 @@ var CartoLayer = function (_CompositeLayer) {
|
|
|
97
97
|
return _super.apply(this, arguments);
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
|
|
101
|
-
key: "initializeState",
|
|
102
|
-
value: function initializeState() {
|
|
103
|
-
this.state = {
|
|
104
|
-
data: null,
|
|
105
|
-
apiVersion: null
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
}, {
|
|
109
|
-
key: "isLoaded",
|
|
110
|
-
get: function get() {
|
|
111
|
-
return this.getSubLayers().length > 0 && (0, _get2.default)((0, _getPrototypeOf2.default)(CartoLayer.prototype), "isLoaded", this);
|
|
112
|
-
}
|
|
113
|
-
}, {
|
|
114
|
-
key: "_checkProps",
|
|
115
|
-
value: function _checkProps(props) {
|
|
116
|
-
var type = props.type,
|
|
117
|
-
credentials = props.credentials,
|
|
118
|
-
connection = props.connection,
|
|
119
|
-
geoColumn = props.geoColumn,
|
|
120
|
-
columns = props.columns;
|
|
100
|
+
var _proto = CartoLayer.prototype;
|
|
121
101
|
|
|
122
|
-
|
|
102
|
+
_proto.initializeState = function initializeState() {
|
|
103
|
+
this.state = {
|
|
104
|
+
data: null,
|
|
105
|
+
apiVersion: null
|
|
106
|
+
};
|
|
107
|
+
};
|
|
123
108
|
|
|
124
|
-
|
|
109
|
+
_proto._checkProps = function _checkProps(props) {
|
|
110
|
+
var type = props.type,
|
|
111
|
+
credentials = props.credentials,
|
|
112
|
+
connection = props.connection,
|
|
113
|
+
geoColumn = props.geoColumn,
|
|
114
|
+
columns = props.columns;
|
|
125
115
|
|
|
126
|
-
|
|
116
|
+
var localCreds = _objectSpread(_objectSpread({}, (0, _config.getDefaultCredentials)()), credentials);
|
|
127
117
|
|
|
128
|
-
|
|
129
|
-
_core.log.assert(type === _mapsApiCommon.MAP_TYPES.QUERY || type === _mapsApiCommon.MAP_TYPES.TILESET, "Invalid type ".concat(type, ". Use type MAP_TYPES.QUERY or MAP_TYPES.TILESET for apiVersion ").concat(apiVersion));
|
|
118
|
+
var apiVersion = localCreds.apiVersion;
|
|
130
119
|
|
|
131
|
-
|
|
120
|
+
_core.log.assert(Object.values(_api.API_VERSIONS).includes(apiVersion), "Invalid apiVersion ".concat(apiVersion, ". Use API_VERSIONS enum."));
|
|
132
121
|
|
|
133
|
-
|
|
122
|
+
if (apiVersion === _api.API_VERSIONS.V1 || apiVersion === _api.API_VERSIONS.V2) {
|
|
123
|
+
_core.log.assert(type === _mapsApiCommon.MAP_TYPES.QUERY || type === _mapsApiCommon.MAP_TYPES.TILESET, "Invalid type ".concat(type, ". Use type MAP_TYPES.QUERY or MAP_TYPES.TILESET for apiVersion ").concat(apiVersion));
|
|
134
124
|
|
|
135
|
-
|
|
136
|
-
} else if (apiVersion === _api.API_VERSIONS.V3) {
|
|
137
|
-
_core.log.assert(connection, 'Missing mandatory connection parameter');
|
|
125
|
+
_core.log.assert(!connection, "Connection prop is not supported for apiVersion ".concat(apiVersion));
|
|
138
126
|
|
|
139
|
-
|
|
127
|
+
_core.log.assert(!geoColumn, "geoColumn prop is not supported for apiVersion ".concat(apiVersion));
|
|
140
128
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
129
|
+
_core.log.assert(!columns, "columns prop is not supported for apiVersion ".concat(apiVersion));
|
|
130
|
+
} else if (apiVersion === _api.API_VERSIONS.V3) {
|
|
131
|
+
_core.log.assert(connection, 'Missing mandatory connection parameter');
|
|
144
132
|
|
|
145
|
-
|
|
146
|
-
_core.log.assert(!geoColumn, "geoColumn prop is only supported for types: ".concat(_mapsApiCommon.GEO_COLUMN_SUPPORT.join()));
|
|
147
|
-
}
|
|
133
|
+
_core.log.assert(Object.values(_mapsApiCommon.MAP_TYPES).includes(type), "Invalid type ".concat(type, ". Use MAP_TYPES enum."));
|
|
148
134
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
135
|
+
if (!_mapsApiCommon.COLUMNS_SUPPORT.includes(type)) {
|
|
136
|
+
_core.log.assert(!columns, "columns prop is only supported for types: ".concat(_mapsApiCommon.COLUMNS_SUPPORT.join()));
|
|
152
137
|
}
|
|
153
|
-
}
|
|
154
|
-
}, {
|
|
155
|
-
key: "updateState",
|
|
156
|
-
value: function updateState(_ref) {
|
|
157
|
-
var props = _ref.props,
|
|
158
|
-
oldProps = _ref.oldProps,
|
|
159
|
-
changeFlags = _ref.changeFlags;
|
|
160
|
-
|
|
161
|
-
this._checkProps(props);
|
|
162
|
-
|
|
163
|
-
var shouldUpdateData = changeFlags.dataChanged || props.aggregationExp !== oldProps.aggregationExp || props.aggregationResLevel !== oldProps.aggregationResLevel || props.connection !== oldProps.connection || props.geoColumn !== oldProps.geoColumn || props.formatTiles !== oldProps.formatTiles || props.type !== oldProps.type || JSON.stringify(props.columns) !== JSON.stringify(oldProps.columns) || JSON.stringify(props.credentials) !== JSON.stringify(oldProps.credentials) || JSON.stringify(props.queryParameters) !== JSON.stringify(oldProps.queryParameters);
|
|
164
138
|
|
|
165
|
-
if (
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
apiVersion: null
|
|
169
|
-
});
|
|
139
|
+
if (!_mapsApiCommon.GEO_COLUMN_SUPPORT.includes(type)) {
|
|
140
|
+
_core.log.assert(!geoColumn, "geoColumn prop is only supported for types: ".concat(_mapsApiCommon.GEO_COLUMN_SUPPORT.join()));
|
|
141
|
+
}
|
|
170
142
|
|
|
171
|
-
|
|
143
|
+
if (columns) {
|
|
144
|
+
_core.log.assert(Array.isArray(columns), 'columns prop must be an Array');
|
|
172
145
|
}
|
|
173
146
|
}
|
|
174
|
-
}
|
|
175
|
-
key: "_updateData",
|
|
176
|
-
value: function () {
|
|
177
|
-
var _updateData2 = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee() {
|
|
178
|
-
var _this$props$onDataLoa, _this$props2, _this$props, type, source, credentials, connection, rest, localConfig, apiVersion, result;
|
|
179
|
-
|
|
180
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
181
|
-
while (1) {
|
|
182
|
-
switch (_context.prev = _context.next) {
|
|
183
|
-
case 0:
|
|
184
|
-
_context.prev = 0;
|
|
185
|
-
_this$props = this.props, type = _this$props.type, source = _this$props.data, credentials = _this$props.credentials, connection = _this$props.connection, rest = (0, _objectWithoutProperties2.default)(_this$props, _excluded);
|
|
186
|
-
localConfig = _objectSpread(_objectSpread({}, (0, _config.getDefaultCredentials)()), credentials);
|
|
187
|
-
apiVersion = localConfig.apiVersion;
|
|
188
|
-
|
|
189
|
-
if (!(apiVersion === _api.API_VERSIONS.V1 || apiVersion === _api.API_VERSIONS.V2)) {
|
|
190
|
-
_context.next = 11;
|
|
191
|
-
break;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
_context.next = 7;
|
|
195
|
-
return (0, _api.getDataV2)({
|
|
196
|
-
type: type,
|
|
197
|
-
source: source,
|
|
198
|
-
credentials: credentials
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
case 7:
|
|
202
|
-
_context.t0 = _context.sent;
|
|
203
|
-
result = {
|
|
204
|
-
data: _context.t0
|
|
205
|
-
};
|
|
206
|
-
_context.next = 14;
|
|
207
|
-
break;
|
|
147
|
+
};
|
|
208
148
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
source: source,
|
|
214
|
-
credentials: credentials,
|
|
215
|
-
connection: connection
|
|
216
|
-
}, rest), {}, {
|
|
217
|
-
format: _mapsApiCommon.FORMATS.TILEJSON
|
|
218
|
-
}));
|
|
219
|
-
|
|
220
|
-
case 13:
|
|
221
|
-
result = _context.sent;
|
|
222
|
-
|
|
223
|
-
case 14:
|
|
224
|
-
this.setState(_objectSpread(_objectSpread({}, result), {}, {
|
|
225
|
-
apiVersion: apiVersion
|
|
226
|
-
}));
|
|
227
|
-
(_this$props$onDataLoa = (_this$props2 = this.props).onDataLoad) === null || _this$props$onDataLoa === void 0 ? void 0 : _this$props$onDataLoa.call(_this$props2, result.data, {
|
|
228
|
-
propName: 'data',
|
|
229
|
-
layer: this
|
|
230
|
-
});
|
|
231
|
-
_context.next = 25;
|
|
232
|
-
break;
|
|
149
|
+
_proto.updateState = function updateState(_ref) {
|
|
150
|
+
var props = _ref.props,
|
|
151
|
+
oldProps = _ref.oldProps,
|
|
152
|
+
changeFlags = _ref.changeFlags;
|
|
233
153
|
|
|
234
|
-
|
|
235
|
-
_context.prev = 18;
|
|
236
|
-
_context.t1 = _context["catch"](0);
|
|
154
|
+
this._checkProps(props);
|
|
237
155
|
|
|
238
|
-
|
|
239
|
-
_context.next = 24;
|
|
240
|
-
break;
|
|
241
|
-
}
|
|
156
|
+
var shouldUpdateData = changeFlags.dataChanged || props.aggregationExp !== oldProps.aggregationExp || props.aggregationResLevel !== oldProps.aggregationResLevel || props.connection !== oldProps.connection || props.geoColumn !== oldProps.geoColumn || props.formatTiles !== oldProps.formatTiles || props.type !== oldProps.type || JSON.stringify(props.columns) !== JSON.stringify(oldProps.columns) || JSON.stringify(props.credentials) !== JSON.stringify(oldProps.credentials) || JSON.stringify(props.queryParameters) !== JSON.stringify(oldProps.queryParameters);
|
|
242
157
|
|
|
243
|
-
|
|
244
|
-
|
|
158
|
+
if (shouldUpdateData) {
|
|
159
|
+
this.setState({
|
|
160
|
+
data: null,
|
|
161
|
+
apiVersion: null
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
this._updateData();
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
_proto._updateData = function () {
|
|
169
|
+
var _updateData2 = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee() {
|
|
170
|
+
var _this$props$onDataLoa, _this$props2, _this$props, type, source, credentials, connection, rest, localConfig, apiVersion, result;
|
|
171
|
+
|
|
172
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
173
|
+
while (1) {
|
|
174
|
+
switch (_context.prev = _context.next) {
|
|
175
|
+
case 0:
|
|
176
|
+
_context.prev = 0;
|
|
177
|
+
_this$props = this.props, type = _this$props.type, source = _this$props.data, credentials = _this$props.credentials, connection = _this$props.connection, rest = (0, _objectWithoutProperties2.default)(_this$props, _excluded);
|
|
178
|
+
localConfig = _objectSpread(_objectSpread({}, (0, _config.getDefaultCredentials)()), credentials);
|
|
179
|
+
apiVersion = localConfig.apiVersion;
|
|
180
|
+
|
|
181
|
+
if (!(apiVersion === _api.API_VERSIONS.V1 || apiVersion === _api.API_VERSIONS.V2)) {
|
|
182
|
+
_context.next = 11;
|
|
245
183
|
break;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
_context.next = 7;
|
|
187
|
+
return (0, _api.getDataV2)({
|
|
188
|
+
type: type,
|
|
189
|
+
source: source,
|
|
190
|
+
credentials: credentials
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
case 7:
|
|
194
|
+
_context.t0 = _context.sent;
|
|
195
|
+
result = {
|
|
196
|
+
data: _context.t0
|
|
197
|
+
};
|
|
198
|
+
_context.next = 14;
|
|
199
|
+
break;
|
|
200
|
+
|
|
201
|
+
case 11:
|
|
202
|
+
_context.next = 13;
|
|
203
|
+
return (0, _api.fetchLayerData)(_objectSpread(_objectSpread({
|
|
204
|
+
type: type,
|
|
205
|
+
source: source,
|
|
206
|
+
credentials: credentials,
|
|
207
|
+
connection: connection
|
|
208
|
+
}, rest), {}, {
|
|
209
|
+
format: _mapsApiCommon.FORMATS.TILEJSON
|
|
210
|
+
}));
|
|
211
|
+
|
|
212
|
+
case 13:
|
|
213
|
+
result = _context.sent;
|
|
214
|
+
|
|
215
|
+
case 14:
|
|
216
|
+
this.setState(_objectSpread(_objectSpread({}, result), {}, {
|
|
217
|
+
apiVersion: apiVersion
|
|
218
|
+
}));
|
|
219
|
+
(_this$props$onDataLoa = (_this$props2 = this.props).onDataLoad) === null || _this$props$onDataLoa === void 0 ? void 0 : _this$props$onDataLoa.call(_this$props2, result.data, {
|
|
220
|
+
propName: 'data',
|
|
221
|
+
layer: this
|
|
222
|
+
});
|
|
223
|
+
_context.next = 25;
|
|
224
|
+
break;
|
|
225
|
+
|
|
226
|
+
case 18:
|
|
227
|
+
_context.prev = 18;
|
|
228
|
+
_context.t1 = _context["catch"](0);
|
|
229
|
+
|
|
230
|
+
if (!this.props.onDataError) {
|
|
231
|
+
_context.next = 24;
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
this.props.onDataError(_context.t1);
|
|
236
|
+
_context.next = 25;
|
|
237
|
+
break;
|
|
246
238
|
|
|
247
|
-
|
|
248
|
-
|
|
239
|
+
case 24:
|
|
240
|
+
throw _context.t1;
|
|
249
241
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
}
|
|
242
|
+
case 25:
|
|
243
|
+
case "end":
|
|
244
|
+
return _context.stop();
|
|
254
245
|
}
|
|
255
|
-
}
|
|
256
|
-
})
|
|
246
|
+
}
|
|
247
|
+
}, _callee, this, [[0, 18]]);
|
|
248
|
+
}));
|
|
257
249
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
250
|
+
function _updateData() {
|
|
251
|
+
return _updateData2.apply(this, arguments);
|
|
252
|
+
}
|
|
261
253
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
}
|
|
254
|
+
return _updateData;
|
|
255
|
+
}();
|
|
256
|
+
|
|
257
|
+
_proto._getSubLayerAndProps = function _getSubLayerAndProps() {
|
|
258
|
+
(0, _utils.assert)(this.state);
|
|
259
|
+
var _this$state = this.state,
|
|
260
|
+
data = _this$state.data,
|
|
261
|
+
apiVersion = _this$state.apiVersion;
|
|
262
|
+
var uniqueIdProperty = defaultProps.uniqueIdProperty;
|
|
263
|
+
var _this$props3 = this.props,
|
|
264
|
+
_notUsed = _this$props3.data,
|
|
265
|
+
propsNoData = (0, _objectWithoutProperties2.default)(_this$props3, _excluded2);
|
|
266
|
+
|
|
267
|
+
var props = _objectSpread({
|
|
268
|
+
uniqueIdProperty: uniqueIdProperty
|
|
269
|
+
}, propsNoData);
|
|
270
|
+
|
|
271
|
+
if (apiVersion === _api.API_VERSIONS.V1 || apiVersion === _api.API_VERSIONS.V2) {
|
|
272
|
+
return [_geoLayers.MVTLayer, props];
|
|
273
|
+
}
|
|
283
274
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
275
|
+
var tileUrl = new URL(data.tiles[0]);
|
|
276
|
+
props.formatTiles = props.formatTiles || tileUrl.searchParams.get('formatTiles');
|
|
277
|
+
return [(0, _layerMap.layerFromTileDataset)(props.formatTiles, data.scheme, props.type), props];
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
_proto.renderLayers = function renderLayers() {
|
|
281
|
+
(0, _utils.assert)(this.state);
|
|
282
|
+
var _this$state2 = this.state,
|
|
283
|
+
apiVersion = _this$state2.apiVersion,
|
|
284
|
+
data = _this$state2.data;
|
|
285
|
+
if (!data) return null;
|
|
286
|
+
var _this$props4 = this.props,
|
|
287
|
+
credentials = _this$props4.credentials,
|
|
288
|
+
updateTriggers = _this$props4.updateTriggers;
|
|
289
|
+
var loadOptions = this.getLoadOptions() || {};
|
|
290
|
+
|
|
291
|
+
if (apiVersion === _api.API_VERSIONS.V3) {
|
|
292
|
+
var _loadOptions$fetch;
|
|
293
|
+
|
|
294
|
+
var localConfig = _objectSpread(_objectSpread({}, (0, _config.getDefaultCredentials)()), credentials);
|
|
295
|
+
|
|
296
|
+
var accessToken = localConfig.accessToken;
|
|
297
|
+
loadOptions.fetch = _objectSpread(_objectSpread({}, loadOptions.fetch), {}, {
|
|
298
|
+
headers: _objectSpread(_objectSpread({}, (_loadOptions$fetch = loadOptions.fetch) === null || _loadOptions$fetch === void 0 ? void 0 : _loadOptions$fetch.headers), {}, {
|
|
299
|
+
Authorization: "Bearer ".concat(accessToken)
|
|
300
|
+
})
|
|
301
|
+
});
|
|
287
302
|
}
|
|
288
|
-
}, {
|
|
289
|
-
key: "renderLayers",
|
|
290
|
-
value: function renderLayers() {
|
|
291
|
-
(0, _utils.assert)(this.state);
|
|
292
|
-
var _this$state2 = this.state,
|
|
293
|
-
apiVersion = _this$state2.apiVersion,
|
|
294
|
-
data = _this$state2.data;
|
|
295
|
-
if (!data) return null;
|
|
296
|
-
var _this$props4 = this.props,
|
|
297
|
-
credentials = _this$props4.credentials,
|
|
298
|
-
updateTriggers = _this$props4.updateTriggers;
|
|
299
|
-
var loadOptions = this.getLoadOptions() || {};
|
|
300
|
-
|
|
301
|
-
if (apiVersion === _api.API_VERSIONS.V3) {
|
|
302
|
-
var _loadOptions$fetch;
|
|
303
|
-
|
|
304
|
-
var localConfig = _objectSpread(_objectSpread({}, (0, _config.getDefaultCredentials)()), credentials);
|
|
305
|
-
|
|
306
|
-
var accessToken = localConfig.accessToken;
|
|
307
|
-
loadOptions.fetch = _objectSpread(_objectSpread({}, loadOptions.fetch), {}, {
|
|
308
|
-
headers: _objectSpread(_objectSpread({}, (_loadOptions$fetch = loadOptions.fetch) === null || _loadOptions$fetch === void 0 ? void 0 : _loadOptions$fetch.headers), {}, {
|
|
309
|
-
Authorization: "Bearer ".concat(accessToken)
|
|
310
|
-
})
|
|
311
|
-
});
|
|
312
|
-
}
|
|
313
303
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
304
|
+
var _this$_getSubLayerAnd = this._getSubLayerAndProps(),
|
|
305
|
+
_this$_getSubLayerAnd2 = (0, _slicedToArray2.default)(_this$_getSubLayerAnd, 2),
|
|
306
|
+
layer = _this$_getSubLayerAnd2[0],
|
|
307
|
+
props = _this$_getSubLayerAnd2[1];
|
|
308
|
+
|
|
309
|
+
return new layer(props, this.getSubLayerProps({
|
|
310
|
+
id: "carto-".concat(layer.layerName),
|
|
311
|
+
data: data,
|
|
312
|
+
loadOptions: loadOptions,
|
|
313
|
+
updateTriggers: updateTriggers
|
|
314
|
+
}));
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
(0, _createClass2.default)(CartoLayer, [{
|
|
318
|
+
key: "isLoaded",
|
|
319
|
+
get: function get() {
|
|
320
|
+
return this.getSubLayers().length > 0 && (0, _get2.default)((0, _getPrototypeOf2.default)(CartoLayer.prototype), "isLoaded", this);
|
|
325
321
|
}
|
|
326
322
|
}]);
|
|
327
323
|
return CartoLayer;
|
|
328
324
|
}(_core.CompositeLayer);
|
|
329
325
|
|
|
330
326
|
exports.default = CartoLayer;
|
|
331
|
-
|
|
332
|
-
|
|
327
|
+
CartoLayer.layerName = 'CartoLayer';
|
|
328
|
+
CartoLayer.defaultProps = defaultProps;
|
|
333
329
|
//# sourceMappingURL=carto-layer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/layers/carto-layer.ts"],"names":["defaultProps","data","type","onDataLoad","value","onDataError","optional","uniqueIdProperty","credentials","connection","format","formatTiles","clientId","geoColumn","columns","headers","aggregationExp","aggregationResLevel","queryParameters","CartoLayer","state","apiVersion","getSubLayers","length","props","localCreds","log","assert","Object","values","API_VERSIONS","includes","V1","V2","MAP_TYPES","QUERY","TILESET","V3","COLUMNS_SUPPORT","join","GEO_COLUMN_SUPPORT","Array","isArray","oldProps","changeFlags","_checkProps","shouldUpdateData","dataChanged","JSON","stringify","setState","_updateData","source","rest","localConfig","result","FORMATS","TILEJSON","propName","layer","_notUsed","propsNoData","MVTLayer","tileUrl","URL","tiles","searchParams","get","scheme","updateTriggers","loadOptions","getLoadOptions","accessToken","fetch","Authorization","_getSubLayerAndProps","getSubLayerProps","id","layerName","CompositeLayer"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AASA;;AACA;;AAEA;;AACA;;AASA;;AAOA;;;;;;;;;;;;;AAEA,IAAMA,YAAY,GAAG;AAEnBC,EAAAA,IAAI,EAAE,IAFa;AAInBC,EAAAA,IAAI,EAAE,IAJa;AAKnBC,EAAAA,UAAU,EAAE;AAACD,IAAAA,IAAI,EAAE,UAAP;AAAmBE,IAAAA,KAAK,EAAE,eAAAH,IAAI,EAAI,CAAE;AAApC,GALO;AAMnBI,EAAAA,WAAW,EAAE;AAACH,IAAAA,IAAI,EAAE,UAAP;AAAmBE,IAAAA,KAAK,EAAE,IAA1B;AAAgCE,IAAAA,QAAQ,EAAE;AAA1C,GANM;AAOnBC,EAAAA,gBAAgB,EAAE,YAPC;AAUnBC,EAAAA,WAAW,EAAE,IAVM;AAgBnBC,EAAAA,UAAU,EAAE,IAhBO;AAmBnBC,EAAAA,MAAM,EAAE,IAnBW;AAsBnBC,EAAAA,WAAW,EAAE,IAtBM;AAyBnBC,EAAAA,QAAQ,EAAE,IAzBS;AA4BnBC,EAAAA,SAAS,EAAE,IA5BQ;AA+BnBC,EAAAA,OAAO,EAAE;AAACZ,IAAAA,IAAI,EAAE,OAAP;AAAgBE,IAAAA,KAAK,EAAE;AAAvB,GA/BU;AAkCnBW,EAAAA,OA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CAAsB;AACpBC,QAAAA,EAAE,kBAAWlB,KAAK,CAACmB,SAAjB,CADkB;AAEpB7E,QAAAA,IAAI,EAAJA,IAFoB;AAGpBqE,QAAAA,WAAW,EAAXA,WAHoB;AAIpBD,QAAAA,cAAc,EAAdA;AAJoB,OAAtB,CAFK,CAAP;AASD;;;EA3KiEU,oB;;;8BAA/C5D,U,eAGA,Y;8BAHAA,U,kBAIGnB,Y","sourcesContent":["import {\n CompositeLayer,\n CompositeLayerProps,\n Layer,\n LayerProps,\n log,\n UpdateParameters\n} from '@deck.gl/core';\n\nimport {MVTLayer} from '@deck.gl/geo-layers';\nimport {fetchLayerData, getDataV2, API_VERSIONS} from '../api';\nimport {CartoAPIError} from '../api/carto-api-error';\nimport {layerFromTileDataset} from '../api/layer-map';\nimport {\n COLUMNS_SUPPORT,\n FORMATS,\n GEO_COLUMN_SUPPORT,\n MapType,\n MAP_TYPES,\n TileFormat,\n QueryParameters\n} from '../api/maps-api-common';\nimport {\n ClassicCredentials,\n CloudNativeCredentials,\n Credentials,\n getDefaultCredentials\n} from '../config';\nimport {FetchLayerDataResult, Headers} from '../api/maps-v3-client';\nimport {assert} from '../utils';\n\nconst defaultProps = {\n // (String, required): data resource to load. table name, sql query or tileset name.\n data: null,\n // (Enum (MAP_TYPES), required)\n type: null,\n onDataLoad: {type: 'function', value: data => {}},\n onDataError: {type: 'function', value: null, optional: true},\n uniqueIdProperty: 'cartodb_id',\n\n // override carto credentials for the layer, set to null to read from default\n credentials: null,\n\n /*********************/\n /* API v3 PARAMETERS */\n /**********************/\n // (String, required): connection name at CARTO platform\n connection: null,\n\n // (String, optional): format of data\n format: null,\n\n // (String, optional): force format of data for tiles\n formatTiles: null,\n\n // (String, optional): clientId identifier used for internal tracing, place here a string to identify the client who is doing the request.\n clientId: null,\n\n // (String, optional): name of the `geo_column` in the CARTO platform. Use this override the default column ('geom'), from which the geometry information should be fetched.\n geoColumn: null,\n\n // (Array<String>, optional): names of columns to fetch. By default, all columns are fetched.\n columns: {type: 'array', value: null},\n\n // (Headers, optional): Custom headers to include in the map instantiation request.\n headers: {type: 'object', value: {}, optional: true},\n\n // (String, optional): aggregation SQL expression. Only used for spatial index datasets\n aggregationExp: null,\n\n // (Number, optional): aggregation resolution level. Only used for spatial index datasets, defaults to 6 for quadbins, 4 for h3\n aggregationResLevel: null,\n\n // (QueryParameters, optional): query parameters to be sent to the server.\n queryParameters: null\n};\n\n/** All properties supported by CartoLayer. */\nexport type CartoLayerProps = _CartoLayerProps & CompositeLayerProps;\n\n/** Properties added by CartoLayer. */\ntype _CartoLayerProps = {\n /**\n * Either a SQL query or a name of dataset/tileset.\n */\n data: string;\n\n /**\n * Data type.\n *\n * Possible values are:\n * * `MAP_TYPES.QUERY`, if data is a SQL query.\n * * `MAP_TYPES.TILESET`, if data is a tileset name.\n * * `MAP_TYPES.TABLE`, if data is a dataset name. Only supported with API v3.\n */\n type: MapType;\n\n /**\n * Name of the connection registered in the CARTO workspace.\n *\n * Required when apiVersion is `API_VERSIONS.V3`.\n */\n connection?: string;\n\n /**\n * Use to override the default tile data format.\n *\n * Only supported when apiVersion is `API_VERSIONS.V3`.\n *\n * Possible values are: `TILE_FORMATS.BINARY`, `TILE_FORMATS.GEOJSON` and `TILE_FORMATS.MVT`.\n */\n formatTiles?: TileFormat;\n\n /**\n * Name of the geo_column in the CARTO platform.\n *\n * Use this override the default column (`'geom'`), from which the geometry information should be fetched.\n *\n * Only supported when apiVersion is `API_VERSIONS.V3` and type is `MAP_TYPES.TABLE`.\n */\n geoColumn?: string;\n\n /**\n * Names of columns to fetch.\n *\n * By default, all columns are fetched\n *\n * Only supported when apiVersion is `API_VERSIONS.V3` and type is `MAP_TYPES.TABLE`.\n */\n columns?: string[];\n\n /**\n * A string pointing to a unique attribute at the result of the query.\n *\n * A unique attribute is needed for highlighting with vector tiles when a feature is split across two or more tiles.\n */\n uniqueIdProperty?: string;\n\n /**\n * Optional. Overrides the configuration to connect with CARTO.\n *\n * @see Credentials\n */\n credentials?: Credentials;\n\n /**\n * Called when the request to the CARTO Maps API failed.\n *\n * By default the CartoAPIError is thrown.\n */\n onDataError?: (err: CartoAPIError) => void;\n\n clientId?: string;\n\n /** Custom headers to include in the map instantiation request **/\n headers?: Headers;\n\n /** Aggregation SQL expression. Only used for spatial index datasets **/\n aggregationExp?: string;\n\n /** Aggregation resolution level. Only used for spatial index datasets, defaults to 6 for quadbins, 4 for h3. **/\n aggregationResLevel?: number;\n\n /** Query parameters to be sent to the server. **/\n queryParameters?: QueryParameters;\n};\n\nexport default class CartoLayer<ExtraProps extends {} = {}> extends CompositeLayer<\n Required<_CartoLayerProps> & ExtraProps\n> {\n static layerName = 'CartoLayer';\n static defaultProps = defaultProps;\n\n initializeState(): void {\n this.state = {\n data: null,\n apiVersion: null\n };\n }\n\n get isLoaded(): boolean {\n return this.getSubLayers().length > 0 && super.isLoaded;\n }\n\n _checkProps(props: CartoLayerProps): void {\n const {type, credentials, connection, geoColumn, columns} = props;\n const localCreds = {...getDefaultCredentials(), ...credentials};\n const {apiVersion} = localCreds;\n\n log.assert(\n Object.values(API_VERSIONS).includes(apiVersion),\n `Invalid apiVersion ${apiVersion}. Use API_VERSIONS enum.`\n );\n\n if (apiVersion === API_VERSIONS.V1 || apiVersion === API_VERSIONS.V2) {\n log.assert(\n type === MAP_TYPES.QUERY || type === MAP_TYPES.TILESET,\n `Invalid type ${type}. Use type MAP_TYPES.QUERY or MAP_TYPES.TILESET for apiVersion ${apiVersion}`\n );\n log.assert(!connection, `Connection prop is not supported for apiVersion ${apiVersion}`);\n log.assert(!geoColumn, `geoColumn prop is not supported for apiVersion ${apiVersion}`);\n log.assert(!columns, `columns prop is not supported for apiVersion ${apiVersion}`);\n } else if (apiVersion === API_VERSIONS.V3) {\n log.assert(connection, 'Missing mandatory connection parameter');\n log.assert(\n Object.values(MAP_TYPES).includes(type),\n `Invalid type ${type}. Use MAP_TYPES enum.`\n );\n if (!COLUMNS_SUPPORT.includes(type)) {\n log.assert(!columns, `columns prop is only supported for types: ${COLUMNS_SUPPORT.join()}`);\n }\n if (!GEO_COLUMN_SUPPORT.includes(type)) {\n log.assert(\n !geoColumn,\n `geoColumn prop is only supported for types: ${GEO_COLUMN_SUPPORT.join()}`\n );\n }\n if (columns) {\n log.assert(Array.isArray(columns), 'columns prop must be an Array');\n }\n }\n }\n\n updateState({props, oldProps, changeFlags}: UpdateParameters<this>) {\n this._checkProps(props);\n const shouldUpdateData =\n changeFlags.dataChanged ||\n props.aggregationExp !== oldProps.aggregationExp ||\n props.aggregationResLevel !== oldProps.aggregationResLevel ||\n props.connection !== oldProps.connection ||\n props.geoColumn !== oldProps.geoColumn ||\n props.formatTiles !== oldProps.formatTiles ||\n props.type !== oldProps.type ||\n JSON.stringify(props.columns) !== JSON.stringify(oldProps.columns) ||\n JSON.stringify(props.credentials) !== JSON.stringify(oldProps.credentials) ||\n JSON.stringify(props.queryParameters) !== JSON.stringify(oldProps.queryParameters);\n\n if (shouldUpdateData) {\n this.setState({data: null, apiVersion: null});\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this._updateData();\n }\n }\n\n async _updateData(): Promise<void> {\n try {\n const {type, data: source, credentials, connection, ...rest} = this.props;\n const localConfig = {...getDefaultCredentials(), ...credentials};\n const {apiVersion} = localConfig;\n\n let result: Partial<FetchLayerDataResult>;\n if (apiVersion === API_VERSIONS.V1 || apiVersion === API_VERSIONS.V2) {\n result = {\n data: await getDataV2({type, source, credentials: credentials as ClassicCredentials})\n };\n } else {\n result = await fetchLayerData({\n type,\n source,\n credentials: credentials as CloudNativeCredentials,\n connection,\n ...rest,\n // CartoLayer only supports tiled output from v8.8, force data format\n format: FORMATS.TILEJSON\n });\n }\n\n this.setState({...result, apiVersion});\n\n this.props.onDataLoad?.(result.data, {\n propName: 'data',\n layer: this\n });\n } catch (err) {\n if (this.props.onDataError) {\n this.props.onDataError(err as CartoAPIError);\n } else {\n throw err;\n }\n }\n }\n\n _getSubLayerAndProps(): [any, LayerProps] {\n assert(this.state);\n\n const {data, apiVersion} = this.state;\n\n const {uniqueIdProperty} = defaultProps;\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const {data: _notUsed, ...propsNoData} = this.props;\n // @ts-expect-error 'uniqueIdProperty' is specified more than once, so this usage will be overwritten.\n const props = {uniqueIdProperty, ...propsNoData};\n\n if (apiVersion === API_VERSIONS.V1 || apiVersion === API_VERSIONS.V2) {\n return [MVTLayer, props];\n }\n\n /* global URL */\n const tileUrl = new URL(data.tiles[0]);\n props.formatTiles =\n props.formatTiles || (tileUrl.searchParams.get('formatTiles') as TileFormat);\n\n return [layerFromTileDataset(props.formatTiles, data.scheme, props.type), props];\n }\n\n renderLayers(): Layer | null {\n assert(this.state);\n\n const {apiVersion, data} = this.state;\n\n if (!data) return null;\n\n const {credentials, updateTriggers} = this.props;\n const loadOptions: any = this.getLoadOptions() || {};\n if (apiVersion === API_VERSIONS.V3) {\n const localConfig = {...getDefaultCredentials(), ...credentials} as CloudNativeCredentials;\n const {accessToken} = localConfig;\n loadOptions.fetch = {\n ...loadOptions.fetch,\n headers: {\n ...loadOptions.fetch?.headers,\n Authorization: `Bearer ${accessToken}`\n }\n };\n }\n\n const [layer, props] = this._getSubLayerAndProps();\n\n // eslint-disable-next-line new-cap\n return new layer(\n props,\n this.getSubLayerProps({\n id: `carto-${layer.layerName}`,\n data,\n loadOptions,\n updateTriggers\n })\n );\n }\n}\n"],"file":"carto-layer.js"}
|
|
1
|
+
{"version":3,"sources":["../../../src/layers/carto-layer.ts"],"names":["defaultProps","data","type","onDataLoad","value","onDataError","optional","uniqueIdProperty","credentials","connection","format","formatTiles","clientId","geoColumn","columns","headers","aggregationExp","aggregationResLevel","queryParameters","CartoLayer","initializeState","state","apiVersion","_checkProps","props","localCreds","log","assert","Object","values","API_VERSIONS","includes","V1","V2","MAP_TYPES","QUERY","TILESET","V3","COLUMNS_SUPPORT","join","GEO_COLUMN_SUPPORT","Array","isArray","updateState","oldProps","changeFlags","shouldUpdateData","dataChanged","JSON","stringify","setState","_updateData","source","rest","localConfig","result","FORMATS","TILEJSON","propName","layer","_getSubLayerAndProps","_notUsed","propsNoData","MVTLayer","tileUrl","URL","tiles","searchParams","get","scheme","renderLayers","updateTriggers","loadOptions","getLoadOptions","accessToken","fetch","Authorization","getSubLayerProps","id","layerName","getSubLayers","length","CompositeLayer"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AASA;;AACA;;AAEA;;AACA;;AASA;;AAOA;;;;;;;;;;;;;AAEA,IAAMA,YAAY,GAAG;AAEnBC,EAAAA,IAAI,EAAE,IAFa;AAInBC,EAAAA,IAAI,EAAE,IAJa;AAKnBC,EAAAA,UAAU,EAAE;AAACD,IAAAA,IAAI,EAAE,UAAP;AAAmBE,IAAAA,KAAK,EAAE,eAAAH,IAAI,EAAI,CAAE;AAApC,GALO;AAMnBI,EAAAA,WAAW,EAAE;AAACH,IAAAA,IAAI,EAAE,UAAP;AAAmBE,IAAAA,KAAK,EAAE,IAA1B;AAAgCE,IAAAA,QAAQ,EAAE;AAA1C,GANM;AAOnBC,EAAAA,gBAAgB,EAAE,YAPC;AAUnBC,EAAAA,WAAW,EAAE,IAVM;AAgBnBC,EAAAA,UAAU,EAAE,IAhBO;AAmBnBC,EAAAA,MAAM,EAAE,IAnBW;AAsBnBC,EAAAA,WAAW,EAAE,IAtBM;AAyBnBC,EAAAA,QAAQ,EAAE,IAzBS;AA4BnBC,EAAAA,SAAS,EAAE,IA5BQ;AA+BnBC,EAAAA,OAAO,EAAE;AAACZ,IAAAA,IAAI,EAAE,OAAP;AAAgBE,IAAAA,KAAK,EAAE;AAAvB,GA/BU;AAkCnBW,EAAAA,OAAO,EAAE;AAACb,IAAAA,IAAI,EAAE,QAAP;AAAiBE,IAAAA,KAAK,EAAE,EAAxB;AAA4BE,IAAAA,QAAQ,EAAE;AAAtC,GAlCU;AAqCnBU,EAAAA,cAAc,EAAE,IArCG;AAwCnBC,EAAAA,mBAAmB,EAAE,IAxCF;AA2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9JD,eAAwB;AACtB,aAAO,KAAKS,YAAL,GAAoBC,MAApB,GAA6B,CAA7B,6FAAP;AACD;;;EAfiEC,oB;;;AAA/C/D,U,CAGZ4D,S,GAAY,Y;AAHA5D,U,CAIZnB,Y,GAAeA,Y","sourcesContent":["import {\n CompositeLayer,\n CompositeLayerProps,\n Layer,\n LayerProps,\n log,\n UpdateParameters\n} from '@deck.gl/core';\n\nimport {MVTLayer} from '@deck.gl/geo-layers';\nimport {fetchLayerData, getDataV2, API_VERSIONS} from '../api';\nimport {CartoAPIError} from '../api/carto-api-error';\nimport {layerFromTileDataset} from '../api/layer-map';\nimport {\n COLUMNS_SUPPORT,\n FORMATS,\n GEO_COLUMN_SUPPORT,\n MapType,\n MAP_TYPES,\n TileFormat,\n QueryParameters\n} from '../api/maps-api-common';\nimport {\n ClassicCredentials,\n CloudNativeCredentials,\n Credentials,\n getDefaultCredentials\n} from '../config';\nimport {FetchLayerDataResult, Headers} from '../api/maps-v3-client';\nimport {assert} from '../utils';\n\nconst defaultProps = {\n // (String, required): data resource to load. table name, sql query or tileset name.\n data: null,\n // (Enum (MAP_TYPES), required)\n type: null,\n onDataLoad: {type: 'function', value: data => {}},\n onDataError: {type: 'function', value: null, optional: true},\n uniqueIdProperty: 'cartodb_id',\n\n // override carto credentials for the layer, set to null to read from default\n credentials: null,\n\n /*********************/\n /* API v3 PARAMETERS */\n /**********************/\n // (String, required): connection name at CARTO platform\n connection: null,\n\n // (String, optional): format of data\n format: null,\n\n // (String, optional): force format of data for tiles\n formatTiles: null,\n\n // (String, optional): clientId identifier used for internal tracing, place here a string to identify the client who is doing the request.\n clientId: null,\n\n // (String, optional): name of the `geo_column` in the CARTO platform. Use this override the default column ('geom'), from which the geometry information should be fetched.\n geoColumn: null,\n\n // (Array<String>, optional): names of columns to fetch. By default, all columns are fetched.\n columns: {type: 'array', value: null},\n\n // (Headers, optional): Custom headers to include in the map instantiation request.\n headers: {type: 'object', value: {}, optional: true},\n\n // (String, optional): aggregation SQL expression. Only used for spatial index datasets\n aggregationExp: null,\n\n // (Number, optional): aggregation resolution level. Only used for spatial index datasets, defaults to 6 for quadbins, 4 for h3\n aggregationResLevel: null,\n\n // (QueryParameters, optional): query parameters to be sent to the server.\n queryParameters: null\n};\n\n/** All properties supported by CartoLayer. */\nexport type CartoLayerProps = _CartoLayerProps & CompositeLayerProps;\n\n/** Properties added by CartoLayer. */\ntype _CartoLayerProps = {\n /**\n * Either a SQL query or a name of dataset/tileset.\n */\n data: string;\n\n /**\n * Data type.\n *\n * Possible values are:\n * * `MAP_TYPES.QUERY`, if data is a SQL query.\n * * `MAP_TYPES.TILESET`, if data is a tileset name.\n * * `MAP_TYPES.TABLE`, if data is a dataset name. Only supported with API v3.\n */\n type: MapType;\n\n /**\n * Name of the connection registered in the CARTO workspace.\n *\n * Required when apiVersion is `API_VERSIONS.V3`.\n */\n connection?: string;\n\n /**\n * Use to override the default tile data format.\n *\n * Only supported when apiVersion is `API_VERSIONS.V3`.\n *\n * Possible values are: `TILE_FORMATS.BINARY`, `TILE_FORMATS.GEOJSON` and `TILE_FORMATS.MVT`.\n */\n formatTiles?: TileFormat;\n\n /**\n * Name of the geo_column in the CARTO platform.\n *\n * Use this override the default column (`'geom'`), from which the geometry information should be fetched.\n *\n * Only supported when apiVersion is `API_VERSIONS.V3` and type is `MAP_TYPES.TABLE`.\n */\n geoColumn?: string;\n\n /**\n * Names of columns to fetch.\n *\n * By default, all columns are fetched\n *\n * Only supported when apiVersion is `API_VERSIONS.V3` and type is `MAP_TYPES.TABLE`.\n */\n columns?: string[];\n\n /**\n * A string pointing to a unique attribute at the result of the query.\n *\n * A unique attribute is needed for highlighting with vector tiles when a feature is split across two or more tiles.\n */\n uniqueIdProperty?: string;\n\n /**\n * Optional. Overrides the configuration to connect with CARTO.\n *\n * @see Credentials\n */\n credentials?: Credentials;\n\n /**\n * Called when the request to the CARTO Maps API failed.\n *\n * By default the CartoAPIError is thrown.\n */\n onDataError?: (err: CartoAPIError) => void;\n\n clientId?: string;\n\n /** Custom headers to include in the map instantiation request **/\n headers?: Headers;\n\n /** Aggregation SQL expression. Only used for spatial index datasets **/\n aggregationExp?: string;\n\n /** Aggregation resolution level. Only used for spatial index datasets, defaults to 6 for quadbins, 4 for h3. **/\n aggregationResLevel?: number;\n\n /** Query parameters to be sent to the server. **/\n queryParameters?: QueryParameters;\n};\n\nexport default class CartoLayer<ExtraProps extends {} = {}> extends CompositeLayer<\n Required<_CartoLayerProps> & ExtraProps\n> {\n static layerName = 'CartoLayer';\n static defaultProps = defaultProps;\n\n initializeState(): void {\n this.state = {\n data: null,\n apiVersion: null\n };\n }\n\n get isLoaded(): boolean {\n return this.getSubLayers().length > 0 && super.isLoaded;\n }\n\n _checkProps(props: CartoLayerProps): void {\n const {type, credentials, connection, geoColumn, columns} = props;\n const localCreds = {...getDefaultCredentials(), ...credentials};\n const {apiVersion} = localCreds;\n\n log.assert(\n Object.values(API_VERSIONS).includes(apiVersion),\n `Invalid apiVersion ${apiVersion}. Use API_VERSIONS enum.`\n );\n\n if (apiVersion === API_VERSIONS.V1 || apiVersion === API_VERSIONS.V2) {\n log.assert(\n type === MAP_TYPES.QUERY || type === MAP_TYPES.TILESET,\n `Invalid type ${type}. Use type MAP_TYPES.QUERY or MAP_TYPES.TILESET for apiVersion ${apiVersion}`\n );\n log.assert(!connection, `Connection prop is not supported for apiVersion ${apiVersion}`);\n log.assert(!geoColumn, `geoColumn prop is not supported for apiVersion ${apiVersion}`);\n log.assert(!columns, `columns prop is not supported for apiVersion ${apiVersion}`);\n } else if (apiVersion === API_VERSIONS.V3) {\n log.assert(connection, 'Missing mandatory connection parameter');\n log.assert(\n Object.values(MAP_TYPES).includes(type),\n `Invalid type ${type}. Use MAP_TYPES enum.`\n );\n if (!COLUMNS_SUPPORT.includes(type)) {\n log.assert(!columns, `columns prop is only supported for types: ${COLUMNS_SUPPORT.join()}`);\n }\n if (!GEO_COLUMN_SUPPORT.includes(type)) {\n log.assert(\n !geoColumn,\n `geoColumn prop is only supported for types: ${GEO_COLUMN_SUPPORT.join()}`\n );\n }\n if (columns) {\n log.assert(Array.isArray(columns), 'columns prop must be an Array');\n }\n }\n }\n\n updateState({props, oldProps, changeFlags}: UpdateParameters<this>) {\n this._checkProps(props);\n const shouldUpdateData =\n changeFlags.dataChanged ||\n props.aggregationExp !== oldProps.aggregationExp ||\n props.aggregationResLevel !== oldProps.aggregationResLevel ||\n props.connection !== oldProps.connection ||\n props.geoColumn !== oldProps.geoColumn ||\n props.formatTiles !== oldProps.formatTiles ||\n props.type !== oldProps.type ||\n JSON.stringify(props.columns) !== JSON.stringify(oldProps.columns) ||\n JSON.stringify(props.credentials) !== JSON.stringify(oldProps.credentials) ||\n JSON.stringify(props.queryParameters) !== JSON.stringify(oldProps.queryParameters);\n\n if (shouldUpdateData) {\n this.setState({data: null, apiVersion: null});\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this._updateData();\n }\n }\n\n async _updateData(): Promise<void> {\n try {\n const {type, data: source, credentials, connection, ...rest} = this.props;\n const localConfig = {...getDefaultCredentials(), ...credentials};\n const {apiVersion} = localConfig;\n\n let result: Partial<FetchLayerDataResult>;\n if (apiVersion === API_VERSIONS.V1 || apiVersion === API_VERSIONS.V2) {\n result = {\n data: await getDataV2({type, source, credentials: credentials as ClassicCredentials})\n };\n } else {\n result = await fetchLayerData({\n type,\n source,\n credentials: credentials as CloudNativeCredentials,\n connection,\n ...rest,\n // CartoLayer only supports tiled output from v8.8, force data format\n format: FORMATS.TILEJSON\n });\n }\n\n this.setState({...result, apiVersion});\n\n this.props.onDataLoad?.(result.data, {\n propName: 'data',\n layer: this\n });\n } catch (err) {\n if (this.props.onDataError) {\n this.props.onDataError(err as CartoAPIError);\n } else {\n throw err;\n }\n }\n }\n\n _getSubLayerAndProps(): [any, LayerProps] {\n assert(this.state);\n\n const {data, apiVersion} = this.state;\n\n const {uniqueIdProperty} = defaultProps;\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const {data: _notUsed, ...propsNoData} = this.props;\n // @ts-expect-error 'uniqueIdProperty' is specified more than once, so this usage will be overwritten.\n const props = {uniqueIdProperty, ...propsNoData};\n\n if (apiVersion === API_VERSIONS.V1 || apiVersion === API_VERSIONS.V2) {\n return [MVTLayer, props];\n }\n\n /* global URL */\n const tileUrl = new URL(data.tiles[0]);\n props.formatTiles =\n props.formatTiles || (tileUrl.searchParams.get('formatTiles') as TileFormat);\n\n return [layerFromTileDataset(props.formatTiles, data.scheme, props.type), props];\n }\n\n renderLayers(): Layer | null {\n assert(this.state);\n\n const {apiVersion, data} = this.state;\n\n if (!data) return null;\n\n const {credentials, updateTriggers} = this.props;\n const loadOptions: any = this.getLoadOptions() || {};\n if (apiVersion === API_VERSIONS.V3) {\n const localConfig = {...getDefaultCredentials(), ...credentials} as CloudNativeCredentials;\n const {accessToken} = localConfig;\n loadOptions.fetch = {\n ...loadOptions.fetch,\n headers: {\n ...loadOptions.fetch?.headers,\n Authorization: `Bearer ${accessToken}`\n }\n };\n }\n\n const [layer, props] = this._getSubLayerAndProps();\n\n // eslint-disable-next-line new-cap\n return new layer(\n props,\n this.getSubLayerProps({\n id: `carto-${layer.layerName}`,\n data,\n loadOptions,\n updateTriggers\n })\n );\n }\n}\n"],"file":"carto-layer.js"}
|