@@ -2,13 +2,8 @@ import type { LayerProps, PickingInfo } from "@deck.gl/core";
2
2
import { project32 } from "@deck.gl/core" ;
3
3
import type { BitmapLayerPickingInfo , BitmapLayerProps } from "@deck.gl/layers" ;
4
4
import { BitmapLayer } from "@deck.gl/layers" ;
5
-
6
- import type { ShaderModule } from "@luma.gl/shadertools" ;
7
- import type { Model } from "@luma.gl/engine" ;
8
-
9
- import type { colorTablesArray } from "@emerson-eps/color-tables/" ;
10
- import { getRgbData } from "@emerson-eps/color-tables" ;
11
-
5
+ import type { Color , LayerProps , PickingInfo } from "@deck.gl/core" ;
6
+ import { project32 } from "@deck.gl/core" ;
12
7
import type {
13
8
ColorMapFunctionType ,
14
9
LayerPickInfo ,
@@ -20,16 +15,17 @@ import { decodeRGB, type ValueDecoder } from "../utils/propertyMapTools";
20
15
import fsColormap from "./colormap.fs.glsl" ;
21
16
import type { DeckGLLayerContext } from "../../components/Map" ;
22
17
import type { ContinuousLegendDataType } from "../../components/ColorLegend" ;
18
+ import type { ShaderModule } from "@luma.gl/shadertools" ;
19
+ import type { Model } from "@luma.gl/engine" ;
20
+ import type { Texture } from "@luma.gl/core" ;
23
21
24
22
function getImageData (
25
23
colorMapName : string ,
26
24
colorTables : colorTablesArray ,
27
25
colorMapFunction ?: ColorMapFunctionType
28
26
) {
29
27
const isColorMapFunctionDefined = typeof colorMapFunction !== "undefined" ;
30
-
31
28
const data = new Uint8Array ( 256 * 3 ) ;
32
-
33
29
for ( let i = 0 ; i < 256 ; i ++ ) {
34
30
const value = i / 255.0 ;
35
31
const rgb = isColorMapFunctionDefined
@@ -93,6 +89,25 @@ export interface ColormapLayerProps
93
89
// Rotates image around bounds upper left corner counterclockwise in degrees.
94
90
rotDeg : number ;
95
91
92
+ // If true, draw contour lines. Default false.
93
+ contours : boolean ;
94
+
95
+ // If true, apply hillshading. Default false.
96
+ hillshading : boolean ;
97
+
98
+ // Contour reference height. Default 0.
99
+ contourReferencePoint : number ;
100
+
101
+ // Height between contour lines. Default 50.
102
+ contourInterval : number ;
103
+
104
+ /** Clamp colormap to this color at ends.
105
+ * Given as array of three values (r,g,b) e.g: [255, 0, 0]
106
+ * If not set or set to true, it will clamp to color map min and max values.
107
+ * If set to false the clamp color will be completely transparent.
108
+ */
109
+ colorMapClampColor : Color | undefined | boolean ;
110
+
96
111
// Non public properties:
97
112
reportBoundingBox ?: React . Dispatch < ReportBoundingBoxAction > ;
98
113
}
@@ -114,13 +129,13 @@ const defaultProps = {
114
129
} ,
115
130
rotDeg : 0 ,
116
131
colorMapName : "Rainbow" ,
132
+ contours : false ,
133
+ hillshading : false ,
134
+ contourReferencePoint : 0 ,
135
+ contourInterval : 50 , // 50 meter by default
117
136
} ;
118
137
119
138
export default class ColormapLayer extends BitmapLayer < ColormapLayerProps > {
120
- initializeState ( ) : void {
121
- super . initializeState ( ) ;
122
- }
123
-
124
139
setShaderModuleProps (
125
140
...props : Parameters < Model [ "shaderInputs" ] [ "setProps" ] >
126
141
) : void {
@@ -161,7 +176,7 @@ export default class ColormapLayer extends BitmapLayer<ColormapLayerProps> {
161
176
const valueRangeMin = this . props . valueRange [ 0 ] ?? 0.0 ;
162
177
const valueRangeMax = this . props . valueRange [ 1 ] ?? 1.0 ;
163
178
164
- // If specified color map will extend from colorMapRangeMin to colorMapRangeMax.
179
+ // If specified, color map will extend from colorMapRangeMin to colorMapRangeMax.
165
180
// Otherwise it will extend from valueRangeMin to valueRangeMax.
166
181
const colorMapRangeMin = this . props . colorMapRange ?. [ 0 ] ?? valueRangeMin ;
167
182
const colorMapRangeMax = this . props . colorMapRange ?. [ 1 ] ?? valueRangeMax ;
@@ -179,13 +194,48 @@ export default class ColormapLayer extends BitmapLayer<ColormapLayerProps> {
179
194
180
195
this . state . model ?. setBindings ( { colormap } ) ;
181
196
197
+ const bitmapResolution = this . props . image
198
+ ? [
199
+ ( this . props . image as Texture ) . width ,
200
+ ( this . props . image as Texture ) . height ,
201
+ ]
202
+ : [ 1 , 1 ] ;
203
+
204
+ const contours = this . props . contours ;
205
+ const hillshading = this . props . hillshading ;
206
+
207
+ const contourReferencePoint = this . props . contourReferencePoint ;
208
+ const contourInterval = this . props . contourInterval ;
209
+
210
+ const isClampColor : boolean =
211
+ this . props . colorMapClampColor !== undefined &&
212
+ this . props . colorMapClampColor !== true &&
213
+ this . props . colorMapClampColor !== false ;
214
+ let colorMapClampColor = isClampColor
215
+ ? this . props . colorMapClampColor
216
+ : [ 0 , 0 , 0 ] ;
217
+
218
+ colorMapClampColor = ( colorMapClampColor as Color ) . map (
219
+ ( x ) => ( x ?? 0 ) / 255
220
+ ) ;
221
+
222
+ const isColorMapClampColorTransparent : boolean =
223
+ ( this . props . colorMapClampColor as boolean ) === false ;
224
+
182
225
super . setShaderModuleProps ( {
183
226
map : {
184
227
valueRangeMin,
185
228
valueRangeMax,
186
229
colorMapRangeMin,
187
230
colorMapRangeMax,
188
-
231
+ contours,
232
+ hillshading,
233
+ bitmapResolution,
234
+ contourReferencePoint,
235
+ contourInterval,
236
+ isClampColor,
237
+ colorMapClampColor,
238
+ isColorMapClampColorTransparent,
189
239
rgbScaler : this . props . valueDecoder . rgbScaler ,
190
240
floatScaler : this . props . valueDecoder . floatScaler ,
191
241
offset : this . props . valueDecoder . offset ,
@@ -220,6 +270,10 @@ export default class ColormapLayer extends BitmapLayer<ColormapLayerProps> {
220
270
// We just need to decode that RGB color into a property float value.
221
271
const val = decodeRGB ( info . color , mergedDecoder , this . props . valueRange ) ;
222
272
273
+ if ( info . coordinate ) {
274
+ info . coordinate [ 2 ] = NaN ; // disable z value in 2D map;
275
+ }
276
+
223
277
return {
224
278
...info ,
225
279
// Picking color doesn't represent object index in this layer.
@@ -258,7 +312,14 @@ uniform mapUniforms {
258
312
float valueRangeMax;
259
313
float colorMapRangeMin;
260
314
float colorMapRangeMax;
261
-
315
+ vec2 bitmapResolution;
316
+ bool contours;
317
+ bool hillshading;
318
+ float contourReferencePoint;
319
+ float contourInterval;
320
+ bool isClampColor;
321
+ vec3 colorMapClampColor;
322
+ bool isColorMapClampColorTransparent;
262
323
vec3 rgbScaler; // r, g and b multipliers
263
324
float floatScaler; // value multiplier
264
325
float offset; // translation of the r, g, b sum
@@ -274,13 +335,7 @@ float decode_rgb2float(vec3 rgb) {
274
335
value = floor(value / map.step + 0.5) * map.step;
275
336
}
276
337
277
- // If colorMapRangeMin/Max specified, color map will span this interval.
278
- float x = value * (map.valueRangeMax - map.valueRangeMin) + map.valueRangeMin;
279
- x = (x - map.colorMapRangeMin) / (map.colorMapRangeMax - map.colorMapRangeMin);
280
- x = max(0.0, x);
281
- x = min(1.0, x);
282
-
283
- return x;
338
+ return value;
284
339
}
285
340
` ;
286
341
@@ -289,7 +344,14 @@ type Map2DUniformsType = {
289
344
valueRangeMax : number ;
290
345
colorMapRangeMin : number ;
291
346
colorMapRangeMax : number ;
292
-
347
+ bitmapResolution : [ number , number ] ;
348
+ contours : boolean ;
349
+ hillshading : boolean ;
350
+ contourReferencePoint : number ;
351
+ contourInterval : number ;
352
+ isClampColor : boolean ;
353
+ colorMapClampColor : [ number , number , number ] ;
354
+ isColorMapClampColorTransparent : boolean ;
293
355
rgbScaler : [ number , number , number ] ;
294
356
floatScaler : number ;
295
357
offset : number ;
@@ -306,7 +368,14 @@ const map2DUniforms = {
306
368
valueRangeMax : "f32" ,
307
369
colorMapRangeMin : "f32" ,
308
370
colorMapRangeMax : "f32" ,
309
-
371
+ bitmapResolution : "vec2<f32>" ,
372
+ contours : "u32" ,
373
+ hillshading : "u32" ,
374
+ contourReferencePoint : "f32" ,
375
+ contourInterval : "f32" ,
376
+ isClampColor : "u32" ,
377
+ colorMapClampColor : "vec3<f32>" ,
378
+ isColorMapClampColorTransparent : "u32" ,
310
379
rgbScaler : "vec3<f32>" ,
311
380
floatScaler : "f32" ,
312
381
offset : "f32" ,
0 commit comments