maint: merge individual tracks
This commit is contained in:
parent
cff09659f9
commit
abadb2ec7d
2 changed files with 23 additions and 6 deletions
|
@ -1,3 +1,11 @@
|
|||
# gpx-web-utils
|
||||
|
||||

|
||||
|
||||
## 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`
|
||||
|
|
21
src/utils.rs
21
src/utils.rs
|
@ -9,15 +9,24 @@ pub fn translate_js_to_rust(files: js_sys::Array) -> Vec<String> {
|
|||
}
|
||||
|
||||
pub fn join_gpx_files(files: Vec<String>) -> 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"),
|
||||
|
@ -32,10 +41,10 @@ pub fn join_gpx_files(files: Vec<String>) -> 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<u8> {
|
||||
|
|
Loading…
Add table
Reference in a new issue