@deck.gl/carto 8.8.19 → 8.8.20
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 +42413 -42270
- package/dist/es5/api/carto-api-error.js +87 -0
- package/dist/es5/api/carto-api-error.js.map +1 -0
- package/dist/es5/api/index.js +8 -0
- package/dist/es5/api/index.js.map +1 -1
- package/dist/es5/api/maps-api-common.js +9 -1
- package/dist/es5/api/maps-api-common.js.map +1 -1
- package/dist/es5/api/maps-v3-client.js +135 -109
- package/dist/es5/api/maps-v3-client.js.map +1 -1
- package/dist/es5/index.js +6 -0
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/layers/carto-layer.js.map +1 -1
- package/dist/es5/layers/quadbin-tile-layer.js +8 -2
- package/dist/es5/layers/quadbin-tile-layer.js.map +1 -1
- package/dist/esm/api/carto-api-error.js +51 -0
- package/dist/esm/api/carto-api-error.js.map +1 -0
- package/dist/esm/api/index.js +1 -0
- package/dist/esm/api/index.js.map +1 -1
- package/dist/esm/api/maps-api-common.js +6 -0
- package/dist/esm/api/maps-api-common.js.map +1 -1
- package/dist/esm/api/maps-v3-client.js +59 -35
- package/dist/esm/api/maps-v3-client.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/layers/carto-layer.js.map +1 -1
- package/dist/esm/layers/quadbin-tile-layer.js +4 -4
- package/dist/esm/layers/quadbin-tile-layer.js.map +1 -1
- package/dist.min.js +4 -4
- package/package.json +2 -2
- package/src/api/carto-api-error.ts +67 -0
- package/src/api/index.ts +2 -0
- package/src/api/maps-api-common.ts +8 -0
- package/src/api/maps-v3-client.ts +37 -29
- package/src/index.ts +2 -1
- package/src/layers/carto-layer.ts +4 -3
- package/src/layers/quadbin-tile-layer.ts +4 -2
- package/typed/api/index.d.ts +2 -0
- package/typed/api/index.d.ts.map +1 -1
- package/typed/api/maps-api-common.d.ts +7 -0
- package/typed/api/maps-api-common.d.ts.map +1 -1
- package/typed/api/maps-v3-client.d.ts.map +1 -1
- package/typed/index.d.ts +2 -2
- package/typed/index.d.ts.map +1 -1
- package/typed/layers/carto-layer.d.ts +3 -2
- package/typed/layers/carto-layer.d.ts.map +1 -1
- package/typed/layers/quadbin-tile-layer.d.ts +4 -1
- package/typed/layers/quadbin-tile-layer.d.ts.map +1 -1
- package/typed/layers/schema/carto-spa-tile.d.ts +57 -0
- package/typed/layers/schema/carto-spa-tile.d.ts.map +1 -0
- package/typed/api/index.js +0 -3
- package/typed/api/layer-map.js +0 -264
- package/typed/api/maps-api-common.js +0 -50
- package/typed/api/maps-client.js +0 -125
- package/typed/api/maps-v3-client.js +0 -304
- package/typed/api/parseMap.js +0 -178
- package/typed/basemap.js +0 -9
- package/typed/config.js +0 -35
- package/typed/index.js +0 -10
- package/typed/layers/carto-layer.js +0 -173
- package/typed/layers/carto-tile-layer.js +0 -105
- package/typed/layers/h3-tile-layer.js +0 -47
- package/typed/layers/h3-tileset-2d.js +0 -85
- package/typed/layers/quadkey-tile-layer.js +0 -42
- package/typed/layers/quadkey-tileset-2d.js +0 -36
- package/typed/layers/schema/carto-tile.js +0 -161
- package/typed/layers/spatial-index-tile-layer.js +0 -40
- package/typed/style/color-bins-style.js +0 -12
- package/typed/style/color-categories-style.js +0 -16
- package/typed/style/color-continuous-style.js +0 -12
- package/typed/style/palette.js +0 -62
- package/typed/style/utils.js +0 -15
- package/typed/utils.js +0 -4
|
@@ -1,304 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Maps API Client for Carto 3
|
|
3
|
-
*/
|
|
4
|
-
import { getDefaultCredentials, buildMapsUrlFromBase } from '../config';
|
|
5
|
-
import { API_VERSIONS, COLUMNS_SUPPORT, encodeParameter, FORMATS, GEO_COLUMN_SUPPORT, MAP_TYPES, TILE_FORMATS } from './maps-api-common';
|
|
6
|
-
import { parseMap } from './parseMap';
|
|
7
|
-
import { log } from '@deck.gl/core';
|
|
8
|
-
import { assert } from '../utils';
|
|
9
|
-
const MAX_GET_LENGTH = 2048;
|
|
10
|
-
const DEFAULT_CLIENT = 'deck-gl-carto';
|
|
11
|
-
/**
|
|
12
|
-
* Request against Maps API
|
|
13
|
-
*/
|
|
14
|
-
async function request({ method, url, accessToken, body }) {
|
|
15
|
-
const headers = {
|
|
16
|
-
Accept: 'application/json'
|
|
17
|
-
};
|
|
18
|
-
if (accessToken) {
|
|
19
|
-
headers.Authorization = `Bearer ${accessToken}`;
|
|
20
|
-
}
|
|
21
|
-
if (method === 'POST') {
|
|
22
|
-
headers['Content-Type'] = 'application/json';
|
|
23
|
-
}
|
|
24
|
-
try {
|
|
25
|
-
/* global fetch */
|
|
26
|
-
return await fetch(url, {
|
|
27
|
-
method,
|
|
28
|
-
headers,
|
|
29
|
-
body
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
catch (error) {
|
|
33
|
-
throw new Error(`Failed to connect to Maps API: ${error}`);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
async function requestJson({ method, url, accessToken, body }) {
|
|
37
|
-
const response = await request({ method, url, accessToken, body });
|
|
38
|
-
const json = await response.json();
|
|
39
|
-
if (!response.ok) {
|
|
40
|
-
dealWithError({ response, error: json.error });
|
|
41
|
-
}
|
|
42
|
-
return json;
|
|
43
|
-
}
|
|
44
|
-
async function requestData({ method, url, accessToken, format, body }) {
|
|
45
|
-
if (format === FORMATS.NDJSON) {
|
|
46
|
-
return request({ method, url, accessToken, body });
|
|
47
|
-
}
|
|
48
|
-
const data = await requestJson({ method, url, accessToken, body });
|
|
49
|
-
return data.rows ? data.rows : data;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Display proper message from Maps API error
|
|
53
|
-
*/
|
|
54
|
-
function dealWithError({ response, error }) {
|
|
55
|
-
switch (response.status) {
|
|
56
|
-
case 400:
|
|
57
|
-
throw new Error(`Bad request. ${error}`);
|
|
58
|
-
case 401:
|
|
59
|
-
case 403:
|
|
60
|
-
throw new Error(`Unauthorized access. ${error}`);
|
|
61
|
-
default:
|
|
62
|
-
throw new Error(error);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Build a URL with all required parameters
|
|
67
|
-
*/
|
|
68
|
-
function getParameters({ type, source, geoColumn, columns, clientId, aggregationExp, aggregationResLevel }) {
|
|
69
|
-
const parameters = [encodeParameter('client', clientId || DEFAULT_CLIENT)];
|
|
70
|
-
const sourceName = type === MAP_TYPES.QUERY ? 'q' : 'name';
|
|
71
|
-
parameters.push(encodeParameter(sourceName, source));
|
|
72
|
-
if (geoColumn) {
|
|
73
|
-
parameters.push(encodeParameter('geo_column', geoColumn));
|
|
74
|
-
}
|
|
75
|
-
if (columns) {
|
|
76
|
-
parameters.push(encodeParameter('columns', columns.join(',')));
|
|
77
|
-
}
|
|
78
|
-
if (aggregationExp) {
|
|
79
|
-
parameters.push(encodeParameter('aggregationExp', aggregationExp));
|
|
80
|
-
}
|
|
81
|
-
if (aggregationResLevel) {
|
|
82
|
-
parameters.push(encodeParameter('aggregationResLevel', aggregationResLevel));
|
|
83
|
-
}
|
|
84
|
-
return parameters.join('&');
|
|
85
|
-
}
|
|
86
|
-
export async function mapInstantiation({ type, source, connection, credentials, geoColumn, columns, clientId, aggregationExp, aggregationResLevel }) {
|
|
87
|
-
const baseUrl = `${credentials.mapsUrl}/${connection}/${type}`;
|
|
88
|
-
const url = `${baseUrl}?${getParameters({
|
|
89
|
-
type,
|
|
90
|
-
source,
|
|
91
|
-
geoColumn,
|
|
92
|
-
columns,
|
|
93
|
-
clientId,
|
|
94
|
-
aggregationExp,
|
|
95
|
-
aggregationResLevel
|
|
96
|
-
})}`;
|
|
97
|
-
const { accessToken } = credentials;
|
|
98
|
-
if (url.length > MAX_GET_LENGTH && type === MAP_TYPES.QUERY) {
|
|
99
|
-
// need to be a POST request
|
|
100
|
-
const body = JSON.stringify({
|
|
101
|
-
q: source,
|
|
102
|
-
client: clientId || DEFAULT_CLIENT
|
|
103
|
-
});
|
|
104
|
-
return await requestJson({ method: 'POST', url: baseUrl, accessToken, body });
|
|
105
|
-
}
|
|
106
|
-
return await requestJson({ url, accessToken });
|
|
107
|
-
}
|
|
108
|
-
function getUrlFromMetadata(metadata, format) {
|
|
109
|
-
const m = metadata[format];
|
|
110
|
-
if (m && !m.error && m.url) {
|
|
111
|
-
return m.url[0];
|
|
112
|
-
}
|
|
113
|
-
return null;
|
|
114
|
-
}
|
|
115
|
-
function checkFetchLayerDataParameters({ type, source, connection, credentials, geoColumn, columns, aggregationExp, aggregationResLevel }) {
|
|
116
|
-
assert(connection, 'Must define connection');
|
|
117
|
-
assert(type, 'Must define a type');
|
|
118
|
-
assert(source, 'Must define a source');
|
|
119
|
-
assert(credentials.apiVersion === API_VERSIONS.V3, 'Method only available for v3');
|
|
120
|
-
assert(credentials.apiBaseUrl, 'Must define apiBaseUrl');
|
|
121
|
-
assert(credentials.accessToken, 'Must define an accessToken');
|
|
122
|
-
if (columns) {
|
|
123
|
-
assert(COLUMNS_SUPPORT.includes(type), `The columns parameter is not supported by type ${type}`);
|
|
124
|
-
}
|
|
125
|
-
if (geoColumn) {
|
|
126
|
-
assert(GEO_COLUMN_SUPPORT.includes(type), `The geoColumn parameter is not supported by type ${type}`);
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
assert(!aggregationExp, 'Have aggregationExp, but geoColumn parameter is missing');
|
|
130
|
-
assert(!aggregationResLevel, 'Have aggregationResLevel, but geoColumn parameter is missing');
|
|
131
|
-
}
|
|
132
|
-
if (!aggregationExp) {
|
|
133
|
-
assert(!aggregationResLevel, 'Have aggregationResLevel, but aggregationExp parameter is missing');
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
export async function fetchLayerData({ type, source, connection, credentials, geoColumn, columns, format, formatTiles, clientId, aggregationExp, aggregationResLevel }) {
|
|
137
|
-
// Internally we split data fetching into two parts to allow us to
|
|
138
|
-
// conditionally fetch the actual data, depending on the metadata state
|
|
139
|
-
const { url, accessToken, mapFormat, metadata } = await _fetchDataUrl({
|
|
140
|
-
type,
|
|
141
|
-
source,
|
|
142
|
-
connection,
|
|
143
|
-
credentials,
|
|
144
|
-
geoColumn,
|
|
145
|
-
columns,
|
|
146
|
-
format,
|
|
147
|
-
formatTiles,
|
|
148
|
-
clientId,
|
|
149
|
-
aggregationExp,
|
|
150
|
-
aggregationResLevel
|
|
151
|
-
});
|
|
152
|
-
const data = await requestData({ url, format: mapFormat, accessToken });
|
|
153
|
-
const result = { data, format: mapFormat, schema: metadata.schema };
|
|
154
|
-
return result;
|
|
155
|
-
}
|
|
156
|
-
async function _fetchDataUrl({ type, source, connection, credentials, geoColumn, columns, format, formatTiles, clientId, aggregationExp, aggregationResLevel }) {
|
|
157
|
-
const defaultCredentials = getDefaultCredentials();
|
|
158
|
-
// Only pick up default credentials if they have been defined for
|
|
159
|
-
// correct API version
|
|
160
|
-
const localCreds = {
|
|
161
|
-
...(defaultCredentials.apiVersion === API_VERSIONS.V3 && defaultCredentials),
|
|
162
|
-
...credentials
|
|
163
|
-
};
|
|
164
|
-
checkFetchLayerDataParameters({
|
|
165
|
-
type,
|
|
166
|
-
source,
|
|
167
|
-
connection,
|
|
168
|
-
credentials: localCreds,
|
|
169
|
-
geoColumn,
|
|
170
|
-
columns,
|
|
171
|
-
aggregationExp,
|
|
172
|
-
aggregationResLevel
|
|
173
|
-
});
|
|
174
|
-
if (!localCreds.mapsUrl) {
|
|
175
|
-
localCreds.mapsUrl = buildMapsUrlFromBase(localCreds.apiBaseUrl);
|
|
176
|
-
}
|
|
177
|
-
const metadata = await mapInstantiation({
|
|
178
|
-
type,
|
|
179
|
-
source,
|
|
180
|
-
connection,
|
|
181
|
-
credentials: localCreds,
|
|
182
|
-
geoColumn,
|
|
183
|
-
columns,
|
|
184
|
-
clientId,
|
|
185
|
-
aggregationExp,
|
|
186
|
-
aggregationResLevel
|
|
187
|
-
});
|
|
188
|
-
let url = null;
|
|
189
|
-
let mapFormat;
|
|
190
|
-
if (format) {
|
|
191
|
-
mapFormat = format;
|
|
192
|
-
url = getUrlFromMetadata(metadata, format);
|
|
193
|
-
assert(url, `Format ${format} not available`);
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
// guess map format
|
|
197
|
-
const prioritizedFormats = [FORMATS.GEOJSON, FORMATS.JSON, FORMATS.NDJSON, FORMATS.TILEJSON];
|
|
198
|
-
for (const f of prioritizedFormats) {
|
|
199
|
-
url = getUrlFromMetadata(metadata, f);
|
|
200
|
-
if (url) {
|
|
201
|
-
mapFormat = f;
|
|
202
|
-
break;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
assert(url && mapFormat, 'Unsupported data formats received from backend.');
|
|
206
|
-
}
|
|
207
|
-
if (format === FORMATS.TILEJSON && formatTiles) {
|
|
208
|
-
log.assert(Object.values(TILE_FORMATS).includes(formatTiles), `Invalid value for formatTiles: ${formatTiles}. Use value from TILE_FORMATS`);
|
|
209
|
-
url += `&${encodeParameter('formatTiles', formatTiles)}`;
|
|
210
|
-
}
|
|
211
|
-
const { accessToken } = localCreds;
|
|
212
|
-
return { url, accessToken, mapFormat, metadata };
|
|
213
|
-
}
|
|
214
|
-
export async function getData({ type, source, connection, credentials, geoColumn, columns, format, clientId }) {
|
|
215
|
-
log.deprecated('getData', 'fetchLayerData')();
|
|
216
|
-
const layerData = await fetchLayerData({
|
|
217
|
-
type,
|
|
218
|
-
source,
|
|
219
|
-
connection,
|
|
220
|
-
credentials,
|
|
221
|
-
geoColumn,
|
|
222
|
-
columns,
|
|
223
|
-
format,
|
|
224
|
-
clientId
|
|
225
|
-
});
|
|
226
|
-
return layerData.data;
|
|
227
|
-
}
|
|
228
|
-
/* global clearInterval, setInterval, URL */
|
|
229
|
-
async function _fetchMapDataset(dataset, accessToken, credentials, clientId) {
|
|
230
|
-
const { connectionName: connection, columns, format, geoColumn, source, type } = dataset;
|
|
231
|
-
// First fetch metadata
|
|
232
|
-
const { url, mapFormat } = await _fetchDataUrl({
|
|
233
|
-
clientId,
|
|
234
|
-
credentials: { ...credentials, accessToken },
|
|
235
|
-
connection,
|
|
236
|
-
columns,
|
|
237
|
-
format,
|
|
238
|
-
geoColumn,
|
|
239
|
-
source,
|
|
240
|
-
type
|
|
241
|
-
});
|
|
242
|
-
// Extract the last time the data changed
|
|
243
|
-
const cache = parseInt(new URL(url).searchParams.get('cache') || '', 10);
|
|
244
|
-
if (cache && dataset.cache === cache) {
|
|
245
|
-
return false;
|
|
246
|
-
}
|
|
247
|
-
dataset.cache = cache;
|
|
248
|
-
// Only fetch if the data has changed
|
|
249
|
-
dataset.data = await requestData({ url, format: mapFormat, accessToken });
|
|
250
|
-
return true;
|
|
251
|
-
}
|
|
252
|
-
async function fillInMapDatasets({ datasets, token }, clientId, credentials) {
|
|
253
|
-
const promises = datasets.map(dataset => _fetchMapDataset(dataset, token, credentials, clientId));
|
|
254
|
-
return await Promise.all(promises);
|
|
255
|
-
}
|
|
256
|
-
export async function fetchMap({ cartoMapId, clientId, credentials, autoRefresh, onNewData }) {
|
|
257
|
-
const defaultCredentials = getDefaultCredentials();
|
|
258
|
-
const localCreds = {
|
|
259
|
-
...(defaultCredentials.apiVersion === API_VERSIONS.V3 && defaultCredentials),
|
|
260
|
-
...credentials
|
|
261
|
-
};
|
|
262
|
-
const { accessToken } = localCreds;
|
|
263
|
-
assert(cartoMapId, 'Must define CARTO map id: fetchMap({cartoMapId: "XXXX-XXXX-XXXX"})');
|
|
264
|
-
assert(localCreds.apiVersion === API_VERSIONS.V3, 'Method only available for v3');
|
|
265
|
-
assert(localCreds.apiBaseUrl, 'Must define apiBaseUrl');
|
|
266
|
-
if (!localCreds.mapsUrl) {
|
|
267
|
-
localCreds.mapsUrl = buildMapsUrlFromBase(localCreds.apiBaseUrl);
|
|
268
|
-
}
|
|
269
|
-
if (autoRefresh || onNewData) {
|
|
270
|
-
assert(onNewData, 'Must define `onNewData` when using autoRefresh');
|
|
271
|
-
assert(typeof onNewData === 'function', '`onNewData` must be a function');
|
|
272
|
-
assert(typeof autoRefresh === 'number' && autoRefresh > 0, '`autoRefresh` must be a positive number');
|
|
273
|
-
}
|
|
274
|
-
const url = `${localCreds.mapsUrl}/public/${cartoMapId}`;
|
|
275
|
-
const map = await requestJson({ url, accessToken });
|
|
276
|
-
// Periodically check if the data has changed. Note that this
|
|
277
|
-
// will not update when a map is published.
|
|
278
|
-
let stopAutoRefresh;
|
|
279
|
-
if (autoRefresh) {
|
|
280
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
281
|
-
const intervalId = setInterval(async () => {
|
|
282
|
-
const changed = await fillInMapDatasets(map, clientId, localCreds);
|
|
283
|
-
if (onNewData && changed.some(v => v === true)) {
|
|
284
|
-
onNewData(parseMap(map));
|
|
285
|
-
}
|
|
286
|
-
}, autoRefresh * 1000);
|
|
287
|
-
stopAutoRefresh = () => {
|
|
288
|
-
clearInterval(intervalId);
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
const geojsonLayers = map.keplerMapConfig.config.visState.layers.filter(({ type }) => type === 'geojson' || type === 'point');
|
|
292
|
-
const geojsonDatasetIds = geojsonLayers.map(({ config }) => config.dataId);
|
|
293
|
-
map.datasets.forEach(dataset => {
|
|
294
|
-
if (geojsonDatasetIds.includes(dataset.id)) {
|
|
295
|
-
dataset.format = 'geojson';
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
// Mutates map.datasets so that dataset.data contains data
|
|
299
|
-
await fillInMapDatasets(map, clientId, localCreds);
|
|
300
|
-
return {
|
|
301
|
-
...parseMap(map),
|
|
302
|
-
...{ stopAutoRefresh }
|
|
303
|
-
};
|
|
304
|
-
}
|
package/typed/api/parseMap.js
DELETED
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import GL from '@luma.gl/constants';
|
|
2
|
-
import { AGGREGATION, getLayer, getColorAccessor, getColorValueAccessor, getSizeAccessor, getTextAccessor, getTextPixelOffsetAccessor, OPACITY_MAP, opacityToAlpha } from './layer-map';
|
|
3
|
-
import { _flatten as flatten, log } from '@deck.gl/core';
|
|
4
|
-
import { assert } from '../utils';
|
|
5
|
-
export function parseMap(json) {
|
|
6
|
-
const { keplerMapConfig, datasets } = json;
|
|
7
|
-
assert(keplerMapConfig.version === 'v1', 'Only support Kepler v1');
|
|
8
|
-
const { mapState, mapStyle } = keplerMapConfig.config;
|
|
9
|
-
const { layers, layerBlending, interactionConfig } = keplerMapConfig.config.visState;
|
|
10
|
-
return {
|
|
11
|
-
id: json.id,
|
|
12
|
-
title: json.title,
|
|
13
|
-
description: json.description,
|
|
14
|
-
createdAt: json.createdAt,
|
|
15
|
-
updatedAt: json.updatedAt,
|
|
16
|
-
initialViewState: mapState,
|
|
17
|
-
mapStyle,
|
|
18
|
-
layers: extractTextLayers(layers.reverse()).map(({ id, type, config, visualChannels }) => {
|
|
19
|
-
try {
|
|
20
|
-
const { dataId } = config;
|
|
21
|
-
const dataset = datasets.find(d => d.id === dataId);
|
|
22
|
-
assert(dataset, `No dataset matching dataId: ${dataId}`);
|
|
23
|
-
const { data } = dataset;
|
|
24
|
-
assert(data, `No data loaded for dataId: ${dataId}`);
|
|
25
|
-
const { Layer, propMap, defaultProps } = getLayer(type, config, dataset);
|
|
26
|
-
return new Layer({
|
|
27
|
-
id,
|
|
28
|
-
data,
|
|
29
|
-
...defaultProps,
|
|
30
|
-
...createBlendingProps(layerBlending),
|
|
31
|
-
...(!config.textLabel && createInteractionProps(interactionConfig)),
|
|
32
|
-
...createStyleProps(config, propMap),
|
|
33
|
-
...createChannelProps(visualChannels, type, config, data) // Must come after style
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
catch (e) {
|
|
37
|
-
log.error(e.message)();
|
|
38
|
-
return undefined;
|
|
39
|
-
}
|
|
40
|
-
})
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
function extractTextLayers(layers) {
|
|
44
|
-
return flatten(layers.map(({ id, config, ...rest }) => {
|
|
45
|
-
const { textLabel, ...configRest } = config;
|
|
46
|
-
return [
|
|
47
|
-
// Original layer without textLabel
|
|
48
|
-
{ id, config: configRest, ...rest },
|
|
49
|
-
// One layer per valid text label, with full opacity
|
|
50
|
-
...textLabel
|
|
51
|
-
.filter(t => t.field)
|
|
52
|
-
.map(t => {
|
|
53
|
-
return {
|
|
54
|
-
id: `${id}-label-${t.field.name}`,
|
|
55
|
-
config: {
|
|
56
|
-
textLabel: t,
|
|
57
|
-
...configRest,
|
|
58
|
-
label: `${config.label}-label-${t.field.name}`,
|
|
59
|
-
visConfig: { ...configRest.visConfig, opacity: 1 }
|
|
60
|
-
},
|
|
61
|
-
...rest
|
|
62
|
-
};
|
|
63
|
-
})
|
|
64
|
-
];
|
|
65
|
-
}));
|
|
66
|
-
}
|
|
67
|
-
function createBlendingProps(layerBlending) {
|
|
68
|
-
if (layerBlending === 'additive') {
|
|
69
|
-
return {
|
|
70
|
-
parameters: {
|
|
71
|
-
blendFunc: [GL.SRC_ALPHA, GL.DST_ALPHA],
|
|
72
|
-
blendEquation: GL.FUNC_ADD
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
else if (layerBlending === 'subtractive') {
|
|
77
|
-
return {
|
|
78
|
-
parameters: {
|
|
79
|
-
blendFunc: [GL.ONE, GL.ONE_MINUS_DST_COLOR, GL.SRC_ALPHA, GL.DST_ALPHA],
|
|
80
|
-
blendEquation: [GL.FUNC_SUBTRACT, GL.FUNC_ADD]
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
return {};
|
|
85
|
-
}
|
|
86
|
-
function createInteractionProps(interactionConfig) {
|
|
87
|
-
const pickable = interactionConfig && interactionConfig.tooltip.enabled;
|
|
88
|
-
return {
|
|
89
|
-
autoHighlight: pickable,
|
|
90
|
-
pickable
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
function mapProps(source, target, mapping) {
|
|
94
|
-
for (const sourceKey in mapping) {
|
|
95
|
-
const sourceValue = source[sourceKey];
|
|
96
|
-
const targetKey = mapping[sourceKey];
|
|
97
|
-
if (sourceValue === undefined) {
|
|
98
|
-
// eslint-disable-next-line no-continue
|
|
99
|
-
continue;
|
|
100
|
-
}
|
|
101
|
-
if (typeof targetKey === 'string') {
|
|
102
|
-
target[targetKey] = sourceValue;
|
|
103
|
-
}
|
|
104
|
-
else if (typeof targetKey === 'function') {
|
|
105
|
-
const [key, value] = Object.entries(targetKey(sourceValue))[0];
|
|
106
|
-
target[key] = value;
|
|
107
|
-
}
|
|
108
|
-
else if (typeof targetKey === 'object') {
|
|
109
|
-
// Nested definition, recurse down one level (also handles arrays)
|
|
110
|
-
mapProps(sourceValue, target, targetKey);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
function createStyleProps(config, mapping) {
|
|
115
|
-
const result = {};
|
|
116
|
-
mapProps(config, result, mapping);
|
|
117
|
-
// Kepler format sometimes omits strokeColor. TODO: remove once we can rely on
|
|
118
|
-
// `strokeColor` always being set when `stroke: true`.
|
|
119
|
-
if (result.stroked && !result.getLineColor) {
|
|
120
|
-
result.getLineColor = result.getFillColor;
|
|
121
|
-
}
|
|
122
|
-
for (const colorAccessor in OPACITY_MAP) {
|
|
123
|
-
if (Array.isArray(result[colorAccessor])) {
|
|
124
|
-
const color = [...result[colorAccessor]];
|
|
125
|
-
const opacityKey = OPACITY_MAP[colorAccessor];
|
|
126
|
-
const opacity = config.visConfig[opacityKey];
|
|
127
|
-
color[3] = opacityToAlpha(opacity);
|
|
128
|
-
result[colorAccessor] = color;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
result.highlightColor = config.visConfig.enable3d ? [255, 255, 255, 60] : [252, 242, 26, 255];
|
|
132
|
-
return result;
|
|
133
|
-
}
|
|
134
|
-
/* eslint-disable complexity, max-statements */
|
|
135
|
-
function createChannelProps(visualChannels, type, config, data) {
|
|
136
|
-
const { colorField, colorScale, sizeField, sizeScale, strokeColorField, strokeColorScale } = visualChannels;
|
|
137
|
-
let { heightField, heightScale } = visualChannels;
|
|
138
|
-
if (type === 'hexagonId') {
|
|
139
|
-
heightField = sizeField;
|
|
140
|
-
heightScale = sizeScale;
|
|
141
|
-
}
|
|
142
|
-
const { textLabel, visConfig } = config;
|
|
143
|
-
const result = {};
|
|
144
|
-
const textLabelField = textLabel && textLabel.field;
|
|
145
|
-
if (type === 'grid' || type === 'hexagon') {
|
|
146
|
-
result.colorScaleType = colorScale;
|
|
147
|
-
if (colorField) {
|
|
148
|
-
const { colorAggregation } = config.visConfig;
|
|
149
|
-
if (!AGGREGATION[colorAggregation]) {
|
|
150
|
-
result.getColorValue = getColorValueAccessor(colorField, colorAggregation, data);
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
result.getColorWeight = d => d[colorField.name];
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
else if (colorField) {
|
|
158
|
-
result.getFillColor = getColorAccessor(colorField, colorScale, visConfig.colorRange, visConfig.opacity, data);
|
|
159
|
-
}
|
|
160
|
-
if (strokeColorField) {
|
|
161
|
-
const fallbackOpacity = type === 'point' ? visConfig.opacity : 1;
|
|
162
|
-
const opacity = visConfig.strokeOpacity !== undefined ? visConfig.strokeOpacity : fallbackOpacity;
|
|
163
|
-
result.getLineColor = getColorAccessor(strokeColorField, strokeColorScale, visConfig.strokeColorRange, opacity, data);
|
|
164
|
-
}
|
|
165
|
-
if (heightField) {
|
|
166
|
-
result.getElevation = getSizeAccessor(heightField, heightScale, visConfig.heightRange || visConfig.sizeRange, data);
|
|
167
|
-
}
|
|
168
|
-
if (sizeField) {
|
|
169
|
-
result.getPointRadius = getSizeAccessor(sizeField, sizeScale, visConfig.radiusRange || visConfig.sizeRange, data);
|
|
170
|
-
}
|
|
171
|
-
if (textLabelField) {
|
|
172
|
-
result.getText = getTextAccessor(textLabelField, data);
|
|
173
|
-
result.pointType = 'text';
|
|
174
|
-
const radius = result.getPointRadius || visConfig.radius;
|
|
175
|
-
result.getTextPixelOffset = getTextPixelOffsetAccessor(textLabel, radius);
|
|
176
|
-
}
|
|
177
|
-
return result;
|
|
178
|
-
}
|
package/typed/basemap.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
const baseUrl = 'https://basemaps.cartocdn.com/gl/{basemap}-gl-style/style.json';
|
|
2
|
-
export default {
|
|
3
|
-
VOYAGER: baseUrl.replace('{basemap}', 'voyager'),
|
|
4
|
-
POSITRON: baseUrl.replace('{basemap}', 'positron'),
|
|
5
|
-
DARK_MATTER: baseUrl.replace('{basemap}', 'dark-matter'),
|
|
6
|
-
VOYAGER_NOLABELS: baseUrl.replace('{basemap}', 'voyager-nolabels'),
|
|
7
|
-
POSITRON_NOLABELS: baseUrl.replace('{basemap}', 'positron-nolabels'),
|
|
8
|
-
DARK_MATTER_NOLABELS: baseUrl.replace('{basemap}', 'dark-matter-nolabels')
|
|
9
|
-
};
|
package/typed/config.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { API_VERSIONS } from './api/maps-api-common';
|
|
2
|
-
export const defaultClassicCredentials = {
|
|
3
|
-
apiKey: 'default_public',
|
|
4
|
-
region: 'us',
|
|
5
|
-
username: 'public'
|
|
6
|
-
};
|
|
7
|
-
export const defaultCloudNativeCredentials = {
|
|
8
|
-
apiBaseUrl: 'https://gcp-us-east1.api.carto.com'
|
|
9
|
-
};
|
|
10
|
-
let credentials = {};
|
|
11
|
-
setDefaultCredentials({});
|
|
12
|
-
export function setDefaultCredentials({ apiVersion, ...rest }) {
|
|
13
|
-
apiVersion = apiVersion || API_VERSIONS.V3;
|
|
14
|
-
switch (apiVersion) {
|
|
15
|
-
case API_VERSIONS.V1:
|
|
16
|
-
case API_VERSIONS.V2:
|
|
17
|
-
credentials = { apiVersion, ...defaultClassicCredentials, ...rest };
|
|
18
|
-
break;
|
|
19
|
-
case API_VERSIONS.V3:
|
|
20
|
-
credentials = { apiVersion, ...defaultCloudNativeCredentials, ...rest };
|
|
21
|
-
break;
|
|
22
|
-
default:
|
|
23
|
-
throw new Error(`Invalid API version ${apiVersion}. Use API_VERSIONS enum.`);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
export function getDefaultCredentials() {
|
|
27
|
-
return credentials;
|
|
28
|
-
}
|
|
29
|
-
export function buildMapsUrlFromBase(apiBaseUrl) {
|
|
30
|
-
let suffix = '/v3/maps';
|
|
31
|
-
if (apiBaseUrl.endsWith('/')) {
|
|
32
|
-
suffix = suffix.substring(1);
|
|
33
|
-
}
|
|
34
|
-
return `${apiBaseUrl}${suffix}`;
|
|
35
|
-
}
|
package/typed/index.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export { getDefaultCredentials, setDefaultCredentials } from './config';
|
|
2
|
-
export { default as CartoLayer } from './layers/carto-layer';
|
|
3
|
-
export { default as _CartoTileLayer } from './layers/carto-tile-layer';
|
|
4
|
-
export { default as _H3TileLayer } from './layers/h3-tile-layer';
|
|
5
|
-
export { default as _QuadkeyTileLayer } from './layers/quadkey-tile-layer';
|
|
6
|
-
export { default as BASEMAP } from './basemap';
|
|
7
|
-
export { default as colorBins } from './style/color-bins-style';
|
|
8
|
-
export { default as colorCategories } from './style/color-categories-style';
|
|
9
|
-
export { default as colorContinuous } from './style/color-continuous-style';
|
|
10
|
-
export { FORMATS, TILE_FORMATS, MAP_TYPES, API_VERSIONS, fetchLayerData, fetchMap, getDataV2 as _getDataV2, getData, mapInstantiation as _mapInstantiation } from './api';
|