-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathstyle.rs
271 lines (245 loc) · 7.08 KB
/
style.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
use std::collections::HashMap;
use std::fmt;
use std::str::FromStr;
use crate::errors::Error;
use crate::types::Vec2;
/// `kml:Style`, [12.2](http://docs.opengeospatial.org/is/12-007r2/12-007r2.html#798) in the KML
/// specification
#[derive(Clone, Default, Debug, PartialEq)]
pub struct Style {
pub id: Option<String>,
pub balloon: Option<BalloonStyle>,
pub icon: Option<IconStyle>,
pub label: Option<LabelStyle>,
pub line: Option<LineStyle>,
pub poly: Option<PolyStyle>,
pub list: Option<ListStyle>,
pub attrs: HashMap<String, String>,
}
/// `kml:StyleMap`, [12.3](http://docs.opengeospatial.org/is/12-007r2/12-007r2.html#811) in the KML
/// specification
#[derive(Clone, Default, Debug, PartialEq, Eq)]
pub struct StyleMap {
pub id: Option<String>,
pub pairs: Vec<Pair>,
pub attrs: HashMap<String, String>,
}
/// `kml:Pair`, [12.4](http://docs.opengeospatial.org/is/12-007r2/12-007r2.html#819) in the KML
/// specification
#[derive(Clone, Default, Debug, PartialEq, Eq)]
pub struct Pair {
pub key: String,
pub style_url: String,
pub attrs: HashMap<String, String>,
}
/// `kml:BalloonStyle`, [12.7](http://docs.opengeospatial.org/is/12-007r2/12-007r2.html#841) in the
/// KML specification
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct BalloonStyle {
pub id: Option<String>,
pub bg_color: Option<String>,
pub text_color: String,
pub text: Option<String>,
pub display: bool,
pub attrs: HashMap<String, String>,
}
impl Default for BalloonStyle {
fn default() -> BalloonStyle {
BalloonStyle {
id: None,
bg_color: None,
text_color: "ffffffff".to_string(),
text: None,
display: true,
attrs: HashMap::new(),
}
}
}
/// `kml:colorMode`, [12.11](http://docs.opengeospatial.org/is/12-007r2/12-007r2.html#879) in the
/// KML specification
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
pub enum ColorMode {
#[default]
Normal,
Random,
}
impl FromStr for ColorMode {
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"normal" => Ok(Self::Normal),
"random" => Ok(Self::Random),
v => Err(Error::InvalidColorMode(v.to_string())),
}
}
}
impl fmt::Display for ColorMode {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"{}",
match self {
Self::Normal => "normal",
Self::Random => "random",
}
)
}
}
/// `kml:IconStyle`, [12.12](http://docs.opengeospatial.org/is/12-007r2/12-007r2.html#883) in the
/// KML specification
#[derive(Clone, Debug, PartialEq)]
pub struct IconStyle {
pub id: Option<String>,
pub scale: f64,
pub heading: f64,
pub hot_spot: Option<Vec2>,
pub icon: Icon,
pub color: String,
pub color_mode: ColorMode,
pub attrs: HashMap<String, String>,
}
impl Default for IconStyle {
fn default() -> IconStyle {
IconStyle {
id: None,
scale: 1.0,
heading: 0.0,
hot_spot: None,
icon: Icon::default(),
color: "ffffffff".to_string(),
color_mode: ColorMode::default(),
attrs: HashMap::new(),
}
}
}
/// `kml:Icon`, [12.13](http://docs.opengeospatial.org/is/12-007r2/12-007r2.html#900) in the KML
/// specification.
///
/// Implements on `kml:BasicLinkType`
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct Icon {
pub href: String,
pub attrs: HashMap<String, String>,
}
/// `kml:LabelStyle`, [12.14](http://docs.opengeospatial.org/is/12-007r2/12-007r2.html#909) in the
/// KML specification.
#[derive(Clone, Debug, PartialEq)]
pub struct LabelStyle {
pub id: Option<String>,
pub color: String,
pub color_mode: ColorMode,
pub scale: f64,
pub attrs: HashMap<String, String>,
}
impl Default for LabelStyle {
fn default() -> LabelStyle {
LabelStyle {
id: None,
color: "ffffffff".to_string(),
color_mode: ColorMode::default(),
scale: 1.0,
attrs: HashMap::new(),
}
}
}
/// `kml:LineStyle`, [12.15](http://docs.opengeospatial.org/is/12-007r2/12-007r2.html#917) in the
/// KML specification.
#[derive(Clone, Debug, PartialEq)]
pub struct LineStyle {
pub id: Option<String>,
pub color: String,
pub color_mode: ColorMode,
pub width: f64,
pub attrs: HashMap<String, String>,
}
impl Default for LineStyle {
fn default() -> LineStyle {
LineStyle {
id: None,
color: "ffffffff".to_string(),
color_mode: ColorMode::default(),
width: 1.0,
attrs: HashMap::new(),
}
}
}
/// `kml:PolyStyle`, [12.16](http://docs.opengeospatial.org/is/12-007r2/12-007r2.html#927) in the
/// KML specification.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct PolyStyle {
pub id: Option<String>,
pub color: String,
pub color_mode: ColorMode,
pub fill: bool,
pub outline: bool,
pub attrs: HashMap<String, String>,
}
impl Default for PolyStyle {
fn default() -> PolyStyle {
PolyStyle {
id: None,
color: "ffffffff".to_string(),
color_mode: ColorMode::default(),
fill: true,
outline: true,
attrs: HashMap::new(),
}
}
}
/// `kml:listItemType`, [12.18](http://docs.opengeospatial.org/is/12-007r2/12-007r2.html#955) in the
/// KML specification.
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub enum ListItemType {
#[default]
Check,
CheckOffOnly,
CheckHideChildren,
RadioFolder,
}
impl FromStr for ListItemType {
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"check" => Ok(Self::Check),
"checkOffOnly" => Ok(Self::CheckOffOnly),
"checkHideChildren" => Ok(Self::CheckHideChildren),
"radioFolder" => Ok(Self::RadioFolder),
v => Err(Error::InvalidListItemType(v.to_string())),
}
}
}
impl fmt::Display for ListItemType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"{}",
match self {
Self::Check => "check",
Self::CheckOffOnly => "checkOffOnly",
Self::CheckHideChildren => "checkHideChildren",
Self::RadioFolder => "radioFolder",
}
)
}
}
/// `kml:ListStyle`, [12.17](http://docs.opengeospatial.org/is/12-007r2/12-007r2.html#940) in the
/// KML specification.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ListStyle {
pub id: Option<String>,
pub bg_color: String,
pub max_snippet_lines: u32,
pub list_item_type: ListItemType,
pub attrs: HashMap<String, String>,
}
impl Default for ListStyle {
fn default() -> ListStyle {
ListStyle {
id: None,
bg_color: "ffffffff".to_string(),
max_snippet_lines: 2,
list_item_type: ListItemType::default(),
attrs: HashMap::new(),
}
}
}