@carto/api-client 0.5.15-alpha.raster-5 → 0.5.16
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/CHANGELOG.md +9 -0
- package/build/api-client.cjs +325 -979
- package/build/api-client.cjs.map +1 -1
- package/build/api-client.d.cts +87 -154
- package/build/api-client.d.ts +87 -154
- package/build/api-client.js +319 -965
- package/build/api-client.js.map +1 -1
- package/build/worker-compat.js +1395 -1276
- package/build/worker-compat.js.map +1 -1
- package/build/worker.js +34 -0
- package/build/worker.js.map +1 -1
- package/package.json +3 -5
- package/src/fetch-map/basemap-styles.ts +1 -1
- package/src/fetch-map/index.ts +1 -6
- package/src/fetch-map/layer-map.ts +40 -130
- package/src/fetch-map/parse-map.ts +165 -284
- package/src/fetch-map/types.ts +7 -21
- package/src/fetch-map/utils.ts +0 -56
- package/src/index.ts +1 -7
- package/src/models/model.ts +1 -0
- package/src/sources/index.ts +12 -0
- package/src/sources/trajectory-query-source.ts +101 -0
- package/src/sources/trajectory-table-source.ts +96 -0
- package/src/sources/types.ts +12 -53
- package/src/widget-sources/types.ts +29 -1
- package/src/widget-sources/widget-remote-source.ts +30 -0
- package/src/widget-sources/widget-source.ts +11 -0
- package/src/widget-sources/widget-tileset-source-impl.ts +49 -0
- package/src/widget-sources/widget-tileset-source.ts +13 -0
- package/src/workers/constants.ts +1 -0
- package/src/fetch-map/raster-layer.ts +0 -536
- package/src/fetch-map/vec-expr-evaluator.ts +0 -374
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"homepage": "https://github.com/CartoDB/carto-api-client#readme",
|
|
9
9
|
"author": "Don McCurdy <donmccurdy@carto.com>",
|
|
10
10
|
"packageManager": "yarn@4.3.1",
|
|
11
|
-
"version": "0.5.
|
|
11
|
+
"version": "0.5.16",
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"publishConfig": {
|
|
14
14
|
"access": "public"
|
|
@@ -71,7 +71,6 @@
|
|
|
71
71
|
"d3-format": "^3.1.0",
|
|
72
72
|
"d3-scale": "^4.0.2",
|
|
73
73
|
"h3-js": "^4.1.0",
|
|
74
|
-
"jsep": "^1.4.0",
|
|
75
74
|
"quadbin": "^0.4.1-alpha.0"
|
|
76
75
|
},
|
|
77
76
|
"devDependencies": {
|
|
@@ -122,7 +121,7 @@
|
|
|
122
121
|
"rimraf": "^6.0.1",
|
|
123
122
|
"semver": "^7.7.1",
|
|
124
123
|
"thenby": "^1.3.4",
|
|
125
|
-
"tinybench": "^
|
|
124
|
+
"tinybench": "^5.0.1",
|
|
126
125
|
"tsup": "^8.3.6",
|
|
127
126
|
"typescript": "~5.9.2",
|
|
128
127
|
"typescript-eslint": "^8.26.1",
|
|
@@ -132,6 +131,5 @@
|
|
|
132
131
|
"resolutions": {
|
|
133
132
|
"@carto/api-client": "portal:./",
|
|
134
133
|
"rollup": "^4.20.0"
|
|
135
|
-
}
|
|
136
|
-
"stableVersion": "0.5.14"
|
|
134
|
+
}
|
|
137
135
|
}
|
|
@@ -92,7 +92,7 @@ export const STYLE_LAYER_GROUPS: StyleLayerGroup[] = [
|
|
|
92
92
|
];
|
|
93
93
|
|
|
94
94
|
export function applyLayerGroupFilters(
|
|
95
|
-
style: any,
|
|
95
|
+
style: any,
|
|
96
96
|
visibleLayerGroups: Record<StyleLayerGroupSlug, boolean>
|
|
97
97
|
) {
|
|
98
98
|
if (!Array.isArray(style?.layers)) {
|
package/src/fetch-map/index.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
default as BASEMAP,
|
|
3
|
-
applyLayerGroupFilters as _applyLayerGroupFilters,
|
|
4
|
-
} from './basemap-styles.js';
|
|
5
|
-
export {getRasterTileLayerStyleProps as _getRasterTileLayerStyleProps} from './raster-layer.js';
|
|
1
|
+
export {default as BASEMAP} from './basemap-styles.js';
|
|
6
2
|
export {fetchMap} from './fetch-map.js';
|
|
7
3
|
export type {FetchMapOptions, FetchMapResult} from './fetch-map.js';
|
|
8
4
|
export type {
|
|
@@ -15,4 +11,3 @@ export type {
|
|
|
15
11
|
export * from './basemap.js';
|
|
16
12
|
export * from './layer-map.js';
|
|
17
13
|
export * from './parse-map.js';
|
|
18
|
-
export {getLog10ScaleSteps as _getLog10ScaleSteps} from './utils.js';
|
|
@@ -25,11 +25,9 @@ import {
|
|
|
25
25
|
createBinaryProxy,
|
|
26
26
|
formatDate,
|
|
27
27
|
formatTimestamp,
|
|
28
|
-
getLog10ScaleSteps,
|
|
29
28
|
scaleIdentity,
|
|
30
29
|
} from './utils.js';
|
|
31
30
|
import type {
|
|
32
|
-
ColorRange,
|
|
33
31
|
CustomMarkersRange,
|
|
34
32
|
Dataset,
|
|
35
33
|
MapLayerConfig,
|
|
@@ -40,7 +38,6 @@ import type {
|
|
|
40
38
|
import type {ProviderType, SchemaField} from '../types.js';
|
|
41
39
|
import {DEFAULT_AGGREGATION_EXP_ALIAS} from '../constants-internal.js';
|
|
42
40
|
import {AggregationTypes} from '../constants.js';
|
|
43
|
-
import type {Attribute, TilejsonResult} from '../sources/types.js';
|
|
44
41
|
|
|
45
42
|
export type D3Scale = {
|
|
46
43
|
domain: (d?: any) => any[];
|
|
@@ -75,21 +72,7 @@ function identity<T>(v: T): T {
|
|
|
75
72
|
return v;
|
|
76
73
|
}
|
|
77
74
|
|
|
78
|
-
const hexToRGB = (c: any) => {
|
|
79
|
-
const {r, g, b} = rgb(c);
|
|
80
|
-
return [r, g, b];
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const rgbToHex = (c: number[]) => {
|
|
84
|
-
const [r, g, b] = c;
|
|
85
|
-
const rStr = r.toString(16).padStart(2, '0');
|
|
86
|
-
const gStr = g.toString(16).padStart(2, '0');
|
|
87
|
-
const bStr = b.toString(16).padStart(2, '0');
|
|
88
|
-
return `#${rStr}${gStr}${bStr}`.toUpperCase();
|
|
89
|
-
};
|
|
90
|
-
|
|
91
75
|
const UNKNOWN_COLOR = '#868d91';
|
|
92
|
-
const UNKNOWN_COLOR_RGB = hexToRGB(UNKNOWN_COLOR);
|
|
93
76
|
|
|
94
77
|
export const OPACITY_MAP: Record<string, string> = {
|
|
95
78
|
getFillColor: 'opacity',
|
|
@@ -130,13 +113,6 @@ const sharedPropMap = {
|
|
|
130
113
|
},
|
|
131
114
|
};
|
|
132
115
|
|
|
133
|
-
const rasterPropsMap = {
|
|
134
|
-
isVisible: 'visible',
|
|
135
|
-
visConfig: {
|
|
136
|
-
opacity: 'opacity',
|
|
137
|
-
},
|
|
138
|
-
};
|
|
139
|
-
|
|
140
116
|
const customMarkersPropsMap = {
|
|
141
117
|
color: 'getIconColor',
|
|
142
118
|
visConfig: {
|
|
@@ -198,13 +174,6 @@ export function getLayerProps(
|
|
|
198
174
|
);
|
|
199
175
|
}
|
|
200
176
|
|
|
201
|
-
if (type === 'raster') {
|
|
202
|
-
return {
|
|
203
|
-
propMap: rasterPropsMap,
|
|
204
|
-
defaultProps: {},
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
|
|
208
177
|
let basePropMap: any = sharedPropMap;
|
|
209
178
|
if (config.visConfig?.customMarkers) {
|
|
210
179
|
basePropMap = mergePropMaps(basePropMap, customMarkersPropsMap);
|
|
@@ -226,21 +195,18 @@ export function getLayerProps(
|
|
|
226
195
|
}
|
|
227
196
|
|
|
228
197
|
function domainFromAttribute(
|
|
229
|
-
attribute:
|
|
198
|
+
attribute: any,
|
|
230
199
|
scaleType: ScaleType,
|
|
231
200
|
scaleLength: number
|
|
232
|
-
)
|
|
201
|
+
) {
|
|
233
202
|
if (scaleType === 'ordinal' || scaleType === 'point') {
|
|
234
|
-
if (!attribute.categories) {
|
|
235
|
-
return [0, 1];
|
|
236
|
-
}
|
|
237
203
|
return attribute.categories
|
|
238
204
|
.map((c: any) => c.category)
|
|
239
205
|
.filter((c: any) => c !== undefined && c !== null);
|
|
240
206
|
}
|
|
241
207
|
|
|
242
208
|
if (scaleType === 'quantile' && attribute.quantiles) {
|
|
243
|
-
return
|
|
209
|
+
return attribute.quantiles.global
|
|
244
210
|
? attribute.quantiles.global[scaleLength]
|
|
245
211
|
: attribute.quantiles[scaleLength];
|
|
246
212
|
}
|
|
@@ -249,7 +215,7 @@ function domainFromAttribute(
|
|
|
249
215
|
if (scaleType === 'log' && min === 0) {
|
|
250
216
|
min = 1e-5;
|
|
251
217
|
}
|
|
252
|
-
return [min
|
|
218
|
+
return [min, attribute.max];
|
|
253
219
|
}
|
|
254
220
|
|
|
255
221
|
function domainFromValues(values: any, scaleType: ScaleType) {
|
|
@@ -269,8 +235,8 @@ function domainFromValues(values: any, scaleType: ScaleType) {
|
|
|
269
235
|
}
|
|
270
236
|
|
|
271
237
|
function calculateDomain(
|
|
272
|
-
data:
|
|
273
|
-
name:
|
|
238
|
+
data: any,
|
|
239
|
+
name: any,
|
|
274
240
|
scaleType: ScaleType,
|
|
275
241
|
scaleLength?: number
|
|
276
242
|
) {
|
|
@@ -278,16 +244,14 @@ function calculateDomain(
|
|
|
278
244
|
// Tileset data type
|
|
279
245
|
const {attributes} = data.tilestats.layers[0];
|
|
280
246
|
const attribute = attributes.find((a: any) => a.attribute === name);
|
|
281
|
-
|
|
282
|
-
return domainFromAttribute(attribute, scaleType, scaleLength as number);
|
|
283
|
-
}
|
|
247
|
+
return domainFromAttribute(attribute, scaleType, scaleLength as number);
|
|
284
248
|
}
|
|
285
249
|
|
|
286
250
|
return [0, 1];
|
|
287
251
|
}
|
|
288
252
|
|
|
289
253
|
function normalizeAccessor(accessor: any, data: any) {
|
|
290
|
-
if (data.features || data.tilestats
|
|
254
|
+
if (data.features || data.tilestats) {
|
|
291
255
|
return (object: any, info: any) => {
|
|
292
256
|
if (object) {
|
|
293
257
|
return accessor(object.properties || object.__source.object.properties);
|
|
@@ -333,101 +297,61 @@ function findAccessorKey(keys: string[], properties: any): string[] {
|
|
|
333
297
|
export function getColorAccessor(
|
|
334
298
|
{name, colorColumn}: VisualChannelField,
|
|
335
299
|
scaleType: ScaleType,
|
|
336
|
-
{aggregation, range}: {aggregation
|
|
300
|
+
{aggregation, range}: {aggregation: string; range: any},
|
|
337
301
|
opacity: number | undefined,
|
|
338
|
-
data:
|
|
339
|
-
): {
|
|
340
|
-
|
|
341
|
-
domain: number[] | string[];
|
|
342
|
-
scaleDomain: number[] | string[];
|
|
343
|
-
range: string[];
|
|
344
|
-
} {
|
|
345
|
-
const {scale, domain} = calculateLayerScale(
|
|
302
|
+
data: any
|
|
303
|
+
): {accessor: any; scale: any} {
|
|
304
|
+
const scale = calculateLayerScale(
|
|
346
305
|
colorColumn || name,
|
|
347
|
-
|
|
306
|
+
scaleType,
|
|
348
307
|
range,
|
|
349
308
|
data
|
|
350
309
|
);
|
|
351
310
|
const alpha = opacityToAlpha(opacity);
|
|
352
311
|
|
|
353
|
-
let accessorKeys = getAccessorKeys(
|
|
312
|
+
let accessorKeys = getAccessorKeys(name, aggregation);
|
|
354
313
|
const accessor = (properties: any) => {
|
|
355
314
|
if (!(accessorKeys[0] in properties)) {
|
|
356
315
|
accessorKeys = findAccessorKey(accessorKeys, properties);
|
|
357
316
|
}
|
|
358
317
|
const propertyValue = properties[accessorKeys[0]];
|
|
359
|
-
const
|
|
360
|
-
|
|
361
|
-
return [...rgb, propertyValue === null ? 0 : alpha];
|
|
362
|
-
};
|
|
363
|
-
return {
|
|
364
|
-
accessor: normalizeAccessor(accessor, data),
|
|
365
|
-
scaleDomain: scale.domain(),
|
|
366
|
-
domain,
|
|
367
|
-
range: (scale.range() || []).map(rgbToHex),
|
|
318
|
+
const {r, g, b} = rgb(scale(propertyValue));
|
|
319
|
+
return [r, g, b, propertyValue === null ? 0 : alpha];
|
|
368
320
|
};
|
|
321
|
+
return {accessor: normalizeAccessor(accessor, data), scale};
|
|
369
322
|
}
|
|
370
323
|
|
|
371
|
-
|
|
372
|
-
name:
|
|
324
|
+
function calculateLayerScale(
|
|
325
|
+
name: any,
|
|
373
326
|
scaleType: ScaleType,
|
|
374
|
-
range:
|
|
375
|
-
data:
|
|
376
|
-
)
|
|
377
|
-
|
|
378
|
-
let
|
|
327
|
+
range: any,
|
|
328
|
+
data: any
|
|
329
|
+
) {
|
|
330
|
+
const scale = SCALE_FUNCS[scaleType]();
|
|
331
|
+
let domain: (string | number)[] = [];
|
|
379
332
|
let scaleColor: string[] = [];
|
|
380
|
-
const {colors} = range;
|
|
381
|
-
|
|
382
|
-
if (scaleType === 'custom') {
|
|
383
|
-
domain = calculateDomain(data, name, scaleType, colors.length);
|
|
384
|
-
const [min, max] = domain as number[];
|
|
385
|
-
if (range.uiCustomScaleType === 'logarithmic') {
|
|
386
|
-
scaleDomain = getLog10ScaleSteps({
|
|
387
|
-
min,
|
|
388
|
-
max,
|
|
389
|
-
steps: colors.length,
|
|
390
|
-
});
|
|
391
333
|
|
|
392
|
-
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
|
|
334
|
+
if (scaleType !== 'identity') {
|
|
335
|
+
const {colorMap, colors} = range;
|
|
336
|
+
|
|
337
|
+
if (Array.isArray(colorMap)) {
|
|
396
338
|
colorMap.forEach(([value, color]) => {
|
|
397
|
-
|
|
339
|
+
domain.push(value);
|
|
398
340
|
scaleColor.push(color);
|
|
399
341
|
});
|
|
342
|
+
} else {
|
|
343
|
+
domain = calculateDomain(data, name, scaleType, colors.length);
|
|
344
|
+
scaleColor = colors;
|
|
400
345
|
}
|
|
401
|
-
} else if (scaleType !== 'identity') {
|
|
402
|
-
domain = calculateDomain(data, name, scaleType, colors.length);
|
|
403
|
-
scaleColor = colors;
|
|
404
346
|
|
|
405
347
|
if (scaleType === 'ordinal') {
|
|
406
348
|
domain = domain.slice(0, scaleColor.length);
|
|
407
349
|
}
|
|
408
350
|
}
|
|
409
351
|
|
|
410
|
-
return {
|
|
411
|
-
scale: createColorScale(
|
|
412
|
-
scaleType,
|
|
413
|
-
scaleDomain || domain,
|
|
414
|
-
scaleColor.map(hexToRGB),
|
|
415
|
-
UNKNOWN_COLOR_RGB
|
|
416
|
-
),
|
|
417
|
-
domain,
|
|
418
|
-
};
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
export function createColorScale<T>(
|
|
422
|
-
scaleType: ScaleType,
|
|
423
|
-
domain: string[] | number[],
|
|
424
|
-
range: T[],
|
|
425
|
-
unknown: T
|
|
426
|
-
) {
|
|
427
|
-
const scale = SCALE_FUNCS[scaleType]();
|
|
428
352
|
scale.domain(domain);
|
|
429
|
-
scale.range(
|
|
430
|
-
scale.unknown!(
|
|
353
|
+
scale.range(scaleColor);
|
|
354
|
+
scale.unknown!(UNKNOWN_COLOR);
|
|
431
355
|
|
|
432
356
|
return scale;
|
|
433
357
|
}
|
|
@@ -503,22 +427,13 @@ export function getSizeAccessor(
|
|
|
503
427
|
{name}: VisualChannelField,
|
|
504
428
|
scaleType: ScaleType | undefined,
|
|
505
429
|
aggregation: string | null | undefined,
|
|
506
|
-
range:
|
|
507
|
-
data:
|
|
508
|
-
): {
|
|
509
|
-
accessor: any;
|
|
510
|
-
domain: number[];
|
|
511
|
-
scaleDomain: number[];
|
|
512
|
-
range: number[] | undefined;
|
|
513
|
-
} {
|
|
430
|
+
range: Iterable<Range> | null | undefined,
|
|
431
|
+
data: any
|
|
432
|
+
): {accessor: any; scale: any} {
|
|
514
433
|
const scale = scaleType ? SCALE_FUNCS[scaleType]() : identity;
|
|
515
|
-
|
|
516
|
-
if (scaleType && range) {
|
|
434
|
+
if (scaleType) {
|
|
517
435
|
if (aggregation !== AggregationTypes.Count) {
|
|
518
|
-
|
|
519
|
-
(scale as D3Scale).domain(domain);
|
|
520
|
-
} else {
|
|
521
|
-
domain = (scale as D3Scale).domain();
|
|
436
|
+
(scale as D3Scale).domain(calculateDomain(data, name, scaleType));
|
|
522
437
|
}
|
|
523
438
|
(scale as D3Scale).range(range);
|
|
524
439
|
}
|
|
@@ -531,12 +446,7 @@ export function getSizeAccessor(
|
|
|
531
446
|
const propertyValue = properties[accessorKeys[0]];
|
|
532
447
|
return scale(propertyValue);
|
|
533
448
|
};
|
|
534
|
-
return {
|
|
535
|
-
accessor: normalizeAccessor(accessor, data),
|
|
536
|
-
domain,
|
|
537
|
-
scaleDomain: domain,
|
|
538
|
-
range,
|
|
539
|
-
};
|
|
449
|
+
return {accessor: normalizeAccessor(accessor, data), scale};
|
|
540
450
|
}
|
|
541
451
|
|
|
542
452
|
const FORMATS: Record<string, (value: any) => string> = {
|