diff --git a/web-frontend/src/lib/common.js b/web-frontend/src/lib/common.js index 1ade5ae..df5bdc7 100644 --- a/web-frontend/src/lib/common.js +++ b/web-frontend/src/lib/common.js @@ -5,7 +5,6 @@ export const emptyxpin = { address: '', latLon: [0.0, 0.0], decimalDegrees: '', - srcCoordsRepr: '0.0, 0.0' }; export const WasmStatus = { diff --git a/web-frontend/src/routes/app/+page.svelte b/web-frontend/src/routes/app/+page.svelte index 80d2808..cecf529 100644 --- a/web-frontend/src/routes/app/+page.svelte +++ b/web-frontend/src/routes/app/+page.svelte @@ -135,7 +135,7 @@ // Update coordinate display if (fromTextInput) { selectedCoordinateType = coordinateTypes[addr.srcCoordsType] || selectedCoordinateType; - coordinateInputValue = addr.srcCoordsRepr || coordinateInputValue; + coordinateInputValue = addr.getCoordsRepr() || coordinateInputValue; } else { coordinateInputValue = addr.get_coords_repr_as( coordinateTypes.indexOf(selectedCoordinateType) diff --git a/xpin-wasm/src/lib.rs b/xpin-wasm/src/lib.rs index 09c06de..280ffc8 100644 --- a/xpin-wasm/src/lib.rs +++ b/xpin-wasm/src/lib.rs @@ -47,8 +47,6 @@ pub struct EncodedAddress { pub address: String, /// The coordinates used to encode this address src_coords: Coordinate, - #[wasm_bindgen(js_name = srcCoordsRepr)] - pub src_coords_repr: String, #[wasm_bindgen(js_name = srcCoordsType)] pub src_coords_type: CoordinateType, #[wasm_bindgen(js_name = latLon)] @@ -66,6 +64,13 @@ impl EncodedAddress { /// Get the string representation of the encoded value #[wasm_bindgen] // TODO: Do not return option + pub fn get_coords_repr(&self, coordinate_type: CoordinateType) -> String { + self.src_coords.to_string() + } + + /// Get the string representation of the encoded value as a different type + #[wasm_bindgen] + // TODO: Do not return option pub fn get_coords_repr_as(&self, coordinate_type: CoordinateType) -> Option { self.src_coords // TODO: Remove the clone here @@ -94,19 +99,23 @@ impl EncodedAddress { let src_coords = Coordinate::from_str(i) .map_err(|e| format!("Could not parse str {i:?} as a coordinate {e:?}"))?; - // TODO: Remove the clone here - let latlon = LatLon::from(&src_coords); + let src_latlon = LatLon::from(&src_coords); let mut ret = Self::try_from( - xpin::Address::from_lat_lon(latlon.get_lat(), latlon.get_lon()) + xpin::Address::from_lat_lon(src_latlon.get_lat(), src_latlon.get_lon()) .as_ref() .map_err(|e| e.to_string())?, ) .map_err(|e| e.to_string())?; - ret.src_coords_repr = src_coords.to_string(); + ret.src_coords = ret + .src_coords + .try_as_type(&src_coords.get_type().into()) + .map_err(|e| e.to_string())? + .into(); + + // TODO: Remove this ret.src_coords_type = src_coords.get_type().into(); - ret.src_coords = src_coords; Ok(ret) } @@ -163,7 +172,6 @@ impl TryFrom<&'_ Address<'_>> for EncodedAddress { Ok(Self { address: addr.to_string(), lat_lon: Box::new([lat, lon]), - src_coords_repr: src_coords.to_string(), src_coords_type: src_coords.get_type().into(), src_coords, decimal_degrees: format!("{}, {}", lat, lon),