Skip to content

Commit 9cdc061

Browse files
committed
Merge pull request allenhwkim#590 from TimoPerplex/pull-zoom-to-include-fix
Updated zoomToIncludeMarkers to only fit to bounds if there are markers
2 parents b8cfe56 + 90c65be commit 9cdc061

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

controllers/map-controller.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,21 @@
9595
* @function zoomToIncludeMarkers
9696
*/
9797
vm.zoomToIncludeMarkers = function() {
98-
var bounds = new google.maps.LatLngBounds();
99-
for (var k1 in vm.map.markers) {
100-
bounds.extend(vm.map.markers[k1].getPosition());
101-
}
102-
for (var k2 in vm.map.customMarkers) {
103-
bounds.extend(vm.map.customMarkers[k2].getPosition());
98+
// Only fit to bounds if we have any markers
99+
// object.keys is supported in all major browsers (IE9+)
100+
if ((vm.map.markers != null && Object.keys(vm.map.markers).length > 0) || (vm.map.customMarkers != null && Object.keys(vm.map.customMarkers).length > 0)) {
101+
var bounds = new google.maps.LatLngBounds();
102+
for (var k1 in vm.map.markers) {
103+
bounds.extend(vm.map.markers[k1].getPosition());
104+
}
105+
for (var k2 in vm.map.customMarkers) {
106+
bounds.extend(vm.map.customMarkers[k2].getPosition());
107+
}
108+
if (vm.mapOptions.maximumZoom) {
109+
vm.enableMaximumZoomCheck = true; //enable zoom check after resizing for markers
110+
}
111+
vm.map.fitBounds(bounds);
104112
}
105-
if (vm.mapOptions.maximumZoom) {
106-
vm.enableMaximumZoomCheck = true; //enable zoom check after resizing for markers
107-
}
108-
vm.map.fitBounds(bounds);
109113
};
110114

111115
/**

0 commit comments

Comments
 (0)