Skip to content

Commit

Permalink
Remember the last center position in the map view (#8120)
Browse files Browse the repository at this point in the history
### What

When ever we compute a center position from the data, we keep it around
in the view state such that we can use it should the data suddenly
disappear (aka. time cursor to before data was born, or empty range
visible history).

Part of:
- #8109 


https://github.com/user-attachments/assets/f460c427-4407-4d0f-9a51-922031d37a19


### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested the web demo (if applicable):
* Using examples from latest `main` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/8120?manifest_url=https://app.rerun.io/version/main/examples_manifest.json)
* Using full set of examples from `nightly` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/8120?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json)
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG
* [x] If applicable, add a new check to the [release
checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)!
* [x] If have noted any breaking changes to the log API in
`CHANGELOG.md` and the migration guide

- [PR Build Summary](https://build.rerun.io/pr/8120)
- [Recent benchmark results](https://build.rerun.io/graphs/crates.html)
- [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)

To run all checks from `main`, comment on the PR with `@rerun-bot
full-check`.

To deploy documentation changes immediately after merging this PR, add
the `deploy docs` label.
  • Loading branch information
abey79 authored Nov 13, 2024
1 parent 72795eb commit 7841b5e
Showing 1 changed file with 21 additions and 5 deletions.
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

0 comments on commit 7841b5e

Please sign in to comment.