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

panTo() does not center map at requested coordinate #922

Closed
broofa opened this issue Aug 19, 2012 · 4 comments
Closed

panTo() does not center map at requested coordinate #922

broofa opened this issue Aug 19, 2012 · 4 comments

Comments

@broofa
Copy link

broofa commented Aug 19, 2012

Let's try to center and zoom a map on the greenwich observatory ...

  • Go to a leaflet map (e.g. the one on http://leaflet.cloudmade.com/)
  • map.setZoom(0); map.panTo(0,0); (start at a known coord/zoom level)
  • map.panTo([51.4768, 0.0006]) to center map at greenwich observatory (in theory)
  • map.setZoom(16) to zoom in
  • Notice the map is nowhere near the observatory. In fact, we're ~10 miles north of it

This is confirmed by map.getCenter().toString() => LatLng(51.61802, 0)

@mourner
Copy link
Member

mourner commented Aug 19, 2012

Duplicate of #426. panTo works correctly, the problem is that it pans it on zoom 0 with rounding to pixels, and then you zoom by 16 zoom levels. So it's a rounding problem.

@mourner mourner closed this as completed Aug 19, 2012
@miguelcobain
Copy link
Contributor

Sorry, for commenting here, but this seems like a very accurate description of what I'm seeing.

I've made this jsbin: https://jsbin.com/putezoyido/edit?js,console,output

When you click "Go to new location" we call

map.panTo([41.142937, -8.534538]);

however, moveend is triggered and if we check the map's center there we get

41.14293584388727
-8.534536957740785

Is this something expected or a bug?

@chrillewoodz
Copy link

So what's the solution? :S I'm trying to pan but it pans me nowhere near the coordinates I'm giving it.. Been trying to find a solution for the last hour but none of them works. Why can't the panTo just work like it's supposed to?

@ghybs
Copy link
Collaborator

ghybs commented Apr 17, 2018

Hi @chrillewoodz, great to hear that you find Leaflet useful!

Instead of commenting an old and closed ticket, and if you are really sure that this is a bug in Leaflet, please open a new issue.

Please provide an effective bug report, and in particular all the information requested in the issue template (provided when you create a new issue), so that we can effectively investigate.

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

No branches or pull requests

5 participants