Make WMS server selection deterministic, by using a real number hashing algorithm on the parameter string to select the server URL. Also, patch TMS since it doesn't use getFullParameterString(). Passes all tests. Fixes #410.
git-svn-id: http://svn.openlayers.org/trunk/openlayers@2821 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -90,6 +90,18 @@ OpenLayers.Layer.HTTPRequest.prototype =
|
||||
this.params = OpenLayers.Util.extend(this.params, newParams);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {String} paramString
|
||||
* @param {Array(String)} urls
|
||||
*/
|
||||
selectUrl: function(paramString, urls) {
|
||||
var product = 1;
|
||||
for (var i = 0; i < paramString.length; i++) {
|
||||
product *= paramString.charCodeAt(i) * (Math.sqrt(5) - 1) / Math.sqrt(3);
|
||||
product -= Math.floor(product);
|
||||
}
|
||||
return urls[Math.floor(product * urls.length)];
|
||||
},
|
||||
|
||||
/** combine url with layer's params and these newParams.
|
||||
*
|
||||
@@ -109,15 +121,6 @@ OpenLayers.Layer.HTTPRequest.prototype =
|
||||
// use layer's url unless altUrl passed in
|
||||
var url = (altUrl == null) ? this.url : altUrl;
|
||||
|
||||
// if url is not a string, it should be an array of strings,
|
||||
// in which case we will randomly select one of them in order
|
||||
// to evenly distribute requests to different urls.
|
||||
if (typeof url == "object") {
|
||||
url = url[Math.floor(Math.random()*url.length)];
|
||||
}
|
||||
// requestString always starts with url
|
||||
var requestString = url;
|
||||
|
||||
// create a new params hashtable with all the layer params and the
|
||||
// new params together. then convert to string
|
||||
var allParams = OpenLayers.Util.extend(new Object(), this.params);
|
||||
@@ -131,6 +134,17 @@ OpenLayers.Layer.HTTPRequest.prototype =
|
||||
}
|
||||
}
|
||||
var paramsString = OpenLayers.Util.getParameterString(allParams);
|
||||
|
||||
// if url is not a string, it should be an array of strings,
|
||||
// in which case we will deterministically select one of them in
|
||||
// order to evenly distribute requests to different urls.
|
||||
if (url instanceof Array) {
|
||||
url = this.selectUrl(paramsString, url);
|
||||
}
|
||||
|
||||
// requestString always starts with url
|
||||
var requestString = url;
|
||||
|
||||
if (paramsString != "") {
|
||||
var lastServerChar = url.charAt(url.length - 1);
|
||||
if ((lastServerChar == "&") || (lastServerChar == "?")) {
|
||||
|
||||
@@ -75,7 +75,12 @@ OpenLayers.Layer.TMS.prototype =
|
||||
var x = (bounds.left - this.tileOrigin.lon) / (res * this.tileSize.w);
|
||||
var y = (bounds.bottom - this.tileOrigin.lat) / (res * this.tileSize.h);
|
||||
var z = this.map.getZoom();
|
||||
return this.url + "1.0.0" + "/" + this.layername + "/" + z + "/" + x + "/" + y + "." + this.type;
|
||||
var path = "1.0.0" + "/" + this.layername + "/" + z + "/" + x + "/" + y + "." + this.type;
|
||||
var url = this.url;
|
||||
if (url instanceof Array) {
|
||||
url = this.selectUrl(path, url);
|
||||
}
|
||||
return url + path;
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user