diff --git a/debug/map/grid.html b/debug/map/grid.html index 234fc05c..1e757743 100644 --- a/debug/map/grid.html +++ b/debug/map/grid.html @@ -38,6 +38,7 @@ grid.on('loading', function() { console.log('loading'); }); grid.on('load', function() { console.log('load'); }); + grid.on('tileunload', function(tile) { console.log('tileunload ' + tile.coords.x + ',' + tile.coords.y + ',' + tile.coords.z); }); var map = L.map('map') .setView([50.5, 30.51], 10) diff --git a/src/layer/tile/GridLayer.js b/src/layer/tile/GridLayer.js index 4a15de35..1707eab5 100644 --- a/src/layer/tile/GridLayer.js +++ b/src/layer/tile/GridLayer.js @@ -41,6 +41,7 @@ L.GridLayer = L.Layer.extend({ }, onRemove: function (map) { + this._removeAllTiles(); L.DomUtil.remove(this._container); map._removeZoomLimit(this); this._container = null; @@ -217,6 +218,7 @@ L.GridLayer = L.Layer.extend({ this._levels[z].el.style.zIndex = maxZoom - Math.abs(zoom - z); } else { L.DomUtil.remove(this._levels[z].el); + this._removeTilesAtZoom(z); delete this._levels[z]; } } @@ -273,6 +275,15 @@ L.GridLayer = L.Layer.extend({ } }, + _removeTilesAtZoom: function (zoom) { + for (var key in this._tiles) { + if (this._tiles[key].coords.z !== zoom) { + continue; + } + this._removeTile(key); + } + }, + _removeAllTiles: function () { for (var key in this._tiles) { this._removeTile(key);