From ad8fc9c36bc6846b486868a691b60f340ff63ffd Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 25 Jan 2018 08:08:05 +0100 Subject: [PATCH] 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 --- spec/suites/layer/tile/TileLayerSpec.js | 23 +++++++++++++++++++++++ src/layer/tile/GridLayer.js | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/spec/suites/layer/tile/TileLayerSpec.js b/spec/suites/layer/tile/TileLayerSpec.js index 2813d032..655c2320 100644 --- a/spec/suites/layer/tile/TileLayerSpec.js +++ b/spec/suites/layer/tile/TileLayerSpec.js @@ -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); + }); + }); }); diff --git a/src/layer/tile/GridLayer.js b/src/layer/tile/GridLayer.js index 57168205..482f5dfe 100755 --- a/src/layer/tile/GridLayer.js +++ b/src/layer/tile/GridLayer.js @@ -842,7 +842,7 @@ export var GridLayer = Layer.extend({ }, _tileReady: function (coords, err, tile) { - if (!this._map) { return; } + if (!this._map || tile.getAttribute('src') === Util.emptyImageUrl) { return; } if (err) { // @event tileerror: TileErrorEvent