/* Copyright (c) 2006-2011 by OpenLayers Contributors (see authors.txt for * full list of contributors). Published under the Clear BSD license. * See http://svn.openlayers.org/trunk/openlayers/license.txt for the * full text of the license. */ /** * @requires OpenLayers/Tile/Image.js */ /** * 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 instances * configured with or * set to true. * * Inherits from: * - */ OpenLayers.Tile.Image.IFrame = { /** * 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.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: renderTile */ renderTile: function() { 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); // submit the form (means fetching the image) form.submit(); this.imgDiv.removeChild(form); delete form; } return true; }, /** * Method: initImgDiv * Creates the imgDiv property on the tile. */ initImgDiv: function() { 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(); this.imgDiv = null; } } if (this.useIFrame) { if (this.imgDiv == null) { var eventPane = document.createElement("div"); if(OpenLayers.BROWSER_NAME == "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); } }, /** * Method: createIFrame * Create the IFrame which shows the image. * * Returns: * {DOMElement} Iframe */ createIFrame: function() { var id = this.id+'_iFrame'; var iframe; if(OpenLayers.BROWSER_NAME == "msie") { // InternetExplorer does not set the name attribute of an iFrame // properly via DOM manipulation, so we need to do it on our own with // this hack. iframe = document.createElement('