Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e31f190
feat(map): an MGRS grid on the map, its squares named (#1042 piece 8)
flight1973 Nov 16, 2026
cfe9897
feat(map): the grid can go on top of the layers, in a color of its own
flight1973 Nov 17, 2026
c45945e
fix(map): saved grid settings and MGRS steps are required by name; na…
flight1973 Nov 17, 2026
ab7d7bb
fix(map): an empty grid pass draws nothing on the GPU; names past 84°…
flight1973 Nov 17, 2026
bf8e75b
test(engine): a fixture project with an MGRS grid on top in its own c…
flight1973 Nov 17, 2026
669cb5c
Merge branch 'main' into feat/1042-mgrs-grid
giswqs Nov 17, 2026
b278812
style: format after the main merge, and end the MGRS fixture with a n…
flight1973 Nov 18, 2026
3e75222
fix(ui): the grid color keeps its RGB when only its opacity changes; …
flight1973 Nov 18, 2026
8833795
docs(map): MGRS names go with the lines at no opacity and pause with …
flight1973 Nov 18, 2026
8aeacfc
test(ui): the grid color keeps its RGB when only its opacity is raised
flight1973 Nov 19, 2026
646e7f1
Merge remote-tracking branch 'origin/main' into sync/2321
flight1973 Nov 19, 2026
c1eb725
Merge remote-tracking branch 'origin/main' into feat/1042-mgrs-grid
flight1973 Nov 20, 2026
aa97fb0
Merge remote-tracking branch 'origin/main' into feat/1042-mgrs-grid
flight1973 Nov 20, 2026
fab4a4f
test(engine): the saved-task grid color test uses a valid color
flight1973 Nov 20, 2026
af971fa
fix(map): a map's look keeps and compares the grid drawn over the lay…
flight1973 Nov 20, 2026
fa2203e
Merge remote-tracking branch 'origin/main' into feat/1042-mgrs-grid
flight1973 Nov 21, 2026
2ef8732
Merge remote-tracking branch 'origin/main' into feat/1042-mgrs-grid
flight1973 Nov 21, 2026
c77d4da
docs(render): the MGRS label check is a sample of nine points, as lab…
flight1973 Nov 21, 2026
be9092c
Merge remote-tracking branch 'origin/main' into pr-2321
giswqs Nov 21, 2026
ddc9fa6
Address Claude review feedback
giswqs Nov 21, 2026
425cbb4
Merge remote-tracking branch 'origin/main' into pr-2321
giswqs Nov 21, 2026
cd96a0b
Address Claude review feedback
giswqs Nov 21, 2026
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
45 changes: 41 additions & 4 deletions crates/engine/src/cmd/navigate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub fn commands() -> Vec<C> {
C::new("map.basemap", "Basemap", "Home › Add", basemap).roles(&[]).effects(crate::policy::Effects::NONE)
.params(r##"{"name": "paper"|"midnight"|"ocean"|"atlas"|"blank", "keepTiles"?: bool (keeps the web tile basemaps over it), "color"?: "#RRGGBB" (blank: the paper's colour, drawn where a blank map draws white, the tilted view's sky included; null or #FFFFFF: white; default: as it was. Another basemap takes the paper off and keeps its own colours; a color given with it is said as a warning)}"##),
C::new("map.graticule", "Graticule", "View › Display", graticule).roles(&[]).effects(crate::policy::Effects::NONE)
.params(r#"{"on"?: bool (toggles when omitted, on when a type or crs is given), "type"?: "degrees"|"measured"|"utm", "crs"?: a projected system for the measured grid (EPSG:2056, WKT or a PROJ string; "" or null: the map's own when projected, else the UTM zone at the view's centre)}"#),
.params(r##"{"on"?: bool (toggles when omitted, on when a type or crs is given, kept as it is when only onTop or color is given), "type"?: "degrees"|"measured"|"utm"|"mgrs", "crs"?: a projected system for the measured grid (EPSG:2056, WKT or a PROJ string; "" or null: the map's own when projected, else the UTM zone at the view's centre), "onTop"?: bool (the lines over the layers, under the labels; false or null: with the basemap, under the layers), "color"?: "#RRGGBB"|"#RRGGBBAA" ("" or null: the basemap's)}"##),
C::new("map.reloadWebLayers", "Reload Web Layers", "View › Display", |_, _| {
// The map view draws again when the tile cache's generation moves.
crate::render::rustgis_tiles::cache::clear();
Expand Down Expand Up @@ -868,9 +868,26 @@ fn set_bearing(s: &mut Session, p: &Value) -> CmdResult {

/// Shows or hides the map's graticule, and sets what it draws: a type or a coordinate system
/// given shows it too. A coordinate system is for the measured grid, and refused (naming it) when
/// it can't be read or isn't projected.
/// it can't be read or isn't projected. Whether its lines go over the layers, and their color,
/// are set without showing or hiding it.
fn graticule(s: &mut Session, p: &Value) -> CmdResult {
use rustgis_map::graticule::GraticuleType;
let on_top = match p.get("onTop") {
None => None,
// As for the color: null puts the default back (under the layers).
Some(Value::Null) => Some(false),
Some(v) => Some(super::bool_value(v).ok_or_else(|| format!("onTop must be true or false, not {v}"))?),
};
let color = match p.get("color") {
None => None,
Some(Value::Null) => Some(None),
Some(Value::String(c)) if c.trim().is_empty() => Some(None),
Some(v) => Some(Some(
v.as_str()
.and_then(rustgis_map::Rgba::from_hex)
.ok_or_else(|| format!("color must be #RRGGBB or #RRGGBBAA (\"\" or null for the basemap's), not {v}"))?,
)),
};
let kind = match p.get("type") {
None | Some(Value::Null) => None,
Some(Value::String(t)) => Some(GraticuleType::from_name(t).ok_or_else(|| {
Expand Down Expand Up @@ -914,12 +931,32 @@ fn graticule(s: &mut Session, p: &Value) -> CmdResult {
return Err(format!("crs is the measured grid's; the graticule is \"{}\" (give \"type\": \"measured\")", kind_after.code()));
}
let set = kind.is_some() || crs.is_some();
m.graticule = super::b(p, "on").unwrap_or(if set { true } else { !m.graticule });
// Only the lines' place or color given: shown or hidden as it was.
let styled = on_top.is_some() || color.is_some();
m.graticule = super::b(p, "on").unwrap_or(if set {
true
} else if styled {
m.graticule
} else {
!m.graticule
});
m.graticule_type = kind_after;
if let Some(c) = crs {
m.graticule_crs = c;
}
Ok(json!({"on": m.graticule, "type": m.graticule_type.code(), "crs": m.graticule_crs}))
if let Some(t) = on_top {
m.graticule_on_top = t;
}
if let Some(c) = color {
m.graticule_color = c;
}
Ok(json!({
"on": m.graticule,
"type": m.graticule_type.code(),
"crs": m.graticule_crs,
"onTop": m.graticule_on_top,
"color": m.graticule_color.map(rustgis_map::Rgba::hex),
}))
}

fn basemap(s: &mut Session, p: &Value) -> CmdResult {
Expand Down
3 changes: 3 additions & 0 deletions crates/engine/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ pub const CAPABILITIES: &[&str] = &[
"layout-element-background",
SIZE_BY_CAPABILITY,
"picture-markers",
"graticule-mgrs",
Comment thread
giswqs marked this conversation as resolved.
Resolved
"graticule-on-top",
"graticule-color",
"layout-element-ink",
"layout-element-wrap",
"layout-chart-data",
Expand Down
75 changes: 74 additions & 1 deletion crates/engine/src/project_capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ const COMMAND_CAPABILITIES: &[(&str, CommandCheck)] = &[
("tabulate-intersection-empty-zones", command_uses_tabulate_empty_zones),
("layout-element-background", command_uses_element_background),
("picture-markers", command_uses_picture_marker),
("graticule-mgrs", command_draws_mgrs_graticule),
("graticule-on-top", command_puts_graticule_on_top),
("graticule-color", command_colors_graticule),
("layout-element-ink", command_uses_element_ink),
("layout-element-wrap", command_uses_element_wrap),
("layout-chart-data", command_uses_chart_data),
Expand All @@ -136,6 +139,42 @@ const COMMAND_CAPABILITIES: &[(&str, CommandCheck)] = &[
("layout-frame-border", command_uses_frame_border),
];

/// A saved `map.graticule` that switches to the MGRS grid, its type read as the command reads it:
/// an older reader refuses the type, so the command would fail there.
fn command_draws_mgrs_graticule(id: &str, params: &Value) -> bool {
match id {
"map.graticule" => params
.get("type")
.and_then(Value::as_str)
.and_then(rustgis_map::graticule::GraticuleType::from_name)
.is_some_and(|t| t == rustgis_map::graticule::GraticuleType::Mgrs),
"script.run" => params.get("script").and_then(Value::as_str).is_some_and(|s| script_uses(s, command_draws_mgrs_graticule)),
_ => false,
}
}

/// A saved `map.graticule` that sets whether the grid draws over the layers, or puts the default
/// back with `null`: an older reader ignores the key, and without `on`, `type` or `crs` it toggles
/// the grid where this one keeps it as it is, so any value needs it.
fn command_puts_graticule_on_top(id: &str, params: &Value) -> bool {
match id {
"map.graticule" => params.get("onTop").is_some(),
"script.run" => params.get("script").and_then(Value::as_str).is_some_and(|s| script_uses(s, command_puts_graticule_on_top)),
_ => false,
}
}

/// A saved `map.graticule` that sets the grid's color, or puts the palette's back with `null` or
/// `""`: an older reader ignores the key, and without `on`, `type` or `crs` it toggles the grid
/// where this one keeps it as it is, so any value needs it.
fn command_colors_graticule(id: &str, params: &Value) -> bool {
match id {
"map.graticule" => params.get("color").is_some(),
"script.run" => params.get("script").and_then(Value::as_str).is_some_and(|s| script_uses(s, command_colors_graticule)),
_ => false,
}
}

/// A layout command that changes a map frame's border (#2557): an older reader warns that it
/// ignores `border` and draws the default one. `null` only gives the default back, which an older
/// reader's frames always have.
Expand Down Expand Up @@ -441,12 +480,21 @@ fn map_capabilities<'a>(maps: impl IntoIterator<Item = &'a Map>) -> Vec<&'static
mut sized,
mut pictures,
mut zarr,
) = (false, false, false, false, false, false, false, false, false, false, false);
mut mgrs,
mut on_top,
mut grid_color,
) = (false, false, false, false, false, false, false, false, false, false, false, false, false, false);
let (mut offline_area_id, mut paper, mut native) = (false, false, false);
for map in maps {
offline_area_id |= map.offline_area_id.is_some();
// A blank basemap's paper colour (#2532), which an older reader would draw and save white.
paper |= map.paper.is_some();
// An older reader doesn't know the MGRS graticule (#1042 piece 8): it refuses the
// project by name rather than failing to read the type.
mgrs |= map.graticule_type == rustgis_map::graticule::GraticuleType::Mgrs;
// Nor the graticule drawn over the layers or in a color of its own: it would save them away.
on_top |= map.graticule_on_top;
grid_color |= map.graticule_color.is_some();
if let Some(t) = &map.view.terrain {
block |= t.block.is_some();
// A round block (#2318), which an older reader would draw and save as a box.
Expand Down Expand Up @@ -482,6 +530,9 @@ fn map_capabilities<'a>(maps: impl IntoIterator<Item = &'a Map>) -> Vec<&'static
(offline_area_id, "offline-map-area-id"),
(paper, "blank-paper"),
(native, super::NATIVE_COORDINATES),
(mgrs, "graticule-mgrs"),
(on_top, "graticule-on-top"),
(grid_color, "graticule-color"),
]
.into_iter()
.filter_map(|(used, name)| used.then_some(name))
Expand Down Expand Up @@ -564,6 +615,28 @@ mod tests {
serde_json::from_slice(bytes).unwrap()
}

/// A saved MGRS graticule drawn on top in a color of its own (#1042 piece 8) reads back as it
/// was, and saving names all three again; a map without them names none.
#[test]
fn graticule_mgrs_fixture_reads_its_grid() {
use rustgis_map::graticule::GraticuleType;
let fixture = Project::from_json(include_str!("../../../schema/fixtures/graticule_mgrs.rgis")).unwrap();
let saved = serde_json::to_value(&fixture).unwrap();
assert_eq!(saved["requires"], json!(["graticule-mgrs", "graticule-on-top", "graticule-color"]));
let map = &fixture.maps[0];
assert_eq!(map.graticule_type, GraticuleType::Mgrs);
assert!(map.graticule && map.graticule_on_top);
assert_eq!(map.graticule_color.map(|c| (c.r(), c.g(), c.b(), c.a())), Some((48, 48, 48, 153)));
let reopened = Project::from_json(&saved.to_string()).unwrap();
assert_eq!(serde_json::to_value(&reopened).unwrap(), saved);
let mut plain = fixture;
let map = &mut plain.maps[0];
map.graticule_type = GraticuleType::Utm;
map.graticule_on_top = false;
map.graticule_color = None;
assert!(serde_json::to_value(&plain).unwrap().get("requires").is_none());
}

/// A saved image marker reads back as the image it was, and saving names it again.
#[test]
fn picture_markers_fixture_reads_its_image() {
Expand Down
Loading
Loading