Add skyvector coordinate format to all and wasm

This commit is contained in:
Austen Adler 2023-04-22 14:02:08 -04:00
parent e6ea554b91
commit 12c8c77402
3 changed files with 14 additions and 3 deletions

View File

@ -7,6 +7,7 @@ use crate::{
dmm,
dms,
plus, //xpin
skyvector,
utm,
Coordinate,
Error,
@ -23,6 +24,7 @@ pub struct Coordinates {
pub utm: utm::Coordinate,
// pub xpin: xpin::Xpin,
pub plus: plus::Coordinate,
pub skyvector: skyvector::Coordinate,
}
impl TryFrom<LatLon> for Coordinates {
@ -36,6 +38,7 @@ impl TryFrom<LatLon> for Coordinates {
dmm: dmm::Coordinate::from(latlon),
utm: utm::Coordinate::try_from(latlon)?,
plus: plus::Coordinate::try_from(latlon)?,
skyvector: skyvector::Coordinate::from(latlon),
})
}
}

View File

@ -69,14 +69,14 @@ impl Coordinate {
let lat = dms.get_lat();
let lon = dms.get_lon();
format!(
"{:02}{:02}{:02}{}{:03}{:02}{:02}{}",
"{:02.0}{:02.0}{:02.0}{}{:03.0}{:02.0}{:02.0}{}",
lat.degrees,
lat.minutes,
lat.seconds,
lat.seconds.trunc(),
lat.direction,
lon.degrees,
lon.minutes,
lon.seconds,
lon.seconds.trunc(),
lon.direction,
)
}
@ -171,5 +171,10 @@ mod tests {
Coordinate::from_str("900000S1000000E"),
Ok(Coordinate::from(LatLon::new(-90.0_f64, 100.0_f64).unwrap()))
);
assert_eq!(
Coordinate::from_str("697926N1082388W").unwrap().0,
Coordinate::from(LatLon::new(69.79268710495744, -108.23886036872865).unwrap()).0
)
}
}

View File

@ -74,6 +74,8 @@ pub struct Coordinates {
// pub xpin: String,
#[wasm_bindgen(js_name = "Plus")]
pub plus: String,
#[wasm_bindgen(js_name = "Skyvector")]
pub skyvector: String,
}
impl From<&spatial_coordinate_systems::all::Coordinates> for Coordinates {
@ -84,6 +86,7 @@ impl From<&spatial_coordinate_systems::all::Coordinates> for Coordinates {
dmm: value.dmm.to_string(),
utm: value.utm.to_string(),
plus: value.plus.to_string(),
skyvector: value.skyvector.to_string(),
}
}
}