@@ -6,7 +6,7 @@ import {MapboxOverlay} from '@deck.gl/mapbox';
6
6
7
7
import { DeckProps } from '@deck.gl/core' ;
8
8
import { trajectoryQuerySource , trajectoryTableSource } from '@carto/api-client' ;
9
- import { TrajectoryTileLayer , colorContinuous } from '@deck.gl/carto' ;
9
+ import { TrajectoryTileLayer , colorCategories , colorContinuous } from '@deck.gl/carto' ;
10
10
import { normalizeTimestamp } from '@deck.gl/carto/layers/trajectory-utils' ;
11
11
12
12
import RangeInput from './range-input' ;
@@ -296,16 +296,38 @@ export default function App() {
296
296
data : dataSource ,
297
297
renderMode : showTrips ? 'trips' : 'paths' ,
298
298
uniqueIdProperty : 'trajectoryId' , // TODO internalize this
299
- // Example: Use speed-based coloring with CARTO palette
299
+
300
+ // Color entire line by trajectoryId
301
+ //_getLineColor: colorContinuous({
302
+ // attr: 'trajectoryId',
303
+ // domain: [0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],
304
+ // colors: palette
305
+ //}),
306
+ getLineColor : ( d : any , info : any ) => {
307
+ //return [255 * Math.random(), 255 * Math.random(), 255 * Math.random(), 255];
308
+ const { data, index } = info ;
309
+ const nVertices = data . startIndices [ index + 1 ] - data . startIndices [ index ] ;
310
+ const colors = new Array ( nVertices ) . fill ( 0 ) . map ( ( _ , i ) => {
311
+ return [ 255 * Math . random ( ) , 255 * Math . random ( ) , 255 * Math . random ( ) , 255 ] ;
312
+ } ) ;
313
+
314
+ // Return an array to color each vertex
315
+ return colors ;
316
+ } ,
317
+
318
+
319
+ // Alternative API, dedicated accessor: Color each vertex by speed
300
320
getVertexColor : colorContinuous ( {
301
321
attr : ( d : any ) => d . speed ,
302
322
domain : [ 5 , 7 , 9 , 11 , 13 , 15 ] ,
303
323
colors : palette
304
324
} ) ,
305
325
306
326
// Alternative examples:
307
- // getVertexColor: ({speed}) => speed > 10 ? [255, 0, 0, 255] : [0, 255, 0, 255], // Red/Green based on speed
308
- // getVertexColor: ({speed}, {index}) => [Math.min(255, speed * 20), 100, 200, 255], // Speed-based red intensity
327
+ // getVertexColor: (d: any) => {
328
+
329
+ // return d.speed > 10 ? [255, 0, 0, 255] : [0, 255, 0, 255]; // Red/Green based on speed
330
+ //},
309
331
currentTime,
310
332
trailLength,
311
333
getWidth : lineWidth ,
0 commit comments