@deck.gl/carto 8.7.9 → 8.8.0-alpha.2
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 +33062 -40367
- package/dist/es5/api/maps-api-common.js.map +1 -1
- package/dist/es5/api/maps-v3-client.js +9 -23
- package/dist/es5/api/maps-v3-client.js.map +1 -1
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/layers/carto-layer.js +22 -12
- package/dist/es5/layers/carto-layer.js.map +1 -1
- package/dist/esm/api/maps-api-common.js.map +1 -1
- package/dist/esm/api/maps-v3-client.js +2 -19
- package/dist/esm/api/maps-v3-client.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/layers/carto-layer.js +23 -7
- package/dist/esm/layers/carto-layer.js.map +1 -1
- package/dist.min.js +4 -4
- package/package.json +9 -8
- package/src/api/maps-api-common.ts +3 -3
- package/src/api/maps-v3-client.ts +3 -19
- package/src/index.ts +2 -0
- package/src/layers/{carto-layer.js → carto-layer.ts} +147 -22
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@deck.gl/carto",
|
|
3
3
|
"description": "CARTO official integration with Deck.gl. Build geospatial applications using CARTO and Deck.gl.",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "8.
|
|
5
|
+
"version": "8.8.0-alpha.2",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
8
8
|
},
|
|
@@ -31,12 +31,12 @@
|
|
|
31
31
|
"prepublishOnly": "npm run build-bundle && npm run build-bundle -- --env.dev"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@loaders.gl/gis": "^3.
|
|
35
|
-
"@loaders.gl/loader-utils": "^3.
|
|
36
|
-
"@loaders.gl/mvt": "^3.
|
|
37
|
-
"@loaders.gl/tiles": "^3.
|
|
34
|
+
"@loaders.gl/gis": "^3.2.0-alpha.4",
|
|
35
|
+
"@loaders.gl/loader-utils": "^3.2.0-alpha.4",
|
|
36
|
+
"@loaders.gl/mvt": "^3.2.0-alpha.4",
|
|
37
|
+
"@loaders.gl/tiles": "^3.2.0-alpha.4",
|
|
38
38
|
"@luma.gl/constants": "^8.5.10",
|
|
39
|
-
"@math.gl/web-mercator": "
|
|
39
|
+
"@math.gl/web-mercator": "3.6.0-alpha.5",
|
|
40
40
|
"cartocolor": "^4.0.2",
|
|
41
41
|
"d3-array": "^2.8.0",
|
|
42
42
|
"d3-color": "^2.0.0",
|
|
@@ -53,9 +53,10 @@
|
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"@deck.gl/aggregation-layers": "^8.0.0",
|
|
55
55
|
"@deck.gl/core": "^8.0.0",
|
|
56
|
+
"@deck.gl/extensions": "^8.0.0",
|
|
56
57
|
"@deck.gl/geo-layers": "^8.0.0",
|
|
57
58
|
"@deck.gl/layers": "^8.0.0",
|
|
58
|
-
"@loaders.gl/core": "^3.
|
|
59
|
+
"@loaders.gl/core": "^3.0.0"
|
|
59
60
|
},
|
|
60
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "a52215449dff06fb683f5afd6399526353d11f35"
|
|
61
62
|
}
|
|
@@ -20,8 +20,8 @@ export const MAP_TYPES = {
|
|
|
20
20
|
TILESET: 'tileset'
|
|
21
21
|
} as const;
|
|
22
22
|
export type MapType = ValuesOf<typeof MAP_TYPES>;
|
|
23
|
-
export const COLUMNS_SUPPORT = [MAP_TYPES.TABLE];
|
|
24
|
-
export const GEO_COLUMN_SUPPORT = [MAP_TYPES.QUERY, MAP_TYPES.TABLE];
|
|
23
|
+
export const COLUMNS_SUPPORT: MapType[] = [MAP_TYPES.TABLE];
|
|
24
|
+
export const GEO_COLUMN_SUPPORT: MapType[] = [MAP_TYPES.QUERY, MAP_TYPES.TABLE];
|
|
25
25
|
|
|
26
26
|
// AVAILABLE FORMATS
|
|
27
27
|
export const FORMATS = {
|
|
@@ -59,7 +59,7 @@ export interface SchemaField {
|
|
|
59
59
|
export interface MapInstantiation extends MapInstantiationFormats {
|
|
60
60
|
nrows: number;
|
|
61
61
|
size?: number;
|
|
62
|
-
schema
|
|
62
|
+
schema: SchemaField[];
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
type MapInstantiationFormats = Record<
|
|
@@ -112,7 +112,6 @@ type FetchLayerDataParams = {
|
|
|
112
112
|
credentials: CloudNativeCredentials;
|
|
113
113
|
geoColumn?: string;
|
|
114
114
|
columns?: string[];
|
|
115
|
-
schema?: boolean;
|
|
116
115
|
clientId?: string;
|
|
117
116
|
format?: Format;
|
|
118
117
|
formatTiles?: TileFormat;
|
|
@@ -128,15 +127,11 @@ function getParameters({
|
|
|
128
127
|
source,
|
|
129
128
|
geoColumn,
|
|
130
129
|
columns,
|
|
131
|
-
schema,
|
|
132
130
|
clientId,
|
|
133
131
|
aggregationExp,
|
|
134
132
|
aggregationResLevel
|
|
135
133
|
}: Omit<FetchLayerDataParams, 'connection' | 'credentials'>) {
|
|
136
134
|
const parameters = [encodeParameter('client', clientId || DEFAULT_CLIENT)];
|
|
137
|
-
if (schema) {
|
|
138
|
-
parameters.push(encodeParameter('schema', true));
|
|
139
|
-
}
|
|
140
135
|
|
|
141
136
|
const sourceName = type === MAP_TYPES.QUERY ? 'q' : 'name';
|
|
142
137
|
parameters.push(encodeParameter(sourceName, source));
|
|
@@ -164,7 +159,6 @@ export async function mapInstantiation({
|
|
|
164
159
|
credentials,
|
|
165
160
|
geoColumn,
|
|
166
161
|
columns,
|
|
167
|
-
schema,
|
|
168
162
|
clientId,
|
|
169
163
|
aggregationExp,
|
|
170
164
|
aggregationResLevel
|
|
@@ -175,7 +169,6 @@ export async function mapInstantiation({
|
|
|
175
169
|
source,
|
|
176
170
|
geoColumn,
|
|
177
171
|
columns,
|
|
178
|
-
schema,
|
|
179
172
|
clientId,
|
|
180
173
|
aggregationExp,
|
|
181
174
|
aggregationResLevel
|
|
@@ -248,8 +241,8 @@ function checkFetchLayerDataParameters({
|
|
|
248
241
|
|
|
249
242
|
export interface FetchLayerDataResult {
|
|
250
243
|
data: any;
|
|
251
|
-
format
|
|
252
|
-
schema
|
|
244
|
+
format?: Format;
|
|
245
|
+
schema: SchemaField[];
|
|
253
246
|
}
|
|
254
247
|
export async function fetchLayerData({
|
|
255
248
|
type,
|
|
@@ -260,7 +253,6 @@ export async function fetchLayerData({
|
|
|
260
253
|
columns,
|
|
261
254
|
format,
|
|
262
255
|
formatTiles,
|
|
263
|
-
schema,
|
|
264
256
|
clientId,
|
|
265
257
|
aggregationExp,
|
|
266
258
|
aggregationResLevel
|
|
@@ -276,18 +268,13 @@ export async function fetchLayerData({
|
|
|
276
268
|
columns,
|
|
277
269
|
format,
|
|
278
270
|
formatTiles,
|
|
279
|
-
schema,
|
|
280
271
|
clientId,
|
|
281
272
|
aggregationExp,
|
|
282
273
|
aggregationResLevel
|
|
283
274
|
});
|
|
284
275
|
|
|
285
276
|
const data = await requestData({url, format: mapFormat, accessToken});
|
|
286
|
-
const result: FetchLayerDataResult = {data, format: mapFormat};
|
|
287
|
-
if (schema) {
|
|
288
|
-
result.schema = metadata.schema;
|
|
289
|
-
}
|
|
290
|
-
|
|
277
|
+
const result: FetchLayerDataResult = {data, format: mapFormat, schema: metadata.schema};
|
|
291
278
|
return result;
|
|
292
279
|
}
|
|
293
280
|
|
|
@@ -300,7 +287,6 @@ async function _fetchDataUrl({
|
|
|
300
287
|
columns,
|
|
301
288
|
format,
|
|
302
289
|
formatTiles,
|
|
303
|
-
schema,
|
|
304
290
|
clientId,
|
|
305
291
|
aggregationExp,
|
|
306
292
|
aggregationResLevel
|
|
@@ -334,7 +320,6 @@ async function _fetchDataUrl({
|
|
|
334
320
|
credentials: localCreds,
|
|
335
321
|
geoColumn,
|
|
336
322
|
columns,
|
|
337
|
-
schema,
|
|
338
323
|
clientId,
|
|
339
324
|
aggregationExp,
|
|
340
325
|
aggregationResLevel
|
|
@@ -390,7 +375,6 @@ export async function getData({
|
|
|
390
375
|
geoColumn,
|
|
391
376
|
columns,
|
|
392
377
|
format,
|
|
393
|
-
schema: false,
|
|
394
378
|
clientId
|
|
395
379
|
});
|
|
396
380
|
return layerData.data;
|
package/src/index.ts
CHANGED
|
@@ -1,16 +1,28 @@
|
|
|
1
|
-
import {CompositeLayer, log} from '@deck.gl/core';
|
|
1
|
+
import {CompositeLayer, Layer, log} from '@deck.gl/core';
|
|
2
2
|
import CartoTileLayer from './carto-tile-layer';
|
|
3
3
|
import {MVTLayer} from '@deck.gl/geo-layers';
|
|
4
4
|
import {GeoJsonLayer} from '@deck.gl/layers';
|
|
5
5
|
import {fetchLayerData, getDataV2, API_VERSIONS} from '../api';
|
|
6
6
|
import {
|
|
7
7
|
COLUMNS_SUPPORT,
|
|
8
|
+
Format,
|
|
8
9
|
FORMATS,
|
|
9
10
|
GEO_COLUMN_SUPPORT,
|
|
11
|
+
MapType,
|
|
10
12
|
MAP_TYPES,
|
|
13
|
+
TileFormat,
|
|
11
14
|
TILE_FORMATS
|
|
12
15
|
} from '../api/maps-api-common';
|
|
13
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
ClassicCredentials,
|
|
18
|
+
CloudNativeCredentials,
|
|
19
|
+
Credentials,
|
|
20
|
+
getDefaultCredentials
|
|
21
|
+
} from '../config';
|
|
22
|
+
import {CompositeLayerProps, LayerProps} from 'modules/core/src/types/layer-props';
|
|
23
|
+
import {ChangeFlags} from 'modules/core/src/lib/layer-state';
|
|
24
|
+
import {FetchLayerDataResult} from '../api/maps-v3-client';
|
|
25
|
+
import {assert} from '../utils';
|
|
14
26
|
|
|
15
27
|
const defaultProps = {
|
|
16
28
|
// (String, required): data resource to load. table name, sql query or tileset name.
|
|
@@ -46,19 +58,105 @@ const defaultProps = {
|
|
|
46
58
|
columns: {type: 'array', value: null}
|
|
47
59
|
};
|
|
48
60
|
|
|
49
|
-
export
|
|
50
|
-
|
|
61
|
+
export interface CartoLayerProps<DataT = any> extends CompositeLayerProps<DataT> {
|
|
62
|
+
/**
|
|
63
|
+
* Either a SQL query or a name of dataset/tileset.
|
|
64
|
+
*/
|
|
65
|
+
data: string;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Data type.
|
|
69
|
+
*
|
|
70
|
+
* Possible values are:
|
|
71
|
+
* * `MAP_TYPES.QUERY`, if data is a SQL query.
|
|
72
|
+
* * `MAP_TYPES.TILESET`, if data is a tileset name.
|
|
73
|
+
* * `MAP_TYPES.TABLE`, if data is a dataset name. Only supported with API v3.
|
|
74
|
+
*/
|
|
75
|
+
type: MapType;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Name of the connection registered in the CARTO workspace.
|
|
79
|
+
*
|
|
80
|
+
* Required when apiVersion is `API_VERSIONS.V3`.
|
|
81
|
+
*/
|
|
82
|
+
connection?: string;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Use to override the default data format.
|
|
86
|
+
*
|
|
87
|
+
* Only supported when apiVersion is `API_VERSIONS.V3`.
|
|
88
|
+
*
|
|
89
|
+
* Possible values are: `FORMATS.GEOJSON`, `FORMATS.JSON` and `FORMATS.TILEJSON`.
|
|
90
|
+
*/
|
|
91
|
+
format?: Format;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Use to override the default tile data format.
|
|
95
|
+
*
|
|
96
|
+
* Only supported when apiVersion is `API_VERSIONS.V3` and format is `FORMATS.TILEJSON`.
|
|
97
|
+
*
|
|
98
|
+
* Possible values are: `TILE_FORMATS.BINARY`, `TILE_FORMATS.GEOJSON` and `TILE_FORMATS.MVT`.
|
|
99
|
+
*/
|
|
100
|
+
formatTiles?: TileFormat;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Name of the geo_column in the CARTO platform.
|
|
104
|
+
*
|
|
105
|
+
* Use this override the default column (`'geom'`), from which the geometry information should be fetched.
|
|
106
|
+
*
|
|
107
|
+
* Only supported when apiVersion is `API_VERSIONS.V3` and type is `MAP_TYPES.TABLE`.
|
|
108
|
+
*/
|
|
109
|
+
geoColumn?: string;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Names of columns to fetch.
|
|
113
|
+
*
|
|
114
|
+
* By default, all columns are fetched
|
|
115
|
+
*
|
|
116
|
+
* Only supported when apiVersion is `API_VERSIONS.V3` and type is `MAP_TYPES.TABLE`.
|
|
117
|
+
*/
|
|
118
|
+
columns?: string[];
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* A string pointing to a unique attribute at the result of the query.
|
|
122
|
+
*
|
|
123
|
+
* A unique attribute is needed for highlighting with vector tiles when a feature is split across two or more tiles.
|
|
124
|
+
*/
|
|
125
|
+
uniqueIdProperty?: string;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Optional. Overrides the configuration to connect with CARTO.
|
|
129
|
+
*
|
|
130
|
+
* @see Credentials
|
|
131
|
+
*/
|
|
132
|
+
credentials?: Credentials;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Called when the request to the CARTO Maps API failed.
|
|
136
|
+
*
|
|
137
|
+
* By default the Error is thrown.
|
|
138
|
+
*/
|
|
139
|
+
onDataError?: (err: unknown) => void;
|
|
140
|
+
|
|
141
|
+
clientId?: string;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export default class CartoLayer<DataT = any> extends CompositeLayer<CartoLayerProps<DataT>> {
|
|
145
|
+
static layerName = 'CartoLayer';
|
|
146
|
+
static defaultProps = defaultProps as any;
|
|
147
|
+
|
|
148
|
+
initializeState(): void {
|
|
51
149
|
this.state = {
|
|
52
150
|
data: null,
|
|
53
151
|
apiVersion: null
|
|
54
152
|
};
|
|
55
153
|
}
|
|
56
154
|
|
|
57
|
-
get isLoaded() {
|
|
155
|
+
get isLoaded(): boolean {
|
|
58
156
|
return this.getSubLayers().length > 0 && super.isLoaded;
|
|
59
157
|
}
|
|
60
158
|
|
|
61
|
-
_checkProps(props) {
|
|
159
|
+
_checkProps(props: CartoLayerProps): void {
|
|
62
160
|
const {type, credentials, connection, geoColumn, columns} = props;
|
|
63
161
|
const localCreds = {...getDefaultCredentials(), ...credentials};
|
|
64
162
|
const {apiVersion} = localCreds;
|
|
@@ -97,7 +195,16 @@ export default class CartoLayer extends CompositeLayer {
|
|
|
97
195
|
}
|
|
98
196
|
}
|
|
99
197
|
|
|
100
|
-
updateState({
|
|
198
|
+
updateState({
|
|
199
|
+
props,
|
|
200
|
+
oldProps,
|
|
201
|
+
changeFlags
|
|
202
|
+
}: {
|
|
203
|
+
props: CartoLayerProps;
|
|
204
|
+
oldProps: CartoLayerProps;
|
|
205
|
+
context: any;
|
|
206
|
+
changeFlags: ChangeFlags;
|
|
207
|
+
}): void {
|
|
101
208
|
this._checkProps(props);
|
|
102
209
|
const shouldUpdateData =
|
|
103
210
|
changeFlags.dataChanged ||
|
|
@@ -111,40 +218,57 @@ export default class CartoLayer extends CompositeLayer {
|
|
|
111
218
|
|
|
112
219
|
if (shouldUpdateData) {
|
|
113
220
|
this.setState({data: null, apiVersion: null});
|
|
221
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
114
222
|
this._updateData();
|
|
115
223
|
}
|
|
116
224
|
}
|
|
117
225
|
|
|
118
|
-
async _updateData() {
|
|
226
|
+
async _updateData(): Promise<void> {
|
|
119
227
|
try {
|
|
120
|
-
const {type, data: source, clientId, credentials, ...rest} = this.props;
|
|
228
|
+
const {type, data: source, clientId, credentials, connection, ...rest} = this.props;
|
|
121
229
|
const localConfig = {...getDefaultCredentials(), ...credentials};
|
|
122
230
|
const {apiVersion} = localConfig;
|
|
123
231
|
|
|
124
|
-
let result;
|
|
232
|
+
let result: FetchLayerDataResult;
|
|
125
233
|
if (apiVersion === API_VERSIONS.V1 || apiVersion === API_VERSIONS.V2) {
|
|
126
|
-
result = {
|
|
234
|
+
result = {
|
|
235
|
+
data: await getDataV2({type, source, credentials: credentials as ClassicCredentials})
|
|
236
|
+
};
|
|
127
237
|
} else {
|
|
128
|
-
result = await fetchLayerData({
|
|
238
|
+
result = await fetchLayerData({
|
|
239
|
+
type,
|
|
240
|
+
source,
|
|
241
|
+
clientId,
|
|
242
|
+
credentials: credentials as CloudNativeCredentials,
|
|
243
|
+
connection: connection as string,
|
|
244
|
+
...rest
|
|
245
|
+
});
|
|
129
246
|
}
|
|
130
247
|
|
|
131
248
|
this.setState({...result, apiVersion});
|
|
132
|
-
|
|
249
|
+
|
|
250
|
+
this.props.onDataLoad?.(result.data, {
|
|
251
|
+
propName: 'data',
|
|
252
|
+
layer: this
|
|
253
|
+
});
|
|
133
254
|
} catch (err) {
|
|
134
255
|
if (this.props.onDataError) {
|
|
135
|
-
this.props.onDataError(err);
|
|
256
|
+
this.props.onDataError(err as Error);
|
|
136
257
|
} else {
|
|
137
258
|
throw err;
|
|
138
259
|
}
|
|
139
260
|
}
|
|
140
261
|
}
|
|
141
262
|
|
|
142
|
-
_getSubLayerAndProps() {
|
|
263
|
+
_getSubLayerAndProps(): [any, LayerProps] {
|
|
264
|
+
assert(this.state);
|
|
265
|
+
|
|
143
266
|
const {data, format, apiVersion} = this.state;
|
|
144
267
|
|
|
145
268
|
const {uniqueIdProperty} = defaultProps;
|
|
146
|
-
|
|
147
|
-
|
|
269
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
270
|
+
const {data: _notUsed, ...propsNoData} = this.props;
|
|
271
|
+
const props = {uniqueIdProperty, ...propsNoData};
|
|
148
272
|
|
|
149
273
|
if (apiVersion === API_VERSIONS.V1 || apiVersion === API_VERSIONS.V2) {
|
|
150
274
|
return [MVTLayer, props];
|
|
@@ -155,7 +279,9 @@ export default class CartoLayer extends CompositeLayer {
|
|
|
155
279
|
const tileUrl = new URL(data.tiles[0]);
|
|
156
280
|
|
|
157
281
|
props.formatTiles =
|
|
158
|
-
props.formatTiles ||
|
|
282
|
+
props.formatTiles ||
|
|
283
|
+
(tileUrl.searchParams.get('formatTiles') as TileFormat) ||
|
|
284
|
+
TILE_FORMATS.MVT;
|
|
159
285
|
|
|
160
286
|
return props.formatTiles === TILE_FORMATS.MVT ? [MVTLayer, props] : [CartoTileLayer, props];
|
|
161
287
|
}
|
|
@@ -164,7 +290,9 @@ export default class CartoLayer extends CompositeLayer {
|
|
|
164
290
|
return [GeoJsonLayer, props];
|
|
165
291
|
}
|
|
166
292
|
|
|
167
|
-
renderLayers() {
|
|
293
|
+
renderLayers(): Layer | null {
|
|
294
|
+
assert(this.state);
|
|
295
|
+
|
|
168
296
|
const {data} = this.state;
|
|
169
297
|
|
|
170
298
|
if (!data) return null;
|
|
@@ -184,6 +312,3 @@ export default class CartoLayer extends CompositeLayer {
|
|
|
184
312
|
);
|
|
185
313
|
}
|
|
186
314
|
}
|
|
187
|
-
|
|
188
|
-
CartoLayer.layerName = 'CartoLayer';
|
|
189
|
-
CartoLayer.defaultProps = defaultProps;
|