I am having issue with colors of the polygons. So i display polygones/areas in the map and i set for each color depending of their properties:
map.setPaintProperty("layerName", "fill-color", [
"interpolate",
["linear"],
["get", key],
range[0], colors[0],
range[1], colors[1],
range[2], colors[2],
]);
But some of these polygons just do not have the "key" property in them hence the map reads them like undefined/nullish and sets default color to them a pure black. I need to change this black color to something else but cant figure it out.
I tried to add default color after the ranges but it didnt work . Also tried if i could do it via styling/css but its a canvas so seems that this is not an option.
map.setPaintProperty("layerName", "fill-color", [
"interpolate",
["linear"],
["get", key],
range[0], colors[0],
range[1], colors[1],
range[2], colors[2],
defaultColor
]);
This solution worked for me :
//This will put color of white for the missing property
map.setPaintProperty(
'layerName',
'fill-color',
["case", ["==", ["get", key], null], "#ffffff", [
"interpolate",
["linear"],
["get", key],
range[0], colors[0],
range[1], colors[1],
range[2], colors[2],
]]
);
This works also for opacity:
map.setPaintProperty(
'layerName',
'fill-opacity',
["case", ["==", ["get", key], null], 0.1, 0.7]
);