Skip to main content

mln_map/
map_options.rs

1use mln_map_types::{ConstrainMode, MapMode, NorthOrientation, TerrainOptions, ViewportMode};
2use mln_util::size::Size;
3
4/// What a map does with a style image once no layer uses it.
5#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
6pub enum UnusedStyleImagePolicy {
7    /// Remove it from the style, unless the image sets `keep_unused`. A
8    /// layer that uses it again reports it missing with
9    /// [`MapEvent::StyleImageMissing`](crate::MapEvent::StyleImageMissing).
10    #[default]
11    Remove,
12    /// Keep it in the style.
13    Keep,
14}
15
16/// How a map renders and lays itself out.
17#[derive(Clone, Copy, Debug)]
18pub struct MapOptions {
19    /// Continuous by default, so the map renders as data arrives from the
20    /// network and reacts immediately to state changes.
21    pub map_mode: MapMode,
22    /// Limits how far the map can move off the world. `HeightOnly` by
23    /// default.
24    pub constrain_mode: ConstrainMode,
25    /// Can flip the vertical orientation of the map, as some devices use an
26    /// inverted orientation.
27    pub viewport_mode: ViewportMode,
28    /// Which way north points on the screen. Upwards by default.
29    pub north_orientation: NorthOrientation,
30    /// Whether symbols collide across sources. On by default.
31    pub cross_source_collisions: bool,
32    /// The size of the map and its renderer backend.
33    pub size: Size,
34    /// 1 by default.
35    pub pixel_ratio: f32,
36    /// Whether MLT vector tiles decode streams encoded with FastPFOR. Off
37    /// by default.
38    pub fast_pfor_enabled: bool,
39    /// What the map does with a style image once no layer uses it. By
40    /// default, it removes the image.
41    pub unused_style_image_policy: UnusedStyleImagePolicy,
42    /// Whether the center stands on the terrain, as
43    /// [`Viewport::center_clamped_to_ground`] describes. On by default.
44    ///
45    /// [`Viewport::center_clamped_to_ground`]: crate::Viewport::center_clamped_to_ground
46    pub center_clamped_to_ground: bool,
47    /// How the map draws its terrain, for the map's lifetime.
48    pub terrain: TerrainOptions,
49}
50
51impl Default for MapOptions {
52    fn default() -> Self {
53        MapOptions {
54            map_mode: MapMode::Continuous,
55            constrain_mode: ConstrainMode::HeightOnly,
56            viewport_mode: ViewportMode::Default,
57            north_orientation: NorthOrientation::Upwards,
58            cross_source_collisions: true,
59            size: Size::new(64, 64),
60            pixel_ratio: 1.0,
61            fast_pfor_enabled: false,
62            unused_style_image_policy: UnusedStyleImagePolicy::Remove,
63            center_clamped_to_ground: true,
64            terrain: TerrainOptions::default(),
65        }
66    }
67}