angular-ui / ui-leaflet

AngularJS directive to embed an interact with maps managed by Leaflet library
http://angular-ui.github.io/ui-leaflet
Other
314 stars 134 forks source link

bounds is not set after initial map load #16

Open nmccready opened 9 years ago

nmccready commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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
                }
            };