Skip to content

Commit

Permalink
Don't reuse tile images unless we have a new url to load.
Browse files Browse the repository at this point in the history
Without this change, some browsers don't cache the images. See openlayers#454 for a discussion about this issue.
  • Loading branch information
ahocevar committed May 25, 2012
1 parent 440b9fb commit ff1f99a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/OpenLayers/Tile/Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:') {
Expand All @@ -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);
}
}
},

Expand Down

0 comments on commit ff1f99a

Please sign in to comment.