OpenLayers OpenLayers

Changeset 2852

Show
Ignore:
Timestamp:
03/22/07 13:47:40 (2 years ago)
Author:
euzuro
Message:

final fix for #410

Files:

Legend:

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

    r2832 r2852  
    1313  OpenLayers.Class.inherit( OpenLayers.Layer, { 
    1414 
    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 */ 
    1626    url: null, 
    1727 
    1828    /** Hashtable of key/value parameters 
     29     *  
    1930     * @type Object */ 
    2031    params: null, 
     
    3344     *  
    3445     * @param {String} name 
    35      * @param {String} url 
     46     * @param {Array(String) or String} url 
    3647     * @param {Object} params 
    3748     * @param {Object} options Hashtable of extra options to tag onto the layer 
     
    92103     
    93104    /** 
     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     * 
    94111     * @param {String} paramString 
    95112     * @param {Array(String)} urls 
     113     *  
     114     * @returns An entry from the urls array, deterministically selected based 
     115     *           on the paramString. 
     116     * @type String 
     117     *  
    96118     */ 
    97119    selectUrl: function(paramString, urls) { 
    98120        var product = 1; 
    99121        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;  
    101123            product -= Math.floor(product);  
    102124        } 
     
    112134     *        "server?key1=value1&key2=value2&key3=value3" 
    113135     *  
     136     * WARNING: The altUrl parameter is deprecated and will be removed in 3.0. 
     137     * 
    114138     * @param {Object} newParams 
    115139     * @param {String} altUrl Use this as the url instead of the layer's url 
     140     *    
    116141     *  
    117142     * @type String 
    118143     */ 
    119144    getFullRequestString:function(newParams, altUrl) { 
    120          
    121         // use layer's url unless altUrl passed in 
    122         var url = (altUrl == null) ? this.url : altUrl; 
     145 
     146        // if not altUrl passed in, use layer's url 
     147        var url = altUrl || this.url; 
    123148         
    124149        // create a new params hashtable with all the layer params and the  
     
    126151        var allParams = OpenLayers.Util.extend(new Object(), this.params); 
    127152        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  
    128163        // ignore parameters that are already in the url search string 
    129164        var urlParams =  
     
    134169            } 
    135170        } 
    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); 
    144172         
    145173        // requestString always starts with url 
  • trunk/openlayers/tests/Layer/test_HTTPRequest.html

    r2831 r2852  
    159159        layer = new OpenLayers.Layer.HTTPRequest(name, tUrl, tParams, null); 
    160160        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"); 
    164164 
    165165    } 
     
    171171 
    172172        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" );  
     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" );  
    175175        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" );  
     176        t.eq( layer.selectUrl("bbox=0,0,180,90",   urls), "wms4", "selectUrl(90,180) returns 2" );  
    177177    } 
    178178 
  • trunk/openlayers/tests/Layer/test_WMS.html

    r2836 r2852  
    214214        map.addLayer(wmslayer); 
    215215        map.setCenter(new OpenLayers.LonLat(0,0), 5); 
    216         var tile = layer.grid[0][0]; 
     216         
     217        var tile = wmslayer.grid[0][0]; 
    217218        t.eq( tile.bounds.left, -22.5, "left side matches" );  
    218219        t.eq( tile.bounds.right, -11.25, "top side matches" );