@deck.gl/carto 9.4.0-alpha.2 → 9.4.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.
Files changed (34) hide show
  1. package/dist/api/types.d.ts +1 -11
  2. package/dist/api/types.d.ts.map +1 -1
  3. package/dist/cartoPropertiesTile-worker.js +115 -163
  4. package/dist/cartoRasterTile-worker.js +107 -153
  5. package/dist/cartoSpatialTile-worker.js +123 -175
  6. package/dist/cartoVectorTile-worker.js +191 -301
  7. package/dist/dist.dev.js +872 -1514
  8. package/dist/index.cjs +19749 -216
  9. package/dist/index.cjs.map +3 -4
  10. package/dist/layers/h3-tile-layer.d.ts.map +1 -1
  11. package/dist/layers/quadbin-tile-layer.d.ts.map +1 -1
  12. package/dist/layers/raster-tile-layer.d.ts.map +1 -1
  13. package/dist/layers/schema/carto-properties-tile-loader.js +1 -1
  14. package/dist/layers/schema/carto-properties-tile-loader.js.map +1 -1
  15. package/dist/layers/schema/carto-raster-tile-loader.js +1 -1
  16. package/dist/layers/schema/carto-raster-tile-loader.js.map +1 -1
  17. package/dist/layers/schema/carto-spatial-tile-loader.js +1 -1
  18. package/dist/layers/schema/carto-spatial-tile-loader.js.map +1 -1
  19. package/dist/layers/schema/carto-vector-tile-loader.js +1 -1
  20. package/dist/layers/schema/carto-vector-tile-loader.js.map +1 -1
  21. package/dist/utils.d.ts +2 -2
  22. package/dist.min.js +10 -10
  23. package/package.json +5 -5
  24. package/src/api/types.ts +1 -13
  25. package/dist/api/layer-map.d.ts +0 -57
  26. package/dist/api/layer-map.d.ts.map +0 -1
  27. package/dist/api/layer-map.js +0 -385
  28. package/dist/api/layer-map.js.map +0 -1
  29. package/dist/api/parse-map.d.ts +0 -32
  30. package/dist/api/parse-map.d.ts.map +0 -1
  31. package/dist/api/parse-map.js +0 -260
  32. package/dist/api/parse-map.js.map +0 -1
  33. package/src/api/layer-map.ts +0 -498
  34. package/src/api/parse-map.ts +0 -372
@@ -1,372 +0,0 @@
1
- // deck.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
-
5
- /* eslint-disable no-shadow */
6
-
7
- import {ColorParameters} from '@luma.gl/core';
8
- import {Layer, log} from '@deck.gl/core';
9
- import {
10
- AGGREGATION,
11
- getLayer,
12
- getColorAccessor,
13
- getColorValueAccessor,
14
- getSizeAccessor,
15
- getTextAccessor,
16
- OPACITY_MAP,
17
- opacityToAlpha,
18
- getIconUrlAccessor,
19
- negateAccessor,
20
- getMaxMarkerSize
21
- } from './layer-map';
22
- import {assert} from '../utils';
23
- import {KeplerMapConfig, MapDataset, MapLayerConfig, VisualChannels} from './types';
24
-
25
- export type ParseMapResult = {
26
- /** Map id. */
27
- id: string;
28
-
29
- /** Title of map. */
30
- title: string;
31
-
32
- /** Description of map. */
33
- description?: string;
34
- createdAt: string;
35
- updatedAt: string;
36
- initialViewState: any;
37
-
38
- /** @deprecated Use `basemap`. */
39
- mapStyle: any;
40
- token: string;
41
-
42
- layers: Layer[];
43
- };
44
-
45
- export function parseMap(json) {
46
- const {keplerMapConfig, datasets, token} = json;
47
- assert(keplerMapConfig.version === 'v1', 'Only support Kepler v1');
48
- const {mapState, mapStyle} = keplerMapConfig.config as KeplerMapConfig;
49
- const {layers, layerBlending, interactionConfig} = keplerMapConfig.config.visState;
50
-
51
- return {
52
- id: json.id,
53
- title: json.title,
54
- description: json.description,
55
- createdAt: json.createdAt,
56
- updatedAt: json.updatedAt,
57
- initialViewState: mapState,
58
- /** @deprecated Use `basemap`. */
59
- mapStyle,
60
- token,
61
- layers: layers.reverse().map(({id, type, config, visualChannels}) => {
62
- try {
63
- const {dataId} = config;
64
- const dataset: MapDataset | null = datasets.find(d => d.id === dataId);
65
- assert(dataset, `No dataset matching dataId: ${dataId}`);
66
- const {data} = dataset;
67
- assert(data, `No data loaded for dataId: ${dataId}`);
68
- const {Layer, propMap, defaultProps} = getLayer(type, config, dataset);
69
- const styleProps = createStyleProps(config, propMap);
70
- return new Layer({
71
- id,
72
- data,
73
- ...defaultProps,
74
- ...createInteractionProps(interactionConfig),
75
- ...styleProps,
76
- ...createChannelProps(id, type, config, visualChannels, data), // Must come after style
77
- ...createParametersProp(layerBlending, styleProps.parameters || {}), // Must come after style
78
- ...createLoadOptions(token)
79
- });
80
- } catch (e: any) {
81
- log.error(e.message)();
82
- return undefined;
83
- }
84
- })
85
- };
86
- }
87
-
88
- function createParametersProp(layerBlending: string, parameters: ColorParameters) {
89
- if (layerBlending === 'additive') {
90
- parameters.blendColorSrcFactor = parameters.blendAlphaSrcFactor = 'src-alpha';
91
- parameters.blendColorDstFactor = parameters.blendAlphaDstFactor = 'dst-alpha';
92
- parameters.blendColorOperation = parameters.blendAlphaOperation = 'add';
93
- } else if (layerBlending === 'subtractive') {
94
- parameters.blendColorSrcFactor = 'one';
95
- parameters.blendColorDstFactor = 'one-minus-dst';
96
- parameters.blendAlphaSrcFactor = 'src-alpha';
97
- parameters.blendAlphaDstFactor = 'dst-alpha';
98
- parameters.blendColorOperation = 'subtract';
99
- parameters.blendAlphaOperation = 'add';
100
- }
101
-
102
- return Object.keys(parameters).length ? {parameters} : {};
103
- }
104
-
105
- function createInteractionProps(interactionConfig) {
106
- const pickable = interactionConfig && interactionConfig.tooltip.enabled;
107
- return {
108
- autoHighlight: pickable,
109
- pickable
110
- };
111
- }
112
-
113
- function mapProps(source, target, mapping) {
114
- for (const sourceKey in mapping) {
115
- const sourceValue = source[sourceKey];
116
- const targetKey = mapping[sourceKey];
117
- if (sourceValue === undefined) {
118
- // eslint-disable-next-line no-continue
119
- continue;
120
- }
121
- if (typeof targetKey === 'string') {
122
- target[targetKey] = sourceValue;
123
- } else if (typeof targetKey === 'function') {
124
- const [key, value] = Object.entries(targetKey(sourceValue))[0];
125
- target[key] = value;
126
- } else if (typeof targetKey === 'object') {
127
- // Nested definition, recurse down one level (also handles arrays)
128
- mapProps(sourceValue, target, targetKey);
129
- }
130
- }
131
- }
132
-
133
- function createStyleProps(config: MapLayerConfig, mapping) {
134
- const result: Record<string, any> = {};
135
- mapProps(config, result, mapping);
136
-
137
- // Kepler format sometimes omits strokeColor. TODO: remove once we can rely on
138
- // `strokeColor` always being set when `stroke: true`.
139
- if (result.stroked && !result.getLineColor) {
140
- result.getLineColor = result.getFillColor;
141
- }
142
-
143
- for (const colorAccessor in OPACITY_MAP) {
144
- if (Array.isArray(result[colorAccessor])) {
145
- const color = [...result[colorAccessor]];
146
- const opacityKey = OPACITY_MAP[colorAccessor];
147
- const opacity = config.visConfig[opacityKey];
148
- color[3] = opacityToAlpha(opacity);
149
- result[colorAccessor] = color;
150
- }
151
- }
152
-
153
- result.highlightColor = config.visConfig.enable3d ? [255, 255, 255, 60] : [252, 242, 26, 255];
154
- return result;
155
- }
156
-
157
- /* eslint-disable complexity, max-statements */
158
- function createChannelProps(
159
- id: string,
160
- type: string,
161
- config: MapLayerConfig,
162
- visualChannels: VisualChannels,
163
- data
164
- ) {
165
- const {
166
- colorField,
167
- colorScale,
168
- radiusField,
169
- radiusScale,
170
- sizeField,
171
- sizeScale,
172
- strokeColorField,
173
- strokeColorScale,
174
- weightField
175
- } = visualChannels;
176
- let {heightField, heightScale} = visualChannels;
177
- if (type === 'hexagonId') {
178
- heightField = sizeField;
179
- heightScale = sizeScale;
180
- }
181
- const {textLabel, visConfig} = config;
182
- const result: Record<string, any> = {};
183
-
184
- if (type === 'grid' || type === 'hexagon') {
185
- result.colorScaleType = colorScale;
186
- if (colorField) {
187
- const {colorAggregation} = config.visConfig;
188
- if (!AGGREGATION[colorAggregation]) {
189
- result.getColorValue = getColorValueAccessor(colorField, colorAggregation, data);
190
- } else {
191
- result.getColorWeight = d => d[colorField.name];
192
- }
193
- }
194
- } else if (colorField) {
195
- const {colorAggregation: aggregation, colorRange: range} = visConfig;
196
- result.getFillColor = getColorAccessor(
197
- colorField,
198
- // @ts-ignore
199
- colorScale,
200
- {aggregation, range},
201
- visConfig.opacity,
202
- data
203
- );
204
- }
205
-
206
- if (type === 'point') {
207
- const altitude = config.columns?.altitude;
208
- if (altitude) {
209
- result.dataTransform = data => {
210
- data.features.forEach(({geometry, properties}) => {
211
- const {type, coordinates} = geometry;
212
- if (type === 'Point') {
213
- coordinates[2] = properties[altitude];
214
- }
215
- });
216
- return data;
217
- };
218
- }
219
- }
220
-
221
- if (radiusField || sizeField) {
222
- result.getPointRadius = getSizeAccessor(
223
- // @ts-ignore
224
- radiusField || sizeField,
225
- // @ts-ignore
226
- radiusScale || sizeScale,
227
- visConfig.sizeAggregation,
228
- visConfig.radiusRange || visConfig.sizeRange,
229
- data
230
- );
231
- }
232
-
233
- if (strokeColorField) {
234
- const fallbackOpacity = type === 'point' ? visConfig.opacity : 1;
235
- const opacity =
236
- visConfig.strokeOpacity !== undefined ? visConfig.strokeOpacity : fallbackOpacity;
237
- const {strokeColorAggregation: aggregation, strokeColorRange: range} = visConfig;
238
- result.getLineColor = getColorAccessor(
239
- strokeColorField,
240
- // @ts-ignore
241
- strokeColorScale,
242
- // @ts-ignore
243
- {aggregation, range},
244
- opacity,
245
- data
246
- );
247
- }
248
- if (heightField && visConfig.enable3d) {
249
- result.getElevation = getSizeAccessor(
250
- heightField,
251
- // @ts-ignore
252
- heightScale,
253
- visConfig.heightAggregation,
254
- visConfig.heightRange || visConfig.sizeRange,
255
- data
256
- );
257
- }
258
-
259
- if (weightField) {
260
- result.getWeight = getSizeAccessor(
261
- weightField,
262
- undefined,
263
- visConfig.weightAggregation,
264
- undefined,
265
- data
266
- );
267
- }
268
-
269
- if (visConfig.customMarkers) {
270
- const maxIconSize = getMaxMarkerSize(visConfig, visualChannels);
271
- const {getPointRadius, getFillColor} = result;
272
- const {customMarkersUrl, customMarkersRange, filled: useMaskedIcons} = visConfig;
273
-
274
- result.pointType = 'icon';
275
- result.getIcon = getIconUrlAccessor(
276
- visualChannels.customMarkersField,
277
- customMarkersRange,
278
- {fallbackUrl: customMarkersUrl, maxIconSize, useMaskedIcons},
279
- data
280
- );
281
- result._subLayerProps = {
282
- 'points-icon': {
283
- loadOptions: {
284
- image: {
285
- type: 'imagebitmap'
286
- },
287
- imagebitmap: {
288
- resizeWidth: maxIconSize,
289
- resizeHeight: maxIconSize,
290
- resizeQuality: 'high'
291
- }
292
- }
293
- }
294
- };
295
-
296
- if (getFillColor && useMaskedIcons) {
297
- result.getIconColor = getFillColor;
298
- }
299
-
300
- if (getPointRadius) {
301
- result.getIconSize = getPointRadius;
302
- }
303
-
304
- if (visualChannels.rotationField) {
305
- result.getIconAngle = negateAccessor(
306
- getSizeAccessor(visualChannels.rotationField, undefined, null, undefined, data)
307
- );
308
- }
309
- } else if (type === 'point' || type === 'tileset') {
310
- result.pointType = 'circle';
311
- }
312
-
313
- if (textLabel && textLabel.length && textLabel[0].field) {
314
- const [mainLabel, secondaryLabel] = textLabel;
315
- const collisionGroup = id;
316
-
317
- ({
318
- alignment: result.getTextAlignmentBaseline,
319
- anchor: result.getTextAnchor,
320
- color: result.getTextColor,
321
- outlineColor: result.textOutlineColor,
322
- size: result.textSizeScale
323
- } = mainLabel);
324
- const {
325
- color: getSecondaryColor,
326
- field: secondaryField,
327
- outlineColor: secondaryOutlineColor,
328
- size: secondarySizeScale
329
- } = secondaryLabel || {};
330
-
331
- result.getText = mainLabel.field && getTextAccessor(mainLabel.field, data);
332
- const getSecondaryText = secondaryField && getTextAccessor(secondaryField, data);
333
-
334
- result.pointType = `${result.pointType}+text`;
335
- result.textCharacterSet = 'auto';
336
- result.textFontFamily = 'Inter, sans';
337
- result.textFontSettings = {sdf: true};
338
- result.textFontWeight = 600;
339
- result.textOutlineWidth = 3;
340
-
341
- result._subLayerProps = {
342
- ...result._subLayerProps,
343
- 'points-text': {
344
- // The following props are injected by default by VectorTileLayer:
345
- // type: PointLabelLayer,
346
- // extensions: [new CollisionFilterExtension()],
347
- collisionEnabled: true,
348
- collisionGroup,
349
-
350
- // getPointRadius already has radiusScale baked in, so only pass one or the other
351
- ...(result.getPointRadius
352
- ? {getRadius: result.getPointRadius}
353
- : {radiusScale: visConfig.radius}),
354
-
355
- ...(secondaryField && {
356
- getSecondaryText,
357
- getSecondaryColor,
358
- secondarySizeScale,
359
- secondaryOutlineColor
360
- })
361
- }
362
- };
363
- }
364
-
365
- return result;
366
- }
367
-
368
- function createLoadOptions(accessToken: string) {
369
- return {
370
- loadOptions: {core: {fetch: {headers: {Authorization: `Bearer ${accessToken}`}}}}
371
- };
372
- }