diff --git a/src/map/Map.js b/src/map/Map.js index ee2a411d..9d2cb376 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -88,7 +88,7 @@ L.Map = L.Evented.extend({ return this.setView(newCenter, zoom, {zoom: options}); }, - fitBounds: function (bounds, options) { + _getBoundsCenterZoom: function (bounds, options) { options = options || {}; bounds = bounds.getBounds ? bounds.getBounds() : L.latLngBounds(bounds); @@ -106,7 +106,15 @@ L.Map = L.Evented.extend({ nePoint = this.project(bounds.getNorthEast(), zoom), center = this.unproject(swPoint.add(nePoint).divideBy(2).add(paddingOffset), zoom); - return this.setView(center, zoom, options); + return { + center: center, + zoom: zoom + }; + }, + + fitBounds: function (bounds, options) { + var target = this._getBoundsCenterZoom(bounds, options); + return this.setView(target.center, target.zoom, options); }, fitWorld: function (options) { diff --git a/src/map/anim/Map.FlyTo.js b/src/map/anim/Map.FlyTo.js index 81128f1a..d55c3eeb 100644 --- a/src/map/anim/Map.FlyTo.js +++ b/src/map/anim/Map.FlyTo.js @@ -56,5 +56,10 @@ L.Map.include({ this.fire('zoomstart'); frame.call(this); + }, + + flyToBounds: function(bounds, options) { + var target = this._getBoundsCenterZoom(bounds, options); + return this.flyTo(target.center, target.zoom); } });