Skip to content
This repository has been archived by the owner on Nov 9, 2023. It is now read-only.

Commit

Permalink
New methods: fitZoom and fitBounds
Browse files Browse the repository at this point in the history
  • Loading branch information
hpneo committed Jun 6, 2012
1 parent 06553ed commit 16b21ce
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -8,6 +8,10 @@ Visit the examples in [hpneo.github.com/gmaps](http://hpneo.github.com/gmaps/)
Changelog
---------

0.1.12.4
-----------------------
* New methods: fitZoom and fitBounds

0.1.12.3
-----------------------
* New method: refresh
Expand Down
2 changes: 1 addition & 1 deletion examples/geolocation.html
Expand Up @@ -11,7 +11,7 @@
<script type="text/javascript">
var map;
$(document).ready(function(){
map = new GMaps({
var map = new GMaps({
div: '#map',
lat: -12.043333,
lng: -77.028333
Expand Down
22 changes: 22 additions & 0 deletions gmaps.js
Expand Up @@ -163,6 +163,28 @@ var GMaps = (function($) {
google.maps.event.trigger(this.map, 'resize');
};

this.fitZoom = function() {
var latLngs = [];
var markers_length = this.markers.length;

for(var i=0; i < markers_length; i++) {
latLngs.push(this.markers[i].getPosition());
}

this.fitBounds(latLngs);
};

this.fitBounds = function(latLngs) {
var total = latLngs.length;
var bounds = new google.maps.LatLngBounds();

for(var i=0; i < total; i++) {
bounds.extend(latLngs[i]);
}

this.map.fitBounds(bounds);
};

// Map methods
this.setCenter = function(lat, lng, callback) {
this.map.panTo(new google.maps.LatLng(lat, lng));
Expand Down

0 comments on commit 16b21ce

Please sign in to comment.