Skip to content

Commit 9aa1c0d

Browse files
committed
chore: Decode ML label placement
Decode the symbol-placement value and notify that line labels are not supported yet.
1 parent 73ff690 commit 9aa1c0d

2 files changed

Lines changed: 34 additions & 11 deletions

File tree

galileo-maplibre/src/layer/vector_tile.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use serde::Deserialize;
1717

1818
use crate::layer::{UNSUPPORTED, log_unsupported_field};
1919
use crate::style::color::MlColor;
20+
use crate::style::layer::symbol::SymbolPlacement;
2021
use crate::style::layer::{FillLayer, Layer as MaplibreStyleLayer, LineLayer, SymbolLayer};
2122
use crate::style::source::{TileScheme, VectorSource};
2223
use crate::style::value::{FunctionStop, FunctionType, MlStyleValue};
@@ -271,7 +272,6 @@ fn symbol_rule(symbol: &SymbolLayer, tile_schema: &TileSchema) -> Option<StyleRu
271272
)?;
272273

273274
let (font_family, weight, font_style) = parse_ml_fonts(&symbol.layout.text_font);
274-
dbg!(&font_color);
275275

276276
let style = VtTextStyle {
277277
font_family,
@@ -295,16 +295,25 @@ fn symbol_rule(symbol: &SymbolLayer, tile_schema: &TileSchema) -> Option<StyleRu
295295
outline_color: outline_color.into(),
296296
};
297297

298-
Some(StyleRule {
299-
layer_name: Some(source_layer),
300-
symbol: VectorTileSymbol::Label(VectorTileLabelSymbol {
301-
pattern: symbol.layout.text_field.clone().unwrap_or_default(),
302-
text_style: style,
298+
match symbol.layout.symbol_placement {
299+
Some(SymbolPlacement::Point) | None => Some(StyleRule {
300+
layer_name: Some(source_layer),
301+
symbol: VectorTileSymbol::Label(VectorTileLabelSymbol {
302+
pattern: symbol.layout.text_field.clone().unwrap_or_default(),
303+
text_style: style,
304+
}),
305+
min_resolution,
306+
max_resolution,
307+
filter: filter.map(Into::into),
303308
}),
304-
min_resolution,
305-
max_resolution,
306-
filter: filter.map(Into::into),
307-
})
309+
Some(SymbolPlacement::Line) | Some(SymbolPlacement::LineCenter) => {
310+
log::debug!(
311+
"{UNSUPPORTED} Placing labels along lines is not supported yet. Layer '{}' is skipped.",
312+
symbol.id
313+
);
314+
None
315+
}
316+
}
308317
}
309318

310319
/// Parses Maplibre `text-font` entries into a font family list, [`FontWeight`], and [`FontStyle`].

galileo-maplibre/src/style/layer/symbol.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,20 @@ impl Default for SymbolPaint {
140140
}
141141
}
142142

143+
/// Rule for placing a a text or symbol label.
144+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
145+
pub enum SymbolPlacement {
146+
/// At position of a point geometry.
147+
#[serde(rename = "point")]
148+
Point,
149+
/// Along a line.
150+
#[serde(rename = "line")]
151+
Line,
152+
/// At a center point of line or polygon geometry.
153+
#[serde(rename = "line-center")]
154+
LineCenter,
155+
}
156+
143157
/// Layout properties for a `symbol` layer.
144158
#[derive(Debug, Clone, PartialEq, Deserialize, Default)]
145159
pub struct SymbolLayout {
@@ -149,7 +163,7 @@ pub struct SymbolLayout {
149163

150164
/// Label placement relative to its geometry. Supports expressions.
151165
#[serde(rename = "symbol-placement", skip_serializing_if = "Option::is_none")]
152-
pub symbol_placement: Option<Value>,
166+
pub symbol_placement: Option<SymbolPlacement>,
153167

154168
/// Distance between two symbol anchors. Supports expressions.
155169
#[serde(rename = "symbol-spacing", skip_serializing_if = "Option::is_none")]

0 commit comments

Comments
 (0)