Hello everyone,
I'm facing an issue while trying to apply a UniqueValueRenderer on a 3D FeatureLayer in a SceneView. My goal is to change the color of the features based on an alert field coming from a CSV file. I have managed to get it working perfectly in 2D (MapView), but when switching to 3D, all the features appear with the same color, instead of applying unique colors based on the alert values.
Here’s the relevant code:
// Function to update the layer's symbology
function updateLayerSymbology(data) {
const uniqueValues = data.map(function(element) {
return {
value: element.id, // id from the CSV related to the layer
symbol: {
type: "polygon-3d", // 3D symbol for polygons
symbolLayers: [{
type: "fill",
material: {
color: getColorBasedOnAlert(element.alerta) // Color based on the alert value
},
outline: { color: "black" }
}]
}
};
});
const renderer = {
type: "unique-value",
field: "comarca_sg", // Field in the layer corresponding to the id from the CSV
uniqueValueInfos: uniqueValues,
defaultSymbol: { // Default symbol
type: "polygon-3d",
symbolLayers: [{
type: "fill",
material: { color: "gray" },
outline: { color: "black" }
}]
}
};
featureLayer.renderer = renderer;
}
// Function to get the color based on the alert value
function getColorBasedOnAlert(alerta) {
alerta = alerta.trim();
if (alerta === "A5") return "#d73027"; // Dark red
else if (alerta === "A4") return "#fc8d59"; // Light red
else if (alerta === "A3") return "#fee08b"; // Yellow
else if (alerta === "A2") return "#d9ef8b"; // Yellow-green
else if (alerta === "A1") return "#91cf60"; // Light green
else if (alerta === "A0" || alerta === "NO ALERTA") return "#1a9850"; // Dark green
else return "#1a9850"; // Default green
}
I would appreciate any advice or suggestions on how to solve this problem. Thanks in advance!