dioxus_leaflet/types/
map_options.rs

1use serde::{Deserialize, Serialize};
2use super::{TileLayer, LeafletResources};
3
4/// Map configuration options
5#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6pub struct MapOptions {
7    pub zoom_control: bool,
8    pub scroll_wheel_zoom: bool,
9    pub double_click_zoom: bool,
10    pub touch_zoom: bool,
11    pub dragging: bool,
12    pub keyboard: bool,
13    pub attribution_control: bool,
14    pub tile_layer: TileLayer,
15    pub leaflet_resources: LeafletResources,
16}
17
18impl Default for MapOptions {
19    fn default() -> Self {
20        Self {
21            zoom_control: true,
22            scroll_wheel_zoom: true,
23            double_click_zoom: true,
24            touch_zoom: true,
25            dragging: true,
26            keyboard: true,
27            attribution_control: true,
28            tile_layer: TileLayer::default(),
29            leaflet_resources: LeafletResources::default(),
30        }
31    }
32}
33
34impl MapOptions {
35    /// Creates a MapOptions with all controls disabled and default tile layer
36    pub fn minimal() -> Self {
37        Self {
38            zoom_control: false,
39            scroll_wheel_zoom: false,
40            double_click_zoom: false,
41            touch_zoom: false,
42            dragging: false,
43            keyboard: false,
44            attribution_control: false,
45            tile_layer: TileLayer::default(),
46            leaflet_resources: LeafletResources::default(),
47        }
48    }
49
50    /// Builder method to enable/disable zoom control
51    pub fn with_zoom_control(mut self, enabled: bool) -> Self {
52        self.zoom_control = enabled;
53        self
54    }
55
56    /// Builder method to enable/disable scroll wheel zoom
57    pub fn with_scroll_wheel_zoom(mut self, enabled: bool) -> Self {
58        self.scroll_wheel_zoom = enabled;
59        self
60    }
61
62    /// Builder method to enable/disable double click zoom
63    pub fn with_double_click_zoom(mut self, enabled: bool) -> Self {
64        self.double_click_zoom = enabled;
65        self
66    }
67
68    /// Builder method to enable/disable touch zoom
69    pub fn with_touch_zoom(mut self, enabled: bool) -> Self {
70        self.touch_zoom = enabled;
71        self
72    }
73
74    /// Builder method to enable/disable dragging
75    pub fn with_dragging(mut self, enabled: bool) -> Self {
76        self.dragging = enabled;
77        self
78    }
79
80    /// Builder method to enable/disable keyboard controls
81    pub fn with_keyboard(mut self, enabled: bool) -> Self {
82        self.keyboard = enabled;
83        self
84    }
85
86    /// Builder method to enable/disable attribution control
87    pub fn with_attribution_control(mut self, enabled: bool) -> Self {
88        self.attribution_control = enabled;
89        self
90    }
91
92    /// Builder method to set tile layer
93    pub fn with_tile_layer(mut self, tile_layer: TileLayer) -> Self {
94        self.tile_layer = tile_layer;
95        self
96    }
97
98    /// Builder method to set Leaflet resources configuration
99    pub fn with_leaflet_resources(mut self, resources: LeafletResources) -> Self {
100        self.leaflet_resources = resources;
101        self
102    }
103}