make Tile.Image compatible with CSS-based tile fade animation

This commit is contained in:
Éric Lemoine
2011-12-31 00:19:19 +01:00
parent d417231bb8
commit 5edd3d3f84
2 changed files with 111 additions and 13 deletions

View File

@@ -80,7 +80,7 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, {
* transition effects are not supported if POST requests are used.
*/
maxGetUrlLength: null,
/** TBD 3.0 - reorder the parameters to the init function to remove
* URL. the getUrl() function on the layer gets called on
* each draw(), so no need to specify it here.
@@ -243,13 +243,9 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, {
style.width = "100%";
style.height = "100%";
}
style.display = "none";
style.visibility = "hidden";
style.opacity = 0;
style.position = "absolute";
if (this.layer.opacity < 1) {
OpenLayers.Util.modifyDOMElement(this.imgDiv, null, null,
null, null, null, null,
this.layer.opacity);
}
if (this.layerAlphaHack) {
// move the image out of sight
style.paddingTop = style.height;
@@ -311,7 +307,9 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, {
*/
setImgSrc: function(url) {
var img = this.imgDiv;
img.style.display = "none";
img.style.visibility = 'hidden';
img.style.opacity = 0;
img.style.filter = 'alpha(opacity=0)';
if (url) {
img.src = url;
}
@@ -360,9 +358,28 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, {
onImageLoad: function() {
var img = this.imgDiv;
OpenLayers.Event.stopObservingElement(img);
img.style.display = "";
this.isLoading = false;
this.events.triggerEvent("loadend");
var opacity = this.layer.opacity,
tileAnimation = this.layer.map.tileAnimation;
if (OpenLayers.TRANSITION && tileAnimation && opacity) {
// if the displaying of the tile is animated we delay the
// loadend event until after the end of the transition, this
// to avoid flash effects because the backbuffer is removed
// before the tile is actually displayed
OpenLayers.Event.observe(img, OpenLayers.TRANSITION_END,
OpenLayers.Function.bind(this.onTransitionEnd, this)
);
}
img.style.visibility = 'inherit';
img.style.opacity = opacity;
img.style.filter = 'alpha(opacity=' + (opacity * 100) + ')';
if (!OpenLayers.TRANSITION || !tileAnimation || !opacity) {
this.isLoading = false;
this.events.triggerEvent("loadend");
}
// IE<7 needs a reflow when the tiles are loaded because of the
// percentage based positioning. Otherwise nothing is shown
@@ -402,6 +419,16 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, {
}
},
/**
* Method: onTransitionEnd
* Handler for the transitionend event.
*/
onTransitionEnd: function() {
OpenLayers.Event.stopObservingElement(this.imgDiv);
this.isLoading = false;
this.events.triggerEvent('loadend');
},
CLASS_NAME: "OpenLayers.Tile.Image"
});