From 3a9da3bd7ca2ac8c0772a2d4328de45d109b9b5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20S=C3=A1nchez=20Ortega?= Date: Thu, 4 Jun 2015 15:02:28 +0200 Subject: [PATCH] Fixes #3431, GridLayer.setOpacity() behaviour on active tiles. --- debug/tests/tile-opacity.html | 44 +++++++++++++++++++++++++++++++++++ src/layer/tile/GridLayer.js | 9 ++++--- 2 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 debug/tests/tile-opacity.html diff --git a/debug/tests/tile-opacity.html b/debug/tests/tile-opacity.html new file mode 100644 index 000000000..12c81e3fd --- /dev/null +++ b/debug/tests/tile-opacity.html @@ -0,0 +1,44 @@ + + + + Leaflet debug page + + + + + + + + + + + + + + The opacity of the "toner" layer should pulse nicely, even when dragging/zooming the map around with new tiles. +
+ + + + diff --git a/src/layer/tile/GridLayer.js b/src/layer/tile/GridLayer.js index 9b6cfb160..730960f16 100644 --- a/src/layer/tile/GridLayer.js +++ b/src/layer/tile/GridLayer.js @@ -155,11 +155,12 @@ L.GridLayer = L.Layer.extend({ } var now = +new Date(), - nextFrame = false; + nextFrame = false, + willPrune = false; for (var key in this._tiles) { var tile = this._tiles[key]; - if (!tile.current || !tile.loaded || tile.active) { continue; } + if (!tile.current || !tile.loaded) { continue; } var fade = Math.min(1, (now - tile.loaded) / 200); if (fade < 1) { @@ -167,11 +168,13 @@ L.GridLayer = L.Layer.extend({ nextFrame = true; } else { L.DomUtil.setOpacity(tile.el, opacity); + if (tile.active) { willPrune = true; } tile.active = true; - this._pruneTiles(); } } + if (willPrune) { this._pruneTiles(); } + if (nextFrame) { L.Util.cancelAnimFrame(this._fadeFrame); this._fadeFrame = L.Util.requestAnimFrame(this._updateOpacity, this);