Skip to content

Commit 12174d5

Browse files
shri-achaMaximkaaa
authored andcommitted
feat: replace max/min_zoom with resolution levels and resolution level checks
1 parent 01f7dd6 commit 12174d5

5 files changed

Lines changed: 21 additions & 5 deletions

File tree

galileo/examples/vector_tiles_labels.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ pub(crate) fn run() {
4343
let labels_style = VectorTileStyle {
4444
rules: vec![StyleRule {
4545
layer_name: None,
46+
max_resolution:None,
47+
min_resolution: None,
4648
properties: Default::default(),
4749
symbol: VectorTileSymbol::Label(VectorTileLabelSymbol {
4850
pattern: String::from("{name}"),

galileo/src/layer/vector_tile_layer/builder.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,8 @@ impl VectorTileLayerBuilder {
458458
rules: vec![
459459
StyleRule {
460460
layer_name: None,
461+
max_resolution: None,
462+
min_resolution: None,
461463
properties: Default::default(),
462464
symbol: VectorTileSymbol::Line(VectorTileLineSymbol {
463465
width: 1.0,
@@ -466,6 +468,8 @@ impl VectorTileLayerBuilder {
466468
},
467469
StyleRule {
468470
layer_name: None,
471+
max_resolution: None,
472+
min_resolution: None,
469473
properties: Default::default(),
470474
symbol: VectorTileSymbol::Polygon(VectorTilePolygonSymbol {
471475
fill_color: Color::GRAY,

galileo/src/layer/vector_tile_layer/style.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub struct VectorTileStyle {
2323

2424
impl VectorTileStyle {
2525
/// Get a rule for the given feature.
26-
pub fn get_style_rule(&self, layer_name: &str, feature: &MvtFeature) -> Option<&StyleRule> {
26+
pub fn get_style_rule(&self, layer_name: &str,resolution_level: f64, feature: &MvtFeature) -> Option<&StyleRule> {
2727
self.rules.iter().find(|&rule| {
2828
let correct_geometry_type = match feature.geometry {
2929
MvtGeometry::Point(_)
@@ -50,6 +50,12 @@ impl VectorTileStyle {
5050
if rule.layer_name.as_ref().is_some_and(|v| v != layer_name) {
5151
return false;
5252
}
53+
if rule.max_resolution.is_some_and(|v| v < resolution_level) {
54+
return false;
55+
}
56+
if rule.min_resolution.is_some_and(|v| v > resolution_level) {
57+
return false;
58+
}
5359

5460
let filter_check_passed = rule.properties.iter().all(|filter| {
5561
let value = feature.properties.get(&filter.property_name);
@@ -102,6 +108,10 @@ fn compare_numeric(a: &galileo_mvt::MvtValue, b: &str, cmp: impl Fn(f64, f64) ->
102108
pub struct StyleRule {
103109
/// If set, a feature must belong to the set layer. If not set, layer is not checked.
104110
pub layer_name: Option<String>,
111+
/// Determins the maximum resolution
112+
pub max_resolution: Option<f64>,
113+
/// Determins the minimum resolution
114+
pub min_resolution: Option<f64>,
105115
/// Specifies a set of attributes of a feature that must have the given values for this rule to be applied.
106116
#[serde(default)]
107117
pub properties: Vec<PropertyFilter>,
@@ -331,6 +341,8 @@ mod tests {
331341
fn serialize_with_bincode() {
332342
let rule = StyleRule {
333343
layer_name: None,
344+
min_resolution:None,
345+
max_resolution:None,
334346
properties: vec![],
335347
symbol: VectorTileSymbol::None,
336348
};

galileo/src/layer/vector_tile_layer/tile_provider/vt_processor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl VtProcessor {
5959

6060
for layer in mvt_tile.layers.iter().rev() {
6161
for feature in &layer.features {
62-
let Some(rule) = style.get_style_rule(&layer.name, feature) else {
62+
let Some(rule) = style.get_style_rule(&layer.name, lod_resolution, feature) else {
6363
continue;
6464
};
6565

galileo/src/tile_schema/schema.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ impl TileSchema {
5252
} else {
5353
None
5454
}
55-
}
56-
57-
/// Width of a single tile.
55+
} /// Width of a single tile.
5856
pub fn tile_width(&self) -> u32 {
5957
self.tile_width
6058
}

0 commit comments

Comments
 (0)