@@ -9,14 +9,14 @@ use galileo::layer::vector_tile_layer::expressions::{
99 StepValue , StyleValue ,
1010} ;
1111use galileo:: layer:: vector_tile_layer:: style:: {
12- StyleRule , VectorTilePolygonSymbol , VectorTileStyle , VectorTileSymbol ,
12+ StyleRule , VectorTileLineSymbol , VectorTilePolygonSymbol , VectorTileStyle , VectorTileSymbol ,
1313} ;
1414use galileo:: tile_schema:: { TileSchema , TileSchemaBuilder , VerticalDirection } ;
1515use serde:: Deserialize ;
1616
17- use crate :: layer:: UNSUPPORTED ;
17+ use crate :: layer:: { UNSUPPORTED , log_unsupported } ;
1818use crate :: style:: color:: MlColor ;
19- use crate :: style:: layer:: { FillLayer , Layer as MaplibreStyleLayer } ;
19+ use crate :: style:: layer:: { FillLayer , Layer as MaplibreStyleLayer , LineLayer } ;
2020use crate :: style:: source:: { TileScheme , VectorSource } ;
2121use crate :: style:: value:: { FunctionStop , MlStyleValue } ;
2222
@@ -92,22 +92,19 @@ fn get_background(layers: &[&MaplibreStyleLayer]) -> StyleValue<Color> {
9292 }
9393 } ;
9494
95- let Some ( color) = & layer. paint . background_color else {
96- return DEFAULT_TILE_BACKGROUND ;
97- } ;
98-
99- get_color_value ( color, layer. paint . background_opacity . as_ref ( ) )
100- . unwrap_or ( DEFAULT_TILE_BACKGROUND )
95+ get_color_value (
96+ & layer. paint . background_color ,
97+ & layer. paint . background_opacity ,
98+ )
99+ . unwrap_or ( DEFAULT_TILE_BACKGROUND )
101100}
102101
103102fn get_color_value (
104103 color : & MlStyleValue < MlColor > ,
105- opacity : Option < & MlStyleValue < f64 > > ,
104+ opacity : & MlStyleValue < f64 > ,
106105) -> Option < StyleValue < Color > > {
107106 let galileo_color = get_galileo_value ( color) ?;
108- let galileo_opacity = opacity
109- . and_then ( get_galileo_value)
110- . unwrap_or ( StyleValue :: Simple ( 1.0 ) ) ;
107+ let galileo_opacity = get_galileo_value ( opacity) . unwrap_or ( StyleValue :: Simple ( 1.0 ) ) ;
111108
112109 match ( galileo_color, galileo_opacity) {
113110 ( StyleValue :: Simple ( c) , StyleValue :: Simple ( o) ) => Some ( ( * c) . with_alpha_float ( o) . into ( ) ) ,
@@ -194,11 +191,11 @@ fn build_rules(layers: &[&MaplibreStyleLayer], tile_schema: &TileSchema) -> Vec<
194191 MaplibreStyleLayer :: Fill ( fill) => {
195192 if let Some ( rule) = fill_rule ( fill, tile_schema) {
196193 rules. push ( rule) ;
197- log :: debug! (
198- "Maplibre layer '{}' of type '{}' is added as a VT style rule" ,
199- layer . id ( ) ,
200- layer . type_name ( )
201- ) ;
194+ }
195+ }
196+ MaplibreStyleLayer :: Line ( line ) => {
197+ if let Some ( rule ) = line_rule ( line , tile_schema ) {
198+ rules . push ( rule ) ;
202199 }
203200 }
204201 other => {
@@ -208,8 +205,16 @@ fn build_rules(layers: &[&MaplibreStyleLayer], tile_schema: &TileSchema) -> Vec<
208205 other. type_name( ) ,
209206 other. id( ) ,
210207 ) ;
208+
209+ continue ;
211210 }
212211 }
212+
213+ log:: trace!(
214+ "Maplibre layer '{}' of type '{}' is added as a VT style rule" ,
215+ layer. id( ) ,
216+ layer. type_name( )
217+ ) ;
213218 }
214219 rules
215220}
@@ -227,9 +232,16 @@ fn fill_rule(fill: &FillLayer, tile_schema: &TileSchema) -> Option<StyleRule> {
227232 }
228233 } ;
229234
230- let fill_color = fill. paint . fill_color . as_ref ( ) ? ;
235+ let fill_color = & fill. paint . fill_color ;
231236 let fill_opacity = & fill. paint . fill_opacity ;
232- let color = get_color_value ( fill_color, fill_opacity. as_ref ( ) ) ?;
237+ let color = get_color_value ( fill_color, fill_opacity) ?;
238+
239+ log_unsupported ! ( fill. paint. fill_antialias) ;
240+ log_unsupported ! ( fill. paint. fill_outline_color) ;
241+ log_unsupported ! ( fill. paint. fill_pattern) ;
242+ log_unsupported ! ( fill. paint. fill_translate) ;
243+ log_unsupported ! ( fill. paint. fill_translate_anchor) ;
244+ log_unsupported ! ( fill. paint. fill_emissive_strength) ;
233245
234246 let min_resolution = fill
235247 . maxzoom
@@ -247,6 +259,61 @@ fn fill_rule(fill: &FillLayer, tile_schema: &TileSchema) -> Option<StyleRule> {
247259 } )
248260}
249261
262+ /// Converts a [`LineLayer`] to a [`StyleRule`], or logs and returns `None` if unsupported.
263+ fn line_rule ( line : & LineLayer , tile_schema : & TileSchema ) -> Option < StyleRule > {
264+ if line. paint . line_dasharray . is_some ( ) {
265+ log:: debug!(
266+ "{UNSUPPORTED} Line dasharray is not supported yet; skipping layer {}" ,
267+ line. id
268+ ) ;
269+ return None ;
270+ }
271+
272+ log_unsupported ! ( line. paint. line_blur) ;
273+ log_unsupported ! ( line. paint. line_gap_width) ;
274+ log_unsupported ! ( line. paint. line_gradient) ;
275+ log_unsupported ! ( line. paint. line_pattern) ;
276+ log_unsupported ! ( line. paint. line_translate) ;
277+ log_unsupported ! ( line. paint. line_translate_anchor) ;
278+ log_unsupported ! ( line. paint. line_emissive_strength) ;
279+ log_unsupported ! ( line. paint. line_offset) ;
280+
281+ let source_layer = match & line. source_layer {
282+ Some ( l) => l. clone ( ) ,
283+ None => {
284+ log:: debug!(
285+ "{UNSUPPORTED} Line layer '{}' has no source-layer; skipping." ,
286+ line. id
287+ ) ;
288+ return None ;
289+ }
290+ } ;
291+
292+ let stroke_color = & line. paint . line_color ;
293+ let stroke_opacity = & line. paint . line_opacity ;
294+ let color = get_color_value ( stroke_color, stroke_opacity) . unwrap_or ( Color :: TRANSPARENT . into ( ) ) ;
295+ let stroke_width = & line. paint . line_width ;
296+ let width = get_galileo_value ( stroke_width) . unwrap_or ( 1.0 . into ( ) ) ;
297+
298+ let min_resolution = line
299+ . maxzoom
300+ . and_then ( |lod| tile_schema. lod_resolution ( lod. round ( ) as u32 ) ) ;
301+ let max_resolution = line
302+ . minzoom
303+ . and_then ( |lod| tile_schema. lod_resolution ( lod. round ( ) as u32 ) ) ;
304+
305+ Some ( StyleRule {
306+ layer_name : Some ( source_layer) ,
307+ symbol : VectorTileSymbol :: Line ( VectorTileLineSymbol {
308+ width,
309+ stroke_color : color,
310+ } ) ,
311+ min_resolution,
312+ max_resolution,
313+ ..Default :: default ( )
314+ } )
315+ }
316+
250317/// Converts WGS84 bounding box `[west, south, east, north]` (degrees) to a Web Mercator [`Rect`]
251318/// in projected meters, suitable for use with [`TileSchemaBuilder::tile_bounds`].
252319fn wgs84_bounds_to_mercator ( bounds : [ f64 ; 4 ] ) -> Option < Rect > {
0 commit comments