From 9129ed4cbccb5e00a48214656bd84afb41ca1e5d Mon Sep 17 00:00:00 2001 From: Ollivier Robert Date: Thu, 12 Dec 2024 15:24:09 +0100 Subject: [PATCH] Add styleUrl to Placemark. --- src/reader.rs | 5 +++++ src/types/placemark.rs | 1 + src/writer.rs | 3 +++ 3 files changed, 9 insertions(+) diff --git a/src/reader.rs b/src/reader.rs index 5d78148..21c2535 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -423,6 +423,7 @@ where let mut description: Option = None; let mut geometry: Option> = None; let mut children: Vec = Vec::new(); + let mut style_url: Option = None; loop { let e = self.reader.read_event_into(&mut self.buf)?; @@ -432,6 +433,7 @@ where match e.local_name().as_ref() { b"name" => name = Some(self.read_str()?), b"description" => description = Some(self.read_str()?), + b"styleUrl" => style_url = Some(self.read_str()?), b"Point" => geometry = Some(Geometry::Point(self.read_point(attrs)?)), b"LineString" => { geometry = Some(Geometry::LineString(self.read_line_string(attrs)?)) @@ -462,6 +464,7 @@ where Ok(Placemark { name, description, + style_url, geometry, attrs, children, @@ -1599,6 +1602,7 @@ mod tests { 1¼ miles + #foo -1.0,1.0,0 @@ -1614,6 +1618,7 @@ mod tests { .unwrap(); assert_eq!(placemark.name, Some("Test & Test".to_string())); assert_eq!(placemark.description, Some("1¼ miles".to_string())); + assert_eq!(placemark.style_url, Some("#foo".to_string())); } #[test] diff --git a/src/types/placemark.rs b/src/types/placemark.rs index 3813ad3..713486c 100644 --- a/src/types/placemark.rs +++ b/src/types/placemark.rs @@ -16,6 +16,7 @@ pub struct Placemark { pub name: Option, pub description: Option, pub geometry: Option>, + pub style_url: Option, pub attrs: HashMap, pub children: Vec, } diff --git a/src/writer.rs b/src/writer.rs index 653d47e..c69925c 100644 --- a/src/writer.rs +++ b/src/writer.rs @@ -250,6 +250,9 @@ where if let Some(geometry) = &placemark.geometry { self.write_geometry(geometry)?; } + if let Some(style_url) = &placemark.style_url { + self.write_text_element("styleUrl", style_url)?; + } Ok(self .writer .write_event(Event::End(BytesEnd::new("Placemark")))?)