🔧 Rebuild indices on zoom change, not pan

This commit is contained in:
Elena Torro
2025-12-09 10:41:36 +01:00
parent 0889df8e08
commit b8feb6374d
2 changed files with 15 additions and 4 deletions

View File

@@ -251,11 +251,16 @@ pub extern "C" fn set_view_end() {
state.render_state.options.set_fast_mode(false);
// We can have renders in progress
state.render_state.cancel_animation_frame();
// Only rebuild tile indices when zoom has changed.
// During pan-only operations, shapes stay in the same tiles
// because tile_size = 1/scale * TILE_SIZE (depends only on zoom).
if state.render_state.zoom_changed() {
if state.render_state.options.is_profile_rebuild_tiles() {
state.rebuild_tiles();
} else {
state.rebuild_tiles_shallow();
}
}
});
}

View File

@@ -2057,6 +2057,12 @@ impl RenderState {
self.cached_viewbox.zoom() * self.options.dpr()
}
/// Returns true if the zoom level has changed since the last cached viewbox.
/// Used to optimize pan-only operations where tile indices don't need to be rebuilt.
pub fn zoom_changed(&self) -> bool {
(self.viewbox.zoom - self.cached_viewbox.zoom).abs() > f32::EPSILON
}
pub fn mark_touched(&mut self, uuid: Uuid) {
self.touched_ids.insert(uuid);
}