From 8b87a9d31c966b431e9547bcc411f9da7f3c527a Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Wed, 28 Oct 2026 09:25:36 +0100 Subject: web: load an alternative hill database from the UI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Secondary button under the database status line: picks a .dat (or gzipped) peak list at runtime — e.g. a regional file like everest.dat instead of the full 21k gipfel.dat. Markers and track reference hill indices, so they are dropped when the database is swapped. --- crates/wipfel/src/app.rs | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'crates/wipfel/src') diff --git a/crates/wipfel/src/app.rs b/crates/wipfel/src/app.rs index a7af089..fbe49c4 100644 --- a/crates/wipfel/src/app.rs +++ b/crates/wipfel/src/app.rs @@ -190,6 +190,8 @@ pub fn app() -> Html { let track = use_state(Vec::::new); let track_width = use_state(|| 200.0f64); let track_file_ref = use_node_ref(); + // optional alternative hill database (e.g. a regional list) + let db_file_ref = use_node_ref(); // set once the user pans or zooms by hand; auto-fit is then suppressed // until the next image load let user_moved = use_mut_ref(|| false); @@ -492,6 +494,65 @@ pub fn app() -> Html { }) }; + let open_db_picker = { + let db_file_ref = db_file_ref.clone(); + Callback::from(move |_: MouseEvent| { + if let Some(input) = db_file_ref.cast::() { + input.click(); + } + }) + }; + + // replace the hill database at runtime (e.g. everest.dat for the + // Khumbu); markers and track reference hill indices and are dropped + let on_db_file_change = { + let pan = pan.clone(); + let db_status = db_status.clone(); + let markers = markers.clone(); + let track = track.clone(); + Callback::from(move |e: Event| { + let input: HtmlInputElement = e.target_unchecked_into(); + let Some(file) = input.files().and_then(|f| f.item(0)) else { + return; + }; + let (pan, db_status, markers, track) = ( + pan.clone(), + db_status.clone(), + markers.clone(), + track.clone(), + ); + let name = file.name(); + spawn_local(async move { + match bridge::read_blob(&file).await { + Ok(bytes) => { + // accept plain .dat and gzipped variants + let raw = match bytes.first() { + Some(0x1f) if bytes.get(1) == Some(&0x8b) => match gunzip(&bytes) { + Ok(r) => r, + Err(err) => { + db_status.set(format!("gunzip failed: {err}")); + return; + } + }, + _ => bytes, + }; + match pan.borrow_mut().load_data_from_bytes(&raw) { + Ok(()) => { + markers.set(Vec::new()); + track.set(Vec::new()); + let n = pan.borrow().hills.len(); + db_status.set(format!("Hill database {name}: {n} peaks")); + } + Err(err) => db_status.set(format!("Database failed: {err}")), + } + } + Err(err) => db_status.set(format!("Failed to read {name}: {err}")), + } + }); + input.set_value(""); // allow re-selecting the same file + }) + }; + // parse a GPX file and swap it into the panorama as track-point hills // (always appended last, so marker hill indices never shift) let on_track_file_change = { @@ -960,6 +1021,16 @@ pub fn app() -> Html { />

{ (*status).clone() }

{ (*db_status).clone() }

+ + if bitmap.is_some() { <>
{ "Viewpoint" }
-- cgit v1.2.3