@@ -4,10 +4,23 @@ use serde::Deserialize;
44use serde_json:: Value ;
55
66use super :: common:: { Visibility , deserialize_visibility_or_default} ;
7- use crate :: style:: deserialize_opt_f64;
7+ use crate :: style:: color:: MlColor ;
8+ use crate :: style:: expression:: MlExpr ;
9+ use crate :: style:: value:: MlStyleValue ;
10+ use crate :: style:: {
11+ default_one, default_transparent, deser_default_one, deser_default_transparent,
12+ deserialize_opt_f64,
13+ } ;
14+
15+ fn default_font ( ) -> Vec < String > {
16+ vec ! [
17+ "Open Sans Regular" . to_string( ) ,
18+ "Arial Unicode MS Regular" . to_string( ) ,
19+ ]
20+ }
821
922/// Paint properties for a `symbol` layer.
10- #[ derive( Debug , Clone , PartialEq , Deserialize , Default ) ]
23+ #[ derive( Debug , Clone , PartialEq , Deserialize ) ]
1124pub struct SymbolPaint {
1225 /// Icon colour. Supports expressions.
1326 #[ serde( rename = "icon-color" , skip_serializing_if = "Option::is_none" ) ]
@@ -26,8 +39,13 @@ pub struct SymbolPaint {
2639 pub icon_halo_blur : Option < Value > ,
2740
2841 /// Icon opacity. Supports expressions.
29- #[ serde( rename = "icon-opacity" , skip_serializing_if = "Option::is_none" ) ]
30- pub icon_opacity : Option < Value > ,
42+ #[ serde(
43+ rename = "icon-opacity" ,
44+ default = "default_one" ,
45+ deserialize_with = "deser_default_one" ,
46+ skip_serializing_if = "Option::is_none"
47+ ) ]
48+ pub icon_opacity : MlStyleValue < f64 > ,
3149
3250 /// Icon translation offset. Supports expressions.
3351 #[ serde( rename = "icon-translate" , skip_serializing_if = "Option::is_none" ) ]
@@ -48,24 +66,37 @@ pub struct SymbolPaint {
4866 pub icon_emissive_strength : Option < Value > ,
4967
5068 /// Text colour. Supports expressions.
51- #[ serde( rename = "text-color" , skip_serializing_if = "Option::is_none" ) ]
52- pub text_color : Option < Value > ,
69+ #[ serde(
70+ rename = "text-color" ,
71+ default = "default_transparent" ,
72+ deserialize_with = "deser_default_transparent"
73+ ) ]
74+ pub text_color : MlStyleValue < MlColor > ,
5375
5476 /// Text halo colour. Supports expressions.
55- #[ serde( rename = "text-halo-color" , skip_serializing_if = "Option::is_none" ) ]
56- pub text_halo_color : Option < Value > ,
77+ #[ serde(
78+ rename = "text-halo-color" ,
79+ default = "default_transparent" ,
80+ deserialize_with = "deser_default_transparent"
81+ ) ]
82+ pub text_halo_color : MlStyleValue < MlColor > ,
5783
5884 /// Width of the halo around text. Supports expressions.
5985 #[ serde( rename = "text-halo-width" , skip_serializing_if = "Option::is_none" ) ]
60- pub text_halo_width : Option < Value > ,
86+ pub text_halo_width : Option < MlStyleValue < f64 > > ,
6187
6288 /// Fade out the halo towards the outside. Supports expressions.
6389 #[ serde( rename = "text-halo-blur" , skip_serializing_if = "Option::is_none" ) ]
6490 pub text_halo_blur : Option < Value > ,
6591
6692 /// Text opacity. Supports expressions.
67- #[ serde( rename = "text-opacity" , skip_serializing_if = "Option::is_none" ) ]
68- pub text_opacity : Option < Value > ,
93+ #[ serde(
94+ rename = "text-opacity" ,
95+ default = "default_one" ,
96+ deserialize_with = "deser_default_one" ,
97+ skip_serializing_if = "Option::is_none"
98+ ) ]
99+ pub text_opacity : MlStyleValue < f64 > ,
69100
70101 /// Text translation offset. Supports expressions.
71102 #[ serde( rename = "text-translate" , skip_serializing_if = "Option::is_none" ) ]
@@ -86,6 +117,29 @@ pub struct SymbolPaint {
86117 pub text_emissive_strength : Option < Value > ,
87118}
88119
120+ impl Default for SymbolPaint {
121+ fn default ( ) -> Self {
122+ Self {
123+ icon_color : Default :: default ( ) ,
124+ icon_halo_color : Default :: default ( ) ,
125+ icon_halo_width : Default :: default ( ) ,
126+ icon_halo_blur : Default :: default ( ) ,
127+ icon_opacity : default_one ( ) ,
128+ icon_translate : Default :: default ( ) ,
129+ icon_translate_anchor : Default :: default ( ) ,
130+ icon_emissive_strength : Default :: default ( ) ,
131+ text_color : default_transparent ( ) ,
132+ text_halo_color : default_transparent ( ) ,
133+ text_halo_width : Default :: default ( ) ,
134+ text_halo_blur : Default :: default ( ) ,
135+ text_opacity : default_one ( ) ,
136+ text_translate : Default :: default ( ) ,
137+ text_translate_anchor : Default :: default ( ) ,
138+ text_emissive_strength : Default :: default ( ) ,
139+ }
140+ }
141+ }
142+
89143/// Layout properties for a `symbol` layer.
90144#[ derive( Debug , Clone , PartialEq , Deserialize , Default ) ]
91145pub struct SymbolLayout {
@@ -180,15 +234,15 @@ pub struct SymbolLayout {
180234
181235 /// Part of the text placed nearest to the anchor. Supports expressions.
182236 #[ serde( rename = "text-anchor" , skip_serializing_if = "Option::is_none" ) ]
183- pub text_anchor : Option < Value > ,
237+ pub text_anchor : Option < String > ,
184238
185239 /// Value to use for a text label. Supports expressions.
186240 #[ serde( rename = "text-field" , skip_serializing_if = "Option::is_none" ) ]
187- pub text_field : Option < Value > ,
241+ pub text_field : Option < String > ,
188242
189243 /// Font stack for the glyphs. Supports expressions.
190- #[ serde( rename = "text-font" , skip_serializing_if = "Option::is_none " ) ]
191- pub text_font : Option < Value > ,
244+ #[ serde( rename = "text-font" , default = "default_font " ) ]
245+ pub text_font : Vec < String > ,
192246
193247 /// If true, other symbols can be visible even if they collide with the text.
194248 #[ serde(
@@ -248,8 +302,8 @@ pub struct SymbolLayout {
248302 pub text_rotation_alignment : Option < Value > ,
249303
250304 /// Font size. Supports expressions.
251- #[ serde( rename = "text-size" , skip_serializing_if = "Option::is_none" ) ]
252- pub text_size : Option < Value > ,
305+ #[ serde( rename = "text-size" ) ]
306+ pub text_size : Option < MlStyleValue < f64 > > ,
253307
254308 /// Specifies how to capitalize text. Supports expressions.
255309 #[ serde( rename = "text-transform" , skip_serializing_if = "Option::is_none" ) ]
@@ -303,7 +357,7 @@ pub struct SymbolLayer {
303357
304358 /// Filter expression to select features from the source.
305359 #[ serde( skip_serializing_if = "Option::is_none" ) ]
306- pub filter : Option < Value > ,
360+ pub filter : Option < MlExpr > ,
307361
308362 /// Layout properties.
309363 #[ serde( default ) ]
0 commit comments