Skip to content

Commit 00a99ab

Browse files
committed
Merge pull request angular-ui#1826 from davidpelayo/master
gMap.fitBounds requires to be async
2 parents e6b021d + fda9f71 commit 00a99ab

File tree

4 files changed

+27
-42
lines changed

4 files changed

+27
-42
lines changed

dist/angular-google-maps-street-view_dev_mapped.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/angular-google-maps.js

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! angular-google-maps 2.3.2 2016-02-11
1+
/*! angular-google-maps 2.3.2 2016-04-25
22
* AngularJS directives for Google Maps
33
* git: https://github.com/angular-ui/angular-google-maps.git
44
*/
@@ -1036,7 +1036,7 @@ Nicholas McCready - https://twitter.com/nmccready
10361036
}).call(this);
10371037
;(function() {
10381038
angular.module('uiGmapgoogle-maps.directives.api.utils').service('uiGmapFitHelper', [
1039-
'uiGmapLogger', function($log) {
1039+
'uiGmapLogger', '$timeout', function($log, $timeout) {
10401040
return {
10411041
fit: function(markersOrPoints, gMap) {
10421042
var bounds, everSet, key, markerOrPoint, point;
@@ -1054,7 +1054,9 @@ Nicholas McCready - https://twitter.com/nmccready
10541054
bounds.extend(point);
10551055
}
10561056
if (everSet) {
1057-
return gMap.fitBounds(bounds);
1057+
return $timeout(function() {
1058+
return gMap.fitBounds(bounds);
1059+
});
10581060
}
10591061
}
10601062
}
@@ -1098,7 +1100,9 @@ Nicholas McCready - https://twitter.com/nmccready
10981100
if (!value) {
10991101
return;
11001102
}
1101-
if (Array.isArray(value) && value.length === 2) {
1103+
if (value instanceof google.maps.LatLng) {
1104+
return value;
1105+
} else if (Array.isArray(value) && value.length === 2) {
11021106
return new google.maps.LatLng(value[1], value[0]);
11031107
} else if (angular.isDefined(value.type) && value.type === 'Point') {
11041108
return new google.maps.LatLng(value.coordinates[1], value.coordinates[0]);
@@ -6644,7 +6648,7 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
66446648
};
66456649

66466650
Map.prototype.link = function(scope, element, attrs) {
6647-
var listeners, unbindCenterWatch;
6651+
var listeners;
66486652
listeners = [];
66496653
scope.$on('$destroy', function() {
66506654
uiGmapEventsHelper.removeEvents(listeners);
@@ -6654,18 +6658,6 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
66546658
}
66556659
});
66566660
scope.idleAndZoomChanged = false;
6657-
if (scope.center == null) {
6658-
unbindCenterWatch = scope.$watch('center', (function(_this) {
6659-
return function() {
6660-
if (!scope.center) {
6661-
return;
6662-
}
6663-
unbindCenterWatch();
6664-
return _this.link(scope, element, attrs);
6665-
};
6666-
})(this));
6667-
return;
6668-
}
66696661
return uiGmapGoogleMapApi.then((function(_this) {
66706662
return function(maps) {
66716663
var _gMap, customListeners, disabledEvents, dragging, el, eventName, getEventHandler, mapOptions, maybeHookToEvent, opts, ref, resolveSpawned, settingFromDirective, spawned, type, updateCenter, zoomPromise;
@@ -6679,13 +6671,15 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
66796671
map: _gMap
66806672
});
66816673
};
6682-
if (!_this.validateCoords(scope.center)) {
6683-
$log.error('angular-google-maps: could not find a valid center property');
6674+
if (!angular.isDefined(scope.center) && !angular.isDefined(scope.bounds)) {
6675+
$log.error('angular-google-maps: a center or bounds property is required');
66846676
return;
66856677
}
6678+
if (!angular.isDefined(scope.center)) {
6679+
scope.center = new google.maps.LatLngBounds(_this.getCoords(scope.bounds.southwest), _this.getCoords(scope.bounds.northeast)).getCenter();
6680+
}
66866681
if (!angular.isDefined(scope.zoom)) {
6687-
$log.error('angular-google-maps: map zoom property not set');
6688-
return;
6682+
scope.zoom = 10;
66896683
}
66906684
el = angular.element(element);
66916685
el.addClass('angular-google-map');
@@ -6764,16 +6758,6 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
67646758
s = scope;
67656759
}
67666760
if (_.includes(disabledEvents, 'center')) {
6767-
return;
6768-
}
6769-
if (angular.isDefined(s.center.type)) {
6770-
if (s.center.coordinates[1] !== c.lat()) {
6771-
s.center.coordinates[1] = c.lat();
6772-
}
6773-
if (s.center.coordinates[0] !== c.lng()) {
6774-
return s.center.coordinates[0] = c.lng();
6775-
}
6776-
} else {
67776761
if (s.center.latitude !== c.lat()) {
67786762
s.center.latitude = c.lat();
67796763
}

dist/angular-google-maps.min.js

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
angular.module('uiGmapgoogle-maps.directives.api.utils')
2-
.service 'uiGmapFitHelper', [ 'uiGmapLogger', ($log) ->
2+
.service 'uiGmapFitHelper', [ 'uiGmapLogger', '$timeout', ($log, $timeout) ->
33
fit: (markersOrPoints, gMap) ->
44
if gMap and markersOrPoints?.length
55
bounds = new google.maps.LatLngBounds()
@@ -9,5 +9,6 @@ angular.module('uiGmapgoogle-maps.directives.api.utils')
99
everSet = true unless everSet
1010
point = if _.isFunction markerOrPoint.getPosition then markerOrPoint.getPosition() else markerOrPoint
1111
bounds.extend point
12-
gMap.fitBounds(bounds) if everSet
12+
if everSet
13+
$timeout () -> gMap.fitBounds(bounds)
1314
]

0 commit comments

Comments
 (0)