Skip to content

Commit 907e047

Browse files
committed
fix(regression): Fix raster tiles fade in setting
Fix configuring fade in duration for raster tile layers.
1 parent 10b1f70 commit 907e047

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

galileo/src/layer/raster_tile_layer/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ pub struct RasterTileLayer {
2626
tile_loader: Arc<dyn RasterTileLoader>,
2727
tile_container: Arc<TilesContainer<(), RasterTileProvider>>,
2828
tile_schema: TileSchema,
29-
fade_in_duration: Duration,
3029
messenger: Option<Arc<dyn Messenger>>,
3130
attribution: Option<Attribution>,
3231
}
@@ -35,13 +34,12 @@ impl std::fmt::Debug for RasterTileLayer {
3534
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3635
f.debug_struct("RasterTileLayer")
3736
.field("tile_schema", &self.tile_schema)
38-
.field("fade_in_duration", &self.fade_in_duration)
3937
.finish()
4038
}
4139
}
4240

4341
impl RasterTileLayer {
44-
/// Creates anew layer.
42+
/// Creates a new layer.
4543
pub fn new(
4644
tile_schema: TileSchema,
4745
tile_loader: impl RasterTileLoader + 'static,
@@ -54,7 +52,6 @@ impl RasterTileLayer {
5452
RasterTileProvider::new(tile_schema.clone()),
5553
)),
5654
tile_schema,
57-
fade_in_duration: Duration::from_millis(300),
5855
messenger,
5956
attribution: None,
6057
}
@@ -73,15 +70,14 @@ impl RasterTileLayer {
7370
RasterTileProvider::new(tile_schema.clone()),
7471
)),
7572
tile_schema,
76-
fade_in_duration: Duration::from_millis(300),
7773
messenger: messenger.map(|m| m.into()),
7874
attribution,
7975
}
8076
}
8177

8278
/// Sets fade in duration for newly loaded tiles.
8379
pub fn set_fade_in_duration(&mut self, duration: Duration) {
84-
self.fade_in_duration = duration;
80+
self.tile_container.set_fade_in_duration(duration);
8581
}
8682

8783
fn update_displayed_tiles(&self, view: &MapView, canvas: &dyn Canvas) {
@@ -168,6 +164,7 @@ impl Layer for RasterTileLayer {
168164
.filter_map(|v| {
169165
let tile_bbox = self.tile_schema.tile_bbox(v.index)?;
170166
let offset = Vector2::new(tile_bbox.x_min() as f32, tile_bbox.y_max() as f32);
167+
171168
Some(BundleToDraw::new(&*v.bundle, v.opacity, offset))
172169
})
173170
.collect();

galileo/src/layer/tiles.rs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::sync::atomic::{AtomicU64, Ordering};
12
use std::sync::Arc;
23
use std::time::Duration;
34

@@ -7,6 +8,8 @@ use crate::render::PackedBundle;
78
use crate::tile_schema::{TileIndex, WrappingTileIndex};
89
use crate::TileSchema;
910

11+
const DEFAULT_FADE_IN_DURATION: Duration = Duration::from_millis(300);
12+
1013
#[derive(Clone)]
1114
pub(crate) struct DisplayedTile<StyleId: Copy> {
1215
pub(crate) index: WrappingTileIndex,
@@ -34,6 +37,7 @@ where
3437
pub(crate) tiles: Mutex<Vec<DisplayedTile<StyleId>>>,
3538
tile_schema: TileSchema,
3639
pub(crate) tile_provider: Provider,
40+
pub fade_in_duration: AtomicU64,
3741
}
3842

3943
impl<StyleId, Provider> TilesContainer<StyleId, Provider>
@@ -46,6 +50,7 @@ where
4650
tiles: Default::default(),
4751
tile_schema,
4852
tile_provider,
53+
fade_in_duration: AtomicU64::new(DEFAULT_FADE_IN_DURATION.as_millis() as u64),
4954
}
5055
}
5156

@@ -60,7 +65,7 @@ where
6065
let mut to_substitute = vec![];
6166

6267
let now = web_time::Instant::now();
63-
let fade_in_time = self.fade_in_time();
68+
let fade_in_time = self.fade_in_duration();
6469
let mut requires_redraw = false;
6570

6671
for index in needed_indices {
@@ -70,9 +75,13 @@ where
7075
{
7176
if !displayed.is_opaque() {
7277
to_substitute.push(index);
73-
displayed.opacity = ((now.duration_since(displayed.displayed_at)).as_secs_f64()
74-
/ fade_in_time.as_secs_f64())
75-
.min(1.0) as f32;
78+
let fade_in_secs = fade_in_time.as_secs_f64();
79+
displayed.opacity = if fade_in_secs > 0.001 {
80+
((now.duration_since(displayed.displayed_at)).as_secs_f64() / fade_in_secs)
81+
.min(1.0) as f32
82+
} else {
83+
1.0
84+
};
7685
requires_redraw = true;
7786
}
7887

@@ -81,11 +90,12 @@ where
8190
match self.tile_provider.get_tile(index.into(), style_id) {
8291
None => to_substitute.push(index),
8392
Some(bundle) => {
93+
let opacity = if self.requires_animation() { 0.0 } else { 1.0 };
8494
needed_tiles.push(DisplayedTile {
8595
index,
8696
bundle,
8797
style_id,
88-
opacity: 0.0,
98+
opacity,
8999
displayed_at: now,
90100
});
91101
to_substitute.push(index);
@@ -126,7 +136,16 @@ where
126136
requires_redraw
127137
}
128138

129-
fn fade_in_time(&self) -> Duration {
130-
Duration::from_millis(300)
139+
pub fn fade_in_duration(&self) -> Duration {
140+
Duration::from_millis(self.fade_in_duration.load(Ordering::Relaxed))
141+
}
142+
143+
pub fn set_fade_in_duration(&self, duration: Duration) {
144+
self.fade_in_duration
145+
.store(duration.as_millis() as u64, Ordering::Relaxed);
146+
}
147+
148+
fn requires_animation(&self) -> bool {
149+
self.fade_in_duration.load(Ordering::Relaxed) > 1
131150
}
132151
}

0 commit comments

Comments
 (0)