3
3
// Copyright (c) vis.gl contributors
4
4
5
5
import { BinaryLineFeature } from '@loaders.gl/schema' ;
6
+ import { NumericProps } from './schema/spatialjson-utils' ;
6
7
7
8
8
9
@@ -175,7 +176,7 @@ export function rebuildGeometry(
175
176
validPoints : TrajectoryPoint [ ] ,
176
177
pathIndices : number [ ] ,
177
178
) : ProcessedGeometry {
178
- const { positions, properties} = originalGeometry ;
179
+ const { positions, numericProps , properties} = originalGeometry ;
179
180
const newN = validPoints . length ;
180
181
181
182
if ( newN === 0 ) {
@@ -195,25 +196,43 @@ export function rebuildGeometry(
195
196
}
196
197
197
198
const size = 2 ;
198
-
199
+ const newNumericProps : NumericProps = { } ;
200
+ const numericPropKeys = Object . keys ( numericProps ) ;
201
+ for ( const prop of numericPropKeys ) {
202
+ const size = numericProps [ prop ] . size || 1 ;
203
+ newNumericProps [ prop ] = { value : new Float32Array ( newN ) , size} ;
204
+ }
205
+
199
206
// Properties are per-line.
200
207
const newFeatureIds = new Uint16Array ( newN ) ;
208
+ let dst = 0 ;
201
209
for ( let i = 0 ; i < pathIndices . length - 1 ; i ++ ) {
202
210
const startIndex = pathIndices [ i ] ;
203
211
const endIndex = pathIndices [ i + 1 ] ;
204
- const point = validPoints [ startIndex ] ;
212
+ const point = validPoints [ startIndex ] ; // is this correct??? validPoints[i]????
213
+ const srcIndex = point . index ;
214
+ const numVertices = endIndex - startIndex ;
215
+
205
216
const trajectoryId = point . trajectoryId ;
206
- newProperties [ i ] = { trajectoryId, ...properties [ point . index ] }
217
+ newProperties [ i ] = { trajectoryId, ...properties [ srcIndex ] }
207
218
208
219
for ( let j = startIndex ; j < endIndex ; j ++ ) {
209
220
newFeatureIds [ j ] = i ; // Each vertex is marked with featureId of the line
210
221
}
222
+
223
+ for ( const prop of numericPropKeys ) {
224
+ const { value : originalValue } = originalGeometry . numericProps [ prop ] ;
225
+ const { value, size} = newNumericProps [ prop ] ;
226
+ const dataSlice = originalValue . subarray ( srcIndex * size , ( srcIndex + numVertices ) * size )
227
+ value . set ( dataSlice , dst * size ) ;
228
+ }
229
+ dst += numVertices ;
211
230
}
212
231
213
232
return {
214
233
positions : { value : newPositions , size} ,
215
234
properties : newProperties ,
216
- numericProps : { } , // TODO add numericProps
235
+ numericProps : newNumericProps ,
217
236
featureIds : { value : newFeatureIds , size : 1 } ,
218
237
globalFeatureIds : { value : newFeatureIds , size : 1 } ,
219
238
pathIndices : { value : new Uint16Array ( pathIndices ) , size : 1 } ,
0 commit comments