Make MapServer multi-url selection deterministic. (Closes #803)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@5622 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -144,19 +144,19 @@ OpenLayers.Layer.MapServer = OpenLayers.Class(OpenLayers.Layer.Grid, {
|
|||||||
// use layer's url unless altUrl passed in
|
// use layer's url unless altUrl passed in
|
||||||
var url = (altUrl == null) ? this.url : altUrl;
|
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
|
// create a new params hashtable with all the layer params and the
|
||||||
// new params together. then convert to string
|
// new params together. then convert to string
|
||||||
var allParams = OpenLayers.Util.extend({}, this.params);
|
var allParams = OpenLayers.Util.extend({}, this.params);
|
||||||
allParams = OpenLayers.Util.extend(allParams, newParams);
|
allParams = OpenLayers.Util.extend(allParams, newParams);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
// ignore parameters that are already in the url search string
|
// ignore parameters that are already in the url search string
|
||||||
var urlParams = OpenLayers.Util.upperCaseObject(
|
var urlParams = OpenLayers.Util.upperCaseObject(
|
||||||
OpenLayers.Util.getParameters(url));
|
OpenLayers.Util.getParameters(url));
|
||||||
@@ -165,8 +165,11 @@ OpenLayers.Layer.MapServer = OpenLayers.Class(OpenLayers.Layer.Grid, {
|
|||||||
delete allParams[key];
|
delete allParams[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var paramsString = OpenLayers.Util.getParameterString(allParams);
|
paramsString = OpenLayers.Util.getParameterString(allParams);
|
||||||
|
|
||||||
|
// requestString always starts with url
|
||||||
|
var requestString = url;
|
||||||
|
|
||||||
// MapServer needs '+' seperating things like bounds/height/width.
|
// MapServer needs '+' seperating things like bounds/height/width.
|
||||||
// Since typically this is URL encoded, we use a slight hack: we
|
// Since typically this is URL encoded, we use a slight hack: we
|
||||||
// depend on the list-like functionality of getParameterString to
|
// depend on the list-like functionality of getParameterString to
|
||||||
|
|||||||
@@ -156,9 +156,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test_07_Layer_MapServer_getFullRequestString (t) {
|
function test_07_Layer_MapServer_getFullRequestString (t) {
|
||||||
|
t.plan( 3 );
|
||||||
|
|
||||||
t.plan( 1 );
|
|
||||||
var map = new OpenLayers.Map('map');
|
var map = new OpenLayers.Map('map');
|
||||||
tUrl = "http://labs.metacarta.com/cgi-bin/mapserv";
|
tUrl = "http://labs.metacarta.com/cgi-bin/mapserv";
|
||||||
tParams = { layers: 'basic',
|
tParams = { layers: 'basic',
|
||||||
@@ -178,6 +176,23 @@
|
|||||||
|
|
||||||
t.eq(str, sStr , "getFullRequestString() works");
|
t.eq(str, sStr , "getFullRequestString() works");
|
||||||
map.destroy();
|
map.destroy();
|
||||||
|
|
||||||
|
tUrl = ["http://octo.metacarta.com/cgi-bin/mapserv","http://labs.metacarta.com/cgi-bin/mapserv"];
|
||||||
|
layer = new OpenLayers.Layer.MapServer(name, tUrl, tParams, null);
|
||||||
|
str = layer.getFullRequestString({'c':'d'});
|
||||||
|
t.eq(str, tUrl[1] + '?' + OpenLayers.Util.getParameterString(OpenLayers.Util.extend(tParams,{'c':'d'})), "getFullRequestString() works for list of two urls and is deterministic");
|
||||||
|
layer.destroy();
|
||||||
|
var tParams = {
|
||||||
|
layers: 'basic',
|
||||||
|
format: 'png',
|
||||||
|
mode: 'map',
|
||||||
|
map_imagetype: 'png'
|
||||||
|
};
|
||||||
|
tUrl = ["http://octo.metacarta.com/cgi-bin/mapserv","http://labs.metacarta.com/cgi-bin/mapserv"];
|
||||||
|
layer = new OpenLayers.Layer.MapServer(name, tUrl, tParams, null);
|
||||||
|
str = layer.getFullRequestString({'a':'b'});
|
||||||
|
t.eq(str, tUrl[0] + '?' + OpenLayers.Util.getParameterString(OpenLayers.Util.extend(tParams,{'a':'b'})), "getFullRequestString() works for list of two urls and is deterministic");
|
||||||
|
layer.destroy();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user