diff --git a/README.md b/README.md index 2c24c09..614606f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,11 @@ # gpx-web-utils ![ci](https://github.com/thermokarst/gpx-web-utils/workflows/ci/badge.svg) + +## quickstart + +1. install [wasm-pack](https://rustwasm.github.io/wasm-pack/installer/) +2. `wasm-pack build` +3. `cd www` +4. `npm install` +5. `npm run start` diff --git a/src/utils.rs b/src/utils.rs index c8cd025..79e912a 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -9,16 +9,25 @@ pub fn translate_js_to_rust(files: js_sys::Array) -> Vec { } pub fn join_gpx_files(files: Vec) -> gpx::Gpx { - let mut merged: gpx::Gpx = Default::default(); + let mut merged_gpx: gpx::Gpx = Default::default(); + let mut merged_track: gpx::Track = gpx::Track::new(); for file in files.iter() { let buffer = std::io::BufReader::new(file.as_bytes()); let mut parsed_gpx: gpx::Gpx = gpx::read(buffer).expect("invalid gpx"); - merged.tracks.append(&mut parsed_gpx.tracks); - merged.waypoints.append(&mut parsed_gpx.waypoints); + // consolidate all track segements into one single track. + for track in parsed_gpx.tracks { + for segment in track.segments { + merged_track.segments.push(segment); + } + } + + merged_gpx.waypoints.append(&mut parsed_gpx.waypoints); } + merged_gpx.tracks.push(merged_track); + let link = gpx::Link { href: String::from("https://gpx.thermokar.st"), ..Default::default() @@ -32,10 +41,10 @@ pub fn join_gpx_files(files: Vec) -> gpx::Gpx { author: Some(author), ..Default::default() }; - merged.metadata = Some(metadata); - merged.version = gpx::GpxVersion::Gpx11; + merged_gpx.metadata = Some(metadata); + merged_gpx.version = gpx::GpxVersion::Gpx11; - merged + merged_gpx } pub fn write_gpx_to_buffer(gpx: gpx::Gpx) -> Vec {