Skip to main content

mln_map/
map_options.rs

1// Ports include/mln/map/map_options.hpp and src/mln/map/map_options.cpp.
2//
3// C++ hides the fields behind a pimpl; the port keeps them private with the
4// same builder (`with_*`, by value) and getter methods.
5
6use mln_map_types::{ConstrainMode, MapMode, NorthOrientation, ViewportMode};
7use mln_util::size::Size;
8
9/// Holds values for Map options.
10#[derive(Clone, Debug)]
11pub struct MapOptions {
12    map_mode: MapMode,
13    constrain_mode: ConstrainMode,
14    viewport_mode: ViewportMode,
15    orientation: NorthOrientation,
16    cross_source_collisions: bool,
17    capture_rendered_features: bool,
18    size: Size,
19    pixel_ratio: f32,
20    fast_pfor_enabled: bool,
21}
22
23impl Default for MapOptions {
24    fn default() -> Self {
25        MapOptions {
26            map_mode: MapMode::Continuous,
27            constrain_mode: ConstrainMode::HeightOnly,
28            viewport_mode: ViewportMode::Default,
29            orientation: NorthOrientation::Upwards,
30            cross_source_collisions: true,
31            capture_rendered_features: false,
32            size: Size::new(64, 64),
33            pixel_ratio: 1.0,
34            fast_pfor_enabled: false,
35        }
36    }
37}
38
39impl MapOptions {
40    /// `MapOptions()`: the defaults above.
41    pub fn new() -> Self {
42        Self::default()
43    }
44
45    /// Sets the map rendering mode. By default, it is set to Continuous so
46    /// the map will render as data arrives from the network and react
47    /// immediately to state changes.
48    pub fn with_map_mode(mut self, mode: MapMode) -> Self {
49        self.map_mode = mode;
50        self
51    }
52
53    pub fn map_mode(&self) -> MapMode {
54        self.map_mode
55    }
56
57    /// Sets the map constrain mode. This can be used to limit the map to
58    /// wrap around the globe horizontally. By default, it is set to
59    /// HeightOnly.
60    pub fn with_constrain_mode(mut self, mode: ConstrainMode) -> Self {
61        self.constrain_mode = mode;
62        self
63    }
64
65    pub fn constrain_mode(&self) -> ConstrainMode {
66        self.constrain_mode
67    }
68
69    /// Sets the viewport mode. This can be used to flip the vertical
70    /// orientation of the map as some devices may use inverted orientation.
71    pub fn with_viewport_mode(mut self, mode: ViewportMode) -> Self {
72        self.viewport_mode = mode;
73        self
74    }
75
76    pub fn viewport_mode(&self) -> ViewportMode {
77        self.viewport_mode
78    }
79
80    /// Enable or disable cross-source symbol collision detection. By
81    /// default, it is set to true.
82    pub fn with_cross_source_collisions(mut self, enable_collisions: bool) -> Self {
83        self.cross_source_collisions = enable_collisions;
84        self
85    }
86
87    pub fn cross_source_collisions(&self) -> bool {
88        self.cross_source_collisions
89    }
90
91    /// Sets the orientation of the Map. By default, it is set to Upwards.
92    pub fn with_north_orientation(mut self, orientation: NorthOrientation) -> Self {
93        self.orientation = orientation;
94        self
95    }
96
97    pub fn north_orientation(&self) -> NorthOrientation {
98        self.orientation
99    }
100
101    /// Sets the size to resize the map object and renderer backend.
102    pub fn with_size(mut self, size: Size) -> Self {
103        self.size = size;
104        self
105    }
106
107    pub fn size(&self) -> Size {
108        self.size
109    }
110
111    /// Sets the custom pixel ratio. By default, it is set to 1.
112    pub fn with_pixel_ratio(mut self, ratio: f32) -> Self {
113        self.pixel_ratio = ratio;
114        self
115    }
116
117    pub fn pixel_ratio(&self) -> f32 {
118        self.pixel_ratio
119    }
120
121    /// Enable or disable capturing of rendered feature information.
122    pub fn with_rendered_feature_info(mut self, capture: bool) -> Self {
123        self.capture_rendered_features = capture;
124        self
125    }
126
127    pub fn rendered_feature_info(&self) -> bool {
128        self.capture_rendered_features
129    }
130
131    pub fn with_fast_pfor_enabled(mut self, enable: bool) -> Self {
132        self.fast_pfor_enabled = enable;
133        self
134    }
135
136    pub fn fast_pfor_enabled(&self) -> bool {
137        self.fast_pfor_enabled
138    }
139}