@@ -7,7 +7,7 @@ import {_Tile2DHeader, TripsLayer, TripsLayerProps} from '@deck.gl/geo-layers';
7
7
import { GeoJsonLayer } from '@deck.gl/layers' ;
8
8
9
9
import type { TilejsonResult } from '@carto/api-client' ;
10
- import VectorTileLayer , { VectorTileLayerProps } from './vector-tile-layer' ;
10
+ import VectorTileLayer , { VectorTileLayerProps } from './vector-tile-layer' ;
11
11
import { transformTrajectoryData , type TileBounds , normalizeTimestamp } from './trajectory-utils' ;
12
12
import { autocomputeSpeed } from './trajectory-speed-utils' ;
13
13
import { createBinaryProxy , createEmptyBinary } from '../utils' ;
@@ -24,7 +24,10 @@ const defaultProps: DefaultProps<TrajectoryTileLayerProps> = {
24
24
/** All properties supported by TrajectoryTileLayer. */
25
25
export type TrajectoryTileLayerProps < FeaturePropertiesT = unknown > = _TrajectoryTileLayerProps &
26
26
Omit < TripsLayerProps < FeaturePropertiesT > , 'data' > &
27
- Pick < VectorTileLayerProps < FeaturePropertiesT > , 'getFillColor' | 'getLineColor' | 'uniqueIdProperty' > ;
27
+ Pick <
28
+ VectorTileLayerProps < FeaturePropertiesT > ,
29
+ 'getFillColor' | 'getLineColor' | 'uniqueIdProperty'
30
+ > ;
28
31
29
32
/** Properties added by TrajectoryTileLayer. */
30
33
type _TrajectoryTileLayerProps = {
@@ -46,8 +49,8 @@ type _TrajectoryTileLayerProps = {
46
49
/**
47
50
* Helper function to wrap `getFillColor` accessor into a `getLineColor` accessor
48
51
* which will invoke `getFillColor` for each vertex in the line
49
- * @param getFillColor
50
- * @returns
52
+ * @param getFillColor
53
+ * @returns
51
54
*/
52
55
function getLineColorFromFillColor ( getFillColor : TrajectoryTileLayerProps [ 'getFillColor' ] ) {
53
56
return ( d : any , info : any ) => {
@@ -58,12 +61,14 @@ function getLineColorFromFillColor(getFillColor: TrajectoryTileLayerProps['getFi
58
61
const colors = new Array ( nVertices ) . fill ( 0 ) . map ( ( _ , i ) => {
59
62
const index = startIndex + i ;
60
63
const properties = createBinaryProxy ( data , index ) ;
61
- const d = { properties } as any ;
62
- return typeof getFillColor === 'function' ? getFillColor ( d , { index, data, target } ) : getFillColor ;
64
+ const d = { properties} as any ;
65
+ return typeof getFillColor === 'function'
66
+ ? getFillColor ( d , { index, data, target} )
67
+ : getFillColor ;
63
68
} ) ;
64
69
65
70
return colors ;
66
- }
71
+ } ;
67
72
}
68
73
69
74
// @ts -ignore
@@ -90,18 +95,22 @@ export default class TrajectoryTileLayer<
90
95
super . updateState ( parameters ) ;
91
96
if ( parameters . props . data && parameters . props . data . widgetSource ) {
92
97
const dataSourceProps = parameters . props . data . widgetSource . props ;
93
- const { trajectoryIdColumn, timestampColumn } = dataSourceProps ;
94
-
98
+ const { trajectoryIdColumn, timestampColumn} = dataSourceProps ;
99
+
95
100
if ( ! trajectoryIdColumn ) {
96
- throw new Error ( 'TrajectoryTileLayer: trajectoryIdColumn is required in data source configuration' ) ;
101
+ throw new Error (
102
+ 'TrajectoryTileLayer: trajectoryIdColumn is required in data source configuration'
103
+ ) ;
97
104
}
98
105
if ( ! timestampColumn ) {
99
- throw new Error ( 'TrajectoryTileLayer: timestampColumn is required in data source configuration' ) ;
106
+ throw new Error (
107
+ 'TrajectoryTileLayer: timestampColumn is required in data source configuration'
108
+ ) ;
100
109
}
101
-
110
+
102
111
this . setState ( { trajectoryIdColumn, timestampColumn} ) ;
103
112
}
104
-
113
+
105
114
// Read timestampRange from the data source (tilejson)
106
115
if ( parameters . props . data && parameters . props . data . timestampRange ) {
107
116
const { min, max} = parameters . props . data . timestampRange ;
@@ -119,7 +128,7 @@ export default class TrajectoryTileLayer<
119
128
const tileBounds = tile . bbox as TileBounds ;
120
129
const { minTime, maxTime} = this . state ;
121
130
122
- let lines = transformTrajectoryData (
131
+ const lines = transformTrajectoryData (
123
132
data . points ,
124
133
this . state . trajectoryIdColumn ,
125
134
this . state . timestampColumn ,
@@ -131,7 +140,7 @@ export default class TrajectoryTileLayer<
131
140
if ( this . props . autocomputeSpeed ) {
132
141
autocomputeSpeed ( lines ) ;
133
142
}
134
- return { ...createEmptyBinary ( ) , lines }
143
+ return { ...createEmptyBinary ( ) , lines} ;
135
144
}
136
145
137
146
renderSubLayers (
@@ -140,7 +149,7 @@ export default class TrajectoryTileLayer<
140
149
data : any ;
141
150
_offset : number ;
142
151
tile : _Tile2DHeader ;
143
- _subLayerProps : CompositeLayerProps [ " _subLayerProps" ] ;
152
+ _subLayerProps : CompositeLayerProps [ ' _subLayerProps' ] ;
144
153
}
145
154
) : GeoJsonLayer | GeoJsonLayer [ ] | null {
146
155
if ( props . data === null ) {
@@ -150,7 +159,7 @@ export default class TrajectoryTileLayer<
150
159
// This may not be as efficient as just rendering a PathLayer, but it allows to
151
160
// switch between the render modes without reloading data
152
161
const showTrips = props . renderMode === 'trips' ;
153
-
162
+
154
163
// Normalize currentTime to match the normalized timestamps in the data
155
164
const normalizedCurrentTime = props . currentTime ! - this . state . minTime ;
156
165
const { minTime, maxTime} = this . state ;
@@ -161,27 +170,29 @@ export default class TrajectoryTileLayer<
161
170
widthUnits : props . widthUnits || 'pixels' ,
162
171
lineJointRounded : props . jointRounded !== undefined ? props . jointRounded : true ,
163
172
capRounded : props . capRounded !== undefined ? props . capRounded : true ,
164
- _pathType : props . _pathType || 'open' ,
173
+ _pathType : props . _pathType || 'open'
165
174
} ;
166
175
167
- const getLineColor = props . getFillColor ? getLineColorFromFillColor ( props . getFillColor ) : props . getLineColor ;
176
+ const getLineColor = props . getFillColor
177
+ ? getLineColorFromFillColor ( props . getFillColor )
178
+ : props . getLineColor ;
168
179
169
180
const modifiedProps = {
170
181
...props ,
171
182
getLineColor,
172
183
_subLayerProps : {
173
184
...props . _subLayerProps ,
174
185
linestrings : {
175
- type : TripsLayer ,
176
- currentTime : showTrips ? normalizedCurrentTime : totalTimeSpan ,
177
- trailLength : showTrips ? props . trailLength : totalTimeSpan ,
178
- parameters : { depthTest : false } ,
179
- ...layerProps ,
180
- ...props . _subLayerProps ?. linestrings
181
- }
186
+ type : TripsLayer ,
187
+ currentTime : showTrips ? normalizedCurrentTime : totalTimeSpan ,
188
+ trailLength : showTrips ? props . trailLength : totalTimeSpan ,
189
+ parameters : { depthTest : false } ,
190
+ ...layerProps ,
191
+ ...props . _subLayerProps ?. linestrings
192
+ }
182
193
}
183
194
} ;
184
195
185
196
return super . renderSubLayers ( modifiedProps as any ) ;
186
197
}
187
- }
198
+ }
0 commit comments