Skip to content
Open
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
14 changes: 7 additions & 7 deletions crates/engine/src/cmd/labels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ pub fn commands() -> Vec<C> {
};
let weight_asked = weight.filter(|w| w.fract() != 0.0 || !rustgis_map::symbology::LABEL_WEIGHT.contains(w));
let weight = weight.map(rustgis_map::symbology::label_weight);
// How much labels keep off the layer's points (#3526): 0 to 10, null back to 0. A
// How much labels keep off the layer's points or lines (#3526, #3613): 0 to 10, null back to 0. A
// number out of range or a fraction is held to a whole one, and says so.
let obstacle = match p.get("obstacleWeight") {
None => None,
Expand Down Expand Up @@ -287,15 +287,15 @@ pub fn commands() -> Vec<C> {
let layer = s.map().layer(id).ok_or("no such layer")?;
let held = held_geometries(layer);
let (points, lines, _) = held;
// On a layer whose points aren't obstacles it would do nothing; off is taken anywhere.
// On a layer whose points or lines aren't obstacles it would do nothing; off is taken anywhere.
// The rule is the layer's, shared with the Labeling pane's row.
if obstacle.is_some_and(|w| w > 0) && !layer.takes_obstacle_weight() {
return Err(if !points {
"obstacleWeight is for layers with points: lines and polygons aren't obstacles yet"
return Err(if !points && !lines {
"obstacleWeight is for layers with points or lines: polygons aren't obstacles yet"
} else if layer.graphics {
"obstacleWeight isn't for a graphics layer: its points are text and images, which draw no obstacle"
"obstacleWeight isn't for a graphics layer: its elements are no obstacle"
} else {
"obstacleWeight isn't for a cluster or heat map layer: it draws no points"
"obstacleWeight isn't for a cluster or heat map layer: it draws no points or lines"
}
.into());
}
Expand Down Expand Up @@ -468,7 +468,7 @@ pub fn commands() -> Vec<C> {
.inputs(super::Inputs::single_layer)
.when(need_feature_layer)
.params(
r#"{"layer"?, "class"?: name (none: the Default class, by whatever name it has), "position"?: "auto"|"center"|"above"|"below"|"left"|"right"|"aboveRight"|"aboveLeft"|"belowRight"|"belowLeft"|"parallel" (along a line, straight)|"curved" (along a line, following its bends)|"perpendicular" (a point's, square to the nearest line of `to`, starting at the point; none that near: as auto) (required without offset, repeat, lineOffset, otherPositions, showAll, weight, obstacleWeight, clearance, removeDuplicates, callout, to, side, fit, abbreviations or guide), "to"?: {"layer": a line or polygon layer's name, "within"?: points (1 to 500; 20)} | null, "side"?: "away" (the side of the line the point isn't on; the default)|"left"|"right" (as the line runs), "offset"?: [right, down] points (-200 to 200 each) the label moves from where its position puts it ([0, 0]: none; perpendicular: [out along the normal, down as the text reads]; a label along a line isn't moved), "repeat"?: points (10 to 10000) between a line's labels, spaced out from the one at its middle, at most 32 a line (0 or null: the one at its middle; parallel and curved only), "lineOffset"?: points (-200 to 200) between a line and its label's nearest edge, above the line as the text reads, negative below it (0 or null: on the line; parallel and curved only), "otherPositions"?: bool (a label whose place is taken tries others: a point's round the point, corners first; a line's along the line, nearest its middle first, placed parallel or curved without a repeat; a polygon's goes first where its shape fits best inside it, then where it goes without this; then, if its text fits the box of the polygon on the screen, up to 16 places further inside, a text box from the first and then two, corners first, where all of it is inside and in view, or else round that box, corners first; true is refused for any other line label, and on polygons for a curved label or one along a guide), "fit"?: "auto"|"off" (curved along a line: "auto" abbreviates a name that can't follow the line, sets one longer than a third of it on its straightest stretch, and spreads one over labels.style's stretch of a line more than three times its length; "off" or null: as placed), "abbreviations"?: {word: abbreviation} (whole words a fitted label puts short, ignoring case, over the built-in English, Portuguese and Spanish list, as {"Creek": "Cr.", "Córrego": "Cór."}; null or {}: the built-in list alone), "showAll"?: bool (every label drawn, over the others where they crowd), "weight"?: 0 to 10 (where labels compete for a place, the heavier class's wins, whatever its layer's place; equal weights: the layer above, then the class listed first; a fraction rounded; null: 5), "obstacleWeight"?: 0 to 10 (the layer's, for layers with points, whatever class is named: a label whose class's weight isn't above it isn't placed over one of the layer's points, its own feature's aside; labels moved by hand go where they were put; a fraction rounded; 0 or null: no obstacle), "clearance"?: points (0 to 100: the room the class's labels keep free of other labels, two labels keeping both their clearances apart; null: 2), "removeDuplicates"?: points (1 to 2000: a label is left out within this distance of one placed before it for another feature of its layer and class with the same text; a label moved by hand always shows; false or null: off), "callout"?: true|false|points (5 to 500: a label crowded off its spot moves to a free one nearby, a line drawn back to its feature at most this long; true keeps its length, or 40; false, 0 or null: none; not labels along a line or with an icon), "guide"?: {"layer": a line layer's name (as ridge or valley lines; not drawn by this), "field"?: a field both layers have} | null (points and polygons, not perpendicular ones: each label curved along its guide line, the one with the feature's value in field, else the longest in view under the label inside its polygon, or the nearest to its point within the text's width; a feature with none its text fits along is labelled as without a guide; null: none)}"#,
r#"{"layer"?, "class"?: name (none: the Default class, by whatever name it has), "position"?: "auto"|"center"|"above"|"below"|"left"|"right"|"aboveRight"|"aboveLeft"|"belowRight"|"belowLeft"|"parallel" (along a line, straight)|"curved" (along a line, following its bends)|"perpendicular" (a point's, square to the nearest line of `to`, starting at the point; none that near: as auto) (required without offset, repeat, lineOffset, otherPositions, showAll, weight, obstacleWeight, clearance, removeDuplicates, callout, to, side, fit, abbreviations or guide), "to"?: {"layer": a line or polygon layer's name, "within"?: points (1 to 500; 20)} | null, "side"?: "away" (the side of the line the point isn't on; the default)|"left"|"right" (as the line runs), "offset"?: [right, down] points (-200 to 200 each) the label moves from where its position puts it ([0, 0]: none; perpendicular: [out along the normal, down as the text reads]; a label along a line isn't moved), "repeat"?: points (10 to 10000) between a line's labels, spaced out from the one at its middle, at most 32 a line (0 or null: the one at its middle; parallel and curved only), "lineOffset"?: points (-200 to 200) between a line and its label's nearest edge, above the line as the text reads, negative below it (0 or null: on the line; parallel and curved only), "otherPositions"?: bool (a label whose place is taken tries others: a point's round the point, corners first; a line's along the line, nearest its middle first, placed parallel or curved without a repeat; a polygon's goes first where its shape fits best inside it, then where it goes without this; then, if its text fits the box of the polygon on the screen, up to 16 places further inside, a text box from the first and then two, corners first, where all of it is inside and in view, or else round that box, corners first; true is refused for any other line label, and on polygons for a curved label or one along a guide), "fit"?: "auto"|"off" (curved along a line: "auto" abbreviates a name that can't follow the line, sets one longer than a third of it on its straightest stretch, and spreads one over labels.style's stretch of a line more than three times its length; "off" or null: as placed), "abbreviations"?: {word: abbreviation} (whole words a fitted label puts short, ignoring case, over the built-in English, Portuguese and Spanish list, as {"Creek": "Cr.", "Córrego": "Cór."}; null or {}: the built-in list alone), "showAll"?: bool (every label drawn, over the others where they crowd), "weight"?: 0 to 10 (where labels compete for a place, the heavier class's wins, whatever its layer's place; equal weights: the layer above, then the class listed first; a fraction rounded; null: 5), "obstacleWeight"?: 0 to 10 (the layer's, for layers with points or lines, whatever class is named: a label whose class's weight isn't above it isn't placed over one of the layer's points or lines, its own feature's aside; labels moved by hand go where they were put; a fraction rounded; 0 or null: no obstacle), "clearance"?: points (0 to 100: the room the class's labels keep free of other labels, two labels keeping both their clearances apart; null: 2), "removeDuplicates"?: points (1 to 2000: a label is left out within this distance of one placed before it for another feature of its layer and class with the same text; a label moved by hand always shows; false or null: off), "callout"?: true|false|points (5 to 500: a label crowded off its spot moves to a free one nearby, a line drawn back to its feature at most this long; true keeps its length, or 40; false, 0 or null: none; not labels along a line or with an icon), "guide"?: {"layer": a line layer's name (as ridge or valley lines; not drawn by this), "field"?: a field both layers have} | null (points and polygons, not perpendicular ones: each label curved along its guide line, the one with the feature's value in field, else the longest in view under the label inside its polygon, or the nearest to its point within the text's width; a feature with none its text fits along is labelled as without a guide; null: none)}"#,
),
// Labels moved by hand (the Move Label tool, as QGIS's): kept by their feature's id.
C::new("labels.move", "Move Label", "Labeling › Label Placement", |s, p| {
Expand Down
2 changes: 1 addition & 1 deletion crates/engine/src/project_capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1829,7 +1829,7 @@ fn label_guide(layer: &Layer) -> bool {
layer.labels.in_order().any(|c| c.guide.is_some())
}

/// Whether a layer's points are obstacles for labels (#3526): an older reader would drop the
/// Whether a layer's points or lines are obstacles for labels (#3526, #3613): an older reader would drop the
/// weight, and place and save the labels as without it.
fn label_obstacle(layer: &Layer) -> bool {
layer.labels.obstacle_weight > 0
Expand Down
16 changes: 10 additions & 6 deletions crates/engine/src/tests/label_obstacles.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! A point layer's points as obstacles for labels (#3526): `labels.placement`'s `obstacleWeight`,
//! A point or line layer's points or lines as obstacles for labels (#3526, #3613): `labels.placement`'s `obstacleWeight`,
//! how it is saved, and what requires `label-obstacles`.

use super::*;
Expand Down Expand Up @@ -55,14 +55,18 @@ fn a_point_layer_takes_an_obstacle_weight() {
}

#[test]
fn only_a_layer_with_points_is_an_obstacle() {
fn only_a_layer_with_points_or_lines_is_an_obstacle() {
let mut s = world();
// A line layer takes it (#3613); a polygon layer doesn't yet.
let rivers = s.map().layer_by_name("Rivers").unwrap().id;
let err = s.run("labels.placement", &json!({"layer": "Rivers", "obstacleWeight": 5})).unwrap_err();
assert!(err.to_string().contains("point"), "{err}");
assert_eq!(weight(&s, rivers), 0);
s.run("labels.placement", &json!({"layer": "Rivers", "obstacleWeight": 5})).unwrap();
assert_eq!(weight(&s, rivers), 5);
let countries = s.map().layer_by_name("Countries").unwrap().id;
let err = s.run("labels.placement", &json!({"layer": "Countries", "obstacleWeight": 5})).unwrap_err();
assert!(err.to_string().contains("polygons"), "{err}");
assert_eq!(weight(&s, countries), 0);
// Off is taken anywhere.
s.run("labels.placement", &json!({"layer": "Rivers", "obstacleWeight": 0})).unwrap();
s.run("labels.placement", &json!({"layer": "Countries", "obstacleWeight": 0})).unwrap();
// A graphics layer's points are its text and images, a cluster's or heat map's aren't drawn:
// no obstacle either, so it isn't taken only to do nothing.
let cities = s.map().layer_by_name("Cities").unwrap().id;
Expand Down
9 changes: 6 additions & 3 deletions crates/map/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1414,11 +1414,14 @@ impl Layer {
kind != GeometryType::None && (self.geometry_type() == kind || self.geometry_kinds.contains(&self.dataset.features, kind))
}

/// Whether the layer's points can be obstacles for labels (#3526): it has points, draws them
/// (not a graphics, cluster or heat map layer), so an obstacle weight above 0 means something.
/// Whether the layer's points or lines can be obstacles for labels (#3526, #3613): it has
/// some, draws them (not a graphics, cluster or heat map layer), so an obstacle weight above 0
/// means something.
/// The one rule for `labels.placement`'s `obstacleWeight` and the Labeling pane's row.
pub fn takes_obstacle_weight(&self) -> bool {
!self.graphics && self.aggregation.is_none() && self.has_geometry(GeometryType::Point)
!self.graphics
&& self.aggregation.is_none()
&& (self.has_geometry(GeometryType::Point) || self.has_geometry(GeometryType::Polyline))
}

/// Copies of every geometry in a map projection's coordinates (`key` names the projection),
Expand Down
2 changes: 1 addition & 1 deletion crates/map/src/symbology.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2958,7 +2958,7 @@ pub struct Labeling {
pub default: LabelClass,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub classes: Vec<LabelClass>,
/// How much labels keep off this layer's points (#3526): a label whose class's weight isn't
/// How much labels keep off this layer's points or lines (#3526, #3613): a label whose class's weight isn't
/// above it isn't placed over one. 0 to 10; 0: the layer is no obstacle. The layer's, not a
/// class's, and in force with its labels off too.
#[serde(default, skip_serializing_if = "is_no_obstacle")]
Expand Down
4 changes: 2 additions & 2 deletions crates/render/src/approximations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ pub(crate) fn walls_left_plain(name: &str, n: usize) {
);
}

/// Counts `n` of layer `name`'s points in view left out of the obstacles for labels (#3526), as a
/// Counts `n` of layer `name`'s points (or lines) in view left out of the obstacles for labels (#3526), as a
/// frame holds only as many as memory allows. The count is of the layer's chunks and of a tilted
/// view's bands together: said when what frames approximated is taken ([`flush_obstacles_left`]).
pub(crate) fn obstacles_left_out(name: &str, n: usize) {
Expand Down Expand Up @@ -358,7 +358,7 @@ fn flush_obstacles_left() {
note(
format!("{name}\0obstacles"),
format!(
"{name}: {n} points in view aren't kept off by labels, as a frame holds only as many obstacles as memory allows; zoom in or filter the layer"
"{name}: {n} points or lines in view aren't kept off by labels, as a frame holds only as many obstacles as memory allows; zoom in or filter the layer"
),
);
}
Expand Down
Loading
Loading