dioxus_maplibre/handle/
mod.rs1mod controls;
4mod escape_hatch;
5mod feature_state;
6mod getters;
7mod images;
8mod layer_events;
9mod layers;
10mod markers;
11mod navigation;
12mod padding;
13mod popups;
14mod queries;
15mod sources;
16mod style;
17mod terrain_atmosphere;
18
19use crate::options::ControlPosition;
20
21#[derive(Debug, Clone, PartialEq, Eq)]
26pub struct MapHandle {
27 map_id: String,
28}
29
30impl MapHandle {
31 #[allow(dead_code)] pub(crate) fn new(map_id: String) -> Self {
34 Self { map_id }
35 }
36
37 pub fn map_id(&self) -> &str {
39 &self.map_id
40 }
41
42 #[cfg(target_arch = "wasm32")]
44 pub(crate) fn fire_and_forget(&self, js_fn: impl FnOnce() -> String) {
45 let js = js_fn();
46 dioxus::prelude::spawn(async move {
47 let _ = document::eval(&js).await;
48 });
49 }
50
51 #[allow(clippy::unused_self)]
52 #[cfg(not(target_arch = "wasm32"))]
53 pub(crate) fn fire_and_forget(&self, _js_fn: impl FnOnce() -> String) {
54 }
56
57 #[cfg(target_arch = "wasm32")]
59 pub(crate) fn eval_raw(&self, js: &str) {
60 let js = js.to_string();
61 dioxus::prelude::spawn(async move {
62 let _ = document::eval(&js).await;
63 });
64 }
65
66 #[allow(clippy::unused_self)]
67 #[cfg(not(target_arch = "wasm32"))]
68 pub(crate) fn eval_raw(&self, _js: &str) {}
69}
70
71#[cfg(target_arch = "wasm32")]
72use dioxus::prelude::document;
73
74pub(crate) fn control_position_str(pos: ControlPosition) -> &'static str {
75 match pos {
76 ControlPosition::TopLeft => "top-left",
77 ControlPosition::TopRight => "top-right",
78 ControlPosition::BottomLeft => "bottom-left",
79 ControlPosition::BottomRight => "bottom-right",
80 }
81}