From 31a47fc4393856a0a0380b2fdcf79f9dac72ad56 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Mon, 9 Nov 2026 10:21:03 +0100 Subject: web: projection switch, external image URLs, zoom buttons - ?file= now also accepts absolute http(s) image URLs (CORS applies); README documents all URL parameters - Projection dropdown (rectilinear / cylindrical-panoramic), synced from the gipfel comment on load; cylindrical lifts the lens-FOV visibility limit (unlimited view angle) so 360 deg panoramas show peaks in every direction - force visibility rebuild on every image load (the change detection alone could keep a stale list when the limit value was unchanged) - Google-Maps-style +/- zoom buttons at the lower right of the canvas - save/load roundtrip test for the projection type in the gipfel comment; build stamp in the sidebar footer and ?debug=1 console diagnostics to spot stale cached bundles and inspect the effective visibility state --- README.md | 23 +++++++ crates/gipfel-core/src/metadata.rs | 24 +++++++ crates/gipfel/Cargo.toml | 1 + crates/gipfel/build-release.sh | 3 +- crates/gipfel/serve-here.sh | 3 +- crates/gipfel/src/app.rs | 129 +++++++++++++++++++++++++++++++++---- crates/gipfel/www/style.css | 29 +++++++++ dist/gipfel/gipfel.js | 11 ++-- dist/gipfel/gipfel_bg.wasm | Bin 551505 -> 555370 bytes dist/gipfel/style.css | 29 +++++++++ 10 files changed, 235 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 3ecf7a0..85d49ef 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,29 @@ right-click removes it. Once at least two mountains are positioned, gipfel fits the view parameters automatically and moves the remaining peaks to their correct positions. More markers improve the fit. +URL Parameters +-------------- +The web app can be fully linked to: image and view parameters are +passed as URL query parameters, e.g. + + https://example.org/gipfel/?file=photo.jpg + https://example.org/gipfel/?file=https://host/pano.jpg&az=57.4&pitch=-20 + +* `file` — image to open: a path on the same host, or an absolute + `http(s)` URL (the remote host must allow CORS) +* `az` — azimuth in degrees (true north) +* `pitch` — pitch in degrees +* `roll` — roll in degrees +* `focal` — focal length in mm (35 mm equivalent) +* `vis` — visibility override (0.01–0.1, same scale as the Visibility + slider; higher shows more distant peaks) + +The parameters are applied *after* the image's own EXIF/gipfel +metadata, so they override values recorded in the photo. A `gipfel:` +comment saved by "Save image…" is read back when the saved file is +opened again, so annotated images carry their view without any URL +parameters. + You may also want to have a look at the (outdated) [screen video](http://www.flpsed.org/images/gipfel.avi) for an example session. diff --git a/crates/gipfel-core/src/metadata.rs b/crates/gipfel-core/src/metadata.rs index 428cf79..d9c98f9 100644 --- a/crates/gipfel-core/src/metadata.rs +++ b/crates/gipfel-core/src/metadata.rs @@ -768,3 +768,27 @@ mod tests { assert!((pan.get_scale() - 50.0 * 1000.0 / 35.0).abs() < 1e-9); } } + +#[cfg(test)] +mod save_tests { + use super::*; + + #[test] + fn comment_roundtrip_preserves_projection_type() { + let mut md = ImageMetaData::new(); + md.longitude = 10.5; + md.latitude = 47.0; + md.height = 2993.0; + md.direction = 57.4; + md.pitch = -20.0; + md.roll = 0.3; + md.focal_length_35mm = 27.0; + md.projection_type = 1; // cylindrical + // minimal valid JPEG (SOI, empty COM, EOI) + let jpg = b"\xff\xd8\xff\xfe\x00\x02\xff\xd9"; + let out = md.save_image_to_bytes(jpg).unwrap(); + let mut md2 = ImageMetaData::new(); + md2.load_image_from_bytes(&out); + assert_eq!(md2.projection_type, 1, "projection type lost in comment roundtrip"); + } +} diff --git a/crates/gipfel/Cargo.toml b/crates/gipfel/Cargo.toml index 55b4e05..35df39b 100644 --- a/crates/gipfel/Cargo.toml +++ b/crates/gipfel/Cargo.toml @@ -16,6 +16,7 @@ yew = { version = "0.21", features = ["csr"] } [dependencies.web-sys] version = "0.3" features = [ + "console", "Blob", "BlobPropertyBag", "CanvasRenderingContext2d", diff --git a/crates/gipfel/build-release.sh b/crates/gipfel/build-release.sh index 1e429ca..d118b59 100755 --- a/crates/gipfel/build-release.sh +++ b/crates/gipfel/build-release.sh @@ -21,7 +21,8 @@ esac # size-optimized build for the web (the workspace default profile # targets native binaries); --remove-name-section drops the debug # symbol names wasm-bindgen adds for devtools -CARGO_PROFILE_RELEASE_OPT_LEVEL=z cargo build -p gipfel --target wasm32-unknown-unknown --release +touch crates/gipfel/src/app.rs # re-stamp every build (option_env! does not track STAMP) +STAMP=$(date -u +%Y-%m-%d_%H:%M) CARGO_PROFILE_RELEASE_OPT_LEVEL=z cargo build -p gipfel --target wasm32-unknown-unknown --release # stage into a fresh temp dir and swap it in only on success, so a # failing build never destroys the previous site and the old site is diff --git a/crates/gipfel/serve-here.sh b/crates/gipfel/serve-here.sh index 2eaaf4d..1fd3a46 100755 --- a/crates/gipfel/serve-here.sh +++ b/crates/gipfel/serve-here.sh @@ -3,7 +3,8 @@ # /tmp/gipfel-dist (python http.server on :8090). Dev-only helper. set -e cd "$(dirname "$0")/../.." -cargo build -p gipfel --target wasm32-unknown-unknown --release +touch crates/gipfel/src/app.rs # re-stamp every build (option_env! does not track STAMP) +STAMP=$(date -u +%Y-%m-%d_%H:%M) cargo build -p gipfel --target wasm32-unknown-unknown --release DIST=/tmp/gipfel-dist mkdir -p "$DIST" wasm-bindgen --target web --out-dir "$DIST" target/wasm32-unknown-unknown/release/gipfel.wasm diff --git a/crates/gipfel/src/app.rs b/crates/gipfel/src/app.rs index 7479b8e..9fff27a 100644 --- a/crates/gipfel/src/app.rs +++ b/crates/gipfel/src/app.rs @@ -9,6 +9,7 @@ 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 gipfel_core::projection::ProjectionType; use wasm_bindgen::closure::Closure; use wasm_bindgen::JsCast; use wasm_bindgen_futures::spawn_local; @@ -73,6 +74,14 @@ struct FindPeak { query: String, } +/// Build stamp injected by serve-here.sh / build-release.sh so a +/// quick glance at the sidebar reveals whether the browser is running +/// a cached old bundle. +const BUILD_STAMP: &str = match option_env!("STAMP") { + Some(s) => s, + None => "dev", +}; + /// Read a query parameter from the page URL (e.g. `/?file=test.jpg`). fn url_param(name: &str) -> Option { let search = bridge::window().location().search().ok()?; @@ -209,6 +218,9 @@ pub fn app() -> Html { let pan = use_mut_ref(Panorama::new); let markers = use_state(Vec::::new); let fit_distortion = use_state(|| false); + // 0 = rectilinear, 1 = cylindrical (panoramic); mirrors + // Panorama::projection_type, synced from the image comment on load + let projection = use_state(|| 0u32); let hover = use_state(|| Option::::None); let vp = use_state(UiParams::default); let img_size = use_state(|| (0u32, 0u32)); @@ -440,6 +452,7 @@ pub fn app() -> Html { let img_md = img_md.clone(); let profile_name = profile_name.clone(); let profiles = profiles.clone(); + let projection = projection.clone(); Callback::from(move |(bytes, name): (Vec, String)| { let (bitmap, status, fit, pan, markers, fit_info) = (bitmap.clone(), status.clone(), fit.clone(), pan.clone(), markers.clone(), fit_info.clone()); @@ -453,6 +466,7 @@ pub fn app() -> Html { let img_md = img_md.clone(); let profile_name = profile_name.clone(); let profiles = profiles.clone(); + let projection = projection.clone(); spawn_local(async move { match bridge::decode_bitmap(&bytes).await { Ok(bmp) => { @@ -528,6 +542,15 @@ pub fn app() -> Html { } }; vp.set(u); + // a saved gipfel comment may request the panoramic + // projection; sync the dropdown with the result + projection.set(pan.borrow().projection_type as u32); + // force the per-render limit block to re-evaluate: + // its change detection compares against the old + // value, and a metadata-driven switch to cylindrical + // (limit 0) would otherwise look "unchanged" and + // keep the stale visibility list + pan.borrow_mut().max_view_angle = -1.0; img_size.set((w, h)); let vp = if have { format!("viewpoint from image · {vis} peaks visible") @@ -561,18 +584,21 @@ pub fn app() -> Html { }) }; - // Auto-load an image given as ?file= so a photo can - // be opened by URL alone, e.g. /?file=test.jpg. It goes through the + // Auto-load an image given as ?file= so a photo + // can be opened by link alone, e.g. /?file=test.jpg or + // /?file=https://example.org/pano.jpg&az=57.4. It goes through the // normal load pipeline, so EXIF viewpoint/focal metadata is applied - // exactly as for a picked file. + // exactly as for a picked file. External URLs need CORS on their + // host; the status line reports failures. { let load_bytes = load_bytes.clone(); let status = status.clone(); let overrides = overrides.clone(); use_effect_with((), move |_| { let Some(path) = url_param("file") else { return }; - if path.is_empty() || path.starts_with("http") || path.contains(":/") { - status.set("?file= must be a same-origin path".to_string()); + let external = path.starts_with("https://") || path.starts_with("http://"); + if path.is_empty() || (!external && path.contains(":/")) { + status.set("?file= must be a path on this host or an http(s) URL".to_string()); return; } let name = path.rsplit('/').next().unwrap_or(&path).to_string(); @@ -895,6 +921,21 @@ pub fn app() -> Html { }) }; + let on_projection = { + let pan = pan.clone(); + let projection = projection.clone(); + Callback::from(move |e: Event| { + let sel: web_sys::HtmlSelectElement = e.target_unchecked_into(); + let cyl = sel.value() == "1"; + projection.set(if cyl { 1 } else { 0 }); + pan.borrow_mut().set_projection(if cyl { + ProjectionType::Cylindrical + } else { + ProjectionType::Rectilinear + }); + }) + }; + let on_distortion_toggle = { let fit_distortion = fit_distortion.clone(); let markers = markers.clone(); @@ -1218,24 +1259,43 @@ pub fn app() -> Html { // Lens FOV visibility limit, port of the desktop bump(): the angle at // which the (possibly distorted) projection reaches the image edge. // Peaks beyond it cannot be inside the photo even if the fitted - // distortion folds their projection back into the image. Running this - // every render is idempotent and cheap; visibility is only rebuilt - // when the limit actually changed. + // distortion folds their projection back into the image. Cylindrical + // (panoramic) images are exempt: they may cover the full 360°, so the + // limit is set to 0 = unlimited. Running this every render is + // idempotent and cheap; visibility is only rebuilt when the limit + // actually changed. { let mut p = pan.borrow_mut(); - let limit = if img_size.0 > 0 { + let limit = if img_size.0 == 0 || p.projection_type == ProjectionType::Cylindrical { + // 0 = unlimited: no image loaded, or panoramic projection, + // whose image may wrap all the way around the viewpoint + 0.0 + } else { let c = p.parms.a_center; let proj = gipfel_core::projection::projection_from_type(p.projection_type); let a_edge = alph_at_img_x(p.projection_type, &*proj, &p.parms, img_size.0 as f64 / 2.0, c); (a_edge - c).abs() - } else { - 0.0 }; if (limit - p.max_view_angle).abs() > 1e-9 { p.max_view_angle = limit; let known: Vec = markers.iter().map(|m| m.hill).collect(); p.update_visible_mountains(Some(&known)); } + // ?debug=1 dumps the effective visibility state to the browser + // console on every render (DevTools → Console) + if url_param("debug").is_some() { + web_sys::console::log_1( + &format!( + "gipfel dbg: proj={:?} max_view_angle={:.4} visible={} img={}x{}", + p.projection_type, + p.max_view_angle, + p.visible.len(), + img_size.0, + img_size.1 + ) + .into(), + ); + } } // overlay data for the canvas @@ -1292,6 +1352,42 @@ pub fn app() -> Html { let nav_open = nav_open.clone(); Callback::from(move |_: MouseEvent| nav_open.set(false)) }; + + // Google-Maps-style +/- buttons: zoom about the canvas center using + // the same math as wheel/pinch zoom; counts as manual navigation so + // the auto-fit stays out of the way afterwards + let zoom_step = { + let apply = apply_view.clone(); + let user_moved = user_moved.clone(); + let canvas_ref = canvas_ref.clone(); + Rc::new(move |factor: f64| { + let (cx, cy) = canvas_ref + .cast::() + .map(|c| { + ( + c.client_width() as f64 / 2.0, + c.client_height() as f64 / 2.0, + ) + }) + .unwrap_or((400.0, 300.0)); + *user_moved.borrow_mut() = true; + apply(&move |v| { + let ns = (v.scale * factor).clamp(0.02, 64.0); + let k = ns / v.scale; + v.ox = cx - (cx - v.ox) * k; + v.oy = cy - (cy - v.oy) * k; + v.scale = ns; + }); + }) + }; + let zoom_in = { + let zoom = zoom_step.clone(); + Callback::from(move |_: MouseEvent| zoom(1.4)) + }; + let zoom_out = { + let zoom = zoom_step.clone(); + Callback::from(move |_: MouseEvent| zoom(1.0 / 1.4)) + }; let expand_cb = { let nav_open = nav_open.clone(); Callback::from(move |_: MouseEvent| nav_open.set(true)) @@ -1350,6 +1446,10 @@ pub fn app() -> Html {
{ "Projection" }
+