feat: add smooth scroll zooming#2198
Conversation
fef6a96 to
2c9a434
Compare
|
Hey @vinlet, Wow! This is hugely appreciated - and something I've wanted to implement and has been top of my personal priority list for a while, but I've always been put off by needing to handle the whole trackpad/mouse thing (it's a well known issue in Flutter as well, see flutter/flutter#32120). Although it's true that most users use flutter_map on mobile platforms, one of flutter_map's biggest advantages is that it does actually run on web and desktop unlike the alternatives, so any improvements that bring that support even further ahead are great. Given this is such a big thing to test and get right, and because the gesture handling has historically been a messy part of flutter_map, this might not be merged quickly (especially as I'm about to be unavailable for coding/testing for a while). But we'll look into it. Thanks again! |
|
@JaffaKetchup that's ok! I'll try to be available and respond if there's news. |
There was a problem hiding this comment.
Hey, thanks for this again! I think this looks good to me. I'm tempted to release this into a prerelease first to see whether we can drum up some testers, since I'm aware that this part of the code can be very very fiddly and behave differently with different devices and on different platforms - but I'm not sure yet.
I'm also considering making a couple other changes to the example app and API surface as you mentioned.
Add smooth scrolling toggle to demo page
…mOptions` Removed redundant tests
|
I've updated the example app and the API. Also removed a couple tests that I believe are redundant (the ones testing defaults of the constructors of |
smooth_scroll_zoom.mp4
With some help from Claude Code and Opus 4.6 (I'm sorry) I ported MapLibre GL JS's implementation of animated smooth zooming for mouse wheel scrolls. I feel like this was sorely missing from
flutter_map, though I'm aware web/desktop users are probably not in the majority.MapLibre's implementation tries to differentiate mouse wheels from trackpads through some magic (whic is apparently damn hard). I ported that logic verbatim but not sure how well it applies to Flutter. Apparently pretty well.
On top of MapLibre's implementation I made the scroll rate and animation duration configurable, but non-defaults probably dont't play well with some of the other hardcoded delays from MapLibre's implementation.
The old behavior still exists but I made smooth scrolling the default which is technically a breaking change, so let me know if that's not ok...
Manually tested it in:
Random notes:
DateTime.now(), but I found somewhat of a clever/ugly hack to fake it out withpackage:clockwithout adding it as a dependency.TestAppinscroll_wheel_zoom_test.dartto add in custominteractionOptionsbut realized it's a bad idea long term. So instead I added aninteractionOptionsparam toTestApp. But this still feels like pointless busywork. In my projects I typically have something likewrapInTestApp(Widget child)where you can pass in anyFlutterMapyou like. I didn't do this here because the PR would blow up.TestApp, tests still work and don't pointlessly print messages when running tests.InteractionOptions.scrollWheelVelocityand move it intoScrollZoomOptions, maybe even merge it withScrollZoomOptions.wheelZoomRatesomehow?Credit where credit is due: