1
- import type { CompositeLayerProps } from "@deck.gl/core/lib/composite-layer" ;
2
- import { CompositeLayer , type PickInfo , SolidPolygonLayer , TextLayer } from "deck.gl" ;
1
+ import { CompositeLayer , SolidPolygonLayer , TextLayer } from "deck.gl" ;
3
2
import pMap from "p-map" ;
4
3
5
- import type { SolidPolygonLayerProps , TextLayerProps } from "@deck.gl/layers" ;
6
4
import { ColorPaletteExtension , XRLayer } from "@hms-dbmi/viv" ;
7
5
import type { SupportedTypedArray } from "@vivjs/types" ;
6
+ import type { CompositeLayerProps , PickingInfo , SolidPolygonLayerProps , TextLayerProps } from "deck.gl" ;
8
7
import type { ZarrPixelSource } from "../ZarrPixelSource" ;
9
8
import type { BaseLayerProps } from "../state" ;
10
9
import { assert } from "../utils" ;
@@ -19,7 +18,7 @@ export interface GridLoader {
19
18
type Polygon = Array < [ number , number ] > ;
20
19
21
20
export interface GridLayerProps
22
- extends Omit < CompositeLayerProps < unknown > , "modelMatrix" | "opacity" | "onClick" | "id" > ,
21
+ extends Omit < CompositeLayerProps , "modelMatrix" | "opacity" | "onClick" | "id" | "loaders "> ,
23
22
BaseLayerProps {
24
23
loaders : GridLoader [ ] ;
25
24
rows : number ;
@@ -86,9 +85,15 @@ function refreshGridData(props: GridLayerProps) {
86
85
return pMap ( loaders , mapper , { concurrency } ) ;
87
86
}
88
87
89
- export default class GridLayer extends CompositeLayer < unknown , CompositeLayerProps < unknown > & GridLayerProps > {
88
+ type SharedLayerState = {
89
+ gridData : Awaited < ReturnType < typeof refreshGridData > > ;
90
+ width : number ;
91
+ height : number ;
92
+ } ;
93
+
94
+ export default class GridLayer extends CompositeLayer < GridLayerProps > {
90
95
initializeState ( ) {
91
- this . state = { gridData : [ ] , width : 0 , height : 0 } ;
96
+ this . # state = { gridData : [ ] , width : 0 , height : 0 } ;
92
97
refreshGridData ( this . props ) . then ( ( gridData ) => {
93
98
const { width, height } = validateWidthHeight ( gridData ) ;
94
99
this . setState ( { gridData, width, height } ) ;
@@ -117,29 +122,35 @@ export default class GridLayer extends CompositeLayer<unknown, CompositeLayerPro
117
122
}
118
123
}
119
124
120
- getPickingInfo ( { info } : { info : PickInfo < unknown > } ) {
125
+ get #state( ) : SharedLayerState {
126
+ // @ts -expect-error - type safe access to state
127
+ return this . state ;
128
+ }
129
+
130
+ set #state( value : SharedLayerState ) {
131
+ this . state = value ;
132
+ }
133
+
134
+ getPickingInfo ( { info } : { info : PickingInfo < unknown > } ) {
121
135
// provide Grid row and column info for mouse events (hover & click)
122
136
if ( ! info . coordinate ) {
123
137
return info ;
124
138
}
125
139
const spacer = this . props . spacer || 0 ;
126
- const { width, height } = this . state ;
140
+ const { width, height } = this . # state;
127
141
const [ x , y ] = info . coordinate ;
128
142
const row = Math . floor ( y / ( height + spacer ) ) ;
129
143
const column = Math . floor ( x / ( width + spacer ) ) ;
130
- return {
131
- ...info ,
132
- gridCoord : { row, column } ,
133
- } ;
144
+ return { ...info , gridCoord : { row, column } } ;
134
145
}
135
146
136
147
renderLayers ( ) {
137
- const { gridData, width, height } = this . state ;
148
+ const { gridData, width, height } = this . # state;
138
149
if ( width === 0 || height === 0 ) return null ; // early return if no data
139
150
140
151
const { rows, columns, spacer = 0 , id = "" } = this . props ;
141
152
type Data = { row : number ; col : number ; loader : Pick < ZarrPixelSource , "dtype" > ; data : Array < SupportedTypedArray > } ;
142
- const layers = gridData . map ( ( d : Data ) => {
153
+ const layers = gridData . map ( ( d ) => {
143
154
const y = d . row * ( height + spacer ) ;
144
155
const x = d . col * ( width + spacer ) ;
145
156
const layerProps = {
@@ -172,7 +183,6 @@ export default class GridLayer extends CompositeLayer<unknown, CompositeLayerPro
172
183
pickable : true , // enable picking
173
184
id : `${ id } -GridLayer-picking` ,
174
185
} satisfies SolidPolygonLayerProps < Data > ;
175
- // @ts -expect-error - SolidPolygonLayer props are not well typed
176
186
const layer = new SolidPolygonLayer < Data , SolidPolygonLayerProps < Data > > ( { ...this . props , ...layerProps } ) ;
177
187
layers . push ( layer ) ;
178
188
}
0 commit comments