From ff1f99a03f766258780139f988ef9e4e18c1d37b Mon Sep 17 00:00:00 2001 From: ahocevar Date: Fri, 25 May 2012 18:47:57 +0200 Subject: [PATCH] Don't reuse tile images unless we have a new url to load. Without this change, some browsers don't cache the images. See #454 for a discussion about this issue. --- lib/OpenLayers/Tile/Image.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/OpenLayers/Tile/Image.js b/lib/OpenLayers/Tile/Image.js index 50c2548202..abfdf24f39 100644 --- a/lib/OpenLayers/Tile/Image.js +++ b/lib/OpenLayers/Tile/Image.js @@ -339,9 +339,9 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, { */ setImgSrc: function(url) { var img = this.imgDiv; - img.style.visibility = 'hidden'; - img.style.opacity = 0; if (url) { + img.style.visibility = 'hidden'; + img.style.opacity = 0; // don't set crossOrigin if the url is a data URL if (this.crossOriginKeyword) { if (url.substr(0, 5) !== 'data:') { @@ -351,6 +351,13 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, { } } img.src = url; + } else { + // Remove reference to the image, and leave it to the browser's + // caching and garbage collection. + this.imgDiv = null; + if (img.parentNode) { + img.parentNode.removeChild(img); + } } },