Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/assistant/skills/print-layout/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ description: Make a printable page layout — map frame, title, legend, north ar
1. Get the map right first: symbology, labels and extent. A layout's map frame shows the map's current view.
2. For a finished sheet or a figure for a paper in one step, use `layout.publication` with a `"profile"`
(a page size alone, `"a4"`, `"letter"`, `"legal"`, `"tabloid"`, `"a5"` to `"a0"`, for a sheet turned to the area's shape, or with its orientation, `"a4-portrait"`, `"letter-landscape"`, … to choose; `"figure-1col"`, `"thesis-full"`, … for a figure), the `"extent"`
to fit, and the texts: `"title"`, `"subtitle"`, `"sources"`, `"note"`, a `"locator"` (`"globe"`: the visible polygon layers held in the project, not streamed ones, over the basemap; `"inset"` or `"none"`; when omitted, `"globe"` on a sheet and `"none"` on a figure), and `"decimal": ","` for a map in a language with a decimal comma. A sheet's `"style"` arranges it: `"classic"` (the default), `"banner"`, `"panel"`, `"editorial"`, `"modular"`, `"poster"` (for a poster-like sheet) or `"edge"` (the map from side to side of the page; it also takes `"paper"`, the page colour as `"#RRGGBB"`, `"kicker"`, a short line over the title, and `"figures"`, up to three `{"value", "label"}` under the map, whose texts may hold layer statistics such as `{count:Layer}`), with an `"accent"` colour as `"#RRGGBB"`. Its
to fit, and the texts: `"title"`, `"subtitle"`, `"sources"`, `"note"`, a `"locator"` (`"globe"`: the visible polygon layers held in the project, not streamed ones, over the basemap; `"inset"`; `["inset", "globe"]`, both, the globe outlining the inset; or `"none"`; when omitted, `"globe"` on a sheet and `"none"` on a figure), and `"decimal": ","` for a map in a language with a decimal comma. A sheet's `"style"` arranges it: `"classic"` (the default), `"banner"`, `"panel"`, `"editorial"`, `"modular"`, `"poster"` (for a poster-like sheet) or `"edge"` (the map from side to side of the page; it also takes `"paper"`, the page colour as `"#RRGGBB"`, `"kicker"`, a short line over the title, and `"figures"`, up to three `{"value", "label"}` under the map, whose texts may hold layer statistics such as `{count:Layer}`), with an `"accent"` colour as `"#RRGGBB"`. Its
surrounds (locator, north arrow, legend, scale bar) start from an `"arrangement"` (`"classic"`, `"mirrored"`, `"legendRight"`, `"legendTop"`, or a corner for each; `"best"`, the default, tries the user's favourite, set with `layout.arrangement`, and the others), and one over the data moves to the freest place in the frame, the largest first (the legend, as a rule); read its `"arrangement"`, `"moved"` and `"warnings"`. It places the frame at a round scale, the
graticule, legend (a long one in up to three columns: its own choice, though a legend takes up to six), scale bar and north arrow, and wraps the footer. `"grid"`, `"scaleBar"` and `"northArrow"` take `"none"` to leave that part out, or an object of its options (the grid's `"step"` or `"type"`, the bar's `"units"` or `"style"`, the arrow's `"style"`, `"fill"`, `"outline"` and `"show"`). Its result lists every element's id and name
(`"elements"`), so skip to step 5 to adjust them. Otherwise,
Expand Down
2 changes: 1 addition & 1 deletion crates/engine/src/cmd/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub fn commands() -> Vec<C> {
r#""note"?: text, "#,
r#""author"?: text (default: "Made with RustGIS · {date}"; "" or [] for none), "#,
r#""headings"?: [the sources' heading, the reference's heading, an editorial column's heading], "#,
r#""locator"?: "globe" (a globe with the area outlined; the default on sheets, but for a map on the globe with no extent, the globe seen whole, which by default has no locator (one asked for by name is drawn) and no scale bar, the globe filling its frame) | "inset" (the surrounding region, the area outlined) | "none" (the default on figures), "#,
r#""locator"?: "globe" (a globe with the area outlined; the default on sheets, but for a map on the globe with no extent, the globe seen whole, which by default has no locator (one asked for by name is drawn) and no scale bar, the globe filling its frame) | "inset" (the surrounding region, the area outlined) | ["inset", "globe"] (both side by side, the globe outlining the inset) | "none" (the default on figures), "#,
r#""decimal"?: "." (the default) | "," (graticule, scale bar and colorbar numbers and {scale} with a decimal comma: 0,05 and 1:6.300.000), "#,
r#""colorbar"?: "auto" (the default: the top visible raster with a colour scale, not drawn by classes, gets one, under the legend in its box; a raster drawn by classes has them in the legend's rows instead) | "none" (no colorbar, and the legend's box has no room for one), "#,
r#""veil"?: true (the default: when no shape of the legend fits, a map that runs on past the extent, with a long legend, has what is outside the extent veiled and its surrounds grouped there, at up to half the scale on a sheet) | false (never veiled, and drawn at its scale; the map may still move aside), "#,
Expand Down
2 changes: 1 addition & 1 deletion crates/engine/src/cmd/layout/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ pub(in crate::cmd::layout) fn scale_text_mm(text: &str, text_pt: f64, bold: bool
}

/// What a publication places over its map, which a scale bar box measured again must stay off.
pub(in crate::cmd::layout) const PLACED_OVER_MAP: [&str; 3] = ["Legend Box", "Locator", "North Arrow"];
pub(in crate::cmd::layout) const PLACED_OVER_MAP: [&str; 5] = ["Legend Box", "Locator", "Locator Inset", "Locator Globe", "North Arrow"];

/// What a publication's scale bar box is measured from: its frame (id, map, centre, scale, width),
/// its bar (id, and the bar as it is set: every setting changes its labels or their room) and the
Expand Down
4 changes: 2 additions & 2 deletions crates/engine/src/cmd/layout/inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@ pub(in crate::cmd::layout) fn locator_orphan(input: &impl crate::cmd::InputSourc
pub(in crate::cmd::layout) fn publication_inputs(input: &crate::cmd::InputContext<'_>, p: &Value) -> Result<crate::cmd::Inputs, String> {
let s = input;
let (_, profile) = publication_profile(p)?;
let locator = publication_locator(p, profile.sheet, shows_whole_globe(s.map(), p))?;
let locators = publication_locators(p, profile.sheet, shows_whole_globe(s.map(), p))?;
let map = s.map();
let mut inputs = crate::cmd::Inputs::layers(map.layers.iter().filter(|l| map.shows(l)).map(|l| (map, l)));
inputs.maps.push(map.instance_id());
if matches!(locator, Locator::Globe) {
if locators.contains(&Locator::Globe) {
if let Some(old) = locator_orphan(input).and_then(|i| s.project.maps.get(i)) {
inputs.maps.push(old.instance_id());
inputs.layers.extend(old.layers.iter().map(|l| (old.instance_id(), l.id)));
Expand Down
137 changes: 85 additions & 52 deletions crates/engine/src/cmd/layout/publication/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ pub(in crate::cmd::layout) fn decimal_mark(p: &Value) -> Result<Option<bool>, St
}
}

/// What a publication layout locates its area on.
/// What a publication layout locates its area on, in the order they nest.
#[derive(Clone, Copy, PartialEq)]
pub(in crate::cmd::layout) enum Locator {
Globe,
Inset,
None,
Globe,
}

/// The scale at which `map` on the globe, centred on `center`, draws a globe `d_mm` across in a
Expand Down Expand Up @@ -121,7 +120,7 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu
};
let headings = texts_of(p, "headings")?.unwrap_or_default();
let comma = decimal_mark(p)?.unwrap_or(false);
let locator = publication_locator(p, sheet, whole_globe)?;
let locators = publication_locators(p, sheet, whole_globe)?;
let colorbar = publication_colorbar(p)?;
let may_veil = publication_veil(p)?;
let context_in_legend = publication_flag(p, "contextInLegend")?.unwrap_or(false);
Expand Down Expand Up @@ -972,17 +971,20 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu
// The locator: a globe (a copy of the map's polygon layers on the globe, its diameter nearly
// the frame's) or the surrounding region on the map itself, the area outlined on either by
// the map frame's extent indicator.
// Two locators sit side by side, each `side` square.
let (locator_count, locator_gap) = (locators.len().max(1) as f64, 3.0 * k);
let side = match column {
// In a column, its width up to an A4 portrait column's (a landscape sheet's wider
// column doesn't make it larger), leaving the legend most of the height under it.
Some(c) => c.w.min(52.0 * k).min(0.45 * c.h).max(0.0),
// In a column, its width (shared by two) up to an A4 portrait column's (a landscape
// sheet's wider column doesn't make it larger), leaving the legend most of the height
// under it.
Some(c) => ((c.w - (locator_count - 1.0) * locator_gap) / locator_count).min(52.0 * k).min(0.45 * c.h).max(0.0),
None if sheet => (0.24 * fw.min(fh)).clamp(25.0 * k, 70.0 * k),
None => (0.3 * fw.min(fh)).clamp(18.0, 45.0),
};
let mut locator_cut = None;
let locator_map = match locator {
Locator::None => None,
Locator::Globe => {
let globe_locator = match locators.contains(&Locator::Globe) {
false => None,
true => {
let src = s.map();
let base = format!("{} Locator", src.name);
// A locator an earlier sheet made that no layout shows any more (its layout deleted)
Expand Down Expand Up @@ -1115,8 +1117,16 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu
}
Some((name, globe, FrameShape::Circle, at))
}
Locator::Inset => Some((s.map().name.clone(), round_scale(scale * fw / side * 4.0), FrameShape::Rectangle, center)),
};
// The inset first: it outlines the area, and the globe after it outlines the inset.
let inset_locator = locators
.contains(&Locator::Inset)
.then(|| (s.map().name.clone(), round_scale(scale * fw / side * 4.0), FrameShape::Rectangle, center));
let locator_maps: Vec<_> = [(Locator::Inset, inset_locator), (Locator::Globe, globe_locator)]
.into_iter()
.filter_map(|(kind, frame)| frame.map(|frame| (kind, frame)))
.collect();
let locators_w = locator_count * side + (locator_count - 1.0) * locator_gap;
// The legend lists what the frame draws: its map synced to the frame's view first, as an
// export does, so a streamed layer has its features there. (This changes the session's map,
// so it comes after the last refusal: nothing below fails.) While one is still reading, the
Expand Down Expand Up @@ -1226,8 +1236,8 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu
let pad = 2.0;
// The surrounds to place: what each is and its size (the arrangement gives its corner).
let mut surrounds: Vec<(Surround, f64, f64)> = Vec::new();
if locator_map.is_some() && column.is_none() {
surrounds.push((Surround::Locator, side, side));
if !locator_maps.is_empty() && column.is_none() {
surrounds.push((Surround::Locator, locators_w, side));
}
// At a continental span the graticule's lines give north, and one arrow can't point north
// across the whole frame: none, unless "northArrow": "always" (#1379). Left out so, it is said;
Expand Down Expand Up @@ -1360,14 +1370,14 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu
bands
};
let size_of = |kind: Surround| surrounds.iter().find(|x| x.0 == kind).map(|x| (x.1, x.2));
let (locator_side, arrow_size) = (size_of(Surround::Locator).map(|x| x.0), size_of(Surround::Arrow));
let (locator_size, arrow_size) = (size_of(Surround::Locator), size_of(Surround::Arrow));
// The fewest columns from `from` up in which the surrounds group in a band around `clip`, with
// their places; the scale bar's box `scale_bar` is the one at the scale tried.
let grouped = |clip: Rect, from: usize, known: &[(f64, f64); PUBLICATION_LEGEND_COLUMNS], scale_bar: (f64, f64)| {
(from..known.len()).find_map(|i| {
bands_around(clip)
.iter()
.find_map(|band| veil_panel(*band, whole(known[i]), locator_side, arrow_size, scale_bar, GROUP_GAP))
.find_map(|band| veil_panel(*band, whole(known[i]), locator_size, arrow_size, scale_bar, GROUP_GAP))
.map(|places| (i, places))
})
};
Expand Down Expand Up @@ -1852,37 +1862,50 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu
let spot_of = |what: Surround| spots.iter().find(|(kind, _)| *kind == what).map(|(_, r)| *r);
// In a column, at its top, centred across it; otherwise in its corner over the map.
let locator_rect = match column {
Some(c) => Some((c.x + (c.w - side) / 2.0, c.y, side, side)),
Some(c) => Some((c.x + (c.w - locators_w) / 2.0, c.y, locators_w, side)),
None => spot_of(Surround::Locator).inspect(|&r| placed.push(("locator", r))),
};
let surround_box = |fill: Rgba| if style.cards() { pub_card(fill, clear, 0.0, 2.0 * k) } else { pub_box(fill, clear, 0.0) };
if let (Some((map, locator_scale, shape, locator_center)), Some(r)) = (&locator_map, locator_rect) {
if let Some(r) = locator_rect.filter(|_| !locator_maps.is_empty()) {
if let (true, Some(c)) = (card, column) {
l.add(
"Locator Card",
(c.x - card_pad, r.1 - card_pad, c.w + 2.0 * card_pad, r.3 + 2.0 * card_pad),
pub_card(Rgba::rgb(0xFF, 0xFF, 0xFF), Rgba::new(0x2B, 0x26, 0x20, 60), 0.4, card_r),
);
}
l.add(
"Locator",
r,
ElementKind::MapFrame {
map: map.clone(),
center: *locator_center,
scale: *locator_scale,
shape: shape.clone(),
grid: None,
sections: Vec::new(),
extent_of: Some(frame),
extent_color: rustgis_map::layout::INDICATOR_COLOR,
extent_width: rustgis_map::layout::INDICATOR_WIDTH,
border_color: rustgis_map::layout::FRAME_BORDER_COLOR,
border_width: rustgis_map::layout::FRAME_BORDER_WIDTH,
bearing: 0.0,
pitch: 0.0,
},
);
// Inset first from the left. A pair over the map's right half is mirrored, so the inset
// is the one against the frame's edge there too.
let from_right = column.is_none() && r.0 + r.2 / 2.0 > fx + fw / 2.0;
// What the next locator outlines: the map frame, then the locator before it.
let mut target = frame;
for (i, (kind, (map, locator_scale, shape, locator_center))) in locator_maps.iter().enumerate() {
let slot = if from_right { locator_maps.len() - 1 - i } else { i };
let name = match kind {
_ if locator_maps.len() == 1 => "Locator",
Comment thread
jgregoriorincon marked this conversation as resolved.
Resolved
Locator::Inset => "Locator Inset",
Locator::Globe => "Locator Globe",
};
target = l.add(
name,
(r.0 + slot as f64 * (side + locator_gap), r.1, side, r.3),
ElementKind::MapFrame {
map: map.clone(),
center: *locator_center,
scale: *locator_scale,
shape: shape.clone(),
grid: None,
sections: Vec::new(),
extent_of: Some(target),
extent_color: rustgis_map::layout::INDICATOR_COLOR,
extent_width: rustgis_map::layout::INDICATOR_WIDTH,
border_color: rustgis_map::layout::FRAME_BORDER_COLOR,
border_width: rustgis_map::layout::FRAME_BORDER_WIDTH,
bearing: 0.0,
pitch: 0.0,
},
);
}
}
if let Some(r) = spot_of(Surround::Arrow) {
placed.push(("north arrow", r));
Expand All @@ -1894,7 +1917,7 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu
// In a panel, the legend under the locator, as tall as it needs within what is left.
let legend_rect = match column {
Some(c) if content_h > 0.0 => {
let ly = c.y + if locator_map.is_some() { side + 3.0 * k + if card { 2.0 * card_pad } else { 0.0 } } else { 0.0 };
let ly = c.y + if !locator_maps.is_empty() { side + 3.0 * k + if card { 2.0 * card_pad } else { 0.0 } } else { 0.0 };
let room_h = c.y + c.h - ly;
if room_h < MIN_LEGEND_MM {
warnings.push("the side column leaves the legend no room under the locator, so it is left out: shorten its texts".into());
Expand Down Expand Up @@ -2084,7 +2107,9 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu
if let Some(crs) = p.get("grid").and_then(|g| g.get("crs")).and_then(Value::as_str) {
crate::cmd::say_crs_note(s, crs);
}
let locator = locator_map.map(|(map, ..)| map);
// One locator's map by name; two, both names, the inset's first.
let mut named_maps: Vec<String> = locator_maps.into_iter().map(|(_, (map, ..))| map).collect();
Comment thread
jgregoriorincon marked this conversation as resolved.
Resolved
let locator = if named_maps.len() > 1 { json!(named_maps) } else { json!(named_maps.pop()) };
Ok(
json!({"layout": i, "name": name, "profile": profile.id, "page": [w, h], "scale": scale, "grid": step, "locator": locator, "style": style.code(), "arrangement": arrangement_used, "legendColumns": legend.as_ref().map(|_| legend_cols), "mapShift": [map_shift.0, map_shift.1], "veiled": veiled.is_some(), "legendBox": legend_rect.is_some() && !legend_bare, "elements": elements, "moved": moved, "coverage": coverage_written, "warnings": warnings}),
)
Expand Down Expand Up @@ -2252,23 +2277,31 @@ pub(crate) fn globe_locator_center(map: &Map, area: Coord, scale: f64, side_mm:
if globe(inside).forward(area).is_some() { (inside, true) } else { (area, false) }
}

/// Parses the publication's locator choice with its default: a globe on a sheet, none on a figure
/// or where the map is itself the globe seen whole (it would only show it again, smaller).
pub(in crate::cmd::layout) fn publication_locator(p: &Value, sheet: bool, whole_globe: bool) -> Result<Locator, String> {
/// Parses the publication's locator choice, a name or a list of "inset" and "globe", with its
/// default: a globe on a sheet, none on a figure or where the map is itself the globe seen whole (it
/// would only show it again, smaller). A list is a set: whatever its order, the inset comes first.
pub(in crate::cmd::layout) fn publication_locators(p: &Value, sheet: bool, whole_globe: bool) -> Result<Vec<Locator>, String> {
let one = |v: &Value| match v.as_str().map(str::trim) {
Some("globe") => Ok(Some(Locator::Globe)),
Some("inset") => Ok(Some(Locator::Inset)),
Some("none") => Ok(None),
_ => Err("locator is \"globe\", \"inset\", \"none\" or a list of \"inset\" and \"globe\"".to_string()),
};
Ok(match p.get("locator").filter(|v| !v.is_null()) {
None => {
if sheet && !whole_globe {
Locator::Globe
} else {
Locator::None
None => (sheet && !whole_globe).then_some(Locator::Globe).into_iter().collect(),
Some(Value::Array(list)) => {
let mut chosen = Vec::new();
for v in list {
let locator = one(v)?.ok_or("locator: \"none\" goes alone, not in a list")?;
if chosen.contains(&locator) {
return Err(format!("locator: {v} is given twice"));
}
chosen.push(locator);
}
chosen.sort_by_key(|&l| l == Locator::Globe);
chosen
}
Some(v) => match v.as_str().map(str::trim) {
Some("globe") => Locator::Globe,
Some("inset") => Locator::Inset,
Some("none") => Locator::None,
_ => return Err("locator is \"globe\", \"inset\" or \"none\"".into()),
},
Some(v) => one(v)?.into_iter().collect(),
})
}

Expand Down
Loading
Loading