Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

New methods: fitZoom and fitBounds

  • Loading branch information...
commit 16b21cea3bb3e0dd92019755a1162e6b4e51147c 1 parent 06553ed
@hpneo authored
Showing with 27 additions and 1 deletion.
  1. +4 −0 README.md
  2. +1 −1  examples/geolocation.html
  3. +22 −0 gmaps.js
View
4 README.md
@@ -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
View
2  examples/geolocation.html
@@ -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
View
22 gmaps.js
@@ -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));
Please sign in to comment.
Something went wrong with that request. Please try again.