Skip to content

Commit 9d20d40

Browse files
gritsenkoMaximkaaa
authored andcommitted
fix: Fix typos and zoom bounds checking in MapControllerConfiguration
1 parent 4e0f49a commit 9d20d40

1 file changed

Lines changed: 28 additions & 10 deletions

File tree

galileo/src/control/map.rs

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl MapControllerConfiguration {
6262
///
6363
/// For example, the value of `0.2` means, that every time the mouse wheel is turned, the map
6464
/// will be zoomed by 0.2 times.
65-
pub fn zoom_apeed(&self) -> f64 {
65+
pub fn zoom_speed(&self) -> f64 {
6666
self.zoom_speed
6767
}
6868

@@ -112,7 +112,7 @@ impl MapControllerConfiguration {
112112

113113
/// Sets minimum allowed resolution.
114114
pub fn set_min_resolution(&mut self, resolution: f64) {
115-
self.max_resolution = resolution;
115+
self.min_resolution = resolution;
116116
}
117117

118118
/// Sensitivity for map rotation by dragging right mouse button.
@@ -142,15 +142,15 @@ impl MapControllerConfiguration {
142142

143143
/// Minimum allowed tilt of the map in radians.
144144
///
145-
/// The value of `0.0` means the map is viewd from above. The value of `PI/2` corresponds to
145+
/// The value of `0.0` means the map is viewed from above. The value of `PI/2` corresponds to
146146
/// the map tilted horizontally.
147147
pub fn min_rotation_x(&self) -> f64 {
148148
self.min_rotation_x
149149
}
150150

151151
/// Sets minimum allowed tilt of the map in radians.
152152
///
153-
/// The value of `0.0` means the map is viewd from above. The value of `PI/2` corresponds to
153+
/// The value of `0.0` means the map is viewed from above. The value of `PI/2` corresponds to
154154
/// the map tilted horizontally.
155155
pub fn with_min_rotation_x(mut self, rotation: f64) -> Self {
156156
self.min_rotation_x = rotation;
@@ -159,23 +159,23 @@ impl MapControllerConfiguration {
159159

160160
/// Sets minimum allowed tilt of the map in radians.
161161
///
162-
/// The value of `0.0` means the map is viewd from above. The value of `PI/2` corresponds to
162+
/// The value of `0.0` means the map is viewed from above. The value of `PI/2` corresponds to
163163
/// the map tilted horizontally.
164164
pub fn set_min_rotation_x(&mut self, rotation: f64) {
165165
self.min_rotation_x = rotation;
166166
}
167167

168168
/// Maximum allowed tilt of the map in radians.
169169
///
170-
/// The value of `0.0` means the map is viewd from above. The value of `PI/2` corresponds to
170+
/// The value of `0.0` means the map is viewed from above. The value of `PI/2` corresponds to
171171
/// the map tilted horizontally.
172172
pub fn max_rotation_x(&self) -> f64 {
173173
self.max_rotation_x
174174
}
175175

176176
/// Sets maximum allowed tilt of the map in radians.
177177
///
178-
/// The value of `0.0` means the map is viewd from above. The value of `PI/2` corresponds to
178+
/// The value of `0.0` means the map is viewed from above. The value of `PI/2` corresponds to
179179
/// the map tilted horizontally.
180180
pub fn with_max_rotation_x(mut self, rotation: f64) -> Self {
181181
self.max_rotation_x = rotation;
@@ -184,10 +184,10 @@ impl MapControllerConfiguration {
184184

185185
/// Sets maximum allowed tilt of the map in radians.
186186
///
187-
/// The value of `0.0` means the map is viewd from above. The value of `PI/2` corresponds to
187+
/// The value of `0.0` means the map is viewed from above. The value of `PI/2` corresponds to
188188
/// the map tilted horizontally.
189189
pub fn set_max_rotation_x(&mut self, rotation: f64) {
190-
self.min_rotation_x = rotation;
190+
self.max_rotation_x = rotation;
191191
}
192192

193193
/// Minimum allowed rotation of the map around in radians.
@@ -231,7 +231,7 @@ impl MapControllerConfiguration {
231231
///
232232
/// Positive values correspond to counterclockwise rotation.
233233
pub fn set_max_rotation_z(&mut self, rotation: f64) {
234-
self.min_rotation_z = rotation;
234+
self.max_rotation_z = rotation;
235235
}
236236

237237
/// Disables tilting of the map by setting min and max rotation x to `0.0.
@@ -307,6 +307,16 @@ impl UserEventHandler for MapController {
307307
},
308308
UserEvent::Scroll(delta, mouse_event) => {
309309
let zoom = self.get_zoom(*delta);
310+
// Use the animation target resolution so rapid scrolling doesn't
311+
// overshoot the limit when animations are still in flight.
312+
let target_resolution = map.target_view().resolution() * zoom;
313+
314+
if target_resolution < self.config.min_resolution
315+
|| target_resolution > self.config.max_resolution
316+
{
317+
return EventPropagation::Stop;
318+
}
319+
310320
let target = map
311321
.target_view()
312322
.zoom(zoom, mouse_event.screen_pointer_position);
@@ -316,6 +326,14 @@ impl UserEventHandler for MapController {
316326
EventPropagation::Stop
317327
}
318328
UserEvent::Zoom(zoom, center) => {
329+
let target_resolution = map.view().resolution() * zoom;
330+
331+
if target_resolution < self.config.min_resolution
332+
|| target_resolution > self.config.max_resolution
333+
{
334+
return EventPropagation::Stop;
335+
}
336+
319337
let target = map.view().zoom(*zoom, *center);
320338
let adjusted = self.adjust_target_view(target);
321339
map.set_view(adjusted);

0 commit comments

Comments
 (0)