Skip to main content

dioxus_maplibre/handle/
getters.rs

1//! Async getter MapHandle methods.
2#![allow(clippy::unused_async)]
3
4use super::MapHandle;
5use crate::types::{Bounds, LatLng};
6#[cfg(target_arch = "wasm32")]
7use dioxus::prelude::document;
8
9impl MapHandle {
10    /// Get the current zoom level
11    #[cfg(target_arch = "wasm32")]
12    pub async fn get_zoom(&self) -> Option<f64> {
13        let js = crate::interop::get_zoom_js(&self.map_id);
14        document::eval(&js).join::<f64>().await.ok()
15    }
16
17    /// Get the current center coordinate
18    #[cfg(target_arch = "wasm32")]
19    pub async fn get_center(&self) -> Option<LatLng> {
20        let js = crate::interop::get_center_js(&self.map_id);
21        document::eval(&js).join::<LatLng>().await.ok()
22    }
23
24    /// Get the current bearing (rotation)
25    #[cfg(target_arch = "wasm32")]
26    pub async fn get_bearing(&self) -> Option<f64> {
27        let js = crate::interop::get_bearing_js(&self.map_id);
28        document::eval(&js).join::<f64>().await.ok()
29    }
30
31    /// Get the current pitch (tilt)
32    #[cfg(target_arch = "wasm32")]
33    pub async fn get_pitch(&self) -> Option<f64> {
34        let js = crate::interop::get_pitch_js(&self.map_id);
35        document::eval(&js).join::<f64>().await.ok()
36    }
37
38    /// Get the current viewport bounds
39    #[cfg(target_arch = "wasm32")]
40    pub async fn get_bounds(&self) -> Option<Bounds> {
41        let js = crate::interop::get_bounds_js(&self.map_id);
42        document::eval(&js).join::<Bounds>().await.ok()
43    }
44
45    // No-op stubs for native targets
46    #[cfg(not(target_arch = "wasm32"))]
47    pub async fn get_zoom(&self) -> Option<f64> {
48        None
49    }
50    #[cfg(not(target_arch = "wasm32"))]
51    pub async fn get_center(&self) -> Option<LatLng> {
52        None
53    }
54    #[cfg(not(target_arch = "wasm32"))]
55    pub async fn get_bearing(&self) -> Option<f64> {
56        None
57    }
58    #[cfg(not(target_arch = "wasm32"))]
59    pub async fn get_pitch(&self) -> Option<f64> {
60        None
61    }
62    #[cfg(not(target_arch = "wasm32"))]
63    pub async fn get_bounds(&self) -> Option<Bounds> {
64        None
65    }
66}