Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
JaffaKetchup opened this issue Dec 15, 2024 · 4 comments
Open
Labels
P: 2 (soon™?) S: core Scoped to the core flutter_map functionality

Comments

@JaffaKetchup
Copy link
Member

JaffaKetchup commented Dec 15, 2024

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 JaffaKetchup added feature This issue requests a new feature P: 2 (soon™?) labels Dec 15, 2024
@JaffaKetchup
Copy link
Member Author

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

@monsieurtanuki
Copy link
Contributor

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

(Sorry about that)

@JaffaKetchup JaffaKetchup added the S: core Scoped to the core flutter_map functionality label Jan 8, 2025
@JaffaKetchup
Copy link
Member Author

(Also see #1905 (comment))

@JaffaKetchup JaffaKetchup removed the feature This issue requests a new feature label Jan 18, 2025
@JaffaKetchup
Copy link
Member Author

Trackpad zooming is bugged. See these lines:

LatLng _calculatePinchZoomAndMove(
ScaleUpdateDetails details,
double zoomAfterPinchZoom,
) {
final oldCenterPt =
_camera.projectAtZoom(_camera.center, zoomAfterPinchZoom);
final newFocalLatLong =
_camera.offsetToCrs(_focalStartLocal, zoomAfterPinchZoom);
final newFocalPt =
_camera.projectAtZoom(newFocalLatLong, zoomAfterPinchZoom);
final oldFocalPt =
_camera.projectAtZoom(_focalStartLatLng, zoomAfterPinchZoom);
final zoomDifference = oldFocalPt - newFocalPt;
final moveDifference = _rotateOffset(_focalStartLocal - _lastFocalLocal);
final newCenterPt = oldCenterPt + zoomDifference + moveDifference;
return _camera.unprojectAtZoom(newCenterPt, zoomAfterPinchZoom);
}

These lines are also used when a touchscreen zoom is used. 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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P: 2 (soon™?) S: core Scoped to the core flutter_map functionality
Projects
None yet
Development

No branches or pull requests

2 participants