Skip to content

Commit 5ed45ba

Browse files
feat: allow custom valueToColor4 via constructor
Signed-off-by: Chris Santamaria <chris@santamaria.me>
1 parent 4eb77bd commit 5ed45ba

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/layer.ts

+9-10
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,8 @@ class MapboxInterpolateHeatmapLayer implements HeatmapLayer {
2525
opacity = 0.5;
2626
p = 3;
2727
aoi?: { lat: number; lon: number }[] = [];
28-
valueToColor?: string = `
29-
vec3 valueToColor(float value) {
30-
return vec3(max((value-0.5)*2.0, 0.0), 1.0 - 2.0*abs(value - 0.5), max((0.5-value)*2.0, 0.0));
31-
}
32-
`;
33-
valueToColor4?: string = `
34-
vec4 valueToColor4(float value, float defaultOpacity) {
35-
return vec4(valueToColor(value), defaultOpacity);
36-
}
37-
`;
28+
valueToColor?: string;
29+
valueToColor4?: string;
3830
textureCoverSameAreaAsROI: boolean;
3931
points: number[][] = [];
4032
// Custom Props
@@ -74,6 +66,13 @@ class MapboxInterpolateHeatmapLayer implements HeatmapLayer {
7466
vec3 valueToColor(float value) {
7567
return vec3(max((value-0.5)*2.0, 0.0), 1.0 - 2.0*abs(value - 0.5), max((0.5-value)*2.0, 0.0));
7668
}
69+
`;
70+
this.valueToColor4 =
71+
options.valueToColor4 ||
72+
`
73+
vec4 valueToColor4(float value, float defaultOpacity) {
74+
return vec4(valueToColor(value), defaultOpacity);
75+
}
7776
`;
7877
this.opacity = options.opacity || 0.5;
7978
this.minValue = options.minValue || Infinity;

0 commit comments

Comments
 (0)