Fix(GridLayer): Do not fire 'tileload' event if tile src is empty image (#6025)

* do not fire 'load' event if tile src is the empty image (i.e. L.Util.emptyImageUrl)

* add TileLayer setUrl test
This commit is contained in:
Andrew 2018-01-25 08:08:05 +01:00 committed by ghybs
parent 2dc70945f8
commit ad8fc9c36b
2 changed files with 24 additions and 1 deletions

View File

@ -455,4 +455,27 @@ describe('TileLayer', function () {
}); });
} }
}); });
describe('#setUrl', function () {
it('fires only one load event', function (done) {
var layer = L.tileLayer(placeKitten).addTo(map);
var counts = {
load: 0,
tileload: 0
};
map.setView([0, 0], 1);
layer.on('tileload load', function (e) {
counts[e.type]++;
});
layer.setUrl(placeKitten);
setTimeout(function () {
expect(counts.load).to.equal(1);
expect(counts.tileload).to.equal(8);
done();
}, 250);
});
});
}); });

View File

@ -842,7 +842,7 @@ export var GridLayer = Layer.extend({
}, },
_tileReady: function (coords, err, tile) { _tileReady: function (coords, err, tile) {
if (!this._map) { return; } if (!this._map || tile.getAttribute('src') === Util.emptyImageUrl) { return; }
if (err) { if (err) {
// @event tileerror: TileErrorEvent // @event tileerror: TileErrorEvent