-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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 works incorrectly on a date line cross #295
Comments
Hi, I have the same problem. To resolve it I test manually if the mapcenter is inside the bounds. This fails and then I know I got the bounds for the wrong side of the earth. |
Thanks, will think about this. |
Hi weitzj is it possible to have a look at your code to fix this problem? I can see how your solution would work when the world is zoomed out enough and I have that working. But if we are zoomed in more the it doesnt work... |
I tried this, personally. /**
* temp fix to address https://github.com/CloudMade/Leaflet/issues/295
* @return L.LatLngBounds - mapBounds - the unaltered mapBounds object, if the bug is not triggered, else return the entire earth
*/
getSafeMapBounds: function(mapBounds){
var mapBounds = this._map.getBounds();
if (!mapBounds.contains(this._map.getCenter())) {
return new L.LatLngBounds(new L.LatLng(-60, -170), new L.LatLng(85, 179)); //The World!
}
return mapBounds;
}, That said, I haven't had a chance to test it extensively, yet, but it appears to work for my purposes (I can use the entire world instead of just the bounds, in my case) |
Well, this is my fix: you need to switch the longitudes, since they get flipped: /**
|
Thanks for sharing guys, I'll try to incorporate a similar fix to the upcoming stable release. |
Thanks Weitzj. I'll update mine. That seems to be a more intelligent solution, now that I better understand the problem! |
Should be properly fixed now, guys, check it out! |
Good job, it works well. |
Works great! Thanks, Mourner! |
Awesome, thanks :) |
Super thanks Mourner! Works a treat! |
Hi,
I have an issue using the getBounds function of the map object. If the map extent is out of the typical longitude range [-180, 180], the getBounds returns what is NOT visible. For example, if the map shows from Japan to New-York, the returned bounds are: _southWest: lat: -17.9, lng: -67.5
_northEast: lat: 79.8, lng: 95.6
This is what is NOT visible (south america to north russia). Indeed, the map center is not contained in the bounds.
The getBounds method could return an array of bounds when is out of the [-180,180] range. From X to 180 and -180 to Y.
What do you think ?
Jeff
The text was updated successfully, but these errors were encountered: