deck.gl
deck.gl copied to clipboard
How setColorValues
Hi, I'm working with HexagonLayer and I'm working with getColorValue function to set colors depending on certain criteria.
First, shows me perfectly but when I move mouse on map goes crazy as you can see in image
.
why is it happening?
How can solve it??
If you could help me I would appreciate it. Here you can find full code.
new HexagonLayer({
id: `hexagon-layer-${uuidv4()}`,
data: this.getCoordinates(),
pickable: true,
extruded: true,
radius: 5,
elevationRange: [0, 50],
elevationScale: 1,
colorRange: ALARM_COLORS,
colorDomain: [1, 3],
getPosition: d => d.COORDINATES,
getColorValue: d => this.elevationColor(d),
getElevationValue: d => this.elevationByLogScale(d),
onClick: this.handleHexagonClick,
})
elevationColor = values => {
let alarms = values.map(supplypoint => supplypoint.ALARMS).slice();
let hasActiveAlarms = alarms.filter( alarm => alarm.active);
if (hasActiveAlarms.length > 0) {
return 2;
}
let dates = alarms.map(alarm => alarm.date);
if (existAlarmGenerated15DaysAgo(dates)) {
return 3;
}
return 1;
};
sumElevations = values => {
if (values.length >= 1) {
let totalVolumes = 0;
for (let item of values) {
if (item.hasOwnProperty("VOLUME")) {
totalVolumes += item.VOLUME;
}
}
return totalVolumes;
}
return 0;
};
elevationByLogScale = values => {
let totalVolumes = this.sumElevations(values);
let scale = parseInt(this.logScale(totalVolumes));
if (isNaN(scale)) return 0;
return scale;
};
Already solved. It is because the getCoordinates function that generates the data for the layer is in the render with the layer, so every time the mouse is moved it renders and since the data is mocked and generated randomly, that is why it changes color, the ones that have only 1 supply point.
Sorry and thanks for your help and patience