OpenLayers OpenLayers

Ticket #1622: mapguideHttpTile.patch

File mapguideHttpTile.patch, 5.4 kB (added by openlayers, 4 months ago)
  • MapGuide.js

    old new  
    3333    singleTile: false, 
    3434     
    3535    /** 
     36     * APIProperty: useHttpTile 
     37     * {Boolean} use a tile cache exposed directly via a webserver rather than the  
     38     *    via mapguide server. This does require extra configuration on the Mapguide Server, 
     39     *    and will only work when singleTile is false. The url for the layer must be set to the 
     40     *    webserver path rather than the Mapguide mapagent.    
     41     *    See http://trac.osgeo.org/mapguide/wiki/CodeSamples/Tiles/ServingTilesViaHttp  
     42     **/ 
     43    useHttpTile: false, 
     44     
     45    /** 
    3646     * Constant: TILE_PARAMS 
    3747     * {Object} Hashtable of default parameter key/value pairs for tiled layer 
    3848     */ 
    3949    TILE_PARAMS: { 
    4050         operation: 'GETTILEIMAGE', 
    41          version: '1.2.0' 
     51         version: '1.2.0', 
     52         tileColumnsPerFolder: 30, 
     53         tileRowsPerFolder: 30, 
     54         format: 'png' 
    4255    }, 
    4356 
    4457    /** 
     
    219232          var rowidx = Math.floor((this.maxExtent.top-bounds.top)/currentRes); 
    220233          rowidx = Math.round(rowidx/this.tileSize.h); 
    221234 
     235          if (this.useHttpTile){ 
     236              url = this.getImageFilePath( 
     237                       { 
     238                           tilecol: colidx, 
     239                           tilerow: rowidx, 
     240                           scaleindex: this.resolutions.length - this.map.zoom - 1 
     241                        }); 
     242           
     243          } else { 
    222244          url = this.getFullRequestString( 
    223245                       { 
    224246                           tilecol: colidx, 
     
    226248                           scaleindex: this.resolutions.length - this.map.zoom - 1 
    227249                        }); 
    228250         } 
     251         } 
    229252         
    230253        return url; 
    231254    }, 
    232255 
    233256    /** 
    234      * Method: getFullRequestString 
    235      * getFullRequestString on MapGuide layers is special, because we  
    236      * do a regular expression replace on ',' in parameters to '+'. 
    237      * This is why it is subclassed here. 
     257     * Method: getImageFilePath 
     258     * special handler to request mapguide tiles from an http exposed tilecache  
    238259     * 
    239260     * Parameters: 
    240261     * altUrl - {String} Alternative base URL to use. 
    241262     * 
    242263     * Returns: 
    243      * {String} A string with the layer's url appropriately encoded for MapGuid
     264     * {String} A string with the url for the tile imag
    244265     */ 
     266    getImageFilePath:function(newParams, altUrl) { 
     267     
     268     
     269        // use layer's url unless altUrl passed in 
     270        var url = (altUrl == null) ? this.url : altUrl; 
     271         
     272        // if url is not a string, it should be an array of strings,  
     273        //  in which case we will randomly select one of them in order 
     274        //  to evenly distribute requests to different urls. 
     275        if (typeof url == "object") { 
     276            url = url[Math.floor(Math.random()*url.length)]; 
     277        }    
     278        // requestString always starts with url 
     279        var requestString = url;         
     280 
     281        // create a new params hashtable with all the layer params and the  
     282        // new params together. then convert to string 
     283        var allParams = OpenLayers.Util.extend({}, this.params); 
     284        allParams = OpenLayers.Util.extend(allParams, newParams); 
     285        // ignore parameters that are already in the url search string 
     286        var urlParams = OpenLayers.Util.upperCaseObject( 
     287                            OpenLayers.Util.getArgs(url)); 
     288        for(var key in allParams) { 
     289            if(key.toUpperCase() in urlParams) { 
     290                delete allParams[key]; 
     291            } 
     292        } 
     293        var paramsString = OpenLayers.Util.getParameterString(allParams); 
     294         
     295        /* MapGuide needs '+' seperating things like bounds/height/width. 
     296           Since typically this is URL encoded, we use a slight hack: we 
     297           depend on the list-like functionality of getParameterString to 
     298           leave ',' only in the case of list items (since otherwise it is 
     299           encoded) then do a regular expression replace on the , characters 
     300           to '+' */ 
     301        paramsString = paramsString.replace(/,/g, "+"); 
     302 
     303        var tileRowGroup = "" 
     304        var tileColGroup = ""; 
     305         
     306        if (newParams.tilerow < 0) 
     307            tileRowGroup =  '-'; 
     308             
     309        if (newParams.tilerow == 0 )     
     310            tileRowGroup += 0; 
     311        else 
     312            tileRowGroup += Math.floor(newParams.tilerow/this.TILE_PARAMS.tileRowsPerFolder) * this.TILE_PARAMS.tileRowsPerFolder ; 
     313             
     314        if (newParams.tilecol < 0) 
     315            tileColGroup =  '-'; 
     316         
     317        if (newParams.tilecol == 0) 
     318            tileColGroup += 0; 
     319        else                 
     320            tileColGroup += Math.floor(newParams.tilecol/this.TILE_PARAMS.tileColumnsPerFolder) * this.TILE_PARAMS.tileColumnsPerFolder;                     
     321         
     322        var tilePath = '/S' + newParams.scaleindex 
     323                        + '/' + this.params.basemaplayergroupname 
     324                        + '/R' + tileRowGroup 
     325                        + '/C' + tileColGroup 
     326                        + '/' + (newParams.tilerow % this.TILE_PARAMS.tileRowsPerFolder)  
     327                        + '_' + (newParams.tilecol % this.TILE_PARAMS.tileColumnsPerFolder)  
     328                        + '.' + this.TILE_PARAMS.format; 
     329                        // +'?r='+newParams.tilerow+'&c='+newParams.tilecol; 
     330         
     331        requestString +=tilePath; 
     332         
     333        return requestString; 
     334    }, 
     335     
    245336    getFullRequestString:function(newParams, altUrl) { 
    246337        // use layer's url unless altUrl passed in 
    247338        var url = (altUrl == null) ? this.url : altUrl;