From 8431ea2ac57d64a98ac79e302934c3edf9bf3e55 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Tue, 27 Oct 2026 12:29:43 +0100 Subject: web: Find Peak becomes a searchable picker over the close-hill list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Distance-ranked candidates are useless while the initial viewpoint is still rough — the true peak may project far from the click. Mirrors the desktop dialog instead: click opens a search box over pan.close (geographically near hills, dedup/track filtered), name-substring filter, sorted, capped at 300 entries, 'Name (1234 m)' labels, autofocused search, Cancel button. Selection marks the clicked position with the chosen hill, whatever its current projection. --- crates/gipfel-web/src/app.rs | 204 ++++++++++++++++++++++++++-------------- crates/gipfel-web/www/style.css | 39 +++++++- 2 files changed, 170 insertions(+), 73 deletions(-) diff --git a/crates/gipfel-web/src/app.rs b/crates/gipfel-web/src/app.rs index 30704e4..23126e9 100644 --- a/crates/gipfel-web/src/app.rs +++ b/crates/gipfel-web/src/app.rs @@ -5,12 +5,13 @@ use std::io::Read; use std::rc::Rc; use flate2::read::GzDecoder; +use gipfel_core::hill::{FLAG_DUPLIC, FLAG_TRACK_POINT}; use gipfel_core::metadata::{apply_image_metadata, ImageMetaData}; use gipfel_core::panorama::Panorama; use wasm_bindgen::closure::Closure; use wasm_bindgen::JsCast; use wasm_bindgen_futures::spawn_local; -use web_sys::{DragEvent, Event, HtmlCanvasElement, HtmlInputElement, MouseEvent}; +use web_sys::{DragEvent, Event, HtmlCanvasElement, HtmlInputElement, InputEvent, MouseEvent}; use yew::prelude::*; use crate::bridge; @@ -50,21 +51,14 @@ impl Default for UiParams { } } -/// one entry of the Find Peak candidate list -#[derive(Clone, PartialEq)] -struct FpItem { - hill: usize, - label: String, -} - -/// open Find Peak popup: anchor (screen + image coords) and candidates +/// open Find Peak popup: anchor (screen + image coords) and search query #[derive(Clone, PartialEq)] struct FindPeak { sx: f64, sy: f64, ix: f64, iy: f64, - items: Vec, + query: String, } fn gunzip(gz: &[u8]) -> Result, String> { @@ -75,6 +69,81 @@ fn gunzip(gz: &[u8]) -> Result, String> { .map_err(|e| format!("gunzip: {e}")) } +#[derive(Properties, PartialEq)] +struct FpProps { + fp: FindPeak, + items: Vec<(String, usize)>, + on_pick: Callback, + on_query: Callback, + on_close: Callback<()>, +} + +/// searchable Find Peak dialog: type to filter, click to select +#[function_component(FindPeakPanel)] +fn find_peak_panel(p: &FpProps) -> Html { + let input_ref = use_node_ref(); + // focus the search box when the dialog opens + { + let input_ref = input_ref.clone(); + use_effect_with((), move |_| { + if let Some(i) = input_ref.cast::() { + let _ = i.focus(); + } + }); + } + let on_query = { + let on_query = p.on_query.clone(); + Callback::from(move |e: InputEvent| { + let input: HtmlInputElement = e.target_unchecked_into(); + on_query.emit(input.value()); + }) + }; + let on_close = { + let on_close = p.on_close.clone(); + Callback::from(move |_: MouseEvent| on_close.emit(())) + }; + html! { + <> +
+
+
{ "Find Peak" }
+
+ +
+
+ { + for p.items.iter().map(|(label, idx)| { + let onclick = { + let on_pick = p.on_pick.clone(); + let i = *idx; + Callback::from(move |_: MouseEvent| on_pick.emit(i)) + }; + html! { + + } + }) + } + if p.items.is_empty() { +

{ "no matches" }

+ } +
+
+ +
+
+ + } +} + #[function_component(App)] pub fn app() -> Html { let bitmap = use_state(|| None::); @@ -398,41 +467,60 @@ pub fn app() -> Html { let fp_close = { let find_peak = find_peak.clone(); - Callback::from(move |_: MouseEvent| find_peak.set(None)) + Callback::from(move |_: ()| find_peak.set(None)) }; - // Find Peak popup (built outside the main html! for macro simplicity) + // Find Peak picker: searchable list over the geographically close hills + // (same candidate set and filtering as the desktop dialog) let findpeak_popup = if let Some(fp) = &*find_peak { - let fp2 = fp.clone(); - let items: Html = fp2 - .items - .iter() - .map(|it| { - let onclick = { - let mark = mark_peak.clone(); - let find_peak = find_peak.clone(); - let (hill, ix, iy) = (it.hill, fp2.ix, fp2.iy); - Callback::from(move |_: MouseEvent| { - mark.emit((hill, ix, iy)); - find_peak.set(None); - }) - }; - html! { - + let items: Vec<(String, usize)> = { + let p = pan.borrow(); + let q = fp.query.to_uppercase(); + let mut entries: Vec<(String, usize)> = p + .close + .iter() + .filter(|&&i| { + let h = &p.hills[i]; + h.flags & (FLAG_DUPLIC | FLAG_TRACK_POINT) == 0 + && (q.is_empty() || h.name.to_uppercase().contains(&q)) + }) + .map(|&i| { + ( + format!("{} ({} m)", p.hills[i].name, p.hills[i].height as i64), + i, + ) + }) + .collect(); + entries.sort_by(|a, b| a.0.cmp(&b.0)); + entries.truncate(300); + entries + }; + let on_pick = { + let mark = mark_peak.clone(); + let find_peak = find_peak.clone(); + let (ix, iy) = (fp.ix, fp.iy); + Callback::from(move |hill: usize| { + mark.emit((hill, ix, iy)); + find_peak.set(None); + }) + }; + let on_query = { + let find_peak = find_peak.clone(); + Callback::from(move |q: String| { + if let Some(mut fp) = (*find_peak).clone() { + fp.query = q; + find_peak.set(Some(fp)); } }) - .collect(); + }; html! { - <> -
-
-
{ "Find Peak" }
- { items } -
- + } } else { Html::default() @@ -464,55 +552,27 @@ pub fn app() -> Html { click: { let pan = pan.clone(); let view = view.clone(); - let status = status.clone(); let mark = mark_peak.clone(); let find_peak = find_peak.clone(); let img_size = img_size.clone(); Callback::from(move |(ix, iy): (f64, f64)| { let scale = view.scale; - let p = pan.borrow(); // unambiguous click right on a peak: mark directly - if let Some(idx) = markers::nearest_hill(&p, ix, iy, 10.0 / scale) { - drop(p); + if let Some(idx) = markers::nearest_hill(&pan.borrow(), ix, iy, 10.0 / scale) { find_peak.set(None); mark.emit((idx, ix, iy)); return; } - // otherwise offer a Find Peak list, like the desktop dialog - let r = 60.0 / scale; - let mut cands: Vec<(f64, usize)> = p - .visible - .iter() - .map(|&i| ((p.hills[i].x - ix).hypot(p.hills[i].y - iy), i)) - .filter(|(d, _)| *d <= r) - .collect(); - if cands.is_empty() { - drop(p); - status.set("No peaks near click — zoom in or adjust the view.".to_string()); - find_peak.set(None); - return; - } - cands.sort_by(|a, b| a.0.total_cmp(&b.0)); - cands.truncate(15); - let items: Vec = cands - .iter() - .map(|(d, i)| FpItem { - hill: *i, - label: format!( - "{} · {:.0} m · {:.0} px", - p.hills[*i].name, - p.hills[*i].height, - d * scale - ), - }) - .collect(); + // otherwise open the Find Peak picker (searchable, like the + // desktop dialog): the correct peak may project far away + // while the viewpoint is still rough let (w, h) = (img_size.0 as f64, img_size.1 as f64); find_peak.set(Some(FindPeak { sx: (ix + w / 2.0) * scale + view.ox, sy: (iy + h / 2.0) * scale + view.oy, ix, iy, - items, + query: String::new(), })); }) }, diff --git a/crates/gipfel-web/www/style.css b/crates/gipfel-web/www/style.css index 9e7e8a0..5122c43 100644 --- a/crates/gipfel-web/www/style.css +++ b/crates/gipfel-web/www/style.css @@ -152,13 +152,50 @@ canvas.compass { .findpeak { position: absolute; z-index: 10; + width: 280px; background: #1e1e26; border: 1px solid #3a3a46; border-radius: 6px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5); + display: flex; + flex-direction: column; +} +.fpsearch { + padding: 8px; + border-bottom: 1px solid #2c2c34; +} +.fpsearch input { + width: 100%; + padding: 5px 8px; + background: #24242c; + border: 1px solid #3a3a46; + border-radius: 4px; + color: #e8e8ea; + font-size: 13px; +} +.fplist { max-height: 320px; overflow-y: auto; - min-width: 220px; +} +.fpempty { + padding: 8px 10px; + font-size: 13px; + color: #8a8a94; + margin: 0; +} +.fpfoot { + padding: 6px 8px; + border-top: 1px solid #2c2c34; + text-align: right; +} +.fpcancel { + padding: 4px 12px; + background: #34343e; + color: #e8e8ea; + border: 0; + border-radius: 4px; + font-size: 12px; + cursor: pointer; } .fphead { padding: 6px 10px; -- cgit v1.2.3