import and export of routes, ref #192

This commit is contained in:
vcoppe committed 2026-10-09 09:26:38 +02:00
1 parent da9abbae5e
commit dc36de2a48
10 files changed
+620 -62

No files matched your search

+5 -1
View File
@@ -56,8 +56,10 @@ pub fn selection_statistics() -> GlobalStatistics {
}
/// A file as GPX (UTF-8 bytes), `undefined` if it does not exist. The options say which data of the trackpoints
/// to keep.
/// to keep, and with `as_route` that the segments are written as routes (`rte`) instead of tracks:
/// the anchors are the route points, and the trackpoints between them the points of their path.
#[wasm_bindgen]
#[allow(clippy::too_many_arguments)]
pub fn export_file(
file_id: &str,
time: bool,
@@ -66,6 +68,7 @@ pub fn export_file(
atemp: bool,
power: bool,
osm: bool,
as_route: bool,
) -> Option<Vec<u8>> {
let id = parse_file_id(file_id)?;
let options = engine::ExportOptions {
@@ -75,6 +78,7 @@ pub fn export_file(
atemp,
power,
osm,
as_route,
};
with_engine(|e| e.export(&id, options)).flatten()
}
+23 -2
View File
@@ -112,7 +112,10 @@ fn test_unknown_file_has_no_structure() {
assert!(crate::queries::files::file_structure(&id).is_undefined());
assert!(crate::queries::files::file_structure("not an id").is_undefined());
assert!(crate::queries::files::file_statistics(&id).is_undefined());
assert!(crate::queries::files::export_file(&id, true, true, true, true, true, true).is_none());
assert!(
crate::queries::files::export_file(&id, true, true, true, true, true, true, false)
.is_none()
);
assert_eq!(
crate::queries::coordinates::segment_coordinates(&id).length(),
0
@@ -265,7 +268,8 @@ fn test_export_and_exportable_data() {
let ids = order();
let bytes =
crate::queries::files::export_file(&ids[0], true, true, true, true, true, true).unwrap();
crate::queries::files::export_file(&ids[0], true, true, true, true, true, true, false)
.unwrap();
assert!(String::from_utf8(bytes).unwrap().contains("<gpx"));
// the time is the first bit
@@ -284,6 +288,23 @@ fn test_export_and_exportable_data() {
assert_eq!(crate::queries::files::exportable_data(&[1, 2, 3]), 0);
}
#[wasm_bindgen_test]
fn test_export_as_route() {
started_with(&[(SIMPLE, "plain")]);
let id = order().remove(0);
let text = |as_route| {
let bytes =
crate::queries::files::export_file(&id, true, true, true, true, true, true, as_route)
.unwrap();
String::from_utf8(bytes).unwrap()
};
let tracks = text(false);
assert!(tracks.contains("<trk>") && !tracks.contains("<rte>"));
let routes = text(true);
assert!(routes.contains("<rte>") && !routes.contains("<trk>"));
assert!(routes.contains("<rtept"));
}
#[wasm_bindgen_test]
fn test_select_and_reorder_files() {
started_with(&[(SIMPLE, "a"), (WITH_TIME, "b")]);