Skip to content

Commit d3743e3

Browse files
committed
feat: Convert ML filters to Galileo
Support for some widely used filters in Maplibre layers. Implemented operators are `==, !=, >, >=, <, <=, has, !has, in, !in, all`. Only comparing literal values to feature properties is implemented.
1 parent 168b4af commit d3743e3

5 files changed

Lines changed: 238 additions & 37 deletions

File tree

galileo-maplibre/src/layer/mod.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub(crate) const UNSUPPORTED: &str = "[maplibre:unsupported]";
2020
/// Usage: `log_unsupported!(layer.paint.some_field);`
2121
///
2222
/// The field path is used as the property name in the message, so no extra string is needed.
23-
macro_rules! log_unsupported {
23+
macro_rules! log_unsupported_field {
2424
($field:expr) => {
2525
if $field.is_some() {
2626
log::debug!(
@@ -32,7 +32,18 @@ macro_rules! log_unsupported {
3232
};
3333
}
3434

35+
macro_rules! log_unsupported {
36+
($field:expr) => {
37+
log::debug!(
38+
"{} '{}' is not supported yet; ignored",
39+
$crate::layer::UNSUPPORTED,
40+
stringify!($field),
41+
);
42+
};
43+
}
44+
3545
pub(crate) use log_unsupported;
46+
pub(crate) use log_unsupported_field;
3647

3748
/// A Galileo [`Layer`] that renders a Maplibre style definition.
3849
///

galileo-maplibre/src/layer/vector_tile.rs

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use galileo::layer::vector_tile_layer::style::{
1414
use galileo::tile_schema::{TileSchema, TileSchemaBuilder, VerticalDirection};
1515
use serde::Deserialize;
1616

17-
use crate::layer::{UNSUPPORTED, log_unsupported};
17+
use crate::layer::{UNSUPPORTED, log_unsupported_field};
1818
use crate::style::color::MlColor;
1919
use crate::style::layer::{FillLayer, Layer as MaplibreStyleLayer, LineLayer};
2020
use crate::style::source::{TileScheme, VectorSource};
@@ -188,6 +188,10 @@ fn build_rules(layers: &[&MaplibreStyleLayer], tile_schema: &TileSchema) -> Vec<
188188
let mut rules = Vec::new();
189189
for &layer in layers {
190190
match layer {
191+
MaplibreStyleLayer::Background(_) => {
192+
// Handled by `get_background` function
193+
continue;
194+
}
191195
MaplibreStyleLayer::Fill(fill) => {
192196
if let Some(rule) = fill_rule(fill, tile_schema) {
193197
rules.push(rule);
@@ -236,26 +240,31 @@ fn fill_rule(fill: &FillLayer, tile_schema: &TileSchema) -> Option<StyleRule> {
236240
let fill_opacity = &fill.paint.fill_opacity;
237241
let color = get_color_value(fill_color, fill_opacity)?;
238242

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);
243+
log_unsupported_field!(fill.paint.fill_antialias);
244+
log_unsupported_field!(fill.paint.fill_outline_color);
245+
log_unsupported_field!(fill.paint.fill_pattern);
246+
log_unsupported_field!(fill.paint.fill_translate);
247+
log_unsupported_field!(fill.paint.fill_translate_anchor);
248+
log_unsupported_field!(fill.paint.fill_emissive_strength);
245249

246250
let min_resolution = fill
247251
.maxzoom
248252
.and_then(|lod| tile_schema.lod_resolution(lod.round() as u32));
249253
let max_resolution = fill
250254
.minzoom
251255
.and_then(|lod| tile_schema.lod_resolution(lod.round() as u32));
256+
let filter = fill
257+
.filter
258+
.as_ref()
259+
.map(|v| v.to_prop_filters())
260+
.unwrap_or_default();
252261

253262
Some(StyleRule {
254263
layer_name: Some(source_layer),
255264
symbol: VectorTileSymbol::Polygon(VectorTilePolygonSymbol { fill_color: color }),
256265
min_resolution,
257266
max_resolution,
258-
..Default::default()
267+
properties: filter,
259268
})
260269
}
261270

@@ -269,14 +278,14 @@ fn line_rule(line: &LineLayer, tile_schema: &TileSchema) -> Option<StyleRule> {
269278
return None;
270279
}
271280

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);
281+
log_unsupported_field!(line.paint.line_blur);
282+
log_unsupported_field!(line.paint.line_gap_width);
283+
log_unsupported_field!(line.paint.line_gradient);
284+
log_unsupported_field!(line.paint.line_pattern);
285+
log_unsupported_field!(line.paint.line_translate);
286+
log_unsupported_field!(line.paint.line_translate_anchor);
287+
log_unsupported_field!(line.paint.line_emissive_strength);
288+
log_unsupported_field!(line.paint.line_offset);
280289

281290
let source_layer = match &line.source_layer {
282291
Some(l) => l.clone(),
@@ -301,6 +310,11 @@ fn line_rule(line: &LineLayer, tile_schema: &TileSchema) -> Option<StyleRule> {
301310
let max_resolution = line
302311
.minzoom
303312
.and_then(|lod| tile_schema.lod_resolution(lod.round() as u32));
313+
let filter = line
314+
.filter
315+
.as_ref()
316+
.map(|v| v.to_prop_filters())
317+
.unwrap_or_default();
304318

305319
Some(StyleRule {
306320
layer_name: Some(source_layer),
@@ -310,7 +324,7 @@ fn line_rule(line: &LineLayer, tile_schema: &TileSchema) -> Option<StyleRule> {
310324
}),
311325
min_resolution,
312326
max_resolution,
313-
..Default::default()
327+
properties: filter,
314328
})
315329
}
316330

0 commit comments

Comments
 (0)