necessary adaptations to the Tile.IFrame mixin - back buffering is disabled when using POST and iframe tiles

This commit is contained in:
Éric Lemoine
2011-10-19 23:19:29 +02:00
parent a37202ac09
commit 853bfeaee1

View File

@@ -29,38 +29,50 @@ OpenLayers.Tile.Image.IFrame = {
useIFrame: null, useIFrame: null,
/** /**
* Method: updateBackBuffer * Method: draw
* Update the <backBufferData>, and return a new or reposition the * Set useIFrame in the instance, and operate the to/from image from/to
* backBuffer. When a backbuffer is returned, the tile's markup is not * iframe switch, if necessary. Then call the parent function.
* available any more.
* *
* Returns: * Returns:
* {HTMLDivElement} the tile's markup in a cloned element, or undefined if * {Boolean}
* no backbuffer is currently available or needed
*/ */
updateBackBuffer: function() { draw: function() {
this.url = this.layer.getURL(this.bounds); var draw = OpenLayers.Tile.Image.prototype.shouldDraw.call(this);
if(draw) {
// this.url isn't set to the currect value yet, so we call getURL
// on the layer and store the result in a local variable
var url = this.layer.getURL(this.bounds);
var usedIFrame = this.useIFrame; var usedIFrame = this.useIFrame;
this.useIFrame = this.maxGetUrlLength !== null && !this.layer.async && this.useIFrame = this.maxGetUrlLength !== null &&
this.url.length > this.maxGetUrlLength; !this.layer.async &&
url.length > this.maxGetUrlLength;
var fromIFrame = usedIFrame && !this.useIFrame; var fromIFrame = usedIFrame && !this.useIFrame;
var toIFrame = !usedIFrame && this.useIFrame; var toIFrame = !usedIFrame && this.useIFrame;
if (fromIFrame || toIFrame) {
// switch between get (image) and post (iframe) if(fromIFrame || toIFrame) {
this.clear();
if (this.imgDiv && this.imgDiv.parentNode === this.frame) { // Switching between GET (image) and POST (iframe).
// We remove the imgDiv (really either an image or an iframe)
// from the frame and set it to null to make sure initImage
// will call createImage.
if(this.imgDiv && this.imgDiv.parentNode === this.frame) {
this.frame.removeChild(this.imgDiv); this.frame.removeChild(this.imgDiv);
} }
this.imgDiv = null; this.imgDiv = null;
if (fromIFrame) {
// remove eventPane // And if we had an iframe we also remove the event pane.
if(fromIFrame) {
this.frame.removeChild(this.frame.firstChild); this.frame.removeChild(this.frame.firstChild);
this.resetBackBuffer();
} }
} }
if (!this.useIFrame) {
OpenLayers.Tile.Image.prototype.updateBackBuffer.apply(this, arguments);
} }
return OpenLayers.Tile.Image.prototype.draw.apply(this, arguments);
}, },
/** /**
@@ -183,6 +195,22 @@ OpenLayers.Tile.Image.IFrame = {
} else { } else {
OpenLayers.Tile.Image.prototype.setImgSrc.apply(this, arguments); OpenLayers.Tile.Image.prototype.setImgSrc.apply(this, arguments);
} }
} },
/**
* Method: cloneMarkup
* Override cloneMarkup to not attempt cloning when we use an iframe.
* Moving an iframe from one element to another makes it necessary to
* reload the iframe because its content is lost. So we just give up.
*
* Returns:
* {DOMElement}
*/
cloneMarkup: function() {
var clone;
if(!this.useIFrame) {
clone = OpenLayers.Tile.Image.prototype.cloneMarkup.call(this);
}
return clone;
}
}; };