From 19659b5ae1e8326f4b02065aec6833d2f2c985f7 Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Fri, 6 Nov 2026 11:00:37 -0300 Subject: [PATCH 01/13] feat(plugins): a plugin command's `layer.addUrl` with "bbox" goes to the app (#1330, part 2) A plugin's command run by the app was refused a window, since it can't wait. Now it is left to the app like any download: the read runs off the frame, the layer lands, and the command runs again with what adding it answered (#1202). A box that can't be read is still refused while the command runs. The landed window completes its request's claim with "window" (what it read), which the claim takes only when it repeats the request's own box, cell size and "cog". Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/layer.rs | 11 +++--- crates/engine/src/policy/downloads.rs | 34 +++++++++++++++++- crates/engine/src/tests.rs | 14 ++++++-- crates/ui-egui/src/pluginpanel.rs | 51 +++++++++++++++++++++++++++ docs/plugins.md | 3 +- docs/user-guide/data-formats.md | 11 +++--- 6 files changed, 109 insertions(+), 15 deletions(-) diff --git a/crates/engine/src/cmd/layer.rs b/crates/engine/src/cmd/layer.rs index f6bc99da35..156fb7d974 100644 --- a/crates/engine/src/cmd/layer.rs +++ b/crates/engine/src/cmd/layer.rs @@ -3246,13 +3246,14 @@ fn add_url_as_given(s: &mut Session, p: &Value) -> CmdResult { } if window { window_checks(p, url, scan)?; - // A plugin's command run by the app leaves what would wait to the app, off the frame; a - // window waits for its header and tiles, which the app doesn't take over yet. + // A plugin's command run by the app leaves what would wait to the app, off the frame + // ([`read_cog_window`]); a box that can't be read is refused now, while the command runs. #[cfg(not(target_arch = "wasm32"))] if s.leave_downloads { - return Err(format!( - "{url}: a window (\"bbox\") waits for its tiles, which a plugin's command can't do in the app yet: run layer.addUrl from the command line or a script, or leave out \"bbox\" to draw the file in place" - )); + window_settled(s, p, url)?; + let mut asked = p.clone(); + asked["url"] = json!(url); + return s.request_url(&asked); } return add_cog_window(s, p, url); } diff --git a/crates/engine/src/policy/downloads.rs b/crates/engine/src/policy/downloads.rs index f4d6fe0145..ba8a48b95d 100644 --- a/crates/engine/src/policy/downloads.rs +++ b/crates/engine/src/policy/downloads.rs @@ -10,6 +10,15 @@ use std::{ }, }; +/// What a window the app read off the frame says it read (`"window"`, #1330) is what its request +/// asked for: a box, and its cell size and `"cog"` if the request gave them, nothing else. +fn asked_window(asked: &Value, window: &Value) -> bool { + const KEYS: [&str; 3] = ["bbox", "cellSize", "cog"]; + let given = |k: &str| asked.get(k).filter(|v| !v.is_null()); + given("bbox").is_some() + && window.as_object().is_some_and(|w| w.keys().all(|k| KEYS.contains(&k.as_str())) && KEYS.iter().all(|k| given(k) == w.get(*k))) +} + pub(super) struct Claim { pub c: Continuation, pub params: Value, @@ -436,7 +445,8 @@ impl Session { let refinement = (key == "id" && value.as_u64() == Some(id)) || (key == "cog" && in_place && value.as_bool() == Some(true)) || (key == "whole" && value.as_bool() == Some(true)) - || (key == "zoom" && value.as_bool() == Some(false) && claim.params.get(key).and_then(Value::as_bool) == Some(true)); + || (key == "zoom" && value.as_bool() == Some(false) && claim.params.get(key).and_then(Value::as_bool) == Some(true)) + || (key == "window" && asked_window(&claim.params, value)); if !refinement && claim.params.get(key) != Some(value) { return Err("the download's address or parameters changed since it was requested".into()); } @@ -490,3 +500,25 @@ impl Session { self.policy.work.claims.remove(&id); } } + +#[cfg(test)] +mod tests { + use super::asked_window; + use serde_json::json; + + /// A window the app read completes its request only as what was asked (#1330): the same box, + /// cell size and `"cog"`, and nothing more; a request with no box takes no window. + #[test] + fn a_landed_window_completes_only_what_was_asked() { + let asked = json!({"url": "https://x.org/a.tif", "bbox": [10.25, 45.5, 10.5, 45.75], "cellSize": 30, "name": "W"}); + assert!(asked_window(&asked, &json!({"bbox": [10.25, 45.5, 10.5, 45.75], "cellSize": 30}))); + assert!(!asked_window(&asked, &json!({"bbox": [0, 0, 1, 1], "cellSize": 30})), "another box"); + assert!(!asked_window(&asked, &json!({"bbox": [10.25, 45.5, 10.5, 45.75]})), "its cell size left out"); + assert!(!asked_window(&asked, &json!({"bbox": [10.25, 45.5, 10.5, 45.75], "cellSize": 30, "cog": true})), "cog not asked"); + assert!(!asked_window(&asked, &json!({"bbox": [10.25, 45.5, 10.5, 45.75], "cellSize": 30, "url": "https://y.org"})), "another key"); + assert!(!asked_window(&asked, &json!("view")), "not an object"); + let view = json!({"url": "https://x.org/a.tif", "bbox": "view", "cellSize": null}); + assert!(asked_window(&view, &json!({"bbox": "view"})), "a null cell size is none given"); + assert!(!asked_window(&json!({"url": "https://x.org/a.tif"}), &json!({})), "no box asked"); + } +} diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index c0872918db..473533eb6b 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -30100,11 +30100,19 @@ fn a_cog_window_comes_in_as_a_raster() { assert!(e.contains("names a .geojson file"), "{e}"); let e = s.run("layer.addUrl", &json!({"url": wrapped("https://data.example.com"), "bbox": [10.25, 45.5, 10.5, 45.75]})).unwrap_err(); assert!(!e.contains("names a .com file"), "{e}"); - // A plugin's command run by the app doesn't wait for a window: refused, and said. + // A plugin's command run by the app leaves a window to the app (#1330): asked for with its + // box and nothing fetched; a box that can't be read is refused as the command runs. + let before = sent.load(std::sync::atomic::Ordering::Relaxed); + let asked = json!({"url": format!("{base}/scene.tif"), "bbox": [10.25, 45.5, 10.5, 45.75], "name": "Left"}); s.leave_downloads = true; - let e = s.run("layer.addUrl", &json!({"url": format!("{base}/scene.tif"), "bbox": [10.25, 45.5, 10.5, 45.75]})).unwrap_err(); + assert_eq!(s.run("layer.addUrl", &asked).unwrap()["pending"], true); + let e = s.run("layer.addUrl", &json!({"url": format!("{base}/scene.tif"), "bbox": "here"})).unwrap_err(); s.leave_downloads = false; - assert!(e.contains("a plugin's command can't do in the app yet"), "{e}"); + assert!(e.contains("bbox is"), "{e}"); + assert_eq!(sent.load(std::sync::atomic::Ordering::Relaxed), before, "nothing fetched"); + let taken = s.take_url_requests(); + assert_eq!(taken.len(), 1); + assert_eq!(taken[0].params()["bbox"], asked["bbox"]); // Byte windows round nothing, and say nothing of it; an Int32 window of 16,777,216 plus the // byte value says how many `f32` rounded: the odd ones, half of its 65,536 cells. assert!(s.notices_since(mark0).iter().all(|n| !n.text.contains("rounded")), "{:?}", s.notices_since(mark0)); diff --git a/crates/ui-egui/src/pluginpanel.rs b/crates/ui-egui/src/pluginpanel.rs index 1b7030e624..c1d6343145 100644 --- a/crates/ui-egui/src/pluginpanel.rs +++ b/crates/ui-egui/src/pluginpanel.rs @@ -695,6 +695,57 @@ mod tests { plugins::unload("ui-scan"); } + /// A plugin's command asking for a window of a cloud-optimised GeoTIFF doesn't wait for it: + /// the app reads it off the frame, adds it when it lands, and runs the command again, whose + /// `layer.addUrl` answers what was added (#1330). + #[test] + fn a_plugin_reads_a_window_off_the_frame() { + let _turn = crate::fetching::turn(); + use rustgis_engine::plugins; + use std::sync::atomic::Ordering; + let slow = crate::fetching::slow_ranges(rustgis_engine::data::raster::cog::example(1024, 256)); + let pkg = plugins::Package::from_zip(&plugins::testing::package("ui-window", &["edit", "network"])).unwrap(); + plugins::load(pkg, "test").unwrap(); + let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(1400.0, 860.0)).with_step_dt(0.05).build_ui_state( + |ui, app: &mut RustGisApp| { + let ctx = ui.ctx().clone(); + app.logic(&ctx); + app.ui(ui); + }, + RustGisApp::with_sample(), + ); + let url = format!("{}/scene.tif", slow.origin); + // The header in hand, so only the window's tiles wait. + rustgis_engine::render::rustgis_tiles::cog::info_blocking(&url).unwrap(); + slow.open.store(false, Ordering::Relaxed); + let params = json!({"url": url, "bbox": [10.25, 45.5, 10.5, 45.75], "name": "Window"}); + let r = h.state_mut().run("plugin:ui-window/f", json!({"op": "layer.addUrl", "params": params})).unwrap(); + assert_eq!(r["pending"], true); + let deadline = std::time::Instant::now() + std::time::Duration::from_secs(10); + while slow.held.load(Ordering::Relaxed) == 0 { + assert!(std::time::Instant::now() < deadline, "no request held"); + let frame = std::time::Instant::now(); + h.step(); + assert!(frame.elapsed() < std::time::Duration::from_secs(5), "the read held the frame"); + std::thread::sleep(std::time::Duration::from_millis(20)); + } + assert!(h.state().session.map().layer_by_name("Window").is_none(), "nothing waited"); + assert!(h.state().session.plugin_retries_waiting()); + slow.open.store(true, Ordering::Relaxed); + let deadline = std::time::Instant::now() + std::time::Duration::from_secs(30); + let landed = |app: &RustGisApp| app.session.map().layer_by_name("Window").is_some() && !app.session.plugin_retries_waiting(); + while !landed(h.state()) { + assert!(std::time::Instant::now() < deadline, "timed out waiting: {:?}", h.state().session.notices); + h.step(); + std::thread::sleep(std::time::Duration::from_millis(20)); + } + let app = h.state(); + assert!(app.session.map().layer_by_name("Window").is_some_and(|l| l.is_raster())); + assert!(app.session.map().layer_by_name("Window (2)").is_none(), "added once"); + assert!(app.session.notices.iter().all(|n| !n.error), "{:?}", app.session.notices); + plugins::unload("ui-window"); + } + /// A download that lands after its plugin command stopped waiting for it isn't added, and /// that is said once, with its address, whether or not that holds a key (#1202). #[test] diff --git a/docs/plugins.md b/docs/plugins.md index 53b5446f15..5f43ae7871 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -449,7 +449,8 @@ download a file whole it answers `{"pending": true, "url": …}`: RustGIS downlo frame, saying so in the status bar, and adds the layer when it lands (its own undo step), as **Home › Add › Add Data › From URL** does. On the desktop that goes for reading a GeoTIFF's, FlatGeobuf's or GeoParquet's header too; in the web app a PMTiles archive, a cloud-optimised -GeoTIFF or a FlatGeobuf or GeoParquet whose header was fetched already is added at once. Up to 16 +GeoTIFF or a FlatGeobuf or GeoParquet whose header was fetched already is added at once. A window +of a cloud-optimised GeoTIFF (`"bbox"`, on the desktop) is read and added the same way. Up to 16 downloads wait at a time: a request past 16 fails, and if the command then fails too, none of its downloads start. Run by `rustgis-cli`, a script or a task, the command waits and answers what was added. diff --git a/docs/user-guide/data-formats.md b/docs/user-guide/data-formats.md index 7292aa1502..b2f5a4f264 100644 --- a/docs/user-guide/data-formats.md +++ b/docs/user-guide/data-formats.md @@ -191,11 +191,12 @@ tile), without a STAC catalogue: while it is read and kept. - The Add Data From URL dialog has no box to fill in, so a window is asked for by a command. On the command line and in a script, `layer.addUrl` waits for it and answers what was added. In the - desktop app, `ui.addUrl` with `"bbox"` reads it off the frame: the map stays in use, and the - layer is added when the read lands. These are read one at a time, with 16 under way at most, - and the next starts once the app has taken the last. If another project is opened meanwhile, one - still waiting isn't read, and one being read can't be cancelled yet: it runs to its end and - isn't added. Each is said in a notice. + desktop app, `ui.addUrl` with `"bbox"`, and a plugin's command calling `layer.addUrl` with it, + read it off the frame: the map stays in use, and the layer is added when the read lands (the + plugin's command then runs again with what adding it answered). These are read one at a time, + with 16 under way at most, and the next starts once the app has taken the last. If another + project is opened meanwhile, one still waiting isn't read, and one being read can't be cancelled + yet: it runs to its end and isn't added. Each is said in a notice. - The file's no-data, colour table (a palette file draws in its colours) and band names come with it, and class names given as `CLASS_` items in GDAL's metadata tag, as the MapBiomas files on Source Cooperative give theirs. These come from the file's own tags: an `.aux.xml` From 2715012ecc7bbfeb14715a695ad36389064f83de Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Sun, 8 Nov 2026 06:43:30 -0300 Subject: [PATCH 02/13] test(plugins): a plugin command runs again and answers the window added (#1330) Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/tests.rs | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 473533eb6b..a687fc4e60 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -29833,6 +29833,45 @@ fn a_windows_bands_are_started_within_its_wait() { assert_eq!(e, "2 of 4 bands read in 5 minutes, so the window is given up: take a smaller box or a larger cellSize"); } +/// A plugin's command asking for a window runs again once the app has read it and added it, and +/// its `layer.addUrl` then answers the raster added (#1330): the window it lands with is the one +/// the command asked for, so its claim takes it. +#[cfg(not(target_arch = "wasm32"))] +#[test] +fn a_plugin_command_runs_again_when_its_window_is_added() { + use crate::cmd::layer::{read_cog_window, window_asked}; + use rustgis_data::raster::cog::example; + let (base, _) = serve_ranges(example(1024, 256)); + let mut s = world(); + plugin("eng-window", &["edit", "network"]); + let layers = s.map().layers.len(); + let url = format!("{base}/scene.tif"); + let bbox = json!([10.25, 45.5, 10.5, 45.75]); + let p = json!({"op": "layer.addUrl", "params": {"url": url, "bbox": bbox, "name": "Window"}}); + s.run_leaving_downloads("plugin:eng-window/f", &p).unwrap(); + let asked = s.take_url_requests(); + assert_eq!(asked.len(), 1); + assert_eq!(s.map().layers.len(), layers, "nothing added while it is read"); + // The app reads it apart from the session and adds it with the request's number, and with + // what a task needs to read it again, as `start_window_read` does. + let id = s.download_started_for(&asked[0]).unwrap(); + let read = read_cog_window(&window_asked(&s, asked[0].params()).unwrap()).unwrap(); + assert!(s.download_landed_window(id, read)); + let mut add = asked[0].params().clone(); + add["id"] = json!(id); + add["window"] = json!({"bbox": bbox}); + s.complete_download(id, &add).unwrap(); + assert_eq!(s.map().layers.len(), layers + 1); + let added = s.map().layer_by_name("Window").filter(|l| l.is_raster()).unwrap().id; + let ran = s.poll_plugin_retries(); + assert_eq!(ran.len(), 1, "{ran:?}"); + let (cmd, answer) = &ran[0]; + assert_eq!(cmd, "plugin:eng-window/f"); + assert_eq!(answer.as_ref().unwrap()["layer"], json!(added), "{answer:?}"); + assert_eq!(s.map().layers.len(), layers + 1, "added once"); + assert!(s.take_url_requests().is_empty() && !s.plugin_retries_waiting()); +} + /// A window's read needs no session: on a thread, as the app reads it, then added when it lands /// (#1330). What can't be a window is refused before the read starts, and an error names the /// address without its keys. From dd95812da12d8e9faf4cb1dad7f46040489868fa Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Mon, 9 Nov 2026 00:28:36 -0300 Subject: [PATCH 03/13] fix(plugins): a window asked for the view keeps the view it was asked in (#1330) A plugin command run again after a download sees the view it first ran with only while it runs; the app reads the window it then asks for on a later frame, when the map shows the user's view again. The request now carries the box "view" was when it was asked for, and the app reads that box. A caller can't give it: the key is dropped from what a command asks. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/layer.rs | 39 ++++++++++++++++++++++++++++++++-- crates/engine/src/tests.rs | 27 +++++++++++++++++++++++ 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/layer.rs b/crates/engine/src/cmd/layer.rs index f6988a1f3c..38857b804a 100644 --- a/crates/engine/src/cmd/layer.rs +++ b/crates/engine/src/cmd/layer.rs @@ -3261,14 +3261,25 @@ fn add_url_as_given(s: &mut Session, p: &Value) -> CmdResult { return Err(format!("{url}: \"cellSize\" goes with \"bbox\": give a box, or leave it out")); } if window { + // The view a request was asked in is the session's to keep, not a caller's to give. + let mut own = p.clone(); + if let Some(o) = own.as_object_mut() { + o.remove(VIEW_ASKED); + } + let p = &own; window_checks(p, url, scan)?; // A plugin's command run by the app leaves what would wait to the app, off the frame // ([`read_cog_window`]); a box that can't be read is refused now, while the command runs. #[cfg(not(target_arch = "wasm32"))] if s.leave_downloads { - window_settled(s, p, url)?; + let settled = window_settled(s, p, url)?; let mut asked = p.clone(); asked["url"] = json!(url); + // `"view"` is the view now: the app reads the window on a later frame, and a command + // run again after a download sees the view it first ran with only while it runs. + if is_view(p.get("bbox")) { + asked[VIEW_ASKED] = json!(settled.bbox); + } return s.request_url(&asked); } return add_cog_window(s, p, url); @@ -3998,6 +4009,13 @@ pub struct WindowAsked { name: Option, } +#[cfg(all(test, not(target_arch = "wasm32")))] +impl WindowAsked { + pub(crate) fn bbox(&self) -> [f64; 4] { + self.bbox + } +} + /// A window read by [`read_cog_window`], waiting to be added to the project: its raster made and /// its GeoTIFF written, so that adding it holds no frame for long. #[cfg(not(target_arch = "wasm32"))] @@ -4375,8 +4393,17 @@ pub(crate) fn box_in_file_longitudes(x0: f64, x1: f64, fx0: f64, fx1: f64) -> Re #[cfg(not(target_arch = "wasm32"))] fn window_box(s: &Session, p: &Value) -> Result<[f64; 4], String> { const NEED: &str = "bbox is [west, south, east, north] in degrees, or \"view\""; + let seen = p.get(VIEW_ASKED).and_then(Value::as_array).filter(|_| is_view(p.get("bbox"))); let [w, so, e, n] = match p.get("bbox") { - Some(Value::String(v)) if v.trim().eq_ignore_ascii_case("view") => { + // The view a request was made in (`add`, above), checked as a box given. + Some(_) if seen.is_some() => { + let v: Option> = seen.into_iter().flatten().map(|x| x.as_f64().filter(|x| x.is_finite())).collect(); + match v.as_deref() { + Some([w, so, e, n]) => [*w, *so, *e, *n], + _ => return Err(NEED.into()), + } + } + Some(v) if is_view(Some(v)) => { let e = super::workspace::view_extent(s); if e.is_empty() { return Err("the map's extent isn't known; give bbox".into()); @@ -4401,6 +4428,14 @@ fn window_box(s: &Session, p: &Value) -> Result<[f64; 4], String> { if w < e && so < n && lon(w) && lon(e) && lat(so) && lat(n) { Ok([w, so, e, n]) } else { Err(NEED.into()) } } +/// Where a window request left to the app keeps the box `"bbox": "view"` was when it was asked for. +const VIEW_ASKED: &str = "viewAsked"; + +/// `"bbox": "view"`, in any case or spacing. +fn is_view(bbox: Option<&Value>) -> bool { + bbox.and_then(Value::as_str).is_some_and(|v| v.trim().eq_ignore_ascii_case("view")) +} + /// A GeoTIFF's name from its address: the file name without its extension, or for a dated /// address (`…/landsat/{date:YYYY}.tif`) what is left of it once the dates are taken out, else its /// folder's name. diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index b9678b1e60..93051fdc22 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -30526,6 +30526,33 @@ fn a_windows_bands_are_started_within_its_wait() { assert_eq!(e, "2 of 4 bands read in 5 minutes, so the window is given up: take a smaller box or a larger cellSize"); } +/// A plugin's command asking for the view's window is read for the view it was asked in, though the +/// app reads it on a later frame, when the map may show another (#1330): a command run again after +/// a download sees the view it first ran with only while it runs. +#[cfg(not(target_arch = "wasm32"))] +#[test] +fn a_window_asked_for_the_view_keeps_the_view_it_was_asked_in() { + use crate::cmd::layer::window_asked; + let mut s = world(); + plugin("eng-window-view", &["edit", "network"]); + s.run("map.zoomToExtent", &json!({"extent": [10.0, 45.0, 11.0, 46.0]})).unwrap(); + let seen = crate::cmd::workspace::view_extent(&s); + let p = json!({"op": "layer.addUrl", "params": {"url": "https://x.org/scene.tif", "bbox": "view", "viewAsked": [0, 0, 1, 1]}}); + s.run_leaving_downloads("plugin:eng-window-view/f", &p).unwrap(); + let asked = s.take_url_requests(); + assert_eq!(asked.len(), 1); + s.run("map.zoomToExtent", &json!({"extent": [-50.0, -20.0, -40.0, -10.0]})).unwrap(); + let read = window_asked(&s, asked[0].params()).unwrap().bbox(); + let want = [seen.min_x, seen.min_y, seen.max_x, seen.max_y]; + assert!(read.iter().zip(want).all(|(a, b)| (a - b).abs() < 1e-9), "{read:?} {want:?}"); + // What the request says to read is the box it was asked in, not one a caller gave. + assert_eq!(asked[0].params()["bbox"], "view"); + // A box asked for now is the view now. + let now = crate::cmd::workspace::view_extent(&s); + let read = window_asked(&s, &json!({"url": "https://x.org/scene.tif", "bbox": "view"})).unwrap().bbox(); + assert!((read[0] - now.min_x).abs() < 1e-9 && (read[3] - now.max_y).abs() < 1e-9, "{read:?}"); +} + /// A plugin's command asking for a window runs again once the app has read it and added it, and /// its `layer.addUrl` then answers the raster added (#1330): the window it lands with is the one /// the command asked for, so its claim takes it. From c01bb07c4664fcdf8ea0abae93e5fd08b7b73210 Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Mon, 9 Nov 2026 01:10:47 -0300 Subject: [PATCH 04/13] fix(plugins): keep the view's box beside a window request, not in it (#1330) The box "bbox": "view" was when a command asked is kept on the queued request (UrlRequest::view_asked) instead of in its parameters, so a command run again is matched by what it asked and is answered the raster added, and no caller can give the box. is_view is native-only, as its callers are (the wasm build has -D warnings). The view test now completes the window and checks the command run again gets the raster. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/layer.rs | 51 ++++++++++++--------------- crates/engine/src/lib.rs | 10 ++++++ crates/engine/src/policy/downloads.rs | 5 +-- crates/engine/src/tests.rs | 40 ++++++++++++++------- crates/ui-egui/src/lib.rs | 13 +++++-- 5 files changed, 73 insertions(+), 46 deletions(-) diff --git a/crates/engine/src/cmd/layer.rs b/crates/engine/src/cmd/layer.rs index 38857b804a..bd541e5b71 100644 --- a/crates/engine/src/cmd/layer.rs +++ b/crates/engine/src/cmd/layer.rs @@ -3261,26 +3261,21 @@ fn add_url_as_given(s: &mut Session, p: &Value) -> CmdResult { return Err(format!("{url}: \"cellSize\" goes with \"bbox\": give a box, or leave it out")); } if window { - // The view a request was asked in is the session's to keep, not a caller's to give. - let mut own = p.clone(); - if let Some(o) = own.as_object_mut() { - o.remove(VIEW_ASKED); - } - let p = &own; window_checks(p, url, scan)?; // A plugin's command run by the app leaves what would wait to the app, off the frame // ([`read_cog_window`]); a box that can't be read is refused now, while the command runs. #[cfg(not(target_arch = "wasm32"))] if s.leave_downloads { - let settled = window_settled(s, p, url)?; + let settled = window_settled(s, p, url, None)?; let mut asked = p.clone(); asked["url"] = json!(url); // `"view"` is the view now: the app reads the window on a later frame, and a command - // run again after a download sees the view it first ran with only while it runs. - if is_view(p.get("bbox")) { - asked[VIEW_ASKED] = json!(settled.bbox); - } - return s.request_url(&asked); + // run again after a download sees the view it first ran with only while it runs. The + // request keeps the box beside what was asked, by which a run again is answered. + s.window_view = is_view(p.get("bbox")).then_some(settled.bbox); + let queued = s.request_url(&asked); + s.window_view = None; + return queued; } return add_cog_window(s, p, url); } @@ -4032,9 +4027,9 @@ pub struct CogWindow { /// `p`'s box and cell size, read on the frame, which holds the view. #[cfg(not(target_arch = "wasm32"))] -fn window_settled(s: &Session, p: &Value, url: &str) -> Result { +fn window_settled(s: &Session, p: &Value, url: &str, seen: Option<[f64; 4]>) -> Result { let named = |e: String| if e.starts_with(url) { e } else { format!("{url}: {e}") }; - let bbox = window_box(s, p).map_err(named)?; + let bbox = window_box(s, p, seen).map_err(named)?; let cell = match p.get("cellSize").filter(|v| !v.is_null()) { None => None, Some(v) => Some(v.as_f64().filter(|c| c.is_finite() && *c > 0.0).ok_or_else(|| named("cellSize is a size above 0".into()))?), @@ -4047,18 +4042,25 @@ fn window_settled(s: &Session, p: &Value, url: &str) -> Result Result { + window_asked_in(s, p, None) +} + +/// [`window_asked`], `"bbox": "view"` being `seen` when given: the box the view was when a request +/// was queued ([`crate::UrlRequest::view_asked`]). +#[cfg(not(target_arch = "wasm32"))] +pub fn window_asked_in(s: &Session, p: &Value, seen: Option<[f64; 4]>) -> Result { let url = ps(p, "url").map(str::trim).filter(|u| !u.is_empty()).ok_or("url is required")?; let checked = web_address(url) .and_then(|_| super::raster::as_scan(p)) .and_then(|scan| window_checks(p, url, scan)) - .and_then(|()| window_settled(s, p, url)); + .and_then(|()| window_settled(s, p, url, seen)); checked.map_err(|e| crate::sources::redact_text(&e)) } /// `layer.addUrl` with `"bbox"`, for those that wait: read here and added. #[cfg(not(target_arch = "wasm32"))] fn add_cog_window(s: &mut Session, p: &Value, url: &str) -> CmdResult { - let read = read_cog_window(&window_settled(s, p, url)?)?; + let read = read_cog_window(&window_settled(s, p, url, None)?)?; add_window(s, p, read) } @@ -4391,18 +4393,11 @@ pub(crate) fn box_in_file_longitudes(x0: f64, x1: f64, fx0: f64, fx1: f64) -> Re /// A window's box: `[west, south, east, north]` in degrees, or `"view"`, the map's extent. #[cfg(not(target_arch = "wasm32"))] -fn window_box(s: &Session, p: &Value) -> Result<[f64; 4], String> { +fn window_box(s: &Session, p: &Value, seen: Option<[f64; 4]>) -> Result<[f64; 4], String> { const NEED: &str = "bbox is [west, south, east, north] in degrees, or \"view\""; - let seen = p.get(VIEW_ASKED).and_then(Value::as_array).filter(|_| is_view(p.get("bbox"))); let [w, so, e, n] = match p.get("bbox") { - // The view a request was made in (`add`, above), checked as a box given. - Some(_) if seen.is_some() => { - let v: Option> = seen.into_iter().flatten().map(|x| x.as_f64().filter(|x| x.is_finite())).collect(); - match v.as_deref() { - Some([w, so, e, n]) => [*w, *so, *e, *n], - _ => return Err(NEED.into()), - } - } + // The view a request was asked in ([`crate::UrlRequest::view_asked`]). + Some(v) if is_view(Some(v)) && seen.is_some() => seen.unwrap_or_default(), Some(v) if is_view(Some(v)) => { let e = super::workspace::view_extent(s); if e.is_empty() { @@ -4428,10 +4423,8 @@ fn window_box(s: &Session, p: &Value) -> Result<[f64; 4], String> { if w < e && so < n && lon(w) && lon(e) && lat(so) && lat(n) { Ok([w, so, e, n]) } else { Err(NEED.into()) } } -/// Where a window request left to the app keeps the box `"bbox": "view"` was when it was asked for. -const VIEW_ASKED: &str = "viewAsked"; - /// `"bbox": "view"`, in any case or spacing. +#[cfg(not(target_arch = "wasm32"))] fn is_view(bbox: Option<&Value>) -> bool { bbox.and_then(Value::as_str).is_some_and(|v| v.trim().eq_ignore_ascii_case("view")) } diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index 9767463d16..1f618834ad 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -50,11 +50,18 @@ pub struct UrlRequest { key: u64, params: Value, authority: std::sync::Arc, + /// For a window asked with `"bbox": "view"`: the box the view was then, kept apart from its + /// parameters, which a caller gives and a command run again is matched by. + view: Option<[f64; 4]>, } impl UrlRequest { pub fn params(&self) -> &Value { &self.params } + /// The box `"bbox": "view"` was when the command asked (`cmd::layer::window_asked_in`). + pub fn view_asked(&self) -> Option<[f64; 4]> { + self.view + } } pub type CmdResult = Result; @@ -823,6 +830,8 @@ pub struct Session { /// Downloads a command asked for where nothing may wait (the browser): the parameters of /// `layer.addUrl` calls, for the front end to fetch and add (see [`Session::take_url_requests`]). pub(crate) url_requests: Vec, + /// The view's box a window request being queued keeps ([`UrlRequest::view_asked`]). + pub(crate) window_view: Option<[f64; 4]>, /// Set by [`Session::request_url`] for [`Session::guarded`]: the command running changed /// nothing, it only left a request (a plugin's own answer can't claim that). request_only: bool, @@ -1156,6 +1165,7 @@ impl Session { #[cfg(not(target_arch = "wasm32"))] landed_windows: Vec::new(), url_requests: Vec::new(), + window_view: None, file_outputs: Vec::new(), #[cfg(test)] queue_gp_files: false, diff --git a/crates/engine/src/policy/downloads.rs b/crates/engine/src/policy/downloads.rs index 8bad4c9808..cce4415ece 100644 --- a/crates/engine/src/policy/downloads.rs +++ b/crates/engine/src/policy/downloads.rs @@ -62,7 +62,7 @@ impl Session { requests: self .url_requests .iter() - .map(|q| UrlRequest { key: q.key, params: q.params.clone(), authority: q.authority.clone() }) + .map(|q| UrlRequest { key: q.key, params: q.params.clone(), authority: q.authority.clone(), view: q.view }) .collect(), queued: self.policy.work.queued.clone(), } @@ -280,7 +280,8 @@ impl Session { self.next_pending = self.next_pending.wrapping_add(1); let key = self.next_pending; self.policy.work.queued.insert(key, Queued { c: Arc::downgrade(&c), import, consumed: Arc::new(AtomicBool::new(false)) }); - self.url_requests.push(UrlRequest { key, params, authority: c }); + let view = self.window_view.take(); + self.url_requests.push(UrlRequest { key, params, authority: c, view }); } if !import && let Some(asked_now) = self.call_requests.as_mut() diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 93051fdc22..73c04b229f 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -30528,29 +30528,45 @@ fn a_windows_bands_are_started_within_its_wait() { /// A plugin's command asking for the view's window is read for the view it was asked in, though the /// app reads it on a later frame, when the map may show another (#1330): a command run again after -/// a download sees the view it first ran with only while it runs. +/// a download sees the view it first ran with only while it runs. The box is kept beside the +/// request, not in what it asks, so the command run again is answered the raster added. #[cfg(not(target_arch = "wasm32"))] #[test] fn a_window_asked_for_the_view_keeps_the_view_it_was_asked_in() { - use crate::cmd::layer::window_asked; + use crate::cmd::layer::{read_cog_window, window_asked, window_asked_in}; + use rustgis_data::raster::cog::example; + let (base, _) = serve_ranges(example(1024, 256)); let mut s = world(); plugin("eng-window-view", &["edit", "network"]); - s.run("map.zoomToExtent", &json!({"extent": [10.0, 45.0, 11.0, 46.0]})).unwrap(); + let layers = s.map().layers.len(); + s.run("map.zoomToExtent", &json!({"extent": [10.3, 45.55, 10.45, 45.7]})).unwrap(); let seen = crate::cmd::workspace::view_extent(&s); - let p = json!({"op": "layer.addUrl", "params": {"url": "https://x.org/scene.tif", "bbox": "view", "viewAsked": [0, 0, 1, 1]}}); + let p = json!({"op": "layer.addUrl", "params": {"url": format!("{base}/scene.tif"), "bbox": "view", "name": "Window"}}); s.run_leaving_downloads("plugin:eng-window-view/f", &p).unwrap(); let asked = s.take_url_requests(); assert_eq!(asked.len(), 1); + assert_eq!(asked[0].params()["bbox"], "view", "what it asks is as it asked it"); + let close = + |a: [f64; 4], b: rustgis_geom::Extent| a.iter().zip([b.min_x, b.min_y, b.max_x, b.max_y]).all(|(a, b)| (a - b).abs() < 1e-9); s.run("map.zoomToExtent", &json!({"extent": [-50.0, -20.0, -40.0, -10.0]})).unwrap(); - let read = window_asked(&s, asked[0].params()).unwrap().bbox(); - let want = [seen.min_x, seen.min_y, seen.max_x, seen.max_y]; - assert!(read.iter().zip(want).all(|(a, b)| (a - b).abs() < 1e-9), "{read:?} {want:?}"); - // What the request says to read is the box it was asked in, not one a caller gave. - assert_eq!(asked[0].params()["bbox"], "view"); - // A box asked for now is the view now. + let window = window_asked_in(&s, asked[0].params(), asked[0].view_asked()).unwrap(); + assert!(close(window.bbox(), seen), "{:?} {seen:?}", window.bbox()); + // Without the request's box, `"view"` is the view now. let now = crate::cmd::workspace::view_extent(&s); - let read = window_asked(&s, &json!({"url": "https://x.org/scene.tif", "bbox": "view"})).unwrap().bbox(); - assert!((read[0] - now.min_x).abs() < 1e-9 && (read[3] - now.max_y).abs() < 1e-9, "{read:?}"); + assert!(close(window_asked(&s, asked[0].params()).unwrap().bbox(), now)); + // Read and added: the command run again is answered the raster added, and asks nothing more. + let id = s.download_started_for(&asked[0]).unwrap(); + assert!(s.download_landed_window(id, read_cog_window(&window).unwrap())); + let mut add = asked[0].params().clone(); + add["id"] = json!(id); + add["window"] = json!({"bbox": "view"}); + s.complete_download(id, &add).unwrap(); + let added = s.map().layer_by_name("Window").filter(|l| l.is_raster()).unwrap().id; + let ran = s.poll_plugin_retries(); + assert_eq!(ran.len(), 1, "{ran:?}"); + assert_eq!(ran[0].1.as_ref().unwrap()["layer"], json!(added), "{ran:?}"); + assert_eq!(s.map().layers.len(), layers + 1, "added once"); + assert!(s.take_url_requests().is_empty() && !s.plugin_retries_waiting()); } /// A plugin's command asking for a window runs again once the app has read it and added it, and diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 0fdcf54a97..bcf92c0c86 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -4445,7 +4445,7 @@ impl RustGisApp { } #[cfg(not(target_arch = "wasm32"))] if window { - return self.start_window_read(p, url, q, claim); + return self.start_window_read(p, url, q, claim, request.and_then(rustgis_engine::UrlRequest::view_asked)); } let shown = rustgis_engine::data::s3_address::inner(&url); self.session.notify(i18n::fmt("Downloading {url}…", &[("url", shown)]), false); @@ -4614,8 +4614,15 @@ impl RustGisApp { /// thread, to add it with `q` when it lands (#1330). The command line and scripts wait for it /// in `layer.addUrl` instead. What's wrong with what was asked is refused here, on the frame. #[cfg(not(target_arch = "wasm32"))] - fn start_window_read(&mut self, p: &Value, url: String, mut q: Value, claim: Option) -> Result { - let asked = rustgis_engine::cmd::layer::window_asked(&self.session, p).and_then(|asked| { + fn start_window_read( + &mut self, + p: &Value, + url: String, + mut q: Value, + claim: Option, + seen: Option<[f64; 4]>, + ) -> Result { + let asked = rustgis_engine::cmd::layer::window_asked_in(&self.session, p, seen).and_then(|asked| { if self.ui.window_reads.len() >= MAX_WINDOW_READS { return Err(i18n::fmt( "{url}: {count} windows are being read already: ask again once one has been added", From 5d77e0c1c886f5743fa51a6a2af8c60d7a2ce563 Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Mon, 9 Nov 2026 01:34:54 -0300 Subject: [PATCH 05/13] fix(plugins): a window of the view joins only one asked in the same view (#1330) A request for the view joined a queued or in-flight one by its parameters alone, so a command that moved the map between two such requests got the first view's raster for the second. The queued match compares the request's view box too, and the in-flight match the box kept by request number (pruned with the requests). window_box matches on seen instead of unwrapping behind a guard. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/layer.rs | 28 ++++++++++++++------------- crates/engine/src/cmd/plugin_fetch.rs | 4 ++++ crates/engine/src/lib.rs | 4 ++++ crates/engine/src/policy/downloads.rs | 8 +++++++- 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/crates/engine/src/cmd/layer.rs b/crates/engine/src/cmd/layer.rs index bd541e5b71..4a3af62df5 100644 --- a/crates/engine/src/cmd/layer.rs +++ b/crates/engine/src/cmd/layer.rs @@ -4396,20 +4396,22 @@ pub(crate) fn box_in_file_longitudes(x0: f64, x1: f64, fx0: f64, fx1: f64) -> Re fn window_box(s: &Session, p: &Value, seen: Option<[f64; 4]>) -> Result<[f64; 4], String> { const NEED: &str = "bbox is [west, south, east, north] in degrees, or \"view\""; let [w, so, e, n] = match p.get("bbox") { - // The view a request was asked in ([`crate::UrlRequest::view_asked`]). - Some(v) if is_view(Some(v)) && seen.is_some() => seen.unwrap_or_default(), - Some(v) if is_view(Some(v)) => { - let e = super::workspace::view_extent(s); - if e.is_empty() { - return Err("the map's extent isn't known; give bbox".into()); - } - // A view past 180° (across the antimeridian, or the world more than once) isn't cut - // to fit: what it shows past there would be left out. - if e.min_x < -180.0 || e.max_x > 180.0 { - return Err("the view reaches past 180° of longitude; give bbox".into()); + Some(v) if is_view(Some(v)) => match seen { + // The view a request was asked in ([`crate::UrlRequest::view_asked`]). + Some(b) => b, + None => { + let e = super::workspace::view_extent(s); + if e.is_empty() { + return Err("the map's extent isn't known; give bbox".into()); + } + // A view past 180° (across the antimeridian, or the world more than once) isn't + // cut to fit: what it shows past there would be left out. + if e.min_x < -180.0 || e.max_x > 180.0 { + return Err("the view reaches past 180° of longitude; give bbox".into()); + } + [e.min_x, e.min_y.max(-90.0), e.max_x, e.max_y.min(90.0)] } - [e.min_x, e.min_y.max(-90.0), e.max_x, e.max_y.min(90.0)] - } + }, Some(Value::Array(a)) => { let v: Option> = a.iter().map(|x| x.as_f64().filter(|x| x.is_finite())).collect(); match v.as_deref() { diff --git a/crates/engine/src/cmd/plugin_fetch.rs b/crates/engine/src/cmd/plugin_fetch.rs index 39541c1871..227f064700 100644 --- a/crates/engine/src/cmd/plugin_fetch.rs +++ b/crates/engine/src/cmd/plugin_fetch.rs @@ -945,6 +945,10 @@ impl Session { let waiting = std::mem::take(&mut self.plugin_retries); self.url_waits.keep_only(&waiting); self.plugin_retries = waiting; + // The views of requests no longer queued, being made or kept for a command. + let queued: Vec = self.url_requests.iter().filter_map(|q| q.params().get("request").and_then(Value::as_u64)).collect(); + let waits = &self.url_waits; + self.window_views.retain(|n, _| waits.has(*n) || queued.contains(n)); ran } } diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index 1f618834ad..9d5fc27201 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -832,6 +832,9 @@ pub struct Session { pub(crate) url_requests: Vec, /// The view's box a window request being queued keeps ([`UrlRequest::view_asked`]). pub(crate) window_view: Option<[f64; 4]>, + /// The view's boxes of the window requests made, by their numbers: a request for the view + /// joins one queued or being made only when it was asked in the same view. + pub(crate) window_views: std::collections::BTreeMap, /// Set by [`Session::request_url`] for [`Session::guarded`]: the command running changed /// nothing, it only left a request (a plugin's own answer can't claim that). request_only: bool, @@ -1166,6 +1169,7 @@ impl Session { landed_windows: Vec::new(), url_requests: Vec::new(), window_view: None, + window_views: Default::default(), file_outputs: Vec::new(), #[cfg(test)] queue_gp_files: false, diff --git a/crates/engine/src/policy/downloads.rs b/crates/engine/src/policy/downloads.rs index cce4415ece..f0ffc0b02a 100644 --- a/crates/engine/src/policy/downloads.rs +++ b/crates/engine/src/policy/downloads.rs @@ -239,6 +239,7 @@ impl Session { .iter() .find(|q| { crate::cmd::plugins::fetch::same_request(&q.params, &asked) + && q.view == self.window_view && self.same_url_caller(&q.authority, &c) && self.check_continuation(&q.authority).is_ok() }) @@ -260,7 +261,9 @@ impl Session { self.url_waits.owner(n).is_some_and(|owner| self.same_url_caller(owner, &c) && self.check_continuation(owner).is_ok()) }) }) - .filter(|n| !self.url_waits.taken_away(*n, &self.project)); + .filter(|n| !self.url_waits.taken_away(*n, &self.project)) + // A window of the view is the one asked in the same view: another is read again. + .filter(|n| self.window_views.get(n).copied() == self.window_view); let number = match given.or(waiting).or(made) { Some(n) => n, None => { @@ -281,6 +284,9 @@ impl Session { let key = self.next_pending; self.policy.work.queued.insert(key, Queued { c: Arc::downgrade(&c), import, consumed: Arc::new(AtomicBool::new(false)) }); let view = self.window_view.take(); + if let Some(v) = view { + self.window_views.insert(number, v); + } self.url_requests.push(UrlRequest { key, params, authority: c, view }); } if !import From 159e41839cff67e2954094ab37b55756eb4170fb Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Mon, 9 Nov 2026 01:52:59 -0300 Subject: [PATCH 06/13] fix(plugins): view boxes travel with the waits; join check inside the lookup (#1330) The boxes of view windows, by request number, now live in UrlWaits, so they go aside with a project, come back with it and are restored on a rollback as the waits are; they are pruned with the waits and cleared when no command waits. The in-flight lookup checks the view inside its match, so it returns the first request that agrees on it. A test queues view requests in two views and with none. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/plugin_fetch.rs | 11 +++++++---- crates/engine/src/lib.rs | 4 ---- crates/engine/src/policy/downloads.rs | 13 ++++++++----- crates/engine/src/tests.rs | 17 +++++++++++++++++ 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/crates/engine/src/cmd/plugin_fetch.rs b/crates/engine/src/cmd/plugin_fetch.rs index 227f064700..d03fe18f0d 100644 --- a/crates/engine/src/cmd/plugin_fetch.rs +++ b/crates/engine/src/cmd/plugin_fetch.rs @@ -321,6 +321,10 @@ pub(crate) struct Retry { /// waiting for them runs again. #[derive(Clone, Default)] pub(crate) struct UrlWaits { + /// The view's boxes of the window requests asked with `"bbox": "view"`, by their numbers: a + /// request for the view joins one being made only when it was asked in the same view. Kept + /// here, they go aside with a project and back on a rollback as the waits do. + pub(crate) views: std::collections::BTreeMap, owners: std::collections::BTreeMap, in_flight: Vec<(u64, Value, Instant)>, landed: Vec<(u64, Value, CmdResult, Added)>, @@ -615,6 +619,7 @@ impl UrlWaits { let wanted = |n: &u64| waiting.iter().any(|r| r.requests.contains(n)); self.in_flight.retain(|(n, ..)| wanted(n)); self.landed.retain(|(n, ..)| wanted(n)); + self.views.retain(|n, _| wanted(n)); let retained: Vec = self .in_flight .iter() @@ -880,6 +885,8 @@ impl Session { fn poll_plugin_retries_at(&mut self, now: Instant) -> Vec<(String, CmdResult)> { self.url_waits.documents_in(); if self.plugin_retries.is_empty() { + // No command waits for a window of the view. + self.url_waits.views.clear(); return Vec::new(); } // Said here too: the command may go on without it, and what it answers goes nowhere. @@ -945,10 +952,6 @@ impl Session { let waiting = std::mem::take(&mut self.plugin_retries); self.url_waits.keep_only(&waiting); self.plugin_retries = waiting; - // The views of requests no longer queued, being made or kept for a command. - let queued: Vec = self.url_requests.iter().filter_map(|q| q.params().get("request").and_then(Value::as_u64)).collect(); - let waits = &self.url_waits; - self.window_views.retain(|n, _| waits.has(*n) || queued.contains(n)); ran } } diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index 9d5fc27201..1f618834ad 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -832,9 +832,6 @@ pub struct Session { pub(crate) url_requests: Vec, /// The view's box a window request being queued keeps ([`UrlRequest::view_asked`]). pub(crate) window_view: Option<[f64; 4]>, - /// The view's boxes of the window requests made, by their numbers: a request for the view - /// joins one queued or being made only when it was asked in the same view. - pub(crate) window_views: std::collections::BTreeMap, /// Set by [`Session::request_url`] for [`Session::guarded`]: the command running changed /// nothing, it only left a request (a plugin's own answer can't claim that). request_only: bool, @@ -1169,7 +1166,6 @@ impl Session { landed_windows: Vec::new(), url_requests: Vec::new(), window_view: None, - window_views: Default::default(), file_outputs: Vec::new(), #[cfg(test)] queue_gp_files: false, diff --git a/crates/engine/src/policy/downloads.rs b/crates/engine/src/policy/downloads.rs index f0ffc0b02a..6d416f5b5b 100644 --- a/crates/engine/src/policy/downloads.rs +++ b/crates/engine/src/policy/downloads.rs @@ -257,13 +257,16 @@ impl Session { .call_requests .as_ref() .and_then(|_| { + // A window of the view is the one asked in the same view: another is read again. self.url_waits.in_flight(&asked, |n| { - self.url_waits.owner(n).is_some_and(|owner| self.same_url_caller(owner, &c) && self.check_continuation(owner).is_ok()) + self.url_waits.views.get(&n).copied() == self.window_view + && self + .url_waits + .owner(n) + .is_some_and(|owner| self.same_url_caller(owner, &c) && self.check_continuation(owner).is_ok()) }) }) - .filter(|n| !self.url_waits.taken_away(*n, &self.project)) - // A window of the view is the one asked in the same view: another is read again. - .filter(|n| self.window_views.get(n).copied() == self.window_view); + .filter(|n| !self.url_waits.taken_away(*n, &self.project)); let number = match given.or(waiting).or(made) { Some(n) => n, None => { @@ -285,7 +288,7 @@ impl Session { self.policy.work.queued.insert(key, Queued { c: Arc::downgrade(&c), import, consumed: Arc::new(AtomicBool::new(false)) }); let view = self.window_view.take(); if let Some(v) = view { - self.window_views.insert(number, v); + self.url_waits.views.insert(number, v); } self.url_requests.push(UrlRequest { key, params, authority: c, view }); } diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 73c04b229f..0eda422944 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -30526,6 +30526,23 @@ fn a_windows_bands_are_started_within_its_wait() { assert_eq!(e, "2 of 4 bands read in 5 minutes, so the window is given up: take a smaller box or a larger cellSize"); } +/// A request for the view's window joins one queued only when it was asked in the same view: +/// asked in another, it is another request, read for its own view (#1330). +#[test] +fn a_window_of_the_view_joins_only_one_asked_in_the_same_view() { + let mut s = Session::new(Project::default()); + let p = json!({"url": "https://x.org/scene.tif", "bbox": "view"}); + let (a, b) = ([10.0, 45.0, 11.0, 46.0], [20.0, 45.0, 21.0, 46.0]); + for view in [Some(a), Some(a), Some(b), None] { + s.window_view = view; + s.request_url(&p).unwrap(); + s.window_view = None; + } + let views: Vec> = s.take_url_requests().iter().map(crate::UrlRequest::view_asked).collect(); + assert_eq!(views, [Some(a), Some(b), None], "the same view's asked once"); + assert_eq!(s.url_waits.views.len(), 2, "kept by request number"); +} + /// A plugin's command asking for the view's window is read for the view it was asked in, though the /// app reads it on a later frame, when the map may show another (#1330): a command run again after /// a download sees the view it first ran with only while it runs. The box is kept beside the From 8b864007dd3c4beb1c5c9c0900d9bf5f650282c5 Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Mon, 9 Nov 2026 02:04:17 -0300 Subject: [PATCH 07/13] fix(plugins): keep the view boxes of live waits when no command waits (#1330) On the early return with no command waiting, the boxes were all cleared while in-flight and landed waits stayed, so a later request in the same view would read its window again. They are now pruned to the waits still being made or landed. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/plugin_fetch.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/plugin_fetch.rs b/crates/engine/src/cmd/plugin_fetch.rs index d03fe18f0d..885233ec61 100644 --- a/crates/engine/src/cmd/plugin_fetch.rs +++ b/crates/engine/src/cmd/plugin_fetch.rs @@ -615,6 +615,12 @@ impl UrlWaits { } /// Only what `waiting` still waits for is kept. + /// Keeps the views of the requests still being made or landed only. + fn prune_views(&mut self) { + let live: Vec = self.in_flight.iter().map(|(n, ..)| *n).chain(self.landed.iter().map(|(n, ..)| *n)).collect(); + self.views.retain(|n, _| live.contains(n)); + } + fn keep_only(&mut self, waiting: &[Retry]) { let wanted = |n: &u64| waiting.iter().any(|r| r.requests.contains(n)); self.in_flight.retain(|(n, ..)| wanted(n)); @@ -885,8 +891,7 @@ impl Session { fn poll_plugin_retries_at(&mut self, now: Instant) -> Vec<(String, CmdResult)> { self.url_waits.documents_in(); if self.plugin_retries.is_empty() { - // No command waits for a window of the view. - self.url_waits.views.clear(); + self.url_waits.prune_views(); return Vec::new(); } // Said here too: the command may go on without it, and what it answers goes nowhere. From 5df8b265381ccc2a84fe8eadda4e1be77474306f Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Mon, 9 Nov 2026 02:19:47 -0300 Subject: [PATCH 08/13] docs(plugins): a script or model the app runs leaves a window to it too; test it (#1330) Since this PR, layer.addUrl with "bbox" under deferred downloads is queued for the app, not refused, for the app's reads (scripts, models) as for plugin commands, as whole downloads already are. The data formats page says so, and a test pins it. A doc comment misplaced by prune_views goes back to keep_only. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/plugin_fetch.rs | 2 +- crates/engine/src/tests.rs | 14 ++++++++++++++ docs/user-guide/data-formats.md | 9 +++++---- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/crates/engine/src/cmd/plugin_fetch.rs b/crates/engine/src/cmd/plugin_fetch.rs index 885233ec61..35930ba49d 100644 --- a/crates/engine/src/cmd/plugin_fetch.rs +++ b/crates/engine/src/cmd/plugin_fetch.rs @@ -614,13 +614,13 @@ impl UrlWaits { } } - /// Only what `waiting` still waits for is kept. /// Keeps the views of the requests still being made or landed only. fn prune_views(&mut self) { let live: Vec = self.in_flight.iter().map(|(n, ..)| *n).chain(self.landed.iter().map(|(n, ..)| *n)).collect(); self.views.retain(|n, _| live.contains(n)); } + /// Only what `waiting` still waits for is kept. fn keep_only(&mut self, waiting: &[Retry]) { let wanted = |n: &u64| waiting.iter().any(|r| r.requests.contains(n)); self.in_flight.retain(|(n, ..)| wanted(n)); diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 0eda422944..a18ec8a6c3 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -30526,6 +30526,20 @@ fn a_windows_bands_are_started_within_its_wait() { assert_eq!(e, "2 of 4 bands read in 5 minutes, so the window is given up: take a smaller box or a larger cellSize"); } +/// A script or model the desktop app runs off the frame, as a plugin's command, leaves a window to +/// the app: answered pending, and queued, not refused (#1330). +#[cfg(not(target_arch = "wasm32"))] +#[test] +fn a_script_run_by_the_app_leaves_a_window_to_it() { + let mut s = world(); + let p = json!({"url": "https://x.org/scene.tif", "bbox": [10.25, 45.5, 10.5, 45.75]}); + let answer = s.with_deferred_downloads(|s| s.run("layer.addUrl", &p)).unwrap(); + assert_eq!(answer["pending"], true, "{answer}"); + let asked = s.take_url_requests(); + assert_eq!(asked.len(), 1); + assert_eq!(asked[0].params()["bbox"], p["bbox"]); +} + /// A request for the view's window joins one queued only when it was asked in the same view: /// asked in another, it is another request, read for its own view (#1330). #[test] diff --git a/docs/user-guide/data-formats.md b/docs/user-guide/data-formats.md index 5ad8de0455..611c6d2571 100644 --- a/docs/user-guide/data-formats.md +++ b/docs/user-guide/data-formats.md @@ -190,10 +190,11 @@ tile), without a STAC catalogue: A window reads 256 bands at most. A window near the limit takes several hundred MB of memory while it is read and kept. - The Add Data From URL dialog has no box to fill in, so a window is asked for by a command. On - the command line and in a script, `layer.addUrl` waits for it and answers what was added. In the - desktop app, `ui.addUrl` with `"bbox"`, and a plugin's command calling `layer.addUrl` with it, - read it off the frame: the map stays in use, and the layer is added when the read lands (the - plugin's command then runs again with what adding it answered). These are read one at a time, + the command line and in Python, `layer.addUrl` waits for it and answers what was added. In the + desktop app, `ui.addUrl` with `"bbox"`, and `layer.addUrl` with it from a plugin's command or + from a script or model run there, read it off the frame: the map stays in use, and the layer is + added when the read lands (a plugin's command then runs again with what adding it answered; a + script or model is answered `"pending"` and goes on, as with a whole file it downloads). These are read one at a time, with 16 under way at most, and the next starts once the app has taken the last. If another project is opened meanwhile, one still waiting isn't read, and one being read can't be cancelled yet: it runs to its end and isn't added. Each is said in a notice. From 76b3198d91b4bb453946ab7c8cc558aac3f59dd7 Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Mon, 9 Nov 2026 02:48:14 -0300 Subject: [PATCH 09/13] fix(plugins): a command run again gets each view's own window (#1330) A command run again was answered by the landed windows' parameters only, so two windows of the view asked in two views both got the first. The answers are now told apart by the view each was asked in (kept by request number when the app starts the download, as a pending command's own waits may have been restored since it queued it), and the command's call is matched with the view it sees now. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/layer.rs | 9 +++++++++ crates/engine/src/cmd/plugin_fetch.rs | 24 ++++++++++++++++++------ crates/engine/src/policy/downloads.rs | 5 +++++ crates/engine/src/tests.rs | 24 ++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 6 deletions(-) diff --git a/crates/engine/src/cmd/layer.rs b/crates/engine/src/cmd/layer.rs index 4a3af62df5..1045cbe9b3 100644 --- a/crates/engine/src/cmd/layer.rs +++ b/crates/engine/src/cmd/layer.rs @@ -3218,6 +3218,15 @@ fn add_url_as_given(s: &mut Session, p: &Value) -> CmdResult { // adding it answered, as often as the run asks for it (the app downloaded and added it once). // Answering it changes nothing (the layer is its own undo step). let wanted = s.asked_for(p); + // A window of the view is answered by the one asked in the view the command sees now. + #[cfg(not(target_arch = "wasm32"))] + let wanted = match p.get("bbox") { + Some(b) if s.leave_downloads && is_view(Some(b)) => { + let at = ps(p, "url").map(str::trim).unwrap_or_default(); + Session::with_view(&wanted, Some(window_settled(s, p, at, None)?.bbox)) + } + _ => wanted, + }; if s.leave_downloads && let Some((answer, added)) = s.rerun_answer(&wanted) { diff --git a/crates/engine/src/cmd/plugin_fetch.rs b/crates/engine/src/cmd/plugin_fetch.rs index 35930ba49d..d0c1a850d5 100644 --- a/crates/engine/src/cmd/plugin_fetch.rs +++ b/crates/engine/src/cmd/plugin_fetch.rs @@ -319,6 +319,10 @@ pub(crate) struct Retry { /// The downloads plugin commands wait for (#1202): those the app is making, with what was /// asked and since when, and those added, with what adding them answered, until the command /// waiting for them runs again. +/// The key a window of the view is told apart by when a command run again is answered +/// ([`Session::with_view`]): matched only, never read as a parameter. +const VIEW_ASKED: &str = "viewAsked"; + #[derive(Clone, Default)] pub(crate) struct UrlWaits { /// The view's boxes of the window requests asked with `"bbox": "view"`, by their numbers: a @@ -738,6 +742,17 @@ impl Session { Ok(None) } + /// What a window of the view was asked as, for a command run again to be answered by: `asked` + /// with the box the view was then (`UrlWaits::views`), so two windows of the view asked in + /// two views are told apart. Others are `asked` as it is. + pub(crate) fn with_view(asked: &Value, view: Option<[f64; 4]>) -> Value { + let mut asked = asked.clone(); + if let (Some(v), Some(o)) = (view, asked.as_object_mut()) { + o.insert(VIEW_ASKED.into(), json!(v)); + } + asked + } + /// Whether a command run again has an answer for `wanted`. #[cfg(not(target_arch = "wasm32"))] pub(crate) fn rerun_has(&self, wanted: &Value) -> bool { @@ -923,12 +938,9 @@ impl Session { // runs, and the ones it waited for. These stay in `landed` until no command waits // for them (`keep_only`, below), so another command waiting for the same download // gets the answer too. - let mine = self - .url_waits - .landed - .iter() - .filter(|(n, ..)| r.requests.contains(n)) - .map(|(_, asked, answer, added)| (asked.clone(), answer.clone(), added.clone())); + let mine = self.url_waits.landed.iter().filter(|(n, ..)| r.requests.contains(n)).map(|(n, asked, answer, added)| { + (Self::with_view(asked, self.url_waits.views.get(n).copied()), answer.clone(), added.clone()) + }); self.rerun_landed = r.answered.iter().cloned().chain(mine).collect(); self.rerun_said = r.said; self.retry_tries = r.tries; diff --git a/crates/engine/src/policy/downloads.rs b/crates/engine/src/policy/downloads.rs index 6d416f5b5b..b028573765 100644 --- a/crates/engine/src/policy/downloads.rs +++ b/crates/engine/src/policy/downloads.rs @@ -369,6 +369,11 @@ impl Session { } let c = (*c).clone(); let id = self.download_started(); + // The view a window of the view was asked in, by its number, now that the request is made + // (the command's own waits may have been restored since it was queued). + if let (Some(v), Some(n)) = (request.view, request.params.get("request").and_then(Value::as_u64)) { + self.url_waits.views.insert(n, v); + } self.policy.work.claims.insert(id, Claim { c, params: request.params.clone(), live: Arc::new(AtomicBool::new(true)), import }); Ok(id) } diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index a18ec8a6c3..1e3c33bcb1 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -30540,6 +30540,30 @@ fn a_script_run_by_the_app_leaves_a_window_to_it() { assert_eq!(asked[0].params()["bbox"], p["bbox"]); } +/// A command run again that asks for windows of the view in two views is answered each by the +/// window asked in that view, not twice by the first (#1330). +#[cfg(not(target_arch = "wasm32"))] +#[test] +fn a_command_run_again_gets_each_view_s_own_window() { + let mut s = world(); + let p = json!({"url": "https://x.org/scene.tif", "bbox": "view"}); + let asked = s.asked_for(&p); + let mut views = Vec::new(); + for (extent, marker) in [([10.0, 45.0, 11.0, 46.0], "A"), ([20.0, 45.0, 21.0, 46.0], "B")] { + s.run("map.zoomToExtent", &json!({"extent": extent})).unwrap(); + let e = crate::cmd::workspace::view_extent(&s); + let view = [e.min_x, e.min_y, e.max_x, e.max_y]; + s.rerun_landed.push((Session::with_view(&asked, Some(view)), Ok(json!({"marker": marker})), Default::default())); + views.push(extent); + } + let answer = |s: &mut Session, extent: [f64; 4]| { + s.run("map.zoomToExtent", &json!({"extent": extent})).unwrap(); + s.with_deferred_downloads(|s| s.run("layer.addUrl", &p)).unwrap()["marker"].clone() + }; + assert_eq!(answer(&mut s, views[1]), "B"); + assert_eq!(answer(&mut s, views[0]), "A"); +} + /// A request for the view's window joins one queued only when it was asked in the same view: /// asked in another, it is another request, read for its own view (#1330). #[test] From 6b820098dcfa200b4b1848efe9d178bf04237f31 Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Mon, 9 Nov 2026 02:55:31 -0300 Subject: [PATCH 10/13] docs(plugins): UrlWaits keeps its doc comment, above VIEW_ASKED (#1330) Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/plugin_fetch.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/cmd/plugin_fetch.rs b/crates/engine/src/cmd/plugin_fetch.rs index d0c1a850d5..82aada6127 100644 --- a/crates/engine/src/cmd/plugin_fetch.rs +++ b/crates/engine/src/cmd/plugin_fetch.rs @@ -316,13 +316,13 @@ pub(crate) struct Retry { tries: u32, } -/// The downloads plugin commands wait for (#1202): those the app is making, with what was -/// asked and since when, and those added, with what adding them answered, until the command -/// waiting for them runs again. /// The key a window of the view is told apart by when a command run again is answered /// ([`Session::with_view`]): matched only, never read as a parameter. const VIEW_ASKED: &str = "viewAsked"; +/// The downloads plugin commands wait for (#1202): those the app is making, with what was +/// asked and since when, and those added, with what adding them answered, until the command +/// waiting for them runs again. #[derive(Clone, Default)] pub(crate) struct UrlWaits { /// The view's boxes of the window requests asked with `"bbox": "view"`, by their numbers: a From 86b9113d74bbf16b8ea4a619cafe092fe2393677 Mon Sep 17 00:00:00 2001 From: giswqs Date: Mon, 9 Nov 2026 16:51:20 -0500 Subject: [PATCH 11/13] docs(data-formats): wrap the window paragraph --- docs/user-guide/data-formats.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/user-guide/data-formats.md b/docs/user-guide/data-formats.md index f776c64280..cf1425a97d 100644 --- a/docs/user-guide/data-formats.md +++ b/docs/user-guide/data-formats.md @@ -194,10 +194,10 @@ tile), without a STAC catalogue: desktop app, `ui.addUrl` with `"bbox"`, and `layer.addUrl` with it from a plugin's command or from a script or model run there, read it off the frame: the map stays in use, and the layer is added when the read lands (a plugin's command then runs again with what adding it answered; a - script or model is answered `"pending"` and goes on, as with a whole file it downloads). These are read one at a time, - with 16 under way at most, and the next starts once the app has taken the last. If another - project is opened meanwhile, one still waiting isn't read, and one being read can't be cancelled - yet: it runs to its end and isn't added. Each is said in a notice. + script or model is answered `"pending"` and goes on, as with a whole file it downloads). These + are read one at a time, with 16 under way at most, and the next starts once the app has taken + the last. If another project is opened meanwhile, one still waiting isn't read, and one being + read can't be cancelled yet: it runs to its end and isn't added. Each is said in a notice. - The file's no-data, colour table (a palette file draws in its colours) and band names come with it, and class names given as `CLASS_` items in GDAL's metadata tag, as the MapBiomas files on Source Cooperative give theirs. These come from the file's own tags: an `.aux.xml` From c06e1d075f67d284ece9d56c8963945563602de7 Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Tue, 10 Nov 2026 05:19:29 -0300 Subject: [PATCH 12/13] fix(plugins): a caller's own "viewAsked" is left out of what it asked for (#1330) Only the session tells windows of the view apart (with_view): asked_for drops a caller-written viewAsked, so it is no parameter at all. start_window_read's doc says who waits in layer.addUrl (the command line) and who leaves the window to the app (a plugin's command or a script the app runs). Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/plugin_fetch.rs | 11 +++++++---- crates/engine/src/tests.rs | 3 +++ crates/ui-egui/src/lib.rs | 5 +++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/crates/engine/src/cmd/plugin_fetch.rs b/crates/engine/src/cmd/plugin_fetch.rs index 3c8c63553b..e1e267a95a 100644 --- a/crates/engine/src/cmd/plugin_fetch.rs +++ b/crates/engine/src/cmd/plugin_fetch.rs @@ -682,10 +682,13 @@ impl Session { /// eventual `layer.addDownload`; a command run again asks for the same. pub(crate) fn asked_for(&self, p: &Value) -> Value { let mut asked = without_request(p); - if self.web_logins.is_anonymous() - && let Some(o) = asked.as_object_mut() - { - o.insert("anonymous".into(), json!(true)); + if let Some(o) = asked.as_object_mut() { + // Only the session tells windows of the view apart ([`Session::with_view`]): a caller's + // own `viewAsked` is left out. + o.remove(VIEW_ASKED); + if self.web_logins.is_anonymous() { + o.insert("anonymous".into(), json!(true)); + } } asked } diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 225ee1e570..6d05e169b9 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -33198,6 +33198,9 @@ fn a_command_run_again_gets_each_view_s_own_window() { }; assert_eq!(answer(&mut s, views[1]), "B"); assert_eq!(answer(&mut s, views[0]), "A"); + // A caller can't write the key the view is told apart by. + let written = s.asked_for(&json!({"url": "https://x.org/scene.tif", "bbox": "view", "viewAsked": [0, 0, 1, 1]})); + assert_eq!(written, asked); } /// A request for the view's window joins one queued only when it was asked in the same view: diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 75b147a2c9..79c08d514e 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -4660,8 +4660,9 @@ impl RustGisApp { } /// Starts reading a window of a cloud-optimised GeoTIFF (`p`, a `ui.addUrl` with `"bbox"`) on a - /// thread, to add it with `q` when it lands (#1330). The command line and scripts wait for it - /// in `layer.addUrl` instead. What's wrong with what was asked is refused here, on the frame. + /// thread, to add it with `q` when it lands (#1330). The command line waits for it in + /// `layer.addUrl` instead; a plugin's command or a script the app runs leaves it to the app. + /// What's wrong with what was asked is refused here, on the frame. #[cfg(not(target_arch = "wasm32"))] fn start_window_read( &mut self, From 00bc1aee130b3b4ffa6af7f44444427ea0abb6a6 Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Tue, 10 Nov 2026 05:43:49 -0300 Subject: [PATCH 13/13] test(plugins): a window of the view being read joins only the same view (#1330) The in-flight half of the join rule had no test: a command asking again while the window is read joins it in the same view, and asks again in another view or with a box. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/tests.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 6d05e169b9..add6b0d757 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -33220,6 +33220,35 @@ fn a_window_of_the_view_joins_only_one_asked_in_the_same_view() { assert_eq!(s.url_waits.views.len(), 2, "kept by request number"); } +/// A window of the view that is being read joins a command asking for it again in the same view; +/// asked in another view, or with a box, it is another request (#1330). +#[cfg(not(target_arch = "wasm32"))] +#[test] +fn a_window_of_the_view_being_read_joins_only_the_same_view() { + let mut s = world(); + plugin("eng-window-flight", &["edit", "network"]); + let ask = |s: &mut Session, bbox: Value| { + let p = json!({"op": "layer.addUrl", "params": {"url": "https://x.org/scene.tif", "bbox": bbox, "name": "Window"}}); + s.run_leaving_downloads("plugin:eng-window-flight/f", &p).unwrap(); + s.take_url_requests() + }; + s.run("map.zoomToExtent", &json!({"extent": [10.0, 45.0, 11.0, 46.0]})).unwrap(); + let first = ask(&mut s, json!("view")); + assert_eq!(first.len(), 1); + s.download_started_for(&first[0]).unwrap(); + // While it is read: the same view joins it. + assert!(ask(&mut s, json!("view")).is_empty(), "the same view's window is read once"); + // Another view: another request, for that view. + s.run("map.zoomToExtent", &json!({"extent": [20.0, 45.0, 21.0, 46.0]})).unwrap(); + let other = ask(&mut s, json!("view")); + assert_eq!(other.len(), 1); + assert!(other[0].view_asked().is_some() && other[0].view_asked() != first[0].view_asked()); + // A box: another request, with no view. + let boxed = ask(&mut s, json!([10.25, 45.5, 10.5, 45.75])); + assert_eq!(boxed.len(), 1); + assert_eq!(boxed[0].view_asked(), None); +} + /// A plugin's command asking for the view's window is read for the view it was asked in, though the /// app reads it on a later frame, when the map may show another (#1330): a command run again after /// a download sees the view it first ran with only while it runs. The box is kept beside the