From a697a322ba416a9581e48d02d2f7c3892b17e6bd Mon Sep 17 00:00:00 2001 From: Ian Shiland Date: Thu, 26 Nov 2026 07:57:48 -0500 Subject: [PATCH 1/4] fix(engine): a service read by address is re-added from Recent page by page (#2553) A layer added with layer.addUrl or layer.addDownload and "service": true is read page by page, but Recent kept only its address, name and layer. Adding it again from the Data Sources pane ran ui.addUrl without the flag, so the read stopped at the server's first page. Recent now keeps "service": "true" in the source's extra for such an add, sources.list says to add it with layer.addUrl {url, service: true}, and the pane passes the flag back. Add From Service feature layers, Web Data's FEMA NFHL Features button and Open Data feature results all add this way. --- crates/engine/src/cmd/sources.rs | 3 ++- crates/engine/src/sources.rs | 17 ++++++++++++- crates/engine/src/tests.rs | 4 +++ crates/ui-egui/src/sourcespane.rs | 42 +++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/sources.rs b/crates/engine/src/cmd/sources.rs index e411d33e00..0cdfd5f515 100644 --- a/crates/engine/src/cmd/sources.rs +++ b/crates/engine/src/cmd/sources.rs @@ -41,7 +41,8 @@ fn adds_with(kind: &str) -> &'static str { fn shown(s: &Source) -> Value { let mut v = serde_json::to_value(s).unwrap_or(Value::Null); - v["addWith"] = json!(adds_with(&s.kind)); + let service = s.kind == "url" && s.extra.get("service").and_then(Value::as_str) == Some("true"); + v["addWith"] = json!(if service { "layer.addUrl {url, service: true}" } else { adds_with(&s.kind) }); v } diff --git a/crates/engine/src/sources.rs b/crates/engine/src/sources.rs index 43d0100c91..8a5f229683 100644 --- a/crates/engine/src/sources.rs +++ b/crates/engine/src/sources.rs @@ -922,7 +922,18 @@ pub fn added_by(id: &str, p: &Value) -> Option { let layer = |k: &str| text(p, k).map(|l| json!({k: l})).unwrap_or(Value::Null); match id { "layer.addData" => Some(src("file", text(p, "path")?, text(p, "name"), layer("layer"))), - "layer.addUrl" | "layer.addDownload" => Some(src("url", text(p, "url")?, text(p, "name"), layer("layer"))), + "layer.addUrl" | "layer.addDownload" => { + let mut extra = layer("layer"); + // A service's features are read page by page; adding the address again without the + // flag would read only the first page. + if p.get("service").and_then(crate::cmd::bool_value) == Some(true) { + extra = json!({"service": "true"}); + if let Some(l) = text(p, "layer") { + extra["layer"] = json!(l); + } + } + Some(src("url", text(p, "url")?, text(p, "name"), extra)) + } "map.addTiles" => { let url = text(p, "url")?; let mut extra = serde_json::Map::new(); @@ -1697,6 +1708,10 @@ MIIE added_by("service.add", &json!({"url": "https://h/wms", "layer": "a", "type": "wms"})).unwrap().extra, json!({"layer": "a", "type": "wms"}) ); + let service = json!({"url": "https://h/collections/a/items", "name": "A", "service": true}); + assert_eq!(added_by("layer.addUrl", &service).unwrap().extra, json!({"service": "true"})); + assert_eq!(clean(added_by("layer.addDownload", &service).unwrap()).unwrap().extra, json!({"service": "true"})); + assert_eq!(added_by("layer.addUrl", &json!({"url": "https://h/a.geojson", "service": false})).unwrap().extra, Value::Null); assert!(added_by("layer.remove", &json!({})).is_none()); assert!(added_by("layer.addData", &json!({})).is_none()); assert!(library().iter().all(|(_, s)| clean(s.clone()).is_ok())); diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index af5180eb7a..6264ad5eec 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -27165,6 +27165,10 @@ fn a_service_query_added_by_address_is_read_in_pages_without_the_app() { assert_eq!((sym.marker, sym.fill), (rustgis_map::symbology::Marker::Square, rustgis_map::Rgba::rgb(230, 0, 0))); let texts: Vec<_> = s.notices.iter().map(|n| n.text.as_str()).collect(); assert!(!texts.iter().any(|t| t.contains("record limit") || t.contains("aren't read")), "{texts:?}"); + // Recent keeps that it was read as a service, so adding it again reads every page too. + let recent = &s.run("sources.list", &Value::Null).unwrap()["recent"][0]; + assert_eq!((&recent["kind"], &recent["extra"]), (&json!("url"), &json!({"service": "true"}))); + assert_eq!(recent["addWith"], "layer.addUrl {url, service: true}"); // Bounds that aren't a geographic rectangle are refused before anything is fetched, as when the // app adds the download. let e = s.run("layer.addUrl", &json!({"url": url, "name": "Bad", "service": true, "bounds": [10, 0, 5, 1]})).unwrap_err(); diff --git a/crates/ui-egui/src/sourcespane.rs b/crates/ui-egui/src/sourcespane.rs index b2e2a7ba2c..220f50a5dc 100644 --- a/crates/ui-egui/src/sourcespane.rs +++ b/crates/ui-egui/src/sourcespane.rs @@ -148,6 +148,9 @@ pub fn open(app: &mut RustGisApp, s: &Source) -> Result<(), String> { if let Some(l) = text(x, "layer") { p["layer"] = json!(l); } + if text(x, "service") == Some("true") { + p["service"] = json!(true); + } app.run("ui.addUrl", p).map(|_| ()) } "tiles" => { @@ -516,3 +519,42 @@ pub fn show(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { }); }); } + +#[cfg(test)] +mod tests { + use super::*; + use rustgis_engine::render::rustgis_tiles::{ + address::{Origin, Reach}, + cache, + }; + + /// A service's features added by address are read page by page when added again from Recent, + /// as they were the first time. + #[test] + fn a_service_read_by_address_is_read_in_pages_again_from_recent() { + let first = "https://recent-pages.example/collections/parcels/items"; + let next = "https://recent-pages.example/collections/parcels/items?page=2"; + let _turn = crate::fetching::turn(); + cache::set_fetcher_with_origin(move |url, ceiling, done, _| { + let clean = cache::split_download_limit(&url).0.to_string(); + let links = if clean == first { json!([{"rel":"next","type":"application/geo+json","href":next}]) } else { json!([]) }; + let body = json!({"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[0,0]},"properties":{}}],"links":links}); + let origin = Origin::with_observed_reach(&clean, Reach::Public.min(ceiling)).unwrap(); + done(Ok(cache::Fetched { bytes: body.to_string().into_bytes(), origin })); + }); + let mut app = RustGisApp::new(rustgis_engine::Session::new(rustgis_engine::Project::default())); + let read = |app: &mut RustGisApp| { + for _ in 0..4 { + crate::serviceui::poll_pages(app, &egui::Context::default()); + } + app.session.map().layers.last().map(|l| l.dataset.features.len()) + }; + app.run("ui.addUrl", json!({"url": first, "name": "Parcels", "service": true})).unwrap(); + assert_eq!(read(&mut app), Some(2), "{:?}", app.dialogs.error); + let recent = app.session.sources.recent.first().cloned().unwrap(); + assert_eq!((recent.kind.as_str(), recent.address.as_str()), ("url", first)); + open(&mut app, &recent).unwrap(); + assert_eq!(read(&mut app), Some(2), "{:?}", app.dialogs.error); + assert_eq!(app.session.map().layers.len(), 2); + } +} From 979708c57437b0f30eb5d0dfdc8791c10f3c9b8f Mon Sep 17 00:00:00 2001 From: Ian Shiland Date: Thu, 26 Nov 2026 08:46:56 -0500 Subject: [PATCH 2/4] fix(engine): a WCS coverage is re-added from Recent in the system it was asked in (#2553) A coverage added with layer.addUrl or layer.addDownload and "coverage": true was kept in Recent as a plain address, without the flag or its coverageCrs. Adding it again from the Data Sources pane read the GetCoverage address as an ordinary download, not in the system it was asked in. Recent now keeps "coverage" and, with it, "coverageCrs" in the source's extra, as it keeps "service"; sources.list names them in addWith, and the pane passes them back to ui.addUrl, which forwards both to layer.addDownload. Source::flag reads a kept flag, so its spelling lives in one place, and the sources.save description lists the three keys. --- crates/engine/src/cmd/sources.rs | 19 +++++++++--- crates/engine/src/sources.rs | 39 ++++++++++++++++++++----- crates/engine/src/tests/services_own.rs | 4 +++ crates/ui-egui/src/sourcespane.rs | 24 +++++++++++++-- 4 files changed, 73 insertions(+), 13 deletions(-) diff --git a/crates/engine/src/cmd/sources.rs b/crates/engine/src/cmd/sources.rs index 0cdfd5f515..1becdcdfad 100644 --- a/crates/engine/src/cmd/sources.rs +++ b/crates/engine/src/cmd/sources.rs @@ -5,14 +5,14 @@ use serde_json::{Value, json}; use super::ps; -use crate::sources::{KINDS, Source, library}; +use crate::sources::{KINDS, Source, URL_FLAGS, library}; use crate::{CmdResult, CommandSpec as C, Session}; pub fn commands() -> Vec { vec![ C::new("sources.list", "List Data Sources", "Home › Add › Data Sources", list).roles(&[]).effects(crate::policy::Effects::NONE).view(), C::new("sources.save", "Save Data Source", "Home › Add › Data Sources", |s, p| keep(s, p, "saved")).roles(&[]).effects(crate::policy::Effects::NONE.with(crate::policy::Effect::Files)).view().params( - r#"{"kind": "service"|"database"|"stac"|"file"|"url"|"tiles"|"zarr"|"s3", "address": "its path, web address or connection (never with a password)", "name"?: text, "extra"?: {"type"?: service type, "layer"?: text}}"#, + r#"{"kind": "service"|"database"|"stac"|"file"|"url"|"tiles"|"zarr"|"s3", "address": "its path, web address or connection (never with a password)", "name"?: text, "extra"?: {"type"?: service type, "layer"?: text, "service"?: "true" (a url source: a web service's features, read in pages), "coverage"?: "true" (a url source: a WCS coverage's GetCoverage address), "coverageCrs"?: "EPSG:" (with coverage: the system it was asked in)}}"#, ), C::new("sources.favourite", "Favourite Data Source", "Home › Add › Data Sources", favourite).roles(&[]).effects(crate::policy::Effects::NONE.with(crate::policy::Effect::Files)) .view() @@ -39,10 +39,21 @@ fn adds_with(kind: &str) -> &'static str { } } +/// How this source is added: [`adds_with`] its kind, with the flags a `url` source's add had. +fn add_with(s: &Source) -> String { + let mut keys = vec!["url".to_string()]; + if s.kind == "url" { + keys.extend(URL_FLAGS.iter().filter(|f| s.flag(f)).map(|f| format!("{f}: true"))); + if s.extra.get("coverageCrs").is_some() { + keys.push("coverageCrs".into()); + } + } + if keys.len() == 1 { adds_with(&s.kind).to_string() } else { format!("layer.addUrl {{{}}}", keys.join(", ")) } +} + fn shown(s: &Source) -> Value { let mut v = serde_json::to_value(s).unwrap_or(Value::Null); - let service = s.kind == "url" && s.extra.get("service").and_then(Value::as_str) == Some("true"); - v["addWith"] = json!(if service { "layer.addUrl {url, service: true}" } else { adds_with(&s.kind) }); + v["addWith"] = json!(add_with(s)); v } diff --git a/crates/engine/src/sources.rs b/crates/engine/src/sources.rs index 8a5f229683..ca2dd1922e 100644 --- a/crates/engine/src/sources.rs +++ b/crates/engine/src/sources.rs @@ -506,7 +506,20 @@ fn same(a: &Source, b: &Source) -> bool { identity(&a.kind, &a.address) == identity(&b.kind, &b.address) } +/// What a `url` source's add may have had that changes how its address is read, kept in `extra` +/// for adding it again with `layer.addUrl`: a service's features are read page by page, a WCS +/// coverage in the system it was asked in (`coverageCrs`, kept with it). +pub const URL_FLAGS: [&str; 2] = ["service", "coverage"]; + +/// A flag as `extra` keeps it: its values are text. +const FLAG_ON: &str = "true"; + impl Source { + /// Whether the add this source records had `flag` (one of [`URL_FLAGS`]). + pub fn flag(&self, flag: &str) -> bool { + self.extra.get(flag).and_then(Value::as_str) == Some(FLAG_ON) + } + /// A source's identity: its kind and address. Everywhere a list is matched (kept, forgotten, /// noted as recent, shown as a favourite) it is by this; `extra` (a layer, a service type) /// is what the last one kept said. @@ -923,15 +936,21 @@ pub fn added_by(id: &str, p: &Value) -> Option { match id { "layer.addData" => Some(src("file", text(p, "path")?, text(p, "name"), layer("layer"))), "layer.addUrl" | "layer.addDownload" => { - let mut extra = layer("layer"); - // A service's features are read page by page; adding the address again without the - // flag would read only the first page. - if p.get("service").and_then(crate::cmd::bool_value) == Some(true) { - extra = json!({"service": "true"}); - if let Some(l) = text(p, "layer") { - extra["layer"] = json!(l); + let mut extra = serde_json::Map::new(); + if let Some(l) = text(p, "layer") { + extra.insert("layer".into(), json!(l)); + } + for flag in URL_FLAGS { + if p.get(flag).and_then(crate::cmd::bool_value) == Some(true) { + extra.insert(flag.into(), json!(FLAG_ON)); } } + if extra.contains_key("coverage") + && let Some(crs) = text(p, "coverageCrs") + { + extra.insert("coverageCrs".into(), json!(crs)); + } + let extra = if extra.is_empty() { Value::Null } else { Value::Object(extra) }; Some(src("url", text(p, "url")?, text(p, "name"), extra)) } "map.addTiles" => { @@ -1712,6 +1731,12 @@ MIIE assert_eq!(added_by("layer.addUrl", &service).unwrap().extra, json!({"service": "true"})); assert_eq!(clean(added_by("layer.addDownload", &service).unwrap()).unwrap().extra, json!({"service": "true"})); assert_eq!(added_by("layer.addUrl", &json!({"url": "https://h/a.geojson", "service": false})).unwrap().extra, Value::Null); + let coverage = json!({"url": "https://h/wcs?REQUEST=GetCoverage", "coverage": true, "coverageCrs": "EPSG:2056"}); + let kept = clean(added_by("layer.addDownload", &coverage).unwrap()).unwrap(); + assert_eq!(kept.extra, json!({"coverage": "true", "coverageCrs": "EPSG:2056"})); + assert!(kept.flag("coverage") && !kept.flag("service")); + // A system without the coverage flag isn't one the address is read in. + assert_eq!(added_by("layer.addUrl", &json!({"url": "https://h/a.tif", "coverageCrs": "EPSG:2056"})).unwrap().extra, Value::Null); assert!(added_by("layer.remove", &json!({})).is_none()); assert!(added_by("layer.addData", &json!({})).is_none()); assert!(library().iter().all(|(_, s)| clean(s.clone()).is_ok())); diff --git a/crates/engine/src/tests/services_own.rs b/crates/engine/src/tests/services_own.rs index 79183ce12e..c370060e2b 100644 --- a/crates/engine/src/tests/services_own.rs +++ b/crates/engine/src/tests/services_own.rs @@ -311,4 +311,8 @@ fn a_coverage_answer_without_its_system_is_read_in_the_one_asked_for() { assert_eq!(crs_of(&s, &added["layer"]), lv95); let added = s.run("layer.addUrl", &json!({"url": unsaid, "name": "Given", "coverage": true, "coverageCrs": "EPSG:2056"})).unwrap(); assert_eq!(crs_of(&s, &added["layer"]), lv95); + // Recent keeps both, so adding it again reads it in the same system. + let recent = &s.run("sources.list", &serde_json::Value::Null).unwrap()["recent"][0]; + assert_eq!((&recent["address"], &recent["extra"]), (&json!(unsaid), &json!({"coverage": "true", "coverageCrs": "EPSG:2056"}))); + assert_eq!(recent["addWith"], "layer.addUrl {url, coverage: true, coverageCrs}"); } diff --git a/crates/ui-egui/src/sourcespane.rs b/crates/ui-egui/src/sourcespane.rs index 220f50a5dc..dfd463c5fd 100644 --- a/crates/ui-egui/src/sourcespane.rs +++ b/crates/ui-egui/src/sourcespane.rs @@ -148,8 +148,13 @@ pub fn open(app: &mut RustGisApp, s: &Source) -> Result<(), String> { if let Some(l) = text(x, "layer") { p["layer"] = json!(l); } - if text(x, "service") == Some("true") { - p["service"] = json!(true); + for flag in rustgis_engine::sources::URL_FLAGS { + if s.flag(flag) { + p[flag] = json!(true); + } + } + if let Some(crs) = text(x, "coverageCrs") { + p["coverageCrs"] = json!(crs); } app.run("ui.addUrl", p).map(|_| ()) } @@ -557,4 +562,19 @@ mod tests { assert_eq!(read(&mut app), Some(2), "{:?}", app.dialogs.error); assert_eq!(app.session.map().layers.len(), 2); } + + /// A WCS coverage added by address is asked for again from Recent as a coverage, in the system + /// it was asked in the first time. + #[test] + fn a_coverage_is_added_again_from_recent_in_the_system_it_was_asked_in() { + let _turn = crate::fetching::turn(); + cache::set_fetcher(|_, _| {}); + let mut app = RustGisApp::new(rustgis_engine::Session::new(rustgis_engine::Project::default())); + let url = "https://wcs-recent.invalid/wcs?SERVICE=WCS&VERSION=2.0.1&REQUEST=GetCoverage&COVERAGEID=dem"; + let added = json!({"id": 1, "url": url, "name": "Terrain", "coverage": true, "coverageCrs": "EPSG:2056"}); + let recent = rustgis_engine::sources::clean(rustgis_engine::sources::added_by("layer.addDownload", &added).unwrap()).unwrap(); + open(&mut app, &recent).unwrap(); + let asked = app.ui.downloads.last().map(|d| (d.params["coverage"].clone(), d.params["coverageCrs"].clone())); + assert_eq!(asked, Some((json!(true), json!("EPSG:2056")))); + } } From aaad31c18c65e6e884828d54359e91d98c75072a Mon Sep 17 00:00:00 2001 From: Ian Shiland Date: Thu, 26 Nov 2026 09:22:52 -0500 Subject: [PATCH 3/4] fix(engine): addWith names coverageCrs only for a coverage source (#2553) A url source saved with sources.save and only "coverageCrs" in its extra got the hint layer.addUrl {url, coverageCrs}, though layer.addUrl reads a coverageCrs only with "coverage": true. The hint now names it only beside the coverage flag, as added_by keeps it. --- crates/engine/src/cmd/sources.rs | 2 +- crates/engine/src/tests/services_own.rs | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/cmd/sources.rs b/crates/engine/src/cmd/sources.rs index 1becdcdfad..b4475dac7a 100644 --- a/crates/engine/src/cmd/sources.rs +++ b/crates/engine/src/cmd/sources.rs @@ -44,7 +44,7 @@ fn add_with(s: &Source) -> String { let mut keys = vec!["url".to_string()]; if s.kind == "url" { keys.extend(URL_FLAGS.iter().filter(|f| s.flag(f)).map(|f| format!("{f}: true"))); - if s.extra.get("coverageCrs").is_some() { + if s.flag("coverage") && s.extra.get("coverageCrs").is_some() { keys.push("coverageCrs".into()); } } diff --git a/crates/engine/src/tests/services_own.rs b/crates/engine/src/tests/services_own.rs index c370060e2b..0912bf7c2e 100644 --- a/crates/engine/src/tests/services_own.rs +++ b/crates/engine/src/tests/services_own.rs @@ -315,4 +315,7 @@ fn a_coverage_answer_without_its_system_is_read_in_the_one_asked_for() { let recent = &s.run("sources.list", &serde_json::Value::Null).unwrap()["recent"][0]; assert_eq!((&recent["address"], &recent["extra"]), (&json!(unsaid), &json!({"coverage": "true", "coverageCrs": "EPSG:2056"}))); assert_eq!(recent["addWith"], "layer.addUrl {url, coverage: true, coverageCrs}"); + // coverageCrs alone doesn't make a source a coverage. + let saved = s.run("sources.save", &json!({"kind": "url", "address": unsaid, "extra": {"coverageCrs": "EPSG:2056"}})).unwrap(); + assert_eq!(saved["addWith"], "layer.addUrl {url}"); } From da4b5c80bd57cbc9c51b85b9f738c55ee9d9fbd3 Mon Sep 17 00:00:00 2001 From: Ian Shiland Date: Thu, 26 Nov 2026 09:47:41 -0500 Subject: [PATCH 4/4] fix(ui): pass coverageCrs from Recent only with the coverage flag (#2553) sourcespane::open passed a source's coverageCrs to ui.addUrl even without "coverage", unlike added_by and add_with. It now passes it only beside the flag. No behaviour changes: add_url ignores coverageCrs without coverage, so there is no new test. --- crates/ui-egui/src/sourcespane.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/sourcespane.rs b/crates/ui-egui/src/sourcespane.rs index dfd463c5fd..dda123c7ac 100644 --- a/crates/ui-egui/src/sourcespane.rs +++ b/crates/ui-egui/src/sourcespane.rs @@ -153,7 +153,9 @@ pub fn open(app: &mut RustGisApp, s: &Source) -> Result<(), String> { p[flag] = json!(true); } } - if let Some(crs) = text(x, "coverageCrs") { + if s.flag("coverage") + && let Some(crs) = text(x, "coverageCrs") + { p["coverageCrs"] = json!(crs); } app.run("ui.addUrl", p).map(|_| ())