@@ -5,28 +5,38 @@ import {
5
5
LayerContext ,
6
6
GetPickingInfoParams ,
7
7
} from "deck.gl" ;
8
+ import type { CompositeLayerProps , UpdateParameters } from "deck.gl" ;
8
9
import type { BitmapLayerPickingInfo } from "@deck.gl/layers" ;
9
10
import type { Texture } from "@luma.gl/core" ;
10
11
11
12
import { NumericDataPaintLayer } from "../NumericDataPaintLayer" ;
12
13
import type { NumericDataLayerProps , NumericDataPickingInfo } from "./types" ;
13
14
15
+ const textureDefaultOption = {
16
+ format : "r32float" as const ,
17
+ dimension : "2d" as const ,
18
+ } ;
19
+
20
+ const textureSamplerDefaultOption = {
21
+ minFilter : "linear" as const ,
22
+ magFilter : "linear" as const ,
23
+ mipmapFilter : "linear" as const ,
24
+ addressModeU : "clamp-to-edge" as const ,
25
+ addressModeV : "clamp-to-edge" as const ,
26
+ } ;
27
+
14
28
export default class NumericDataLayer extends CompositeLayer < NumericDataLayerProps > {
15
29
static layerName : string = "numeric-data-layer" ;
16
30
17
31
initializeState ( context : LayerContext ) : void {
18
32
const { tileSize, textureParameters } = this . props ;
19
33
const dataTexture = context . device . createTexture ( {
20
34
data : this . props . imageData ,
21
- format : "r32float" ,
22
35
width : tileSize ,
23
36
height : tileSize ,
37
+ ...textureDefaultOption ,
24
38
sampler : {
25
- minFilter : "linear" ,
26
- magFilter : "linear" ,
27
- mipmapFilter : "linear" ,
28
- addressModeU : "clamp-to-edge" ,
29
- addressModeV : "clamp-to-edge" ,
39
+ ...textureSamplerDefaultOption ,
30
40
...textureParameters ,
31
41
} ,
32
42
} ) ;
@@ -35,6 +45,32 @@ export default class NumericDataLayer extends CompositeLayer<NumericDataLayerPro
35
45
} ) ;
36
46
}
37
47
48
+ updateState (
49
+ params : UpdateParameters <
50
+ Layer < NumericDataLayerProps & Required < CompositeLayerProps > >
51
+ >
52
+ ) : void {
53
+ const { props, oldProps, context } = params ;
54
+ const { imageData } = props ;
55
+ const { imageData : oldImageData } = oldProps ;
56
+ if ( imageData !== oldImageData ) {
57
+ const { tileSize, textureParameters } = props ;
58
+ const dataTexture = context . device . createTexture ( {
59
+ data : imageData ,
60
+ width : tileSize ,
61
+ height : tileSize ,
62
+ ...textureDefaultOption ,
63
+ sampler : {
64
+ ...textureSamplerDefaultOption ,
65
+ ...textureParameters ,
66
+ } ,
67
+ } ) ;
68
+ this . setState ( {
69
+ dataTexture,
70
+ } ) ;
71
+ }
72
+ }
73
+
38
74
getPickingInfo ( parmas : GetPickingInfoParams ) : NumericDataPickingInfo {
39
75
const info = parmas . info as BitmapLayerPickingInfo ;
40
76
if ( info . bitmap ) {
0 commit comments