Made Tile.Image.IFrame an addin which will be used only if a layer is configured with the maxGetUrlLength option. This deprecates Layer.WMS.Post. r=tschaub (closes #2824)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@10755 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
ahocevar
2010-09-16 21:54:22 +00:00
parent 1284b71bbc
commit ce90aebfd0
11 changed files with 300 additions and 224 deletions

View File

@@ -9,87 +9,49 @@
*/
/**
* Class: OpenLayers.Tile.Image.IFrame
* Instances of OpenLayers.Tile.Image.IFrame are used to manage the image tiles
* used by Layer.WMS.Post loaded via HTTP-POST-protocol. Create a new image
* tile with the <OpenLayers.Tile.Image.IFrame> constructor.
* Constant: OpenLayers.Tile.Image.IFrame
* Mixin for tiles that use form-encoded POST requests to get images from
* remote services. Images will be loaded using HTTP-POST into an IFrame.
*
* This mixin will be applied to <OpenLayers.Tile.Image> instances
* configured with <OpenLayers.Tile.Image.allowPost> or
* <OpenLayers.Tile.Image.enforcePost> set to true.
*
* Inherits from:
* - <OpenLayers.Tile.Image>
*/
OpenLayers.Tile.Image.IFrame = OpenLayers.Class(OpenLayers.Tile.Image, {
OpenLayers.Tile.Image.IFrame = {
/**
* Property: layerAlphaHack
* {Boolean} Always false for an instance.
*/
/**
* Constructor: OpenLayers.Tile.Image.IFrame
* Constructor for a new <OpenLayers.Tile.Image.IFrame> instance.
*
* Parameters:
* layer - {<OpenLayers.Layer>} layer that the tile will go in.
* position - {<OpenLayers.Pixel>}
* bounds - {<OpenLayers.Bounds>}
* size - {<OpenLayers.Size>}
*/
initialize: function(layer, position, bounds, url, size) {
OpenLayers.Tile.Image.prototype.initialize.apply(this, arguments);
this.layerAlphaHack = false;
},
/**
* Method: destroy
* nullify references to prevent circular references and memory leaks
*/
destroy: function() {
if(this.imgDiv != null) {
// unregister the "load" handler
OpenLayers.Event.stopObservingElement(this.imgDiv.firstChild);
}
OpenLayers.Tile.Image.prototype.destroy.apply(this, arguments);
},
* Property: useIFrame
* {Boolean} true if we are currently using an IFrame to render POST
* responses, false if we are using an img element to render GET responses.
*/
useIFrame: null,
/**
* Method: clear
* Removes the iframe from DOM (avoids back-button problems).
*/
clear: function() {
if(this.imgDiv) {
var iFrame = this.imgDiv.firstChild;
OpenLayers.Event.stopObservingElement(iFrame);
this.imgDiv.removeChild(iFrame);
if (this.useIFrame) {
if (this.imgDiv) {
var iFrame = this.imgDiv.firstChild;
OpenLayers.Event.stopObservingElement(iFrame);
this.imgDiv.removeChild(iFrame);
delete iFrame;
}
} else {
OpenLayers.Tile.Image.prototype.clear.apply(this, arguments)
}
},
/**
* Method: clone
*
* Parameters:
* obj - {<OpenLayers.Tile.Image.IFrame>} The tile to be cloned
*
* Returns:
* {<OpenLayers.Tile.Image.IFrame>} An exact clone of this
* <OpenLayers.Tile.Image.IFrame>
*/
clone: function (obj) {
if (obj == null) {
obj = new OpenLayers.Tile.Image.IFrame(
this.layer, this.position, this.bounds, this.url, this.size);
}
//pick up properties from superclass
obj = OpenLayers.Tile.Image.prototype.clone.apply(this, [obj]);
return obj;
},
/**
* Method: renderTile
*/
renderTile: function() {
if(OpenLayers.Tile.Image.prototype.renderTile.apply(this, arguments)) {
if (OpenLayers.Tile.Image.prototype.renderTile.apply(this, arguments) &&
this.useIFrame) {
// create a html form and add it temporary to the layer div
var form = this.createRequestForm();
this.imgDiv.appendChild(form);
@@ -97,7 +59,9 @@ OpenLayers.Tile.Image.IFrame = OpenLayers.Class(OpenLayers.Tile.Image, {
// submit the form (means fetching the image)
form.submit();
this.imgDiv.removeChild(form);
delete form;
}
return true;
},
/**
@@ -105,24 +69,57 @@ OpenLayers.Tile.Image.IFrame = OpenLayers.Class(OpenLayers.Tile.Image, {
* Creates the imgDiv property on the tile.
*/
initImgDiv: function() {
this.imgDiv = this.createImgDiv();
OpenLayers.Util.modifyDOMElement(this.imgDiv, this.id, null,
this.layer.getImageSize(), "relative");
this.imgDiv.className = 'olTileImage';
this.frame.appendChild(this.imgDiv);
this.layer.div.appendChild(this.frame);
if(this.layer.opacity != null) {
OpenLayers.Util.modifyDOMElement(this.imgDiv, null, null, null,
null, null, null,
this.layer.opacity);
this.useIFrame = this.maxGetUrlLength !== null && !this.layer.async &&
this.url.length > this.maxGetUrlLength;
if (this.imgDiv != null) {
var nodeName = this.imgDiv.nodeName.toLowerCase();
if ((this.useIFrame && nodeName == "img") ||
(!this.useIFrame && nodeName == "div")) {
// switch between get and post
this.removeImgDiv();
delete this.imgDiv;
} else {
return;
}
}
if (this.useIFrame) {
var eventPane = document.createElement("div");
// we need this reference to check back the viewRequestID
this.imgDiv.map = this.layer.map;
if(OpenLayers.Util.getBrowserName() == "msie") {
// IE cannot handle events on elements without backgroundcolor. So we
// use this little hack to make elements transparent
eventPane.style.backgroundColor = '#FFFFFF';
eventPane.style.filter = 'chroma(color=#FFFFFF)';
}
OpenLayers.Util.modifyDOMElement(eventPane, null,
new OpenLayers.Pixel(0,0), this.layer.getImageSize(), "absolute");
this.imgDiv = document.createElement("div");
this.imgDiv.appendChild(eventPane);
OpenLayers.Util.modifyDOMElement(this.imgDiv, this.id, null,
this.layer.getImageSize(), "relative");
this.imgDiv.className = 'olTileImage';
this.frame.appendChild(this.imgDiv);
this.layer.div.appendChild(this.frame);
if(this.layer.opacity != null) {
OpenLayers.Util.modifyDOMElement(this.imgDiv, null, null, null,
null, null, null,
this.layer.opacity);
}
// we need this reference to check back the viewRequestID
this.imgDiv.map = this.layer.map;
this.imgDiv.viewRequestID = this.layer.map.viewRequestID;
} else {
OpenLayers.Tile.Image.prototype.initImgDiv.apply(this, arguments);
}
},
/**
@@ -238,13 +235,9 @@ OpenLayers.Tile.Image.IFrame = OpenLayers.Class(OpenLayers.Tile.Image, {
// adding all parameters in layer params as hidden fields to the html
// form element
var imageSize = this.layer.getImageSize();
var params = OpenLayers.Util.extend(
{
"BBOX": this.encodeBBOX ? this.bounds.toBBOX() :
this.bounds.toArray(),
"WIDTH": imageSize.w,
"HEIGHT": imageSize.h
}, this.layer.params);
var params = OpenLayers.Util.getParameters(
this.url.substr(this.layer.url.length)
);
for(var par in params) {
var field = document.createElement('input');
@@ -255,8 +248,5 @@ OpenLayers.Tile.Image.IFrame = OpenLayers.Class(OpenLayers.Tile.Image, {
}
return form;
},
CLASS_NAME: "OpenLayers.Tile.Image.IFrame"
}
);
}
}