From f91431fefa0418b80dea1246aecac2c6a9dfc416 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Tue, 27 Oct 2026 14:54:05 +0100 Subject: web: GPX track loading MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - core: track::load_gpx_from_bytes (path wrapper delegates to it; same hardening: size cap, no entity expansion, direct-child ) - sidebar: 'Load GPX Track…' button + hidden .gpx file input; the track swaps in via remove_hills(FLAG_TRACK_POINT) + add_hills, so marker hill indices never shift (track hills always live at the end of the hill list) - rendering: desktop parity — consecutive visible points joined with round-cap strokes, width = scale*track_width/(dist_m*10) clamped to [1,1000] image px, red (blue when hidden by terrain); a Track width slider (50-1000 m, default 200) appears in Display once a track is loaded - track points and duplicates are excluded from guide dots, hover and click hit-testing (they are scenery, not markable peaks) --- crates/wipfel/src/app.rs | 94 ++++++++++++++++++++++++++++++++++++++-- crates/wipfel/src/canvas_view.rs | 33 +++++++++++++- crates/wipfel/src/markers.rs | 8 +++- 3 files changed, 130 insertions(+), 5 deletions(-) (limited to 'crates/wipfel') diff --git a/crates/wipfel/src/app.rs b/crates/wipfel/src/app.rs index 2b205fa..d0c8ecd 100644 --- a/crates/wipfel/src/app.rs +++ b/crates/wipfel/src/app.rs @@ -5,7 +5,8 @@ use std::io::Read; use std::rc::Rc; use flate2::read::GzDecoder; -use gipfel_core::hill::{FLAG_DUPLIC, FLAG_HIDDEN, FLAG_TRACK_POINT}; +use gipfel_core::hill::{FLAG_DUPLIC, FLAG_HIDDEN, FLAG_TRACK_POINT, FLAG_VISIBLE}; +use gipfel_core::track as gpx; use gipfel_core::metadata::{apply_image_metadata, ImageMetaData}; use gipfel_core::panorama::Panorama; use wasm_bindgen::closure::Closure; @@ -15,7 +16,7 @@ use web_sys::{DragEvent, Event, HtmlCanvasElement, HtmlInputElement, InputEvent, use yew::prelude::*; use crate::bridge; -use crate::canvas_view::{CanvasView, DotView, MarkerView, ViewCallbacks, ViewState}; +use crate::canvas_view::{CanvasView, DotView, MarkerView, TrackView, ViewCallbacks, ViewState}; use crate::compass::{Compass, CompassData}; use crate::markers::{self, Marker}; use crate::widgets::{NumItem, SliderItem}; @@ -163,6 +164,10 @@ pub fn app() -> Html { let find_peak = use_state(|| Option::::None); let show_hidden = use_state(|| false); let peak_labels = use_state(|| false); + // hill indices of the GPS track, in file order + let track = use_state(Vec::::new); + let track_width = use_state(|| 200.0f64); + let track_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); @@ -433,6 +438,50 @@ pub fn app() -> Html { }) }; + let open_track_picker = { + let track_file_ref = track_file_ref.clone(); + Callback::from(move |_: MouseEvent| { + if let Some(input) = track_file_ref.cast::() { + input.click(); + } + }) + }; + + // 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 = { + let pan = pan.clone(); + let track = track.clone(); + let status = status.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, track, status) = (pan.clone(), track.clone(), status.clone()); + let name = file.name(); + spawn_local(async move { + match bridge::read_blob(&file).await { + Ok(bytes) => match gpx::load_gpx_from_bytes(&bytes, 2000) { + Ok(hills) => { + let n = hills.len(); + { + let p = &mut *pan.borrow_mut(); + p.remove_hills(FLAG_TRACK_POINT); + p.add_hills(&hills); + track.set((p.hills.len() - n..p.hills.len()).collect()); + } + status.set(format!("Track {name}: {n} points")); + } + Err(err) => status.set(format!("GPX failed: {err}")), + }, + Err(err) => status.set(format!("Failed to read {name}: {err}")), + } + }); + input.set_value(""); // allow re-selecting the same file + }) + }; + let on_distortion_toggle = { let fit_distortion = fit_distortion.clone(); let markers = markers.clone(); @@ -501,6 +550,10 @@ pub fn app() -> Html { peak_labels.set(input.checked()); }) }; + let on_track_width = { + let track_width = track_width.clone(); + Callback::from(move |v: f64| track_width.set(v)) + }; // compass strip: shares the image transform, drag changes azimuth let compass_data = { @@ -720,7 +773,10 @@ pub fn app() -> Html { let marked: Vec = markers.iter().map(|m| m.hill).collect(); p.visible .iter() - .filter(|&&i| *show_hidden || p.hills[i].flags & FLAG_HIDDEN == 0) + .filter(|&&i| { + p.hills[i].flags & (FLAG_DUPLIC | FLAG_TRACK_POINT) == 0 + && (*show_hidden || p.hills[i].flags & FLAG_HIDDEN == 0) + }) .map(|&i| DotView { x: p.hills[i].x, y: p.hills[i].y, @@ -730,6 +786,24 @@ pub fn app() -> Html { }) .collect() }; + let track_views: Vec = { + let p = pan.borrow(); + track + .iter() + .filter(|&&i| p.hills[i].flags & FLAG_VISIBLE != 0) + .map(|&i| { + let h = &p.hills[i]; + // C: scale * track_width / (dist_m * 10), distance in meters + let dist_m = p.get_real_distance(i).max(1.0); + TrackView { + x: h.x, + y: h.y, + hidden: h.flags & FLAG_HIDDEN != 0, + width: (p.get_scale() * *track_width / (dist_m * 10.0)).clamp(1.0, 1000.0), + } + }) + .collect() + }; let zoom_pct = (view.scale * 100.0).round(); let n_markers = markers.len(); @@ -740,6 +814,7 @@ pub fn app() -> Html {

{ "wipfel" }

{ "web gipfel photogrammetry" }

+ Html { class="hidden-file" onchange={on_file_change} /> +

{ (*status).clone() }

{ (*db_status).clone() }

if bitmap.is_some() { @@ -774,6 +856,11 @@ pub fn app() -> Html { { "Fit distortion (needs ≥ 4 markers)" }
{ "Display" }
+ if !track.is_empty() { + + }