diff --git a/assets/js/input.js b/assets/js/input.js index 5bf43bd..f3f34f0 100755 --- a/assets/js/input.js +++ b/assets/js/input.js @@ -130,6 +130,8 @@ this.setLocations(); + this.fitBounds(); + this.activateIconSelect(); if ( this.settings.drawingManager && this.settings.editable ) @@ -723,6 +725,38 @@ }, + fitBounds: function () { + var bounds = new google.maps.LatLngBounds(); + var hasBounds = false; + + for ( var key in this.mapObjects ) { + var mapObject = this.mapObjects[key]; + + if ( + mapObject instanceof google.maps.Circle || + mapObject instanceof google.maps.Rectangle + ) { + bounds.union(mapObject.getBounds()); + hasBounds = true; + } + + if (mapObject instanceof google.maps.Polygon) { + mapObject.getPaths().forEach(function(path) { + path.forEach(function(latLng) { + bounds.extend(latLng); + }); + }); + hasBounds = true; + } + + } + + if (hasBounds) { + this.map.fitBounds(bounds); + this.map.setCenter(bounds.getCenter()); + } + }, + contextmenu: function(latLng, pixel) { var self = this,