From 19d83d45460c69a4aa61c27777201983ac5fdea5 Mon Sep 17 00:00:00 2001 From: Antoine Beyeler Date: Wed, 13 Nov 2024 14:47:35 +0100 Subject: [PATCH] Remember the last center position in the map view --- .../re_space_view_map/src/map_space_view.rs | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/crates/viewer/re_space_view_map/src/map_space_view.rs b/crates/viewer/re_space_view_map/src/map_space_view.rs index 694f0eaf42c2..d571cff601e1 100644 --- a/crates/viewer/re_space_view_map/src/map_space_view.rs +++ b/crates/viewer/re_space_view_map/src/map_space_view.rs @@ -25,17 +25,33 @@ use re_viewport_blueprint::ViewProperty; use crate::map_overlays; use crate::visualizers::{update_span, GeoLineStringsVisualizer, GeoPointsVisualizer}; -#[derive(Default)] pub struct MapSpaceViewState { tiles: Option, map_memory: MapMemory, selected_provider: MapProvider, + last_center_position: walkers::Position, + /// Because `re_renderer` can have varying, multiple frames of delay, we must keep track of the /// last picked results for when picking results is not available on a given frame. last_gpu_picking_result: Option, } +impl Default for MapSpaceViewState { + fn default() -> Self { + Self { + tiles: None, + map_memory: Default::default(), + selected_provider: Default::default(), + + // default to Rerun HQ whenever we have no data (either now or historically) to provide + // a better location + last_center_position: walkers::Position::from_lat_lon(59.319224, 18.075514), + last_gpu_picking_result: None, + } + } +} + impl MapSpaceViewState { // This method ensures that tiles is initialized and returns mutable references to tiles and map_memory. pub fn ensure_and_get_mut_refs( @@ -213,10 +229,10 @@ Displays geospatial primitives on a map. update_span(&mut span, geo_points_visualizer.span()); update_span(&mut span, geo_line_strings_visualizers.span()); - let default_center_position = span - .as_ref() - .map(|span| span.center()) - .unwrap_or(walkers::Position::from_lat_lon(59.319224, 18.075514)); // Rerun HQ + if let Some(span) = &span { + state.last_center_position = span.center(); + } + let default_center_position = state.last_center_position; let blueprint_zoom_level = map_zoom .component_or_empty::()?