applying patch for #399 - MultiServer - some small formatting/commenting changes.

git-svn-id: http://svn.openlayers.org/trunk/openlayers@1872 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2006-11-16 09:03:17 +00:00
parent 1f18b68e7d
commit ac949589a0
2 changed files with 43 additions and 3 deletions

35
examples/multiserver.html Normal file
View File

@@ -0,0 +1,35 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
#map {
width: 800px;
height: 475px;
border: 1px solid black;
}
</style>
<script src="../lib/OpenLayers.js"></script>
<script type="text/javascript">
<!--
var lon = 5;
var lat = 40;
var zoom = 5;
var map, layer;
function init(){
map = new OpenLayers.Map( $('map') );
var urlArray = ["http://labs.metacarta.com/wms-c/Basic.py",
"http://monitor.metacarta.com/wms-c/Basic.py"];
layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
urlArray,
{layers: 'basic'} );
map.addLayer(layer);
map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
}
// -->
</script>
</head>
<body onload="init()">
<div id="map"></div>
</body>
</html>

View File

@@ -109,6 +109,12 @@ 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;
@@ -117,13 +123,12 @@ OpenLayers.Layer.HTTPRequest.prototype =
var allParams = OpenLayers.Util.extend(new Object(), this.params);
var allParams = OpenLayers.Util.extend(allParams, newParams);
var paramsString = OpenLayers.Util.getParameterString(allParams);
if (paramsString != "") {
var lastServerChar = this.url.charAt(this.url.length - 1);
var lastServerChar = url.charAt(url.length - 1);
if ((lastServerChar == "&") || (lastServerChar == "?")) {
requestString += paramsString;
} else {
if (this.url.indexOf('?') == -1) {
if (url.indexOf('?') == -1) {
//serverPath has no ? -- add one
requestString += '?' + paramsString;
} else {