Merge pull request #3392 from IvanSanchez/master

Implement L.Map.flyToBounds(), #3391
This commit is contained in:
Vladimir Agafonkin 2015-04-22 14:23:17 +03:00
commit 578247150c
2 changed files with 15 additions and 2 deletions

View File

@ -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) {

View File

@ -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);
}
});