@@ -2,33 +2,40 @@ import * as arrow from "apache-arrow";
22import { GetPickingInfoParams } from "@deck.gl/core/typed" ;
33import { GeoArrowPickingInfo } from "./types" ;
44
5+ export interface GeoArrowExtraPickingProps {
6+ recordBatchIdx : number ;
7+ tableOffsets : Uint32Array ;
8+ invertedGeomOffsets ?: Uint8Array | Uint16Array | Uint32Array ;
9+ }
10+
511export function getPickingInfo (
6- { info, sourceLayer } : GetPickingInfoParams ,
12+ {
13+ info,
14+ sourceLayer,
15+ } : GetPickingInfoParams & {
16+ sourceLayer : { props : GeoArrowExtraPickingProps } ;
17+ } ,
718 table : arrow . Table ,
819) : GeoArrowPickingInfo {
920 // Geometry index as rendered
1021 let index = info . index ;
1122
12- // if a MultiPoint dataset, map from the rendered index back to the feature
13- // index
14- // @ts -expect-error `invertedGeomOffsets` is manually set on layer props
23+ // if a Multi- geometry dataset, map from the rendered index back to the
24+ // feature index
1525 if ( sourceLayer . props . invertedGeomOffsets ) {
16- // @ts -expect-error `invertedGeomOffsets` is manually set on layer props
1726 index = sourceLayer . props . invertedGeomOffsets [ index ] ;
1827 }
1928
20- // @ts -expect-error `recordBatchIdx` is manually set on layer props
21- const recordBatchIdx : number = sourceLayer . props . recordBatchIdx ;
29+ const recordBatchIdx = sourceLayer . props . recordBatchIdx ;
30+ const tableOffsets = sourceLayer . props . tableOffsets ;
31+
2232 const batch = table . batches [ recordBatchIdx ] ;
2333 const row = batch . get ( index ) ;
2434 if ( row === null ) {
2535 return info ;
2636 }
2737
28- // @ts -expect-error hack: using private method to avoid recomputing via
29- // batch lengths on each iteration
30- const offsets : number [ ] = table . _offsets ;
31- const currentBatchOffset = offsets [ recordBatchIdx ] ;
38+ const currentBatchOffset = tableOffsets [ recordBatchIdx ] ;
3239
3340 // Update index to be _global_ index, not within the specific record batch
3441 index += currentBatchOffset ;
@@ -38,3 +45,16 @@ export function getPickingInfo(
3845 object : row ,
3946 } ;
4047}
48+
49+ // This is vendored from Arrow JS because it's a private API
50+ export function computeChunkOffsets < T extends arrow . DataType > (
51+ chunks : ReadonlyArray < arrow . Data < T > > ,
52+ ) {
53+ return chunks . reduce (
54+ ( offsets , chunk , index ) => {
55+ offsets [ index + 1 ] = offsets [ index ] + chunk . length ;
56+ return offsets ;
57+ } ,
58+ new Uint32Array ( chunks . length + 1 ) ,
59+ ) ;
60+ }
0 commit comments