@@ -30,7 +30,11 @@ import {
3030 validatePolygonType ,
3131 validateVectorAccessors ,
3232} from "./utils.js" ;
33- import { MultiPolygonVector , PolygonVector } from "./types.js" ;
33+ import {
34+ GeoArrowPickingInfo ,
35+ MultiPolygonVector ,
36+ PolygonVector ,
37+ } from "./types.js" ;
3438import { EXTENSION_NAME } from "./constants.js" ;
3539
3640const DEFAULT_COLOR : [ number , number , number , number ] = [ 0 , 0 , 0 , 255 ] ;
@@ -142,7 +146,10 @@ export class GeoArrowSolidPolygonLayer<
142146 static defaultProps = defaultProps ;
143147 static layerName = "GeoArrowSolidPolygonLayer" ;
144148
145- getPickingInfo ( { info, sourceLayer } : GetPickingInfoParams ) : PickingInfo {
149+ getPickingInfo ( {
150+ info,
151+ sourceLayer,
152+ } : GetPickingInfoParams ) : GeoArrowPickingInfo {
146153 const { data : table } = this . props ;
147154
148155 // Geometry index as rendered
@@ -166,11 +173,13 @@ export class GeoArrowSolidPolygonLayer<
166173 const offsets : number [ ] = table . _offsets ;
167174 const currentBatchOffset = offsets [ recordBatchIdx ] ;
168175
169- info . object = row ;
170176 // Update index to be _global_ index, not within the specific record batch
171177 index += currentBatchOffset ;
172- info . index = index ;
173- return info ;
178+ return {
179+ ...info ,
180+ index,
181+ object : row ,
182+ } ;
174183 }
175184
176185 renderLayers ( ) : Layer < { } > | LayersList | null {
@@ -390,10 +399,19 @@ export class GeoArrowSolidPolygonLayer<
390399 startIndices : resolvedPolygonToCoordOffsets ,
391400 attributes : {
392401 getPolygon : { value : flatCoordinateArray , size : nDim } ,
402+ instancePickingColors : {
403+ value : encodePickingColors (
404+ resolvedMultiPolygonToCoordOffsets ,
405+ this . encodePickingColor
406+ ) ,
407+ size : 3 ,
408+ } ,
393409 } ,
394410 } ,
395411 } ;
396412
413+ console . log ( resolvedMultiPolygonToCoordOffsets ) ;
414+
397415 assignAccessor ( {
398416 props,
399417 propName : "getElevation" ,
@@ -423,3 +441,29 @@ export class GeoArrowSolidPolygonLayer<
423441 return layers ;
424442 }
425443}
444+
445+ function encodePickingColors (
446+ geomToCoordOffsets : Int32Array ,
447+ encodePickingColor : ( id : number , result : number [ ] ) => void
448+ ) : Uint8ClampedArray {
449+ const largestOffset = geomToCoordOffsets [ geomToCoordOffsets . length - 1 ] ;
450+ const pickingColors = new Uint8ClampedArray ( largestOffset ) ;
451+
452+ const pickingColor = [ ] ;
453+ for ( let arrayIdx = 0 ; arrayIdx < geomToCoordOffsets . length - 1 ; arrayIdx ++ ) {
454+ const thisOffset = geomToCoordOffsets [ arrayIdx ] ;
455+ const nextOffset = geomToCoordOffsets [ arrayIdx + 1 ] ;
456+
457+ // Note: we encode the picking color once per _feature_, but then assign it
458+ // to the color array once per _vertex_
459+ encodePickingColor ( arrayIdx , pickingColor ) ;
460+ for ( let offset = thisOffset ; offset < nextOffset ; offset ++ ) {
461+ pickingColors [ offset * 3 ] = pickingColor [ 0 ] ;
462+ pickingColors [ offset * 3 + 1 ] = pickingColor [ 1 ] ;
463+ pickingColors [ offset * 3 + 2 ] = pickingColor [ 2 ] ;
464+ }
465+ }
466+
467+ console . log ( pickingColors ) ;
468+ return pickingColors ;
469+ }
0 commit comments