@deck.gl/carto 8.7.0-alpha.9 → 8.7.0-beta.1
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 +218 -2825
- package/dist/es5/api/layer-map.js +16 -1
- package/dist/es5/api/layer-map.js.map +1 -1
- package/dist/es5/api/maps-v3-client.js +33 -26
- package/dist/es5/api/maps-v3-client.js.map +1 -1
- package/dist/es5/api/parseMap.js +24 -18
- package/dist/es5/api/parseMap.js.map +1 -1
- package/dist/es5/layers/carto-dynamic-tile-layer.js +1 -3
- package/dist/es5/layers/carto-dynamic-tile-layer.js.map +1 -1
- package/dist/es5/layers/carto-layer.js +5 -3
- package/dist/es5/layers/carto-layer.js.map +1 -1
- package/dist/esm/api/layer-map.js +8 -1
- package/dist/esm/api/layer-map.js.map +1 -1
- package/dist/esm/api/maps-v3-client.js +29 -17
- package/dist/esm/api/maps-v3-client.js.map +1 -1
- package/dist/esm/api/parseMap.js +31 -26
- package/dist/esm/api/parseMap.js.map +1 -1
- package/dist/esm/layers/carto-dynamic-tile-layer.js +2 -3
- package/dist/esm/layers/carto-dynamic-tile-layer.js.map +1 -1
- package/dist/esm/layers/carto-layer.js +3 -0
- package/dist/esm/layers/carto-layer.js.map +1 -1
- package/dist.min.js +14 -14
- package/package.json +7 -7
- package/src/api/layer-map.js +13 -1
- package/src/api/maps-v3-client.js +35 -18
- package/src/api/parseMap.js +23 -19
- package/src/layers/carto-dynamic-tile-layer.js +2 -3
- package/src/layers/carto-layer.js +5 -2
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.7.0-
|
|
5
|
+
"version": "8.7.0-beta.1",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
8
8
|
},
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"prepublishOnly": "npm run build-bundle && npm run build-bundle -- --env.dev"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@loaders.gl/gis": "^3.1.
|
|
35
|
-
"@loaders.gl/loader-utils": "^3.1.
|
|
36
|
-
"@loaders.gl/mvt": "^3.1.
|
|
37
|
-
"@loaders.gl/tiles": "^3.1.
|
|
34
|
+
"@loaders.gl/gis": "^3.1.5",
|
|
35
|
+
"@loaders.gl/loader-utils": "^3.1.5",
|
|
36
|
+
"@loaders.gl/mvt": "^3.1.5",
|
|
37
|
+
"@loaders.gl/tiles": "^3.1.5",
|
|
38
38
|
"@math.gl/web-mercator": "^3.5.6",
|
|
39
39
|
"cartocolor": "^4.0.2",
|
|
40
40
|
"d3-array": "^2.8.0",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@deck.gl/core": "^8.0.0",
|
|
48
48
|
"@deck.gl/geo-layers": "^8.0.0",
|
|
49
49
|
"@deck.gl/layers": "^8.0.0",
|
|
50
|
-
"@loaders.gl/core": "^3.1.
|
|
50
|
+
"@loaders.gl/core": "^3.1.5"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "0297ca9d2c85d980b075e2af4cfbeb75e31db55a"
|
|
53
53
|
}
|
package/src/api/layer-map.js
CHANGED
|
@@ -85,7 +85,12 @@ export const LAYER_MAP = {
|
|
|
85
85
|
mvt: {
|
|
86
86
|
Layer: MVTLayer,
|
|
87
87
|
propMap: sharedPropMap,
|
|
88
|
-
defaultProps: {
|
|
88
|
+
defaultProps: {
|
|
89
|
+
...defaultProps,
|
|
90
|
+
pointRadiusScale: 0.3,
|
|
91
|
+
lineWidthScale: 2,
|
|
92
|
+
uniqueIdProperty: 'geoid'
|
|
93
|
+
}
|
|
89
94
|
}
|
|
90
95
|
};
|
|
91
96
|
|
|
@@ -104,6 +109,11 @@ function domainFromAttribute(attribute, scaleType) {
|
|
|
104
109
|
function domainFromValues(values, scaleType) {
|
|
105
110
|
if (scaleType === 'ordinal') {
|
|
106
111
|
return [...new Set(values)].sort();
|
|
112
|
+
} else if (scaleType === 'quantile') {
|
|
113
|
+
return values.sort((a, b) => a - b);
|
|
114
|
+
} else if (scaleType === 'log') {
|
|
115
|
+
const [d0, d1] = extent(values);
|
|
116
|
+
return [d0 === 0 ? 1e-5 : d0, d1];
|
|
107
117
|
}
|
|
108
118
|
return extent(values);
|
|
109
119
|
}
|
|
@@ -193,3 +203,5 @@ export function getTextPixelOffsetAccessor({alignment, anchor, size}, radius) {
|
|
|
193
203
|
}
|
|
194
204
|
: calculateOffset(radius);
|
|
195
205
|
}
|
|
206
|
+
|
|
207
|
+
export {domainFromValues as _domainFromValues};
|
|
@@ -7,6 +7,7 @@ import {parseMap} from './parseMap';
|
|
|
7
7
|
import {log} from '@deck.gl/core';
|
|
8
8
|
|
|
9
9
|
const MAX_GET_LENGTH = 2048;
|
|
10
|
+
const DEFAULT_CLIENT = 'deck-gl-carto';
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Request against Maps API
|
|
@@ -69,8 +70,8 @@ function dealWithError({response, error}) {
|
|
|
69
70
|
/**
|
|
70
71
|
* Build a URL with all required parameters
|
|
71
72
|
*/
|
|
72
|
-
function getParameters({type, source, geoColumn, columns, schema}) {
|
|
73
|
-
const parameters = [encodeParameter('client',
|
|
73
|
+
function getParameters({type, source, geoColumn, columns, schema, clientId}) {
|
|
74
|
+
const parameters = [encodeParameter('client', clientId || DEFAULT_CLIENT)];
|
|
74
75
|
if (schema) {
|
|
75
76
|
parameters.push(encodeParameter('schema', true));
|
|
76
77
|
}
|
|
@@ -97,10 +98,11 @@ export async function mapInstantiation({
|
|
|
97
98
|
credentials,
|
|
98
99
|
geoColumn,
|
|
99
100
|
columns,
|
|
100
|
-
schema
|
|
101
|
+
schema,
|
|
102
|
+
clientId
|
|
101
103
|
}) {
|
|
102
104
|
const baseUrl = `${credentials.mapsUrl}/${connection}/${type}`;
|
|
103
|
-
const url = `${baseUrl}?${getParameters({type, source, geoColumn, columns, schema})}`;
|
|
105
|
+
const url = `${baseUrl}?${getParameters({type, source, geoColumn, columns, schema, clientId})}`;
|
|
104
106
|
const {accessToken} = credentials;
|
|
105
107
|
|
|
106
108
|
const format = 'json';
|
|
@@ -109,7 +111,7 @@ export async function mapInstantiation({
|
|
|
109
111
|
// need to be a POST request
|
|
110
112
|
const body = JSON.stringify({
|
|
111
113
|
q: source,
|
|
112
|
-
client:
|
|
114
|
+
client: clientId || DEFAULT_CLIENT
|
|
113
115
|
});
|
|
114
116
|
return await request({method: 'POST', url: baseUrl, format, accessToken, body});
|
|
115
117
|
}
|
|
@@ -145,7 +147,8 @@ export async function fetchLayerData({
|
|
|
145
147
|
geoColumn,
|
|
146
148
|
columns,
|
|
147
149
|
format,
|
|
148
|
-
schema
|
|
150
|
+
schema,
|
|
151
|
+
clientId
|
|
149
152
|
}) {
|
|
150
153
|
// Internally we split data fetching into two parts to allow us to
|
|
151
154
|
// conditionally fetch the actual data, depending on the metadata state
|
|
@@ -157,7 +160,8 @@ export async function fetchLayerData({
|
|
|
157
160
|
geoColumn,
|
|
158
161
|
columns,
|
|
159
162
|
format,
|
|
160
|
-
schema
|
|
163
|
+
schema,
|
|
164
|
+
clientId
|
|
161
165
|
});
|
|
162
166
|
|
|
163
167
|
const data = await request({url, format: mapFormat, accessToken});
|
|
@@ -177,7 +181,8 @@ async function _fetchDataUrl({
|
|
|
177
181
|
geoColumn,
|
|
178
182
|
columns,
|
|
179
183
|
format,
|
|
180
|
-
schema
|
|
184
|
+
schema,
|
|
185
|
+
clientId
|
|
181
186
|
}) {
|
|
182
187
|
const defaultCredentials = getDefaultCredentials();
|
|
183
188
|
// Only pick up default credentials if they have been defined for
|
|
@@ -199,7 +204,8 @@ async function _fetchDataUrl({
|
|
|
199
204
|
credentials: localCreds,
|
|
200
205
|
geoColumn,
|
|
201
206
|
columns,
|
|
202
|
-
schema
|
|
207
|
+
schema,
|
|
208
|
+
clientId
|
|
203
209
|
});
|
|
204
210
|
let url;
|
|
205
211
|
let mapFormat;
|
|
@@ -224,7 +230,16 @@ async function _fetchDataUrl({
|
|
|
224
230
|
return {url, accessToken, mapFormat, metadata};
|
|
225
231
|
}
|
|
226
232
|
|
|
227
|
-
export async function getData({
|
|
233
|
+
export async function getData({
|
|
234
|
+
type,
|
|
235
|
+
source,
|
|
236
|
+
connection,
|
|
237
|
+
credentials,
|
|
238
|
+
geoColumn,
|
|
239
|
+
columns,
|
|
240
|
+
format,
|
|
241
|
+
clientId
|
|
242
|
+
}) {
|
|
228
243
|
log.deprecated('getData', 'fetchLayerData')();
|
|
229
244
|
const layerData = await fetchLayerData({
|
|
230
245
|
type,
|
|
@@ -234,20 +249,22 @@ export async function getData({type, source, connection, credentials, geoColumn,
|
|
|
234
249
|
geoColumn,
|
|
235
250
|
columns,
|
|
236
251
|
format,
|
|
237
|
-
schema: false
|
|
252
|
+
schema: false,
|
|
253
|
+
clientId
|
|
238
254
|
});
|
|
239
255
|
return layerData.data;
|
|
240
256
|
}
|
|
241
257
|
|
|
242
258
|
/* global clearInterval, setInterval, URLSearchParams */
|
|
243
|
-
async function _fetchMapDataset(dataset, accessToken, credentials) {
|
|
259
|
+
async function _fetchMapDataset(dataset, accessToken, credentials, clientId) {
|
|
244
260
|
// First fetch metadata
|
|
245
261
|
const {connectionName: connection, source, type} = dataset;
|
|
246
262
|
const {url, mapFormat} = await _fetchDataUrl({
|
|
247
263
|
credentials: {...credentials, accessToken},
|
|
248
264
|
connection,
|
|
249
265
|
source,
|
|
250
|
-
type
|
|
266
|
+
type,
|
|
267
|
+
clientId
|
|
251
268
|
});
|
|
252
269
|
|
|
253
270
|
// Extract the last time the data changed
|
|
@@ -263,12 +280,12 @@ async function _fetchMapDataset(dataset, accessToken, credentials) {
|
|
|
263
280
|
return true;
|
|
264
281
|
}
|
|
265
282
|
|
|
266
|
-
async function fillInMapDatasets({datasets, token}, credentials) {
|
|
267
|
-
const promises = datasets.map(dataset => _fetchMapDataset(dataset, token, credentials));
|
|
283
|
+
async function fillInMapDatasets({datasets, token}, clientId, credentials) {
|
|
284
|
+
const promises = datasets.map(dataset => _fetchMapDataset(dataset, token, credentials, clientId));
|
|
268
285
|
return await Promise.all(promises);
|
|
269
286
|
}
|
|
270
287
|
|
|
271
|
-
export async function fetchMap({cartoMapId, credentials, autoRefresh, onNewData}) {
|
|
288
|
+
export async function fetchMap({cartoMapId, clientId, credentials, autoRefresh, onNewData}) {
|
|
272
289
|
const defaultCredentials = getDefaultCredentials();
|
|
273
290
|
const localCreds = {
|
|
274
291
|
...(defaultCredentials.apiVersion === API_VERSIONS.V3 && defaultCredentials),
|
|
@@ -297,7 +314,7 @@ export async function fetchMap({cartoMapId, credentials, autoRefresh, onNewData}
|
|
|
297
314
|
let stopAutoRefresh;
|
|
298
315
|
if (autoRefresh) {
|
|
299
316
|
const intervalId = setInterval(async () => {
|
|
300
|
-
const changed = await fillInMapDatasets(map, credentials);
|
|
317
|
+
const changed = await fillInMapDatasets(map, clientId, credentials);
|
|
301
318
|
if (changed.some(v => v === true)) {
|
|
302
319
|
onNewData(parseMap(map));
|
|
303
320
|
}
|
|
@@ -308,7 +325,7 @@ export async function fetchMap({cartoMapId, credentials, autoRefresh, onNewData}
|
|
|
308
325
|
}
|
|
309
326
|
|
|
310
327
|
// Mutates map.datasets so that dataset.data contains data
|
|
311
|
-
await fillInMapDatasets(map, credentials);
|
|
328
|
+
await fillInMapDatasets(map, clientId, credentials);
|
|
312
329
|
return {
|
|
313
330
|
...parseMap(map),
|
|
314
331
|
...{stopAutoRefresh}
|
package/src/api/parseMap.js
CHANGED
|
@@ -23,23 +23,28 @@ export function parseMap(json) {
|
|
|
23
23
|
initialViewState: mapState,
|
|
24
24
|
mapStyle,
|
|
25
25
|
layers: extractTextLayers(layers.reverse()).map(({id, type, config, visualChannels}) => {
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
try {
|
|
27
|
+
log.assert(type in LAYER_MAP, `Unsupported layer type: ${type}`);
|
|
28
|
+
const {Layer, propMap, defaultProps} = LAYER_MAP[type];
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
30
|
+
const {dataId} = config;
|
|
31
|
+
const dataset = datasets.find(d => d.id === dataId);
|
|
32
|
+
log.assert(dataset, `No dataset matching dataId: ${dataId}`);
|
|
33
|
+
const {data} = dataset;
|
|
34
|
+
log.assert(data, `No data loaded for dataId: ${dataId}`);
|
|
35
|
+
return new Layer({
|
|
36
|
+
id,
|
|
37
|
+
data,
|
|
38
|
+
...defaultProps,
|
|
39
|
+
...createBlendingProps(layerBlending),
|
|
40
|
+
...(!config.textLabel && createInteractionProps(interactionConfig)),
|
|
41
|
+
...createStyleProps(config, propMap),
|
|
42
|
+
...createChannelProps(visualChannels, type, config, data) // Must come after style
|
|
43
|
+
});
|
|
44
|
+
} catch (e) {
|
|
45
|
+
log.error(e.message)();
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
43
48
|
})
|
|
44
49
|
};
|
|
45
50
|
}
|
|
@@ -146,12 +151,11 @@ function createChannelProps(visualChannels, type, config, data) {
|
|
|
146
151
|
);
|
|
147
152
|
}
|
|
148
153
|
if (strokeColorField) {
|
|
149
|
-
const opacity =
|
|
150
|
-
visConfig.strokeOpacity !== undefined ? visConfig.strokeOpacity / visConfig.opacity : 1;
|
|
154
|
+
const opacity = visConfig.strokeOpacity !== undefined ? visConfig.strokeOpacity : 1;
|
|
151
155
|
result.getLineColor = getColorAccessor(
|
|
152
156
|
strokeColorField,
|
|
153
157
|
strokeColorScale,
|
|
154
|
-
visConfig.
|
|
158
|
+
visConfig.strokeColorRange,
|
|
155
159
|
opacity,
|
|
156
160
|
data
|
|
157
161
|
);
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
/* global TextDecoder */
|
|
2
2
|
import {log} from '@deck.gl/core';
|
|
3
3
|
import {ClipExtension} from '@deck.gl/extensions';
|
|
4
|
-
import {MVTLayer} from '@deck.gl/geo-layers';
|
|
4
|
+
import {MVTLayer, _getURLFromTemplate} from '@deck.gl/geo-layers';
|
|
5
5
|
import {GeoJsonLayer} from '@deck.gl/layers';
|
|
6
6
|
import {geojsonToBinary} from '@loaders.gl/gis';
|
|
7
7
|
import {encodeParameter} from '../api/maps-api-common';
|
|
8
|
-
import {getURLFromTemplate} from '@deck.gl/geo-layers/tile-layer/utils';
|
|
9
8
|
|
|
10
9
|
function parseJSON(arrayBuffer) {
|
|
11
10
|
return JSON.parse(new TextDecoder().decode(arrayBuffer));
|
|
@@ -37,7 +36,7 @@ const CartoDynamicTileLoader = {
|
|
|
37
36
|
|
|
38
37
|
export default class CartoDynamicTileLayer extends MVTLayer {
|
|
39
38
|
getTileData(tile) {
|
|
40
|
-
let url =
|
|
39
|
+
let url = _getURLFromTemplate(this.state.data, tile);
|
|
41
40
|
if (!url) {
|
|
42
41
|
return Promise.reject('Invalid URL');
|
|
43
42
|
}
|
|
@@ -27,6 +27,9 @@ const defaultProps = {
|
|
|
27
27
|
// (String, optional): format of data
|
|
28
28
|
format: null,
|
|
29
29
|
|
|
30
|
+
// (String, optional): clientId identifier used for internal tracing, place here a string to identify the client who is doing the request.
|
|
31
|
+
clientId: null,
|
|
32
|
+
|
|
30
33
|
// (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.
|
|
31
34
|
geoColumn: null,
|
|
32
35
|
|
|
@@ -98,7 +101,7 @@ export default class CartoLayer extends CompositeLayer {
|
|
|
98
101
|
|
|
99
102
|
async _updateData() {
|
|
100
103
|
try {
|
|
101
|
-
const {type, data: source, credentials, ...rest} = this.props;
|
|
104
|
+
const {type, data: source, clientId, credentials, ...rest} = this.props;
|
|
102
105
|
const localConfig = {...getDefaultCredentials(), ...credentials};
|
|
103
106
|
const {apiVersion} = localConfig;
|
|
104
107
|
|
|
@@ -106,7 +109,7 @@ export default class CartoLayer extends CompositeLayer {
|
|
|
106
109
|
if (apiVersion === API_VERSIONS.V1 || apiVersion === API_VERSIONS.V2) {
|
|
107
110
|
result = {data: await getDataV2({type, source, credentials})};
|
|
108
111
|
} else {
|
|
109
|
-
result = await fetchLayerData({type, source, credentials, ...rest});
|
|
112
|
+
result = await fetchLayerData({type, source, clientId, credentials, ...rest});
|
|
110
113
|
}
|
|
111
114
|
|
|
112
115
|
this.setState({...result, apiVersion});
|