@deck.gl/carto 8.9.0-alpha.4 → 8.9.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.
Files changed (111) hide show
  1. package/dist/dist.dev.js +13597 -58102
  2. package/dist/es5/api/carto-api-error.js +87 -0
  3. package/dist/es5/api/carto-api-error.js.map +1 -0
  4. package/dist/es5/api/index.js +8 -0
  5. package/dist/es5/api/index.js.map +1 -1
  6. package/dist/es5/api/layer-map.js +13 -1
  7. package/dist/es5/api/layer-map.js.map +1 -1
  8. package/dist/es5/api/maps-api-common.js +9 -1
  9. package/dist/es5/api/maps-api-common.js.map +1 -1
  10. package/dist/es5/api/maps-v3-client.js +145 -113
  11. package/dist/es5/api/maps-v3-client.js.map +1 -1
  12. package/dist/es5/api/parseMap.js +32 -15
  13. package/dist/es5/api/parseMap.js.map +1 -1
  14. package/dist/es5/index.js +6 -0
  15. package/dist/es5/index.js.map +1 -1
  16. package/dist/es5/layers/carto-layer.js.map +1 -1
  17. package/dist/es5/layers/carto-tile-layer.js.map +1 -1
  18. package/dist/es5/layers/quadbin-layer.js +3 -1
  19. package/dist/es5/layers/quadbin-layer.js.map +1 -1
  20. package/dist/es5/layers/quadbin-tile-layer.js +8 -2
  21. package/dist/es5/layers/quadbin-tile-layer.js.map +1 -1
  22. package/dist/es5/layers/quadbin-utils.js +5 -3
  23. package/dist/es5/layers/quadbin-utils.js.map +1 -1
  24. package/dist/es5/layers/spatial-index-tile-layer.js +21 -0
  25. package/dist/es5/layers/spatial-index-tile-layer.js.map +1 -1
  26. package/dist/esm/api/carto-api-error.js +51 -0
  27. package/dist/esm/api/carto-api-error.js.map +1 -0
  28. package/dist/esm/api/index.js +1 -0
  29. package/dist/esm/api/index.js.map +1 -1
  30. package/dist/esm/api/layer-map.js +11 -1
  31. package/dist/esm/api/layer-map.js.map +1 -1
  32. package/dist/esm/api/maps-api-common.js +6 -0
  33. package/dist/esm/api/maps-api-common.js.map +1 -1
  34. package/dist/esm/api/maps-v3-client.js +70 -41
  35. package/dist/esm/api/maps-v3-client.js.map +1 -1
  36. package/dist/esm/api/parseMap.js +36 -16
  37. package/dist/esm/api/parseMap.js.map +1 -1
  38. package/dist/esm/index.js +1 -1
  39. package/dist/esm/index.js.map +1 -1
  40. package/dist/esm/layers/carto-layer.js.map +1 -1
  41. package/dist/esm/layers/carto-tile-layer.js.map +1 -1
  42. package/dist/esm/layers/quadbin-layer.js +3 -1
  43. package/dist/esm/layers/quadbin-layer.js.map +1 -1
  44. package/dist/esm/layers/quadbin-tile-layer.js +4 -4
  45. package/dist/esm/layers/quadbin-tile-layer.js.map +1 -1
  46. package/dist/esm/layers/quadbin-utils.js +4 -4
  47. package/dist/esm/layers/quadbin-utils.js.map +1 -1
  48. package/dist/esm/layers/spatial-index-tile-layer.js +20 -0
  49. package/dist/esm/layers/spatial-index-tile-layer.js.map +1 -1
  50. package/dist.min.js +24 -278
  51. package/package.json +13 -13
  52. package/src/api/carto-api-error.ts +67 -0
  53. package/src/api/index.ts +2 -0
  54. package/src/api/layer-map.ts +15 -3
  55. package/src/api/maps-api-common.ts +8 -0
  56. package/src/api/maps-v3-client.ts +44 -38
  57. package/src/api/parseMap.ts +24 -16
  58. package/src/index.ts +2 -1
  59. package/src/layers/carto-layer.ts +4 -3
  60. package/src/layers/carto-tile-layer.ts +1 -1
  61. package/src/layers/quadbin-layer.ts +4 -2
  62. package/src/layers/quadbin-tile-layer.ts +4 -2
  63. package/src/layers/quadbin-utils.ts +4 -4
  64. package/src/layers/spatial-index-tile-layer.ts +28 -1
  65. package/typed/api/carto-api-error.d.ts +24 -0
  66. package/typed/api/carto-api-error.d.ts.map +1 -0
  67. package/typed/api/index.d.ts +2 -0
  68. package/typed/api/index.d.ts.map +1 -1
  69. package/typed/api/index.js +3 -0
  70. package/typed/api/layer-map.d.ts.map +1 -1
  71. package/typed/api/layer-map.js +264 -0
  72. package/typed/api/maps-api-common.d.ts +7 -0
  73. package/typed/api/maps-api-common.d.ts.map +1 -1
  74. package/typed/api/maps-api-common.js +50 -0
  75. package/typed/api/maps-client.js +125 -0
  76. package/typed/api/maps-v3-client.d.ts.map +1 -1
  77. package/typed/api/maps-v3-client.js +304 -0
  78. package/typed/api/parseMap.d.ts.map +1 -1
  79. package/typed/api/parseMap.js +178 -0
  80. package/typed/basemap.js +9 -0
  81. package/typed/config.js +35 -0
  82. package/typed/index.d.ts +2 -2
  83. package/typed/index.d.ts.map +1 -1
  84. package/typed/index.js +10 -0
  85. package/typed/layers/carto-layer.d.ts +3 -2
  86. package/typed/layers/carto-layer.d.ts.map +1 -1
  87. package/typed/layers/carto-layer.js +173 -0
  88. package/typed/layers/carto-tile-layer.js +105 -0
  89. package/typed/layers/h3-tile-layer.js +47 -0
  90. package/typed/layers/h3-tileset-2d.js +85 -0
  91. package/typed/layers/quadbin-layer.d.ts.map +1 -1
  92. package/typed/layers/quadbin-tile-layer.d.ts +4 -1
  93. package/typed/layers/quadbin-tile-layer.d.ts.map +1 -1
  94. package/typed/layers/quadbin-utils.d.ts +2 -2
  95. package/typed/layers/quadbin-utils.d.ts.map +1 -1
  96. package/typed/layers/quadkey-tile-layer.d.ts +21 -0
  97. package/typed/layers/quadkey-tile-layer.d.ts.map +1 -0
  98. package/typed/layers/quadkey-tile-layer.js +42 -0
  99. package/typed/layers/quadkey-tileset-2d.d.ts +15 -0
  100. package/typed/layers/quadkey-tileset-2d.d.ts.map +1 -0
  101. package/typed/layers/quadkey-tileset-2d.js +36 -0
  102. package/typed/layers/schema/carto-tile.js +161 -0
  103. package/typed/layers/spatial-index-tile-layer.d.ts +11 -1
  104. package/typed/layers/spatial-index-tile-layer.d.ts.map +1 -1
  105. package/typed/layers/spatial-index-tile-layer.js +40 -0
  106. package/typed/style/color-bins-style.js +12 -0
  107. package/typed/style/color-categories-style.js +16 -0
  108. package/typed/style/color-continuous-style.js +12 -0
  109. package/typed/style/palette.js +62 -0
  110. package/typed/style/utils.js +15 -0
  111. package/typed/utils.js +4 -0
@@ -0,0 +1,304 @@
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
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"parseMap.d.ts","sourceRoot":"","sources":["../../src/api/parseMap.ts"],"names":[],"mappings":"AAmBA,wBAAgB,QAAQ,CAAC,IAAI,KAAA;;;;;;;;;;EAuC5B"}
1
+ {"version":3,"file":"parseMap.d.ts","sourceRoot":"","sources":["../../src/api/parseMap.ts"],"names":[],"mappings":"AAmBA,wBAAgB,QAAQ,CAAC,IAAI,KAAA;;;;;;;;;;EAwC5B"}
@@ -0,0 +1,178 @@
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
+ }
@@ -0,0 +1,9 @@
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
+ };
@@ -0,0 +1,35 @@
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.d.ts CHANGED
@@ -7,7 +7,7 @@ export { default as BASEMAP } from './basemap';
7
7
  export { default as colorBins } from './style/color-bins-style';
8
8
  export { default as colorCategories } from './style/color-categories-style';
9
9
  export { default as colorContinuous } from './style/color-continuous-style';
10
- export { FORMATS, TILE_FORMATS, MAP_TYPES, API_VERSIONS, fetchLayerData, fetchMap, getDataV2 as _getDataV2, mapInstantiation as _mapInstantiation } from './api';
11
- export type { QueryParameters } from './api';
10
+ export { FORMATS, TILE_FORMATS, MAP_TYPES, API_VERSIONS, CartoAPIError, fetchLayerData, fetchMap, getDataV2 as _getDataV2, mapInstantiation as _mapInstantiation } from './api';
11
+ export type { APIErrorContext, QueryParameters } from './api';
12
12
  export type { CartoLayerProps } from './layers/carto-layer';
13
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,qBAAqB,EAAE,qBAAqB,EAAC,MAAM,UAAU,CAAC;AACtE,OAAO,EAAC,OAAO,IAAI,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAC,OAAO,IAAI,eAAe,EAAC,MAAM,2BAA2B,CAAC;AACrE,OAAO,EAAC,OAAO,IAAI,YAAY,EAAC,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAC,OAAO,IAAI,iBAAiB,EAAC,MAAM,6BAA6B,CAAC;AACzE,OAAO,EAAC,OAAO,IAAI,OAAO,EAAC,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAC,OAAO,IAAI,SAAS,EAAC,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAC,OAAO,IAAI,eAAe,EAAC,MAAM,gCAAgC,CAAC;AAC1E,OAAO,EAAC,OAAO,IAAI,eAAe,EAAC,MAAM,gCAAgC,CAAC;AAC1E,OAAO,EACL,OAAO,EACP,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,cAAc,EACd,QAAQ,EACR,SAAS,IAAI,UAAU,EACvB,gBAAgB,IAAI,iBAAiB,EACtC,MAAM,OAAO,CAAC;AACf,YAAY,EAAC,eAAe,EAAC,MAAM,OAAO,CAAC;AAC3C,YAAY,EAAC,eAAe,EAAC,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,qBAAqB,EAAE,qBAAqB,EAAC,MAAM,UAAU,CAAC;AACtE,OAAO,EAAC,OAAO,IAAI,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAC,OAAO,IAAI,eAAe,EAAC,MAAM,2BAA2B,CAAC;AACrE,OAAO,EAAC,OAAO,IAAI,YAAY,EAAC,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAC,OAAO,IAAI,iBAAiB,EAAC,MAAM,6BAA6B,CAAC;AACzE,OAAO,EAAC,OAAO,IAAI,OAAO,EAAC,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAC,OAAO,IAAI,SAAS,EAAC,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAC,OAAO,IAAI,eAAe,EAAC,MAAM,gCAAgC,CAAC;AAC1E,OAAO,EAAC,OAAO,IAAI,eAAe,EAAC,MAAM,gCAAgC,CAAC;AAC1E,OAAO,EACL,OAAO,EACP,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,aAAa,EACb,cAAc,EACd,QAAQ,EACR,SAAS,IAAI,UAAU,EACvB,gBAAgB,IAAI,iBAAiB,EACtC,MAAM,OAAO,CAAC;AACf,YAAY,EAAC,eAAe,EAAE,eAAe,EAAC,MAAM,OAAO,CAAC;AAC5D,YAAY,EAAC,eAAe,EAAC,MAAM,sBAAsB,CAAC"}
package/typed/index.js ADDED
@@ -0,0 +1,10 @@
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';
@@ -1,4 +1,5 @@
1
1
  import { CompositeLayer, CompositeLayerProps, Layer, LayerProps, UpdateParameters } from '@deck.gl/core/typed';
2
+ import { CartoAPIError } from '../api/carto-api-error';
2
3
  import { MapType, TileFormat, QueryParameters } from '../api/maps-api-common';
3
4
  import { Credentials } from '../config';
4
5
  import { Headers } from '../api/maps-v3-client';
@@ -64,9 +65,9 @@ declare type _CartoLayerProps = {
64
65
  /**
65
66
  * Called when the request to the CARTO Maps API failed.
66
67
  *
67
- * By default the Error is thrown.
68
+ * By default the CartoAPIError is thrown.
68
69
  */
69
- onDataError?: (err: unknown) => void;
70
+ onDataError?: (err: CartoAPIError) => void;
70
71
  clientId?: string;
71
72
  /** Custom headers to include in the map instantiation request **/
72
73
  headers?: Headers;
@@ -1 +1 @@
1
- {"version":3,"file":"carto-layer.d.ts","sourceRoot":"","sources":["../../src/layers/carto-layer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,KAAK,EACL,UAAU,EAEV,gBAAgB,EACjB,MAAM,eAAe,CAAC;AAKvB,OAAO,EAIL,OAAO,EAEP,UAAU,EACV,eAAe,EAChB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAGL,WAAW,EAEZ,MAAM,WAAW,CAAC;AACnB,OAAO,EAAuB,OAAO,EAAC,MAAM,uBAAuB,CAAC;AAiDpE,8CAA8C;AAC9C,oBAAY,eAAe,CAAC,KAAK,GAAG,GAAG,IAAI,gBAAgB,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC;AAEzF,sCAAsC;AACtC,aAAK,gBAAgB,GAAG;IACtB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;;;;;OAOG;IACH,IAAI,EAAE,OAAO,CAAC;IAEd;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,UAAU,CAAC;IAEzB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IAEnB;;;;OAIG;IACH,gBAAgB,C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