Skip to main content

dioxus_maplibre/handle/
markers.rs

1//! Marker-related MapHandle methods.
2#![allow(clippy::needless_pass_by_value)]
3
4use super::MapHandle;
5use crate::options::MarkerOptions;
6use crate::types::LatLng;
7
8impl MapHandle {
9    /// Add a marker at the given position
10    pub fn add_marker(&self, id: &str, position: LatLng, options: MarkerOptions) {
11        self.fire_and_forget(|| {
12            let json = serde_json::to_string(&options).unwrap_or_default();
13            crate::interop::add_marker_js(&self.map_id, id, position.lat, position.lng, &json)
14        });
15    }
16
17    /// Remove a marker
18    pub fn remove_marker(&self, id: &str) {
19        self.fire_and_forget(|| crate::interop::remove_marker_js(&self.map_id, id));
20    }
21
22    /// Update a marker's position
23    pub fn update_marker_position(&self, id: &str, position: LatLng) {
24        self.fire_and_forget(|| {
25            crate::interop::update_marker_position_js(&self.map_id, id, position.lat, position.lng)
26        });
27    }
28}