use serde_json::{Map, Value};
use crate::maplibre::const_number;
use crate::maplibre::layers::paint_of;
use crate::maplibre::Report;
pub(crate) fn convert_hillshade(
id: &str,
layer: &Map<String, Value>,
nodes: &mut Map<String, Value>,
outputs: &mut Vec<String>,
report: &mut Report,
) {
let Some(src) = layer.get("source").and_then(Value::as_str) else {
report.warn(format!("layer `{id}`: hillshade without source — skipped"));
return;
};
let paint = paint_of(layer);
let azimuth = paint
.get("hillshade-illumination-direction")
.and_then(const_number)
.unwrap_or(335.0);
let exaggeration = paint
.get("hillshade-exaggeration")
.and_then(const_number)
.unwrap_or(0.5);
let dem_id = format!("{id}__dem");
let hs_id = format!("{id}__hillshade");
nodes.insert(
dem_id.clone(),
serde_json::json!({ "op": "dem", "source": src }),
);
nodes.insert(
hs_id.clone(),
serde_json::json!({
"op": "hillshade",
"field": format!("@{dem_id}"),
"azimuth-deg": azimuth,
"altitude-deg": 45,
"exaggeration": exaggeration,
"mode": "relief"
}),
);
outputs.push(hs_id);
}