@deck.gl/carto 8.5.5 → 8.5.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.dev.js +54 -11
- package/dist/es5/api/maps-v3-client.js +28 -8
- package/dist/es5/api/maps-v3-client.js.map +1 -1
- package/dist/es5/layers/carto-layer.js +29 -6
- package/dist/es5/layers/carto-layer.js.map +1 -1
- package/dist/esm/api/maps-v3-client.js +29 -5
- package/dist/esm/api/maps-v3-client.js.map +1 -1
- package/dist/esm/layers/carto-layer.js +27 -5
- package/dist/esm/layers/carto-layer.js.map +1 -1
- package/dist.min.js +1 -1
- package/package.json +2 -2
- package/src/api/maps-v3-client.js +31 -7
- package/src/layers/carto-layer.js +23 -4
|
@@ -55,10 +55,11 @@ async function request({method, url, format, accessToken, body}) {
|
|
|
55
55
|
*/
|
|
56
56
|
function dealWithError({response, error}) {
|
|
57
57
|
switch (response.status) {
|
|
58
|
+
case 400:
|
|
59
|
+
throw new Error(`Bad request. ${error}`);
|
|
58
60
|
case 401:
|
|
59
61
|
case 403:
|
|
60
|
-
throw new Error(`Unauthorized access
|
|
61
|
-
|
|
62
|
+
throw new Error(`Unauthorized access. ${error}`);
|
|
62
63
|
default:
|
|
63
64
|
throw new Error(error);
|
|
64
65
|
}
|
|
@@ -67,19 +68,35 @@ function dealWithError({response, error}) {
|
|
|
67
68
|
/**
|
|
68
69
|
* Build a URL with all required parameters
|
|
69
70
|
*/
|
|
70
|
-
function getParameters({type, source}) {
|
|
71
|
+
function getParameters({type, source, geoColumn, columns}) {
|
|
71
72
|
const encodedClient = encodeParameter('client', 'deck-gl-carto');
|
|
72
73
|
const parameters = [encodedClient];
|
|
73
74
|
|
|
74
75
|
const sourceName = type === MAP_TYPES.QUERY ? 'q' : 'name';
|
|
75
76
|
parameters.push(encodeParameter(sourceName, source));
|
|
76
77
|
|
|
78
|
+
if (type === MAP_TYPES.TABLE) {
|
|
79
|
+
if (geoColumn) {
|
|
80
|
+
parameters.push(encodeParameter('geo_column', geoColumn));
|
|
81
|
+
}
|
|
82
|
+
if (columns) {
|
|
83
|
+
parameters.push(encodeParameter('columns', columns.join(',')));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
77
87
|
return parameters.join('&');
|
|
78
88
|
}
|
|
79
89
|
|
|
80
|
-
export async function mapInstantiation({
|
|
90
|
+
export async function mapInstantiation({
|
|
91
|
+
type,
|
|
92
|
+
source,
|
|
93
|
+
connection,
|
|
94
|
+
credentials,
|
|
95
|
+
geoColumn,
|
|
96
|
+
columns
|
|
97
|
+
}) {
|
|
81
98
|
const baseUrl = `${credentials.mapsUrl}/${connection}/${type}`;
|
|
82
|
-
const url = `${baseUrl}?${getParameters({type, source})}`;
|
|
99
|
+
const url = `${baseUrl}?${getParameters({type, source, geoColumn, columns})}`;
|
|
83
100
|
const {accessToken} = credentials;
|
|
84
101
|
|
|
85
102
|
const format = 'json';
|
|
@@ -106,7 +123,7 @@ function getUrlFromMetadata(metadata, format) {
|
|
|
106
123
|
return null;
|
|
107
124
|
}
|
|
108
125
|
|
|
109
|
-
export async function getData({type, source, connection, credentials, format}) {
|
|
126
|
+
export async function getData({type, source, connection, credentials, geoColumn, columns, format}) {
|
|
110
127
|
const localCreds = {...getDefaultCredentials(), ...credentials};
|
|
111
128
|
|
|
112
129
|
log.assert(connection, 'Must define connection');
|
|
@@ -122,7 +139,14 @@ export async function getData({type, source, connection, credentials, format}) {
|
|
|
122
139
|
localCreds.mapsUrl = buildMapsUrlFromBase(localCreds.apiBaseUrl);
|
|
123
140
|
}
|
|
124
141
|
|
|
125
|
-
const metadata = await mapInstantiation({
|
|
142
|
+
const metadata = await mapInstantiation({
|
|
143
|
+
type,
|
|
144
|
+
source,
|
|
145
|
+
connection,
|
|
146
|
+
credentials: localCreds,
|
|
147
|
+
geoColumn,
|
|
148
|
+
columns
|
|
149
|
+
});
|
|
126
150
|
let url;
|
|
127
151
|
let mapFormat;
|
|
128
152
|
|
|
@@ -20,7 +20,13 @@ const defaultProps = {
|
|
|
20
20
|
/* API v3 PARAMETERS */
|
|
21
21
|
/**********************/
|
|
22
22
|
// (String, required): connection name at CARTO platform
|
|
23
|
-
connection: null
|
|
23
|
+
connection: null,
|
|
24
|
+
|
|
25
|
+
// (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.
|
|
26
|
+
geoColumn: null,
|
|
27
|
+
|
|
28
|
+
// (Array<String>, optional): names of columns to fetch. By default, all columns are fetched.
|
|
29
|
+
columns: {type: 'array', value: null}
|
|
24
30
|
};
|
|
25
31
|
|
|
26
32
|
export default class CartoLayer extends CompositeLayer {
|
|
@@ -36,7 +42,7 @@ export default class CartoLayer extends CompositeLayer {
|
|
|
36
42
|
}
|
|
37
43
|
|
|
38
44
|
_checkProps(props) {
|
|
39
|
-
const {type, credentials, connection} = props;
|
|
45
|
+
const {type, credentials, connection, geoColumn, columns} = props;
|
|
40
46
|
const localCreds = {...getDefaultCredentials(), ...credentials};
|
|
41
47
|
const {apiVersion} = localCreds;
|
|
42
48
|
|
|
@@ -51,12 +57,21 @@ export default class CartoLayer extends CompositeLayer {
|
|
|
51
57
|
`Invalid type ${type}. Use type MAP_TYPES.QUERY or MAP_TYPES.TILESET for apiVersion ${apiVersion}`
|
|
52
58
|
);
|
|
53
59
|
log.assert(!connection, `Connection prop is not supported for apiVersion ${apiVersion}`);
|
|
60
|
+
log.assert(!geoColumn, `geoColumn prop is not supported for apiVersion ${apiVersion}`);
|
|
61
|
+
log.assert(!columns, `columns prop is not supported for apiVersion ${apiVersion}`);
|
|
54
62
|
} else if (apiVersion === API_VERSIONS.V3) {
|
|
55
63
|
log.assert(connection, 'Missing mandatory connection parameter');
|
|
56
64
|
log.assert(
|
|
57
65
|
Object.values(MAP_TYPES).includes(type),
|
|
58
66
|
`Invalid type ${type}. Use MAP_TYPES enum.`
|
|
59
67
|
);
|
|
68
|
+
if (type !== MAP_TYPES.TABLE) {
|
|
69
|
+
log.assert(!geoColumn, `geoColumn prop is only supported for type ${MAP_TYPES.TABLE}`);
|
|
70
|
+
log.assert(!columns, `columns prop is only supported for type ${MAP_TYPES.TABLE}`);
|
|
71
|
+
}
|
|
72
|
+
if (columns) {
|
|
73
|
+
log.assert(Array.isArray(columns), 'columns prop must be an Array');
|
|
74
|
+
}
|
|
60
75
|
}
|
|
61
76
|
}
|
|
62
77
|
|
|
@@ -65,6 +80,8 @@ export default class CartoLayer extends CompositeLayer {
|
|
|
65
80
|
const shouldUpdateData =
|
|
66
81
|
changeFlags.dataChanged ||
|
|
67
82
|
props.connection !== oldProps.connection ||
|
|
83
|
+
props.geoColumn !== oldProps.geoColumn ||
|
|
84
|
+
JSON.stringify(props.columns) !== JSON.stringify(oldProps.columns) ||
|
|
68
85
|
props.type !== oldProps.type ||
|
|
69
86
|
JSON.stringify(props.credentials) !== JSON.stringify(oldProps.credentials);
|
|
70
87
|
|
|
@@ -76,7 +93,7 @@ export default class CartoLayer extends CompositeLayer {
|
|
|
76
93
|
|
|
77
94
|
async _updateData() {
|
|
78
95
|
try {
|
|
79
|
-
const {type, data: source, connection, credentials} = this.props;
|
|
96
|
+
const {type, data: source, connection, credentials, geoColumn, columns} = this.props;
|
|
80
97
|
const localConfig = {...getDefaultCredentials(), ...credentials};
|
|
81
98
|
const {apiVersion} = localConfig;
|
|
82
99
|
|
|
@@ -87,7 +104,9 @@ export default class CartoLayer extends CompositeLayer {
|
|
|
87
104
|
type,
|
|
88
105
|
source,
|
|
89
106
|
connection,
|
|
90
|
-
credentials
|
|
107
|
+
credentials,
|
|
108
|
+
geoColumn,
|
|
109
|
+
columns
|
|
91
110
|
});
|
|
92
111
|
} else if (apiVersion === API_VERSIONS.V1 || apiVersion === API_VERSIONS.V2) {
|
|
93
112
|
data = await getDataV2({type, source, credentials});
|