From 62c04e1ce61a74c0b5dacf3208ea323624c4563f Mon Sep 17 00:00:00 2001 From: mavrick Date: Tue, 24 Nov 2026 11:27:24 -0600 Subject: [PATCH 1/4] feat(edit): create points by coordinates --- crates/engine/command-surface.txt | 1 + crates/engine/src/cmd/design.rs | 11 +- crates/engine/src/cmd/edit.rs | 200 ++++++++++++++++++++++++++++++ crates/engine/src/cmd/items.rs | 2 +- crates/engine/src/cmd/navigate.rs | 2 +- crates/ui-egui/src/chrome.rs | 11 ++ crates/ui-egui/src/dialogs.rs | 141 +++++++++++++++++++++ crates/ui-egui/src/ribbon.rs | 10 ++ crates/ui-egui/src/showme.rs | 3 +- docs/user-guide/editing.md | 16 +++ 10 files changed, 391 insertions(+), 6 deletions(-) diff --git a/crates/engine/command-surface.txt b/crates/engine/command-surface.txt index a2d195a995..f0624cbae9 100644 --- a/crates/engine/command-surface.txt +++ b/crates/engine/command-surface.txt @@ -81,6 +81,7 @@ edit.addBox layer? box attributes? template? edit.addCircle layer? circle attributes? template? edit.addFeature layer? table? geometry attributes? template? edit.addField layer? table? name type +edit.addPoint x y crs? layer? name? edit.applyShapeConversion preview confirm edit.boxInfo layer? row edit.calculateField layer? table? field expression diff --git a/crates/engine/src/cmd/design.rs b/crates/engine/src/cmd/design.rs index 68b5c3a3ce..a5b927bd61 100644 --- a/crates/engine/src/cmd/design.rs +++ b/crates/engine/src/cmd/design.rs @@ -2966,11 +2966,16 @@ pub(crate) fn new_feature_inputs(input: &super::InputContext<'_>, p: &Json) -> R return Ok(inputs); } let mut inputs = super::Inputs::primary(s, p)?; - if let Elevation::Surface(name) = &s.map().editing.settings.elevation { - inputs.layers.extend(surface_layer(input, name).map(|l| (s.map().instance_id(), l.id))); + include_new_feature_surface(input, &mut inputs); + Ok(inputs) +} + +/// Every new feature may sample the configured elevation raster, even in a newly created layer. +pub(super) fn include_new_feature_surface(input: &super::InputContext<'_>, inputs: &mut super::Inputs) { + if let Elevation::Surface(name) = &input.map().editing.settings.elevation { + inputs.layers.extend(surface_layer(input, name).map(|l| (input.map().instance_id(), l.id))); inputs.state = json!({"surface":name}); } - Ok(inputs) } #[cfg(test)] diff --git a/crates/engine/src/cmd/edit.rs b/crates/engine/src/cmd/edit.rs index a4110ec14a..bf2757f823 100644 --- a/crates/engine/src/cmd/edit.rs +++ b/crates/engine/src/cmd/edit.rs @@ -23,6 +23,8 @@ pub fn commands() -> Vec { C::new("edit.calculateGeometry", "Calculate Geometry", "Attribute Table", crate::geometry_calc::run).roles(&[]).effects(crate::policy::Effects::NONE) .when(super::design::need_editable) .params(r#"{"layer"?, "field": string, "create": bool, "overwrite": bool, "property": string, "unit": string, "epsg"?: number, "scope": "all"|"selected"}"#), + C::new("edit.addPoint", "Create Point by Coordinates", "Edit › Features", add_point).inputs(point_inputs).roles(&[]).effects(crate::policy::Effects::NONE) + .params(r#"{"x": number or degrees text, "y": number or degrees text, "crs"?: coordinate system|"map"|layer name (omitted: longitude/latitude, including degrees text), "layer"?: name|id (otherwise the active loaded point layer, or a new Points layer), "name"?: text (requires a text field named name in an existing layer)}"#), C::new("edit.addFeature", "Create Feature", "Edit › Features", add_feature).inputs(super::design::new_feature_inputs).roles(&[]).effects(crate::policy::Effects::NONE) .when(super::design::need_editable_or_table) .params(r#"{"layer"?, "table"?: name|id (a standalone table: adds a row, without geometry or template), "geometry": GeoJSON geometry (lon/lat; left out for a table), "attributes"?: {field: value}, "template"?: feature template}"#), @@ -61,6 +63,94 @@ pub fn commands() -> Vec { ] } +/// Whether this layer can receive a coordinate point without loading a streamed source. +pub fn accepts_coordinate_point(l: &rustgis_map::Layer) -> bool { + !l.is_raster() && !l.graphics && !l.dataset.windowed && l.geometry_type() == GeometryType::Point +} + +/// A loaded point layer can accept a single point without reading or materializing a source. +fn point_target(input: &impl super::InputSource, p: &Json) -> Result, String> { + let s = input.input_context(); + let explicit = match p.get("layer") { + None | Some(Json::Null) => false, + Some(Json::String(_) | Json::Number(_)) => true, + _ => return Err("layer must be a name or id".into()), + }; + let id = if explicit { Some(s.layer_id(p)?) } else { s.active_layer }; + let usable = id.filter(|id| s.map().layer(*id).is_some_and(accepts_coordinate_point)); + if explicit && usable.is_none() { + return Err("choose a loaded point layer".into()); + } + Ok(usable) +} + +/// Declare the actual target and the elevation surface, including for a new layer. +fn point_inputs(input: &super::InputContext<'_>, p: &Json) -> Result { + let target = point_target(input, p)?; + let mut inputs = super::Inputs::layers(target.and_then(|id| input.map().layer(id)).map(|l| (input.map(), l))); + inputs.uses_default = p.get("layer").is_none_or(Json::is_null); + super::design::include_new_feature_surface(input, &mut inputs); + Ok(inputs) +} + +/// Creates a point through ordinary edit rules in one Undo step, including a fallback +/// layer. Like other feature creation, editing must be on. Runs inline like `edit.addFeature`; +/// snapping to stored places in a projected layer can search its existing features. +fn add_point(s: &mut Session, p: &Json) -> CmdResult { + editing_on(s)?; + // Keep this command's ingress to the documented X/Y pair; the shared parser also serves + // commands accepting a combined position, which this form does not offer. + if ["position", "lon", "lat"].iter().any(|key| p.get(key).is_some_and(|v| !v.is_null())) { + return Err("use x and y for a coordinate point".into()); + } + for key in ["x", "y"] { + if p.get(key).is_none_or(Json::is_null) { + return Err(format!("{key} is required")); + } + } + let (at, _) = super::navigate::typed_place(s.map(), p, false)?; + let target = point_target(s, p)?; + let name = match p.get("name") { + None | Some(Json::Null) => "", + Some(Json::String(t)) => t.trim(), + _ => return Err("name must be text".into()), + }; + let field = if let Some(id) = target { + let l = s.map().layer(id).ok_or("no layer")?; + l.dataset.fields.iter().find(|f| f.name.eq_ignore_ascii_case("name") && f.ty == FieldType::Text).map(|f| f.name.clone()) + } else { + Some("name".into()) + }; + if !name.is_empty() && field.is_none() { + return Err("this layer has no text field named name; leave Name blank or choose another point layer".into()); + } + let create = |s: &mut Session| { + let id = match target { + Some(id) => id, + None => { + super::items::layer_template(s, &json!({"template":"points"}))?; + s.active_layer.ok_or("the point layer was not created")? + } + }; + let mut attributes = serde_json::Map::new(); + if !name.is_empty() + && let Some(field) = field + { + attributes.insert(field, json!(name)); + } + let mut result = add_geometry(s, id, &json!({"attributes":attributes}), Geometry::Point(at))?; + if target.is_none() { + // The UI explains the fallback before submission; non-UI callers need it too. + s.notify("Created a Points layer because no loaded point layer was selected", false); + } + result["layer"] = json!(id); + Ok(result) + }; + // Only fallback creation needs its own savepoint: it never writes an existing layer's rows. + // A plugin may handle the error and continue; it must not keep an empty fallback layer. + if target.is_none() { s.savepoint("Create Point by Coordinates", create) } else { create(s) } +} + /// What an edit command changes: a layer, or a standalone table (by its position among the /// project's tables). #[derive(Clone, Copy)] @@ -2160,3 +2250,113 @@ mod tests { } } } + +#[cfg(test)] +mod point_tests { + use super::*; + + #[test] + fn coordinate_points_share_a_layer_and_undo_as_single_edits() { + let mut s = Session::new(crate::Project::default()); + s.run("edit.enable", &json!({"on":true})).unwrap(); + let mark = s.notice_mark(); + let first = s.run("edit.addPoint", &json!({"x":14.3,"y":-41.2,"name":"Survey"})).unwrap(); + let id = first["layer"].as_u64().unwrap() as u32; + let l = s.map().layer(id).unwrap(); + assert_eq!(l.dataset.features.len(), 1); + assert_eq!(l.dataset.value(0, 0), &Value::Text("Survey".into())); + assert_eq!(l.dataset.features.geometry(0), Some(&Geometry::Point(rustgis_geom::Coord::new(14.3, -41.2)))); + assert!(s.map().editing.settings.enabled); + assert_eq!( + s.notices_since(mark).iter().filter(|n| n.text == "Created a Points layer because no loaded point layer was selected").count(), + 1 + ); + s.run("edit.addPoint", &json!({"x":0,"y":0})).unwrap(); + assert_eq!(s.map().layers.len(), 1); + assert_eq!(s.map().layer(id).unwrap().dataset.features.len(), 2); + assert_eq!( + s.notices_since(mark).iter().filter(|n| n.text == "Created a Points layer because no loaded point layer was selected").count(), + 1 + ); + s.run("edit.undo", &json!({})).unwrap(); + assert_eq!(s.map().layer(id).unwrap().dataset.features.len(), 1); + s.run("edit.undo", &json!({})).unwrap(); + assert!(s.map().layers.is_empty()); + s.run("edit.redo", &json!({})).unwrap(); + assert_eq!(s.map().layer(id).unwrap().dataset.features.len(), 1); + } + + #[test] + fn coordinate_point_refusals_leave_no_layer_and_projected_input_is_converted() { + let mut s = Session::new(crate::Project::default()); + s.run("edit.enable", &json!({"on":true})).unwrap(); + for p in [ + json!({"x":"bad","y":0}), + json!({"x":0,"y":91}), + json!({"x":0,"y":0,"crs":"EPSG:0"}), + json!({"x":0,"y":0,"name":1}), + json!({"x":0,"y":0,"layer":true}), + ] { + assert!(s.run("edit.addPoint", &p).is_err(), "{p}"); + assert!(s.map().layers.is_empty()); + } + let at = rustgis_geom::lonlat_to_merc(rustgis_geom::Coord::new(7.44, 46.95)); + s.run("edit.addPoint", &json!({"x":at.x,"y":at.y,"crs":"EPSG:3857"})).unwrap(); + let l = s.map().layers.first().unwrap(); + let Some(Geometry::Point(at)) = l.dataset.features.geometry(0) else { panic!("point expected") }; + assert!((at.x - 7.44).abs() < 1e-8); + assert!((at.y - 46.95).abs() < 1e-8); + } + #[test] + fn coordinate_points_respect_editing_and_declare_the_surface_for_a_new_layer() { + use super::super::InputSource; + use rustgis_data::raster::{ColorHint, Crs, GeoTransform, Raster}; + let mut s = Session::new(crate::Project::default()); + s.run("edit.enable", &json!({"on":false})).unwrap(); + assert!(s.run("edit.addPoint", &json!({"x":0,"y":0})).unwrap_err().contains("editing is turned off")); + assert!(s.map().layers.is_empty()); + let raster = Raster::new( + "dem", + 1, + 1, + vec![vec![12.0]], + GeoTransform { origin_x: -1.0, origin_y: 1.0, pixel_width: 2.0, pixel_height: -2.0 }, + Crs::LonLat, + None, + ColorHint::Gray, + "Float32", + ) + .unwrap(); + let surface = s.map_mut().add_raster("dem", rustgis_map::RasterLayer::from_path(raster, "dem.tif")); + s.map_mut().editing.settings.elevation = rustgis_map::design::Elevation::Surface("dem".into()); + s.active_layer = None; + let inputs = point_inputs(&s.input_context(), &json!({"x":0,"y":0})).unwrap(); + assert_eq!(inputs.layers, vec![(s.map().instance_id(), surface)]); + assert!(inputs.uses_default); + s.run("edit.enable", &json!({"on":true})).unwrap(); + s.run("edit.addPoint", &json!({"x":0,"y":0})).unwrap(); + let id = s.active_layer.unwrap(); + let held = s.map().layer(id).unwrap().dataset.clone(); + s.run("edit.enable", &json!({"on":false})).unwrap(); + assert!(s.run("edit.addPoint", &json!({"x":1,"y":1})).unwrap_err().contains("editing is turned off")); + assert_eq!(s.map().layer(id).unwrap().dataset, held); + } + + #[test] + fn coordinate_points_inherit_project_storage_and_reopen() { + use rustgis_data::raster::Crs; + let mut s = Session::new(crate::Project::default()); + s.run("project.coordinateSystem", &json!({"crs":"EPSG:3857"})).unwrap(); + s.run("edit.addPoint", &json!({"x":14.3,"y":-41.2,"name":"Survey"})).unwrap(); + let expected = Geometry::Point(rustgis_geom::lonlat_to_merc(rustgis_geom::Coord::new(14.3, -41.2))); + let layer = s.map().layers.first().unwrap(); + assert_eq!(layer.dataset.coord_crs(), Crs::WebMercator); + assert_eq!(layer.dataset.features.geometry(0), Some(&expected)); + let (text, _) = s.project.saved_text(None).unwrap(); + let reopened = crate::Project::from_json(&text).unwrap(); + let layer = reopened.maps.first().unwrap().layers.first().unwrap(); + assert_eq!(layer.dataset.coord_crs(), Crs::WebMercator); + assert_eq!(layer.dataset.features.geometry(0), Some(&expected)); + assert_eq!(layer.dataset.value(0, 0), &Value::Text("Survey".into())); + } +} diff --git a/crates/engine/src/cmd/items.rs b/crates/engine/src/cmd/items.rs index 45ce47278f..436e0f0914 100644 --- a/crates/engine/src/cmd/items.rs +++ b/crates/engine/src/cmd/items.rs @@ -976,7 +976,7 @@ fn package_gp(s: &mut Session) -> Result, String> { Ok(archive) } -fn layer_template(s: &mut Session, p: &Value) -> CmdResult { +pub(super) fn layer_template(s: &mut Session, p: &Value) -> CmdResult { let t = ps(p, "template").ok_or("template is required")?; let text = |n: &str| Field::new(n, FieldType::Text); let (gt, title, fields) = match t { diff --git a/crates/engine/src/cmd/navigate.rs b/crates/engine/src/cmd/navigate.rs index 1234b0cef8..7463431b39 100644 --- a/crates/engine/src/cmd/navigate.rs +++ b/crates/engine/src/cmd/navigate.rs @@ -855,7 +855,7 @@ fn degrees_text(v: f64) -> String { /// number or text in degrees, minutes and seconds. With it, what the reading assumed, for a /// notice: two bare numbers taken in an order, or an MGRS square taken at its center (`moving` /// says whether the map goes there, which the notice's wording follows). -fn typed_place(map: &Map, p: &Value, moving: bool) -> Result<(Coord, Option), String> { +pub(crate) fn typed_place(map: &Map, p: &Value, moving: bool) -> Result<(Coord, Option), String> { let position = match p.get("position") { None | Some(Value::Null) => None, Some(Value::String(t)) => Some(t.as_str()), diff --git a/crates/ui-egui/src/chrome.rs b/crates/ui-egui/src/chrome.rs index 5e60137f42..684b243279 100644 --- a/crates/ui-egui/src/chrome.rs +++ b/crates/ui-egui/src/chrome.rs @@ -826,6 +826,16 @@ pub fn shortcuts(app: &mut RustGisApp, ctx: &egui::Context) { if crate::saveprompt::waiting(app) || ctx.memory(|m| m.top_modal_layer()).is_some() || app.ui.shortcut_editor.capturing() { return; } + // The repeat-use form is not modal: another pane or an unfinished sketch keeps Escape. + let point_dialog_owns_escape = app.dialogs.open == Some("createPointXY") + && match ctx.memory(|m| m.focused()) { + Some(id) => ctx.read_response(id).is_some_and(|r| r.layer_id.id == egui::Id::unique(("dialog", "createPointXY"))), + None => app.map.sketch_len() == 0 && !app.session.map().view.first_person, + }; + if point_dialog_owns_escape && ctx.input_mut(|i| i.consume_key(Modifiers::NONE, Key::Escape)) { + app.dialogs.open = None; + return; + } if app.ui.history_jump.is_some() && app.dialogs.open.is_none() && !crate::crspicker::list_is_open(ctx) @@ -1117,6 +1127,7 @@ fn search_action(id: &str) -> Option { "project.coordinateSystem" => Dialog("projectProperties"), "map.rename" => Dialog("renameMap"), "map.goToXY" => Dialog("goToXY"), + "edit.addPoint" => Dialog("createPointXY"), "map.exportOrbit" => Dialog("exportOrbit"), "map.findPlace" => Dialog("findPlace"), "map.camera" | "map.setScale" => Dialog("camera"), diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index 645586301e..d69678bda7 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -150,6 +150,7 @@ impl Dialogs { let name: &'static str = match which { "selectByAttributes" => "selectByAttributes", "goToXY" => "goToXY", + "createPointXY" => "createPointXY", "bookmark" => "bookmark", "addField" => "addField", "calculateField" => "calculateField", @@ -344,6 +345,7 @@ pub fn show(app: &mut RustGisApp, ctx: &egui::Context) { let title = match which { "selectByAttributes" => "Select By Attributes", "goToXY" => "By Coordinates", + "createPointXY" => "Create Point by Coordinates", "bookmark" => "New Bookmark", "addField" => "Add Field", "calculateField" => "Calculate Field", @@ -439,6 +441,7 @@ pub fn show(app: &mut RustGisApp, ctx: &egui::Context) { ui.spacing_mut().item_spacing = vec2(8.0, 8.0); match which { "selectByAttributes" => close = select_by_attributes(app, ui, &t), + "createPointXY" => create_point_xy(app, ui), "goToXY" => { // UTM and MGRS are the Earth's grids, so another body's map offers degrees alone. // A grid reference, once typed, is where Go goes: the X and Y boxes gray out. @@ -1151,6 +1154,79 @@ pub fn open_dxf_path(app: &mut RustGisApp, path: &str) -> Result open_dxf(app, path, DxfSource::Path(path.to_string())) } +/// A repeat-use form: errors retain the entry, successful creation clears it and keeps focus +/// on X. The current selection is named each frame because this dialog is not modal. +fn create_point_xy(app: &mut RustGisApp, ui: &mut egui::Ui) { + let target = app + .session + .active_layer + .and_then(|id| app.session.map().layer(id)) + .filter(|l| rustgis_engine::cmd::edit::accepts_coordinate_point(l)); + let target = target.map(|l| l.name.clone()).unwrap_or_else(|| tl!("New Points layer").into()); + ui.label(i18n::fmt("Add to: {layer}", &[("layer", &target)])); + if app.session.active_layer.and_then(|id| app.session.map().layer(id)).is_some_and(|l| l.dataset.windowed) { + ui.label(tl!("The selected layer is read in place. Points will go into a new layer instead.")); + } + if !app.session.map().editing.settings.enabled { + ui.label(tl!("Turn editing on to add points.")); + if ui.button(tl!("Enable Editing")).clicked() + && let Err(e) = app.run("edit.enable", json!({"on":true})) + { + app.dialogs.error = Some(e); + } + } + ui.label(tl!("Coordinates use the system below, independently of the map. A new Points layer is saved in the project.")); + // Status hints disappear after fallback/Enable Editing; field identities must not shift. + let label = ui.label(tl!("X / Longitude")); + let x = ui + .add(egui::TextEdit::singleline(&mut app.dialogs.a).id(egui::Id::unique(("createPointXY", "x"))).desired_width(f32::INFINITY)) + .labelled_by(label.id); + let label = ui.label(tl!("Y / Latitude")); + ui.add(egui::TextEdit::singleline(&mut app.dialogs.b).id(egui::Id::unique(("createPointXY", "y"))).desired_width(f32::INFINITY)) + .labelled_by(label.id); + let label = ui.label(tl!("Coordinate system (blank: longitude/latitude)")); + ui.add( + egui::TextEdit::singleline(&mut app.dialogs.c) + .id(egui::Id::unique(("createPointXY", "crs"))) + .hint_text("EPSG:3857") + .desired_width(f32::INFINITY), + ) + .labelled_by(label.id); + let label = ui.label(tl!("Name (optional)")); + ui.add(egui::TextEdit::singleline(&mut app.dialogs.text).id(egui::Id::unique(("createPointXY", "name"))).desired_width(f32::INFINITY)) + .labelled_by(label.id); + ui.label(egui::RichText::new(tl!("Name uses a text field named name. Leave it blank if the selected layer has no such field.")).weak()); + let enter = ui.input(|i| i.key_pressed(egui::Key::Enter) && !i.modifiers.shift) && enter_is_the_dialogs(ui); + let t = Tokens::get(ui.ctx()); + let (add, close) = ui + .horizontal(|ui| { + let add = crate::widgets::dialog_button(ui, tl!("Add Point"), Some(t.accent), vec2(110.0, 28.0)).clicked(); + let close = crate::widgets::dialog_button(ui, tl!("Close"), None, vec2(110.0, 28.0)).clicked(); + (add, close) + }) + .inner; + if add || enter { + let crs = app.dialogs.c.trim(); + let mut p = json!({"x":app.dialogs.a.trim(), "y":app.dialogs.b.trim(), "name":app.dialogs.text.trim()}); + if !crs.is_empty() { + p["crs"] = json!(crs); + } + match app.run("edit.addPoint", p) { + Ok(_) => { + app.dialogs.a.clear(); + app.dialogs.b.clear(); + app.dialogs.text.clear(); + app.dialogs.error = None; + x.request_focus(); + } + Err(e) => app.dialogs.error = Some(e), + } + } + if close { + app.dialogs.open = None; + } +} + /// The systems Go To XY offers, as (what `map.goToXY` takes as `crs`, its label): degrees; on a /// flat map of the Earth, the map's own; and each layer read in a projected system, by name (at /// most [`XY_LAYER_SYSTEMS`], the first of each system). Also how many more systems the layers @@ -4886,4 +4962,69 @@ mod tests { assert!(h.query_by_label("Add").is_none(), "grouped features have no individual Add"); assert!(h.query_by_label("Remove").is_none(), "grouped features are removed in the Layers pane"); } + /// Drive the full app, including the shortcuts that own Escape and the dialog's Enter. + #[test] + fn coordinate_point_form_repeats_and_retains_invalid_input() { + use egui::accesskit::Role; + use egui_kittest::kittest::Queryable; + let mut app = RustGisApp::with_sample(); + app.run("project.new", json!({})).unwrap(); + app.run("edit.enable", json!({"on":true})).unwrap(); + app.run("layer.template", json!({"template":"points", "name":"Read in place"})).unwrap(); + let streamed = app.session.active_layer.unwrap(); + app.session.map_mut().layer_mut(streamed).unwrap().dataset.windowed = true; + app.run("ui.dialog", json!({"name":"createPointXY"})).unwrap(); + app.dialogs.a = "14.3".into(); + app.dialogs.b = "-41.2".into(); + app.dialogs.text = "Survey".into(); + let mut h = egui_kittest::Harness::builder().with_size(vec2(1400.0, 1000.0)).with_max_steps(64).build_ui_state( + |ui, app: &mut RustGisApp| { + let ctx = ui.ctx().clone(); + app.logic(&ctx); + app.ui(ui); + }, + app, + ); + h.run_steps(4); + h.get_by_role_and_label(Role::Button, "Add Point").click(); + h.run_steps(4); + assert_eq!(h.state().dialogs.open, Some("createPointXY")); + assert_eq!(h.state().dialogs.a, ""); + assert_eq!(h.state().dialogs.b, ""); + assert_eq!(h.state().dialogs.text, ""); + let point_layer = h.state().session.active_layer.unwrap(); + assert_eq!(h.state().session.map().layers.len(), 2); + assert_eq!(h.state().session.map().layer(point_layer).unwrap().dataset.features.len(), 1); + h.event(egui::Event::Text("bad".into())); + h.run_steps(3); + assert_eq!(h.state().dialogs.a, "bad", "successful fallback keeps typing in X after the streamed-layer hint disappears"); + h.state_mut().dialogs.b = "0".into(); + h.key_press(egui::Key::Enter); + h.run_steps(4); + assert!(h.state().dialogs.error.is_some()); + assert_eq!(h.state().dialogs.a, "bad"); + assert_eq!(h.state().session.map().layer(point_layer).unwrap().dataset.features.len(), 1); + h.state_mut().dialogs.a = "15".into(); + h.key_press(egui::Key::Enter); + h.run_steps(4); + assert!(h.state().dialogs.error.is_none()); + assert_eq!(h.state().session.map().layers.len(), 2); + assert_eq!(h.state().session.map().layer(point_layer).unwrap().dataset.features.len(), 2); + h.state_mut().run("tool.set", json!({"tool":"measure"})).unwrap(); + h.run_steps(3); + let at = h.state().map.view_rect.unwrap().0.right_bottom() - vec2(80.0, 80.0); + h.event(egui::Event::PointerMoved(at)); + for pressed in [true, false] { + h.event(egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() }); + } + h.run_steps(3); + assert_eq!(h.state().map.sketch_len(), 1); + h.key_press(egui::Key::Escape); + h.run_steps(3); + assert_eq!(h.state().map.sketch_len(), 0); + assert_eq!(h.state().dialogs.open, Some("createPointXY")); + h.key_press(egui::Key::Escape); + h.run_steps(4); + assert_eq!(h.state().dialogs.open, None); + } } diff --git a/crates/ui-egui/src/ribbon.rs b/crates/ui-egui/src/ribbon.rs index e5a9f18d4d..2d1206ec66 100644 --- a/crates/ui-egui/src/ribbon.rs +++ b/crates/ui-egui/src/ribbon.rs @@ -2836,6 +2836,16 @@ fn edit_tab(app: &mut RustGisApp, ui: &mut Ui) { ); }); group(ui, "Features", |ui| { + small( + ui, + app, + "goto_xy", + "Create Point by Coordinates…", + "Create a point at typed coordinates, in the selected point layer or a new Points layer.", + "ui.dialog", + json!({"name":"createPointXY"}), + false, + ); let gt = app.session.active_layer.and_then(|id| app.session.map().layer(id)).map(|l| l.geometry_type()); let (tool, icon) = match gt { Some(GeometryType::Polyline) => (Tool::CreateLine, "line_tool"), diff --git a/crates/ui-egui/src/showme.rs b/crates/ui-egui/src/showme.rs index bb30fd2148..52573d955f 100644 --- a/crates/ui-egui/src/showme.rs +++ b/crates/ui-egui/src/showme.rs @@ -31,7 +31,8 @@ pub struct ShowMe { } /// Ribbon buttons that open a dialog for a command, rather than running it: the dialog's name. -const DIALOGS: &[(&str, &str)] = &[("select.byAttributes", "selectByAttributes"), ("map.goToXY", "goToXY")]; +const DIALOGS: &[(&str, &str)] = + &[("select.byAttributes", "selectByAttributes"), ("map.goToXY", "goToXY"), ("edit.addPoint", "createPointXY")]; /// Starts showing where a step's command is; returns what to tell the user. pub fn start(app: &mut RustGisApp, st: &TaskStep) -> String { diff --git a/docs/user-guide/editing.md b/docs/user-guide/editing.md index 96d4001981..8b60ed8ec6 100644 --- a/docs/user-guide/editing.md +++ b/docs/user-guide/editing.md @@ -2,6 +2,22 @@ ## Creating features +**Edit › Features › Create Point by Coordinates…** creates points from known X/Y coordinates. +Turn editing on (also offered in the dialog), enter X and Y, optionally a name, and click +**Add Point** or press ++enter++. Leave the coordinate system blank for longitude/latitude +in decimal degrees or degrees, minutes and seconds, or enter a system such as `EPSG:3857` +for numeric eastings and northings. The map's display projection does not change their meaning. +The dialog stays open and clears X, Y and Name after success; ++esc++ closes it when +its fields have focus or no other work owns the key. On the map, Escape still cancels a sketch. + +Points join the selected loaded point layer. Otherwise, a new **Points** layer is created +in the project using the existing point-layer template and the project's coordinate system; +a layer read in place must first be loaded to receive edits. A name uses a +text field named `name` (ignoring case); new Points layers include it. Leave Name blank if +an existing layer has no such field. Each addition, including a new layer, is one Undo step. +The same operation is available through Command Search and `edit.addPoint`, for example: +`edit.addPoint {"x":14.3,"y":-41.2,"name":"Survey"}`. + **Edit › Create** draws new points, lines and polygons into the layer selected in Layers: click once for a point, or click each vertex and double-click to finish a line or polygon (++esc++ cancels). **Delete** (++delete++) removes the selected features across the map's layers. From cfe0020fb37a1718c38c062ff2a78500e59ee998 Mon Sep 17 00:00:00 2001 From: mavrick Date: Tue, 24 Nov 2026 12:26:52 -0600 Subject: [PATCH 2/4] fix(ui): record coordinate point target layers --- crates/ui-egui/src/dialogs.rs | 10 ++++++++++ crates/ui-egui/src/lib.rs | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index d69678bda7..8404fd14c4 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -4977,6 +4977,7 @@ mod tests { app.dialogs.a = "14.3".into(); app.dialogs.b = "-41.2".into(); app.dialogs.text = "Survey".into(); + app.ws.recording = Some(Vec::new()); let mut h = egui_kittest::Harness::builder().with_size(vec2(1400.0, 1000.0)).with_max_steps(64).build_ui_state( |ui, app: &mut RustGisApp| { let ctx = ui.ctx().clone(); @@ -4995,6 +4996,10 @@ mod tests { let point_layer = h.state().session.active_layer.unwrap(); assert_eq!(h.state().session.map().layers.len(), 2); assert_eq!(h.state().session.map().layer(point_layer).unwrap().dataset.features.len(), 1); + assert!( + h.state().ws.recording.as_ref().unwrap().last().unwrap().params.get("layer").is_none(), + "fallback records no incompatible target" + ); h.event(egui::Event::Text("bad".into())); h.run_steps(3); assert_eq!(h.state().dialogs.a, "bad", "successful fallback keeps typing in X after the streamed-layer hint disappears"); @@ -5010,6 +5015,11 @@ mod tests { assert!(h.state().dialogs.error.is_none()); assert_eq!(h.state().session.map().layers.len(), 2); assert_eq!(h.state().session.map().layer(point_layer).unwrap().dataset.features.len(), 2); + assert_eq!( + h.state().ws.recording.as_ref().unwrap().last().unwrap().params["layer"], + "Points", + "later points record their actual target" + ); h.state_mut().run("tool.set", json!({"tool":"measure"})).unwrap(); h.run_steps(3); let at = h.state().map.view_rect.unwrap().0.right_bottom() - vec2(80.0, 80.0); diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index ec2381883f..b18fa77662 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -3671,6 +3671,17 @@ impl RustGisApp { if id.starts_with("edit.") && params.get("table").is_some_and(|t| !t.is_null()) { return None; } + // Coordinate entry uses only a loaded point layer; a fallback must not record the + // incompatible selection as an explicit target that replay would refuse. + if id == "edit.addPoint" + && !self + .session + .active_layer + .and_then(|id| self.session.map().layer(id)) + .is_some_and(rustgis_engine::cmd::edit::accepts_coordinate_point) + { + return None; + } let spec = self.session.registry.get(id).filter(|c| c.mutates && params.get("layer").is_none_or(Value::is_null)).copied()?; if !spec.param_keys().is_some_and(|k| k.contains(&"layer")) { return None; @@ -8376,6 +8387,7 @@ const MAX_STEP_BYTES: usize = 4 << 20; /// an optional `layer` that defaults to the active layer goes here, so a recorded step names it; /// `record_tests::every_optional_layer_is_classified` fails until it is placed here or there. const DEFAULTS_TO_ACTIVE_LAYER: &[&str] = &[ + "edit.addPoint", "select.byAttributes", "stac.search", "select.rows", From 264801c294319367616a9424d27746d74ac1ad91 Mon Sep 17 00:00:00 2001 From: mavrick Date: Tue, 24 Nov 2026 14:01:01 -0600 Subject: [PATCH 3/4] fix(edit): roll back refused points and compact coordinate entry --- crates/engine/src/cmd/design.rs | 31 +++---- crates/engine/src/cmd/edit.rs | 85 ++++++++++++++++++-- crates/engine/src/tests/review_boundaries.rs | 29 +++++++ crates/ui-egui/src/chrome.rs | 7 +- crates/ui-egui/src/dialogs.rs | 30 +++++++ crates/ui-egui/src/ribbon.rs | 20 ++--- docs/user-guide/editing.md | 2 +- 7 files changed, 168 insertions(+), 36 deletions(-) diff --git a/crates/engine/src/cmd/design.rs b/crates/engine/src/cmd/design.rs index a5b927bd61..5b4294cbc4 100644 --- a/crates/engine/src/cmd/design.rs +++ b/crates/engine/src/cmd/design.rs @@ -194,21 +194,6 @@ pub(crate) fn apply_with>(s: &mut Session, id: u32, changes: }; zs.push((*r, z)); } - // Construction belongs to an object, not a reusable numeric id. Each removed or inserted - // feature that passes here (cut/paste, split pieces, edits) forgets its construction. Some - // row changes don't (GeoPackage and offline-area syncs, archive restore): there a feature - // keeps its construction only while its geometry still equals it (see `box_spec`). Undo - // keeps its own cache snapshot. - for change in &changes { - let feature = match (change.before(), change.row) { - (Some(before), None) => Some(before.id), - (None, Some(row)) => s.map().layer(id).and_then(|l| l.dataset.features.get(row)).map(|f| f.id), - _ => None, - }; - if let Some(feature) = feature { - crate::construction::forget_feature(s, id, feature); - } - } let l = s.map_mut().layer_mut(id).ok_or("no such layer")?; // New features: subtype defaults fill empty fields; elevation goes in `z`. if let Some(st) = l.design.subtypes.clone() @@ -376,6 +361,22 @@ pub(crate) fn apply_with>(s: &mut Session, id: u32, changes: e.added += counts.added; e.modified += counts.modified; e.deleted += counts.deleted; + // All refusals are past: construction metadata changes only for a kept edit. + // Construction belongs to an object, not a reusable numeric id. Each removed or inserted + // feature that passes here (cut/paste, split pieces, edits) forgets its construction. Some + // row changes don't (GeoPackage and offline-area syncs, archive restore): there a feature + // keeps its construction only while its geometry still equals it (see `box_spec`). Undo + // keeps its own cache snapshot. + for change in &changes { + let feature = match (change.before(), change.row) { + (Some(before), None) => Some(before.id), + (None, Some(row)) => s.map().layer(id).and_then(|l| l.dataset.features.get(row)).map(|f| f.id), + _ => None, + }; + if let Some(feature) = feature { + crate::construction::forget_feature(s, id, feature); + } + } // Said once the edit is kept: a rejected one changed nothing. for (rule, field, losses, ty) in cuts { let by = crate::notice_text::NoticeText::format("Attribute rule {rule}", [("rule", rule.into())]); diff --git a/crates/engine/src/cmd/edit.rs b/crates/engine/src/cmd/edit.rs index bf2757f823..40b912fc62 100644 --- a/crates/engine/src/cmd/edit.rs +++ b/crates/engine/src/cmd/edit.rs @@ -90,6 +90,19 @@ fn point_inputs(input: &super::InputContext<'_>, p: &Json) -> Result CmdResult { { attributes.insert(field, json!(name)); } - let mut result = add_geometry(s, id, &json!({"attributes":attributes}), Geometry::Point(at))?; + let result = add_geometry(s, id, &json!({"attributes":attributes}), Geometry::Point(at))?; if target.is_none() { // The UI explains the fallback before submission; non-UI callers need it too. s.notify("Created a Points layer because no loaded point layer was selected", false); } - result["layer"] = json!(id); - Ok(result) + Ok(json!({"layer":id,"row":result.get("row")})) }; - // Only fallback creation needs its own savepoint: it never writes an existing layer's rows. - // A plugin may handle the error and continue; it must not keep an empty fallback layer. + // Existing-layer refusals are rolled back by add_geometry without a row snapshot. + // Fallback also restores the layer it created if a plugin handles the error. if target.is_none() { s.savepoint("Create Point by Coordinates", create) } else { create(s) } } @@ -256,11 +268,24 @@ pub(crate) fn add_geometry(s: &mut Session, id: u32, p: &Json, g: Geometry) -> C let layer = l.dataset.name.clone(); let defaults = template.as_ref().map_or(&[][..], |t| &t.defaults[..]); let (attrs, losses, left_out) = new_row(&l.dataset.fields, p, defaults)?; + let row = l.dataset.features.len(); + let fields = l.dataset.fields.len(); l.dataset.push(Some(g), attrs); + if let Err(error) = super::design::apply(s, id, vec![super::design::Change { before: None, row: Some(row) }]) { + // Design only writes the new row, apart from appending an elevation column of nulls + // to older rows. Remove both on refusal without retaining another full row vector. + if let Some(l) = s.map_mut().layer_mut(id) { + l.dataset.features.truncate_rows(row); + for field in (fields..l.dataset.fields.len()).rev() { + l.dataset.features.remove_column(field); + } + l.dataset.fields.truncate(fields); + } + return Err(error); + } + let l = s.map_mut().layer_mut(id).ok_or("no layer")?; l.touch_geometry(); - let row = l.dataset.features.len() - 1; l.selection = vec![row]; - super::design::apply(s, id, vec![super::design::Change { before: None, row: Some(row) }])?; for (field, key) in losses { notify_loss(s, key, &layer, field, row); } @@ -2255,6 +2280,51 @@ mod tests { mod point_tests { use super::*; + /// A caller that handles a command error must not keep a point refused by its surface. + #[test] + fn coordinate_point_surface_refusal_does_not_append_in_a_shared_call() { + use rustgis_data::raster::{ColorHint, Crs, GeoTransform, Raster}; + let mut s = Session::new(crate::Project::default()); + s.run("edit.enable", &json!({"on":true})).unwrap(); + s.run("layer.template", &json!({"template":"points"})).unwrap(); + let id = s.active_layer.unwrap(); + s.run("edit.addPoint", &json!({"x":1,"y":1})).unwrap(); + let kept = s.map().layer(id).unwrap().dataset.clone(); + let selection = s.map().layer(id).unwrap().selection.clone(); + let counts = s.edit_counts.clone(); + let raster = Raster::new( + "south", + 1, + 1, + vec![vec![12.0]], + GeoTransform { origin_x: -1.0, origin_y: 1.0, pixel_width: 2.0, pixel_height: -2.0 }, + Crs::Epsg(3031), + None, + ColorHint::Gray, + "Float32", + ) + .unwrap(); + s.map_mut().add_raster("south", rustgis_map::RasterLayer::from_path(raster, "south.tif")); + s.map_mut().editing.settings.elevation = rustgis_map::design::Elevation::Surface("south".into()); + s.active_layer = Some(id); + let error = add_point(&mut s, &json!({"x":0,"y":90})).unwrap_err(); + assert!(error.contains("surface"), "{error}"); + assert_eq!(s.map().layer(id).unwrap().dataset, kept, "a caught refusal must not retain the appended row"); + assert_eq!(s.map().layer(id).unwrap().selection, selection); + assert_eq!(s.edit_counts, counts); + s.map_mut().editing.settings.elevation = rustgis_map::design::Elevation::Constant(5.0); + s.map_mut().layer_mut(id).unwrap().design.rules.push(rustgis_map::design::AttributeRule { + name: "Reject".into(), + kind: rustgis_map::design::RuleKind::Constraint, + field: String::new(), + expression: "1 = 0".into(), + }); + assert!(add_point(&mut s, &json!({"x":2,"y":2})).unwrap_err().contains("Reject")); + assert_eq!(s.map().layer(id).unwrap().dataset, kept, "a late refusal also removes the added z column from older rows"); + assert_eq!(s.map().layer(id).unwrap().selection, selection); + assert_eq!(s.edit_counts, counts); + } + #[test] fn coordinate_points_share_a_layer_and_undo_as_single_edits() { let mut s = Session::new(crate::Project::default()); @@ -2307,6 +2377,7 @@ mod point_tests { assert!((at.x - 7.44).abs() < 1e-8); assert!((at.y - 46.95).abs() < 1e-8); } + #[test] fn coordinate_points_respect_editing_and_declare_the_surface_for_a_new_layer() { use super::super::InputSource; diff --git a/crates/engine/src/tests/review_boundaries.rs b/crates/engine/src/tests/review_boundaries.rs index 9e0c02b3ee..c47f66948e 100644 --- a/crates/engine/src/tests/review_boundaries.rs +++ b/crates/engine/src/tests/review_boundaries.rs @@ -15,6 +15,35 @@ fn agent(access: AgentAccess) -> Scope { Scope::agent(access, true, "review-boundaries", None, Arc::new(Live)) } +/// Remembered script approval must bind the coordinate system even at its unchanged origin. +#[test] +fn permission_review_coordinate_points_bind_the_resolved_system() { + use rustgis_data::raster::Crs; + use rustgis_data::{Dataset, GeometryType}; + for system in ["map", "Reference"] { + let mut s = Session::new(crate::Project::default()); + s.run("edit.enable", &json!({"on":true})).unwrap(); + s.run("layer.template", &json!({"template":"points", "name":"Pins"})).unwrap(); + let pins = s.active_layer.unwrap(); + let reference = s.map_mut().add_dataset(Dataset::new("Reference", GeometryType::Point, vec![])); + let call = Call::script(&format!("edit.addPoint {}\nproject.connections {{}}", json!({"layer":"Pins","x":0,"y":0,"crs":system}))); + let scope = Scope::assistant(2571, Arc::new(Live)); + let Outcome::NeedsApproval(approved) = s.review(&scope, &call) else { panic!("the file-reading script needs review") }; + let remembered = approved.remember().unwrap(); + let Outcome::NeedsApproval(unchanged) = s.review(&scope, &call) else { panic!("unchanged script needs review") }; + assert!(unchanged.covered_by(&remembered)); + if system == "map" { + s.map_mut().projection = rustgis_map::globe::Projection::Custom("robinson".into()); + } else { + s.map_mut().layer_mut(reference).unwrap().dataset.crs = Some(Crs::WebMercator); + } + let Outcome::NeedsApproval(changed) = s.review(&scope, &call) else { panic!("changed script needs review") }; + assert!(!changed.covered_by(&remembered), "coordinate-system changes invalidate approval: {system}"); + assert!(s.run_remembered(scope, &remembered, &call).is_err()); + assert!(s.map().layer(pins).unwrap().dataset.features.is_empty()); + } +} + #[test] fn permission_review_authentication_changes_are_reserved() { let s = world(); diff --git a/crates/ui-egui/src/chrome.rs b/crates/ui-egui/src/chrome.rs index 684b243279..0b6140aa3a 100644 --- a/crates/ui-egui/src/chrome.rs +++ b/crates/ui-egui/src/chrome.rs @@ -830,7 +830,12 @@ pub fn shortcuts(app: &mut RustGisApp, ctx: &egui::Context) { let point_dialog_owns_escape = app.dialogs.open == Some("createPointXY") && match ctx.memory(|m| m.focused()) { Some(id) => ctx.read_response(id).is_some_and(|r| r.layer_id.id == egui::Id::unique(("dialog", "createPointXY"))), - None => app.map.sketch_len() == 0 && !app.session.map().view.first_person, + None => { + app.map.sketch_len() == 0 + && !app.session.map().view.first_person + && !crate::boxedit::drawing(app) + && !crate::circleedit::drawing(app) + } }; if point_dialog_owns_escape && ctx.input_mut(|i| i.consume_key(Modifiers::NONE, Key::Escape)) { app.dialogs.open = None; diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index 8404fd14c4..119b4e297b 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -4962,6 +4962,7 @@ mod tests { assert!(h.query_by_label("Add").is_none(), "grouped features have no individual Add"); assert!(h.query_by_label("Remove").is_none(), "grouped features are removed in the Layers pane"); } + /// Drive the full app, including the shortcuts that own Escape and the dialog's Enter. #[test] fn coordinate_point_form_repeats_and_retains_invalid_input() { @@ -5033,6 +5034,35 @@ mod tests { h.run_steps(3); assert_eq!(h.state().map.sketch_len(), 0); assert_eq!(h.state().dialogs.open, Some("createPointXY")); + let shapes = h.state_mut().session.map_mut().add_dataset(rustgis_engine::data::Dataset::new( + "Shapes", + rustgis_engine::data::GeometryType::Polygon, + vec![], + )); + h.state_mut().session.active_layer = Some(shapes); + for circle in [true, false] { + h.state_mut().run("tool.set", json!({"tool":if circle {"circle"} else {"rotatedBox"}})).unwrap(); + h.run_steps(3); + let view = h.state().map.view_rect.unwrap().0; + let start = view.right_bottom() - vec2(120.0, 120.0); + if circle { + assert!(crate::circleedit::drag_start(h.state_mut(), view, start, true)); + crate::circleedit::drag_to(h.state_mut(), view, start + vec2(40.0, 40.0)); + } else { + assert!(crate::boxedit::drag_start(h.state_mut(), view, start, true)); + crate::boxedit::drag_to(h.state_mut(), view, start + vec2(40.0, 40.0), false); + } + h.key_press(egui::Key::Escape); + h.run_steps(3); + assert!( + !crate::circleedit::drawing(h.state()) && !crate::boxedit::drawing(h.state()), + "Escape cancels the active shape gesture" + ); + assert_eq!(h.state().dialogs.open, Some("createPointXY")); + crate::circleedit::drag_stop(h.state_mut()); + crate::boxedit::drag_stop(h.state_mut()); + assert!(h.state().session.map().layer(shapes).unwrap().dataset.features.is_empty()); + } h.key_press(egui::Key::Escape); h.run_steps(4); assert_eq!(h.state().dialogs.open, None); diff --git a/crates/ui-egui/src/ribbon.rs b/crates/ui-egui/src/ribbon.rs index 2d1206ec66..004b23659f 100644 --- a/crates/ui-egui/src/ribbon.rs +++ b/crates/ui-egui/src/ribbon.rs @@ -2836,16 +2836,6 @@ fn edit_tab(app: &mut RustGisApp, ui: &mut Ui) { ); }); group(ui, "Features", |ui| { - small( - ui, - app, - "goto_xy", - "Create Point by Coordinates…", - "Create a point at typed coordinates, in the selected point layer or a new Points layer.", - "ui.dialog", - json!({"name":"createPointXY"}), - false, - ); let gt = app.session.active_layer.and_then(|id| app.session.map().layer(id)).map(|l| l.geometry_type()); let (tool, icon) = match gt { Some(GeometryType::Polyline) => (Tool::CreateLine, "line_tool"), @@ -2853,7 +2843,7 @@ fn edit_tab(app: &mut RustGisApp, ui: &mut Ui) { _ => (Tool::CreatePoint, "point_tool"), }; let checked = app.session.tool.creates(); - let r = big( + let (r, options) = big_split_menu( ui, app, icon, @@ -2862,8 +2852,14 @@ fn edit_tab(app: &mut RustGisApp, ui: &mut Ui) { "tool.set", json!({"tool": tool.code()}), checked, - false, + "Create options", + "Create a feature by drawing or by coordinates.", + true, + |ui, app| { + menu_item(ui, app, "goto_xy", "Point by Coordinates…", "ui.dialog", json!({"name":"createPointXY"})); + }, ); + crate::showme::ring(ui, app, options.rect, "ui.dialog", &json!({"name":"createPointXY"})); if r.clicked() { app.map.cancel_sketch(); } diff --git a/docs/user-guide/editing.md b/docs/user-guide/editing.md index 8b60ed8ec6..8a48e83018 100644 --- a/docs/user-guide/editing.md +++ b/docs/user-guide/editing.md @@ -2,7 +2,7 @@ ## Creating features -**Edit › Features › Create Point by Coordinates…** creates points from known X/Y coordinates. +**Edit › Features › Create ▾ › Point by Coordinates…** creates points from known X/Y coordinates. Turn editing on (also offered in the dialog), enter X and Y, optionally a name, and click **Add Point** or press ++enter++. Leave the coordinate system blank for longitude/latitude in decimal degrees or degrees, minutes and seconds, or enter a system such as `EPSG:3857` From 06accfb8c7d8217e3b90aec2e1f3bf5cf7c86aac Mon Sep 17 00:00:00 2001 From: mavrick Date: Tue, 24 Nov 2026 14:40:56 -0600 Subject: [PATCH 4/4] fix(edit): retain surface approval alongside coordinate inputs --- crates/engine/src/cmd/edit.rs | 13 +++++++++++-- docs/user-guide/editing.md | 4 +++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/cmd/edit.rs b/crates/engine/src/cmd/edit.rs index 40b912fc62..ccccb4e4b5 100644 --- a/crates/engine/src/cmd/edit.rs +++ b/crates/engine/src/cmd/edit.rs @@ -94,13 +94,13 @@ fn point_inputs(input: &super::InputContext<'_>, p: &Json) -> Result CmdResult { return Err(format!("{key} is required")); } } + // Combined positions are rejected above; the X/Y path produces no approximation notice. let (at, _) = super::navigate::typed_place(s.map(), p, false)?; let target = point_target(s, p)?; let name = match p.get("name") { @@ -2404,6 +2405,14 @@ mod point_tests { let inputs = point_inputs(&s.input_context(), &json!({"x":0,"y":0})).unwrap(); assert_eq!(inputs.layers, vec![(s.map().instance_id(), surface)]); assert!(inputs.uses_default); + for crs in ["map", "dem"] { + let combined = point_inputs(&s.input_context(), &json!({"x":0,"y":0,"crs":crs})).unwrap(); + assert_eq!( + combined.state.pointer("/feature/surface"), + Some(&json!("dem")), + "coordinate inputs retain the feature surface binding: {crs}" + ); + } s.run("edit.enable", &json!({"on":true})).unwrap(); s.run("edit.addPoint", &json!({"x":0,"y":0})).unwrap(); let id = s.active_layer.unwrap(); diff --git a/docs/user-guide/editing.md b/docs/user-guide/editing.md index 8a48e83018..c62fbaddc0 100644 --- a/docs/user-guide/editing.md +++ b/docs/user-guide/editing.md @@ -6,7 +6,9 @@ Turn editing on (also offered in the dialog), enter X and Y, optionally a name, and click **Add Point** or press ++enter++. Leave the coordinate system blank for longitude/latitude in decimal degrees or degrees, minutes and seconds, or enter a system such as `EPSG:3857` -for numeric eastings and northings. The map's display projection does not change their meaning. +for numeric eastings and northings. Enter `map` to use the map's current flat projection, +or a layer's name to use that layer's coordinate system. Otherwise, changing the map's +display projection does not change the entered coordinates' meaning. The dialog stays open and clears X, Y and Name after success; ++esc++ closes it when its fields have focus or no other work owns the key. On the map, Escape still cancels a sketch.