Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

[fix] heatmap renders nothing with black color or duplicate color (#2978)

Igor Dykhtaf8fbf2461fe8
diff --git a/src/layers/src/heatmap-layer/heatmap-layer.ts b/src/layers/src/heatmap-layer/heatmap-layer.ts
index ad76bc733..038e4ae47 100644
--- a/src/layers/src/heatmap-layer/heatmap-layer.ts
+++ b/src/layers/src/heatmap-layer/heatmap-layer.ts
@@ -2,7 +2,7 @@
// Copyright contributors to the kepler.gl project
import {createSelector} from 'reselect';
-import {CHANNEL_SCALES, SCALE_FUNC, ALL_FIELD_TYPES} from '@kepler.gl/constants';
+import {CHANNEL_SCALES, ALL_FIELD_TYPES} from '@kepler.gl/constants';
import MapboxGLLayer, {MapboxLayerGLConfig} from '../mapboxgl-layer';
import HeatmapLayerIcon from './heatmap-layer-icon';
import {LayerBaseConfigPartial, LayerWeightConfig, VisualChannels} from '../base-layer';
@@ -110,20 +110,14 @@ const DEFAULT_COLUMN_MODE = COLUMN_MODE_POINTS;
* ]
*/
const heatmapDensity = (colorRange: ColorRange): (string | number)[] => {
- const scaleFunction = SCALE_FUNC.quantize;
-
const colors: HexColor[] = ['#000000', ...colorRange.colors];
- const scale = scaleFunction<HexColor>().domain([0, 1]).range(colors);
+ const colorDensity: (string | number)[] = [];
+ colors.forEach((color, index) => {
+ colorDensity.push(index / colors.length);
+ colorDensity.push(`rgb(${hexToRgb(color).join(',')})`);
+ });
- const colorDensity = scale.range().reduce((bands: (string | number)[], level) => {
- const invert = scale.invertExtent(level);
- return [
- ...bands,
- invert[0], // first value in the range
- `rgb(${hexToRgb(level).join(',')})` // color
- ];
- }, []);
colorDensity[1] = 'rgba(0,0,0,0)';
return colorDensity;
};