Skip to content

Commit

Permalink
feat: allow custom valueToColor4 via constructor
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Santamaria <chris@santamaria.me>
  • Loading branch information
chrissantamaria committed Oct 26, 2022
1 parent 4eb77bd commit 5ed45ba
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,8 @@ class MapboxInterpolateHeatmapLayer implements HeatmapLayer {
opacity = 0.5;
p = 3;
aoi?: { lat: number; lon: number }[] = [];
valueToColor?: string = `
vec3 valueToColor(float value) {
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));
}
`;
valueToColor4?: string = `
vec4 valueToColor4(float value, float defaultOpacity) {
return vec4(valueToColor(value), defaultOpacity);
}
`;
valueToColor?: string;
valueToColor4?: string;
textureCoverSameAreaAsROI: boolean;
points: number[][] = [];
// Custom Props
Expand Down Expand Up @@ -74,6 +66,13 @@ class MapboxInterpolateHeatmapLayer implements HeatmapLayer {
vec3 valueToColor(float value) {
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));
}
`;
this.valueToColor4 =
options.valueToColor4 ||
`
vec4 valueToColor4(float value, float defaultOpacity) {
return vec4(valueToColor(value), defaultOpacity);
}
`;
this.opacity = options.opacity || 0.5;
this.minValue = options.minValue || Infinity;
Expand Down

0 comments on commit 5ed45ba

Please # to comment.