From 47479cf18364bea7227e1b7a2570eb75d2164007 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Sun, 29 Nov 2026 19:03:04 -0500 Subject: [PATCH 1/8] feat(layout): a map frame outlines several other frames (#3394) --- crates/engine/src/cmd/layout.rs | 13 +- crates/engine/src/cmd/layout/elements.rs | 40 +++- crates/engine/src/cmd/layout/inputs.rs | 5 +- .../engine/src/cmd/layout/publication/mod.rs | 2 + crates/engine/src/cmd/layout/update.rs | 68 +++--- crates/engine/src/cmd/presentation.rs | 1 + crates/engine/src/project.rs | 1 + crates/engine/src/project_capabilities.rs | 24 ++ crates/engine/src/tests.rs | 3 + .../src/tests/archive_render_revision.rs | 1 + crates/engine/src/tests/layout_extents.rs | 217 ++++++++++++++++++ crates/engine/src/tests/layout_files.rs | 1 + crates/map/src/layout.rs | 48 +++- crates/map/src/layout/elements.rs | 31 +++ crates/map/src/layout/frame.rs | 13 ++ crates/map/src/layout/tests.rs | 3 + crates/render/src/layout.rs | 19 +- .../render/src/layout/legend/count_tests.rs | 1 + crates/render/src/layout/profile_tests.rs | 1 + crates/render/src/layout/tests.rs | 19 ++ crates/render/src/stream_tests.rs | 2 + crates/render/src/tiles.rs | 1 + crates/ui-egui/src/layoutview/format/frame.rs | 37 ++- crates/ui-egui/src/ribbon.rs | 7 +- docs/maintaining.md | 9 + docs/user-guide/layouts.md | 14 +- schema/fixtures/layout_extent_indicators.rgis | 26 +++ schema/project.schema.json | 2 + 28 files changed, 527 insertions(+), 82 deletions(-) create mode 100644 crates/engine/src/tests/layout_extents.rs create mode 100644 schema/fixtures/layout_extent_indicators.rgis diff --git a/crates/engine/src/cmd/layout.rs b/crates/engine/src/cmd/layout.rs index 38c3e29c04..bd84dc87ae 100644 --- a/crates/engine/src/cmd/layout.rs +++ b/crates/engine/src/cmd/layout.rs @@ -8,10 +8,10 @@ use std::sync::LazyLock; use rustgis_geom::{Coord, Extent}; use rustgis_map::layout::{ Arrange, ArrowStyle, Background, CHART_BAR, CHART_BARS, CHART_OUTLINE, ChartOrder, ChartOutline, ClassLabels, CoordFormat, ElementKind, - FeatureCounts, FontFamily, FrameShape, GRID_LABEL_PT, Grid, GridEdges, GridKind, GridStyle, Guides, LAYOUT_TEXT_SIZE, LINE_SPACING, - LayerNames, Layout, LegendFit, LegendSizes, LineDir, LineHead, MAX_CHART_BARS, MAX_CHART_DECIMALS, MAX_CHART_OUTLINE_WIDTH, - MAX_COLORBAR_TICKS, MAX_GRID_WIDTH, MAX_GUIDES, MAX_LEGEND_COLUMNS, MAX_LEGEND_LABEL_CHARS, MAX_LEGEND_LABELS, MAX_LINE_SPACING, - MAX_SCALE_BEFORE_ZERO, MAX_SCALE_DECIMALS, MAX_SCALE_DIVISIONS, MAX_SCALE_SUBDIVISIONS, MAX_SECTIONS, MAX_TICK_MM, + ExtentIndicator, FeatureCounts, FontFamily, FrameShape, GRID_LABEL_PT, Grid, GridEdges, GridKind, GridStyle, Guides, LAYOUT_TEXT_SIZE, + LINE_SPACING, LayerNames, Layout, LegendFit, LegendSizes, LineDir, LineHead, MAX_CHART_BARS, MAX_CHART_DECIMALS, + MAX_CHART_OUTLINE_WIDTH, MAX_COLORBAR_TICKS, MAX_GRID_WIDTH, MAX_GUIDES, MAX_LEGEND_COLUMNS, MAX_LEGEND_LABEL_CHARS, MAX_LEGEND_LABELS, + MAX_LINE_SPACING, MAX_SCALE_BEFORE_ZERO, MAX_SCALE_DECIMALS, MAX_SCALE_DIVISIONS, MAX_SCALE_SUBDIVISIONS, MAX_SECTIONS, MAX_TICK_MM, MAX_UNIT_LABEL_CHARS, MIN_ELEMENT_MM, MIN_LINE_SPACING, MapSeries, Orientation, PAGES, SCALE_BAR_TEXT_PT, ScaleBarFit, ScaleBarStyle, ScaleLabelPosition, ScaleUnits, Section, SectionLine, TextAlign, TextCase, TextVAlign, TickSide, UnitLabelPosition, fit_scale, line_angle, line_at_angle, line_length, @@ -191,7 +191,7 @@ pub fn commands() -> Vec { r##"{"layout"?, "##, r##""kind": "northArrow"|"scaleBar"|"legend"|"colorbar"|"text"|"dynamicText"|"picture"|"table"|"chart"|"rectangle" (a neatline framing the page unless any of x, y, w, h is given)|"ellipse"|"circle"|"line"|"arrow"|"extentIndicator"|"grid"|"section" (a section line over a map frame, named at both ends, A and A', up to 26 a frame; as a grid or an extentIndicator, it adds no element: the reply's "element" is its frame, the one layout.update changes it on with "section", and "section" its name)|"profile" (a raster's profile along a section line of the frame, beside the frame on the side the line runs along, lined up with it: each sample is read at its point of the page line, through the frame's projection, so the curve is straight across from the place it comes from; its box is the frame's side, which it follows when the frame is moved or resized; a tilted frame, one on the globe, or a raster read in place draws none, which a notice and exports say), "##, r##""frame"?: element id (default: the first map frame), "##, - r##""of"?: frame id (extentIndicator, which also takes "color" and "width" in points, default red and 2), "##, + r##""of"?: frame id (extentIndicator, which also takes "color" and "width" in points, default red and 2; a frame keeps one per frame outlined, up to 16, and one for a frame outlined already restyles it), "##, r##""text"? (a text's words; {count:Layer}, {sum:Layer:field}, {mean:Layer:field}, {min:Layer:field} and {max:Layer:field} show the layer's figure, as {scale} shows the scale: of the first map frame's map, over the features the layer's definition query keeps, with the layout's decimal mark; one with no figure shows as written and says why), "##, r##""size"?, "##, r##""color"?: "#RRGGBB"|"#RRGGBBAA" (text, dynamicText, line, arrow, rectangle, ellipse, circle: its outline; extentIndicator; grid; section, default #A8431F; scaleBar; legend, colorbar, table, chart, profile: the ink of its text and lines, default #222222, a chart's bars and a colorbar's colours keeping theirs, and a table drawn without its white cells; refused for other kinds), "##, @@ -362,7 +362,7 @@ pub fn commands() -> Vec { r##""bearing"?: degrees clockwise from north, "##, r##""pitch"?: degrees of tilt (0 to 85), "##, r##""grid"?: {grid options as in layout.addElement} | false (map frame; a grid's "labelSize" goes in it, and is refused outside it unless null), "##, - r##""extentIndicator"?: {"color"?, "width"?: points} | false (map frame: its extent indicator's style, or removes it), "##, + r##""extentIndicator"?: {"of"?: frame id, "color"?, "width"?: points, "remove"?: bool} | false (map frame: restyles, or with "remove" removes, the extent indicator of the frame "of", left out when it has one; false removes them all), "##, r##""border"?: {"color"?: "#RRGGBB"|"#RRGGBBAA", "width"?: points, 0 to 20, 0 for none} | null (map frame: the outline along its shape, default #303030 and 0.8, the keys not given keeping theirs; null gives the default back; refused for other elements), "##, r##""section"?: {"name": the section line it changes, "newName"?, "direction"?, "at"?, "color"?, "width"?, "dash"? ([] or null for solid), as in layout.addElement, the keys not given keeping theirs, "remove"?: true to remove it} (map frame; refused for other elements), "##, r##""layer"?: (colorbar: "" for the top visible raster with a colour scale, not drawn by classes), "##, @@ -591,6 +591,7 @@ fn frame_kind(s: &Session, map: &str, w: f64, shape: FrameShape) -> ElementKind extent_of: None, extent_color: rustgis_map::layout::INDICATOR_COLOR, extent_width: rustgis_map::layout::INDICATOR_WIDTH, + more_extents: Vec::new(), border_color: rustgis_map::layout::FRAME_BORDER_COLOR, border_width: rustgis_map::layout::FRAME_BORDER_WIDTH, bearing, diff --git a/crates/engine/src/cmd/layout/elements.rs b/crates/engine/src/cmd/layout/elements.rs index f8b1ca8c53..5a0847381c 100644 --- a/crates/engine/src/cmd/layout/elements.rs +++ b/crates/engine/src/cmd/layout/elements.rs @@ -643,12 +643,11 @@ pub(in crate::cmd::layout) fn add_element(s: &mut Session, p: &Value) -> CmdResu return Err("of must be another map frame".into()); } unlocked(l, frame)?; - let (color, width) = indicator_style(p, l.element(frame).map(|e| &e.kind))?; + let kind = &l.element(frame).ok_or_else(|| format!("no element {frame}"))?.kind; + let indicators = with_indicator(kind, of, p)?; let l = active(s, p)?; - if let Some(ElementKind::MapFrame { extent_of, extent_color, extent_width, .. }) = l.element_mut(frame).map(|e| &mut e.kind) { - *extent_of = Some(of); - *extent_color = color; - *extent_width = width; + if let Some(e) = l.element_mut(frame) { + e.kind.set_extent_indicators(indicators); } let range = (rustgis_map::layout::MIN_INDICATOR_WIDTH, rustgis_map::layout::MAX_INDICATOR_WIDTH); say_held(s, "Add Element", held_width(p, "extent indicator width", range).into_iter().collect()); @@ -772,14 +771,33 @@ pub(in crate::cmd::layout) fn ticks(p: &Value) -> Result, String> } /// An extent indicator's outline colour and width (points) from `color` and `width` in `p`, each -/// keeping the frame's (`kind`) when not given; one given but not a colour or a number is an -/// error, not left as it was. -pub(in crate::cmd::layout) fn indicator_style(p: &Value, kind: Option<&ElementKind>) -> Result<(Rgba, f64), String> { - let current = match kind { - Some(ElementKind::MapFrame { extent_color, extent_width, .. }) => (*extent_color, *extent_width), +/// keeping `current`'s when not given; one given but not a colour or a number is an error, not +/// left as it was. +pub(in crate::cmd::layout) fn indicator_style(p: &Value, current: (Rgba, f64)) -> Result<(Rgba, f64), String> { + outline_style(p, current, (rustgis_map::layout::MIN_INDICATOR_WIDTH, rustgis_map::layout::MAX_INDICATOR_WIDTH)) +} + +/// A map frame's extent indicators with `of` outlined as `p` says: restyled when outlined +/// already, else added after the others (#3394). +fn with_indicator(kind: &ElementKind, of: u32, p: &Value) -> Result, String> { + let mut list = kind.extent_indicators(); + let at = list.iter().position(|i| i.of == of); + if at.is_none() && list.len() >= rustgis_map::layout::MAX_EXTENT_INDICATORS { + return Err(format!("a map frame outlines at most {} other frames", rustgis_map::layout::MAX_EXTENT_INDICATORS)); + } + let current = match (at.and_then(|i| list.get(i)), kind) { + (Some(i), _) => (i.color, i.width), + // A frame's first keeps the look of one removed before it. + (None, ElementKind::MapFrame { extent_color, extent_width, .. }) if list.is_empty() => (*extent_color, *extent_width), _ => (rustgis_map::layout::INDICATOR_COLOR, rustgis_map::layout::INDICATOR_WIDTH), }; - outline_style(p, current, (rustgis_map::layout::MIN_INDICATOR_WIDTH, rustgis_map::layout::MAX_INDICATOR_WIDTH)) + let (color, width) = indicator_style(p, current)?; + let new = ExtentIndicator { of, color, width }; + match at.and_then(|i| list.get_mut(i)) { + Some(i) => *i = new, + None => list.push(new), + } + Ok(list) } /// A map frame's border colour and width (points, 0 for none) from `color` and `width` in `p`, diff --git a/crates/engine/src/cmd/layout/inputs.rs b/crates/engine/src/cmd/layout/inputs.rs index 5bc27cb3fc..cd0d04ea46 100644 --- a/crates/engine/src/cmd/layout/inputs.rs +++ b/crates/engine/src/cmd/layout/inputs.rs @@ -299,7 +299,10 @@ pub(in crate::cmd::layout) fn close_inputs(input: &crate::cmd::InputContext<'_>, /// Stored surround references consumed by rendering or validation, kept as private selector text. pub(in crate::cmd::layout) fn element_selectors(kind: &ElementKind) -> Option { Some(match kind { - ElementKind::MapFrame { map, extent_of, .. } => json!({"map":map,"extentOf":extent_of}), + ElementKind::MapFrame { map, .. } => { + let of: Vec = kind.extent_indicators().iter().map(|i| i.of).collect(); + json!({"map":map,"extentOf":of}) + } ElementKind::Table { frame, layer, .. } => json!({"frame":frame,"layer":layer}), ElementKind::Chart { frame, layer, field, label, group, stack, .. } => { json!({"frame":frame,"layer":layer,"field":field,"label":label,"group":group,"stack":stack}) diff --git a/crates/engine/src/cmd/layout/publication/mod.rs b/crates/engine/src/cmd/layout/publication/mod.rs index 06aa62922a..9e80e8bc9f 100644 --- a/crates/engine/src/cmd/layout/publication/mod.rs +++ b/crates/engine/src/cmd/layout/publication/mod.rs @@ -1103,6 +1103,7 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu extent_of: None, extent_color: rustgis_map::layout::INDICATOR_COLOR, extent_width: rustgis_map::layout::INDICATOR_WIDTH, + more_extents: Vec::new(), border_color: rustgis_map::layout::FRAME_BORDER_COLOR, // A map that runs to the page's edges has no border. border_width: if edge { 0.0 } else { rustgis_map::layout::FRAME_BORDER_WIDTH }, @@ -1976,6 +1977,7 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu extent_of: Some(target), extent_color: rustgis_map::layout::INDICATOR_COLOR, extent_width: rustgis_map::layout::INDICATOR_WIDTH, + more_extents: Vec::new(), border_color: rustgis_map::layout::FRAME_BORDER_COLOR, border_width: rustgis_map::layout::FRAME_BORDER_WIDTH, bearing: 0.0, diff --git a/crates/engine/src/cmd/layout/update.rs b/crates/engine/src/cmd/layout/update.rs index 72b30bf8b6..3936fec792 100644 --- a/crates/engine/src/cmd/layout/update.rs +++ b/crates/engine/src/cmd/layout/update.rs @@ -5,6 +5,34 @@ use super::*; /// A scale bar's keys beyond its details ([`SCALE_BAR_KEYS`]). pub(in crate::cmd::layout) const SCALE_BAR_LOOK_KEYS: [&str; 7] = ["style", "units", "divisions", "color", "fill", "textSize", "decimals"]; +/// A map frame's extent indicators with the one the object `v` names restyled, or removed with +/// `"remove": true`. `of` is the frame it outlines; left out, the frame's only one (#3394). +fn changed_indicators(kind: &ElementKind, v: &Value) -> Result, String> { + let mut list = kind.extent_indicators(); + if list.is_empty() { + return Err("this frame has no extent indicator: add one with layout.addElement (kind extentIndicator)".into()); + } + let remove = match v.get("remove") { + None | Some(Value::Null) => false, + Some(Value::Bool(b)) => *b, + Some(_) => return Err("remove is true or false".into()), + }; + let at = match v.get("of").filter(|of| !of.is_null()) { + Some(of) => { + let of = of.as_u64().ok_or("of is the id of a frame this one outlines")?; + list.iter().position(|i| u64::from(i.of) == of).ok_or_else(|| format!("this frame doesn't outline {of}"))? + } + None if list.len() == 1 => 0, + None => return Err(format!("this frame outlines {} frames: say which with of", list.len())), + }; + if remove { + list.remove(at); + } else if let Some(i) = list.get_mut(at) { + (i.color, i.width) = indicator_style(v, (i.color, i.width))?; + } + Ok(list) +} + /// A north arrow or scale bar with the options in `p` over `kind`'s; `None` for other elements /// or when `p` has none. A bad value is an error, leaving nothing changed. pub(in crate::cmd::layout) fn restyle(kind: &ElementKind, p: &Value) -> Result, String> { @@ -237,14 +265,12 @@ pub(in crate::cmd::layout) fn update(s: &mut Session, p: &Value) -> CmdResult { let (restyled, new_grid, new_indicator, new_border, new_sections) = { let l = s.project.layouts.get(li).ok_or("no layout")?; let kind = &l.element(id).ok_or_else(|| format!("no element {id}"))?.kind; - // `"extentIndicator": false` takes the frame's indicator away; an object restyles it. + // `"extentIndicator": false` takes the frame's indicators away; an object restyles or + // removes one. let indicator = match (kind, p.get("extentIndicator").filter(|v| !v.is_null())) { - (ElementKind::MapFrame { .. }, Some(Value::Bool(false))) => Some(None), - (ElementKind::MapFrame { extent_of: Some(_), .. }, Some(v @ Value::Object(_))) => Some(Some(indicator_style(v, Some(kind))?)), - (ElementKind::MapFrame { .. }, Some(Value::Object(_))) => { - return Err("this frame has no extent indicator: add one with layout.addElement (kind extentIndicator)".into()); - } - (ElementKind::MapFrame { .. }, Some(_)) => return Err("extentIndicator is an object of color and width, or false".into()), + (ElementKind::MapFrame { .. }, Some(Value::Bool(false))) => Some(Vec::new()), + (ElementKind::MapFrame { .. }, Some(v @ Value::Object(_))) => Some(changed_indicators(kind, v)?), + (ElementKind::MapFrame { .. }, Some(_)) => return Err("extentIndicator is an object, or false".into()), (_, Some(_)) => return Err("only map frames have an extent indicator".into()), _ => None, }; @@ -283,8 +309,8 @@ pub(in crate::cmd::layout) fn update(s: &mut Session, p: &Value) -> CmdResult { if let (Some((_, Some(_))), Some(v)) = (§ions, p.get("section")) { said.extend(held_width(v, "section width", rustgis_map::layout::SECTION_WIDTHS)); } - if let (ElementKind::MapFrame { .. }, Some(Some(_))) = (kind, &indicator) - && let Some(v) = p.get("extentIndicator") + if let (ElementKind::MapFrame { .. }, Some(v @ Value::Object(_))) = (kind, p.get("extentIndicator")) + && v.get("remove") != Some(&Value::Bool(true)) { let range = (rustgis_map::layout::MIN_INDICATOR_WIDTH, rustgis_map::layout::MAX_INDICATOR_WIDTH); said.extend(held_width(v, "extent indicator width", range)); @@ -563,6 +589,9 @@ pub(in crate::cmd::layout) fn update(s: &mut Session, p: &Value) -> CmdResult { (*dir, *head) = (d, hd); } } + if let Some(indicators) = new_indicator { + e.kind.set_extent_indicators(indicators); + } match &mut e.kind { ElementKind::Text { text, @@ -691,29 +720,10 @@ pub(in crate::cmd::layout) fn update(s: &mut Session, p: &Value) -> CmdResult { *reverse = v; } } - ElementKind::MapFrame { - map, - center, - scale, - grid, - bearing, - pitch, - extent_of, - extent_color, - extent_width, - border_color, - border_width, - sections, - .. - } => { + ElementKind::MapFrame { map, center, scale, grid, bearing, pitch, border_color, border_width, sections, .. } => { if let Some((new, _)) = &new_sections { sections.clone_from(new); } - match new_indicator { - Some(None) => *extent_of = None, - Some(Some((c, w))) => (*extent_color, *extent_width) = (c, w), - None => {} - } if let Some((c, w)) = new_border { (*border_color, *border_width) = (c, w); } diff --git a/crates/engine/src/cmd/presentation.rs b/crates/engine/src/cmd/presentation.rs index 7526c486b5..0d513c9c25 100644 --- a/crates/engine/src/cmd/presentation.rs +++ b/crates/engine/src/cmd/presentation.rs @@ -413,6 +413,7 @@ pub fn page_layout(s: &Session, pres: &Presentation, page: &Page) -> Layout { extent_of: None, extent_color: rustgis_map::layout::INDICATOR_COLOR, extent_width: rustgis_map::layout::INDICATOR_WIDTH, + more_extents: Vec::new(), border_color: rustgis_map::layout::FRAME_BORDER_COLOR, border_width: rustgis_map::layout::FRAME_BORDER_WIDTH, bearing: 0.0, diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index 19b0d13216..91cc426d6c 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -127,6 +127,7 @@ pub const CAPABILITIES: &[&str] = &[ "layout-legend-counts", "layout-legend-subtitle", "layout-legend-nested-sizes", + "layout-extent-indicators", "layout-legend-order", "layout-scale-bar-details", "label-guide", diff --git a/crates/engine/src/project_capabilities.rs b/crates/engine/src/project_capabilities.rs index 93bc9c57af..464b502c56 100644 --- a/crates/engine/src/project_capabilities.rs +++ b/crates/engine/src/project_capabilities.rs @@ -181,6 +181,7 @@ const COMMAND_CAPABILITIES: &[(&str, CommandCheck)] = &[ ("layout-legend-counts", command_uses_legend_counts), ("layout-legend-subtitle", command_uses_legend_subtitle), ("layout-legend-nested-sizes", command_uses_legend_nested_sizes), + ("layout-extent-indicators", command_uses_extent_indicators), ("layout-legend-order", command_uses_legend_order), ("layout-scale-bar-details", command_uses_scale_bar_details), ("dggs-system", command_uses_dggs_system), @@ -610,6 +611,27 @@ fn command_uses_legend_subtitle(id: &str, params: &Value) -> bool { } } +/// A layout command that may give a frame more than one extent indicator, or names one of +/// several (#3394): an older reader replaces the indicator on adding another, and ignores `of` +/// and `remove`. A saved command can't tell what its frame outlines already, so every indicator +/// added needs it. +fn command_uses_extent_indicators(id: &str, params: &Value) -> bool { + match id { + "layout.addElement" => params.get("kind").and_then(Value::as_str) == Some("extentIndicator"), + "layout.update" => { + params.get("extentIndicator").is_some_and(|v| ["of", "remove"].iter().any(|k| v.get(k).is_some_and(|v| !v.is_null()))) + } + "layout.import" | "report.existingTemplate" => imported_layout_uses(params, &["\"more_extents\""], extent_indicators_features), + "script.run" => params.get("script").and_then(Value::as_str).is_some_and(|s| script_uses(s, command_uses_extent_indicators)), + _ => false, + } +} + +/// Whether a layout element is a map frame that outlines more than one other frame. +fn extent_indicators_features(e: &rustgis_map::layout::Element) -> bool { + e.kind.has_more_extents() +} + /// A layout command that nests a legend's sizes (#3347): an older reader ignores `sizes`, and a /// legend saved with it, drawing rows. `"rows"` and `null` ask for what it draws. fn command_uses_legend_nested_sizes(id: &str, params: &Value) -> bool { @@ -1531,6 +1553,7 @@ fn layout_capabilities(layouts: &[rustgis_map::layout::Layout]) -> Vec<&'static (elements().any(legend_counts_features), "layout-legend-counts"), (elements().any(legend_subtitle_features), "layout-legend-subtitle"), (elements().any(legend_nested_sizes_features), "layout-legend-nested-sizes"), + (elements().any(extent_indicators_features), "layout-extent-indicators"), (elements().any(legend_orders_layers), "layout-legend-order"), (elements().any(bar_details), "layout-scale-bar-details"), (layouts.iter().any(|l| l.paper.is_some()), "layout-page-color"), @@ -1908,6 +1931,7 @@ mod tests { (&["layout-legend-class-labels"], "layout.update", json!({"element": 1, "classLabels": {"a": {"x": "X"}}})), (&["layout-legend-counts"], "layout.update", json!({"element": 1, "showCounts": true})), (&["layout-legend-nested-sizes"], "layout.update", json!({"element": 1, "sizes": "nested"})), + (&["layout-extent-indicators"], "layout.addElement", json!({"kind": "extentIndicator", "frame": 1, "of": 2})), (&["layout-legend-subtitle"], "layout.update", json!({"element": 1, "subtitle": "a"})), (&["layout-legend-order"], "layout.update", json!({"element": 1, "layerOrder": ["a"]})), (&["dggs-system"], "a5Grid", json!({"system": "H3"})), diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 2eee97bc4a..f11873796b 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -172,6 +172,9 @@ mod layout_publication_locators; #[path = "tests/layout_publication_crs.rs"] mod layout_publication_crs; +#[path = "tests/layout_extents.rs"] +mod layout_extents; + #[path = "tests/sde_connections.rs"] mod sde_connections; diff --git a/crates/engine/src/tests/archive_render_revision.rs b/crates/engine/src/tests/archive_render_revision.rs index 2bc9e89072..863b426864 100644 --- a/crates/engine/src/tests/archive_render_revision.rs +++ b/crates/engine/src/tests/archive_render_revision.rs @@ -148,6 +148,7 @@ fn page(map: &Map) -> map::layout::Layout { extent_of: None, extent_color: map::Rgba::rgb(0, 0, 0), extent_width: 1.0, + more_extents: Vec::new(), border_color: rustgis_map::layout::FRAME_BORDER_COLOR, border_width: rustgis_map::layout::FRAME_BORDER_WIDTH, bearing: 0.0, diff --git a/crates/engine/src/tests/layout_extents.rs b/crates/engine/src/tests/layout_extents.rs new file mode 100644 index 0000000000..feb7622171 --- /dev/null +++ b/crates/engine/src/tests/layout_extents.rs @@ -0,0 +1,217 @@ +//! A map frame that outlines several other frames: one extent indicator each (#3394). + +use super::*; +use rustgis_map::layout::ElementKind; + +const BLUE: &str = "#1F4E9A"; + +/// A world layout with an overview frame and `n` more frames for it to outline. +fn laid_out(n: usize) -> (Session, u64, Vec) { + let mut s = world(); + s.run("layout.new", &json!({"template": "map"})).unwrap(); + let mut frame = || { + s.run("layout.addFrame", &json!({"shape": "rectangle", "x": 10, "y": 10, "w": 40, "h": 30})).unwrap()["element"].as_u64().unwrap() + }; + let overview = frame(); + let others = (0..n).map(|_| frame()).collect(); + (s, overview, others) +} + +fn add(s: &mut Session, frame: u64, of: u64) { + s.run("layout.addElement", &json!({"kind": "extentIndicator", "frame": frame, "of": of})).unwrap(); +} + +fn update(s: &mut Session, frame: u64, indicator: Value) -> Result { + s.run("layout.update", &json!({"element": frame, "extentIndicator": indicator})).map_err(|e| e.to_string()) +} + +/// The frames `frame` outlines, in order, as (frame, colour, width in points). +fn outlined(s: &Session, frame: u64) -> Vec<(u64, String, f64)> { + let kind = &s.project.layouts[0].element(frame as u32).unwrap().kind; + assert!(matches!(kind, ElementKind::MapFrame { .. })); + kind.extent_indicators().iter().map(|i| (i.of.into(), i.color.hex(), i.width)).collect() +} + +/// The frames `frame` outlines, in order. +fn frames(s: &Session, frame: u64) -> Vec { + outlined(s, frame).into_iter().map(|i| i.0).collect() +} + +#[test] +fn a_second_indicator_is_added_beside_the_first() { + let (mut s, overview, of) = laid_out(2); + add(&mut s, overview, of[0]); + s.run("layout.addElement", &json!({"kind": "extentIndicator", "frame": overview, "of": of[0], "color": "#1F4E9A", "width": 1})) + .unwrap(); + let depth = s.undo_depth(); + add(&mut s, overview, of[1]); + // The new one has the default look; the first keeps its own. + assert_eq!(outlined(&s, overview), [(of[0], BLUE.into(), 1.0), (of[1], "#D01C1C".into(), 2.0)]); + assert_eq!(s.undo_depth(), depth + 1); + s.run("edit.undo", &Value::Null).unwrap(); + assert_eq!(frames(&s, overview), [of[0]]); +} + +#[test] +fn a_frame_outlined_already_is_restyled_not_repeated() { + let (mut s, overview, of) = laid_out(2); + add(&mut s, overview, of[0]); + add(&mut s, overview, of[1]); + s.run("layout.addElement", &json!({"kind": "extentIndicator", "frame": overview, "of": of[1], "color": "#1F4E9A"})).unwrap(); + assert_eq!(frames(&s, overview), [of[0], of[1]]); + assert_eq!(outlined(&s, overview)[1], (of[1], BLUE.into(), 2.0)); +} + +#[test] +fn a_frame_outlines_at_most_sixteen() { + let (mut s, overview, of) = laid_out(17); + for &o in &of[..16] { + add(&mut s, overview, o); + } + let before = serde_json::to_value(&s.project).unwrap(); + let err = s.run("layout.addElement", &json!({"kind": "extentIndicator", "frame": overview, "of": of[16]})).unwrap_err().to_string(); + assert!(err.contains("at most 16"), "{err}"); + assert_eq!(serde_json::to_value(&s.project).unwrap(), before); + // One outlined already is still restyled. + s.run("layout.addElement", &json!({"kind": "extentIndicator", "frame": overview, "of": of[15], "width": 3})).unwrap(); +} + +#[test] +fn update_restyles_and_removes_the_indicator_it_names() { + let (mut s, overview, of) = laid_out(3); + for &o in &of { + add(&mut s, overview, o); + } + update(&mut s, overview, json!({"of": of[1], "width": 3})).unwrap(); + assert_eq!(outlined(&s, overview).iter().map(|i| i.2).collect::>(), [2.0, 3.0, 2.0]); + update(&mut s, overview, json!({"of": of[0], "remove": true})).unwrap(); + assert_eq!(frames(&s, overview), [of[1], of[2]]); + assert_eq!(outlined(&s, overview)[0].2, 3.0); + s.run("edit.undo", &Value::Null).unwrap(); + assert_eq!(frames(&s, overview), of); + update(&mut s, overview, json!(false)).unwrap(); + assert!(frames(&s, overview).is_empty()); + s.run("edit.undo", &Value::Null).unwrap(); + assert_eq!(frames(&s, overview), of); +} + +#[test] +fn update_without_of_changes_a_frames_only_indicator() { + let (mut s, overview, of) = laid_out(1); + add(&mut s, overview, of[0]); + update(&mut s, overview, json!({"color": "#1F4E9A"})).unwrap(); + assert_eq!(outlined(&s, overview), [(of[0], BLUE.into(), 2.0)]); + update(&mut s, overview, json!({"remove": true})).unwrap(); + assert!(frames(&s, overview).is_empty()); +} + +#[test] +fn update_refuses_what_it_cannot_tell_and_changes_nothing() { + let (mut s, overview, of) = laid_out(3); + add(&mut s, overview, of[0]); + add(&mut s, overview, of[1]); + for (indicator, said) in [ + (json!({"color": "#1F4E9A"}), "say which with of"), + (json!({"remove": true}), "say which with of"), + (json!({"of": of[2], "width": 3}), "doesn't outline"), + (json!({"of": of[2], "remove": true}), "doesn't outline"), + (json!({"of": "first", "width": 3}), "of is the id"), + (json!({"of": of[0], "remove": "yes"}), "remove is true or false"), + ] { + let before = serde_json::to_value(&s.project).unwrap(); + let err = update(&mut s, overview, indicator.clone()).expect_err(&indicator.to_string()); + assert!(err.contains(said), "{indicator}: {err}"); + assert_eq!(serde_json::to_value(&s.project).unwrap(), before, "{indicator}"); + } +} + +#[test] +fn removing_an_outlined_frame_keeps_the_other_indicators() { + let (mut s, overview, of) = laid_out(3); + for &o in &of { + add(&mut s, overview, o); + } + update(&mut s, overview, json!({"of": of[1], "color": "#1F4E9A"})).unwrap(); + s.run("layout.removeElement", &json!({"element": of[0]})).unwrap(); + assert_eq!(frames(&s, overview), [of[1], of[2]]); + assert_eq!(outlined(&s, overview)[0].1, BLUE); + s.run("edit.undo", &Value::Null).unwrap(); + assert_eq!(frames(&s, overview), of); +} + +#[test] +fn one_indicator_is_saved_as_before() { + let (mut s, overview, of) = laid_out(2); + add(&mut s, overview, of[0]); + let saved = serde_json::to_value(&s.project).unwrap(); + assert!(!saved.to_string().contains("more_extents")); + assert!(saved["requires"].as_array().is_none_or(|r| !r.contains(&json!("layout-extent-indicators")))); +} + +#[test] +fn several_indicators_survive_a_save_and_require_their_capability() { + let (mut s, overview, of) = laid_out(2); + add(&mut s, overview, of[0]); + add(&mut s, overview, of[1]); + let text = serde_json::to_string(&s.project).unwrap(); + let saved: Value = serde_json::from_str(&text).unwrap(); + assert!(saved["requires"].as_array().unwrap().contains(&json!("layout-extent-indicators"))); + let again: Project = serde_json::from_str(&text).unwrap(); + assert_eq!(serde_json::to_string(&again).unwrap(), text); + let layout = serde_json::to_string(&s.project.layouts[0]).unwrap(); + let requires = |id: &str, params: Value| { + let mut p = Project::default(); + p.tasks.push( + serde_json::from_value(json!({"name": "t", "title": "t", "steps": [{"title": "s", "command": id, "params": params}]})).unwrap(), + ); + serde_json::to_value(&p).unwrap()["requires"].as_array().is_some_and(|r| r.contains(&json!("layout-extent-indicators"))) + }; + // A saved command can't tell whether the frame outlines another already, so any added needs it. + assert!(requires("layout.addElement", json!({"kind": "extentIndicator", "of": 2}))); + assert!(requires("layout.update", json!({"element": 1, "extentIndicator": {"of": 2, "width": 1}}))); + assert!(requires("layout.update", json!({"element": 1, "extentIndicator": {"remove": true}}))); + assert!(requires("layout.import", json!({"text": layout}))); + assert!(!requires("layout.update", json!({"element": 1, "extentIndicator": {"width": 1}}))); + assert!(!requires("layout.update", json!({"element": 1, "extentIndicator": false}))); + assert!(!requires("layout.addElement", json!({"kind": "northArrow"}))); +} + +#[test] +fn each_indicator_is_drawn_in_its_own_colour() { + let (mut s, overview, of) = laid_out(2); + // The overview shows far more ground than the two it outlines, which sit apart. + s.run("layout.update", &json!({"element": overview, "scale": 400_000_000, "center": [0, 0]})).unwrap(); + for (frame, lon) in of.iter().zip([-30, 30]) { + s.run("layout.update", &json!({"element": frame, "scale": 100_000_000, "center": [lon, 0]})).unwrap(); + } + for (frame, color) in of.iter().zip(["#FF00FF", "#00FFFF"]) { + s.run("layout.addElement", &json!({"kind": "extentIndicator", "frame": overview, "of": frame, "color": color, "width": 4})) + .unwrap(); + } + // The overview alone, so no other element's pixels are counted. + let mut page = s.project.layouts[0].clone(); + page.elements.iter_mut().for_each(|e| e.visible = u64::from(e.id) == overview || of.contains(&e.id.into())); + page.elements.iter_mut().filter(|e| of.contains(&e.id.into())).for_each(|e| (e.x, e.y) = (4000.0, 4000.0)); + let info = crate::render::layout::PageInfo { page: 1, pages: 1, page_name: String::new() }; + let pm = crate::render::layout::render(&page, &mut s.project.maps, 96.0, &info).unwrap(); + for rgb in [[255, 0, 255], [0, 255, 255]] { + assert!(pm.pixels().iter().any(|p| [p.red(), p.green(), p.blue()] == rgb), "{rgb:?}"); + } +} + +#[test] +fn a_files_orphan_and_repeated_indicators_are_dropped() { + let (mut s, overview, of) = laid_out(2); + add(&mut s, overview, of[0]); + let mut layout = serde_json::to_value(&s.project.layouts[0]).unwrap(); + let frame = layout["elements"].as_array_mut().unwrap().iter_mut().find(|e| e["id"] == overview).unwrap(); + let kind = &mut frame["kind"]["MapFrame"]; + // The first points nowhere; the rest hold itself, a missing frame, the same frame twice and a + // width past the limit. + kind["extent_of"] = json!(999); + kind["more_extents"] = json!([{"of": overview}, {"of": 998}, {"of": of[1], "width": 99}, {"of": of[1]}, {"of": of[0]}]); + let mut other = Session::new(Project::default()); + other.run("layout.import", &json!({"text": layout.to_string()})).unwrap(); + assert_eq!(frames(&other, overview), [of[1], of[0]]); + assert_eq!(outlined(&other, overview)[0].2, rustgis_map::layout::MAX_INDICATOR_WIDTH); +} diff --git a/crates/engine/src/tests/layout_files.rs b/crates/engine/src/tests/layout_files.rs index b71d2a153b..137f5585ce 100644 --- a/crates/engine/src/tests/layout_files.rs +++ b/crates/engine/src/tests/layout_files.rs @@ -132,6 +132,7 @@ fn a_saved_layout_file_requires_what_its_elements_use_and_reads_back_the_same() ("legend-counts", include_str!("../../../../schema/fixtures/layout_legend_counts.rgis")), ("legend-subtitle", include_str!("../../../../schema/fixtures/layout_legend_subtitle.rgis")), ("legend-nested-sizes", include_str!("../../../../schema/fixtures/layout_legend_nested_sizes.rgis")), + ("extent-indicators", include_str!("../../../../schema/fixtures/layout_extent_indicators.rgis")), ("legend-order", include_str!("../../../../schema/fixtures/layout_legend_order.rgis")), ("scale-grid-text", include_str!("../../../../schema/fixtures/layout_scale_grid_text.rgis")), ("page-color", include_str!("../../../../schema/fixtures/layout_page_color.rgis")), diff --git a/crates/map/src/layout.rs b/crates/map/src/layout.rs index 7c052fa979..e617fbc441 100644 --- a/crates/map/src/layout.rs +++ b/crates/map/src/layout.rs @@ -455,10 +455,10 @@ impl Layout { let before = self.elements.len(); self.elements.retain(|e| e.id != id && e.kind.frame() != Some(id)); for e in &mut self.elements { - if let ElementKind::MapFrame { extent_of, .. } = &mut e.kind - && *extent_of == Some(id) - { - *extent_of = None; + let mut indicators = e.kind.extent_indicators(); + if indicators.iter().any(|i| i.of == id) { + indicators.retain(|i| i.of != id); + e.kind.set_extent_indicators(indicators); } } if self.series.as_ref().is_some_and(|s| s.frame == id) { @@ -567,7 +567,23 @@ impl Layout { let mut cut = e.name.chars().nth(200).is_some(); e.name = e.name.chars().take(200).collect(); match &mut e.kind { - ElementKind::MapFrame { center, scale, shape, grid, sections, bearing, pitch, extent_width, border_width, .. } => { + ElementKind::MapFrame { + center, + scale, + shape, + grid, + sections, + bearing, + pitch, + extent_width, + more_extents, + border_width, + .. + } => { + let held = |w: f64| finite_or(w, INDICATOR_WIDTH).clamp(MIN_INDICATOR_WIDTH, MAX_INDICATOR_WIDTH); + for i in more_extents { + i.width = held(i.width); + } *scale = finite_or(*scale, 50_000_000.0).clamp(MIN_FRAME_SCALE, MAX_FRAME_SCALE); *extent_width = finite_or(*extent_width, INDICATOR_WIDTH).clamp(MIN_INDICATOR_WIDTH, MAX_INDICATOR_WIDTH); *border_width = finite_or(*border_width, FRAME_BORDER_WIDTH).clamp(0.0, MAX_FRAME_BORDER_WIDTH); @@ -741,15 +757,25 @@ impl Layout { let boxes = self.frame_boxes(); let (mut adjusted, mut cut_count) = (0usize, 0usize); let elements = std::mem::take(&mut self.elements); - for (mut e, (mut changed, cut)) in elements.into_iter().zip(changed) { + for (mut e, (mut changed, mut cut)) in elements.into_iter().zip(changed) { if e.kind.frame().is_some_and(|f| !frames.contains(&f)) { continue; } - if let ElementKind::MapFrame { extent_of, .. } = &mut e.kind - && extent_of.is_some_and(|o| !frames.contains(&o) || o == e.id) - { - *extent_of = None; - changed = true; + // An indicator outlines another map frame, once; a file's further ones past the limit + // are cut. + let mut indicators = e.kind.extent_indicators(); + let mut outlined = std::collections::HashSet::new(); + indicators.retain(|i| i.of != e.id && frames.contains(&i.of) && outlined.insert(i.of)); + cut |= indicators.len() > MAX_EXTENT_INDICATORS; + indicators.truncate(MAX_EXTENT_INDICATORS); + if matches!(e.kind, ElementKind::MapFrame { .. }) { + // Set on a copy and compared: the first left goes in the first's fields. + let mut held = e.kind.clone(); + held.set_extent_indicators(indicators); + if held != e.kind { + e.kind = held; + changed = true; + } } if let ElementKind::Profile(p) = &e.kind && let Some(frame) = boxes.get(&p.frame) diff --git a/crates/map/src/layout/elements.rs b/crates/map/src/layout/elements.rs index a43112b99a..3c0ca049a9 100644 --- a/crates/map/src/layout/elements.rs +++ b/crates/map/src/layout/elements.rs @@ -27,6 +27,12 @@ pub enum ElementKind { extent_color: Rgba, #[serde(default = "indicator_width", skip_serializing_if = "is_indicator_width")] extent_width: f64, + /// The further frames it outlines (#3394), after `extent_of`'s: read and set the whole + /// list with [`ElementKind::extent_indicators`] and + /// [`ElementKind::set_extent_indicators`]. The first stays in the fields above, and this + /// is left out when empty, so a frame with one indicator keeps its bytes. + #[serde(default, skip_serializing_if = "Vec::is_empty")] + more_extents: Vec, /// The outline drawn round the frame, along its shape: its colour and width (points), 0 /// for none (#2557). Dark grey and 0.8 unless set, and left out then, so layouts saved /// before keep their bytes. @@ -622,6 +628,31 @@ impl ElementKind { if !is_frame_border_color(border_color) || !is_frame_border_width(border_width)) } + /// The frames a map frame outlines, in order; none for another kind. + pub fn extent_indicators(&self) -> Vec { + let ElementKind::MapFrame { extent_of, extent_color, extent_width, more_extents, .. } = self else { return Vec::new() }; + let first = extent_of.map(|of| ExtentIndicator { of, color: *extent_color, width: *extent_width }); + first.into_iter().chain(more_extents.iter().copied()).collect() + } + + /// Sets the frames a map frame outlines. Emptied, the first one's look is kept for the next + /// one added. + pub fn set_extent_indicators(&mut self, indicators: Vec) { + let ElementKind::MapFrame { extent_of, extent_color, extent_width, more_extents, .. } = self else { return }; + let mut rest = indicators.into_iter(); + let first = rest.next(); + *extent_of = first.map(|i| i.of); + if let Some(i) = first { + (*extent_color, *extent_width) = (i.color, i.width); + } + *more_extents = rest.collect(); + } + + /// Whether it is a map frame that outlines more than one other frame (#3394). + pub fn has_more_extents(&self) -> bool { + matches!(self, ElementKind::MapFrame { more_extents, .. } if !more_extents.is_empty()) + } + /// Whether it is a map frame with section lines (#2863). pub fn has_sections(&self) -> bool { matches!(self, ElementKind::MapFrame { sections, .. } if !sections.is_empty()) diff --git a/crates/map/src/layout/frame.rs b/crates/map/src/layout/frame.rs index ba2023a1b0..2d424acc33 100644 --- a/crates/map/src/layout/frame.rs +++ b/crates/map/src/layout/frame.rs @@ -42,6 +42,19 @@ pub const INDICATOR_WIDTH: f64 = 2.0; /// The narrowest and widest an extent indicator's outline may be (points); to hide it, remove it. pub const MIN_INDICATOR_WIDTH: f64 = 0.1; pub const MAX_INDICATOR_WIDTH: f64 = 20.0; +/// The most frames one map frame outlines (#3394). +pub const MAX_EXTENT_INDICATORS: usize = 16; + +/// The outline of another frame's extent in a map frame: which frame, and its colour and width +/// (points). +#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)] +pub struct ExtentIndicator { + pub of: u32, + #[serde(default = "indicator_color", skip_serializing_if = "is_indicator_color")] + pub color: Rgba, + #[serde(default = "indicator_width", skip_serializing_if = "is_indicator_width")] + pub width: f64, +} /// A map frame's border until it is set (#2557): dark grey, 0.8 points. pub const FRAME_BORDER_COLOR: Rgba = Rgba::rgb(0x30, 0x30, 0x30); diff --git a/crates/map/src/layout/tests.rs b/crates/map/src/layout/tests.rs index b927e570c3..b4c976a47e 100644 --- a/crates/map/src/layout/tests.rs +++ b/crates/map/src/layout/tests.rs @@ -852,6 +852,7 @@ fn elements_add_hit_and_remove_with_surrounds() { extent_of: None, extent_color: INDICATOR_COLOR, extent_width: INDICATOR_WIDTH, + more_extents: Vec::new(), border_color: FRAME_BORDER_COLOR, border_width: FRAME_BORDER_WIDTH, bearing: 0.0, @@ -1306,6 +1307,7 @@ fn mgrs_labels_need_a_wgs84_utm_zone() { extent_of: None, extent_color: INDICATOR_COLOR, extent_width: INDICATOR_WIDTH, + more_extents: Vec::new(), border_color: FRAME_BORDER_COLOR, border_width: FRAME_BORDER_WIDTH, bearing: 0.0, @@ -2100,6 +2102,7 @@ fn a_profile_keeps_to_its_frames_side() { extent_of: None, extent_color: INDICATOR_COLOR, extent_width: INDICATOR_WIDTH, + more_extents: Vec::new(), border_color: FRAME_BORDER_COLOR, border_width: FRAME_BORDER_WIDTH, bearing: 0.0, diff --git a/crates/render/src/layout.rs b/crates/render/src/layout.rs index ff11aab193..3dc3e54d1e 100644 --- a/crates/render/src/layout.rs +++ b/crates/render/src/layout.rs @@ -426,7 +426,7 @@ fn draw_page( ((e.x * k - f64::from(bounds.x())) as f32, (e.y * k - f64::from(bounds.y())) as f32, (e.w * k) as f32, (e.h * k) as f32); let Some(r) = Rect::from_xywh(x, y, ew.max(1.0), eh.max(1.0)) else { continue }; match &e.kind { - ElementKind::MapFrame { shape, grid, sections, extent_of, extent_color, extent_width, border_color, border_width, .. } => { + ElementKind::MapFrame { shape, grid, sections, border_color, border_width, .. } => { let Some(&(_, mi, cam, fw, fh)) = frame(e.id) else { placeholder(&mut pm, r, "Missing map", ppp); continue; @@ -464,13 +464,16 @@ fn draw_page( list.push((e.id, e.name.clone())); } } - if let Some(other) = extent_of.and_then(frame) - && let Some(om) = maps.get(other.1) - { - let ring = frame_outline_lonlat(om, &other.2, other.3, other.4); - if let Some(map) = maps.get(mi) { - let from_globe = om.projection.is_globe(); - outline_lonlat(&mut frame_pm, map, &view, &ring, from_globe, *extent_color, *extent_width as f32); + // The extent indicators, in order, a later one over an earlier one. + for i in e.kind.extent_indicators() { + if let Some(other) = frame(i.of) + && let Some(om) = maps.get(other.1) + { + let ring = frame_outline_lonlat(om, &other.2, other.3, other.4); + if let Some(map) = maps.get(mi) { + let from_globe = om.projection.is_globe(); + outline_lonlat(&mut frame_pm, map, &view, &ring, from_globe, i.color, i.width as f32); + } } } // Whole pixels, so the clipped image and its outline line up. diff --git a/crates/render/src/layout/legend/count_tests.rs b/crates/render/src/layout/legend/count_tests.rs index 7c84f9743e..4083fbf3c2 100644 --- a/crates/render/src/layout/legend/count_tests.rs +++ b/crates/render/src/layout/legend/count_tests.rs @@ -371,6 +371,7 @@ fn counts_page(all_classes: bool) -> rustgis_map::layout::Layout { extent_of: None, extent_color: rustgis_map::layout::INDICATOR_COLOR, extent_width: rustgis_map::layout::INDICATOR_WIDTH, + more_extents: Vec::new(), border_color: rustgis_map::layout::FRAME_BORDER_COLOR, border_width: rustgis_map::layout::FRAME_BORDER_WIDTH, }, diff --git a/crates/render/src/layout/profile_tests.rs b/crates/render/src/layout/profile_tests.rs index 966246b7e6..d69e9c53f8 100644 --- a/crates/render/src/layout/profile_tests.rs +++ b/crates/render/src/layout/profile_tests.rs @@ -31,6 +31,7 @@ fn frame_kind(sections: Vec
, bearing: f64, pitch: f64) -> ElementKind { extent_of: None, extent_color: INDICATOR_COLOR, extent_width: INDICATOR_WIDTH, + more_extents: Vec::new(), border_color: FRAME_BORDER_COLOR, border_width: FRAME_BORDER_WIDTH, bearing, diff --git a/crates/render/src/layout/tests.rs b/crates/render/src/layout/tests.rs index 2e642c0be4..a568bcdd32 100644 --- a/crates/render/src/layout/tests.rs +++ b/crates/render/src/layout/tests.rs @@ -3001,6 +3001,7 @@ fn colorbar_page(map: &Map, orientation: Orientation, reverse: bool, title: &str extent_of: None, extent_color: rustgis_map::layout::INDICATOR_COLOR, extent_width: rustgis_map::layout::INDICATOR_WIDTH, + more_extents: Vec::new(), border_color: rustgis_map::layout::FRAME_BORDER_COLOR, border_width: rustgis_map::layout::FRAME_BORDER_WIDTH, bearing: 0.0, @@ -3150,6 +3151,7 @@ fn page_settles_with_suns(suns: &[f64]) { extent_of: None, extent_color: rustgis_map::layout::INDICATOR_COLOR, extent_width: rustgis_map::layout::INDICATOR_WIDTH, + more_extents: Vec::new(), border_color: rustgis_map::layout::FRAME_BORDER_COLOR, border_width: rustgis_map::layout::FRAME_BORDER_WIDTH, bearing: 0.0, @@ -3225,6 +3227,7 @@ fn a_reliefs_shadow_softness_changes_its_page_only_off_the_default() { extent_of: None, extent_color: rustgis_map::layout::INDICATOR_COLOR, extent_width: rustgis_map::layout::INDICATOR_WIDTH, + more_extents: Vec::new(), border_color: rustgis_map::layout::FRAME_BORDER_COLOR, border_width: rustgis_map::layout::FRAME_BORDER_WIDTH, bearing: 0.0, @@ -3319,6 +3322,7 @@ fn a_reliefs_terrain_type_changes_its_frames_contrast_not_its_colour_bar() { extent_of: None, extent_color: rustgis_map::layout::INDICATOR_COLOR, extent_width: rustgis_map::layout::INDICATOR_WIDTH, + more_extents: Vec::new(), border_color: rustgis_map::layout::FRAME_BORDER_COLOR, border_width: rustgis_map::layout::FRAME_BORDER_WIDTH, bearing: 0.0, @@ -3490,6 +3494,7 @@ fn indicator_page(color: Rgba, width: f64) -> Pixmap { extent_of, extent_color: color, extent_width: width, + more_extents: Vec::new(), border_color: rustgis_map::layout::FRAME_BORDER_COLOR, border_width: rustgis_map::layout::FRAME_BORDER_WIDTH, bearing: 0.0, @@ -4515,6 +4520,7 @@ fn a_map_frame_border_takes_its_colour_and_width_or_none() { extent_of: None, extent_color: INDICATOR_COLOR, extent_width: INDICATOR_WIDTH, + more_extents: Vec::new(), border_color, border_width, bearing: 0.0, @@ -4578,6 +4584,7 @@ fn an_extent_indicator_on_a_globe_lands_on_the_area() { extent_of, extent_color: INDICATOR_COLOR, extent_width: INDICATOR_WIDTH, + more_extents: Vec::new(), border_color: rustgis_map::layout::FRAME_BORDER_COLOR, border_width: rustgis_map::layout::FRAME_BORDER_WIDTH, bearing: 0.0, @@ -4628,6 +4635,7 @@ fn a_frame_on_the_globe_is_outlined_by_what_it_shows() { extent_of, extent_color: INDICATOR_COLOR, extent_width: INDICATOR_WIDTH, + more_extents: Vec::new(), border_color: rustgis_map::layout::FRAME_BORDER_COLOR, border_width: rustgis_map::layout::FRAME_BORDER_WIDTH, bearing: 0.0, @@ -4683,6 +4691,7 @@ fn a_frame_partly_off_the_globe_is_outlined_without_a_chord() { extent_of, extent_color: INDICATOR_COLOR, extent_width: INDICATOR_WIDTH, + more_extents: Vec::new(), border_color: rustgis_map::layout::FRAME_BORDER_COLOR, border_width: rustgis_map::layout::FRAME_BORDER_WIDTH, bearing: 0.0, @@ -4757,6 +4766,7 @@ fn a_globe_frame_across_the_antimeridian_is_outlined_in_one_piece() { extent_of, extent_color: INDICATOR_COLOR, extent_width: INDICATOR_WIDTH, + more_extents: Vec::new(), border_color: rustgis_map::layout::FRAME_BORDER_COLOR, border_width: rustgis_map::layout::FRAME_BORDER_WIDTH, bearing: 0.0, @@ -4802,6 +4812,7 @@ fn outline_on(map: Map, source: (Coord, f64, f64, f64), locator: Map, view: (Coo extent_of, extent_color: INDICATOR_COLOR, extent_width: INDICATOR_WIDTH, + more_extents: Vec::new(), border_color: rustgis_map::layout::FRAME_BORDER_COLOR, border_width: rustgis_map::layout::FRAME_BORDER_WIDTH, bearing: 0.0, @@ -5002,6 +5013,7 @@ fn a_flat_frame_wider_than_the_world_is_outlined_where_it_is() { extent_of, extent_color: INDICATOR_COLOR, extent_width: INDICATOR_WIDTH, + more_extents: Vec::new(), border_color: rustgis_map::layout::FRAME_BORDER_COLOR, border_width: rustgis_map::layout::FRAME_BORDER_WIDTH, bearing: 0.0, @@ -5317,6 +5329,7 @@ fn colorbars_draw_the_raster_colour_scale() { extent_of: None, extent_color: rustgis_map::layout::INDICATOR_COLOR, extent_width: rustgis_map::layout::INDICATOR_WIDTH, + more_extents: Vec::new(), border_color: rustgis_map::layout::FRAME_BORDER_COLOR, border_width: rustgis_map::layout::FRAME_BORDER_WIDTH, bearing: 0.0, @@ -5440,6 +5453,7 @@ fn grid_page(grid: rustgis_map::layout::Grid) -> Pixmap { extent_of: None, extent_color: rustgis_map::layout::INDICATOR_COLOR, extent_width: rustgis_map::layout::INDICATOR_WIDTH, + more_extents: Vec::new(), border_color: rustgis_map::layout::FRAME_BORDER_COLOR, border_width: rustgis_map::layout::FRAME_BORDER_WIDTH, bearing: 0.0, @@ -5482,6 +5496,7 @@ fn winterthur_page(grid: rustgis_map::layout::Grid, projection: rustgis_map::Pro extent_of: None, extent_color: rustgis_map::layout::INDICATOR_COLOR, extent_width: rustgis_map::layout::INDICATOR_WIDTH, + more_extents: Vec::new(), border_color: rustgis_map::layout::FRAME_BORDER_COLOR, border_width: rustgis_map::layout::FRAME_BORDER_WIDTH, bearing: 0.0, @@ -5739,6 +5754,7 @@ fn a_measured_grid_on_the_globe_seen_whole_is_drawn() { extent_of: None, extent_color: rustgis_map::layout::INDICATOR_COLOR, extent_width: rustgis_map::layout::INDICATOR_WIDTH, + more_extents: Vec::new(), border_color: rustgis_map::layout::FRAME_BORDER_COLOR, border_width: rustgis_map::layout::FRAME_BORDER_WIDTH, bearing: 0.0, @@ -5774,6 +5790,7 @@ fn a_grid_on_the_globe_is_drawn_on_it() { extent_of: None, extent_color: rustgis_map::layout::INDICATOR_COLOR, extent_width: rustgis_map::layout::INDICATOR_WIDTH, + more_extents: Vec::new(), border_color: rustgis_map::layout::FRAME_BORDER_COLOR, border_width: rustgis_map::layout::FRAME_BORDER_WIDTH, bearing: 0.0, @@ -6686,6 +6703,7 @@ fn colour_test_page() -> (Vec, Layout, u32) { extent_of: None, extent_color: rustgis_map::layout::INDICATOR_COLOR, extent_width: rustgis_map::layout::INDICATOR_WIDTH, + more_extents: Vec::new(), border_color: rustgis_map::layout::FRAME_BORDER_COLOR, border_width: rustgis_map::layout::FRAME_BORDER_WIDTH, bearing: 0.0, @@ -8509,6 +8527,7 @@ fn section_lines_are_drawn_over_their_frame() { extent_of: None, extent_color: INDICATOR_COLOR, extent_width: INDICATOR_WIDTH, + more_extents: Vec::new(), border_color: FRAME_BORDER_COLOR, border_width: FRAME_BORDER_WIDTH, bearing: 0.0, diff --git a/crates/render/src/stream_tests.rs b/crates/render/src/stream_tests.rs index 9ec00dfcd3..c7bd59d085 100644 --- a/crates/render/src/stream_tests.rs +++ b/crates/render/src/stream_tests.rs @@ -564,6 +564,7 @@ fn layout_export_keeps_all_drawn_legend_classes() { extent_of: None, extent_color: INDICATOR_COLOR, extent_width: INDICATOR_WIDTH, + more_extents: Vec::new(), border_color: rustgis_map::layout::FRAME_BORDER_COLOR, border_width: rustgis_map::layout::FRAME_BORDER_WIDTH, bearing: 0.0, @@ -1376,6 +1377,7 @@ fn layout_export_rejects_unopened_local_shapefiles_and_required_masks() { extent_of: None, extent_color: INDICATOR_COLOR, extent_width: INDICATOR_WIDTH, + more_extents: Vec::new(), border_color: rustgis_map::layout::FRAME_BORDER_COLOR, border_width: rustgis_map::layout::FRAME_BORDER_WIDTH, bearing: 0.0, diff --git a/crates/render/src/tiles.rs b/crates/render/src/tiles.rs index 765e99a830..09b69a9229 100644 --- a/crates/render/src/tiles.rs +++ b/crates/render/src/tiles.rs @@ -2161,6 +2161,7 @@ pub(crate) mod tests { extent_of: None, extent_color: INDICATOR_COLOR, extent_width: INDICATOR_WIDTH, + more_extents: Vec::new(), border_color: rustgis_map::layout::FRAME_BORDER_COLOR, border_width: rustgis_map::layout::FRAME_BORDER_WIDTH, bearing: 0.0, diff --git a/crates/ui-egui/src/layoutview/format/frame.rs b/crates/ui-egui/src/layoutview/format/frame.rs index 123ec66c6f..587980b426 100644 --- a/crates/ui-egui/src/layoutview/format/frame.rs +++ b/crates/ui-egui/src/layoutview/format/frame.rs @@ -435,17 +435,34 @@ pub(super) fn frame_sections( }, ); } - // The extent indicator this frame draws (another frame's extent): its colour and width. - if let ElementKind::MapFrame { extent_of: Some(of), extent_color, extent_width, .. } = &e.kind { - let other = layout.element(*of).map_or_else(|| of.to_string(), |o| o.name.clone()); + // The extent indicators this frame draws (other frames' extents): each one's colour and + // width. Several are told apart by `of`; a frame's only one is changed without it. + let indicators = e.kind.extent_indicators(); + if !indicators.is_empty() { + let several = indicators.len() > 1; + let title = if several { tl!("Extent Indicators") } else { tl!("Extent Indicator") }; ui.add_space(4.0); - egui::CollapsingHeader::new(tl!("Extent Indicator")).id_salt(("frame_indicator", id)).default_open(true).show(ui, |ui| { - ui.label(egui::RichText::new(crate::i18n::fmt("Outlines {frame}", &[("frame", &other)])).size(11.5)); - let range = rustgis_engine::map::layout::MIN_INDICATOR_WIDTH..=rustgis_engine::map::layout::MAX_INDICATOR_WIDTH; - let line = Outline { key: "extentIndicator", drag: drag_key("extentWidth"), color: *extent_color, width: *extent_width, range }; - outline_rows(app, ui, ("indicator_props", id), line, None, &update); - if ui.button(tl!("Remove Extent Indicator")).clicked() { - update(app, json!({"extentIndicator": false})); + egui::CollapsingHeader::new(title).id_salt(("frame_indicator", id)).default_open(true).show(ui, |ui| { + for i in &indicators { + let other = layout.element(i.of).map_or_else(|| i.of.to_string(), |o| o.name.clone()); + ui.label(egui::RichText::new(crate::i18n::fmt("Outlines {frame}", &[("frame", &other)])).size(11.5)); + let of = i.of; + let one = |app: &mut RustGisApp, mut change: Value| { + if several { + change["extentIndicator"]["of"] = json!(of); + } + update(app, change); + }; + let range = rustgis_engine::map::layout::MIN_INDICATOR_WIDTH..=rustgis_engine::map::layout::MAX_INDICATOR_WIDTH; + let drag = drag_key(&format!("extentWidth{of}")); + let line = Outline { key: "extentIndicator", drag, color: i.color, width: i.width, range }; + outline_rows(app, ui, ("indicator_props", id, of), line, None, &one); + ui.push_id(of, |ui| { + if ui.button(tl!("Remove Extent Indicator")).clicked() { + let remove = if several { json!({"of": of, "remove": true}) } else { json!(false) }; + update(app, json!({"extentIndicator": remove})); + } + }); } }); } diff --git a/crates/ui-egui/src/ribbon.rs b/crates/ui-egui/src/ribbon.rs index 2651d0a041..cbc91a0d4a 100644 --- a/crates/ui-egui/src/ribbon.rs +++ b/crates/ui-egui/src/ribbon.rs @@ -3532,8 +3532,13 @@ fn layout_groups(app: &mut RustGisApp, ui: &mut Ui) { if others.is_empty() { ui.label(egui::RichText::new(tl!("Add a second map frame first")).weak()); } + let outlined = frame.and_then(|f| layout.element(f)).map(|e| e.kind.extent_indicators()).unwrap_or_default(); for (id, name) in &others { - if ui.button(format!("{name} ({id})")).clicked() { + let label = format!("{name} ({id})"); + if outlined.iter().any(|i| i.of == *id) { + // Ticked, and changed or removed in the Format pane. + ui.add_enabled(false, egui::Checkbox::new(&mut true, label)); + } else if ui.button(label).clicked() { add(app, json!({"kind": "extentIndicator", "of": id})); ui.close(); } diff --git a/docs/maintaining.md b/docs/maintaining.md index 3547bf721d..458721a96c 100644 --- a/docs/maintaining.md +++ b/docs/maintaining.md @@ -355,6 +355,15 @@ commands with that value require it too; `"rows"` and `null` need nothing. A sav or `report.existingTemplate` carrying such a legend requires it as well, and a layout file (`.rgislayout`) with one lists it in its header. +Projects with a map frame that outlines more than one other frame (`more_extents` on a map frame +element) require `layout-extent-indicators`, so an older reader refuses them instead of drawing +the first outline and saving the frame again without the others (#3394). Saved +`layout.addElement` commands that add an extent indicator require it too, since an older reader +replaces the frame's indicator instead of adding one, as do saved `layout.update` commands whose +`extentIndicator` gives `of` or `remove`; its colour, its width and `false` need nothing. A saved +`layout.import` or `report.existingTemplate` carrying such a frame requires it as well, and a +layout file (`.rgislayout`) with one lists it in its header. + Projects with a legend that shows feature counts (`show_counts` on a legend element) require `layout-legend-counts`, so an older reader refuses them instead of drawing no numbers and saving the legend again without the setting (#3237). Saved `layout.addElement` and `layout.update` diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index 170bad2a27..dffe42d385 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -306,11 +306,15 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu basemap with a paper colour) blends into it; **Default Border** brings the dark grey line back. Scripts set the same with `layout.update` and `"border": {"color": "#C8B89A", "width": 0}` (the keys not given keep theirs; `null` gives the default back). -- **Extent indicators**: the **Extent Indicator** section of an overview frame's properties sets - the outline's **Color** and **Line width** (red and 2 pt to begin with), so it can sit quietly on a - muted page, and **Remove Extent Indicator** takes it away. Scripts set the same with `color` - and `width` on `layout.addElement` (`kind` `extentIndicator`), or `layout.update` with - `"extentIndicator": {"color": "#555555", "width": 1}` (`false` removes it). The outline breaks +- **Extent indicators**: an overview frame outlines up to 16 other frames, one added at a time with + **Extent Indicator**, whose menu ticks the ones it outlines already. The **Extent Indicator** + section of its properties (**Extent Indicators** with more than one) sets each outline's + **Color** and **Line width** (red and 2 pt to begin with), so it can sit quietly on a muted page, + and **Remove Extent Indicator** takes that one away. Scripts set the same with `color` and `width` + on `layout.addElement` (`kind` `extentIndicator`, with `of` the frame to outline), or + `layout.update` with `"extentIndicator": {"color": "#555555", "width": 1}`. With several + indicators, `of` says which: `{"of": 3, "width": 1}`, or `{"of": 3, "remove": true}`; `false` + removes them all. An outline breaks where the other frame's edge leaves the Earth (off a globe's disc, or past the edge of its projection's world) and runs up to it there, and where the overview's own projection can't show the place. An outline across the overview map's edge (on a world projection, the meridian diff --git a/schema/fixtures/layout_extent_indicators.rgis b/schema/fixtures/layout_extent_indicators.rgis new file mode 100644 index 0000000000..4b8b1a8a96 --- /dev/null +++ b/schema/fixtures/layout_extent_indicators.rgis @@ -0,0 +1,26 @@ +{ + "format": 2, + "name": "Extent indicators", + "requires": ["layout-extent-indicators"], + "active_map": 0, + "maps": [ + { + "name": "Map", + "layers": [], + "basemap": "Paper", + "camera": {"center": {"x": 0, "y": 0}, "res": 30000} + } + ], + "layouts": [ + { + "name": "Key map", + "width": 200, + "height": 100, + "elements": [ + {"id": 1, "name": "Overview", "x": 5, "y": 5, "w": 90, "h": 90, "kind": {"MapFrame": {"map": "Map", "center": {"x": 0, "y": 0}, "scale": 100000000, "extent_of": 2, "more_extents": [{"of": 3, "color": [31, 78, 154, 255], "width": 1}]}}}, + {"id": 2, "name": "North", "x": 100, "y": 5, "w": 95, "h": 40, "kind": {"MapFrame": {"map": "Map", "center": {"x": 0, "y": 20}, "scale": 10000000}}}, + {"id": 3, "name": "South", "x": 100, "y": 50, "w": 95, "h": 45, "kind": {"MapFrame": {"map": "Map", "center": {"x": 0, "y": -20}, "scale": 10000000}}} + ] + } + ] +} diff --git a/schema/project.schema.json b/schema/project.schema.json index 678fbaa812..0ee20edbd5 100644 --- a/schema/project.schema.json +++ b/schema/project.schema.json @@ -1286,6 +1286,7 @@ "layout-legend-counts", "layout-legend-subtitle", "layout-legend-nested-sizes", + "layout-extent-indicators", "layout-legend-order", "layout-scale-bar-details", "label-guide", @@ -1421,6 +1422,7 @@ "layout-legend-counts", "layout-legend-subtitle", "layout-legend-nested-sizes", + "layout-extent-indicators", "layout-legend-order", "layout-scale-bar-details", "label-guide", From af90b1d5fce4d7d2aaf7dbe4abf362d01d2b6db6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Sun, 29 Nov 2026 19:07:04 -0500 Subject: [PATCH 2/8] fix(layout): tell several extent indicator rows apart by their frame's id (#3394) --- crates/ui-egui/src/layoutview/format/frame.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/layoutview/format/frame.rs b/crates/ui-egui/src/layoutview/format/frame.rs index 587980b426..0af3dbe5f4 100644 --- a/crates/ui-egui/src/layoutview/format/frame.rs +++ b/crates/ui-egui/src/layoutview/format/frame.rs @@ -444,7 +444,11 @@ pub(super) fn frame_sections( ui.add_space(4.0); egui::CollapsingHeader::new(title).id_salt(("frame_indicator", id)).default_open(true).show(ui, |ui| { for i in &indicators { - let other = layout.element(i.of).map_or_else(|| i.of.to_string(), |o| o.name.clone()); + let mut other = layout.element(i.of).map_or_else(|| i.of.to_string(), |o| o.name.clone()); + if several { + // Frames often share a name: the id tells the rows apart, as in the menu. + other = format!("{other} ({})", i.of); + } ui.label(egui::RichText::new(crate::i18n::fmt("Outlines {frame}", &[("frame", &other)])).size(11.5)); let of = i.of; let one = |app: &mut RustGisApp, mut change: Value| { From ba16b9c483a9e26b75cc0d743dc105779b8bc3c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Sun, 29 Nov 2026 19:25:16 -0500 Subject: [PATCH 3/8] fix(layout): say repeated and cut extent indicators, and require the capability only for a removal (#3394) --- crates/engine/src/cmd/diagram.rs | 2 +- crates/engine/src/project.rs | 4 ++-- crates/engine/src/project_capabilities.rs | 6 +++--- crates/engine/src/tests/layout_extents.rs | 25 ++++++++++++++++++++--- docs/maintaining.md | 2 +- 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/crates/engine/src/cmd/diagram.rs b/crates/engine/src/cmd/diagram.rs index 09d31f5c8a..0ca6f76675 100644 --- a/crates/engine/src/cmd/diagram.rs +++ b/crates/engine/src/cmd/diagram.rs @@ -543,7 +543,7 @@ mod tests { "1 diagram(s) that could not be read or named no field removed", "1 diagram category(ies) with a blank field name", "1 diagram category(ies) repeating an earlier field kept", - "1 layout element(s) with a value out of range, a repeated id, an over-long name, a missing map frame reference or a background on a map frame repaired while opening the project (in \"Poster\")", + "1 layout element(s) with a value out of range, a repeated id, an over-long name, a missing map frame reference, a repeated extent indicator or a background on a map frame repaired while opening the project (in \"Poster\")", ] { assert!(said.iter().any(|t| t.contains(text)), "{text}: {said:?}"); } diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index 91cc426d6c..2bdd68e680 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -2822,14 +2822,14 @@ pub(crate) fn layout_notices( let adjusted = total(|r| r.elements_adjusted); if adjusted > 0 { notices.push(format!( - "{name}: {adjusted} layout element(s) with a value out of range, a repeated id, an over-long name, a missing map frame reference or a background on a map frame repaired {when} (in {})", + "{name}: {adjusted} layout element(s) with a value out of range, a repeated id, an over-long name, a missing map frame reference, a repeated extent indicator or a background on a map frame repaired {when} (in {})", layout_names(repairs, |r| r.elements_adjusted) )); } let cut = total(|r| r.elements_cut); if cut > 0 { notices.push(format!( - "{name}: {cut} layout element(s) with a name, text, polygon points, section lines, legend exclusions, scale bar unit labels or legend labels cut to their limits {when} (in {})", + "{name}: {cut} layout element(s) with a name, text, polygon points, section lines, legend exclusions, scale bar unit labels, legend labels or extent indicators cut to their limits {when} (in {})", layout_names(repairs, |r| r.elements_cut) )); } diff --git a/crates/engine/src/project_capabilities.rs b/crates/engine/src/project_capabilities.rs index 464b502c56..e6ac3cbe16 100644 --- a/crates/engine/src/project_capabilities.rs +++ b/crates/engine/src/project_capabilities.rs @@ -618,9 +618,9 @@ fn command_uses_legend_subtitle(id: &str, params: &Value) -> bool { fn command_uses_extent_indicators(id: &str, params: &Value) -> bool { match id { "layout.addElement" => params.get("kind").and_then(Value::as_str) == Some("extentIndicator"), - "layout.update" => { - params.get("extentIndicator").is_some_and(|v| ["of", "remove"].iter().any(|k| v.get(k).is_some_and(|v| !v.is_null()))) - } + "layout.update" => params + .get("extentIndicator") + .is_some_and(|v| v.get("of").is_some_and(|of| !of.is_null()) || v.get("remove") == Some(&Value::Bool(true))), "layout.import" | "report.existingTemplate" => imported_layout_uses(params, &["\"more_extents\""], extent_indicators_features), "script.run" => params.get("script").and_then(Value::as_str).is_some_and(|s| script_uses(s, command_uses_extent_indicators)), _ => false, diff --git a/crates/engine/src/tests/layout_extents.rs b/crates/engine/src/tests/layout_extents.rs index feb7622171..03f440b889 100644 --- a/crates/engine/src/tests/layout_extents.rs +++ b/crates/engine/src/tests/layout_extents.rs @@ -173,6 +173,7 @@ fn several_indicators_survive_a_save_and_require_their_capability() { assert!(requires("layout.import", json!({"text": layout}))); assert!(!requires("layout.update", json!({"element": 1, "extentIndicator": {"width": 1}}))); assert!(!requires("layout.update", json!({"element": 1, "extentIndicator": false}))); + assert!(!requires("layout.update", json!({"element": 1, "extentIndicator": {"remove": false, "width": 1}}))); assert!(!requires("layout.addElement", json!({"kind": "northArrow"}))); } @@ -188,10 +189,9 @@ fn each_indicator_is_drawn_in_its_own_colour() { s.run("layout.addElement", &json!({"kind": "extentIndicator", "frame": overview, "of": frame, "color": color, "width": 4})) .unwrap(); } - // The overview alone, so no other element's pixels are counted. + // The overview alone is drawn, so no other element's pixels are counted. let mut page = s.project.layouts[0].clone(); - page.elements.iter_mut().for_each(|e| e.visible = u64::from(e.id) == overview || of.contains(&e.id.into())); - page.elements.iter_mut().filter(|e| of.contains(&e.id.into())).for_each(|e| (e.x, e.y) = (4000.0, 4000.0)); + page.elements.iter_mut().for_each(|e| e.visible = u64::from(e.id) == overview); let info = crate::render::layout::PageInfo { page: 1, pages: 1, page_name: String::new() }; let pm = crate::render::layout::render(&page, &mut s.project.maps, 96.0, &info).unwrap(); for rgb in [[255, 0, 255], [0, 255, 255]] { @@ -211,7 +211,26 @@ fn a_files_orphan_and_repeated_indicators_are_dropped() { kind["extent_of"] = json!(999); kind["more_extents"] = json!([{"of": overview}, {"of": 998}, {"of": of[1], "width": 99}, {"of": of[1]}, {"of": of[0]}]); let mut other = Session::new(Project::default()); + let mark = other.notice_mark(); other.run("layout.import", &json!({"text": layout.to_string()})).unwrap(); + let said = other.notices_since(mark); + assert!(said.iter().any(|n| n.text.contains("a repeated extent indicator")), "{said:?}"); assert_eq!(frames(&other, overview), [of[1], of[0]]); assert_eq!(outlined(&other, overview)[0].2, rustgis_map::layout::MAX_INDICATOR_WIDTH); } + +#[test] +fn a_files_indicators_past_the_limit_are_cut_and_said() { + let (s, overview, of) = laid_out(17); + let mut layout = serde_json::to_value(&s.project.layouts[0]).unwrap(); + let frame = layout["elements"].as_array_mut().unwrap().iter_mut().find(|e| e["id"] == overview).unwrap(); + let kind = &mut frame["kind"]["MapFrame"]; + kind["extent_of"] = json!(of[0]); + kind["more_extents"] = of[1..].iter().map(|of| json!({"of": of})).collect(); + let mut other = Session::new(Project::default()); + let mark = other.notice_mark(); + other.run("layout.import", &json!({"text": layout.to_string()})).unwrap(); + assert_eq!(frames(&other, overview), of[..16]); + let said = other.notices_since(mark); + assert!(said.iter().any(|n| n.text.contains("extent indicators cut to their limits")), "{said:?}"); +} diff --git a/docs/maintaining.md b/docs/maintaining.md index 458721a96c..46b16fb6aa 100644 --- a/docs/maintaining.md +++ b/docs/maintaining.md @@ -360,7 +360,7 @@ element) require `layout-extent-indicators`, so an older reader refuses them ins the first outline and saving the frame again without the others (#3394). Saved `layout.addElement` commands that add an extent indicator require it too, since an older reader replaces the frame's indicator instead of adding one, as do saved `layout.update` commands whose -`extentIndicator` gives `of` or `remove`; its colour, its width and `false` need nothing. A saved +`extentIndicator` gives `of` or `"remove": true`; its colour, its width and `false` need nothing. A saved `layout.import` or `report.existingTemplate` carrying such a frame requires it as well, and a layout file (`.rgislayout`) with one lists it in its header. From c9591a91a07aadc2d6f4daa580eaa62cc4cd419f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Sun, 29 Nov 2026 19:34:06 -0500 Subject: [PATCH 4/8] fix(layout): keep the legend label cut wording, and disable the indicator menu at its limit (#3394) --- crates/engine/src/project.rs | 2 +- crates/engine/src/tests/layout_extents.rs | 2 +- crates/ui-egui/src/ribbon.rs | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index 2bdd68e680..d82f6a8a8f 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -2829,7 +2829,7 @@ pub(crate) fn layout_notices( let cut = total(|r| r.elements_cut); if cut > 0 { notices.push(format!( - "{name}: {cut} layout element(s) with a name, text, polygon points, section lines, legend exclusions, scale bar unit labels, legend labels or extent indicators cut to their limits {when} (in {})", + "{name}: {cut} layout element(s) with a name, text, polygon points, section lines, extent indicators, legend exclusions, scale bar unit labels or legend labels cut to their limits {when} (in {})", layout_names(repairs, |r| r.elements_cut) )); } diff --git a/crates/engine/src/tests/layout_extents.rs b/crates/engine/src/tests/layout_extents.rs index 03f440b889..42709a7cee 100644 --- a/crates/engine/src/tests/layout_extents.rs +++ b/crates/engine/src/tests/layout_extents.rs @@ -232,5 +232,5 @@ fn a_files_indicators_past_the_limit_are_cut_and_said() { other.run("layout.import", &json!({"text": layout.to_string()})).unwrap(); assert_eq!(frames(&other, overview), of[..16]); let said = other.notices_since(mark); - assert!(said.iter().any(|n| n.text.contains("extent indicators cut to their limits")), "{said:?}"); + assert!(said.iter().any(|n| n.text.contains("extent indicators, legend exclusions")), "{said:?}"); } diff --git a/crates/ui-egui/src/ribbon.rs b/crates/ui-egui/src/ribbon.rs index cbc91a0d4a..45581dff1d 100644 --- a/crates/ui-egui/src/ribbon.rs +++ b/crates/ui-egui/src/ribbon.rs @@ -3538,7 +3538,11 @@ fn layout_groups(app: &mut RustGisApp, ui: &mut Ui) { if outlined.iter().any(|i| i.of == *id) { // Ticked, and changed or removed in the Format pane. ui.add_enabled(false, egui::Checkbox::new(&mut true, label)); - } else if ui.button(label).clicked() { + } else if ui + .add_enabled(outlined.len() < rustgis_engine::map::layout::MAX_EXTENT_INDICATORS, egui::Button::new(label)) + .on_disabled_hover_text(tl!("A map frame outlines at most 16 other frames")) + .clicked() + { add(app, json!({"kind": "extentIndicator", "of": id})); ui.close(); } From c6290c8dc1330aa11c4b1be79a2d9e597067bdeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Sun, 29 Nov 2026 20:26:15 -0500 Subject: [PATCH 5/8] fix(layout): name the indicator limit from its constant, reword the command help and test the pane and menu (#3394) --- crates/engine/src/cmd/layout.rs | 4 +-- crates/ui-egui/src/layoutview/tests.rs | 39 ++++++++++++++++++++++++ crates/ui-egui/src/ribbon.rs | 42 +++++++++++++++++++++++++- 3 files changed, 82 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/cmd/layout.rs b/crates/engine/src/cmd/layout.rs index bd84dc87ae..71c395f2a4 100644 --- a/crates/engine/src/cmd/layout.rs +++ b/crates/engine/src/cmd/layout.rs @@ -191,7 +191,7 @@ pub fn commands() -> Vec { r##"{"layout"?, "##, r##""kind": "northArrow"|"scaleBar"|"legend"|"colorbar"|"text"|"dynamicText"|"picture"|"table"|"chart"|"rectangle" (a neatline framing the page unless any of x, y, w, h is given)|"ellipse"|"circle"|"line"|"arrow"|"extentIndicator"|"grid"|"section" (a section line over a map frame, named at both ends, A and A', up to 26 a frame; as a grid or an extentIndicator, it adds no element: the reply's "element" is its frame, the one layout.update changes it on with "section", and "section" its name)|"profile" (a raster's profile along a section line of the frame, beside the frame on the side the line runs along, lined up with it: each sample is read at its point of the page line, through the frame's projection, so the curve is straight across from the place it comes from; its box is the frame's side, which it follows when the frame is moved or resized; a tilted frame, one on the globe, or a raster read in place draws none, which a notice and exports say), "##, r##""frame"?: element id (default: the first map frame), "##, - r##""of"?: frame id (extentIndicator, which also takes "color" and "width" in points, default red and 2; a frame keeps one per frame outlined, up to 16, and one for a frame outlined already restyles it), "##, + r##""of"?: frame id (extentIndicator: the frame to outline, with "color" and "width" in points, default red and 2; a frame outlines up to 16 others, and giving one it outlines already restyles that outline), "##, r##""text"? (a text's words; {count:Layer}, {sum:Layer:field}, {mean:Layer:field}, {min:Layer:field} and {max:Layer:field} show the layer's figure, as {scale} shows the scale: of the first map frame's map, over the features the layer's definition query keeps, with the layout's decimal mark; one with no figure shows as written and says why), "##, r##""size"?, "##, r##""color"?: "#RRGGBB"|"#RRGGBBAA" (text, dynamicText, line, arrow, rectangle, ellipse, circle: its outline; extentIndicator; grid; section, default #A8431F; scaleBar; legend, colorbar, table, chart, profile: the ink of its text and lines, default #222222, a chart's bars and a colorbar's colours keeping theirs, and a table drawn without its white cells; refused for other kinds), "##, @@ -362,7 +362,7 @@ pub fn commands() -> Vec { r##""bearing"?: degrees clockwise from north, "##, r##""pitch"?: degrees of tilt (0 to 85), "##, r##""grid"?: {grid options as in layout.addElement} | false (map frame; a grid's "labelSize" goes in it, and is refused outside it unless null), "##, - r##""extentIndicator"?: {"of"?: frame id, "color"?, "width"?: points, "remove"?: bool} | false (map frame: restyles, or with "remove" removes, the extent indicator of the frame "of", left out when it has one; false removes them all), "##, + r##""extentIndicator"?: {"of"?: frame id, "color"?, "width"?: points, "remove"?: bool} | false (map frame: restyles one of its extent indicators, or removes it with "remove": true; "of" is the id of the frame that indicator outlines and may be omitted when there is only one; false removes them all), "##, r##""border"?: {"color"?: "#RRGGBB"|"#RRGGBBAA", "width"?: points, 0 to 20, 0 for none} | null (map frame: the outline along its shape, default #303030 and 0.8, the keys not given keeping theirs; null gives the default back; refused for other elements), "##, r##""section"?: {"name": the section line it changes, "newName"?, "direction"?, "at"?, "color"?, "width"?, "dash"? ([] or null for solid), as in layout.addElement, the keys not given keeping theirs, "remove"?: true to remove it} (map frame; refused for other elements), "##, r##""layer"?: (colorbar: "" for the top visible raster with a colour scale, not drawn by classes), "##, diff --git a/crates/ui-egui/src/layoutview/tests.rs b/crates/ui-egui/src/layoutview/tests.rs index d73db7175f..175062c1ca 100644 --- a/crates/ui-egui/src/layoutview/tests.rs +++ b/crates/ui-egui/src/layoutview/tests.rs @@ -2006,6 +2006,45 @@ fn an_overview_frame_shows_its_extent_indicator() { assert!(h.query_by_label("Remove Extent Indicator").is_none(), "and its section with it"); } +/// With several extent indicators (#3394) each has its block, named with its frame's id, and its +/// Remove button takes that one away. +#[test] +fn an_overview_frame_removes_one_of_several_extent_indicators() { + use egui_kittest::kittest::Queryable; + let mut app = RustGisApp::with_sample(); + app.run("layout.new", json!({"name": "Overview"})).unwrap(); + let li = app.session.active_layout.unwrap(); + let main = app.session.project.layouts[li].first_frame().unwrap(); + let mut frame = || app.run("layout.addFrame", json!({"x": 200, "y": 150, "w": 60, "h": 40})).unwrap()["element"].as_u64().unwrap(); + let (inset, other) = (frame() as u32, frame() as u32); + for of in [main, other] { + app.run("layout.addElement", json!({"kind": "extentIndicator", "frame": inset, "of": of})).unwrap(); + } + let rows = [main, other].map(|id| format!("Outlines {} ({id})", app.session.project.layouts[li].element(id).unwrap().name)); + app.layout.selected = Some(inset); + let mut fonts = false; + let mut h = egui_kittest::Harness::builder().with_size(vec2(1200.0, 1100.0)).build_ui_state( + move |ui, app: &mut RustGisApp| { + if !fonts { + crate::theme::install_fonts(ui.ctx(), &[], None); + fonts = true; + return; + } + with_format(app, ui); + }, + app, + ); + h.run_steps(3); + assert!(h.query_by_label("Extent Indicators").is_some()); + assert!(rows.iter().all(|row| h.query_by_label(row).is_some()), "{rows:?}"); + h.get_all_by_label("Remove Extent Indicator").nth(1).unwrap().click(); + h.run_steps(3); + let left = h.state().session.project.layouts[li].element(inset).unwrap().kind.extent_indicators(); + assert_eq!(left.iter().map(|i| i.of).collect::>(), [main]); + assert!(h.query_by_label("Extent Indicator").is_some(), "one again"); + assert_eq!(h.get_all_by_label("Remove Extent Indicator").count(), 1); +} + /// A frame's Section Lines section (#2863) adds one each way, renames it, says one isn't drawn /// when its place is outside the frame, and removes it. #[test] diff --git a/crates/ui-egui/src/ribbon.rs b/crates/ui-egui/src/ribbon.rs index 45581dff1d..8c1a6e9474 100644 --- a/crates/ui-egui/src/ribbon.rs +++ b/crates/ui-egui/src/ribbon.rs @@ -3540,7 +3540,10 @@ fn layout_groups(app: &mut RustGisApp, ui: &mut Ui) { ui.add_enabled(false, egui::Checkbox::new(&mut true, label)); } else if ui .add_enabled(outlined.len() < rustgis_engine::map::layout::MAX_EXTENT_INDICATORS, egui::Button::new(label)) - .on_disabled_hover_text(tl!("A map frame outlines at most 16 other frames")) + .on_disabled_hover_text(crate::i18n::fmt( + "A map frame outlines at most {max} other frames", + &[("max", &rustgis_engine::map::layout::MAX_EXTENT_INDICATORS.to_string())], + )) .clicked() { add(app, json!({"kind": "extentIndicator", "of": id})); @@ -7168,6 +7171,43 @@ mod tests { assert!(h.query_by_label("Layer statistic").is_none(), "no frame, no layers"); } + /// Publish › Map Frames › Extent Indicator ticks the frames outlined already, and at the + /// limit takes no other (#3394). + #[test] + fn the_extent_indicator_menu_ticks_outlined_frames_and_stops_at_the_limit() { + use egui_kittest::kittest::NodeT; + use rustgis_engine::map::layout::MAX_EXTENT_INDICATORS; + let mut app = RustGisApp::with_sample(); + app.run("layout.new", json!({"name": "Key"})).unwrap(); + let li = app.session.active_layout.unwrap(); + let overview = app.session.project.layouts[li].first_frame().unwrap(); + let frames: Vec = (0..=MAX_EXTENT_INDICATORS) + .map(|_| app.run("layout.addFrame", json!({"x": 20, "y": 20, "w": 40, "h": 30})).unwrap()["element"].as_u64().unwrap()) + .collect(); + for of in &frames[..MAX_EXTENT_INDICATORS - 1] { + app.run("layout.addElement", json!({"kind": "extentIndicator", "frame": overview, "of": of})).unwrap(); + } + app.layout.selected = Some(overview); + let label = |app: &RustGisApp, id: u64| format!("{} ({id})", app.session.project.layouts[li].element(id as u32).unwrap().name); + let outlined = label(&app, frames[0]); + let spare = [label(&app, frames[MAX_EXTENT_INDICATORS - 1]), label(&app, frames[MAX_EXTENT_INDICATORS])]; + let mut h = tab_harness(app, layout_groups); + // Room for the whole menu: a click outside the window doesn't reach its item. + h.set_size(vec2(2400.0, 1400.0)); + h.run(); + h.get_by_label("Extent Indicator").click(); + h.run(); + assert!(h.get_by_label(&outlined).accesskit_node().is_disabled(), "outlined already"); + assert!(!h.get_by_label(&spare[1]).accesskit_node().is_disabled(), "room for one more"); + h.get_by_label(&spare[0]).click(); + h.run(); + h.get_by_label("Extent Indicator").click(); + h.run(); + let kind = &h.state().session.project.layouts[li].element(overview).unwrap().kind; + assert_eq!(kind.extent_indicators().len(), MAX_EXTENT_INDICATORS); + assert!(h.get_by_label(&spare[1]).accesskit_node().is_disabled(), "at the limit"); + } + /// New Layout › Publication Layout › a sheet › a style makes that sheet in that style, titled /// with the map's name; a figure has no styles to pick and is made at once. #[test] From 650fff1846c2cc0f10125f2c6b14b251e4734925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Sun, 29 Nov 2026 20:34:19 -0500 Subject: [PATCH 6/8] fix(layout): say in the help what look a first indicator takes, and test the notice for a held width (#3394) --- crates/engine/src/cmd/layout.rs | 2 +- crates/engine/src/tests/layout_extents.rs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/cmd/layout.rs b/crates/engine/src/cmd/layout.rs index 71c395f2a4..436a5e028b 100644 --- a/crates/engine/src/cmd/layout.rs +++ b/crates/engine/src/cmd/layout.rs @@ -191,7 +191,7 @@ pub fn commands() -> Vec { r##"{"layout"?, "##, r##""kind": "northArrow"|"scaleBar"|"legend"|"colorbar"|"text"|"dynamicText"|"picture"|"table"|"chart"|"rectangle" (a neatline framing the page unless any of x, y, w, h is given)|"ellipse"|"circle"|"line"|"arrow"|"extentIndicator"|"grid"|"section" (a section line over a map frame, named at both ends, A and A', up to 26 a frame; as a grid or an extentIndicator, it adds no element: the reply's "element" is its frame, the one layout.update changes it on with "section", and "section" its name)|"profile" (a raster's profile along a section line of the frame, beside the frame on the side the line runs along, lined up with it: each sample is read at its point of the page line, through the frame's projection, so the curve is straight across from the place it comes from; its box is the frame's side, which it follows when the frame is moved or resized; a tilted frame, one on the globe, or a raster read in place draws none, which a notice and exports say), "##, r##""frame"?: element id (default: the first map frame), "##, - r##""of"?: frame id (extentIndicator: the frame to outline, with "color" and "width" in points, default red and 2; a frame outlines up to 16 others, and giving one it outlines already restyles that outline), "##, + r##""of"?: frame id (extentIndicator: the frame to outline, with "color" and "width" in points, default red and 2, or for a frame's first one the look it kept from indicators removed; a frame outlines up to 16 others, and giving one it outlines already restyles that outline), "##, r##""text"? (a text's words; {count:Layer}, {sum:Layer:field}, {mean:Layer:field}, {min:Layer:field} and {max:Layer:field} show the layer's figure, as {scale} shows the scale: of the first map frame's map, over the features the layer's definition query keeps, with the layout's decimal mark; one with no figure shows as written and says why), "##, r##""size"?, "##, r##""color"?: "#RRGGBB"|"#RRGGBBAA" (text, dynamicText, line, arrow, rectangle, ellipse, circle: its outline; extentIndicator; grid; section, default #A8431F; scaleBar; legend, colorbar, table, chart, profile: the ink of its text and lines, default #222222, a chart's bars and a colorbar's colours keeping theirs, and a table drawn without its white cells; refused for other kinds), "##, diff --git a/crates/engine/src/tests/layout_extents.rs b/crates/engine/src/tests/layout_extents.rs index 42709a7cee..b44b7f5bc8 100644 --- a/crates/engine/src/tests/layout_extents.rs +++ b/crates/engine/src/tests/layout_extents.rs @@ -234,3 +234,22 @@ fn a_files_indicators_past_the_limit_are_cut_and_said() { let said = other.notices_since(mark); assert!(said.iter().any(|n| n.text.contains("extent indicators, legend exclusions")), "{said:?}"); } + +#[test] +fn a_files_further_width_past_the_limit_is_said() { + let (mut s, overview, of) = laid_out(2); + add(&mut s, overview, of[0]); + add(&mut s, overview, of[1]); + let mut layout = serde_json::to_value(&s.project.layouts[0]).unwrap(); + let said = |layout: &Value| { + let mut other = Session::new(Project::default()); + let mark = other.notice_mark(); + other.run("layout.import", &json!({"text": layout.to_string()})).unwrap(); + let repaired = other.notices_since(mark).iter().filter(|n| n.text.contains("value out of range")).count(); + (repaired, outlined(&other, overview)[1].2) + }; + assert_eq!(said(&layout), (0, 2.0), "a file within its limits says nothing"); + let frame = layout["elements"].as_array_mut().unwrap().iter_mut().find(|e| e["id"] == overview).unwrap(); + frame["kind"]["MapFrame"]["more_extents"][0]["width"] = json!(99); + assert_eq!(said(&layout), (1, rustgis_map::layout::MAX_INDICATOR_WIDTH)); +} From 8022315bb17fbc3e9390a3cc3f11b40a4eef2003 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Sun, 29 Nov 2026 21:05:06 -0500 Subject: [PATCH 7/8] test(layout): a file within the indicator limit says nothing, and the look kept for a first indicator (#3394) --- crates/engine/src/tests.rs | 2 ++ crates/engine/src/tests/layout_extents.rs | 21 +++++++++++++++------ crates/map/src/layout.rs | 5 +++-- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index d68c795da9..b5a4fdf93c 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -17911,6 +17911,8 @@ fn layouts_compose_export_and_round_trip() { let err = s.run("layout.update", &json!({"element": inset, "extentIndicator": {"color": "#000000"}})).unwrap_err(); assert!(err.contains("no extent indicator"), "{err}"); s.run("layout.addElement", &json!({"kind": "extentIndicator", "frame": inset, "of": frame})).unwrap(); + // A frame's first indicator takes the look it kept from the one removed. + assert_eq!((indicator(&s).1.as_str(), indicator(&s).2), ("#1F4E9A", rustgis_map::layout::MAX_INDICATOR_WIDTH)); // Its border (#2557): dark grey and 0.8 pt by default and not written, its colour and width // set apart, 0 for none, kept within range, and null giving the default back. let border = |s: &Session| match s.project.layouts[0].element(inset as u32).map(|e| &e.kind) { diff --git a/crates/engine/src/tests/layout_extents.rs b/crates/engine/src/tests/layout_extents.rs index b44b7f5bc8..f09e0d5fdc 100644 --- a/crates/engine/src/tests/layout_extents.rs +++ b/crates/engine/src/tests/layout_extents.rs @@ -74,6 +74,7 @@ fn a_frame_outlines_at_most_sixteen() { assert_eq!(serde_json::to_value(&s.project).unwrap(), before); // One outlined already is still restyled. s.run("layout.addElement", &json!({"kind": "extentIndicator", "frame": overview, "of": of[15], "width": 3})).unwrap(); + assert_eq!(outlined(&s, overview)[15].2, 3.0); } #[test] @@ -227,12 +228,20 @@ fn a_files_indicators_past_the_limit_are_cut_and_said() { let kind = &mut frame["kind"]["MapFrame"]; kind["extent_of"] = json!(of[0]); kind["more_extents"] = of[1..].iter().map(|of| json!({"of": of})).collect(); - let mut other = Session::new(Project::default()); - let mark = other.notice_mark(); - other.run("layout.import", &json!({"text": layout.to_string()})).unwrap(); - assert_eq!(frames(&other, overview), of[..16]); - let said = other.notices_since(mark); - assert!(said.iter().any(|n| n.text.contains("extent indicators, legend exclusions")), "{said:?}"); + // How many "cut" and "repaired" notices an import gives, and the frames it keeps. + let import = |layout: &Value| { + let mut other = Session::new(Project::default()); + let mark = other.notice_mark(); + other.run("layout.import", &json!({"text": layout.to_string()})).unwrap(); + let said = other.notices_since(mark); + let count = |part: &str| said.iter().filter(|n| n.text.contains(part)).count(); + (count("extent indicators, legend exclusions"), count("a repeated extent indicator"), frames(&other, overview)) + }; + // A cut element counts as repaired too, as one with a cut name or legend label does. + assert_eq!(import(&layout), (1, 1, of[..16].to_vec())); + let frame = layout["elements"].as_array_mut().unwrap().iter_mut().find(|e| e["id"] == overview).unwrap(); + frame["kind"]["MapFrame"]["more_extents"].as_array_mut().unwrap().pop(); + assert_eq!(import(&layout), (0, 0, of[..16].to_vec()), "16 are within the limit and say nothing"); } #[test] diff --git a/crates/map/src/layout.rs b/crates/map/src/layout.rs index 615879e3ec..317b14490f 100644 --- a/crates/map/src/layout.rs +++ b/crates/map/src/layout.rs @@ -824,8 +824,9 @@ pub struct LayoutRepairs { /// Elements kept with a value brought into range, a new id, a reference cleared, or a unit /// label's line breaks replaced. pub elements_adjusted: usize, - /// Elements with a name, text, polygon points, section lines, legend exclusions, scale bar unit - /// labels or legend labels cut to their limits (the same element may count as adjusted too). + /// Elements with a name, text, polygon points, section lines, extent indicators, legend + /// exclusions, scale bar unit labels or legend labels cut to their limits (the same element may + /// count as adjusted too). pub elements_cut: usize, /// Elements removed: beyond the 500 a layout holds, or tied to a map frame it doesn't have. pub elements_removed: usize, From 4ffbde5de450af397fcfe1514fad1022d473a657 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Sun, 29 Nov 2026 21:50:02 -0500 Subject: [PATCH 8/8] fix(layout): refuse a bad colour or width when removing an extent indicator too (#3394) --- crates/engine/src/cmd/layout/update.rs | 6 ++++-- crates/engine/src/tests/layout_extents.rs | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/layout/update.rs b/crates/engine/src/cmd/layout/update.rs index c32e7c0faa..e33da19c93 100644 --- a/crates/engine/src/cmd/layout/update.rs +++ b/crates/engine/src/cmd/layout/update.rs @@ -25,10 +25,12 @@ fn changed_indicators(kind: &ElementKind, v: &Value) -> Result 0, None => return Err(format!("this frame outlines {} frames: say which with of", list.len())), }; + if let Some(i) = list.get_mut(at) { + // Read before a removal too: a bad colour or width is refused either way. + (i.color, i.width) = indicator_style(v, (i.color, i.width))?; + } if remove { list.remove(at); - } else if let Some(i) = list.get_mut(at) { - (i.color, i.width) = indicator_style(v, (i.color, i.width))?; } Ok(list) } diff --git a/crates/engine/src/tests/layout_extents.rs b/crates/engine/src/tests/layout_extents.rs index f09e0d5fdc..ec45d52111 100644 --- a/crates/engine/src/tests/layout_extents.rs +++ b/crates/engine/src/tests/layout_extents.rs @@ -118,6 +118,8 @@ fn update_refuses_what_it_cannot_tell_and_changes_nothing() { (json!({"of": of[2], "remove": true}), "doesn't outline"), (json!({"of": "first", "width": 3}), "of is the id"), (json!({"of": of[0], "remove": "yes"}), "remove is true or false"), + (json!({"of": of[0], "remove": true, "width": "wide"}), "width must be a number"), + (json!({"of": of[0], "remove": true, "color": 123}), "color must be"), ] { let before = serde_json::to_value(&s.project).unwrap(); let err = update(&mut s, overview, indicator.clone()).expect_err(&indicator.to_string());