diff options
| author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2026-10-27 14:54:05 +0100 |
|---|---|---|
| committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2026-10-27 14:54:22 +0100 |
| commit | f91431fefa0418b80dea1246aecac2c6a9dfc416 (patch) | |
| tree | e0366a87ca243cf1292936ebe44807b301fbc392 /crates/wipfel/src/canvas_view.rs | |
| parent | f519a707e32679ec512518afc3c56eeec03c260a (diff) | |
web: GPX track loading
- core: track::load_gpx_from_bytes (path wrapper delegates to it;
same hardening: size cap, no entity expansion, direct-child <ele>)
- 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)
Diffstat (limited to 'crates/wipfel/src/canvas_view.rs')
| -rw-r--r-- | crates/wipfel/src/canvas_view.rs | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/crates/wipfel/src/canvas_view.rs b/crates/wipfel/src/canvas_view.rs index 76aebfc..9ec2267 100644 --- a/crates/wipfel/src/canvas_view.rs +++ b/crates/wipfel/src/canvas_view.rs @@ -36,6 +36,16 @@ pub struct DotView { pub name: String, } +/// One GPS track point in center-relative image coordinates; `width` is +/// the projected stroke width in image pixels (C: scale*width/(dist_m*10)). +#[derive(Clone, Debug, PartialEq)] +pub struct TrackView { + pub x: f64, + pub y: f64, + pub hidden: bool, + pub width: f64, +} + #[derive(Clone, PartialEq)] pub struct ViewCallbacks { pub pan: Callback<(f64, f64)>, @@ -64,6 +74,8 @@ pub struct Props { /// bumped on window resize to force a redraw pub tick: u32, pub markers: Vec<MarkerView>, + /// GPS track points in file order + pub track: Vec<TrackView>, /// guide dots for all visible hills pub candidates: Vec<DotView>, /// draw name labels for unmarked visible peaks too @@ -101,6 +113,7 @@ pub fn canvas_view(props: &Props) -> Html { let view = props.view.clone(); let canvas_ref = props.canvas_ref.clone(); let markers = props.markers.clone(); + let track = props.track.clone(); let candidates = props.candidates.clone(); let label_font = props.label_font; let peak_labels = props.peak_labels; @@ -110,11 +123,12 @@ pub fn canvas_view(props: &Props) -> Html { view, props.tick, markers.clone(), + track.clone(), candidates.clone(), label_font, peak_labels, ), - move |(bitmap, view, _tick, markers, candidates, label_font, peak_labels)| { + move |(bitmap, view, _tick, markers, track, candidates, label_font, peak_labels)| { let Some(canvas) = canvas_ref.cast::<HtmlCanvasElement>() else { return; }; @@ -154,6 +168,23 @@ pub fn canvas_view(props: &Props) -> Html { let sx = |x: f64| (x + hw) * view.scale + view.ox; let sy = |y: f64| (y + hh) * view.scale + view.oy; + // GPS track: consecutive points joined with round-cap + // strokes scaled by distance (desktop parity: red, or + // blue where the point is hidden by terrain) + for w in track.windows(2) { + let (a, b) = (&w[0], &w[1]); + let color = if a.hidden { "rgb(51, 102, 255)" } else { "rgb(255, 51, 51)" }; + #[allow(deprecated)] + ctx.set_stroke_style(&wasm_bindgen::JsValue::from_str(color)); + ctx.set_line_width((a.width * view.scale).max(1.0)); + ctx.set_line_cap("round"); + ctx.begin_path(); + ctx.move_to(sx(a.x), sy(a.y)); + ctx.line_to(sx(b.x), sy(b.y)); + ctx.stroke(); + } + ctx.set_line_cap("butt"); + // guide dots for all visible peaks: dark outline ring + // bright core so they stay visible on any photo content; // peaks hidden by nearer terrain are drawn grey |
