Fixed viewRequestID regression and mixin issue that caused the mixin to always be applied unless maxGetUrlLength was explicitly set. Includes a regression test for the viewRequestID bit. r=tschaub (closes #2847)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@10773 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
ahocevar
2010-09-17 23:20:55 +00:00
parent b8feb3c22e
commit f4a99d4052
3 changed files with 146 additions and 125 deletions

View File

@@ -110,11 +110,11 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, {
* options - {Object} * options - {Object}
*/ */
initialize: function(layer, position, bounds, url, size, options) { initialize: function(layer, position, bounds, url, size, options) {
options = options || {}; OpenLayers.Tile.prototype.initialize.apply(this, arguments);
if (options.maxGetUrlLength !== null) {
OpenLayers.Util.applyDefaults(options, OpenLayers.Tile.Image.IFrame); 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 this.url = url; //deprecated remove me
@@ -355,102 +355,101 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, {
* Creates the imgDiv property on the tile. * Creates the imgDiv property on the tile.
*/ */
initImgDiv: function() { initImgDiv: function() {
if (this.imgDiv) { if (this.imgDiv == null) {
return; var offset = this.layer.imageOffset;
} var size = this.layer.getImageSize(this.bounds);
var offset = this.layer.imageOffset;
var size = this.layer.getImageSize(this.bounds);
if (this.layerAlphaHack) { if (this.layerAlphaHack) {
this.imgDiv = OpenLayers.Util.createAlphaImageDiv(null, this.imgDiv = OpenLayers.Util.createAlphaImageDiv(null,
offset, offset,
size, size,
null, null,
"relative", "relative",
null, null,
null, null,
null, null,
true); true);
} else { } else {
this.imgDiv = OpenLayers.Util.createImage(null, this.imgDiv = OpenLayers.Util.createImage(null,
offset, offset,
size, size,
null, null,
"relative", "relative",
null, null,
null, null,
true); true);
} }
// needed for changing to a different server for onload error // needed for changing to a different server for onload error
if (this.layer.url instanceof Array) { if (this.layer.url instanceof Array) {
this.imgDiv.urls = this.layer.url.slice(); 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 /* checkImgURL used to be used to called as a work around, but it
ended up hiding problems instead of solving them and broke things ended up hiding problems instead of solving them and broke things
like relative URLs. See discussion on the dev list: like relative URLs. See discussion on the dev list:
http://openlayers.org/pipermail/dev/2007-January/000205.html http://openlayers.org/pipermail/dev/2007-January/000205.html
OpenLayers.Event.observe( this.imgDiv, "load", OpenLayers.Event.observe( this.imgDiv, "load",
OpenLayers.Function.bind(this.checkImgURL, this) ); OpenLayers.Function.bind(this.checkImgURL, this) );
*/ */
this.frame.style.zIndex = this.isBackBuffer ? 0 : 1; this.frame.style.zIndex = this.isBackBuffer ? 0 : 1;
this.frame.appendChild(this.imgDiv); this.frame.appendChild(this.imgDiv);
this.layer.div.appendChild(this.frame); this.layer.div.appendChild(this.frame);
if(this.layer.opacity != null) { if(this.layer.opacity != null) {
OpenLayers.Util.modifyDOMElement(this.imgDiv, null, null, null, OpenLayers.Util.modifyDOMElement(this.imgDiv, null, null, null,
null, null, null, null, null, null,
this.layer.opacity); 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; this.imgDiv.viewRequestID = this.layer.map.viewRequestID;
}, },

View File

@@ -77,44 +77,43 @@ OpenLayers.Tile.Image.IFrame = {
(!this.useIFrame && nodeName == "div")) { (!this.useIFrame && nodeName == "div")) {
// switch between get and post // switch between get and post
this.removeImgDiv(); this.removeImgDiv();
delete this.imgDiv; this.imgDiv = null;
} else {
return;
} }
} }
if (this.useIFrame) { if (this.useIFrame) {
var eventPane = document.createElement("div"); if (this.imgDiv == null) {
var eventPane = document.createElement("div");
if(OpenLayers.Util.getBrowserName() == "msie") { if(OpenLayers.Util.getBrowserName() == "msie") {
// IE cannot handle events on elements without backgroundcolor. So we // IE cannot handle events on elements without backgroundcolor.
// use this little hack to make elements transparent // So we use this little hack to make elements transparent
eventPane.style.backgroundColor = '#FFFFFF'; eventPane.style.backgroundColor = '#FFFFFF';
eventPane.style.filter = 'chroma(color=#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; this.imgDiv.viewRequestID = this.layer.map.viewRequestID;
} else { } else {

View File

@@ -87,6 +87,29 @@
t.ok( clone.imgDiv == null, "clone's imgDiv was not copied"); 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) { function test_Tile_Image_draw (t) {
t.plan( 7 ); t.plan( 7 );