Changeset 2852
- Timestamp:
- 03/22/07 13:47:40 (2 years ago)
- Files:
-
- trunk/openlayers/lib/OpenLayers/Layer/HTTPRequest.js (modified) (6 diffs)
- trunk/openlayers/tests/Layer/test_HTTPRequest.html (modified) (2 diffs)
- trunk/openlayers/tests/Layer/test_WMS.html (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openlayers/lib/OpenLayers/Layer/HTTPRequest.js
r2832 r2852 13 13 OpenLayers.Class.inherit( OpenLayers.Layer, { 14 14 15 /** @type String */ 15 /** Used to hash URL param strings for multi-WMS server selection. 16 * Set to the Golden Ratio per Knuth's recommendation. 17 * 18 * @type Numeric 19 * @private 20 */ 21 URL_HASH_FACTOR: (Math.sqrt(5) - 1) / 2, 22 23 /** This is either an array of url strings or a single url string. 24 * 25 * @type Array(String) or String */ 16 26 url: null, 17 27 18 28 /** Hashtable of key/value parameters 29 * 19 30 * @type Object */ 20 31 params: null, … … 33 44 * 34 45 * @param {String} name 35 * @param { String} url46 * @param {Array(String) or String} url 36 47 * @param {Object} params 37 48 * @param {Object} options Hashtable of extra options to tag onto the layer … … 92 103 93 104 /** 105 * selectUrl() implements the standard floating-point multiplicative 106 * hash function described by Knuth, and hashes the contents of the 107 * given param string into a float between 0 and 1. This float is then 108 * scaled to the size of the provided urls array, and used to select 109 * a URL. 110 * 94 111 * @param {String} paramString 95 112 * @param {Array(String)} urls 113 * 114 * @returns An entry from the urls array, deterministically selected based 115 * on the paramString. 116 * @type String 117 * 96 118 */ 97 119 selectUrl: function(paramString, urls) { 98 120 var product = 1; 99 121 for (var i = 0; i < paramString.length; i++) { 100 product *= paramString.charCodeAt(i) * (Math.sqrt(5) - 1) / Math.sqrt(3);122 product *= paramString.charCodeAt(i) * this.URL_HASH_FACTOR; 101 123 product -= Math.floor(product); 102 124 } … … 112 134 * "server?key1=value1&key2=value2&key3=value3" 113 135 * 136 * WARNING: The altUrl parameter is deprecated and will be removed in 3.0. 137 * 114 138 * @param {Object} newParams 115 139 * @param {String} altUrl Use this as the url instead of the layer's url 140 * 116 141 * 117 142 * @type String 118 143 */ 119 144 getFullRequestString:function(newParams, altUrl) { 120 121 // use layer's url unless altUrl passed in122 var url = (altUrl == null) ? this.url : altUrl;145 146 // if not altUrl passed in, use layer's url 147 var url = altUrl || this.url; 123 148 124 149 // create a new params hashtable with all the layer params and the … … 126 151 var allParams = OpenLayers.Util.extend(new Object(), this.params); 127 152 allParams = OpenLayers.Util.extend(allParams, newParams); 153 var paramsString = OpenLayers.Util.getParameterString(allParams); 154 155 // if url is not a string, it should be an array of strings, 156 // in which case we will deterministically select one of them in 157 // order to evenly distribute requests to different urls. 158 // 159 if (url instanceof Array) { 160 url = this.selectUrl(paramsString, url); 161 } 162 128 163 // ignore parameters that are already in the url search string 129 164 var urlParams = … … 134 169 } 135 170 } 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 } 171 paramsString = OpenLayers.Util.getParameterString(allParams); 144 172 145 173 // requestString always starts with url trunk/openlayers/tests/Layer/test_HTTPRequest.html
r2831 r2852 159 159 layer = new OpenLayers.Layer.HTTPRequest(name, tUrl, tParams, null); 160 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");161 t.eq(str, tUrl[1] + '?' + OpenLayers.Util.getParameterString(tParams), "getFullRequestString() works for list of two urls"); 162 str = layer.getFullRequestString({'a':'b'}); 163 t.eq(str, tUrl[0] + '?' + OpenLayers.Util.getParameterString(OpenLayers.Util.extend(tParams,{'a':'b'})), "getFullRequestString() works for list of two urls and is deterministic"); 164 164 165 165 } … … 171 171 172 172 urls = ["wms1", "wms2", "wms3", "wms4"]; 173 t.eq( layer.selectUrl("bbox=-180,0,0,90", urls), "wms 4", "selectUrl(-90,-180) returns 4" );174 t.eq( layer.selectUrl("bbox=-180,-90,0,0", urls), "wms 3", "selectUrl(90,-180) returns 3" );173 t.eq( layer.selectUrl("bbox=-180,0,0,90", urls), "wms3", "selectUrl(-90,-180) returns 4" ); 174 t.eq( layer.selectUrl("bbox=-180,-90,0,0", urls), "wms1", "selectUrl(90,-180) returns 3" ); 175 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), "wms 2", "selectUrl(90,180) returns 2" );176 t.eq( layer.selectUrl("bbox=0,0,180,90", urls), "wms4", "selectUrl(90,180) returns 2" ); 177 177 } 178 178 trunk/openlayers/tests/Layer/test_WMS.html
r2836 r2852 214 214 map.addLayer(wmslayer); 215 215 map.setCenter(new OpenLayers.LonLat(0,0), 5); 216 var tile = layer.grid[0][0]; 216 217 var tile = wmslayer.grid[0][0]; 217 218 t.eq( tile.bounds.left, -22.5, "left side matches" ); 218 219 t.eq( tile.bounds.right, -11.25, "top side matches" );
