dioxus_leaflet/components/
polygon.rs

1use dioxus::prelude::*;
2use dioxus_logger::tracing::error;
3
4use crate::{components::{map::MapContext, popup::PopupContext}, interop, LatLng, PathOptions};
5
6#[component]
7pub fn Polygon(
8    coordinates: ReadOnlySignal<Vec<LatLng>>,
9
10    #[props(default = PathOptions::default())]
11    options: ReadOnlySignal<PathOptions>,
12
13    children: Option<Element>,
14) -> Element {
15    let map_id: MapContext = use_context();
16    let my_id = dioxus_core::current_scope_id().unwrap().0;
17    use_context_provider(|| PopupContext(my_id));
18
19    use_effect(move || {
20        let coords = coordinates();
21        let opts = options();
22        spawn(async move {
23            if let Err(e) = interop::update_polygon(map_id.0, my_id, &coords, &opts).await {
24                error!("{e}");
25            }
26        });
27    });
28
29    rsx!({children})
30}