@deck.gl/carto 8.7.0-alpha.8 → 8.7.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.dev.js +42141 -23010
- package/dist/es5/api/layer-map.js +67 -42
- package/dist/es5/api/layer-map.js.map +1 -1
- package/dist/es5/api/maps-api-common.js +7 -1
- package/dist/es5/api/maps-api-common.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 +23 -18
- package/dist/es5/api/parseMap.js.map +1 -1
- package/dist/es5/index.js +8 -0
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/layers/carto-dynamic-tile-layer.js +166 -0
- package/dist/es5/layers/carto-dynamic-tile-layer.js.map +1 -0
- package/dist/es5/layers/carto-layer.js +11 -4
- package/dist/es5/layers/carto-layer.js.map +1 -1
- package/dist/esm/api/layer-map.js +50 -35
- package/dist/esm/api/layer-map.js.map +1 -1
- package/dist/esm/api/maps-api-common.js +5 -0
- package/dist/esm/api/maps-api-common.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 -27
- package/dist/esm/api/parseMap.js.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/layers/carto-dynamic-tile-layer.js +97 -0
- package/dist/esm/layers/carto-dynamic-tile-layer.js.map +1 -0
- package/dist/esm/layers/carto-layer.js +9 -2
- package/dist/esm/layers/carto-layer.js.map +1 -1
- package/dist.min.js +4 -4
- package/package.json +8 -7
- package/src/api/layer-map.js +47 -26
- package/src/api/maps-api-common.js +6 -0
- package/src/api/maps-v3-client.js +35 -18
- package/src/api/parseMap.js +23 -21
- package/src/index.js +1 -0
- package/src/layers/carto-dynamic-tile-layer.js +86 -0
- package/src/layers/carto-layer.js +16 -4
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.3",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
8
8
|
},
|
|
@@ -31,10 +31,11 @@
|
|
|
31
31
|
"prepublishOnly": "npm run build-bundle && npm run build-bundle -- --env.dev"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@loaders.gl/
|
|
35
|
-
"@loaders.gl/
|
|
36
|
-
"@loaders.gl/
|
|
37
|
-
"@
|
|
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
|
+
"@math.gl/web-mercator": "^3.5.7",
|
|
38
39
|
"cartocolor": "^4.0.2",
|
|
39
40
|
"d3-array": "^2.8.0",
|
|
40
41
|
"d3-color": "^2.0.0",
|
|
@@ -46,7 +47,7 @@
|
|
|
46
47
|
"@deck.gl/core": "^8.0.0",
|
|
47
48
|
"@deck.gl/geo-layers": "^8.0.0",
|
|
48
49
|
"@deck.gl/layers": "^8.0.0",
|
|
49
|
-
"@loaders.gl/core": "^3.1.
|
|
50
|
+
"@loaders.gl/core": "^3.1.5"
|
|
50
51
|
},
|
|
51
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "32879c662f37d4c912cf702c220a75d6cd0a67bc"
|
|
52
53
|
}
|
package/src/api/layer-map.js
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
} from 'd3-scale';
|
|
12
12
|
import {format as d3Format} from 'd3-format';
|
|
13
13
|
import moment from 'moment-timezone';
|
|
14
|
+
import {log} from '@deck.gl/core';
|
|
14
15
|
import {H3HexagonLayer, MVTLayer} from '@deck.gl/geo-layers';
|
|
15
16
|
import {GeoJsonLayer} from '@deck.gl/layers';
|
|
16
17
|
|
|
@@ -62,32 +63,45 @@ function mergePropMaps(a, b) {
|
|
|
62
63
|
return {...a, ...b, visConfig: {...a.visConfig, ...b.visConfig}};
|
|
63
64
|
}
|
|
64
65
|
|
|
65
|
-
export
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
66
|
+
export function getLayer(type, config) {
|
|
67
|
+
const hexagonId = config.columns?.hex_id;
|
|
68
|
+
|
|
69
|
+
const layer = {
|
|
70
|
+
point: {
|
|
71
|
+
Layer: GeoJsonLayer,
|
|
72
|
+
propMap: mergePropMaps(sharedPropMap, {
|
|
73
|
+
visConfig: {outline: 'stroked'}
|
|
74
|
+
}),
|
|
75
|
+
defaultProps
|
|
76
|
+
},
|
|
77
|
+
geojson: {
|
|
78
|
+
Layer: GeoJsonLayer,
|
|
79
|
+
propMap: sharedPropMap,
|
|
80
|
+
defaultProps: {...defaultProps, lineWidthScale: 2}
|
|
81
|
+
},
|
|
82
|
+
hexagonId: {
|
|
83
|
+
Layer: H3HexagonLayer,
|
|
84
|
+
propMap: mergePropMaps(sharedPropMap, {
|
|
85
|
+
visConfig: {coverage: 'coverage', elevationScale: 'elevationScale'}
|
|
86
|
+
}),
|
|
87
|
+
defaultProps: {...defaultProps, getHexagon: d => d[hexagonId]}
|
|
88
|
+
},
|
|
89
|
+
mvt: {
|
|
90
|
+
Layer: MVTLayer,
|
|
91
|
+
propMap: sharedPropMap,
|
|
92
|
+
defaultProps: {
|
|
93
|
+
...defaultProps,
|
|
94
|
+
pointRadiusScale: 0.3,
|
|
95
|
+
lineWidthScale: 2,
|
|
96
|
+
uniqueIdProperty: 'geoid'
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}[type];
|
|
100
|
+
|
|
101
|
+
log.assert(layer, `Unsupported layer type: ${type}`);
|
|
102
|
+
|
|
103
|
+
return layer;
|
|
104
|
+
}
|
|
91
105
|
|
|
92
106
|
function domainFromAttribute(attribute, scaleType) {
|
|
93
107
|
if (scaleType === 'ordinal' || scaleType === 'point') {
|
|
@@ -104,6 +118,11 @@ function domainFromAttribute(attribute, scaleType) {
|
|
|
104
118
|
function domainFromValues(values, scaleType) {
|
|
105
119
|
if (scaleType === 'ordinal') {
|
|
106
120
|
return [...new Set(values)].sort();
|
|
121
|
+
} else if (scaleType === 'quantile') {
|
|
122
|
+
return values.sort((a, b) => a - b);
|
|
123
|
+
} else if (scaleType === 'log') {
|
|
124
|
+
const [d0, d1] = extent(values);
|
|
125
|
+
return [d0 === 0 ? 1e-5 : d0, d1];
|
|
107
126
|
}
|
|
108
127
|
return extent(values);
|
|
109
128
|
}
|
|
@@ -193,3 +212,5 @@ export function getTextPixelOffsetAccessor({alignment, anchor, size}, radius) {
|
|
|
193
212
|
}
|
|
194
213
|
: calculateOffset(radius);
|
|
195
214
|
}
|
|
215
|
+
|
|
216
|
+
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import GL from '@luma.gl/constants';
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
getLayer,
|
|
4
4
|
getColorAccessor,
|
|
5
5
|
getSizeAccessor,
|
|
6
6
|
getTextAccessor,
|
|
@@ -23,23 +23,26 @@ export function parseMap(json) {
|
|
|
23
23
|
initialViewState: mapState,
|
|
24
24
|
mapStyle,
|
|
25
25
|
layers: extractTextLayers(layers.reverse()).map(({id, type, config, visualChannels}) => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
})
|
|
26
|
+
try {
|
|
27
|
+
const {Layer, propMap, defaultProps} = getLayer(type, config);
|
|
28
|
+
const {dataId} = config;
|
|
29
|
+
const dataset = datasets.find(d => d.id === dataId);
|
|
30
|
+
log.assert(dataset, `No dataset matching dataId: ${dataId}`);
|
|
31
|
+
const {data} = dataset;
|
|
32
|
+
log.assert(data, `No data loaded for dataId: ${dataId}`);
|
|
33
|
+
return new Layer({
|
|
34
|
+
id,
|
|
35
|
+
data,
|
|
36
|
+
...defaultProps,
|
|
37
|
+
...createBlendingProps(layerBlending),
|
|
38
|
+
...(!config.textLabel && createInteractionProps(interactionConfig)),
|
|
39
|
+
...createStyleProps(config, propMap),
|
|
40
|
+
...createChannelProps(visualChannels, type, config, data) // Must come after style
|
|
41
|
+
});
|
|
42
|
+
} catch (e) {
|
|
43
|
+
log.error(e.message)();
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
43
46
|
})
|
|
44
47
|
};
|
|
45
48
|
}
|
|
@@ -146,12 +149,11 @@ function createChannelProps(visualChannels, type, config, data) {
|
|
|
146
149
|
);
|
|
147
150
|
}
|
|
148
151
|
if (strokeColorField) {
|
|
149
|
-
const opacity =
|
|
150
|
-
visConfig.strokeOpacity !== undefined ? visConfig.strokeOpacity / visConfig.opacity : 1;
|
|
152
|
+
const opacity = visConfig.strokeOpacity !== undefined ? visConfig.strokeOpacity : 1;
|
|
151
153
|
result.getLineColor = getColorAccessor(
|
|
152
154
|
strokeColorField,
|
|
153
155
|
strokeColorScale,
|
|
154
|
-
visConfig.
|
|
156
|
+
visConfig.strokeColorRange,
|
|
155
157
|
opacity,
|
|
156
158
|
data
|
|
157
159
|
);
|
package/src/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export {getDefaultCredentials, setDefaultCredentials} from './config.js';
|
|
2
2
|
export {default as CartoLayer} from './layers/carto-layer';
|
|
3
|
+
export {default as _CartoDynamicTileLayer} from './layers/carto-dynamic-tile-layer';
|
|
3
4
|
export {default as BASEMAP} from './basemap';
|
|
4
5
|
export {default as colorBins} from './style/color-bins-style';
|
|
5
6
|
export {default as colorCategories} from './style/color-categories-style';
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/* global TextDecoder */
|
|
2
|
+
import {log} from '@deck.gl/core';
|
|
3
|
+
import {ClipExtension} from '@deck.gl/extensions';
|
|
4
|
+
import {MVTLayer, _getURLFromTemplate} from '@deck.gl/geo-layers';
|
|
5
|
+
import {GeoJsonLayer} from '@deck.gl/layers';
|
|
6
|
+
import {geojsonToBinary} from '@loaders.gl/gis';
|
|
7
|
+
import {encodeParameter} from '../api/maps-api-common';
|
|
8
|
+
|
|
9
|
+
function parseJSON(arrayBuffer) {
|
|
10
|
+
return JSON.parse(new TextDecoder().decode(arrayBuffer));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function parseCartoDynamicTile(arrayBuffer, options) {
|
|
14
|
+
if (!arrayBuffer) return null;
|
|
15
|
+
const formatTiles = options && options.cartoDynamicTile && options.cartoDynamicTile.formatTiles;
|
|
16
|
+
if (formatTiles === 'geojson') return geojsonToBinary(parseJSON(arrayBuffer).features);
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const CartoDynamicTileLoader = {
|
|
21
|
+
name: 'CARTO Dynamic Tile',
|
|
22
|
+
id: 'cartoDynamicTile',
|
|
23
|
+
module: 'carto',
|
|
24
|
+
extensions: ['pbf'],
|
|
25
|
+
mimeTypes: ['application/x-protobuf'],
|
|
26
|
+
category: 'geometry',
|
|
27
|
+
worker: false,
|
|
28
|
+
parse: async (arrayBuffer, options) => parseCartoDynamicTile(arrayBuffer, options),
|
|
29
|
+
parseSync: parseCartoDynamicTile,
|
|
30
|
+
options: {
|
|
31
|
+
cartoDynamicTile: {
|
|
32
|
+
formatTiles: 'geojson'
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export default class CartoDynamicTileLayer extends MVTLayer {
|
|
38
|
+
getTileData(tile) {
|
|
39
|
+
let url = _getURLFromTemplate(this.state.data, tile);
|
|
40
|
+
if (!url) {
|
|
41
|
+
return Promise.reject('Invalid URL');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
let loadOptions = this.getLoadOptions();
|
|
45
|
+
const {fetch, formatTiles} = this.props;
|
|
46
|
+
const {signal} = tile;
|
|
47
|
+
|
|
48
|
+
loadOptions = {
|
|
49
|
+
...loadOptions,
|
|
50
|
+
mimeType: 'application/x-protobuf'
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
if (formatTiles) {
|
|
54
|
+
log.assert(
|
|
55
|
+
['geojson'].includes(formatTiles),
|
|
56
|
+
`Invalid value for formatTiles: ${formatTiles}`
|
|
57
|
+
);
|
|
58
|
+
url += `&${encodeParameter('formatTiles', formatTiles)}`;
|
|
59
|
+
loadOptions.cartoBinaryTile = {formatTiles};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return fetch(url, {propName: 'data', layer: this, loadOptions, signal});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
renderSubLayers(props) {
|
|
66
|
+
if (props.data === null) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
props.autoHighlight = false;
|
|
71
|
+
|
|
72
|
+
const {
|
|
73
|
+
bbox: {west, south, east, north}
|
|
74
|
+
} = props.tile;
|
|
75
|
+
props.extensions = [new ClipExtension()];
|
|
76
|
+
props.clipBounds = [west, south, east, north];
|
|
77
|
+
|
|
78
|
+
const subLayer = new GeoJsonLayer({
|
|
79
|
+
...props
|
|
80
|
+
});
|
|
81
|
+
return subLayer;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
CartoDynamicTileLayer.layerName = 'CartoDynamicTileLayer';
|
|
86
|
+
CartoDynamicTileLayer.defaultProps = {...MVTLayer.defaultProps, loaders: [CartoDynamicTileLoader]};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import {CompositeLayer, log} from '@deck.gl/core';
|
|
2
|
+
import CartoDynamicTileLayer from './carto-dynamic-tile-layer';
|
|
2
3
|
import {MVTLayer} from '@deck.gl/geo-layers';
|
|
3
4
|
import {GeoJsonLayer} from '@deck.gl/layers';
|
|
4
5
|
import {fetchLayerData, getDataV2, API_VERSIONS} from '../api';
|
|
5
|
-
import {FORMATS, MAP_TYPES} from '../api/maps-api-common';
|
|
6
|
+
import {FORMATS, MAP_TYPES, TILE_FORMATS} from '../api/maps-api-common';
|
|
6
7
|
import {getDefaultCredentials} from '../config';
|
|
7
8
|
|
|
8
9
|
const defaultProps = {
|
|
@@ -26,6 +27,9 @@ const defaultProps = {
|
|
|
26
27
|
// (String, optional): format of data
|
|
27
28
|
format: null,
|
|
28
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
|
+
|
|
29
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.
|
|
30
34
|
geoColumn: null,
|
|
31
35
|
|
|
@@ -97,7 +101,7 @@ export default class CartoLayer extends CompositeLayer {
|
|
|
97
101
|
|
|
98
102
|
async _updateData() {
|
|
99
103
|
try {
|
|
100
|
-
const {type, data: source, credentials, ...rest} = this.props;
|
|
104
|
+
const {type, data: source, clientId, credentials, ...rest} = this.props;
|
|
101
105
|
const localConfig = {...getDefaultCredentials(), ...credentials};
|
|
102
106
|
const {apiVersion} = localConfig;
|
|
103
107
|
|
|
@@ -105,7 +109,7 @@ export default class CartoLayer extends CompositeLayer {
|
|
|
105
109
|
if (apiVersion === API_VERSIONS.V1 || apiVersion === API_VERSIONS.V2) {
|
|
106
110
|
result = {data: await getDataV2({type, source, credentials})};
|
|
107
111
|
} else {
|
|
108
|
-
result = await fetchLayerData({type, source, credentials, ...rest});
|
|
112
|
+
result = await fetchLayerData({type, source, clientId, credentials, ...rest});
|
|
109
113
|
}
|
|
110
114
|
|
|
111
115
|
this.setState({...result, apiVersion});
|
|
@@ -128,7 +132,15 @@ export default class CartoLayer extends CompositeLayer {
|
|
|
128
132
|
|
|
129
133
|
let layer;
|
|
130
134
|
|
|
131
|
-
|
|
135
|
+
/* global URLSearchParams */
|
|
136
|
+
const tilesFormat =
|
|
137
|
+
apiVersion === API_VERSIONS.V3 &&
|
|
138
|
+
format === FORMATS.TILEJSON &&
|
|
139
|
+
new URLSearchParams(data.tiles[0]).get('format');
|
|
140
|
+
|
|
141
|
+
if (tilesFormat && tilesFormat !== TILE_FORMATS.MVT) {
|
|
142
|
+
layer = CartoDynamicTileLayer;
|
|
143
|
+
} else if (
|
|
132
144
|
apiVersion === API_VERSIONS.V1 ||
|
|
133
145
|
apiVersion === API_VERSIONS.V2 ||
|
|
134
146
|
format === FORMATS.TILEJSON
|