From 2c8e722bfae8051b73884fa5ce0bf839128c9d4e Mon Sep 17 00:00:00 2001 From: mavrick Date: Fri, 20 Nov 2026 10:17:57 -0600 Subject: [PATCH 1/8] feat(map): tell which layers draw differently from a kept picture (#1057) A layer's look (`look::LayerLook`) keeps what it was drawn from, its settings without its rows, pixels or caches, and compares field by field with every field named; rows and a raster's pixels are compared by allocation and not held. The map's look (`look::MapLook`) does the same for the rest of the map. A source read in place, and a raster read in place, still being read or lit by background shadows, have no look. Part 1 of #1057 step 2: the CPU picture cache uses it next. Co-Authored-By: Claude Opus 5.5 --- crates/map/src/lib.rs | 3 +- crates/map/src/look.rs | 455 +++++++++++++++++++++++++++++++++++++++ crates/map/src/raster.rs | 82 +++++++ 3 files changed, 539 insertions(+), 1 deletion(-) create mode 100644 crates/map/src/look.rs diff --git a/crates/map/src/lib.rs b/crates/map/src/lib.rs index 6a2bb6de9f..b3b7309741 100644 --- a/crates/map/src/lib.rs +++ b/crates/map/src/lib.rs @@ -18,6 +18,7 @@ pub mod graticule; pub mod label_by; pub mod layout; pub mod lod; +pub mod look; pub mod palette; pub mod paths; pub mod planets; @@ -1525,7 +1526,7 @@ pub const MAX_GROUP_DEPTH: usize = 8; /// ordinary layers, kept together in the drawing order; a layer belongs to one group at most. /// A group may sit in another (#836, `parent`): its layers, and its subgroups' at any depth, /// stay together in the drawing order, and every group above it applies too. -#[derive(Clone, Debug, Serialize, Deserialize)] +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct LayerGroup { pub id: u32, pub name: String, diff --git a/crates/map/src/look.rs b/crates/map/src/look.rs new file mode 100644 index 0000000000..6c63e0c691 --- /dev/null +++ b/crates/map/src/look.rs @@ -0,0 +1,455 @@ +//! What a frame draws a map and each of its layers from, kept to tell whether a picture drawn +//! earlier still shows them (#1057). A renderer keeps a [`LayerLook`] for each layer it drew and +//! a [`MapLook`] for the rest of the map, and draws again only from the first layer whose look +//! no longer matches. +//! +//! A look is compared field by field, with every field of [`Layer`] and [`Map`] named, so a field +//! added later has to be placed: drawn (compared) or not (left out with a reason). Rows are +//! compared by their allocation ([`rustgis_data::Features::allocation_key`]), which any edit +//! changes and which doesn't keep them: a look holds no copy of a layer's data. + +use std::sync::Weak; + +use rustgis_data::{Dataset, Feature}; + +use crate::raster::RasterLook; +use crate::{Layer, Map}; + +/// How a layer has changed since its [`LayerLook`] was taken. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum Change { + /// It draws as it did. + Same, + /// Only its transparency differs: a picture of the layer alone, drawn opaque, still shows it. + Transparency, + /// It draws differently. + Drawn, +} + +/// What a layer was drawn from: its settings, without its rows or caches, and its rows' +/// allocation (see the module). +#[derive(Clone, Debug)] +pub struct LayerLook { + /// The layer, its rows, raster and caches taken out. + layer: Layer, + rows: Weak>, + raster: Option, +} + +impl LayerLook { + /// The look of `layer`; `None` for one whose drawing reads more than the layer holds, which no + /// look can vouch for: a source read in place (its file is read again for each frame) or a + /// raster without a look ([`crate::RasterLayer::look`]: read in place, still being read, or + /// lit by shadows worked out in the background). + pub fn of(layer: &Layer) -> Option { + if layer.source.is_some() { + return None; + } + let raster = match &layer.raster { + Some(r) => Some(r.look()?), + None => None, + }; + let rows = layer.dataset.features.allocation_key(); + let mut kept = Layer { raster: None, ..layer.clone() }; + kept.dataset.features = Default::default(); + kept.clear_cache(); + // What these share with the layer could hold its rows: a time binding keeps the rows its + // dates were read from. + kept.time = layer.time.as_ref().map(|t| { + let mut bare = crate::time::TimeBinding::new(t.field.clone()); + bare.window = t.window; + bare + }); + kept.view_memory = Default::default(); + kept.geometry_kinds = Default::default(); + Some(LayerLook { layer: kept, rows, raster }) + } + + /// How the layer `now` was taken of differs from the one this look was taken of. + pub fn change(&self, now: &LayerLook) -> Change { + let raster = match (&self.raster, &now.raster) { + (Some(a), Some(b)) => a.same(b), + (a, b) => a.is_none() && b.is_none(), + }; + if !raster || !Weak::ptr_eq(&self.rows, &now.rows) { + return Change::Drawn; + } + let layer = &now.layer; + let Layer { + id, + name, + visible, + dataset, + renderer, + labels, + transparency, + min_scale, + max_scale, + definition_query, + time, + selection, + // The Layers pane's, not the map's. + expanded: _, + selectable, + graphics, + blend, + mask, + display_filters, + aggregation, + extrusion, + line_strokes, + fill_layers, + no_fill, + hidden_fills, + stroke_levels, + marker_rotation, + diagram, + symbol_by, + size_by, + reference_scale, + priority, + design, + // Compared above, and `of` turns down a layer with a source. + raster: _, + source: _, + // Saving back to a database or GeoPackage: what is drawn is the rows. + postgis: _, + gpkg: _, + synced: _, + connection: _, + anonymous: _, + instance_id, + replacement_rev, + // Caches worked out from the rows, which are compared themselves. + projected: _, + display: _, + display_rejected: _, + display_levels: _, + projected_extents: _, + projected_vertices: _, + thinned: _, + projected_rev: _, + projected_for: _, + projected_crs: _, + view_memory: _, + geometry_kinds: _, + geometry_rev, + } = &self.layer; + let drawn = *id == layer.id + && *name == layer.name + && *visible == layer.visible + && same_dataset(dataset, &layer.dataset) + && *renderer == layer.renderer + && *labels == layer.labels + && *min_scale == layer.min_scale + && *max_scale == layer.max_scale + && *definition_query == layer.definition_query + && same_time(time.as_ref(), layer.time.as_ref()) + && *selection == layer.selection + && *selectable == layer.selectable + && *graphics == layer.graphics + && *blend == layer.blend + && *mask == layer.mask + && *display_filters == layer.display_filters + && *aggregation == layer.aggregation + && *extrusion == layer.extrusion + && *line_strokes == layer.line_strokes + && *fill_layers == layer.fill_layers + && *no_fill == layer.no_fill + && *hidden_fills == layer.hidden_fills + && *stroke_levels == layer.stroke_levels + && *marker_rotation == layer.marker_rotation + && *diagram == layer.diagram + && *symbol_by == layer.symbol_by + && *size_by == layer.size_by + && *reference_scale == layer.reference_scale + && *priority == layer.priority + && *design == layer.design + && *instance_id == layer.instance_id + && *replacement_rev == layer.replacement_rev + && *geometry_rev == layer.geometry_rev; + if !drawn { + Change::Drawn + } else if transparency.to_bits() != layer.transparency.to_bits() { + Change::Transparency + } else { + Change::Same + } + } + + /// The layer's id. + pub fn id(&self) -> u32 { + self.layer.id + } +} + +/// Whether two time bindings show the same rows: the same field through the same window (what +/// they keep beside, worked out from those and the rows, aside). +fn same_time(a: Option<&crate::time::TimeBinding>, b: Option<&crate::time::TimeBinding>) -> bool { + a.map(|t| (&t.field, t.window)) == b.map(|t| (&t.field, t.window)) +} + +/// Whether two datasets hold what a frame draws alike, their rows aside (compared by allocation). +fn same_dataset(a: &Dataset, b: &Dataset) -> bool { + let Dataset { name, geometry_type, fields, features: _, source, crs, crs_incomplete, zm_dropped, windowed } = a; + *name == b.name + && *geometry_type == b.geometry_type + && *fields == b.fields + && *source == b.source + && *crs == b.crs + && *crs_incomplete == b.crs_incomplete + && *zm_dropped == b.zm_dropped + && *windowed == b.windowed +} + +/// What a frame draws from a map apart from its layers: its basemap, tile layers, groups, +/// projection, view settings and the rest (see the module). +#[derive(Clone, Debug)] +pub struct MapLook { + /// The map without its layers. + map: Map, +} + +impl MapLook { + /// The look of `map`, its layers left out (each has its own [`LayerLook`]). + pub fn of(map: &Map) -> MapLook { + let Map { + name, + offline_area_id, + layers: _, + service_groups, + groups, + basemap, + tiles, + camera, + bookmarks, + graticule, + graticule_type, + graticule_crs, + projection, + popup_mode, + label_display, + label_lock, + label_lock_line_anchors, + editing, + swipe, + view, + thumbnail, + animation, + time, + body, + next_layer_id, + instance_id, + } = map; + MapLook { + map: Map { + name: name.clone(), + offline_area_id: offline_area_id.clone(), + layers: Vec::new(), + service_groups: service_groups.clone(), + groups: groups.clone(), + basemap: *basemap, + tiles: tiles.clone(), + camera: *camera, + bookmarks: bookmarks.clone(), + graticule: *graticule, + graticule_type: *graticule_type, + graticule_crs: graticule_crs.clone(), + projection: projection.clone(), + popup_mode: *popup_mode, + label_display: *label_display, + label_lock: label_lock.clone(), + label_lock_line_anchors: label_lock_line_anchors.clone(), + editing: editing.clone(), + swipe: *swipe, + view: view.clone(), + thumbnail: thumbnail.clone(), + animation: animation.clone(), + time: time.clone(), + body: body.clone(), + next_layer_id: *next_layer_id, + instance_id: *instance_id, + }, + } + } + + /// Whether the map `now` was taken of, its layers aside, draws as the one this look was + /// taken of did. + pub fn same(&self, now: &MapLook) -> bool { + let map = &now.map; + let Map { + // Graphics text can show the map's name. + name, + offline_area_id: _, + layers: _, + // A service's layers are drawn as layers; the groups only list them. + service_groups: _, + groups, + basemap, + tiles, + camera, + bookmarks: _, + graticule, + graticule_type, + graticule_crs, + projection, + popup_mode: _, + label_display, + label_lock, + label_lock_line_anchors, + // How sketches snap; nothing on the map's picture. + editing: _, + swipe, + view, + thumbnail: _, + animation: _, + time, + body, + next_layer_id: _, + instance_id, + } = &self.map; + *name == map.name + && *groups == map.groups + && *basemap == map.basemap + && *tiles == map.tiles + && *camera == map.camera + && *graticule == map.graticule + && *graticule_type == map.graticule_type + && *graticule_crs == map.graticule_crs + && *projection == map.projection + && *label_display == map.label_display + && *label_lock == map.label_lock + && *label_lock_line_anchors == map.label_lock_line_anchors + && *swipe == map.swipe + && *view == map.view + && *time == map.time + && *body == map.body + && *instance_id == map.instance_id + } +} + +#[cfg(test)] +mod tests { + use rustgis_data::{Coord, Field, FieldType, Geometry, GeometryType, Value}; + + use super::*; + use crate::symbology::Renderer; + use crate::{Bookmark, Rgba}; + + fn layer() -> Layer { + let mut d = Dataset::new("towns", GeometryType::Point, vec![Field::new("pop", FieldType::Integer)]); + d.push(Some(Geometry::Point(Coord::new(1.0, 2.0))), vec![Value::Int(5)]); + d.push(Some(Geometry::Point(Coord::new(3.0, 4.0))), vec![Value::Int(6)]); + Layer::new(1, d) + } + + fn change(edit: impl FnOnce(&mut Layer)) -> Change { + let mut l = layer(); + let Some(before) = LayerLook::of(&l) else { return Change::Drawn }; + edit(&mut l); + LayerLook::of(&l).map_or(Change::Drawn, |now| before.change(&now)) + } + + #[test] + fn each_drawn_edit_changes_the_look() { + assert_eq!(change(|_| {}), Change::Same); + assert_eq!(change(|l| l.visible = false), Change::Drawn); + assert_eq!(change(|l| l.definition_query = Some("pop > 5".into())), Change::Drawn); + assert_eq!(change(|l| l.selection = vec![1]), Change::Drawn); + assert_eq!(change(|l| l.labels.enabled = !l.labels.enabled), Change::Drawn); + assert_eq!(change(|l| l.min_scale = Some(1000.0)), Change::Drawn); + assert_eq!(change(|l| l.renderer = Renderer::Single(crate::Symbol { fill: Rgba::rgb(1, 2, 3), ..l.symbol(0) })), Change::Drawn); + // A row's value or geometry, however small the edit. + assert_eq!( + change(|l| if let Some(f) = l.dataset.features.get_mut(0) { + f.attrs = vec![Value::Int(7)] + }), + Change::Drawn + ); + assert_eq!(change(|l| l.dataset.push(None, vec![Value::Int(8)])), Change::Drawn); + assert_eq!(change(|l| l.touch_geometry()), Change::Drawn); + } + + #[test] + fn transparency_alone_is_told_apart() { + assert_eq!(change(|l| l.transparency = 0.5), Change::Transparency); + // With anything else, the layer is drawn again. + assert_eq!( + change(|l| { + l.transparency = 0.5; + l.visible = false; + }), + Change::Drawn + ); + } + + #[test] + fn what_the_map_does_not_draw_leaves_the_look() { + assert_eq!(change(|l| l.expanded = !l.expanded), Change::Same); + assert_eq!(change(|l| l.connection = "saved".into()), Change::Same); + // A copy shares its rows, as a frame's snapshot of the map does. + let l = layer(); + let copy = l.clone(); + assert!(LayerLook::of(&l).zip(LayerLook::of(©)).is_some_and(|(a, b)| a.change(&b) == Change::Same)); + } + + #[test] + fn a_raster_in_memory_has_a_look() { + use rustgis_data::raster::{ColorHint, Crs, GeoTransform, Raster}; + let gt = GeoTransform { origin_x: 10.0, origin_y: 50.0, pixel_width: 0.5, pixel_height: -0.5 }; + let Ok(r) = Raster::new("dem", 2, 1, vec![vec![1.0, 2.0]], gt, Crs::LonLat, None, ColorHint::Gray, "Float32") else { + panic!("a raster") + }; + let mut l = layer(); + l.raster = Some(crate::RasterLayer::from_path(r.clone(), "dem.tif")); + let look = |l: &Layer| LayerLook::of(l).expect("a look"); + let before = look(&l); + assert_eq!(before.change(&look(&l.clone())), Change::Same); + if let Some(rl) = &mut l.raster { + rl.style.gamma = 2.0; + } + assert_eq!(before.change(&look(&l)), Change::Drawn, "its style"); + let before = look(&l); + if let Some(rl) = &mut l.raster { + rl.data = Some(std::sync::Arc::new(r)); + } + assert_eq!(before.change(&look(&l)), Change::Drawn, "its pixels"); + if let Some(rl) = &mut l.raster { + rl.in_place = true; + } + assert!(LayerLook::of(&l).is_none(), "read in place"); + } + + #[test] + fn a_look_holds_no_rows() { + let mut l = layer(); + let look = LayerLook::of(&l); + // The first edit after taking it changes the rows where they are, copying none. + let ((), copied) = rustgis_data::before_rows_copy(Box::new(|| {}), || l.dataset.push(None, vec![Value::Int(8)])); + assert!(!copied, "the look kept the rows"); + drop(look); + // As a copy of the rows would. + let held = l.dataset.features.clone(); + let ((), copied) = rustgis_data::before_rows_copy(Box::new(|| {}), || l.dataset.push(None, vec![Value::Int(9)])); + assert!(copied); + drop(held); + } + + #[test] + fn a_layer_drawn_from_more_than_it_holds_has_no_look() { + let mut l = layer(); + l.source = Some(Default::default()); + assert!(LayerLook::of(&l).is_none()); + } + + #[test] + fn the_map_look_follows_what_is_drawn() { + let mut map = Map::new("m"); + let before = MapLook::of(&map); + map.bookmarks.push(Bookmark { name: "home".into(), camera: map.camera, description: String::new() }); + map.add_layer(layer()); + assert!(before.same(&MapLook::of(&map)), "bookmarks and layers aren't part of the map's own look"); + map.graticule = !map.graticule; + assert!(!before.same(&MapLook::of(&map))); + } +} diff --git a/crates/map/src/raster.rs b/crates/map/src/raster.rs index 040dce3ff2..7b9ad8f57b 100644 --- a/crates/map/src/raster.rs +++ b/crates/map/src/raster.rs @@ -732,6 +732,57 @@ impl RasterLayer { Some(stats) } + /// What a frame draws it from ([`crate::look`]): its settings and its pixels' allocation, which + /// doesn't keep them. `None` when drawing reads more than it holds: read in place (the part in + /// view is read as the map draws), still being read, or lit by cast shadows or sky worked out + /// in the background. + pub fn look(&self) -> Option { + let RasterLayer { + path, + in_place, + // Read into `data`, compared itself. + file_name: _, + embedded: _, + subdataset, + crs, + time_zarr, + placement, + style, + data, + // What it says, not what it draws. + error: _, + // Worked out from the pixels and the style. + masked: _, + cast: _, + opening, + read_still, + read_generation: _, + restyle, + look, + pixels_said: _, + error_said: _, + failed_at: _, + failures: _, + lost_said: _, + look_lost: _, + dropped: _, + } = self; + if *in_place || opening.is_some() || read_still.is_some() || self.casts_shadows() { + return None; + } + Some(RasterLook { + path: path.clone(), + subdataset: subdataset.clone(), + crs: crs.clone(), + time_zarr: time_zarr.clone(), + placement: *placement, + style: style.clone(), + restyle: *restyle, + look: look.clone(), + data: Arc::downgrade(data.as_ref()?), + }) + } + /// Whether it is drawn with cast shadows or sky visibility (Shaded Relief with a shadow or a /// sky above 0): its frames are drawn again as they land (see [`RasterLayer::cast_shadows`]). pub fn casts_shadows(&self) -> bool { @@ -1687,6 +1738,37 @@ fn one() -> f64 { 1.0 } +/// What a frame draws a raster layer from ([`RasterLayer::look`]). +#[derive(Clone, Debug)] +pub struct RasterLook { + path: Option, + subdataset: Option, + crs: Option, + time_zarr: Option, + placement: Option<[f64; 4]>, + style: RasterStyle, + restyle: bool, + look: Option, + /// The pixels, by allocation. + data: Weak, +} + +impl RasterLook { + /// Whether `other` draws as this did. + pub fn same(&self, other: &RasterLook) -> bool { + let RasterLook { path, subdataset, crs, time_zarr, placement, style, restyle, look, data } = self; + *path == other.path + && *subdataset == other.subdataset + && *crs == other.crs + && *time_zarr == other.time_zarr + && placement.map(|p| p.map(f64::to_bits)) == other.placement.map(|p| p.map(f64::to_bits)) + && *style == other.style + && *restyle == other.restyle + && *look == other.look + && Weak::ptr_eq(data, &other.data) + } +} + /// The look an address gives a GeoTIFF read in place (`…/scene.tif#bands=5,3,2&range=0,3000`, as /// tile layers kept it): the bands drawn (from 0; one in grey, or red, green and blue) and a fixed /// stretch. From d288d161a8cd9bcd66e645e8f5054668cfbe7abc Mon Sep 17 00:00:00 2001 From: mavrick Date: Fri, 20 Nov 2026 11:32:12 -0600 Subject: [PATCH 2/8] fix(map): compare the system a dataset holds its coordinates in (#1057) A dataset's coordinates can now be held in a system of their own (held_in, #2514); a layer's look compares it, as drawing projects from it. Co-Authored-By: Claude Opus 5.5 --- crates/map/src/look.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/map/src/look.rs b/crates/map/src/look.rs index 6c63e0c691..f5a11075ce 100644 --- a/crates/map/src/look.rs +++ b/crates/map/src/look.rs @@ -191,7 +191,7 @@ fn same_time(a: Option<&crate::time::TimeBinding>, b: Option<&crate::time::TimeB /// Whether two datasets hold what a frame draws alike, their rows aside (compared by allocation). fn same_dataset(a: &Dataset, b: &Dataset) -> bool { - let Dataset { name, geometry_type, fields, features: _, source, crs, crs_incomplete, zm_dropped, windowed } = a; + let Dataset { name, geometry_type, fields, features: _, source, crs, crs_incomplete, zm_dropped, windowed, held_in } = a; *name == b.name && *geometry_type == b.geometry_type && *fields == b.fields @@ -200,6 +200,7 @@ fn same_dataset(a: &Dataset, b: &Dataset) -> bool { && *crs_incomplete == b.crs_incomplete && *zm_dropped == b.zm_dropped && *windowed == b.windowed + && *held_in == b.held_in } /// What a frame draws from a map apart from its layers: its basemap, tile layers, groups, From 8aecd9056140d4a581bf98a5ac6dc9362e874e98 Mon Sep 17 00:00:00 2001 From: mavrick Date: Fri, 20 Nov 2026 12:11:49 -0600 Subject: [PATCH 3/8] perf(map): a map's look keeps nothing it doesn't compare (#1057) Bookmarks, the thumbnail and animation keyframes aren't compared, so the look no longer copies them for each frame. Co-Authored-By: Claude Opus 5.5 --- crates/map/src/look.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/crates/map/src/look.rs b/crates/map/src/look.rs index f5a11075ce..786dd26b00 100644 --- a/crates/map/src/look.rs +++ b/crates/map/src/look.rs @@ -223,7 +223,8 @@ impl MapLook { basemap, tiles, camera, - bookmarks, + // Not compared (see `same`), so not kept. + bookmarks: _, graticule, graticule_type, graticule_crs, @@ -235,8 +236,8 @@ impl MapLook { editing, swipe, view, - thumbnail, - animation, + thumbnail: _, + animation: _, time, body, next_layer_id, @@ -252,7 +253,7 @@ impl MapLook { basemap: *basemap, tiles: tiles.clone(), camera: *camera, - bookmarks: bookmarks.clone(), + bookmarks: Vec::new(), graticule: *graticule, graticule_type: *graticule_type, graticule_crs: graticule_crs.clone(), @@ -264,8 +265,8 @@ impl MapLook { editing: editing.clone(), swipe: *swipe, view: view.clone(), - thumbnail: thumbnail.clone(), - animation: animation.clone(), + thumbnail: None, + animation: Vec::new(), time: time.clone(), body: body.clone(), next_layer_id: *next_layer_id, From 09d35294246b5d35c7e89944a479b8736075024e Mon Sep 17 00:00:00 2001 From: mavrick Date: Fri, 20 Nov 2026 12:28:10 -0600 Subject: [PATCH 4/8] fix(map): a layer's longitude/latitude copy is a cache, left out of its look (#1057) Co-Authored-By: Claude Opus 5.5 --- crates/map/src/look.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/map/src/look.rs b/crates/map/src/look.rs index 786dd26b00..35668115e4 100644 --- a/crates/map/src/look.rs +++ b/crates/map/src/look.rs @@ -131,6 +131,7 @@ impl LayerLook { projected_rev: _, projected_for: _, projected_crs: _, + lonlat: _, view_memory: _, geometry_kinds: _, geometry_rev, From 40d8fcf7c1f2a9543af81a53814cdadcf4dd8140 Mon Sep 17 00:00:00 2001 From: mavrick Date: Fri, 20 Nov 2026 12:34:28 -0600 Subject: [PATCH 5/8] perf(map): the map's look copies no field it leaves uncompared (#1057) The offline area, service groups and editing settings aren't compared, so they aren't copied either; the module says the renderer compares looks by place in the drawing order. Co-Authored-By: Claude Opus 5.5 --- crates/map/src/look.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/crates/map/src/look.rs b/crates/map/src/look.rs index 35668115e4..85dc0714e7 100644 --- a/crates/map/src/look.rs +++ b/crates/map/src/look.rs @@ -1,7 +1,8 @@ //! What a frame draws a map and each of its layers from, kept to tell whether a picture drawn //! earlier still shows them (#1057). A renderer keeps a [`LayerLook`] for each layer it drew and //! a [`MapLook`] for the rest of the map, and draws again only from the first layer whose look -//! no longer matches. +//! no longer matches. Neither look records where a layer is in the drawing order: the renderer +//! compares them place by place, each with its layer's id. //! //! A look is compared field by field, with every field of [`Layer`] and [`Map`] named, so a field //! added later has to be placed: drawn (compared) or not (left out with a reason). Rows are @@ -217,9 +218,9 @@ impl MapLook { pub fn of(map: &Map) -> MapLook { let Map { name, - offline_area_id, + offline_area_id: _, layers: _, - service_groups, + service_groups: _, groups, basemap, tiles, @@ -234,7 +235,7 @@ impl MapLook { label_display, label_lock, label_lock_line_anchors, - editing, + editing: _, swipe, view, thumbnail: _, @@ -247,9 +248,9 @@ impl MapLook { MapLook { map: Map { name: name.clone(), - offline_area_id: offline_area_id.clone(), + offline_area_id: None, layers: Vec::new(), - service_groups: service_groups.clone(), + service_groups: Vec::new(), groups: groups.clone(), basemap: *basemap, tiles: tiles.clone(), @@ -263,7 +264,7 @@ impl MapLook { label_display: *label_display, label_lock: label_lock.clone(), label_lock_line_anchors: label_lock_line_anchors.clone(), - editing: editing.clone(), + editing: Default::default(), swipe: *swipe, view: view.clone(), thumbnail: None, From 9699ed082e71d64a24fd3dd92587fe2f879ad63e Mon Sep 17 00:00:00 2001 From: mavrick Date: Fri, 20 Nov 2026 13:18:21 -0600 Subject: [PATCH 6/8] fix(map): a group shown closed in the Layers pane leaves the map's look (#1057) Groups are compared field by field without `expanded`, as a layer's own is left out. Co-Authored-By: Claude Opus 5.5 --- crates/map/src/lib.rs | 2 +- crates/map/src/look.rs | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/crates/map/src/lib.rs b/crates/map/src/lib.rs index 4c2b4ef001..9807763084 100644 --- a/crates/map/src/lib.rs +++ b/crates/map/src/lib.rs @@ -1577,7 +1577,7 @@ pub const MAX_GROUP_DEPTH: usize = 8; /// ordinary layers, kept together in the drawing order; a layer belongs to one group at most. /// A group may sit in another (#836, `parent`): its layers, and its subgroups' at any depth, /// stay together in the drawing order, and every group above it applies too. -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct LayerGroup { pub id: u32, pub name: String, diff --git a/crates/map/src/look.rs b/crates/map/src/look.rs index 85dc0714e7..14d484c403 100644 --- a/crates/map/src/look.rs +++ b/crates/map/src/look.rs @@ -205,6 +205,20 @@ fn same_dataset(a: &Dataset, b: &Dataset) -> bool { && *held_in == b.held_in } +/// Whether two layer groups apply alike to their layers: whether the Layers pane shows a group +/// open doesn't change the map. +fn same_group(a: &crate::LayerGroup, b: &crate::LayerGroup) -> bool { + let crate::LayerGroup { id, name, visible, expanded: _, transparency, min_scale, max_scale, children, parent } = a; + *id == b.id + && *name == b.name + && *visible == b.visible + && transparency.to_bits() == b.transparency.to_bits() + && *min_scale == b.min_scale + && *max_scale == b.max_scale + && *children == b.children + && *parent == b.parent +} + /// What a frame draws from a map apart from its layers: its basemap, tile layers, groups, /// projection, view settings and the rest (see the module). #[derive(Clone, Debug)] @@ -313,7 +327,8 @@ impl MapLook { instance_id, } = &self.map; *name == map.name - && *groups == map.groups + && groups.len() == map.groups.len() + && groups.iter().zip(&map.groups).all(|(a, b)| same_group(a, b)) && *basemap == map.basemap && *tiles == map.tiles && *camera == map.camera @@ -453,6 +468,26 @@ mod tests { map.bookmarks.push(Bookmark { name: "home".into(), camera: map.camera, description: String::new() }); map.add_layer(layer()); assert!(before.same(&MapLook::of(&map)), "bookmarks and layers aren't part of the map's own look"); + map.groups.push(crate::LayerGroup { + id: 1, + name: "g".into(), + visible: true, + expanded: true, + transparency: 0.0, + min_scale: None, + max_scale: None, + children: Vec::new(), + parent: None, + }); + let grouped = MapLook::of(&map); + if let Some(g) = map.groups.first_mut() { + g.expanded = false; + } + assert!(grouped.same(&MapLook::of(&map)), "a group shown closed in the Layers pane draws the same"); + if let Some(g) = map.groups.first_mut() { + g.visible = false; + } + assert!(!grouped.same(&MapLook::of(&map))); map.graticule = !map.graticule; assert!(!before.same(&MapLook::of(&map))); } From 29e63e1f69c9f23972b0a26be4145a0909c61b22 Mon Sep 17 00:00:00 2001 From: mavrick Date: Fri, 20 Nov 2026 13:59:15 -0600 Subject: [PATCH 7/8] fix(map): a look keeps no save-back state (#1057) A layer's database or GeoPackage edit state holds per-row versions, which aren't drawn: the look drops it with the rows. Co-Authored-By: Claude Opus 5.5 --- crates/map/src/look.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/map/src/look.rs b/crates/map/src/look.rs index 14d484c403..ca3339536f 100644 --- a/crates/map/src/look.rs +++ b/crates/map/src/look.rs @@ -51,7 +51,8 @@ impl LayerLook { None => None, }; let rows = layer.dataset.features.allocation_key(); - let mut kept = Layer { raster: None, ..layer.clone() }; + // Saving back to a database or GeoPackage keeps per-row versions, which aren't drawn. + let mut kept = Layer { raster: None, postgis: None, gpkg: None, synced: None, ..layer.clone() }; kept.dataset.features = Default::default(); kept.clear_cache(); // What these share with the layer could hold its rows: a time binding keeps the rows its From e7212b215083f595cd1be05e73bcbb11ddfcf39b Mon Sep 17 00:00:00 2001 From: mavrick Date: Fri, 20 Nov 2026 14:45:38 -0600 Subject: [PATCH 8/8] fix(map): a look keeps no archived edits (#1057) Edit archiving keeps whole features from before and after each edit; they aren't drawn, so the look drops them. Co-Authored-By: Claude Opus 5.5 --- crates/map/src/look.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/map/src/look.rs b/crates/map/src/look.rs index ca3339536f..65437a452a 100644 --- a/crates/map/src/look.rs +++ b/crates/map/src/look.rs @@ -63,6 +63,8 @@ impl LayerLook { bare }); kept.view_memory = Default::default(); + // Edit archiving keeps whole features from before and after each edit, which aren't drawn. + kept.design.archive = layer.design.archive.as_ref().map(|_| Vec::new()); kept.geometry_kinds = Default::default(); Some(LayerLook { layer: kept, rows, raster }) } @@ -455,6 +457,15 @@ mod tests { drop(held); } + #[test] + fn a_look_keeps_no_archived_edits() { + let mut l = layer(); + let edit = l.dataset.features.first().cloned(); + l.design.archive = Some(vec![crate::design::ArchiveEntry { time: 0.0, id: 1, before: edit.clone(), after: edit }]); + let look = LayerLook::of(&l).expect("a look"); + assert_eq!(look.layer.design.archive, Some(Vec::new())); + } + #[test] fn a_layer_drawn_from_more_than_it_holds_has_no_look() { let mut l = layer();