Skip to content

Commit

Permalink
Add styleUrl to Placemark.
Browse files Browse the repository at this point in the history
  • Loading branch information
keltia committed Dec 12, 2024
1 parent 1a6d64e commit 9129ed4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ where
let mut description: Option<String> = None;
let mut geometry: Option<Geometry<T>> = None;
let mut children: Vec<Element> = Vec::new();
let mut style_url: Option<String> = None;

loop {
let e = self.reader.read_event_into(&mut self.buf)?;
Expand All @@ -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)?))
Expand Down Expand Up @@ -462,6 +464,7 @@ where
Ok(Placemark {
name,
description,
style_url,
geometry,
attrs,
children,
Expand Down Expand Up @@ -1599,6 +1602,7 @@ mod tests {
<Placemark>
<name><![CDATA[Test & Test]]></name>
<description>1¼ miles</description>
<styleUrl>#foo</styleUrl>
<Point>
<coordinates>
-1.0,1.0,0
Expand All @@ -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]
Expand Down
1 change: 1 addition & 0 deletions src/types/placemark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub struct Placemark<T: CoordType = f64> {
pub name: Option<String>,
pub description: Option<String>,
pub geometry: Option<Geometry<T>>,
pub style_url: Option<String>,
pub attrs: HashMap<String, String>,
pub children: Vec<Element>,
}
3 changes: 3 additions & 0 deletions src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")))?)
Expand Down

0 comments on commit 9129ed4

Please sign in to comment.