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

[BUG] Map warps to other side of the planet when map center hits antimeridian #2022

Open
corepuncher opened this issue Jan 30, 2025 · 4 comments
Labels
P: 2 (soon™?) S: core Scoped to the core flutter_map functionality

Comments

@corepuncher
Copy link

What is the bug?

When I pan my map west to -180, instead of stopping like a wall, it flips around to the other side of the globe.

Is there a way to put the "wall" behavior back? I enjoyed that natural blocking behavior actually.

How can we reproduce it?

Unless it's something in my code specifically, just pan/fling westward beyond -180 and see what happens.

If you cannot reproduce, I'll give more info on my setup for troubleshooting.

Do you have a potential solution?

No response

Platforms

All

Severity

Minimum: Allows normal functioning

@corepuncher corepuncher added bug This issue reports broken functionality or another error needs triage This new bug report needs reproducing and prioritizing labels Jan 30, 2025
@josxha
Copy link
Contributor

josxha commented Jan 30, 2025

I'm not able to reproduce this with a normal pan gesture but with a fling gesture.

fling.bug.mp4

@JaffaKetchup
Copy link
Member

This will occur when camera constraints are set. The end of the fling jumps past the constraints.

@JaffaKetchup JaffaKetchup added P: 2 (soon™?) S: core Scoped to the core flutter_map functionality and removed bug This issue reports broken functionality or another error needs triage This new bug report needs reproducing and prioritizing labels Jan 30, 2025
@JaffaKetchup
Copy link
Member

The workaround is probably to inset the constraints a bit from the edge? But we need to look into this.

@JaffaKetchup JaffaKetchup changed the title [BUG] Map warps to other side of the planet when map center hits 180 W [BUG] Map warps to other side of the planet when map center hits antimeridian Jan 30, 2025
@corepuncher
Copy link
Author

corepuncher commented Jan 31, 2025

This will occur when camera constraints are set. The end of the fling jumps past the constraints.

I have no camera constraints set myself.

I see what is happening though.

Since the behavior around the international dateline has changed, my old logic no longer works.

Before: Panning map to -180 would simply stop there. I never had to deal with it.
Now: Panning across -180 flips the longitude to a positive value.

Old Logic: If map centerpoint goes EAST of -40 (or WEST of -180), I move the map to longitude -40 (or -180).

   if (newLat > globals.maxNorthBound) newLat = globals.maxNorthBound;
   if (newLat < globals.maxSouthBound) newLat = globals.maxSouthBound;
   if (newLon < globals.maxWestBound) newLon = globals.maxWestBound;
   if (newLon > globals.maxEastBound) newLon = globals.maxEastBound;


 if (newLat != position.center.latitude || newLon != position.center.longitude) {
     mapState.move(LatLng(newLat, newLon), position.zoom);
 }

But now, the map is allowed to move west of -180, to 180. My old logic sees 180 as > -40, so my logic below warps the map all the way to the other side of my domain to the east side (-40).

Any way to have a flag that puts the "barrier" at -180 back? If not, I'll have to think about how to mitigate. Perhaps if the fling stops anywhere between -180 and "a ways west" of there, snap back to -180, otherwise if they are over the Atlantic Ocean, snap back to -40, or something like that.

Using camera constraints would probably be optimal but I could never get it too "not" thrown an exceptions when changing device orientation, which many times causes it to go out of bounds.

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

3 participants