Skip to content
This repository has been archived by the owner on Sep 26, 2022. It is now read-only.

map.getBounds() returns wrong value #7

Open
IvanSanchez opened this issue Sep 27, 2016 · 2 comments
Open

map.getBounds() returns wrong value #7

IvanSanchez opened this issue Sep 27, 2016 · 2 comments

Comments

@IvanSanchez
Copy link

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
Copy link
Owner

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
Copy link
Author

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.

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

No branches or pull requests

2 participants