Skip to content

Commit 612a865

Browse files
committed
fix: Zoom to limit before canceling zoom events
Previous fix had a problem that with large enough zoom speed, the scrolling would end far from the limit resolution. This is especially visible with tile layers, where the user wouldn't see the top level of the tiles they configured map to show. This fix ensures we always zoom to limit before stopping it.
1 parent 9d20d40 commit 612a865

1 file changed

Lines changed: 6 additions & 11 deletions

File tree

galileo/src/control/map.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -307,21 +307,14 @@ 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-
}
319310

320311
let target = map
321312
.target_view()
322313
.zoom(zoom, mouse_event.screen_pointer_position);
323314
let adjusted = self.adjust_target_view(target);
324-
map.animate_to(adjusted, self.config.zoom_duration);
315+
if (adjusted.resolution() - map.target_view().resolution()).abs() > f64::EPSILON {
316+
map.animate_to(adjusted, self.config.zoom_duration);
317+
}
325318

326319
EventPropagation::Stop
327320
}
@@ -336,7 +329,9 @@ impl UserEventHandler for MapController {
336329

337330
let target = map.view().zoom(*zoom, *center);
338331
let adjusted = self.adjust_target_view(target);
339-
map.set_view(adjusted);
332+
if (adjusted.resolution() - map.target_view().resolution()).abs() > f64::EPSILON {
333+
map.set_view(adjusted);
334+
}
340335

341336
EventPropagation::Stop
342337
}

0 commit comments

Comments
 (0)