diff options
| author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2026-10-28 09:25:36 +0100 |
|---|---|---|
| committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2026-10-28 10:34:53 +0100 |
| commit | 8b87a9d31c966b431e9547bcc411f9da7f3c527a (patch) | |
| tree | fa01e8e323f4dcd26baf20d1ef9fd16a197e224a /crates/wipfel | |
| parent | f0cf0c3e95ca0518de754f7915458bd90e8abf32 (diff) | |
web: load an alternative hill database from the UI
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.
Diffstat (limited to 'crates/wipfel')
| -rw-r--r-- | crates/wipfel/src/app.rs | 71 | ||||
| -rw-r--r-- | crates/wipfel/www/style.css | 9 |
2 files changed, 80 insertions, 0 deletions
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::<usize>::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::<HtmlInputElement>() { + 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 { /> <p class="status">{ (*status).clone() }</p> <p class="hint">{ (*db_status).clone() }</p> + <button class="secondary" onclick={open_db_picker}> + { "Load hill database…" } + </button> + <input + type="file" + class="hidden-file" + accept=".dat,.gz,.gzip,application/gzip" + ref={db_file_ref} + onchange={on_db_file_change} + /> if bitmap.is_some() { <> <div class="section">{ "Viewpoint" }</div> diff --git a/crates/wipfel/www/style.css b/crates/wipfel/www/style.css index 80c4d15..9ed7bd8 100644 --- a/crates/wipfel/www/style.css +++ b/crates/wipfel/www/style.css @@ -163,6 +163,15 @@ body { .sidebar button:hover { background: var(--btn-hover); } +.sidebar button.secondary { + background: var(--chip-bg); + color: var(--text); + font-size: 13px; + padding: 6px 10px; +} +.sidebar button.secondary:hover { + background: var(--chip-hover); +} .status { font-size: 13px; color: var(--text-dim); |
