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

bounds is not set after initial map load #16

Open
nmccready opened this issue Oct 29, 2015 · 2 comments
Open

bounds is not set after initial map load #16

nmccready opened this issue Oct 29, 2015 · 2 comments

Comments

@nmccready
Copy link
Contributor

From @jasadams on March 25, 2014 13:22

I know the way bounds and center was reworked recently. One side effect of this improvement is that after the inital load of my map, the bounds are not set. It is not until I pan or zoom the map that the bounds are set.
I did a little initial investigation and it seems that the listener for the "boundsChanged" event in the bounds directive is not set up in time for the initial broadcast of this event when the center is set in the center directive. The listener is inside a Map.whenReady promise and the map is not ready when the initial center is set.

Copied from original issue: tombatossals/angular-leaflet-directive#340

@nmccready
Copy link
Contributor Author

From @jasadams on March 25, 2014 13:55

If I move the code that sets up the listener to just after the getMap promise it seems to work ok. I thought this may be safe because we shouldn't get a boundsChanged event until the map and the centerController are ready anyway. However, I am not familiar enough with the code to know the potential downsides to this. I have applied this patch in my fork and am using it in my project until there is a more permanent fix in this project.

@nmccready
Copy link
Contributor Author

From @joeystandrew on July 9, 2015 20:2

I am actually having this same issue, to fix it inside my Ionic application I check for missing bounds on map moveEnd and re-set it.

            var trueBounds = map.getBounds();
            var trueNE = trueBounds.getNorthEast();
            var trueSW = trueBounds.getSouthWest();

            $scope.map.bounds = {
                northEast: {
                    lat: trueNE.lat,
                    lng: trueNE.lng
                },
                southWest: {
                    lat: trueSW.lat,
                    lng: trueSW.lng
                }
            };

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

1 participant