dioxus_leaflet/types/
map_options.rs1use super::{LeafletResources, TileLayer};
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6pub enum CRS {
7 EPSG3395,
9 EPSG3857,
11 EPSG4326,
13 EPSG900913,
15 Earth,
17 Simple,
19}
20
21#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
23pub struct MapOptions {
24 pub zoom_control: bool,
25 pub scroll_wheel_zoom: bool,
26 pub double_click_zoom: bool,
27 pub touch_zoom: bool,
28 pub dragging: bool,
29 pub keyboard: bool,
30 pub attribution_control: bool,
31 pub tile_layer: Option<TileLayer>,
32 pub leaflet_resources: LeafletResources,
33 pub crs: Option<CRS>,
34}
35
36impl Default for MapOptions {
37 fn default() -> Self {
38 Self {
39 zoom_control: true,
40 scroll_wheel_zoom: true,
41 double_click_zoom: true,
42 touch_zoom: true,
43 dragging: true,
44 keyboard: true,
45 attribution_control: true,
46 tile_layer: Some(TileLayer::default()),
47 leaflet_resources: LeafletResources::default(),
48 crs: None,
49 }
50 }
51}
52
53impl MapOptions {
54 pub fn minimal() -> Self {
56 Self {
57 zoom_control: false,
58 scroll_wheel_zoom: false,
59 double_click_zoom: false,
60 touch_zoom: false,
61 dragging: false,
62 keyboard: false,
63 attribution_control: false,
64 tile_layer: None,
65 leaflet_resources: LeafletResources::default(),
66 crs: None,
67 }
68 }
69
70 pub fn with_zoom_control(mut self, enabled: bool) -> Self {
72 self.zoom_control = enabled;
73 self
74 }
75
76 pub fn with_scroll_wheel_zoom(mut self, enabled: bool) -> Self {
78 self.scroll_wheel_zoom = enabled;
79 self
80 }
81
82 pub fn with_double_click_zoom(mut self, enabled: bool) -> Self {
84 self.double_click_zoom = enabled;
85 self
86 }
87
88 pub fn with_touch_zoom(mut self, enabled: bool) -> Self {
90 self.touch_zoom = enabled;
91 self
92 }
93
94 pub fn with_dragging(mut self, enabled: bool) -> Self {
96 self.dragging = enabled;
97 self
98 }
99
100 pub fn with_keyboard(mut self, enabled: bool) -> Self {
102 self.keyboard = enabled;
103 self
104 }
105
106 pub fn with_attribution_control(mut self, enabled: bool) -> Self {
108 self.attribution_control = enabled;
109 self
110 }
111
112 pub fn with_tile_layer(mut self, tile_layer: TileLayer) -> Self {
114 self.tile_layer = Some(tile_layer);
115 self
116 }
117
118 pub fn without_tile_layer(mut self) -> Self {
120 self.tile_layer = None;
121 self
122 }
123
124 pub fn with_leaflet_resources(mut self, resources: LeafletResources) -> Self {
126 self.leaflet_resources = resources;
127 self
128 }
129
130 pub fn with_crs(mut self, crs: CRS) -> Self {
132 self.crs = Some(crs);
133 self
134 }
135}