Skip to content

feat: smooth scroll zoom based on MapLibre GL JS#2198

Open
vinlet wants to merge 2 commits intofleaflet:masterfrom
vinlet:smooth-scroll-zoom
Open

feat: smooth scroll zoom based on MapLibre GL JS#2198
vinlet wants to merge 2 commits intofleaflet:masterfrom
vinlet:smooth-scroll-zoom

Conversation

@vinlet
Copy link
Copy Markdown

@vinlet vinlet commented Apr 13, 2026

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:

  • Windows with mouse wheel and trackpad
  • Chrome with mouse wheel and trackpad
  • Firefox with mouse wheel and trackpad
  • Android with mouse wheel

Random notes:

  • On Windows and Chrome, my mouse seems to produce scroll deltas in 100 increments. Firefox does 102 🤷‍♂️. Chrome with trackpad does only integer deltas, Firefox with trackpad does deltas with fractional parts as well. Android with mouse wheel did 64.
  • Added tests. From what I've seen there weren't really tests for gestures, which is understandable because it's a pain. Main pain point was the usage of DateTime.now(), but I found somewhat of a clever/ugly hack to fake it out with package:clock without adding it as a dependency.
  • Should I somehow dedupe the tests? (most code is duplicated between scroll up/down tests)
  • Should I somehow test the exact zoom values that smooth zooming should arrive at?
  • Initially I duplicated TestApp in scroll_wheel_zoom_test.dart to add in custom interactionOptions but realized it's a bad idea long term. So instead I added an interactionOptions param to TestApp. But this still feels like pointless busywork. In my projects I typically have something like wrapInTestApp(Widget child) where you can pass in any FlutterMap you like. I didn't do this here because the PR would blow up.
  • Removed the OSM URL from TestApp, tests still work and don't pointlessly print messages when running tests.
  • We could deprecate InteractionOptions.scrollWheelVelocity and move it into ScrollZoomOptions, maybe even merge it with ScrollZoomOptions.wheelZoomRate somehow?
  • Is this better as a plugin? Currently I don't see how to spin it off easily into a plugin.
  • Please nitpick the PR :) I'm not really familiar with the codebase entirely, so if I missed something or my approach could be improved, let me know.

Credit where credit is due:

@vinlet vinlet force-pushed the smooth-scroll-zoom branch from fef6a96 to 2c9a434 Compare April 13, 2026 20:03
@JaffaKetchup
Copy link
Copy Markdown
Member

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!

@vinlet
Copy link
Copy Markdown
Author

vinlet commented Apr 14, 2026

@JaffaKetchup that's ok! I'll try to be available and respond if there's news.
Note to self: I missed that MapLibre also has tests for smooth scrolling, should have looked into those as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants