dioxus_maplibre/handle/
images.rs1#![allow(clippy::unused_async)]
3
4use super::MapHandle;
5#[cfg(target_arch = "wasm32")]
6use dioxus::prelude::document;
7
8impl MapHandle {
9 pub fn load_image(&self, id: &str, url: &str) {
11 self.fire_and_forget(|| crate::interop::load_image_js(&self.map_id, id, url));
12 }
13
14 #[cfg(target_arch = "wasm32")]
16 pub async fn load_image_async(&self, id: &str, url: &str) -> bool {
17 let js = crate::interop::load_image_async_js(&self.map_id, id, url);
18 document::eval(&js).join::<bool>().await.unwrap_or(false)
19 }
20
21 #[cfg(not(target_arch = "wasm32"))]
23 pub async fn load_image_async(&self, _id: &str, _url: &str) -> bool {
24 false
25 }
26
27 #[cfg(target_arch = "wasm32")]
29 pub async fn has_image(&self, id: &str) -> bool {
30 let js = crate::interop::has_image_js(&self.map_id, id);
31 document::eval(&js).join::<bool>().await.unwrap_or(false)
32 }
33
34 #[cfg(not(target_arch = "wasm32"))]
36 pub async fn has_image(&self, _id: &str) -> bool {
37 false
38 }
39
40 pub fn remove_image(&self, id: &str) {
42 self.fire_and_forget(|| crate::interop::remove_image_js(&self.map_id, id));
43 }
44}