Skip to content
Merged
6 changes: 6 additions & 0 deletions crates/map/src/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,12 @@ impl Projector {
self.engine.to_lonlat(m).filter(|c| c.y.abs() <= 90.0 + 1e-9)
}

/// Which way its map coordinates point
/// ([`rustgis_data::raster::Transformer::axis_directions`]): east, then north, for most.
pub fn axis_directions(&self) -> [(f64, f64); 2] {
self.engine.axis_directions()
}

pub fn to_meter(&self) -> f64 {
self.to_meter
}
Expand Down
24 changes: 15 additions & 9 deletions crates/ui-egui/src/coordreadout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,20 @@ fn layer_conversion(crs: rustgis_engine::data::raster::Crs) -> Option<rustgis_en
Some(t)
}

/// The name of a projected system's unit by the metres in it: `m`, `ft` (international feet),
/// `ftUS` (US survey feet), else none.
pub(crate) fn unit_of(to_meter: f64) -> &'static str {
if (to_meter - 1.0).abs() < 1e-9 {
"m"
} else if (to_meter - 0.3048).abs() < 1e-9 {
"ft"
} else if (to_meter - 1200.0 / 3937.0).abs() < 1e-9 {
"ftUS"
} else {
""
}
}

/// How a system gives a place's coordinates from its longitude and latitude.
enum Plane {
/// A map's flat projection, as the map draws it (Web Mercator's too, for a layer in it).
Expand Down Expand Up @@ -257,15 +271,7 @@ impl MapSystem {
Plane::Flat(Flat::Custom(p)) => p.to_meter(),
Plane::Data(_, to_meter) => *to_meter,
};
let unit = if (to_meter - 1.0).abs() < 1e-9 {
"m"
} else if (to_meter - 0.3048).abs() < 1e-9 {
"ft"
} else if (to_meter - 1200.0 / 3937.0).abs() < 1e-9 {
"ftUS"
} else {
""
};
let unit = unit_of(to_meter);
// Rounded first, then + 0.0: a coordinate that rounds to zero reads 0, not -0.
let scale = 10f64.powi(decimals as i32);
let shown = |v: f64| (v * scale).round() / scale + 0.0;
Expand Down
Loading
Loading