Leaflet icon indicating copy to clipboard operation
Leaflet copied to clipboard

map.getBounds() returns wrong value

Open IvanSanchez opened this issue 8 years ago • 2 comments

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();

IvanSanchez avatar Sep 27 '16 13:09 IvanSanchez

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

fnicollet avatar Sep 28 '16 10:09 fnicollet

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.

IvanSanchez avatar Sep 28 '16 10:09 IvanSanchez