fnicollet / Leaflet

:leaves: JavaScript library for mobile-friendly interactive maps
http://leafletjs.com
BSD 2-Clause "Simplified" License
48 stars 20 forks source link

map.getBounds() returns wrong value #7

Open IvanSanchez opened 8 years ago

IvanSanchez commented 8 years ago

I think that #2 is deeper than just maxBounds, and affects map.getBounds() directly.

Trying this code will show that the map bounds calculation is wrong, as it doesn't take into account the map center and/or rotation somehow:

        var centerMarker;
        var bounds;
        function displayCenter() {
            if (centerMarker) { centerMarker.remove(); }
            centerMarker = L.circleMarker(map.getCenter()).addTo(map);

            if (bounds) { bounds.remove(); }
            bounds = L.rectangle(map.getBounds().pad(-0.1)).addTo(map);
        }

        map.on('moveend zoomend resetview', displayCenter);

        displayCenter();
fnicollet commented 8 years ago

Thanks for noticing that, could be the root of many issues indeed.

So if you take in account the rotation of the map, the bounds will be larger than the non-rotated bounds. Is there not a risk of the latlngBounds being "clamped" to -90,90 / -180/180? Or maybe you have the same issue with leaflet at zoom 0/1? I need to have a closer look

Fabien

IvanSanchez commented 8 years ago

I don't think that'll be a problem, as the bounds can be left unwrapped (for the time being). i.e. a longitude range of [179, 181] is perfectly fine, specially when [179, -179] would cause problems.