From 3b78c59ffc52813a8cce34e48dc78e7c88a434e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 20 Nov 2026 14:00:13 -0500 Subject: [PATCH 1/4] feat(map): the blank basemap takes a paper colour, so a map frame sits on a coloured page (#2532) map.basemap {"name": "blank", "color": "#RRGGBB"} sets the colour a blank map draws where it drew white: the flat view, the GPU clear colour, a tilted view's sky and fog, layout map frames and their exports, and the shared web page. Without a colour, or with null or #FFFFFF, blank stays white. Another basemap takes the paper off; a colour given with it is a warning, not an error. - Map::paper, read through Map::blank_paper() (only on Blank, always opaque); a frame's coverage is still judged on white paper. - A new map and a publication's globe locator keep the paper with the basemap. - Saved projects and map files with a paper colour require "blank-paper"; schema, fixture and docs/maintaining.md updated. - Basemap gallery: a "Paper color" section on Blank, with the picker drawn in the menu itself. - Python set_basemap takes color; user guide updated. --- .../rustgis-python/python/rustgis/__init__.py | 7 +- crates/engine/src/cmd/layout.rs | 2 +- crates/engine/src/cmd/navigate.rs | 29 ++++++++- crates/engine/src/project.rs | 1 + crates/engine/src/project_capabilities.rs | 24 ++++++- crates/engine/src/tests.rs | 64 +++++++++++++++++++ crates/engine/tests/project_save_roundtrip.rs | 1 + crates/map/src/lib.rs | 17 ++++- crates/render/src/layout.rs | 11 ++++ crates/render/src/lib.rs | 29 ++++++++- crates/ui-egui/src/mapview.rs | 12 +++- crates/ui-egui/src/ribbon.rs | 22 +++++++ docs/maintaining.md | 3 +- docs/user-guide/maps.md | 6 +- schema/fixtures/blank_paper.rgis | 15 +++++ schema/project.schema.json | 6 +- 16 files changed, 235 insertions(+), 14 deletions(-) create mode 100644 schema/fixtures/blank_paper.rgis diff --git a/apps/rustgis-python/python/rustgis/__init__.py b/apps/rustgis-python/python/rustgis/__init__.py index e8a87ef357..d530c4e6d9 100644 --- a/apps/rustgis-python/python/rustgis/__init__.py +++ b/apps/rustgis-python/python/rustgis/__init__.py @@ -681,13 +681,16 @@ def bounds(self) -> Tuple[float, float, float, float]: """What the map shows, as ``(west, south, east, north)`` in degrees.""" return tuple(self.info()["extent"]) # type: ignore[return-value] - def set_basemap(self, name: str) -> Any: + def set_basemap(self, name: str, color: Optional[str] = None) -> Any: """Sets the map's basemap. Args: name: ``"paper"``, ``"midnight"``, ``"ocean"``, ``"atlas"`` or ``"blank"``. + color: The blank basemap's paper colour, ``"#RRGGBB"`` (left as it was when not given). """ - return self.run("map.basemap", name=name) + if color is None: + return self.run("map.basemap", name=name) + return self.run("map.basemap", name=name, color=color) def set_center( self, diff --git a/crates/engine/src/cmd/layout.rs b/crates/engine/src/cmd/layout.rs index f56b76b008..cb5aa7650e 100644 --- a/crates/engine/src/cmd/layout.rs +++ b/crates/engine/src/cmd/layout.rs @@ -1953,7 +1953,7 @@ fn publication(s: &mut Session, p: &Value) -> CmdResult { // Not its web tiles (fetched and drawn over the basemap on the disc), swipe, time // slider, layer groups (their hidden layers left out here), bookmarks or animation. let mut m = rustgis_map::Map::new(name); - m.basemap = src.basemap; + (m.basemap, m.paper) = (src.basemap, src.paper); m.graticule = src.graticule; m.body = src.body.clone(); m.set_projection(rustgis_map::Projection::Globe); diff --git a/crates/engine/src/cmd/navigate.rs b/crates/engine/src/cmd/navigate.rs index b7cb4967e2..6b732cb469 100644 --- a/crates/engine/src/cmd/navigate.rs +++ b/crates/engine/src/cmd/navigate.rs @@ -77,7 +77,7 @@ pub fn commands() -> Vec { .view() .params(r#"{"scale": number}"#), C::new("map.basemap", "Basemap", "Home › Add", basemap).roles(&[]).effects(crate::policy::Effects::NONE) - .params(r#"{"name": "paper"|"midnight"|"ocean"|"atlas"|"blank", "keepTiles"?: bool (keeps the web tile basemaps over it)}"#), + .params(r##"{"name": "paper"|"midnight"|"ocean"|"atlas"|"blank", "keepTiles"?: bool (keeps the web tile basemaps over it), "color"?: "#RRGGBB" (blank: the paper's colour, drawn where a blank map draws white, the tilted view's sky included; null or #FFFFFF: white; default: as it was. Another basemap takes the paper off and keeps its own colours; a color given with it is said as a warning)}"##), C::new("map.graticule", "Graticule", "View › Display", graticule).roles(&[]).effects(crate::policy::Effects::NONE) .params(r#"{"on"?: bool (toggles when omitted, on when a type or crs is given), "type"?: "degrees"|"measured"|"utm", "crs"?: a projected system for the measured grid (EPSG:2056, WKT or a PROJ string; "" or null: the map's own when projected, else the UTM zone at the view's centre)}"#), C::new("map.reloadWebLayers", "Reload Web Layers", "View › Display", |_, _| { @@ -924,12 +924,35 @@ fn graticule(s: &mut Session, p: &Value) -> CmdResult { fn basemap(s: &mut Session, p: &Value) -> CmdResult { let n = s_name(p)?; + let basemap = Basemap::from_code(n).ok_or_else(|| format!("unknown basemap '{n}'"))?; + // The blank basemap's paper (#2532): absent keeps it, null takes it off (white). + let paper = match p.get("color") { + None => None, + Some(Value::Null) => Some(None), + Some(Value::String(c)) => match c.trim().strip_prefix('#').filter(|h| h.len() == 6).and_then(rustgis_map::Rgba::from_hex) { + Some(rgba) => Some(Some(rgba)), + None => return Err(format!("color must be \"#RRGGBB\" (opaque), not '{c}'")), + }, + Some(_) => return Err("color must be \"#RRGGBB\" or null".into()), + }; let m = s.map_mut(); - m.basemap = Basemap::from_code(n).ok_or_else(|| format!("unknown basemap '{n}'"))?; + m.basemap = basemap; // A built-in basemap takes the place of the web basemaps (tile overlays stay). if !super::b(p, "keepTiles").unwrap_or(false) { m.tiles.retain(|t| t.overlay); } + if basemap != Basemap::Blank { + // Another basemap draws its own colours: the paper goes, not to be saved unseen. + m.paper = None; + if paper.is_some_and(|c| c.is_some()) { + let warning = format!("color is for the blank basemap only: {} keeps its own colours", basemap.label()); + s.warn(warning.clone()); + return Ok(json!({"warning": warning})); + } + } else if let Some(paper) = paper { + // White is the blank basemap's own paper: nothing to keep, or to require of a reader. + m.paper = paper.filter(|c| *c != rustgis_map::Rgba::rgb(0xFF, 0xFF, 0xFF)); + } Ok(Value::Null) } @@ -1180,7 +1203,7 @@ fn new_map(s: &mut Session, p: &Value) -> CmdResult { name = format!("{base}{i}"); } let mut m = Map::new(name.clone()); - m.basemap = s.map().basemap; + (m.basemap, m.paper) = (s.map().basemap, s.map().paper); s.project.maps.push(m); s.project.active_map = s.project.maps.len() - 1; s.active_layer = None; diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index cb1f6ff15a..58528abc19 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -95,6 +95,7 @@ pub const CAPABILITIES: &[&str] = &[ "offline-map-area-id", "crs-wkt", "zarr-window", + "blank-paper", ]; /// Independent marker sizes alongside classified point colours (`Layer::size_by`). pub(crate) const SIZE_BY_CAPABILITY: &str = "classified-point-size"; diff --git a/crates/engine/src/project_capabilities.rs b/crates/engine/src/project_capabilities.rs index 7c2803f248..c2277ed766 100644 --- a/crates/engine/src/project_capabilities.rs +++ b/crates/engine/src/project_capabilities.rs @@ -374,9 +374,11 @@ fn map_capabilities<'a>(maps: impl IntoIterator) -> Vec<&'static mut pictures, mut zarr, ) = (false, false, false, false, false, false, false, false, false, false, false); - let mut offline_area_id = false; + let (mut offline_area_id, mut paper) = (false, false); for map in maps { offline_area_id |= map.offline_area_id.is_some(); + // A blank basemap's paper colour (#2532), which an older reader would draw and save white. + paper |= map.paper.is_some(); if let Some(t) = &map.view.terrain { block |= t.block.is_some(); // A round block (#2318), which an older reader would draw and save as a box. @@ -409,6 +411,7 @@ fn map_capabilities<'a>(maps: impl IntoIterator) -> Vec<&'static (pictures, "picture-markers"), (zarr, "zarr-window"), (offline_area_id, "offline-map-area-id"), + (paper, "blank-paper"), ] .into_iter() .filter_map(|(used, name)| used.then_some(name)) @@ -1078,6 +1081,25 @@ mod tests { assert!(Project::from_json(&unknown.to_string()).unwrap_err().contains("future-zarr")); } + /// A blank basemap's paper colour (#2532) is required by name in a project and a map file: an + /// older reader would draw the paper white and save the colour away. White paper needs nothing. + #[test] + fn a_blank_paper_colour_is_required_where_it_is_saved() { + let mut p = Project::from_json(include_str!("../../../schema/fixtures/blank_paper.rgis")).unwrap(); + assert_eq!(p.map().blank_paper(), Some(rustgis_map::Rgba::rgb(241, 234, 223))); + let saved = serde_json::to_value(&p).unwrap(); + assert_eq!(saved["requires"], json!(["blank-paper"])); + assert_eq!(saved["maps"][0]["paper"], json!([241, 234, 223, 255])); + assert_eq!(json_bytes(&map_file_bytes(p.map()).unwrap())["requires"], saved["requires"]); + p.maps[0].paper = None; + let clean = serde_json::to_value(&p).unwrap(); + assert!(clean.get("requires").is_none()); + assert!(clean["maps"][0].get("paper").is_none()); + let mut unknown = saved; + unknown["requires"] = json!(["blank-paper", "future-paper"]); + assert!(Project::from_json(&unknown.to_string()).unwrap_err().contains("future-paper")); + } + /// Nondefault relief effects survive project, map and layer files; ordinary relief needs none. #[test] fn relief_headers_cover_each_effect_and_clean_controls() { diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index e7e6974a23..14dcf61eeb 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -15472,6 +15472,70 @@ fn the_globe_has_stars_that_turn_off() { assert!(corner(&mut s) == starry); } +/// A blank basemap's paper colour (#2532): kept until null or another basemap, opaque #RRGGBB only, +/// a warning (not an error) when given with another basemap, and drawn in a layout's map frame. +/// A publication's globe locator draws the map's blank paper (#2532), so the disc's backdrop is +/// the page's colour too. +#[test] +fn a_globe_locator_keeps_the_blank_paper() { + let mut s = world(); + s.run("map.basemap", &json!({"name": "blank", "color": "#F1EADF"})).unwrap(); + let r = s.run("layout.publication", &json!({"extent": [-46.8, -11.6, -38.5, -2.2]})).unwrap(); + let globe = r["locator"].as_str().unwrap().to_string(); + let m = s.project.maps.iter().find(|m| m.name == globe).unwrap(); + assert_eq!(m.blank_paper(), Some(rustgis_map::Rgba::rgb(0xF1, 0xEA, 0xDF))); +} + +#[test] +fn a_blank_basemap_takes_a_paper_colour() { + let cream = rustgis_map::Rgba::rgb(0xF1, 0xEA, 0xDF); + let mut s = Session::new(Project::default()); + s.map_mut().graticule = false; + assert_eq!(s.run("map.basemap", &json!({"name": "blank", "color": "#F1EADF"})).unwrap(), Value::Null); + assert_eq!(s.map().paper, Some(cream)); + assert_eq!(s.map().palette().0, cream); + s.run("map.basemap", &json!({"name": "blank"})).unwrap(); + assert_eq!(s.map().paper, Some(cream), "no color keeps it"); + for bad in [json!("#F1EADF80"), json!("F1EADF"), json!("#F1EA"), json!("cream"), json!(3)] { + let e = s.run("map.basemap", &json!({"name": "blank", "color": bad})).unwrap_err(); + assert!(e.contains("#RRGGBB"), "{e}"); + assert_eq!(s.map().paper, Some(cream), "a refused colour changes nothing"); + } + // A new map starts on the same basemap, its paper included. + let first = s.project.active_map; + s.run("map.new", &json!({"name": "Second"})).unwrap(); + assert_eq!((s.map().basemap, s.map().paper), (rustgis_map::Basemap::Blank, Some(cream))); + s.project.active_map = first; + // A layout's map frame on a cream page draws the cream paper, not a white box. + s.run("layout.new", &json!({"page": "a4", "orientation": "landscape", "template": "blank"})).unwrap(); + s.run("layout.addFrame", &json!({"x": 20, "y": 20, "w": 150, "h": 100})).unwrap(); + let dir = std::env::temp_dir().join(format!("rustgis-blank-paper-{}", std::process::id())); + std::fs::create_dir_all(&dir).unwrap(); + let path = dir.join("paper.png"); + s.run("layout.export", &json!({"path": path.display().to_string(), "dpi": 72})).unwrap(); + let pm = crate::render::decode_png(&std::fs::read(&path).unwrap()).unwrap(); + let _ = std::fs::remove_dir_all(&dir); + // 72 dpi: a point a pixel; 25 mm in from the page's corner lies inside the frame. + let inside = pm.pixel(71, 71).unwrap(); + assert_eq!((inside.red(), inside.green(), inside.blue()), (0xF1, 0xEA, 0xDF)); + s.run("map.basemap", &json!({"name": "blank", "color": "#ffffff"})).unwrap(); + assert_eq!(s.map().paper, None, "white is the blank basemap's own paper"); + s.run("map.basemap", &json!({"name": "blank", "color": "#F1EADF"})).unwrap(); + s.run("map.basemap", &json!({"name": "blank", "color": null})).unwrap(); + assert_eq!(s.map().paper, None, "null: white again"); + s.run("map.basemap", &json!({"name": "blank", "color": "#F1EADF"})).unwrap(); + // Another basemap: no error, a warning, and the paper goes. + let mark = s.notice_mark(); + let v = s.run("map.basemap", &json!({"name": "paper", "color": "#F1EADF"})).unwrap(); + assert!(v["warning"].as_str().is_some_and(|w| w.contains("blank basemap only")), "{v}"); + assert!(s.notices_since(mark).iter().any(|n| n.text.contains("blank basemap only"))); + assert_eq!(s.map().basemap, rustgis_map::Basemap::Paper); + assert_eq!(s.map().paper, None); + s.run("map.basemap", &json!({"name": "blank"})).unwrap(); + assert_eq!(s.map().palette().0, rustgis_map::Rgba::rgb(0xFF, 0xFF, 0xFF), "back on blank: white"); + assert_eq!(s.run("map.basemap", &json!({"name": "ocean"})).unwrap(), Value::Null, "no color, no warning"); +} + #[test] fn exports_draw_the_globe_in_light_space() { // #352: the dark, starry space is the interactive view's; exports and layouts print a light diff --git a/crates/engine/tests/project_save_roundtrip.rs b/crates/engine/tests/project_save_roundtrip.rs index 679a084083..ab46baf31b 100644 --- a/crates/engine/tests/project_save_roundtrip.rs +++ b/crates/engine/tests/project_save_roundtrip.rs @@ -122,6 +122,7 @@ fn step() -> impl Strategy { (prop::sample::select(vec!["legend", "scaleBar", "northArrow", "text", "rectangle", "grid", "colorbar"]), name()) .prop_map(|(k, t)| ("layout.addElement", json!({"kind": k, "text": t}))), prop::sample::select(vec!["paper", "midnight", "ocean", "atlas", "blank"]).prop_map(|n| ("map.basemap", json!({"name": n}))), + prop::sample::select(vec!["#F1EADF", "#101820"]).prop_map(|c| ("map.basemap", json!({"name": "blank", "color": c}))), prop::sample::select(vec!["Albers Equal Area Conic +lat_1=29.5 +lat_2=45.5", "EPSG:3857", "EPSG:4326"]) .prop_map(|t| ("map.projection", json!({"type": t}))), (-180.0..180.0f64).prop_map(|b| ("map.setBearing", json!({"bearing": b}))), diff --git a/crates/map/src/lib.rs b/crates/map/src/lib.rs index 9807763084..529ddb61e9 100644 --- a/crates/map/src/lib.rs +++ b/crates/map/src/lib.rs @@ -1659,6 +1659,10 @@ pub struct Map { #[serde(default, skip_serializing_if = "Vec::is_empty")] pub groups: Vec, pub basemap: Basemap, + /// The blank basemap's paper (#2532): its colour where a blank map would draw white, so a + /// map frame can sit on a coloured page. Opaque; only kept with [`Basemap::Blank`]. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub paper: Option, /// Web tile basemaps and overlays (index 0 on top), each drawn over the map layer it names /// (`TileLayer::over`), or under all of them; see [`Map::stack`]. #[serde(default, skip_serializing_if = "Vec::is_empty")] @@ -1809,6 +1813,7 @@ impl Map { service_groups: Vec::new(), groups: Vec::new(), basemap: Basemap::Paper, + paper: None, tiles: Vec::new(), camera: Camera::world(), bookmarks: Vec::new(), @@ -2969,9 +2974,13 @@ impl Map { /// The built-in basemap's (background, land, land outline, graticule) colours. The world /// outline is the Earth's, so on another body the background is plain: the land's grey, with - /// no land drawn on it (#223). + /// no land drawn on it (#223). A blank basemap's paper colour (#2532) is its background and its + /// land, on any body. pub fn palette(&self) -> (Rgba, Rgba, Rgba, Rgba) { let (water, land, outline, grat) = self.basemap.palette(); + if let Some(paper) = self.blank_paper() { + return (paper, paper, outline, grat); + } if self.body().is_earth() { return (water, land, outline, grat); } @@ -2980,6 +2989,11 @@ impl Map { (grey, grey, Rgba::new(0, 0, 0, 0), grat) } + /// The blank basemap's paper colour, when the map is on the blank basemap and has one. + pub fn blank_paper(&self) -> Option { + self.paper.filter(|_| self.basemap == Basemap::Blank) + } + /// Whether the built-in world outline is drawn: where the palette's land and water differ, so /// not on the blank basemap or another body. pub fn draws_world_outline(&self) -> bool { @@ -3207,6 +3221,7 @@ impl Map { service_groups, groups: _, basemap: _, + paper: _, tiles, camera: _, bookmarks: _, diff --git a/crates/render/src/layout.rs b/crates/render/src/layout.rs index c214f0a717..8abd6e9641 100644 --- a/crates/render/src/layout.rs +++ b/crates/render/src/layout.rs @@ -2886,6 +2886,7 @@ pub fn frame_coverage_judged_on( // Put back when this ends, a panic in the drawing included. struct Aside<'a> { basemap: rustgis_map::Basemap, + paper: Option, tiles: Vec, graticule: bool, lock: Option>, @@ -2899,6 +2900,7 @@ pub fn frame_coverage_judged_on( l.visible = true; } self.map.basemap = self.basemap; + self.map.paper = self.paper; self.map.tiles = std::mem::take(&mut self.tiles); self.map.graticule = self.graticule; self.map.label_lock = self.lock.take(); @@ -2914,6 +2916,8 @@ pub fn frame_coverage_judged_on( let aside = Aside { outlines, basemap: std::mem::replace(&mut map.basemap, rustgis_map::Basemap::Blank), + // Judged on white paper: a blank basemap's paper colour (#2532) would count as drawn. + paper: map.paper.take(), tiles: std::mem::take(&mut map.tiles), graticule: std::mem::replace(&mut map.graticule, false), lock: map.label_lock.take(), @@ -4732,6 +4736,13 @@ mod tests { // A 100 mm frame at 1:1,000,000 shows about 0.9° across: the square sits in its middle. let plain = |map: &mut Map, under| frame_plain_under(map, Coord::new(0.0, 0.0), 1_000_000.0, (100.0, 100.0), under, 128); assert!(plain(&mut map, (2.0, 70.0, 25.0, 25.0)), "a corner is the blank paper"); + // A paper colour (#2532) is the background too, and coverage still finds only the data. + let white = frame_coverage(&mut map, Coord::new(0.0, 0.0), 1_000_000.0, 100.0, 100.0, 64); + map.paper = Some(Rgba::rgb(0xF1, 0xEA, 0xDF)); + assert!(plain(&mut map, (2.0, 70.0, 25.0, 25.0)), "a corner is the coloured paper"); + assert_eq!(frame_coverage(&mut map, Coord::new(0.0, 0.0), 1_000_000.0, 100.0, 100.0, 64), white); + assert_eq!(map.paper, Some(Rgba::rgb(0xF1, 0xEA, 0xDF)), "put back after coverage"); + map.paper = None; assert!(!plain(&mut map, (40.0, 40.0, 20.0, 20.0)), "the data in the middle"); assert!(!plain(&mut map, (48.0, 48.0, 4.0, 4.0)), "one colour all over, but the data's, not the background"); map.graticule = true; diff --git a/crates/render/src/lib.rs b/crates/render/src/lib.rs index 18a03d1ce1..b567c797b8 100644 --- a/crates/render/src/lib.rs +++ b/crates/render/src/lib.rs @@ -3282,8 +3282,12 @@ pub fn gpu_may_turn(map: &Map, view: &View) -> bool { /// The colours of a tilted view's sky (at the top) and of the fog it fades into at the /// horizon, from the basemap. A body without the Earth's atmosphere has neither: the ground -/// fades into the black of space (#223). +/// fades into the black of space (#223). A blank basemap's paper colour is both, as it is (#2532): +/// the block stands on the page's own colour. pub fn tilt_sky(map: &Map) -> (Rgba, Rgba) { + if let Some(paper) = map.blank_paper() { + return (paper, paper); + } if !map.body().is_earth() { let space = globe_space(true); return (space, space); @@ -9472,6 +9476,29 @@ mod tests { assert_eq!(scene.clear, mesh::premul(water), "the clear colour is the basemap's water"); } + /// A blank basemap's paper colour (#2532) is the flat view's canvas on the CPU and the GPU's + /// clear colour, and a tilted view's sky and fog as it is; another basemap leaves it unused. + #[test] + fn a_blank_paper_colour_is_the_canvas_the_clear_colour_and_the_sky() { + let cream = Rgba::rgb(0xF1, 0xEA, 0xDF); + let mut m = Map::new("Map"); + (m.basemap, m.graticule, m.paper) = (rustgis_map::Basemap::Blank, false, Some(cream)); + let view = View { width: 200.0, height: 120.0, pixels_per_point: 1.0, camera: Camera::world(), sky: false }; + let pm = render(&mut m, &view).unwrap().pixmap; + let p = pm.pixel(5, 5).unwrap(); + assert_eq!((p.red(), p.green(), p.blue(), p.alpha()), (0xF1, 0xEA, 0xDF, 255)); + let Some(RenderOutput::Gpu(scene)) = render_backend(&mut m, &view, Backend::Gpu) else { panic!("gpu scene") }; + assert_eq!(scene.clear, mesh::premul(cream)); + assert_eq!(tilt_sky(&m), (cream, cream), "no white mixed in"); + m.paper = None; + let white = Rgba::rgb(0xFF, 0xFF, 0xFF); + assert_eq!(m.palette().0, white, "without a colour, blank stays white"); + m.paper = Some(cream); + m.basemap = rustgis_map::Basemap::Paper; + assert_eq!(m.palette(), m.basemap.palette(), "another basemap keeps its own colours"); + assert_ne!(tilt_sky(&m).0, cream); + } + #[test] fn a_coarse_globe_drape_keeps_point_symbols_their_size() { // A drape over its size limit gets fewer pixels, not a coarser scale: a marker sized in diff --git a/crates/ui-egui/src/mapview.rs b/crates/ui-egui/src/mapview.rs index 67634bbcbb..001d530b5a 100644 --- a/crates/ui-egui/src/mapview.rs +++ b/crates/ui-egui/src/mapview.rs @@ -4808,7 +4808,17 @@ fn shown_layers(session: &rustgis_engine::Session) -> u64 { let mut h = std::hash::DefaultHasher::new(); let project = &session.project; let map = project.map(); - (&session.path, &project.name, project.active_map, &map.name, map.basemap, map.graticule, map.graticule_type, &map.graticule_crs) + ( + &session.path, + &project.name, + project.active_map, + &map.name, + map.basemap, + map.paper, + map.graticule, + map.graticule_type, + &map.graticule_crs, + ) .hash(&mut h); for l in &map.layers { (l.id, l.visible).hash(&mut h); diff --git a/crates/ui-egui/src/ribbon.rs b/crates/ui-egui/src/ribbon.rs index 9d3b438412..37ad606c78 100644 --- a/crates/ui-egui/src/ribbon.rs +++ b/crates/ui-egui/src/ribbon.rs @@ -714,6 +714,27 @@ pub(crate) fn sample_data_gallery(ui: &mut Ui, app: &mut RustGisApp) { } } +/// The blank basemap's paper colour (#2532), while the map is on it with no web basemap over it: +/// the colour a map frame shows on a coloured page. The picker is drawn in the gallery itself: a +/// colour button's picker is a popup of its own, and opening it would close this menu. +fn blank_paper(ui: &mut Ui, app: &mut RustGisApp) { + let map = app.session.map(); + if map.basemap != Basemap::Blank || !map.tiles.iter().all(|t| t.overlay) { + return; + } + let mut c = crate::theme::c32(map.palette().0); + ui.add_space(6.0); + egui::CollapsingHeader::new(tl!("Paper color")).id_salt("blank_paper").show(ui, |ui| { + let picked = ui.scope(|ui| egui::color_picker::color_picker_color32(ui, &mut c, egui::color_picker::Alpha::Opaque)); + if picked.inner { + crate::widgets::one_step_per_press(app, &picked.response); + let [r, g, b, _] = c.to_srgba_unmultiplied(); + let _ = + app.run("map.basemap", json!({"name": "blank", "color": rustgis_engine::map::Rgba::rgb(r, g, b).hex(), "keepTiles": true})); + } + }); +} + pub(crate) fn basemap_gallery(ui: &mut Ui, app: &mut RustGisApp) { let t = Tokens::get(ui.ctx()); ui.label(egui::RichText::new(tl!("Basemaps")).font(semibold(12.5))); @@ -755,6 +776,7 @@ pub(crate) fn basemap_gallery(ui: &mut Ui, app: &mut RustGisApp) { } } }); + blank_paper(ui, app); web_basemaps(ui, app, &t); planet_basemaps(ui, app); tile_layers(ui, app, &t); diff --git a/docs/maintaining.md b/docs/maintaining.md index 85e1442931..82a984254e 100644 --- a/docs/maintaining.md +++ b/docs/maintaining.md @@ -108,7 +108,8 @@ diagram cut to a circle), `terrain-water`, `terrain-water-shore` (a terrain water's shore band other than the default), `terrain-block-water` (water in a block diagram's walls), `shaded-relief-effects` (cast shadows, sky visibility, fill light or rock colour), -`shaded-relief-light` (a Shaded Relief's ambient or balanced light) and +`shaded-relief-light` (a Shaded Relief's ambient or balanced light), +`blank-paper` (a blank basemap's paper colour) and `normalized-legend-urls` for normalized legend addresses. Project requirements include offline map snapshots. `table-export-order` protects saved task commands, command notebook cells and replayable history using Export Table sort or limit options. diff --git a/docs/user-guide/maps.md b/docs/user-guide/maps.md index 5761432073..828dadccac 100644 --- a/docs/user-guide/maps.md +++ b/docs/user-guide/maps.md @@ -428,7 +428,11 @@ place names there. On the desktop, its optional `url` selects another Valhalla s **Home › Add › Basemap** offers five built-in basemaps drawn from a world outline (Paper, Midnight, -Ocean, Atlas, Blank), which need no network, and web tile layers over them: +Ocean, Atlas, Blank), which need no network, and web tile layers over them. On Blank, **Paper +color** under the basemaps sets the colour the map draws where it would draw white, a tilted view's +sky included, so a map frame sits on a coloured layout page without a white box around it +(`map.basemap {"name": "blank", "color": "#F1EADF"}`). Choosing another basemap takes the paper +colour off, as that basemap draws its own colours: - **Raster tiles** from an XYZ or TMS template (`https://…/{z}/{x}/{y}.png`; `{-y}` for rows from the south, `{s}` for subdomains, `{q}` for Bing-style quadkeys) or a WMS through diff --git a/schema/fixtures/blank_paper.rgis b/schema/fixtures/blank_paper.rgis new file mode 100644 index 0000000000..d1e666523e --- /dev/null +++ b/schema/fixtures/blank_paper.rgis @@ -0,0 +1,15 @@ +{ + "format": 2, + "name": "Blank paper", + "requires": ["blank-paper"], + "active_map": 0, + "maps": [ + { + "name": "Map", + "layers": [], + "basemap": "Blank", + "paper": [241, 234, 223, 255], + "camera": {"center": {"x": 0, "y": 0}, "res": 30000} + } + ] +} diff --git a/schema/project.schema.json b/schema/project.schema.json index 15641b69d1..67f26915db 100644 --- a/schema/project.schema.json +++ b/schema/project.schema.json @@ -1090,7 +1090,8 @@ "field-generation", "offline-map-area-id", "crs-wkt", - "zarr-window" + "zarr-window", + "blank-paper" ], "type": "string" }, @@ -1178,7 +1179,8 @@ "field-generation", "offline-map-area-id", "crs-wkt", - "zarr-window" + "zarr-window", + "blank-paper" ], "x-rustgis-reads-format": 2, "x-rustgis-writes-format": 2 From 7745160b9cbfbdc88a34de0f8dae7eec879fc72e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 20 Nov 2026 14:36:27 -0500 Subject: [PATCH 2/4] fix(map): blank paper review round 1: opaque paper, strict #RRGGBB, saved steps require blank-paper (#2532) - Map::blank_paper() returns the paper opaque, so a file's translucent one is drawn opaque. - map.basemap's color takes six hex digits only ("#+F0000" was read as #0F0000). - A saved task step, script or code notebook cell that gives the blank basemap a colour requires blank-paper; white, null and other basemaps don't. - docs/python.md shows set_basemap with a colour; the warning is passed by reference. --- crates/engine/src/cmd/navigate.rs | 10 ++++-- crates/engine/src/project_capabilities.rs | 43 +++++++++++++++++++++++ crates/engine/src/tests.rs | 2 +- crates/map/src/lib.rs | 5 +-- crates/render/src/lib.rs | 2 ++ docs/python.md | 1 + 6 files changed, 58 insertions(+), 5 deletions(-) diff --git a/crates/engine/src/cmd/navigate.rs b/crates/engine/src/cmd/navigate.rs index 6b732cb469..6831993902 100644 --- a/crates/engine/src/cmd/navigate.rs +++ b/crates/engine/src/cmd/navigate.rs @@ -929,7 +929,13 @@ fn basemap(s: &mut Session, p: &Value) -> CmdResult { let paper = match p.get("color") { None => None, Some(Value::Null) => Some(None), - Some(Value::String(c)) => match c.trim().strip_prefix('#').filter(|h| h.len() == 6).and_then(rustgis_map::Rgba::from_hex) { + // Six hex digits: `from_hex` alone would take a sign in a pair ("#+F0000"). + Some(Value::String(c)) => match c + .trim() + .strip_prefix('#') + .filter(|h| h.len() == 6 && h.bytes().all(|b| b.is_ascii_hexdigit())) + .and_then(rustgis_map::Rgba::from_hex) + { Some(rgba) => Some(Some(rgba)), None => return Err(format!("color must be \"#RRGGBB\" (opaque), not '{c}'")), }, @@ -946,7 +952,7 @@ fn basemap(s: &mut Session, p: &Value) -> CmdResult { m.paper = None; if paper.is_some_and(|c| c.is_some()) { let warning = format!("color is for the blank basemap only: {} keeps its own colours", basemap.label()); - s.warn(warning.clone()); + s.warn(&warning); return Ok(json!({"warning": warning})); } } else if let Some(paper) = paper { diff --git a/crates/engine/src/project_capabilities.rs b/crates/engine/src/project_capabilities.rs index c2277ed766..750d6bc733 100644 --- a/crates/engine/src/project_capabilities.rs +++ b/crates/engine/src/project_capabilities.rs @@ -120,8 +120,22 @@ const COMMAND_CAPABILITIES: &[(&str, CommandCheck)] = &[ ("layout-element-wrap", command_uses_element_wrap), ("layout-chart-data", command_uses_chart_data), ("layout-chart-look", command_uses_chart_look), + ("blank-paper", command_uses_blank_paper), ]; +/// A `map.basemap` command that gives the blank basemap a paper colour (#2532): an older reader +/// ignores `color` and draws white. White, `null` or another basemap leaves no paper to keep. +fn command_uses_blank_paper(id: &str, params: &Value) -> bool { + match id { + "map.basemap" => { + params.get("name").and_then(Value::as_str).is_some_and(|n| n.trim().eq_ignore_ascii_case("blank")) + && params.get("color").and_then(Value::as_str).is_some_and(|c| !c.trim().eq_ignore_ascii_case("#FFFFFF")) + } + "script.run" => params.get("script").and_then(Value::as_str).is_some_and(|s| script_uses(s, command_uses_blank_paper)), + _ => false, + } +} + /// A layout command that gives an element a background: an older reader warns that it ignores /// the key and makes the element without one. `null` only takes a background away, which an /// older reader's elements never have. @@ -1095,6 +1109,35 @@ mod tests { let clean = serde_json::to_value(&p).unwrap(); assert!(clean.get("requires").is_none()); assert!(clean["maps"][0].get("paper").is_none()); + // A saved command that gives the blank basemap a colour needs it too; white, null or + // another basemap doesn't. + for (params, required) in [ + (json!({"name": "blank", "color": "#F1EADF"}), true), + (json!({"name": "Blank", "color": "#101820"}), true), + (json!({"name": "blank", "color": "#ffffff"}), false), + (json!({"name": "blank", "color": null}), false), + (json!({"name": "blank"}), false), + (json!({"name": "paper", "color": "#F1EADF"}), false), + ] { + let script = format!("# Paper\nmap.basemap= {params}"); + for (field, value) in [ + ("tasks", json!([{"name": "Task", "steps": [{"title": "Paper", "command": "map.basemap", "params": params}]}])), + ( + "tasks", + json!([{"name": "Script", "steps": [{"title": "Paper", "command": "script.run", "params": {"script": script}}]}]), + ), + ("notebooks", json!([{"name": "Notebook", "cells": [{"kind": "code", "source": script}]}])), + ] { + let mut document = clean.clone(); + document[field] = value; + let saved = serde_json::to_value(Project::from_json(&document.to_string()).unwrap()).unwrap(); + if required { + assert_eq!(saved["requires"], json!(["blank-paper"]), "{field} {params}"); + } else { + assert!(saved.get("requires").is_none(), "{field} {params}"); + } + } + } let mut unknown = saved; unknown["requires"] = json!(["blank-paper", "future-paper"]); assert!(Project::from_json(&unknown.to_string()).unwrap_err().contains("future-paper")); diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 14dcf61eeb..d5b3a04b23 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -15496,7 +15496,7 @@ fn a_blank_basemap_takes_a_paper_colour() { assert_eq!(s.map().palette().0, cream); s.run("map.basemap", &json!({"name": "blank"})).unwrap(); assert_eq!(s.map().paper, Some(cream), "no color keeps it"); - for bad in [json!("#F1EADF80"), json!("F1EADF"), json!("#F1EA"), json!("cream"), json!(3)] { + for bad in [json!("#F1EADF80"), json!("F1EADF"), json!("#F1EA"), json!("#+F0000"), json!("cream"), json!(3)] { let e = s.run("map.basemap", &json!({"name": "blank", "color": bad})).unwrap_err(); assert!(e.contains("#RRGGBB"), "{e}"); assert_eq!(s.map().paper, Some(cream), "a refused colour changes nothing"); diff --git a/crates/map/src/lib.rs b/crates/map/src/lib.rs index 529ddb61e9..f46a9a63f1 100644 --- a/crates/map/src/lib.rs +++ b/crates/map/src/lib.rs @@ -2989,9 +2989,10 @@ impl Map { (grey, grey, Rgba::new(0, 0, 0, 0), grat) } - /// The blank basemap's paper colour, when the map is on the blank basemap and has one. + /// The blank basemap's paper colour, when the map is on the blank basemap and has one: always + /// opaque, a file's translucent one included (the paper is the backdrop: nothing shows through). pub fn blank_paper(&self) -> Option { - self.paper.filter(|_| self.basemap == Basemap::Blank) + self.paper.filter(|_| self.basemap == Basemap::Blank).map(|c| Rgba::rgb(c.r(), c.g(), c.b())) } /// Whether the built-in world outline is drawn: where the palette's land and water differ, so diff --git a/crates/render/src/lib.rs b/crates/render/src/lib.rs index b567c797b8..11ba32dcca 100644 --- a/crates/render/src/lib.rs +++ b/crates/render/src/lib.rs @@ -9490,6 +9490,8 @@ mod tests { let Some(RenderOutput::Gpu(scene)) = render_backend(&mut m, &view, Backend::Gpu) else { panic!("gpu scene") }; assert_eq!(scene.clear, mesh::premul(cream)); assert_eq!(tilt_sky(&m), (cream, cream), "no white mixed in"); + m.paper = Some(Rgba::new(0xF1, 0xEA, 0xDF, 0)); + assert_eq!((m.palette().0, tilt_sky(&m).0), (cream, cream), "a file's translucent paper is drawn opaque"); m.paper = None; let white = Rgba::rgb(0xFF, 0xFF, 0xFF); assert_eq!(m.palette().0, white, "without a colour, blank stays white"); diff --git a/docs/python.md b/docs/python.md index 91f4a602fb..134a183104 100644 --- a/docs/python.md +++ b/docs/python.md @@ -230,6 +230,7 @@ s.set_center(114.1, 22.4, scale=2_000_000) # bearing= and pitch= tilt a s.zoom_to(s["Cities"]) # or a box: (west, south, east, north) s.bounds # what the map shows now s.set_basemap("paper") # paper, midnight, ocean, atlas, blank +s.set_basemap("blank", color="#F1EADF") # blank on a coloured page s.add_tiles("https://tile.openstreetmap.org/{z}/{x}/{y}.png", name="OpenStreetMap") ``` From 9c49587c2783fbb8725aaf15ec41049b3f88c5ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 20 Nov 2026 16:10:42 -0500 Subject: [PATCH 3/4] fix(render): a globe's light space takes the blank paper; review round 2 (#2532) - On the blank basemap the light space around a globe (layout exports, a publication's locator) is the paper colour, so a globe frame on a coloured page has no grey box; the interactive view keeps its dark sky. - Test comments say what each test checks; the paper field's doc says it is drawn opaque. - Python session test for set_basemap with a colour. --- apps/rustgis-python/tests/test_session.py | 7 +++++++ crates/engine/src/tests.rs | 8 ++++---- crates/map/src/lib.rs | 3 ++- crates/render/src/lib.rs | 25 +++++++++++++++++++---- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/apps/rustgis-python/tests/test_session.py b/apps/rustgis-python/tests/test_session.py index edc890c30c..3173d13af0 100644 --- a/apps/rustgis-python/tests/test_session.py +++ b/apps/rustgis-python/tests/test_session.py @@ -377,6 +377,13 @@ def test_the_view(sample): assert abs(sample.info()["center"]["lon"] - 114.17) < 0.01 sample.set_basemap("paper") assert sample.info()["basemap"] == "paper" + # The blank basemap's paper colour (#2532); with another basemap it is a warning. + sample.set_basemap("blank", color="#F1EADF") + assert sample.info()["basemap"] == "blank" + assert "blank basemap only" in sample.set_basemap("paper", color="#F1EADF")["warning"] + assert sample.info()["basemap"] == "paper" + with pytest.raises(rustgis.RustGISError, match="RRGGBB"): + sample.set_basemap("blank", color="cream") diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index d5b3a04b23..1d52a6bb98 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -15472,10 +15472,8 @@ fn the_globe_has_stars_that_turn_off() { assert!(corner(&mut s) == starry); } -/// A blank basemap's paper colour (#2532): kept until null or another basemap, opaque #RRGGBB only, -/// a warning (not an error) when given with another basemap, and drawn in a layout's map frame. -/// A publication's globe locator draws the map's blank paper (#2532), so the disc's backdrop is -/// the page's colour too. +/// A publication's globe locator keeps the map's blank paper (#2532), so the space around its +/// disc is the page's colour too. #[test] fn a_globe_locator_keeps_the_blank_paper() { let mut s = world(); @@ -15486,6 +15484,8 @@ fn a_globe_locator_keeps_the_blank_paper() { assert_eq!(m.blank_paper(), Some(rustgis_map::Rgba::rgb(0xF1, 0xEA, 0xDF))); } +/// A blank basemap's paper colour (#2532): kept until null or another basemap, opaque #RRGGBB only, +/// a warning (not an error) when given with another basemap, and drawn in a layout's map frame. #[test] fn a_blank_basemap_takes_a_paper_colour() { let cream = rustgis_map::Rgba::rgb(0xF1, 0xEA, 0xDF); diff --git a/crates/map/src/lib.rs b/crates/map/src/lib.rs index f46a9a63f1..52eff8a546 100644 --- a/crates/map/src/lib.rs +++ b/crates/map/src/lib.rs @@ -1660,7 +1660,8 @@ pub struct Map { pub groups: Vec, pub basemap: Basemap, /// The blank basemap's paper (#2532): its colour where a blank map would draw white, so a - /// map frame can sit on a coloured page. Opaque; only kept with [`Basemap::Blank`]. + /// map frame can sit on a coloured page. Drawn opaque ([`Map::blank_paper`]); only kept with + /// [`Basemap::Blank`]. #[serde(default, skip_serializing_if = "Option::is_none")] pub paper: Option, /// Web tile basemaps and overlays (index 0 on top), each drawn over the map layer it names diff --git a/crates/render/src/lib.rs b/crates/render/src/lib.rs index 11ba32dcca..aba622fc6f 100644 --- a/crates/render/src/lib.rs +++ b/crates/render/src/lib.rs @@ -6092,13 +6092,17 @@ struct Space { stars: bool, /// The glow of an atmosphere around the disc: the Earth's (#223). atmosphere: bool, + /// A blank basemap's paper colour (#2532), which the light space takes, so a globe frame + /// sits on the page's colour. + paper: Option, } /// The space around the globe for `view`: the interactive view's starry sky, or for exports a -/// light space (dark on the Midnight basemap) without stars. +/// light space (a blank basemap's paper colour; dark on the Midnight basemap) without stars. fn space(view: &View, map: &Map) -> Space { let dark = view.sky || map.basemap == rustgis_map::Basemap::Midnight; - Space { dark, stars: view.sky && map.view.effects.stars, atmosphere: map.body().is_earth() } + let paper = map.blank_paper().filter(|_| !dark); + Space { dark, stars: view.sky && map.view.effects.stars, atmosphere: map.body().is_earth(), paper } } /// Side of the starfield tile in logical points: the stars repeat this far apart. @@ -6221,7 +6225,7 @@ fn globe_shading(pm: &mut Pixmap, g: &Globe, water: Rgba, space: Space, ppp: f32 /// The globe's surroundings and ocean: space (dark or light, starry when it says so), an /// atmosphere glow, and the ocean disc. fn draw_globe_backdrop(pm: &mut Pixmap, g: &Globe, water: Rgba, space: Space, ppp: f32) { - let bg = globe_space(space.dark); + let bg = space.paper.unwrap_or_else(|| globe_space(space.dark)); pm.fill(tiny_skia::Color::from_rgba8(bg.r(), bg.g(), bg.b(), 255)); if space.stars { draw_stars(pm, ppp); @@ -9477,7 +9481,8 @@ mod tests { } /// A blank basemap's paper colour (#2532) is the flat view's canvas on the CPU and the GPU's - /// clear colour, and a tilted view's sky and fog as it is; another basemap leaves it unused. + /// clear colour, a tilted view's sky and fog as it is, and the light space around a globe; + /// another basemap leaves it unused. #[test] fn a_blank_paper_colour_is_the_canvas_the_clear_colour_and_the_sky() { let cream = Rgba::rgb(0xF1, 0xEA, 0xDF); @@ -9490,6 +9495,18 @@ mod tests { let Some(RenderOutput::Gpu(scene)) = render_backend(&mut m, &view, Backend::Gpu) else { panic!("gpu scene") }; assert_eq!(scene.clear, mesh::premul(cream)); assert_eq!(tilt_sky(&m), (cream, cream), "no white mixed in"); + // A globe's light space (exports, a publication's locator) is the paper too; the + // interactive view keeps its dark sky. + m.projection = rustgis_map::Projection::Globe; + let camera = Camera { center: Coord::new(0.0, 0.0), res: 200_000.0, bearing: 0.0, pitch: 0.0 }; + let corner = |m: &mut Map, sky: bool| { + let pm = render(m, &View { camera, sky, ..view }).unwrap().pixmap; + let p = pm.pixel(2, 2).unwrap(); + Rgba::rgb(p.red(), p.green(), p.blue()) + }; + assert_eq!(corner(&mut m, false), cream, "a globe on the paper"); + assert_eq!(corner(&mut m, true), globe_space(true), "the view's sky"); + m.projection = rustgis_map::Projection::default(); m.paper = Some(Rgba::new(0xF1, 0xEA, 0xDF, 0)); assert_eq!((m.palette().0, tilt_sky(&m).0), (cream, cream), "a file's translucent paper is drawn opaque"); m.paper = None; From 71a498b125be022dc9a5e11e65875244ecaefab6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 20 Nov 2026 18:02:39 -0500 Subject: [PATCH 4/4] fix(map): a map's look compares its blank paper, so a new paper colour draws the map again (#2532) --- crates/map/src/look.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/map/src/look.rs b/crates/map/src/look.rs index 65437a452a..e2ee7e4a32 100644 --- a/crates/map/src/look.rs +++ b/crates/map/src/look.rs @@ -240,6 +240,7 @@ impl MapLook { service_groups: _, groups, basemap, + paper, tiles, camera, // Not compared (see `same`), so not kept. @@ -270,6 +271,7 @@ impl MapLook { service_groups: Vec::new(), groups: groups.clone(), basemap: *basemap, + paper: *paper, tiles: tiles.clone(), camera: *camera, bookmarks: Vec::new(), @@ -307,6 +309,7 @@ impl MapLook { service_groups: _, groups, basemap, + paper, tiles, camera, bookmarks: _, @@ -333,6 +336,7 @@ impl MapLook { && groups.len() == map.groups.len() && groups.iter().zip(&map.groups).all(|(a, b)| same_group(a, b)) && *basemap == map.basemap + && *paper == map.paper && *tiles == map.tiles && *camera == map.camera && *graticule == map.graticule @@ -502,5 +506,9 @@ mod tests { assert!(!grouped.same(&MapLook::of(&map))); map.graticule = !map.graticule; assert!(!before.same(&MapLook::of(&map))); + // The blank basemap's paper colour (#2532) is the map's background. + let white = MapLook::of(&map); + map.paper = Some(Rgba([241, 234, 223, 255])); + assert!(!white.same(&MapLook::of(&map)), "a new paper colour draws the map again"); } }