Skip to main content

mln_map/
map_snapshot.rs

1//! A copy of a map's state, which [`Map::snapshot`](crate::Map::snapshot)
2//! takes.
3
4use mln_map_types::{BoundOptions, FreeCameraOptions, MapDebugOptions, MapView, TileLodMode};
5use mln_util::geo::LatLngBounds;
6use mln_util::vectors::{Vec3, Vec4};
7
8/// A map's state at one moment.
9#[derive(Clone, Copy, Debug, PartialEq)]
10pub struct MapSnapshot {
11    /// Grows with each change to the map's state. Two snapshots with the same
12    /// generation show the same state.
13    pub generation: u64,
14    /// Counts the updates that the map has sent to its renderer. A frame shows
15    /// the map's state as of this snapshot once it renders this update.
16    pub update_generation: u64,
17    pub debug: MapDebugOptions,
18    /// Whether the style and every resource that the view needs have loaded,
19    /// and the renderer has drawn them.
20    pub fully_loaded: bool,
21    pub rendering_stats_view_enabled: bool,
22    pub gesture_in_progress: bool,
23    /// Whether any camera command is still animating.
24    pub transition_in_progress: bool,
25    pub tile: TileSettings,
26    pub bounds: CameraBounds,
27    pub free_camera: FreeCamera,
28    pub view: MapView,
29    /// Whether the map draws as a globe, alone or blending into Mercator.
30    pub globe_rendering: bool,
31    /// The setting of [`Map::set_globe_free_bearing`](crate::Map::set_globe_free_bearing).
32    pub globe_free_bearing: bool,
33}
34
35/// How a map picks the tiles to load.
36#[derive(Clone, Copy, Debug, PartialEq)]
37pub struct TileSettings {
38    /// How many zoom levels lower the map also loads tiles for, so it can show
39    /// a coarse map while the current tiles load.
40    pub prefetch_zoom_delta: u8,
41    /// The radius around the view point, in tiles, that keeps full detail.
42    pub lod_min_radius: f64,
43    /// Scales the distance to the view point. Above 1 lowers the detail.
44    pub lod_scale: f64,
45    /// The pitch, in degrees, above which the map lowers the detail.
46    pub lod_pitch_threshold: f64,
47    /// Zoom levels to add for picking the detail. Below 0 loads fewer tiles.
48    pub lod_zoom_shift: f64,
49    pub lod_mode: TileLodMode,
50}
51
52/// All the limits on a map's camera.
53#[derive(Clone, Copy, Debug, PartialEq)]
54pub struct CameraBounds {
55    /// The area that the camera's center stays within, or `None` when no area
56    /// limits it.
57    pub bounds: Option<LatLngBounds>,
58    pub min_zoom: f64,
59    pub max_zoom: f64,
60    /// The lowest pitch, in degrees.
61    pub min_pitch: f64,
62    /// The highest pitch, in degrees.
63    pub max_pitch: f64,
64}
65
66impl From<CameraBounds> for BoundOptions {
67    /// Options that set every limit.
68    fn from(bounds: CameraBounds) -> Self {
69        BoundOptions {
70            bounds: Some(bounds.bounds.unwrap_or_else(LatLngBounds::infinite)),
71            min_zoom: Some(bounds.min_zoom),
72            max_zoom: Some(bounds.max_zoom),
73            min_pitch: Some(bounds.min_pitch),
74            max_pitch: Some(bounds.max_pitch),
75        }
76    }
77}
78
79/// A camera's whole position and orientation in three dimensions.
80#[derive(Clone, Copy, Debug, Default, PartialEq)]
81pub struct FreeCamera {
82    /// The position in Web Mercator units, where the world is 1 wide, (0, 0)
83    /// is its northwest corner and (1, 1) its southeast corner. `z` is the
84    /// altitude in the same units.
85    pub position: Vec3,
86    /// The rotation from looking straight down with north at the top of the
87    /// screen, as a unit quaternion `[x, y, z, w]`.
88    pub orientation: Vec4,
89}
90
91impl From<FreeCamera> for FreeCameraOptions {
92    /// Options that set the position and the orientation.
93    fn from(camera: FreeCamera) -> Self {
94        FreeCameraOptions { position: Some(camera.position), orientation: Some(camera.orientation) }
95    }
96}