File tree Expand file tree Collapse file tree 1 file changed +14
-10
lines changed Expand file tree Collapse file tree 1 file changed +14
-10
lines changed Original file line number Diff line number Diff line change 95
95
* @function zoomToIncludeMarkers
96
96
*/
97
97
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 ) ;
104
112
}
105
- if ( vm . mapOptions . maximumZoom ) {
106
- vm . enableMaximumZoomCheck = true ; //enable zoom check after resizing for markers
107
- }
108
- vm . map . fitBounds ( bounds ) ;
109
113
} ;
110
114
111
115
/**
You can’t perform that action at this time.
0 commit comments