diff --git a/lib/OpenLayers/Tile/Image.js b/lib/OpenLayers/Tile/Image.js index 1d96d6a099..d64c9ba2dd 100644 --- a/lib/OpenLayers/Tile/Image.js +++ b/lib/OpenLayers/Tile/Image.js @@ -110,11 +110,11 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, { * options - {Object} */ initialize: function(layer, position, bounds, url, size, options) { - options = options || {}; - if (options.maxGetUrlLength !== null) { - OpenLayers.Util.applyDefaults(options, OpenLayers.Tile.Image.IFrame); + OpenLayers.Tile.prototype.initialize.apply(this, arguments); + + if (this.maxGetUrlLength != null) { + OpenLayers.Util.extend(this, OpenLayers.Tile.Image.IFrame); } - OpenLayers.Tile.prototype.initialize.apply(this, [layer, position, bounds, url, size, options]); this.url = url; //deprecated remove me @@ -355,102 +355,101 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, { * Creates the imgDiv property on the tile. */ initImgDiv: function() { - if (this.imgDiv) { - return; - } - var offset = this.layer.imageOffset; - var size = this.layer.getImageSize(this.bounds); + if (this.imgDiv == null) { + var offset = this.layer.imageOffset; + var size = this.layer.getImageSize(this.bounds); - if (this.layerAlphaHack) { - this.imgDiv = OpenLayers.Util.createAlphaImageDiv(null, - offset, - size, - null, - "relative", - null, - null, - null, - true); - } else { - this.imgDiv = OpenLayers.Util.createImage(null, - offset, - size, - null, - "relative", - null, - null, - true); - } + if (this.layerAlphaHack) { + this.imgDiv = OpenLayers.Util.createAlphaImageDiv(null, + offset, + size, + null, + "relative", + null, + null, + null, + true); + } else { + this.imgDiv = OpenLayers.Util.createImage(null, + offset, + size, + null, + "relative", + null, + null, + true); + } - // needed for changing to a different server for onload error - if (this.layer.url instanceof Array) { - this.imgDiv.urls = this.layer.url.slice(); - } + // needed for changing to a different server for onload error + if (this.layer.url instanceof Array) { + this.imgDiv.urls = this.layer.url.slice(); + } - this.imgDiv.className = 'olTileImage'; + this.imgDiv.className = 'olTileImage'; - /* checkImgURL used to be used to called as a work around, but it - ended up hiding problems instead of solving them and broke things - like relative URLs. See discussion on the dev list: - http://openlayers.org/pipermail/dev/2007-January/000205.html + /* checkImgURL used to be used to called as a work around, but it + ended up hiding problems instead of solving them and broke things + like relative URLs. See discussion on the dev list: + http://openlayers.org/pipermail/dev/2007-January/000205.html - OpenLayers.Event.observe( this.imgDiv, "load", - OpenLayers.Function.bind(this.checkImgURL, this) ); - */ - this.frame.style.zIndex = this.isBackBuffer ? 0 : 1; - this.frame.appendChild(this.imgDiv); - this.layer.div.appendChild(this.frame); + OpenLayers.Event.observe( this.imgDiv, "load", + OpenLayers.Function.bind(this.checkImgURL, this) ); + */ + this.frame.style.zIndex = this.isBackBuffer ? 0 : 1; + this.frame.appendChild(this.imgDiv); + this.layer.div.appendChild(this.frame); - if(this.layer.opacity != null) { + if(this.layer.opacity != null) { - OpenLayers.Util.modifyDOMElement(this.imgDiv, null, null, null, - null, null, null, - this.layer.opacity); + 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; + + //bind a listener to the onload of the image div so that we + // can register when a tile has finished loading. + var onload = function() { + + //normally isLoading should always be true here but there are some + // right funky conditions where loading and then reloading a tile + // with the same url *really*fast*. this check prevents sending + // a 'loadend' if the msg has already been sent + // + if (this.isLoading) { + this.isLoading = false; + this.events.triggerEvent("loadend"); + } + }; + + if (this.layerAlphaHack) { + OpenLayers.Event.observe(this.imgDiv.childNodes[0], 'load', + OpenLayers.Function.bind(onload, this)); + } else { + OpenLayers.Event.observe(this.imgDiv, 'load', + OpenLayers.Function.bind(onload, this)); + } + + + // Bind a listener to the onerror of the image div so that we + // can registere when a tile has finished loading with errors. + var onerror = function() { + + // If we have gone through all image reload attempts, it is time + // to realize that we are done with this image. Since + // OpenLayers.Util.onImageLoadError already has taken care about + // the error, we can continue as if the image was loaded + // successfully. + if (this.imgDiv._attempts > OpenLayers.IMAGE_RELOAD_ATTEMPTS) { + onload.call(this); + } + }; + OpenLayers.Event.observe(this.imgDiv, "error", + OpenLayers.Function.bind(onerror, this)); } - - // we need this reference to check back the viewRequestID - this.imgDiv.map = this.layer.map; - - //bind a listener to the onload of the image div so that we - // can register when a tile has finished loading. - var onload = function() { - - //normally isLoading should always be true here but there are some - // right funky conditions where loading and then reloading a tile - // with the same url *really*fast*. this check prevents sending - // a 'loadend' if the msg has already been sent - // - if (this.isLoading) { - this.isLoading = false; - this.events.triggerEvent("loadend"); - } - }; - - if (this.layerAlphaHack) { - OpenLayers.Event.observe(this.imgDiv.childNodes[0], 'load', - OpenLayers.Function.bind(onload, this)); - } else { - OpenLayers.Event.observe(this.imgDiv, 'load', - OpenLayers.Function.bind(onload, this)); - } - - - // Bind a listener to the onerror of the image div so that we - // can registere when a tile has finished loading with errors. - var onerror = function() { - - // If we have gone through all image reload attempts, it is time - // to realize that we are done with this image. Since - // OpenLayers.Util.onImageLoadError already has taken care about - // the error, we can continue as if the image was loaded - // successfully. - if (this.imgDiv._attempts > OpenLayers.IMAGE_RELOAD_ATTEMPTS) { - onload.call(this); - } - }; - OpenLayers.Event.observe(this.imgDiv, "error", - OpenLayers.Function.bind(onerror, this)); - + this.imgDiv.viewRequestID = this.layer.map.viewRequestID; }, diff --git a/lib/OpenLayers/Tile/Image/IFrame.js b/lib/OpenLayers/Tile/Image/IFrame.js index 2d17a6b3a3..f7f51a2005 100644 --- a/lib/OpenLayers/Tile/Image/IFrame.js +++ b/lib/OpenLayers/Tile/Image/IFrame.js @@ -77,44 +77,43 @@ OpenLayers.Tile.Image.IFrame = { (!this.useIFrame && nodeName == "div")) { // switch between get and post this.removeImgDiv(); - delete this.imgDiv; - } else { - return; + this.imgDiv = null; } } if (this.useIFrame) { - var eventPane = document.createElement("div"); + if (this.imgDiv == null) { + var eventPane = document.createElement("div"); - 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)'; + 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; } - - 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 { diff --git a/tests/Tile/Image.html b/tests/Tile/Image.html index f5f327b928..c7455cfab2 100644 --- a/tests/Tile/Image.html +++ b/tests/Tile/Image.html @@ -87,6 +87,29 @@ t.ok( clone.imgDiv == null, "clone's imgDiv was not copied"); } + function test_Tile_Image_IFrame_viewRequestID (t) { + t.plan( 2 ); + var map = new OpenLayers.Map('map'); + var layer = new OpenLayers.Layer.WMS( + "Name", + "http://labs.metacarta.com/TESTURL?", + {layers: 'basic'} + ); + map.addLayer(layer); + + var position = new OpenLayers.Pixel(20,30); + var bounds = new OpenLayers.Bounds(1,2,3,4); + tile = layer.addTile(bounds, position); + tile.renderTile(); + t.eq(tile.imgDiv.viewRequestID, map.viewRequestID, "viewRequestID correct after renderTile"); + map.viewRequestID++; + tile.renderTile(); + t.eq(tile.imgDiv.viewRequestID, map.viewRequestID, "viewRequestID correct after subsequent renderTile"); + tile.destroy(); + layer.destroy(); + map.destroy(); + } + function test_Tile_Image_draw (t) { t.plan( 7 );