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,40 +29,52 @@ 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: * {Boolean}
* {HTMLDivElement} the tile's markup in a cloned element, or undefined if
* 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);
var usedIFrame = this.useIFrame; if(draw) {
this.useIFrame = this.maxGetUrlLength !== null && !this.layer.async &&
this.url.length > this.maxGetUrlLength; // this.url isn't set to the currect value yet, so we call getURL
var fromIFrame = usedIFrame && !this.useIFrame; // on the layer and store the result in a local variable
var toIFrame = !usedIFrame && this.useIFrame; var url = this.layer.getURL(this.bounds);
if (fromIFrame || toIFrame) {
// switch between get (image) and post (iframe) var usedIFrame = this.useIFrame;
this.clear(); this.useIFrame = this.maxGetUrlLength !== null &&
if (this.imgDiv && this.imgDiv.parentNode === this.frame) { !this.layer.async &&
this.frame.removeChild(this.imgDiv); url.length > this.maxGetUrlLength;
}
this.imgDiv = null; var fromIFrame = usedIFrame && !this.useIFrame;
if (fromIFrame) { var toIFrame = !usedIFrame && this.useIFrame;
// remove eventPane
this.frame.removeChild(this.frame.firstChild); if(fromIFrame || toIFrame) {
this.resetBackBuffer();
// 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.imgDiv = null;
// And if we had an iframe we also remove the event pane.
if(fromIFrame) {
this.frame.removeChild(this.frame.firstChild);
}
} }
} }
if (!this.useIFrame) { return OpenLayers.Tile.Image.prototype.draw.apply(this, arguments);
OpenLayers.Tile.Image.prototype.updateBackBuffer.apply(this, arguments);
}
}, },
/** /**
* Method: createImage * Method: createImage
* Creates the content for the frame on the tile. * Creates the content for the frame on the tile.
@@ -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;
}
}; };