Skip to main content

mln_map/
map_observer.rs

1// Ports include/mln/map/map_observer.hpp
2//
3// Methods take `&self` (the observer is shared with the map as
4// `Rc<dyn MapObserver>`); implementations use `Cell`/`RefCell` for state.
5
6use mln_renderer::ExceptionPtr;
7
8#[derive(Clone, Copy, Debug, PartialEq, Eq)]
9pub enum MapLoadError {
10    StyleParseError,
11    StyleLoadError,
12    NotFoundError,
13    UnknownError,
14}
15
16#[derive(Clone, Copy, Debug, PartialEq, Eq)]
17#[repr(u32)]
18pub enum CameraChangeMode {
19    Immediate,
20    Animated,
21}
22
23#[derive(Clone, Copy, Debug, PartialEq, Eq)]
24#[repr(u32)]
25pub enum RenderMode {
26    Partial,
27    Full,
28}
29
30#[derive(Clone, Copy, Debug, PartialEq, Eq)]
31pub struct RenderFrameStatus {
32    pub mode: RenderMode,
33    /// In continuous mode, shows that there are ongoing transitions.
34    pub needs_repaint: bool,
35    pub placement_changed: bool,
36    // TODO(port): rendering_stats: Arc<gfx::RenderingStats>.
37}
38
39/// `MapObserver`. All methods have the C++ default (empty) bodies.
40// TODO(port): onSourceChanged(style::Source&), onRegisterShaders, shader
41// compile callbacks, glyph/tile/sprite request callbacks.
42pub trait MapObserver {
43    fn on_camera_will_change(&self, _mode: CameraChangeMode) {}
44    fn on_camera_is_changing(&self) {}
45    fn on_camera_did_change(&self, _mode: CameraChangeMode) {}
46    fn on_will_start_loading_map(&self) {}
47    fn on_did_finish_loading_map(&self) {}
48    fn on_did_fail_loading_map(&self, _error: MapLoadError, _what: &str) {}
49    fn on_will_start_rendering_frame(&self) {}
50    fn on_did_finish_rendering_frame(&self, _status: &RenderFrameStatus) {}
51    fn on_will_start_rendering_map(&self) {}
52    fn on_did_finish_rendering_map(&self, _mode: RenderMode) {}
53    fn on_did_finish_loading_style(&self) {}
54    fn on_did_become_idle(&self) {}
55    fn on_style_image_missing(&self, _id: &str) {}
56    /// This method should return true if unused image can be removed, false
57    /// otherwise. By default, unused image will be removed.
58    fn on_can_remove_unused_style_image(&self, _id: &str) -> bool {
59        true
60    }
61    fn on_render_error(&self, _error: ExceptionPtr) {}
62    /// Called with a description of a corrupted symbol detected by the
63    /// symbol guard checks.
64    fn on_symbol_error(&self, _message: &str) {}
65}
66
67/// `MapObserver::nullObserver()`.
68pub struct NullMapObserver;
69
70impl MapObserver for NullMapObserver {}