diff --git a/lib/OpenLayers/Layer/WMS/Untiled.js b/lib/OpenLayers/Layer/WMS/Untiled.js index 5ff978d8f5..1fe5a70114 100644 --- a/lib/OpenLayers/Layer/WMS/Untiled.js +++ b/lib/OpenLayers/Layer/WMS/Untiled.js @@ -89,6 +89,15 @@ OpenLayers.Layer.WMS.Untiled.prototype = }, + /** Once HTTPRequest has set the map, we can load the image div + * + * @param {OpenLayers.Map} map + */ + setMap: function(map) { + OpenLayers.Layer.HTTPRequest.prototype.setMap.apply(this, arguments); + this.loadImageDiv(); + }, + /** When it is not a minor move (ie when panning or when done dragging) * reload and recenter the div. * @@ -98,61 +107,122 @@ OpenLayers.Layer.WMS.Untiled.prototype = */ moveTo:function(bounds, zoomChanged, minor) { + + if (!minor) { - + + if (bounds == null) { + bounds = this.map.getExtent(); + } var size = this.map.getSize().copyOf(); - - //get the url + // get the url var url = this.getFullRequestString( {BBOX: bounds.toBBOX(), WIDTH: size.w, HEIGHT: size.h} ); - //clear previous wms image - this.div.innerHTML = ""; - - //always position at upper left corner of current viewspace + // always position at upper left corner of current viewspace var tl = new OpenLayers.Pixel(0,0); var pos = this.map.getLayerPxFromViewPortPx(tl); - - //create div - if (this.transparent) { - this.imgDiv = OpenLayers.Util.createAlphaImageDiv(null, - pos, - size, - url, - "absolute"); - } else { - this.imgDiv = OpenLayers.Util.createImage(null, - pos, - size, - url, - "absolute"); - } - this.div.appendChild(this.imgDiv); + // first hide before all modifications + Element.hide(this.imgDiv); + + // update div + var img = this.imgDiv; + if (this.transparent) { + OpenLayers.Util.modifyAlphaImageDiv(this.imgDiv, + null, + pos, + size, + url); + img = this.imgDiv.childNodes[0]; + } else { + OpenLayers.Util.modifyDOMElement(this.imgDiv, + null, + pos, + size); + this.imgDiv.src = url; + } + + // wait until image is done loading to show again + Event.observe(img, + "load", + this.showDiv.bindAsEventListener(this)); } }, - /** + /** Helper function that allows us to first hide the imgDiv, then make all + * the changes (position, size, url). Then when the url is done loading, + * we call this function to show the imgDiv. + * + * @private + */ + showDiv: function() { + Element.show(this.imgDiv); + }, + + /** Once HTTPRequest has updated the url, reload the image div * @param {String} newUrl */ setUrl: function(newUrl) { OpenLayers.Layer.HTTPRequest.prototype.setUrl.apply(this, arguments); - this.moveTo(this.map.getExtent()); + this.moveTo(); }, - /** + /** Once HTTPRequest has updated new params, reload the image div * @param {Object} newParams */ mergeNewParams:function(newParams) { OpenLayers.Layer.HTTPRequest.prototype.mergeNewParams.apply(this, arguments); - this.moveTo(this.map.getExtent()); + this.moveTo(); }, + /** This function first removes the previous image div, then adds a new + * one according to the transparency property. + * + * @private + */ + loadImageDiv: function() { + + var size = this.map.getSize().copyOf(); + var bounds = this.map.getExtent(); + + var url = ""; + if (bounds != null) { + url = this.getFullRequestString( {BBOX: bounds.toBBOX(), + WIDTH: size.w, + HEIGHT: size.h} ); + } + + //clear previous wms image (removes imgDiv) + this.div.innerHTML = ""; + + //always position at upper left corner of current viewspace + var tl = new OpenLayers.Pixel(0,0); + var pos = this.map.getLayerPxFromViewPortPx(tl); + + //create div + if (this.transparent) { + this.imgDiv = OpenLayers.Util.createAlphaImageDiv(null, + pos, + size, + url, + "absolute"); + } else { + this.imgDiv = OpenLayers.Util.createImage(null, + pos, + size, + url, + "absolute"); + } + + this.div.appendChild(this.imgDiv); + }, + /** @final @type String */ CLASS_NAME: "OpenLayers.Layer.WMS.Untiled" });