Ensure that getBounds can be called during the first moveend event

Fixes #1027
This commit is contained in:
John Firebaugh 2012-10-04 14:02:46 -07:00
parent 87bc14d968
commit fbf91fef54
2 changed files with 18 additions and 3 deletions

View File

@ -1 +1,14 @@
describe("Map", noSpecs);
describe("Map", function () {
describe("#getBounds", function () {
it("is safe to call from within a moveend callback during initial load (#1027)", function () {
var c = document.createElement('div'),
map = L.map(c);
map.on("moveend", function () {
map.getBounds();
});
map.setView([51.505, -0.09], 13);
});
});
});

View File

@ -517,6 +517,9 @@ L.Map = L.Class.extend({
this._tileLayersToLoad = this._tileLayersNum;
var loading = !this._loaded;
this._loaded = true;
this.fire('viewreset', {hard: !preserveMapOffset});
this.fire('move');
@ -527,8 +530,7 @@ L.Map = L.Class.extend({
this.fire('moveend', {hard: !preserveMapOffset});
if (!this._loaded) {
this._loaded = true;
if (loading) {
this.fire('load');
}
},