Merge pull request #3392 from IvanSanchez/master
Implement L.Map.flyToBounds(), #3391
This commit is contained in:
commit
578247150c
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user