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

map.getBounds() return values outside visible map #6890

Open
5 tasks done
didulis opened this issue Nov 14, 2019 · 2 comments
Open
5 tasks done

map.getBounds() return values outside visible map #6890

didulis opened this issue Nov 14, 2019 · 2 comments

Comments

@didulis
Copy link

didulis commented Nov 14, 2019

  • I've looked at the documentation to make sure the behavior is documented and expected
  • I'm sure this is a Leaflet code issue, not an issue with my own code nor with the framework I'm using (Cordova, Ionic, Angular, React…)
  • I've searched through the issues to make sure it's not yet reported

Application, developed by us, requests from API coordinates of points for map bounds retrieved by map.getBounds() and adds markers on the map, but sometimes these markers are added outside visible area.
For testing purpose, to see if this behaviour is only in our app or in general, I created this fiddle - https://jsfiddle.net/kzLohbac/1/
(I convert decimal degrees to "deg min sec" format only to simplify visual comparison of coordinates)

Steps to reproduce
Steps to reproduce the behavior:

  • create map widget
  • output map.getBounds() coordinates
  • attach "mousemove" to output coordinates of current mouse location in map
  • slowly move cursor to any edge of visible map and compare last mouse coordinates with previously printed map.getBounds() coordinates (left edge with SouthWest longitude, right edge with NorthEast longitude, top edge with NorthEast latitude and bottom edge with SouthWest latitude)

Expected behavior
Returns the geographical bounds visible in the current map view ( https://leafletjs.com/reference-1.5.0.html#map-getbounds )

Current behavior
Some bounds visible in current map view differ from ones reported by map.getBounds(). And sometimes this difference is about half of the geographic second.

Environment

  • Leaflet version: 1.5.1

  • Browser (with version): Firefox 70.0 (64-bit), Google Chrome 78.0.3904.97 (64-bit)

  • OS/Platform (with version): Fedora 30

  • this example is as simple as possible

  • this example does not rely on any third party code

@lukacg
Copy link

lukacg commented Dec 24, 2019

Try something like this:
bounds = new L.LatLngBounds(new L.LatLng(48, 15),new L.LatLng(49, 17)); map.fitBounds(bounds);

@didulis
Copy link
Author

didulis commented Jan 8, 2020

Just now I had time to test your suggestion @lukacg and map.getBounds() still returns values outside visible map

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

No branches or pull requests

3 participants