mln_engine/map/options.rs
1use mln_style::size::Size;
2
3use crate::camera::{ConstrainMode, NorthOrientation, ViewportMode};
4
5/// What a map does with a style image once no layer uses it.
6#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
7pub enum UnusedStyleImagePolicy {
8 /// Remove it from the style, unless the image sets `keep_unused`. A
9 /// layer that uses it again reports it missing with
10 /// [`MapEvent::StyleImageMissing`](crate::map::MapEvent::StyleImageMissing).
11 #[default]
12 Remove,
13 /// Keep it in the style.
14 Keep,
15}
16
17/// How a map renders and lays itself out.
18#[derive(Clone, Copy, Debug)]
19pub struct MapOptions {
20 /// Continuous by default, so the map renders as data arrives from the
21 /// network and reacts immediately to state changes.
22 pub map_mode: MapMode,
23 /// Limits how far the map can move off the world. `HeightOnly` by
24 /// default.
25 pub constrain_mode: ConstrainMode,
26 /// Can flip the vertical orientation of the map, as some devices use an
27 /// inverted orientation.
28 pub viewport_mode: ViewportMode,
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 /// Whether MLT vector tiles decode streams encoded with FastPFOR. Off
38 /// by default.
39 pub fast_pfor_enabled: bool,
40 /// What the map does with a style image once no layer uses it. By
41 /// default, it removes the image.
42 pub unused_style_image_policy: UnusedStyleImagePolicy,
43 /// Whether the center stands on the terrain, as
44 /// [`Viewport::center_clamped_to_ground`] describes. On by default.
45 ///
46 /// [`Viewport::center_clamped_to_ground`]: crate::camera::Viewport::center_clamped_to_ground
47 pub center_clamped_to_ground: bool,
48 /// How the map draws its terrain, for the map's lifetime.
49 pub terrain: TerrainOptions,
50}
51
52impl Default for MapOptions {
53 fn default() -> Self {
54 MapOptions {
55 map_mode: MapMode::Continuous,
56 constrain_mode: ConstrainMode::HeightOnly,
57 viewport_mode: ViewportMode::Default,
58 north_orientation: NorthOrientation::Upwards,
59 cross_source_collisions: true,
60 size: Size::new(64, 64),
61 pixel_ratio: 1.0,
62 fast_pfor_enabled: false,
63 unused_style_image_policy: UnusedStyleImagePolicy::Remove,
64 center_clamped_to_ground: true,
65 terrain: TerrainOptions::default(),
66 }
67 }
68}
69
70#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, mln_wire::Wire)]
71#[repr(u32)]
72pub enum MapMode {
73 /// continually updating map
74 #[default]
75 Continuous,
76 /// a once-off still image of an arbitrary viewport
77 Static,
78 /// a once-off still image of a single tile
79 Tile,
80}
81
82/// How far the skirts that hang from the edges of terrain tiles reach down.
83/// Skirts hide the cracks where the edges of neighboring tiles don't meet,
84/// and show through where the layers draped over the terrain are
85/// translucent.
86#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
87pub enum TerrainSkirtLength {
88 /// A fifth of a tile's width at the map's zoom, in meters at the
89 /// equator.
90 #[default]
91 Auto,
92 /// No skirts.
93 None,
94}
95
96/// How a map draws its terrain, for the map's lifetime.
97#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
98pub struct TerrainOptions {
99 /// How far the skirts of terrain tiles reach down. `Auto` by default.
100 pub skirt_length: TerrainSkirtLength,
101 /// The most bytes of GPU memory the textures that the terrain drapes
102 /// its layers onto hold, with their mips and the depth and stencil they
103 /// draw with. Past it, the drapes of the tiles farthest from the view's
104 /// center take fewer texels, and look blurrier; no tile loses its
105 /// drape. `None`, the default, sets no limit: the drapes hold what the
106 /// view's tiles need.
107 pub drape_memory_limit: Option<u64>,
108}
109
110impl Default for TerrainOptions {
111 fn default() -> Self {
112 TerrainOptions { skirt_length: TerrainSkirtLength::Auto, drape_memory_limit: None }
113 }
114}