Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remember the last center position in the map view #8120

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions crates/viewer/re_space_view_map/src/map_space_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<HttpTiles>,
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<InstancePathHash>,
}

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(
Expand Down Expand Up @@ -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::<ZoomLevel>()?
Expand Down
Loading