summaryrefslogtreecommitdiff
path: root/crates/gipfel-web
diff options
context:
space:
mode:
Diffstat (limited to 'crates/gipfel-web')
-rw-r--r--crates/gipfel-web/src/app.rs41
-rw-r--r--crates/gipfel-web/src/canvas_view.rs17
-rw-r--r--crates/gipfel-web/src/markers.rs14
3 files changed, 55 insertions, 17 deletions
diff --git a/crates/gipfel-web/src/app.rs b/crates/gipfel-web/src/app.rs
index e4fd435..f4b0de4 100644
--- a/crates/gipfel-web/src/app.rs
+++ b/crates/gipfel-web/src/app.rs
@@ -5,7 +5,7 @@ use std::io::Read;
use std::rc::Rc;
use flate2::read::GzDecoder;
-use gipfel_core::hill::{FLAG_DUPLIC, FLAG_TRACK_POINT};
+use gipfel_core::hill::{FLAG_DUPLIC, FLAG_HIDDEN, FLAG_TRACK_POINT};
use gipfel_core::metadata::{apply_image_metadata, ImageMetaData};
use gipfel_core::panorama::Panorama;
use wasm_bindgen::closure::Closure;
@@ -161,6 +161,7 @@ pub fn app() -> Html {
let vp = use_state(UiParams::default);
let img_size = use_state(|| (0u32, 0u32));
let find_peak = use_state(|| Option::<FindPeak>::None);
+ let show_hidden = use_state(|| false);
// force a redraw when the window is resized so the canvas backing
// store tracks its CSS size (listener lives as long as the app)
@@ -441,6 +442,13 @@ pub fn app() -> Html {
vp.set(u);
})
};
+ let on_show_hidden = {
+ let show_hidden = show_hidden.clone();
+ Callback::from(move |e: Event| {
+ let input: HtmlInputElement = e.target_unchecked_into();
+ show_hidden.set(input.checked());
+ })
+ };
// compass strip: shares the image transform, drag changes azimuth
let compass_data = {
@@ -555,13 +563,14 @@ pub fn app() -> Html {
let mark = mark_peak.clone();
let find_peak = find_peak.clone();
let img_size = img_size.clone();
+ let show_hidden = show_hidden.clone();
Callback::from(move |(ix, iy): (f64, f64)| {
let scale = view.scale;
// unambiguous click right on a peak: mark directly
// (borrow must be released before mark -> do_refit!)
let near = {
let p = pan.borrow();
- markers::nearest_hill(&p, ix, iy, 10.0 / scale)
+ markers::nearest_hill(&p, ix, iy, 10.0 / scale, *show_hidden)
};
if let Some(idx) = near {
find_peak.set(None);
@@ -620,12 +629,14 @@ pub fn app() -> Html {
let pan = pan.clone();
let view = view.clone();
let hover = hover.clone();
+ let show_hidden = show_hidden.clone();
Callback::from(move |(ix, iy): (f64, f64)| {
let p = pan.borrow();
- let name = markers::nearest_hill(&p, ix, iy, 20.0 / view.scale).map(|i| {
- let h = &p.hills[i];
- format!("{} · {:.0} m", h.name, h.height)
- });
+ let name = markers::nearest_hill(&p, ix, iy, 20.0 / view.scale, *show_hidden)
+ .map(|i| {
+ let h = &p.hills[i];
+ format!("{} · {:.0} m", h.name, h.height)
+ });
hover.set(name);
})
},
@@ -647,9 +658,19 @@ pub fn app() -> Html {
})
.collect()
};
- let candidates: Vec<(f64, f64)> = {
+ let candidates: Vec<(f64, f64, bool)> = {
let p = pan.borrow();
- p.visible.iter().map(|&i| (p.hills[i].x, p.hills[i].y)).collect()
+ p.visible
+ .iter()
+ .filter(|&&i| *show_hidden || p.hills[i].flags & FLAG_HIDDEN == 0)
+ .map(|&i| {
+ (
+ p.hills[i].x,
+ p.hills[i].y,
+ p.hills[i].flags & FLAG_HIDDEN != 0,
+ )
+ })
+ .collect()
};
let zoom_pct = (view.scale * 100.0).round();
@@ -695,6 +716,10 @@ pub fn app() -> Html {
{ "Fit distortion (needs ≥ 4 markers)" }
</label>
<div class="section">{ "Display" }</div>
+ <label class="row">
+ <input type="checkbox" checked={*show_hidden} onchange={on_show_hidden} />
+ { "Show hidden peaks" }
+ </label>
<SliderItem label="Visibility" display={format!("{:.0} %", (vp.vis - 0.01) / 0.09 * 100.0)}
value={vp.vis} min={0.01} max={0.1} step={0.001} onchange={on_vis} />
<SliderItem label="Label size" display={format!("{:.0} px", vp.label_font)}
diff --git a/crates/gipfel-web/src/canvas_view.rs b/crates/gipfel-web/src/canvas_view.rs
index ab72b7f..9d4338e 100644
--- a/crates/gipfel-web/src/canvas_view.rs
+++ b/crates/gipfel-web/src/canvas_view.rs
@@ -51,8 +51,9 @@ pub struct Props {
/// bumped on window resize to force a redraw
pub tick: u32,
pub markers: Vec<MarkerView>,
- /// projected positions of all visible hills (small guide dots)
- pub candidates: Vec<(f64, f64)>,
+ /// projected positions of all visible hills (guide dots) with their
+ /// hidden-by-occlusion flag
+ pub candidates: Vec<(f64, f64, bool)>,
/// marker label font size, screen px
pub label_font: f32,
}
@@ -131,10 +132,11 @@ pub fn canvas_view(props: &Props) -> Html {
let sy = |y: f64| (y + hh) * view.scale + view.oy;
// guide dots for all visible peaks: dark outline ring +
- // bright core so they stay visible on any photo content
+ // bright core so they stay visible on any photo content;
+ // peaks hidden by nearer terrain are drawn grey
#[allow(deprecated)]
ctx.set_fill_style(&wasm_bindgen::JsValue::from_str("rgba(0, 0, 0, 0.85)"));
- for (cx, cy) in candidates {
+ for (cx, cy, _hidden) in candidates {
let (px, py) = (sx(*cx), sy(*cy));
if px < -6.0 || py < -6.0 || px > cw + 6.0 || py > ch + 6.0 {
continue;
@@ -143,13 +145,14 @@ pub fn canvas_view(props: &Props) -> Html {
let _ = ctx.arc(px, py, 4.5, 0.0, std::f64::consts::TAU);
ctx.fill();
}
- #[allow(deprecated)]
- ctx.set_fill_style(&wasm_bindgen::JsValue::from_str("rgb(110, 231, 183)"));
- for (cx, cy) in candidates {
+ for (cx, cy, hidden) in candidates {
let (px, py) = (sx(*cx), sy(*cy));
if px < -6.0 || py < -6.0 || px > cw + 6.0 || py > ch + 6.0 {
continue;
}
+ let color = if *hidden { "rgb(150, 150, 150)" } else { "rgb(110, 231, 183)" };
+ #[allow(deprecated)]
+ ctx.set_fill_style(&wasm_bindgen::JsValue::from_str(color));
ctx.begin_path();
let _ = ctx.arc(px, py, 2.5, 0.0, std::f64::consts::TAU);
ctx.fill();
diff --git a/crates/gipfel-web/src/markers.rs b/crates/gipfel-web/src/markers.rs
index d1bf8cb..d024f2e 100644
--- a/crates/gipfel-web/src/markers.rs
+++ b/crates/gipfel-web/src/markers.rs
@@ -34,11 +34,21 @@ pub fn refit(pan: &mut Panorama, markers: &[Marker], fit_distortion: bool) -> Re
}
/// Nearest visible hill to image position `(x, y)`, within `max_dist`
-/// image pixels. Used to resolve marker clicks.
-pub fn nearest_hill(pan: &Panorama, x: f64, y: f64, max_dist: f64) -> Option<usize> {
+/// image pixels. Used to resolve marker clicks. Hills hidden by the
+/// occlusion heuristic are skipped unless `show_hidden`.
+pub fn nearest_hill(
+ pan: &Panorama,
+ x: f64,
+ y: f64,
+ max_dist: f64,
+ show_hidden: bool,
+) -> Option<usize> {
let mut best = None;
let mut best_d = max_dist;
for &i in &pan.visible {
+ if !show_hidden && pan.hills[i].flags & gipfel_core::hill::FLAG_HIDDEN != 0 {
+ continue;
+ }
let h = &pan.hills[i];
let d = (h.x - x).hypot(h.y - y);
if d < best_d {