From 652f2729cdf9307f8ad8d19cbd38cf48fbb0a7e0 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Sun, 14 Aug 2011 15:56:33 +0000 Subject: [PATCH] a bit more code, but this finally fixed the loading image placeholder issue in FF (see #3419) git-svn-id: http://svn.openlayers.org/trunk/openlayers@12247 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Tile/Image.js | 47 +++++++++++++++++++++++------ lib/OpenLayers/Tile/Image/IFrame.js | 8 ----- 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/lib/OpenLayers/Tile/Image.js b/lib/OpenLayers/Tile/Image.js index 1a96d2bccf..5741855b79 100644 --- a/lib/OpenLayers/Tile/Image.js +++ b/lib/OpenLayers/Tile/Image.js @@ -58,6 +58,14 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile.BackBufferable, { */ asyncRequestId: null, + /** + * Property: blankImageUrl + * {String} Using a data scheme url is not supported by all browsers, but + * we don't care because we either set it as css backgroundImage, or the + * image's display style is set to "none" when we use it. + */ + blankImageUrl: "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAQAIBRAA7", + /** * APIProperty: maxGetUrlLength * {Number} If set, requests that would result in GET urls with more @@ -255,14 +263,32 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile.BackBufferable, { if (this.url && img.getAttribute("src") == this.url) { this.onImageLoad(); } else { - OpenLayers.Event.observe( - img, "load", OpenLayers.Function.bind(this.onImageLoad, this) - ); - OpenLayers.Event.observe( - img, "error", OpenLayers.Function.bind(this.onImageError, this) - ); - this.imageReloadAttempts = 0; - this.setImgSrc(this.url); + // We need to start with a blank image, to make sure that no + // loading image placeholder and no old image is displayed when we + // set the display style to "" in onImageLoad, which is called + // after the image is loaded, but before it is rendered. So we set + // a blank image with a data scheme URI, and register for the load + // event (for browsers that support data scheme) and the error + // event (for browsers that don't). In the event handler, we set + // the final src. + var load = OpenLayers.Function.bind(function() { + OpenLayers.Event.stopObservingElement(img); + OpenLayers.Event.observe(img, "load", + OpenLayers.Function.bind(this.onImageLoad, this) + ); + OpenLayers.Event.observe(img, "error", + OpenLayers.Function.bind(this.onImageError, this) + ); + this.imageReloadAttempts = 0; + this.setImgSrc(this.url); + }, this); + if (img.getAttribute("src") == this.blankImageUrl) { + load(); + } else { + OpenLayers.Event.observe(img, "load", load); + OpenLayers.Event.observe(img, "error", load); + img.src = this.blankImageUrl; + } } }, @@ -274,9 +300,10 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile.BackBufferable, { * url - {String} or undefined to hide the image */ setImgSrc: function(url) { - this.imgDiv.style.display = "none"; + var img = this.imgDiv; + img.style.display = "none"; if (url) { - this.imgDiv.src = url; + img.src = url; } }, diff --git a/lib/OpenLayers/Tile/Image/IFrame.js b/lib/OpenLayers/Tile/Image/IFrame.js index 4880988fb9..9616036815 100644 --- a/lib/OpenLayers/Tile/Image/IFrame.js +++ b/lib/OpenLayers/Tile/Image/IFrame.js @@ -28,14 +28,6 @@ OpenLayers.Tile.Image.IFrame = { */ useIFrame: null, - /** - * Property: blankImageUrl - * {String} This is only used as background image for the eventPane, so we - * don't care that this doesn't actually result in a blank image on all - * browsers - */ - blankImageUrl: "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAQAIBRAA7", - /** * Method: updateBackBuffer * Update the , and return a new or reposition the