1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
use super::{LeafletResources, TileLayer};
use serde::{Deserialize, Serialize};
/// Coordinate reference system, matching the names of Leaflet's `L.CRS.*` objects
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum CRS {
/// World Mercator (`L.CRS.EPSG3395`)
EPSG3395,
/// Spherical Mercator, the default used by most tile providers (`L.CRS.EPSG3857`)
EPSG3857,
/// Plate Carrée (`L.CRS.EPSG4326`)
EPSG4326,
/// Alias of EPSG3857 (`L.CRS.EPSG900913`)
EPSG900913,
/// Earth CRS (`L.CRS.Earth`)
Earth,
/// Simple linear CRS for non-geographical maps, such as game maps (`L.CRS.Simple`)
Simple,
}
/// Map configuration options
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct MapOptions {
pub zoom_control: bool,
pub scroll_wheel_zoom: bool,
pub double_click_zoom: bool,
pub touch_zoom: bool,
pub dragging: bool,
pub keyboard: bool,
pub attribution_control: bool,
pub tile_layer: Option<TileLayer>,
pub leaflet_resources: LeafletResources,
pub crs: Option<CRS>,
}
impl Default for MapOptions {
fn default() -> Self {
Self {
zoom_control: true,
scroll_wheel_zoom: true,
double_click_zoom: true,
touch_zoom: true,
dragging: true,
keyboard: true,
attribution_control: true,
tile_layer: Some(TileLayer::default()),
leaflet_resources: LeafletResources::default(),
crs: None,
}
}
}
impl MapOptions {
/// Creates a MapOptions with all controls disabled and no tile layer
pub fn minimal() -> Self {
Self {
zoom_control: false,
scroll_wheel_zoom: false,
double_click_zoom: false,
touch_zoom: false,
dragging: false,
keyboard: false,
attribution_control: false,
tile_layer: None,
leaflet_resources: LeafletResources::default(),
crs: None,
}
}
/// Builder method to enable/disable zoom control
pub fn with_zoom_control(mut self, enabled: bool) -> Self {
self.zoom_control = enabled;
self
}
/// Builder method to enable/disable scroll wheel zoom
pub fn with_scroll_wheel_zoom(mut self, enabled: bool) -> Self {
self.scroll_wheel_zoom = enabled;
self
}
/// Builder method to enable/disable double click zoom
pub fn with_double_click_zoom(mut self, enabled: bool) -> Self {
self.double_click_zoom = enabled;
self
}
/// Builder method to enable/disable touch zoom
pub fn with_touch_zoom(mut self, enabled: bool) -> Self {
self.touch_zoom = enabled;
self
}
/// Builder method to enable/disable dragging
pub fn with_dragging(mut self, enabled: bool) -> Self {
self.dragging = enabled;
self
}
/// Builder method to enable/disable keyboard controls
pub fn with_keyboard(mut self, enabled: bool) -> Self {
self.keyboard = enabled;
self
}
/// Builder method to enable/disable attribution control
pub fn with_attribution_control(mut self, enabled: bool) -> Self {
self.attribution_control = enabled;
self
}
/// Builder method to set tile layer
pub fn with_tile_layer(mut self, tile_layer: TileLayer) -> Self {
self.tile_layer = Some(tile_layer);
self
}
/// Builder method to remove the tile layer (e.g. for maps made only of image overlays)
pub fn without_tile_layer(mut self) -> Self {
self.tile_layer = None;
self
}
/// Builder method to set Leaflet resources configuration
pub fn with_leaflet_resources(mut self, resources: LeafletResources) -> Self {
self.leaflet_resources = resources;
self
}
/// Builder method to set the coordinate reference system (defaults to Leaflet's EPSG3857)
pub fn with_crs(mut self, crs: CRS) -> Self {
self.crs = Some(crs);
self
}
}