dioxus_maplibre/handle/
queries.rs1#![allow(clippy::needless_pass_by_value, clippy::unused_async)]
3
4use super::MapHandle;
5use crate::options::QueryOptions;
6use crate::types::QueryFeature;
7#[cfg(target_arch = "wasm32")]
8use dioxus::prelude::document;
9
10impl MapHandle {
11 #[cfg(target_arch = "wasm32")]
13 pub async fn query_rendered_features(&self, options: QueryOptions) -> Vec<QueryFeature> {
14 let json = serde_json::to_string(&options).unwrap_or_default();
15 let js = crate::interop::query_rendered_features_js(&self.map_id, &json);
16 document::eval(&js)
17 .join::<Vec<QueryFeature>>()
18 .await
19 .unwrap_or_default()
20 }
21
22 #[cfg(not(target_arch = "wasm32"))]
23 pub async fn query_rendered_features(&self, _options: QueryOptions) -> Vec<QueryFeature> {
24 Vec::new()
25 }
26
27 #[cfg(target_arch = "wasm32")]
29 pub async fn query_rendered_features_at(
30 &self,
31 point: crate::types::Point,
32 options: QueryOptions,
33 ) -> Vec<QueryFeature> {
34 let json = serde_json::to_string(&options).unwrap_or_default();
35 let js =
36 crate::interop::query_rendered_features_at_js(&self.map_id, point.x, point.y, &json);
37 document::eval(&js)
38 .join::<Vec<QueryFeature>>()
39 .await
40 .unwrap_or_default()
41 }
42
43 #[cfg(not(target_arch = "wasm32"))]
44 pub async fn query_rendered_features_at(
45 &self,
46 _point: crate::types::Point,
47 _options: QueryOptions,
48 ) -> Vec<QueryFeature> {
49 Vec::new()
50 }
51
52 #[cfg(target_arch = "wasm32")]
54 pub async fn query_source_features(
55 &self,
56 source_id: &str,
57 options: QueryOptions,
58 ) -> Vec<QueryFeature> {
59 let json = serde_json::to_string(&options).unwrap_or_default();
60 let js = crate::interop::query_source_features_js(&self.map_id, source_id, &json);
61 document::eval(&js)
62 .join::<Vec<QueryFeature>>()
63 .await
64 .unwrap_or_default()
65 }
66
67 #[cfg(not(target_arch = "wasm32"))]
68 pub async fn query_source_features(
69 &self,
70 _source_id: &str,
71 _options: QueryOptions,
72 ) -> Vec<QueryFeature> {
73 Vec::new()
74 }
75}