Implement L.Map.flyToBounds(), #3391

This commit is contained in:
Iván Sánchez Ortega 2015-04-22 00:22:52 +02:00
parent c315751b94
commit 4d70fe09a7
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}); return this.setView(newCenter, zoom, {zoom: options});
}, },
fitBounds: function (bounds, options) { _getBoundsCenterZoom: function (bounds, options) {
options = options || {}; options = options || {};
bounds = bounds.getBounds ? bounds.getBounds() : L.latLngBounds(bounds); bounds = bounds.getBounds ? bounds.getBounds() : L.latLngBounds(bounds);
@ -106,7 +106,15 @@ L.Map = L.Evented.extend({
nePoint = this.project(bounds.getNorthEast(), zoom), nePoint = this.project(bounds.getNorthEast(), zoom),
center = this.unproject(swPoint.add(nePoint).divideBy(2).add(paddingOffset), 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) { fitWorld: function (options) {

View File

@ -56,5 +56,10 @@ L.Map.include({
this.fire('zoomstart'); this.fire('zoomstart');
frame.call(this); frame.call(this);
},
flyToBounds: function(bounds, options) {
var target = this._getBoundsCenterZoom(bounds, options);
return this.flyTo(target.center, target.zoom);
} }
}); });