Skip to content

Commit

Permalink
Merge pull request #12 from dwatts3624/fit-bounds
Browse files Browse the repository at this point in the history
Fit boundaries on init
  • Loading branch information
rozklad authored Oct 19, 2020
2 parents 9a85721 + 99ed00a commit a69fefb
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions assets/js/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@

this.setLocations();

this.fitBounds();

this.activateIconSelect();

if ( this.settings.drawingManager && this.settings.editable )
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit a69fefb

Please sign in to comment.