OpenLayers OpenLayers

Changeset 5622

Show
Ignore:
Timestamp:
01/02/08 10:23:45 (1 year ago)
Author:
crschmidt
Message:

Make MapServer multi-url selection deterministic. (Closes #803)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/Layer/MapServer.js

    r5614 r5622  
    145145        var url = (altUrl == null) ? this.url : altUrl; 
    146146         
    147         // if url is not a string, it should be an array of strings,  
    148         //  in which case we will randomly select one of them in order 
    149         //  to evenly distribute requests to different urls. 
    150         if (typeof url == "object") { 
    151             url = url[Math.floor(Math.random()*url.length)]; 
    152         }    
    153         // requestString always starts with url 
    154         var requestString = url;         
    155  
    156147        // create a new params hashtable with all the layer params and the  
    157148        // new params together. then convert to string 
    158149        var allParams = OpenLayers.Util.extend({}, this.params); 
    159150        allParams = OpenLayers.Util.extend(allParams, newParams); 
     151        var paramsString = OpenLayers.Util.getParameterString(allParams); 
     152         
     153        // if url is not a string, it should be an array of strings,  
     154        // in which case we will deterministically select one of them in  
     155        // order to evenly distribute requests to different urls. 
     156        if (url instanceof Array) { 
     157            url = this.selectUrl(paramsString, url); 
     158        }    
     159         
    160160        // ignore parameters that are already in the url search string 
    161161        var urlParams = OpenLayers.Util.upperCaseObject( 
     
    166166            } 
    167167        } 
    168         var paramsString = OpenLayers.Util.getParameterString(allParams); 
    169          
     168        paramsString = OpenLayers.Util.getParameterString(allParams); 
     169         
     170        // requestString always starts with url 
     171        var requestString = url;         
     172 
    170173        // MapServer needs '+' seperating things like bounds/height/width. 
    171174        //   Since typically this is URL encoded, we use a slight hack: we 
  • trunk/openlayers/tests/Layer/test_MapServer.html

    r5524 r5622  
    157157 
    158158    function test_07_Layer_MapServer_getFullRequestString (t) { 
    159  
    160          
    161         t.plan( 1 ); 
     159        t.plan( 3 ); 
    162160        var map = new OpenLayers.Map('map'); 
    163161        tUrl = "http://labs.metacarta.com/cgi-bin/mapserv"; 
     
    179177        t.eq(str, sStr , "getFullRequestString() works"); 
    180178        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(); 
    181196 
    182197    }