Ticket #803: mapserver_deterministic_url.patch
| File mapserver_deterministic_url.patch, 3.8 kB (added by crschmidt, 1 year ago) |
|---|
-
tests/Layer/test_MapServer.html
old new 156 156 } 157 157 158 158 function test_07_Layer_MapServer_getFullRequestString (t) { 159 160 161 t.plan( 1 ); 159 t.plan( 3 ); 162 160 var map = new OpenLayers.Map('map'); 163 161 tUrl = "http://labs.metacarta.com/cgi-bin/mapserv"; 164 162 tParams = { layers: 'basic', … … 178 176 179 177 t.eq(str, sStr , "getFullRequestString() works"); 180 178 map.destroy(); 179 180 tUrl = ["http://octo.metacarta.com/cgi-bin/mapserv","http://labs.metacarta.com/cgi-bin/mapserv"]; 181 layer = new OpenLayers.Layer.MapServer(name, tUrl, tParams, null); 182 str = layer.getFullRequestString({'c':'d'}); 183 t.eq(str, tUrl[1] + '?' + OpenLayers.Util.getParameterString(OpenLayers.Util.extend(tParams,{'c':'d'})), "getFullRequestString() works for list of two urls and is deterministic"); 184 layer.destroy(); 185 var tParams = { 186 layers: 'basic', 187 format: 'png', 188 mode: 'map', 189 map_imagetype: 'png' 190 }; 191 tUrl = ["http://octo.metacarta.com/cgi-bin/mapserv","http://labs.metacarta.com/cgi-bin/mapserv"]; 192 layer = new OpenLayers.Layer.MapServer(name, tUrl, tParams, null); 193 str = layer.getFullRequestString({'a':'b'}); 194 t.eq(str, tUrl[0] + '?' + OpenLayers.Util.getParameterString(OpenLayers.Util.extend(tParams,{'a':'b'})), "getFullRequestString() works for list of two urls and is deterministic"); 195 layer.destroy(); 181 196 182 197 } 183 198 -
lib/OpenLayers/Layer/MapServer.js
old new 142 142 // use layer's url unless altUrl passed in 143 143 var url = (altUrl == null) ? this.url : altUrl; 144 144 145 // if url is not a string, it should be an array of strings,146 // in which case we will randomly select one of them in order147 // to evenly distribute requests to different urls.148 if (typeof url == "object") {149 url = url[Math.floor(Math.random()*url.length)];150 }151 // requestString always starts with url152 var requestString = url;153 154 145 // create a new params hashtable with all the layer params and the 155 146 // new params together. then convert to string 156 147 var allParams = OpenLayers.Util.extend({}, this.params); 157 148 allParams = OpenLayers.Util.extend(allParams, newParams); 149 var paramsString = OpenLayers.Util.getParameterString(allParams); 150 151 // if url is not a string, it should be an array of strings, 152 // in which case we will deterministically select one of them in 153 // order to evenly distribute requests to different urls. 154 if (url instanceof Array) { 155 url = this.selectUrl(paramsString, url); 156 } 157 158 158 // ignore parameters that are already in the url search string 159 159 var urlParams = OpenLayers.Util.upperCaseObject( 160 160 OpenLayers.Util.getParameters(url)); … … 163 163 delete allParams[key]; 164 164 } 165 165 } 166 varparamsString = OpenLayers.Util.getParameterString(allParams);166 paramsString = OpenLayers.Util.getParameterString(allParams); 167 167 168 // requestString always starts with url 169 var requestString = url; 170 168 171 // MapServer needs '+' seperating things like bounds/height/width. 169 172 // Since typically this is URL encoded, we use a slight hack: we 170 173 // depend on the list-like functionality of getParameterString to
