Changeset 2821
- Timestamp:
- 03/19/07 20:00:17 (2 years ago)
- Files:
-
- trunk/openlayers/lib/OpenLayers/Layer/HTTPRequest.js (modified) (3 diffs)
- trunk/openlayers/lib/OpenLayers/Layer/TMS.js (modified) (1 diff)
- trunk/openlayers/tests/Layer/test_HTTPRequest.html (modified) (2 diffs)
- trunk/openlayers/tests/Layer/test_TMS.html (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openlayers/lib/OpenLayers/Layer/HTTPRequest.js
r1907 r2821 91 91 }, 92 92 93 /** 94 * @param {String} paramString 95 * @param {Array(String)} urls 96 */ 97 selectUrl: function(paramString, urls) { 98 var product = 1; 99 for (var i = 0; i < paramString.length; i++) { 100 product *= paramString.charCodeAt(i) * (Math.sqrt(5) - 1) / Math.sqrt(3); 101 product -= Math.floor(product); 102 } 103 return urls[Math.floor(product * urls.length)]; 104 }, 93 105 94 106 /** combine url with layer's params and these newParams. … … 110 122 var url = (altUrl == null) ? this.url : altUrl; 111 123 112 // if url is not a string, it should be an array of strings,113 // in which case we will randomly select one of them in order114 // to evenly distribute requests to different urls.115 if (typeof url == "object") {116 url = url[Math.floor(Math.random()*url.length)];117 }118 // requestString always starts with url119 var requestString = url;120 121 124 // create a new params hashtable with all the layer params and the 122 125 // new params together. then convert to string … … 132 135 } 133 136 var paramsString = OpenLayers.Util.getParameterString(allParams); 137 138 // if url is not a string, it should be an array of strings, 139 // in which case we will deterministically select one of them in 140 // order to evenly distribute requests to different urls. 141 if (url instanceof Array) { 142 url = this.selectUrl(paramsString, url); 143 } 144 145 // requestString always starts with url 146 var requestString = url; 147 134 148 if (paramsString != "") { 135 149 var lastServerChar = url.charAt(url.length - 1); trunk/openlayers/lib/OpenLayers/Layer/TMS.js
r1927 r2821 76 76 var y = (bounds.bottom - this.tileOrigin.lat) / (res * this.tileSize.h); 77 77 var z = this.map.getZoom(); 78 return this.url + "1.0.0" + "/" + this.layername + "/" + z + "/" + x + "/" + y + "." + this.type; 78 var path = "1.0.0" + "/" + this.layername + "/" + z + "/" + x + "/" + y + "." + this.type; 79 var url = this.url; 80 if (url instanceof Array) { 81 url = this.selectUrl(path, url); 82 } 83 return url + path; 79 84 }, 80 85 trunk/openlayers/tests/Layer/test_HTTPRequest.html
r2803 r2821 90 90 format: 'image/png'}; 91 91 92 t.plan( 9);92 t.plan( 12 ); 93 93 94 94 // without ? … … 148 148 str = layer.getFullRequestString(null, tUrl); 149 149 t.eq(str, tUrl + '?' + OpenLayers.Util.getParameterString(tParams), "getFullRequestString() works for url sans ?"); 150 150 151 // single url object 152 tUrl = ["http://octo.metacarta.com/cgi-bin/mapserv"]; 153 layer = new OpenLayers.Layer.HTTPRequest(name, tUrl, tParams, null); 154 str = layer.getFullRequestString(); 155 t.eq(str, tUrl[0] + '?' + OpenLayers.Util.getParameterString(tParams), "getFullRequestString() works for list of one url"); 156 157 // two url object 158 tUrl = ["http://octo.metacarta.com/cgi-bin/mapserv","http://labs.metacarta.com/cgi-bin/mapserv"]; 159 layer = new OpenLayers.Layer.HTTPRequest(name, tUrl, tParams, null); 160 str = layer.getFullRequestString(); 161 t.eq(str, tUrl[0] + '?' + OpenLayers.Util.getParameterString(tParams), "getFullRequestString() works for list of two urls"); 162 str = layer.getFullRequestString({'a':'f'}); 163 t.eq(str, tUrl[1] + '?' + OpenLayers.Util.getParameterString(OpenLayers.Util.extend(tParams,{'a':'f'})), "getFullRequestString() works for list of two urls and is deterministic"); 164 165 } 166 167 function test_04_Layer_HTTPRequest_selectUrl (t) { 168 t.plan( 4 ); 169 170 layer = new OpenLayers.Layer.HTTPRequest(name, url, params, options); 171 172 urls = ["wms1", "wms2", "wms3", "wms4"]; 173 t.eq( layer.selectUrl("bbox=-180,0,0,90", urls), "wms4", "selectUrl(-90,-180) returns 4" ); 174 t.eq( layer.selectUrl("bbox=-180,-90,0,0", urls), "wms3", "selectUrl(90,-180) returns 3" ); 175 t.eq( layer.selectUrl("bbox=0,90,180,0", urls), "wms1", "selectUrl(-90,180) returns 1" ); 176 t.eq( layer.selectUrl("bbox=0,0,180,90", urls), "wms2", "selectUrl(90,180) returns 2" ); 151 177 } 152 178 trunk/openlayers/tests/Layer/test_TMS.html
r2803 r2821 107 107 function test_10_Layer_TMS_getURL(t) { 108 108 109 t.plan( 1);109 t.plan(2); 110 110 111 111 var map = new OpenLayers.Map('map', options); … … 116 116 var tileurl = layer.getURL(new OpenLayers.Bounds(3.515625,45,4.21875,45.703125)); 117 117 t.eq(tileurl, "http://labs.metacarta.com/wms-c/Basic.py/1.0.0/basic/9/261/192.png", "Tile URL is correct"); 118 119 layer.url = ["http://tilecache1/", "http://tilecache2/", "http://tilecache3/"]; 120 tileurl = layer.getURL(new OpenLayers.Bounds(3.515625,45,4.21875,45.703125)); 121 t.eq(tileurl, "http://tilecache2/1.0.0/basic/9/261/192.png", "Tile URL is deterministic"); 118 122 } 119 123
