Skip to content

Commit 1429e88

Browse files
authored
* feat(cache): add default remove_parameters_modifier function
1 parent 64e4853 commit 1429e88

File tree

5 files changed

+13
-16
lines changed

5 files changed

+13
-16
lines changed

galileo/examples/raster_tiles_switch.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! This example shows how to switch tile layers at runtime.
22
3+
use galileo::layer::data_provider::remove_parameters_modifier;
34
use galileo::layer::raster_tile_layer::RasterTileLayerBuilder;
45
use galileo::layer::RasterTileLayer;
56
use galileo::tile_schema::TileIndex;
@@ -85,11 +86,7 @@ fn build_layer(tile_id: &str, messenger: Option<impl Messenger + 'static>) -> Ra
8586
y = index.y
8687
)
8788
})
88-
.with_file_cache_modifier_checked(
89-
".tile_cache",
90-
// Remove query parameters from path if they exist
91-
Box::new(|path| path.split('?').next().unwrap_or(path).to_string()),
92-
);
89+
.with_file_cache_modifier_checked(".tile_cache", Box::new(remove_parameters_modifier));
9390

9491
if let Some(messenger) = messenger {
9592
builder = builder.with_messenger(messenger);

galileo/examples/vector_tiles.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::sync::Arc;
44

55
use egui::FontDefinitions;
66
use galileo::control::{EventPropagation, MouseButton, UserEvent, UserEventHandler};
7+
use galileo::layer::data_provider::remove_parameters_modifier;
78
use galileo::layer::vector_tile_layer::style::VectorTileStyle;
89
use galileo::layer::vector_tile_layer::VectorTileLayerBuilder;
910
use galileo::layer::VectorTileLayer;
@@ -88,11 +89,7 @@ pub(crate) fn run() {
8889
})
8990
.with_style(style)
9091
.with_tile_schema(tile_schema())
91-
.with_file_cache_modifier_checked(
92-
".tile_cache",
93-
// Remove query parameters from path if they exist
94-
Box::new(|path| path.split('?').next().unwrap_or(path).to_string()),
95-
)
92+
.with_file_cache_modifier_checked(".tile_cache", Box::new(remove_parameters_modifier))
9693
.with_attribution(
9794
"© MapTiler© OpenStreetMap contributors".to_string(),
9895
"https://www.maptiler.com/copyright/".to_string(),

galileo/examples/vector_tiles_labels.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! This examples shows how to render labels for vector tile points.
22
3+
use galileo::layer::data_provider::remove_parameters_modifier;
34
use galileo::layer::vector_tile_layer::style::{
45
StyleRule, VectorTileLabelSymbol, VectorTileStyle, VectorTileSymbol,
56
};
@@ -31,11 +32,7 @@ pub(crate) fn run() {
3132
y = index.y
3233
)
3334
})
34-
.with_file_cache_modifier_checked(
35-
".tile_cache",
36-
// Remove query parameters from path if they exist
37-
Box::new(|path| path.split('?').next().unwrap_or(path).to_string()),
38-
)
35+
.with_file_cache_modifier_checked(".tile_cache", Box::new(remove_parameters_modifier))
3936
.with_style(default_style())
4037
.with_tile_schema(tile_schema())
4138
.with_attribution(

galileo/src/layer/data_provider/file_cache.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ use crate::layer::data_provider::PersistentCacheController;
99
/// Function to modify the default file path of the cache
1010
pub type FileCachePathModifier = dyn Fn(&str) -> String + Send + Sync;
1111

12+
/// Modifier to remove parameters from file path.
13+
/// Can be used as a [`FileCachePathModifier`].
14+
pub fn remove_parameters_modifier(path: &str) -> String {
15+
path.split('?').next().unwrap_or(path).to_owned()
16+
}
17+
1218
/// Stores the cached data as a set of files in the specified folder. It generates file names from the given urls.
1319
///
1420
/// Currently, there is no eviction mechanism.

galileo/src/layer/data_provider/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Data sources for layers.
22
33
mod file_cache;
4-
pub use file_cache::{FileCacheController, FileCachePathModifier};
4+
pub use file_cache::{remove_parameters_modifier, FileCacheController, FileCachePathModifier};
55
use maybe_sync::{MaybeSend, MaybeSync};
66

77
use crate::error::GalileoError;

0 commit comments

Comments
 (0)