#[derive(Debug, Clone, PartialEq)]
pub struct Style {
pub id: String,
pub icon_style_scale: f64,
pub icon_url: String,
pub line_style_width: f64,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Point {
pub longitude: f64,
pub latitude: f64,
pub altitude: f64,
pub altitude_mode: AltitudeMode,
}
#[derive(Debug, Clone, PartialEq)]
pub struct LineString {
pub extrude: u32,
pub tessellate: u32,
pub altitude_mode: AltitudeMode,
pub points: Vec<Point>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum AltitudeMode {
ErelativeToGround,
Eabsolute,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Placemark {
pub name: String,
pub description: String,
pub style_id: Option<String>,
pub geo_element: GeoElement,
pub visible: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Folder {
pub name: String,
pub description: String,
pub elements: Vec<Element>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum GeoElement {
EPoint(Point),
ELineString(LineString),
}
#[derive(Debug, Clone, PartialEq)]
pub enum Element {
EFolder(Folder),
EPlacemark(Placemark),
}
#[derive(Debug, Clone, PartialEq)]
pub struct Document {
pub name: String,
pub description: String,
pub styles: Vec<Style>,
pub elements: Vec<Element>,
}
impl From<Placemark> for Element {
fn from(e: Placemark) -> Self {
Element::EPlacemark(e)
}
}
impl From<Point> for GeoElement {
fn from(p: Point) -> Self {
GeoElement::EPoint(p)
}
}
impl Placemark {
pub fn new_point_on_ground(
name: String,
description: String,
style_id: Option<String>,
longitude: f64,
latitude: f64,
) -> Self {
let geo_element: GeoElement = Point {
longitude,
latitude,
altitude: 0f64,
altitude_mode: AltitudeMode::ErelativeToGround,
}
.into();
Placemark {
name,
description,
geo_element,
style_id,
visible: true,
}
}
}
impl From<Folder> for Element {
fn from(e: Folder) -> Self {
Element::EFolder(e)
}
}
impl Placemark {
pub fn new_line(
name: String,
description: String,
style_id: Option<String>,
points: Vec<(f64, f64)>,
) -> Self {
let points = points
.iter()
.map(|(longitude, latitude)| Point {
longitude: *longitude,
latitude: *latitude,
altitude: 0f64,
altitude_mode: AltitudeMode::ErelativeToGround,
})
.collect::<Vec<_>>();
let geo_element: GeoElement = LineString {
extrude: 1,
tessellate: 1,
altitude_mode: AltitudeMode::ErelativeToGround,
points,
}
.into();
Placemark {
name,
description,
style_id,
geo_element,
visible: true,
}
}
}
impl From<LineString> for GeoElement {
fn from(ls: LineString) -> Self {
GeoElement::ELineString(ls)
}
}