"use different server when IMAGE_RELOAD_ATTEMPTS > 1 && layer.url is an array".

Patch from brentp. (Closes #1291)


git-svn-id: http://svn.openlayers.org/trunk/openlayers@7599 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2008-07-30 02:02:36 +00:00
parent d41b6afec4
commit 2d301f456b
2 changed files with 27 additions and 2 deletions

View File

@@ -86,6 +86,7 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, {
this.frame.removeChild(this.imgDiv);
this.imgDiv.map = null;
}
this.imgDiv.urls = null;
}
this.imgDiv = null;
if ((this.frame != null) && (this.frame.parentNode == this.layer.div)) {
@@ -161,6 +162,11 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, {
this.imgDiv.viewRequestID = this.layer.map.viewRequestID;
// needed for changing to a different serve for onload error
if (this.layer.url instanceof Array) {
this.imgDiv.urls = this.layer.url.slice();
}
this.url = this.layer.getURL(this.bounds);
// position the frame
OpenLayers.Util.modifyDOMElement(this.frame,

View File

@@ -363,8 +363,27 @@ OpenLayers.IMAGE_RELOAD_ATTEMPTS = 0;
*/
OpenLayers.Util.onImageLoadError = function() {
this._attempts = (this._attempts) ? (this._attempts + 1) : 1;
if(this._attempts <= OpenLayers.IMAGE_RELOAD_ATTEMPTS) {
if (this._attempts <= OpenLayers.IMAGE_RELOAD_ATTEMPTS) {
var urls = this.urls;
if (urls && urls instanceof Array && urls.length > 1){
var src = this.src.toString();
var current_url, k;
for (k = 0; current_url = urls[k]; k++){
if(src.indexOf(current_url) != -1){
break;
}
}
var guess = Math.floor(urls.length * Math.random())
var new_url = urls[guess];
k = 0;
while(new_url == current_url && k++ < 4){
guess = Math.floor(urls.length * Math.random())
new_url = urls[guess];
}
this.src = src.replace(current_url, new_url);
} else {
this.src = this.src;
}
} else {
this.style.backgroundColor = OpenLayers.Util.onImageLoadErrorColor;
}