@@ -4,7 +4,9 @@ use galileo_mvt::{MvtFeature, MvtValue};
44use serde:: { Deserialize , Serialize } ;
55
66use crate :: Color ;
7- use crate :: expr:: { ExprDeser , ExprFeature , ExprGeometryType , ExprValue , ExprView } ;
7+ use crate :: expr:: {
8+ BoolExpr , ColorExpr , ExprFeature , ExprGeometryType , ExprValue , ExprView , NumExpr ,
9+ } ;
810use crate :: render:: point_paint:: PointPaint ;
911use crate :: render:: text:: {
1012 FontStyle , FontWeight , HorizontalAlignment , TextStyle , VerticalAlignment ,
@@ -21,7 +23,7 @@ pub struct VectorTileStyle {
2123 pub rules : Vec < StyleRule > ,
2224
2325 /// Background color of tiles.
24- pub background : ExprDeser ,
26+ pub background : ColorExpr ,
2527}
2628
2729/// A rule that specifies what kind of features can be drawing with the given symbol.
@@ -36,7 +38,7 @@ pub struct StyleRule {
3638 pub min_resolution : Option < f64 > ,
3739 /// Specifies a set of attributes of a feature that must have the given values for this rule to be applied.
3840 #[ serde( default ) ]
39- pub filter : Option < ExprDeser > ,
41+ pub filter : Option < BoolExpr > ,
4042 /// Symbol to draw a feature with.
4143 #[ serde( default ) ]
4244 pub symbol : VectorTileSymbol ,
@@ -54,7 +56,7 @@ impl StyleRule {
5456 z_index : Some ( z_index) ,
5557 } ;
5658
57- expr. eval ( feature, expr_view) . as_bool ( ) . unwrap_or ( false )
59+ expr. eval ( feature, expr_view)
5860 }
5961}
6062
@@ -149,16 +151,16 @@ impl VectorTileSymbol {
149151#[ derive( Debug , Clone , Serialize , Deserialize , PartialEq ) ]
150152pub struct VectorTilePointSymbol {
151153 /// Size of the point.
152- pub size : ExprDeser ,
154+ pub size : NumExpr ,
153155 /// Color of the point.
154- pub color : ExprDeser ,
156+ pub color : ColorExpr ,
155157}
156158
157159impl VectorTilePointSymbol {
158160 pub ( crate ) fn to_paint ( & self , feature : & MvtFeature , view : ExprView ) -> Option < PointPaint < ' _ > > {
159161 Some ( PointPaint :: circle (
160- self . color . eval ( feature, view) . as_color ( ) ?,
161- self . size . eval ( feature, view) . as_number ( ) ? as f32 ,
162+ self . color . eval ( feature, view) ?,
163+ self . size . eval ( feature, view) ? as f32 ,
162164 ) )
163165 }
164166}
@@ -167,16 +169,16 @@ impl VectorTilePointSymbol {
167169#[ derive( Debug , Clone , Serialize , Deserialize , PartialEq ) ]
168170pub struct VectorTileLineSymbol {
169171 /// Width of the line in pixels.
170- pub width : ExprDeser ,
172+ pub width : NumExpr ,
171173 /// Color of the line in pixels.
172- pub stroke_color : ExprDeser ,
174+ pub stroke_color : ColorExpr ,
173175}
174176
175177impl VectorTileLineSymbol {
176178 pub ( crate ) fn to_paint ( & self , feature : & MvtFeature , view : ExprView ) -> Option < LinePaint > {
177179 Some ( LinePaint {
178- color : self . stroke_color . eval ( feature, view) . as_color ( ) ?,
179- width : self . width . eval ( feature, view) . as_number ( ) ?,
180+ color : self . stroke_color . eval ( feature, view) ?,
181+ width : self . width . eval ( feature, view) ?,
180182 offset : 0.0 ,
181183 line_cap : LineCap :: Butt ,
182184 } )
@@ -187,13 +189,13 @@ impl VectorTileLineSymbol {
187189#[ derive( Debug , Clone , Serialize , Deserialize , PartialEq ) ]
188190pub struct VectorTilePolygonSymbol {
189191 /// Color of the fill of polygon.
190- pub fill_color : ExprDeser ,
192+ pub fill_color : ColorExpr ,
191193}
192194
193195impl VectorTilePolygonSymbol {
194196 pub ( crate ) fn to_paint ( & self , feature : & MvtFeature , view : ExprView ) -> Option < PolygonPaint > {
195197 Some ( PolygonPaint {
196- color : self . fill_color . eval ( feature, view) . as_color ( ) ?,
198+ color : self . fill_color . eval ( feature, view) ?,
197199 } )
198200 }
199201}
@@ -214,10 +216,10 @@ pub struct VtTextStyle {
214216 /// Name of the font to use.
215217 pub font_family : Vec < String > ,
216218 /// Size of the font in pixels.
217- pub font_size : ExprDeser ,
219+ pub font_size : NumExpr ,
218220 /// Color of the font.
219221 #[ serde( default = "default_font_color_style" ) ]
220- pub font_color : ExprDeser ,
222+ pub font_color : ColorExpr ,
221223 /// Alignment of label along horizontal axis.
222224 #[ serde( default ) ]
223225 pub horizontal_alignment : HorizontalAlignment ,
@@ -232,10 +234,10 @@ pub struct VtTextStyle {
232234 pub style : FontStyle ,
233235 /// Width of the outline around the letters.
234236 #[ serde( default = "default_outline_width_style" ) ]
235- pub outline_width : ExprDeser ,
237+ pub outline_width : NumExpr ,
236238 /// Color of the outline around the letters.
237239 #[ serde( default = "default_outline_color_style" ) ]
238- pub outline_color : ExprDeser ,
240+ pub outline_color : ColorExpr ,
239241}
240242
241243impl VtTextStyle {
@@ -244,27 +246,27 @@ impl VtTextStyle {
244246 pub fn get_value ( self , feature : & MvtFeature , view : ExprView ) -> Option < TextStyle > {
245247 Some ( TextStyle {
246248 font_family : self . font_family ,
247- font_size : self . font_size . eval ( feature, view) . as_number ( ) ? as f32 ,
248- font_color : self . font_color . eval ( feature, view) . as_color ( ) ?,
249+ font_size : self . font_size . eval ( feature, view) ? as f32 ,
250+ font_color : self . font_color . eval ( feature, view) ?,
249251 horizontal_alignment : self . horizontal_alignment ,
250252 vertical_alignment : self . vertical_alignment ,
251253 weight : self . weight ,
252254 style : self . style ,
253- outline_width : self . outline_width . eval ( feature, view) . as_number ( ) ? as f32 ,
254- outline_color : self . outline_color . eval ( feature, view) . as_color ( ) ?,
255+ outline_width : self . outline_width . eval ( feature, view) ? as f32 ,
256+ outline_color : self . outline_color . eval ( feature, view) ?,
255257 } )
256258 }
257259}
258260
259- fn default_font_color_style ( ) -> ExprDeser {
261+ fn default_font_color_style ( ) -> ColorExpr {
260262 Color :: BLACK . into ( )
261263}
262264
263- fn default_outline_color_style ( ) -> ExprDeser {
265+ fn default_outline_color_style ( ) -> ColorExpr {
264266 Color :: TRANSPARENT . into ( )
265267}
266268
267- fn default_outline_width_style ( ) -> ExprDeser {
269+ fn default_outline_width_style ( ) -> NumExpr {
268270 0.0 . into ( )
269271}
270272
0 commit comments