Skip to main content

mln_engine/map/
options.rs

1use std::time::Duration;
2
3use mln_style::size::Size;
4
5use crate::camera::{ConstrainMode, NorthOrientation};
6pub use crate::map_mode::MapMode;
7
8/// What a map does with a style image once no layer uses it.
9#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
10pub enum UnusedStyleImagePolicy {
11    /// Remove it from the style, unless the image sets `keep_unused`. A
12    /// layer that uses it again reports it missing with
13    /// [`MapEvent::StyleImageMissing`](crate::map::MapEvent::StyleImageMissing).
14    #[default]
15    Remove,
16    /// Keep it in the style.
17    Keep,
18}
19
20/// How a map renders and lays itself out.
21#[derive(Clone, Copy, Debug)]
22pub struct MapOptions {
23    /// Continuous by default, so the map renders as data arrives from the
24    /// network and reacts immediately to state changes.
25    pub map_mode: MapMode,
26    /// Limits how far the map can move off the world. `HeightOnly` by
27    /// default.
28    pub constrain_mode: ConstrainMode,
29    /// Which way north points on the screen. Upwards by default.
30    pub north_orientation: NorthOrientation,
31    /// Whether symbols collide across sources. On by default.
32    pub cross_source_collisions: bool,
33    /// The size of the map and its renderer backend.
34    pub size: Size,
35    /// 1 by default.
36    pub pixel_ratio: f32,
37    /// How long a continuous map's symbols fade in and out as placement
38    /// changes what shows, and its patterns cross-fade as the zoom crosses
39    /// an integer: placement runs again
40    /// once a fade has had this long, sooner while the map zooms out. By
41    /// default, the style's transition duration, with placement waiting at
42    /// least the default transition's 300 ms. Either way, nothing fades
43    /// until the map first goes idle, so what it shows first doesn't fade
44    /// in.
45    pub fade_duration: Option<Duration>,
46    /// What the map does with a style image once no layer uses it. By
47    /// default, it removes the image.
48    pub unused_style_image_policy: UnusedStyleImagePolicy,
49    /// Whether the center stands on the terrain, as
50    /// [`Viewport::center_clamped_to_ground`] describes. On by default.
51    ///
52    /// [`Viewport::center_clamped_to_ground`]: crate::camera::Viewport::center_clamped_to_ground
53    pub center_clamped_to_ground: bool,
54    /// How the map draws its terrain, for the map's lifetime.
55    pub terrain: TerrainOptions,
56}
57
58impl Default for MapOptions {
59    fn default() -> Self {
60        MapOptions {
61            map_mode: MapMode::Continuous,
62            constrain_mode: ConstrainMode::HeightOnly,
63            north_orientation: NorthOrientation::Upwards,
64            cross_source_collisions: true,
65            size: Size::new(64, 64),
66            pixel_ratio: 1.0,
67            fade_duration: None,
68            unused_style_image_policy: UnusedStyleImagePolicy::Remove,
69            center_clamped_to_ground: true,
70            terrain: TerrainOptions::default(),
71        }
72    }
73}
74
75/// How far the skirts that hang from the edges of terrain tiles reach down.
76/// Skirts hide the cracks where the edges of neighboring tiles don't meet,
77/// and show through where the layers draped over the terrain are
78/// translucent.
79#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
80pub enum TerrainSkirtLength {
81    /// A fifth of a tile's width at the map's zoom, in meters at the
82    /// equator, or in a registered projection in its meters per world unit.
83    #[default]
84    Auto,
85    /// No skirts.
86    None,
87}
88
89/// How a map draws its terrain, for the map's lifetime.
90#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
91pub struct TerrainOptions {
92    /// How far the skirts of terrain tiles reach down. `Auto` by default.
93    pub skirt_length: TerrainSkirtLength,
94    /// The most bytes of GPU memory the textures that the terrain drapes
95    /// its layers onto hold, with their mips and the depth and stencil they
96    /// draw with. Past it, the drapes of the tiles farthest from the view's
97    /// center take fewer texels, and look blurrier; no tile loses its
98    /// drape. `None`, the default, sets no limit: the drapes hold what the
99    /// view's tiles need.
100    pub drape_memory_limit: Option<u64>,
101}
102
103impl Default for TerrainOptions {
104    fn default() -> Self {
105        TerrainOptions { skirt_length: TerrainSkirtLength::Auto, drape_memory_limit: None }
106    }
107}