flutter_map icon indicating copy to clipboard operation
flutter_map copied to clipboard

[FEATURE] Add option to zoom to map center instead of cursor location

Open JaffaKetchup opened this issue 11 months ago • 6 comments

What do you want implemented?

At the moment, zooming with a cursor zooms into the cursor location, which is what most use cases would require. However, some applications may prefer to have the map zoom into the center, regardless of the cursor location.

This has been requested twice in the Discord server: https://discord.com/channels/951867686378409984/1317675189701705778/1317675189701705778, https://discord.com/channels/951867686378409984/1166739850137980958/1166739850137980958

This should work for trackpad as well, as requested in #1905.

What other alternatives are available?

The second link's workaround was to play an animation immediately after the gesture has stopped to move the map back to the desired center, and move the desired marker/widget around to stay in the correct geographic position instead of screen center.

It may also be possible to use constraints to prevent moving during zoom?

Can you provide any other information?

No response

Severity

Annoying: Currently have to use workarounds

JaffaKetchup avatar Dec 15 '24 21:12 JaffaKetchup

(This may be related (the solution) to #1905)

JaffaKetchup avatar Dec 15 '24 21:12 JaffaKetchup

17343014939882807597925728120272 https://m.youtube.com/watch?v=kR2r-A9H3Kg

(Sorry about that)

monsieurtanuki avatar Dec 15 '24 22:12 monsieurtanuki

(Also see https://github.com/fleaflet/flutter_map/issues/1905#issuecomment-2521068993)

JaffaKetchup avatar Jan 08 '25 21:01 JaffaKetchup

Trackpad zooming is bugged. See these lines:

https://github.com/fleaflet/flutter_map/blob/48832daac0a0014b84caa1de118477c431a86001/lib/src/gestures/map_interactive_viewer.dart#L630-L647

These lines are also used when a touchscreen zoom is used - on some platforms. I'm not sure whether there is an easy way to change this, but it's causing issues.

The existing lines (shown below) works correctly on touchscreen and when trying to move using two fingers on a trackpad. However, when zooming on a trackpad, it causes the map to move excessively, especially toward the bottom-right corner, although it does depend on the position of the cursor. Removing moveDifference (as shown) fixes the issue. Unfortunately, it breaks two finger movement.

- final newCenterPt = oldCenterPt + zoomDifference + moveDifference;
+ final newCenterPt = oldCenterPt + zoomDifference;

JaffaKetchup avatar Jan 18 '25 13:01 JaffaKetchup

what are the workarounds? couldnt open the discord link. Im trying to set the trackpad zoom to work as expected. btw, on mac it works perfectly so maybe its possible to figure out what is the difference between the platforms. should fixing the trackpad bug and adding the feature for the center zoom be on the same issue?

roylenz avatar May 23 '25 20:05 roylenz

@JaffaKetchup Ive done some more digging and found that the problem is in the flutter source code (I think) I dont know enough, but applying this commit: https://github.com/Dusk-afk/flutter/commit/59c8ea649e4f4b8368f03d30103076b36fbd1e74 seemed to solve the trackpad problems completely

roylenz avatar May 24 '25 08:05 roylenz

Indeed it looks like the Flutter engine has an issue here. I intend to investigate and hopefully resolve it (https://github.com/flutter/flutter/issues/136029#issuecomment-3239196064) at the source, but in the meantime, the best workaround is to introduce a flag for flutter_map to manually toggle between zooming to the focal point or to the viewport center.

JaffaKetchup avatar Aug 30 '25 11:08 JaffaKetchup

Unmerged from #1905, which has also been split into #2152 (linking https://github.com/flutter/flutter/issues/136029). These detail the more precise problem/desired workaround of correcting the behaviour of zooming into the pointer position/focal point.

This is a separate feature request.

JaffaKetchup avatar Sep 11 '25 14:09 JaffaKetchup