Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/engine/command-surface.txt
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ layer.addDataText fileName text name? x? y? wkt? crs? delimiter? layer? paperSpa
layer.addDatabase database password? layer? crs? name? stream?
layer.addDownload id url name? layer? zoom? x? y? wkt? crs? delimiter? paperSpace? blocks? stream? as? service? bounds? coverage? coverageCrs? drawingInfo? geolibreProject? geolibreLayer? geolibreZarr? connection? anonymous? request? window?
layer.addEncodedPolyline polyline precision? name?
layer.addLayerFile path? text? data?
layer.addLayerFile path? text? data? group? to?
layer.addPhotos paths? folder? name?
layer.addSample name
layer.addSql sql name? database? password? crs? stream? ran?
Expand Down
368 changes: 368 additions & 0 deletions crates/engine/src/cmd/group_file.rs

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions crates/engine/src/cmd/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,16 @@ pub fn commands() -> Vec<C> {
C::new("layer.addLayerFile", "Add Layer File", "Home › Add", |s, p| {
let text = read_text(p)?;
let reach = s.file_reach(p);
// A file holding a group places it as Paste Layers does (#2870).
if super::group_file::holds_group(&text) {
return super::group_file::add_within(s, &text, reach, p);
}
if ["group", "to"].iter().any(|k| p.get(k).is_some_and(|v| !v.is_null())) {
return Err("group and to place the layers of a layer file that holds a group; this one holds one layer".into());
}
super::layer::add_layer_text_within(s, &text, reach)
}).roles(&[]).effects(crate::policy::Effects::NONE.with(crate::policy::Effect::Files))
.params(r#"{"path"?: "*.rgislyr", "text"?: layer file JSON, "data"?: base64 file}"#),
.params(r#"{"path"?: "*.rgislyr", "text"?: layer file JSON, "data"?: base64 file, "group"?: name|id (a file holding a group: into that group, at its top), "to"?: position (a file holding a group: 0 = top, the default)}"#),
// Styles.
C::new("style.new", "New Style", "Style › Styles", |s, p| {
let id = s.layer_id(p)?;
Expand Down Expand Up @@ -718,7 +725,9 @@ fn add_file_styles(s: &mut Session, what: &str, items: Vec<StyleItem>) -> usize
fn import_styles(s: &mut Session, p: &Value) -> CmdResult {
let text = read_text(p)?;
crate::project::check_format(&text, "layer file, map file or project")?;
let layers: Vec<Layer> = if let Ok(l) = serde_json::from_str::<Layer>(&text) {
let layers: Vec<Layer> = if super::group_file::holds_group(&text) {
super::group_file::layers_for_styles(s, &text)?
} else if let Ok(l) = serde_json::from_str::<Layer>(&text) {
for notice in crate::project::label_losses::layer_notices(&text, &l, false) {
s.notify(notice, false);
}
Expand Down
33 changes: 22 additions & 11 deletions crates/engine/src/cmd/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4737,6 +4737,9 @@ pub(crate) fn add_layer_text(s: &mut Session, text: &str) -> CmdResult {
/// ([`Session::file_reach`]).
pub(crate) fn add_layer_text_within(s: &mut Session, text: &str, reach: crate::render::rustgis_tiles::address::Reach) -> CmdResult {
crate::project::check_format(text, "layer file")?;
if super::group_file::holds_group(text) {
return super::group_file::add_within(s, text, reach, &Value::Null);
}
let mut layer: rustgis_map::Layer = serde_json::from_str(text).map_err(|e| format!("not a RustGIS layer file: {e}"))?;
if layer.dataset.source.as_deref().is_some_and(|source| source.starts_with("geolibre-pending:")) {
return Err("a layer file cannot contain runtime GeoLibre download reservations".into());
Expand All @@ -4761,31 +4764,39 @@ pub(crate) fn add_layer_text_within(s: &mut Session, text: &str, reach: crate::r
layer.name = format!("{base} ({i})");
}
let id = s.map_mut().add_layer(layer);
settle_added(s, &[id]);
s.active_layer = Some(id);
Ok(json!({"layer": id}))
}

/// Settles layers `ids` just added to the map in view from a layer file: the project repaired
/// around them, the databases they read resolved, and what reading their rasters left out said.
pub(crate) fn settle_added(s: &mut Session, ids: &[u32]) {
super::connections::clear_active();
for notice in s.project.normalize_text() {
s.notify_text(notice, false);
}
super::connections::restore_active(s);
s.wait_in_place_reads();
super::project::say_conversion_fallbacks(s);
// Only the database the added layer reads can change here.
let keys: Vec<_> = s.map().layer(id).and_then(|l| l.source.as_ref()).map(super::connections::layer_keys).unwrap_or_default();
// Only the databases the added layers read can change here.
let m = s.map();
let keys: Vec<_> = ids.iter().filter_map(|id| m.layer(*id)?.source.as_ref()).flat_map(super::connections::layer_keys).collect();
super::connections::resolve_keys(s, &keys);
crate::s3_connections::resolve_project_s3(s);
super::connections::note_waiting(s);
s.active_layer = Some(id);
// What reading its raster left out is said, as for a raster added (one still read in the
// What reading their rasters left out is said, as for a raster added (one still read in the
// background isn't here yet).
let lost: Vec<rustgis_data::loss::Note> = s
.map()
.layer(id)
.and_then(|l| Some((&l.name, l.raster.as_ref()?.data.as_ref()?)))
.map(|(name, d)| d.lost.iter().map(|l| l.clone().prefixed(name)).collect())
.unwrap_or_default();
let m = s.map();
let lost: Vec<rustgis_data::loss::Note> = ids
.iter()
.filter_map(|id| m.layer(*id))
.filter_map(|l| Some((&l.name, l.raster.as_ref()?.data.as_ref()?)))
.flat_map(|(name, d)| d.lost.iter().map(|l| l.clone().prefixed(name)))
.collect();
for l in lost {
s.say(l);
}
Ok(json!({"layer": id}))
}

/// The most polylines added at once.
Expand Down
58 changes: 43 additions & 15 deletions crates/engine/src/cmd/layer_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ fn unique_group_name(m: &Map, name: &str) -> (String, bool) {

/// What a paste added, as its notice says it: "2 layers", "1 group and 3 layers", "1 group" (an
/// empty group copied).
fn pasted_what(layers: usize, groups: usize) -> String {
pub(crate) fn pasted_what(layers: usize, groups: usize) -> String {
let count = |n: usize, one: &str, many: &str| if n == 1 { format!("1 {one}") } else { format!("{n} {many}") };
match (groups, layers) {
(0, n) => count(n, "layer", "layers"),
Expand All @@ -113,6 +113,47 @@ fn pasted_what(layers: usize, groups: usize) -> String {
fn paste(s: &mut Session, p: &Value) -> CmdResult {
let clip = s.layer_clipboard.clone().ok_or("no layers have been copied")?;
let mi = super::navigate::map_at(s, p)?;
let placed = place(s, mi, clip, p)?;
// Said, as a paste from the Browser can go to a map out of view.
s.notify(format!("Pasted {} into {}", pasted_what(placed.layers.len(), placed.groups.len()), placed.map), false);
placed.say(s, "Paste Layers");
Ok(json!({"map": placed.map, "layers": placed.layers, "groups": placed.groups, "unmasked": placed.unmasked}))
}

/// What [`place`] added: to which map, the layers' ids in drawing order, the groups' ids
/// (outermost first), the layers whose masks were cleared, and how many names were cut.
pub(crate) struct Placed {
pub map: String,
pub layers: Vec<u32>,
pub groups: Vec<u32>,
pub unmasked: Vec<String>,
names_cut: usize,
}

impl Placed {
/// Says the names cut and the masks lost, after the notice of what was added (`what`: the
/// command).
pub(crate) fn say(&self, s: &mut Session, what: &str) {
let (map, names_cut) = (&self.map, self.names_cut);
if names_cut > 0 {
s.notify(
format!("{what}: {names_cut} copied name(s) cut so \" copy\" and a number fit in {} characters", super::MAX_NAME),
false,
);
}
match self.unmasked.as_slice() {
[] => {}
[one] => s.notify(format!("{one} lost its mask: {map} has no polygon layer by that name"), false),
many => s.notify(format!("{} lost their masks: {map} has no polygon layers by those names", many.join(", ")), false),
}
}
}

/// Places `clip`'s layers and groups in map `mi` as Paste Layers does (#2870 shares it): into
/// `p`'s `"group"` at its top, or at its position `"to"` (the top by default); a name the map
/// has gets " copy", and a mask follows its layer when that came too ([`Placed::say`] says
/// what that changed).
pub(crate) fn place(s: &mut Session, mi: usize, clip: LayerClip, p: &Value) -> Result<Placed, String> {
let m = s.project.maps.get(mi).ok_or("no such map")?;
let into = match p.get("group") {
None | Some(Value::Null) => None,
Expand Down Expand Up @@ -213,20 +254,7 @@ fn paste(s: &mut Session, p: &Value) -> CmdResult {
{
s.active_layer = Some(*first);
}
// Said, as a paste from the Browser can go to a map out of view.
s.notify(format!("Pasted {} into {map}", pasted_what(pasted.len(), group_ids.len())), false);
if names_cut > 0 {
s.notify(
format!("Paste Layers: {names_cut} copied name(s) cut so \" copy\" and a number fit in {} characters", super::MAX_NAME),
false,
);
}
match unmasked.as_slice() {
[] => {}
[one] => s.notify(format!("{one} lost its mask: {map} has no polygon layer by that name"), false),
many => s.notify(format!("{} lost their masks: {map} has no polygon layers by those names", many.join(", ")), false),
}
Ok(json!({"map": map, "layers": pasted, "groups": group_ids, "unmasked": unmasked}))
Ok(Placed { map, layers: pasted, groups: group_ids, unmasked, names_cut })
}

/// Resolves explicit layer lists and expanded groups with copy's precise active-layer fallback.
Expand Down
1 change: 1 addition & 0 deletions crates/engine/src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub mod gp;
pub mod gpkg;
pub mod graphics;
pub mod group;
pub(crate) mod group_file;
pub mod history;
pub mod imagery;
#[cfg(not(target_arch = "wasm32"))]
Expand Down
1 change: 1 addition & 0 deletions crates/engine/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ pub const CAPABILITIES: &[&str] = &[
"layout-element-background",
SIZE_BY_CAPABILITY,
"picture-markers",
crate::cmd::group_file::LAYER_GROUP,
"graticule-mgrs",
"graticule-on-top",
"graticule-color",
Expand Down
44 changes: 33 additions & 11 deletions crates/engine/src/project_label_losses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,22 +519,25 @@ pub(crate) fn map_notices(text: &str, map: &rustgis_map::Map, diagrams: bool) ->
/// (matched by place, not by value), or on a perpendicular label (square to its line where one is
/// near).
fn unfollowed_guides<'a>(maps: impl Iterator<Item = &'a rustgis_map::Map>) -> Vec<(ReadPart, String)> {
unfollowed_guides_of(maps.flat_map(|m| m.layers.iter().map(move |l| (m, l))))
}

/// [`unfollowed_guides`] for the layers `labelled`, each with the map it is in.
fn unfollowed_guides_of<'a>(labelled: impl Iterator<Item = (&'a rustgis_map::Map, &'a rustgis_map::Layer)>) -> Vec<(ReadPart, String)> {
use rustgis_data::GeometryType;
let (mut streamed, mut missing, mut fields, mut square) = (Vec::new(), Vec::new(), Vec::new(), 0usize);
for map in maps {
for labelled in &map.layers {
for (c, g) in labelled.labels.in_order().filter_map(|c| Some((c, c.guide.as_ref()?))) {
match map.layer_by_name(&g.layer) {
Some(l) if l.source.is_some() => streamed.push(&g.layer),
Some(l) if l.has_geometry(GeometryType::Polyline) => {
if let Some(f) = g.field.as_ref().filter(|f| [l, labelled].iter().any(|l| l.dataset.field_index(f).is_none())) {
fields.push(f);
}
for (map, labelled) in labelled {
for (c, g) in labelled.labels.in_order().filter_map(|c| Some((c, c.guide.as_ref()?))) {
match map.layer_by_name(&g.layer) {
Some(l) if l.source.is_some() => streamed.push(&g.layer),
Some(l) if l.has_geometry(GeometryType::Polyline) => {
if let Some(f) = g.field.as_ref().filter(|f| [l, labelled].iter().any(|l| l.dataset.field_index(f).is_none())) {
fields.push(f);
}
_ => missing.push(&g.layer),
}
square += usize::from(c.placement == rustgis_map::LabelPlacement::Perpendicular);
_ => missing.push(&g.layer),
}
square += usize::from(c.placement == rustgis_map::LabelPlacement::Perpendicular);
}
}
let named = |mut v: Vec<&String>| {
Expand Down Expand Up @@ -568,6 +571,25 @@ fn unfollowed_guides<'a>(maps: impl Iterator<Item = &'a rustgis_map::Map>) -> Ve
notices.into_iter().map(|m| (ReadPart::Labels, m)).collect()
}

/// What the label guides of the layers `ids`, just added to `map` from a layer file holding a
/// group (#2870), can't follow there, as a map file's are audited.
pub(crate) fn added_guide_notices(map: &rustgis_map::Map, ids: &[u32]) -> Vec<String> {
let labelled = ids.iter().filter_map(|id| map.layer(*id)).map(|l| (map, l));
unfollowed_guides_of(labelled).into_iter().map(|(_, m)| m).collect()
}

/// The same audit for a layer file holding a group (#2870), whose `layers` are read as a map
/// file's are; `name` is the group's.
pub(crate) fn group_file_notices(text: &str, layers: &[rustgis_map::Layer], name: &str, diagrams: bool) -> Vec<String> {
let Ok(raw) = serde_json::from_str::<Map>(text) else { return only(hidden(layers.iter()), diagrams) };
let mut notices = count(raw.layers.iter(), layers.iter().map(|l| &l.labels), name, "the layer file");
if diagrams {
notices.extend(refused_reference_scales(raw.layers.iter()));
}
notices.extend(hidden(layers.iter()));
only(notices, diagrams)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}

/// The same audit for a layer file read on its own.
pub(crate) fn layer_notices(text: &str, layer: &rustgis_map::Layer, diagrams: bool) -> Vec<String> {
let Ok(raw) = serde_json::from_str::<Layer>(text) else { return only(hidden(std::iter::once(layer)), diagrams) };
Expand Down
4 changes: 4 additions & 0 deletions docs/maintaining.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ an older reader must refuse them rather than fail on the marker or lose it. Wher
is an SVG, they also require `svg-markers`: a reader of PNG and JPEG markers only would draw it
as a circle and refuse the command that sets it.

A layer file holding a group (#2870) lists `groups` and `layers` in place of the one layer and
requires `layer-group`, so a reader of one layer refuses it by that name rather than as damaged.
Add Layer File, Add Data and a drop place it as Paste Layers places a copied group.

Projects, model files and web tools that save a percent-slope function require `slope-percent`:
an older reader must refuse them rather than run the saved function in degrees. Project
requirements also cover executable task steps, replayable history and notebook command cells.
Expand Down
2 changes: 2 additions & 0 deletions schema/project.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,7 @@
"layout-element-background",
"classified-point-size",
"picture-markers",
"layer-group",
"graticule-mgrs",
"graticule-on-top",
"graticule-color",
Expand Down Expand Up @@ -1385,6 +1386,7 @@
"layout-element-background",
"classified-point-size",
"picture-markers",
"layer-group",
"graticule-mgrs",
"graticule-on-top",
"graticule-color",
Expand Down
Loading