run view reset before load, fix #2510

This commit is contained in:
Vladimir Agafonkin 2014-03-05 23:27:32 +02:00
parent b5b2dc06dc
commit 1a7b12604b
2 changed files with 27 additions and 7 deletions

View File

@ -1,12 +1,32 @@
describe('TileLayer', function () { describe('TileLayer', function () {
var tileUrl = ''; var tileUrl = '',
map;
beforeEach(function () {
map = L.map(document.createElement('div'));
});
describe("#onAdd", function () {
it('is called after viewreset on first map load', function () {
var layer = L.tileLayer(tileUrl).addTo(map);
var onAdd = layer.onAdd,
onAddSpy = sinon.spy();
layer.onAdd = function () {
onAdd.apply(this, arguments);
onAddSpy();
};
var onReset = sinon.spy();
map.on('viewreset', onReset);
map.setView([0, 0], 0);
expect(onReset.calledBefore(onAddSpy)).to.be.ok();
});
});
describe("#getMaxZoom, #getMinZoom", function () { describe("#getMaxZoom, #getMinZoom", function () {
var map;
beforeEach(function () {
map = L.map(document.createElement('div'));
});
describe("when a tilelayer is added to a map with no other layers", function () { describe("when a tilelayer is added to a map with no other layers", function () {
it("has the same zoomlevels as the tilelayer", function () { it("has the same zoomlevels as the tilelayer", function () {
var maxZoom = 10, var maxZoom = 10,

View File

@ -499,12 +499,12 @@ L.Map = L.Evented.extend({
var loading = !this._loaded; var loading = !this._loaded;
this._loaded = true; this._loaded = true;
this.fire('viewreset', {hard: !preserveMapOffset});
if (loading) { if (loading) {
this.fire('load'); this.fire('load');
} }
this.fire('viewreset', {hard: !preserveMapOffset});
this.fire('move'); this.fire('move');
if (zoomChanged || afterZoomAnim) { if (zoomChanged || afterZoomAnim) {