OpenLayers OpenLayers

Changeset 2499

Show
Ignore:
Timestamp:
03/07/07 21:21:11 (2 years ago)
Author:
bwoodall
Message:

Putting my #501 patches into svn

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/bwoodall/t501/build/build.py

    r2126 r2499  
    1717print "Merging libraries." 
    1818merged = mergejs.run(sourceDirectory, None, configFilename) 
    19 print "Compressing." 
    20 minimized = jsmin.jsmin(merged) 
    21 print "Adding license file." 
    22 minimized = file("license.txt").read() + minimized 
     19#print "Compressing." 
     20#minimized = jsmin.jsmin(merged) 
     21#print "Adding license file." 
     22#minimized = file("license.txt").read() + minimized 
     23minimized = merged 
    2324 
    2425print "Writing to %s." % outputFilename 
  • sandbox/bwoodall/t501/lib/OpenLayers/Layer/Grid.js

    r2091 r2499  
    2323    /** @type Integer */ 
    2424    buffer: 2, 
     25 
     26    /** @type Boolean */ 
     27    newTile: false, 
    2528 
    2629    /** 
     
    163166 
    164167    /** 
     168     * 
     169     *   Mercator decimal form <>  lon/lat routines for tiles 
     170     * 
     171     */ 
     172 
     173    /** 
     174     * @private 
     175     * 
     176     * @param {float} lon 
     177     * @param {Integer} tilesAtThisZoom 
     178     * 
     179     * @returns A integer representing the lon at a particular Zoom 
     180     * @type Integer 
     181     */ 
     182    _lon2Gx:function(lon,tilesAtThisZoom) { 
     183        var x = Math.floor((180+lon) * tilesAtThisZoom / 360); 
     184        return x; 
     185    }, 
     186 
     187    /** 
     188     * @private 
     189     * @param {float} lat 
     190     * @param {Integer} tilesAtThisZoom 
     191     * 
     192     * @returns A integer representing the lat at a particular Zoom 
     193     * @type Integer 
     194     */ 
     195    _lat2Gy:function(lat,tilesAtThisZoom) { 
     196        var srlat = Math.sin( lat * Math.PI / 180); 
     197        var y = Math.floor(((1 - (0.5 * Math.log((1 + srlat) / (1 - srlat))) / Math.PI) / 2.0) * tilesAtThisZoom); 
     198        return y; 
     199    }, 
     200 
     201    /** 
     202     * @private 
     203     * @param {Integer} x 
     204     * @param {Integer} tilesAtThisZoom 
     205     * 
     206     * @returns A float (lon) representing the integer tile at a particular Zoom     * @type float 
     207     */ 
     208    _Gx2lon:function(x, tilesAtThisZoom) { 
     209        var lonWidth = 360.0 / tilesAtThisZoom; 
     210        var lon = -180 + (x * lonWidth); 
     211        return lon; 
     212    }, 
     213 
     214    /** 
     215     * @private 
     216     * @param {Integer} y 
     217     * @param {Integer} tilesAtThisZoom 
     218     * 
     219     * @returns A float (lat) representing the integer tile at a particular Zoom     * @type float 
     220     */ 
     221    _Gy2lat:function(y, tilesAtThisZoom) { 
     222        var latHeight = 2.0 / tilesAtThisZoom; 
     223        var lat = ((tilesAtThisZoom / 2 - y - 1) * latHeight); 
     224        latHeight += lat; 
     225        latHeight = (2.0 * Math.atan(Math.exp(Math.PI * latHeight))) 
     226                 - (Math.PI/2); 
     227        latHeight *= (180/Math.PI); 
     228        lat = (2.0 * Math.atan(Math.exp(Math.PI * lat))) - (Math.PI/2); 
     229        lat *= (180/Math.PI); 
     230        latHeight -= lat; 
     231        if (latHeight < 0.0) { 
     232                lat = lat + latHeight; 
     233                latHeight = -latHeight; 
     234        } 
     235        return lat; 
     236    }, 
     237 
     238    /** 
    165239     * @private 
    166240     */ 
    167241    _initTiles:function() { 
    168242         
    169         // work out mininum number of rows and columns; this is the number of 
    170         // tiles required to cover the viewport plus one for panning 
    171         var viewSize = this.map.getSize(); 
    172         var minRows = Math.ceil(viewSize.h/this.tileSize.h) + 1; 
    173         var minCols = Math.ceil(viewSize.w/this.tileSize.w) + 1; 
    174          
    175243        var bounds = this.map.getExtent(); 
    176         var extent = this.map.getMaxExtent(); 
    177         var resolution = this.map.getResolution(); 
    178         var tilelon = resolution * this.tileSize.w; 
    179         var tilelat = resolution * this.tileSize.h; 
    180          
    181         var offsetlon = bounds.left - extent.left; 
    182         var tilecol = Math.floor(offsetlon/tilelon) - this.buffer; 
    183         var tilecolremain = offsetlon/tilelon - tilecol; 
    184         var tileoffsetx = -tilecolremain * this.tileSize.w; 
    185         var tileoffsetlon = extent.left + tilecol * tilelon; 
    186          
    187         var offsetlat = bounds.top - (extent.bottom + tilelat);   
    188         var tilerow = Math.ceil(offsetlat/tilelat) + this.buffer; 
    189         var tilerowremain = tilerow - offsetlat/tilelat; 
    190         var tileoffsety = -tilerowremain * this.tileSize.h; 
    191         var tileoffsetlat = extent.bottom + tilerow * tilelat; 
    192          
    193         tileoffsetx = Math.round(tileoffsetx); // heaven help us 
    194         tileoffsety = Math.round(tileoffsety); 
    195  
    196         this.origin = new OpenLayers.Pixel(tileoffsetx, tileoffsety); 
    197  
    198         var startX = tileoffsetx;  
    199         var startLon = tileoffsetlon; 
    200  
    201         var rowidx = 0; 
    202      
    203         do { 
    204             var row = this.grid[rowidx++]; 
    205             if (!row) { 
    206                 row = new Array(); 
    207                 this.grid.push(row); 
    208             } 
    209  
    210             tileoffsetlon = startLon; 
    211             tileoffsetx = startX; 
    212             var colidx = 0; 
     244 
     245        var layContainerDivleft = parseInt(this.map.layerContainerDiv.style.left); 
     246        var layContainerDivtop = parseInt(this.map.layerContainerDiv.style.top); 
     247 
     248        if (this.newTile) { 
     249 
     250            var zoom = this.map.getZoom(); 
     251 
     252            var tilesAtThisZoom = 1 << zoom; 
     253 
     254            // find the closest tiles for reference 
     255            var xleft = this._lon2Gx(bounds.left, tilesAtThisZoom); 
     256            var xright = this._lon2Gx(bounds.right, tilesAtThisZoom); 
     257            var ybottom = this._lat2Gy(bounds.bottom, tilesAtThisZoom); 
     258            var ytop = this._lat2Gy(bounds.top, tilesAtThisZoom); 
     259 
     260            // add in buffer 
     261            xleft -= this.buffer; 
     262            xright += this.buffer; 
     263            ybottom += this.buffer; 
     264            ytop -= this.buffer; 
     265 
     266            // get the count of rows and columns 
     267            var tilecol = xright-xleft; 
     268            var tilerow = ybottom-ytop; 
     269 
     270            var decimal_lon = xleft; 
     271            var decimal_lat = ytop; 
     272 
     273            var rowidx = 0; 
     274            do { 
     275                var row = this.grid[rowidx++]; 
     276                if (!row) { 
     277                    row = new Array(); 
     278                    this.grid.push(row); 
     279                } 
     280 
     281                decimal_lon = xleft; 
     282 
     283                var colidx = 0; 
     284                do { 
     285                    var bottomLeft = new OpenLayers.LonLat( 
     286                        this._Gx2lon(decimal_lon, tilesAtThisZoom), 
     287                        this._Gy2lat(decimal_lat, tilesAtThisZoom) ); 
     288 
     289                    var topRight = new OpenLayers.LonLat( 
     290                        this._Gx2lon((decimal_lon + 1), tilesAtThisZoom), 
     291                        this._Gy2lat((decimal_lat - 1), tilesAtThisZoom) ); 
     292 
     293                    var pix = this.map.getLayerPxFromLonLat( bottomLeft ); 
     294 
     295                    var tileBounds = new OpenLayers.Bounds( 
     296                        bottomLeft.lon, 
     297                        bottomLeft.lat, 
     298                        topRight.lon, 
     299                        topRight.lat); 
     300 
     301                    // shift pix from lower left to the upper left 
     302                    // if we are not reprojecting 
     303                    if ( ! this.reproject ) { 
     304                        pix.y -= this.tileSize.h; 
     305                    } 
     306 
     307                    pix.x -= layContainerDivleft; 
     308                    pix.y -= layContainerDivtop; 
     309 
     310                    var tile = row[colidx++]; 
     311                    if (!tile) { 
     312                        tile = this.addTile(tileBounds, pix); 
     313                        row.push(tile); 
     314                    } else { 
     315                        tile.moveTo(tileBounds, pix, false); 
     316                    } 
     317                    decimal_lon++; 
     318                } while (colidx <= tilecol) 
     319                decimal_lat++; 
     320            } while (rowidx <= tilerow ) 
     321        } else { 
     322            // work out mininum number of rows and columns; this is the number of 
     323            // tiles required to cover the viewport plus one for panning 
     324            var viewSize = this.map.getSize(); 
     325            var minRows = Math.ceil(viewSize.h/this.tileSize.h) + 1; 
     326            var minCols = Math.ceil(viewSize.w/this.tileSize.w) + 1; 
     327         
     328            var extent = this.map.getMaxExtent(); 
     329            var resolution = this.map.getResolution(); 
     330            var tilelon = resolution * this.tileSize.w; 
     331            var tilelat = resolution * this.tileSize.h; 
     332         
     333            var offsetlon = bounds.left - extent.left; 
     334            var tilecol = Math.floor(offsetlon/tilelon) - this.buffer; 
     335            var tilecolremain = offsetlon/tilelon - tilecol; 
     336            var tileoffsetx = -tilecolremain * this.tileSize.w; 
     337            var tileoffsetlon = extent.left + tilecol * tilelon; 
     338         
     339            var offsetlat = bounds.top - (extent.bottom + tilelat);   
     340            var tilerow = Math.ceil(offsetlat/tilelat) + this.buffer; 
     341            var tilerowremain = tilerow - offsetlat/tilelat; 
     342            var tileoffsety = -tilerowremain * this.tileSize.h; 
     343            var tileoffsetlat = extent.bottom + tilerow * tilelat; 
     344         
     345            tileoffsetx = Math.round(tileoffsetx); // heaven help us 
     346            tileoffsety = Math.round(tileoffsety); 
     347 
     348            this.origin = new OpenLayers.Pixel(tileoffsetx, tileoffsety); 
     349 
     350            var startX = tileoffsetx;  
     351            var startLon = tileoffsetlon; 
     352 
     353            var rowidx = 0; 
     354     
     355            do { 
     356                var row = this.grid[rowidx++]; 
     357                if (!row) { 
     358                    row = new Array(); 
     359                    this.grid.push(row); 
     360                } 
     361 
     362                tileoffsetlon = startLon; 
     363                tileoffsetx = startX; 
     364                var colidx = 0; 
    213365  
    214             do { 
    215                 var tileBounds = new OpenLayers.Bounds(tileoffsetlon,  
     366                do { 
     367                    var tileBounds = new OpenLayers.Bounds(tileoffsetlon,  
    216368                                                      tileoffsetlat,  
    217369                                                      tileoffsetlon + tilelon, 
    218370                                                      tileoffsetlat + tilelat); 
    219371 
    220                 var x = tileoffsetx; 
    221                 x -= parseInt(this.map.layerContainerDiv.style.left); 
    222  
    223                 var y = tileoffsety; 
    224                 y -= parseInt(this.map.layerContainerDiv.style.top); 
    225  
    226                 var px = new OpenLayers.Pixel(x, y); 
    227                 var tile = row[colidx++]; 
    228                 if (!tile) { 
    229                     tile = this.addTile(tileBounds, px); 
    230                     row.push(tile); 
    231                 } else { 
    232                     tile.moveTo(tileBounds, px, false); 
     372                    var x = tileoffsetx; 
     373                    x -= layContainerDivleft; 
     374 
     375                    var y = tileoffsety; 
     376                    y -= layContainerDivtop; 
     377 
     378                    var px = new OpenLayers.Pixel(x, y); 
     379                    var tile = row[colidx++]; 
     380                    if (!tile) { 
     381                        tile = this.addTile(tileBounds, px); 
     382                        row.push(tile); 
     383                    } else { 
     384                        tile.moveTo(tileBounds, px, false); 
     385                    } 
     386      
     387                    tileoffsetlon += tilelon;        
     388                    tileoffsetx += this.tileSize.w; 
     389                } while ((tileoffsetlon <= bounds.right + tilelon * this.buffer) 
     390                         || colidx < minCols)   
     391              
     392                tileoffsetlat -= tilelat; 
     393                tileoffsety += this.tileSize.h; 
     394            } while((tileoffsetlat >= bounds.bottom - tilelat * this.buffer) 
     395                    || rowidx < minRows) 
     396         
     397            // remove extra rows 
     398            while (this.grid.length > rowidx) { 
     399                var row = this.grid.pop(); 
     400                for (var i=0, l=row.length; i<l; i++) { 
     401                    row[i].destroy(); 
    233402                } 
    234       
    235                 tileoffsetlon += tilelon;        
    236                 tileoffsetx += this.tileSize.w; 
    237             } while ((tileoffsetlon <= bounds.right + tilelon * this.buffer) 
    238                      || colidx < minCols)   
    239               
    240             tileoffsetlat -= tilelat; 
    241             tileoffsety += this.tileSize.h; 
    242         } while((tileoffsetlat >= bounds.bottom - tilelat * this.buffer) 
    243                 || rowidx < minRows) 
    244          
    245         // remove extra rows 
    246         while (this.grid.length > rowidx) { 
    247             var row = this.grid.pop(); 
    248             for (var i=0, l=row.length; i<l; i++) { 
    249                 row[i].destroy(); 
    250             } 
    251         } 
    252          
    253         // remove extra columns 
    254         while (this.grid[0].length > colidx) { 
    255             for (var i=0, l=this.grid.length; i<l; i++) { 
    256                 var row = this.grid[i]; 
    257                 var tile = row.pop(); 
    258                 tile.destroy(); 
     403            } 
     404         
     405            // remove extra columns 
     406            while (this.grid[0].length > colidx) { 
     407                for (var i=0, l=this.grid.length; i<l; i++) { 
     408                    var row = this.grid[i]; 
     409                    var tile = row.pop(); 
     410                    tile.destroy(); 
     411                } 
    259412            } 
    260413        } 
  • sandbox/bwoodall/t501/tests/test_Layer_Grid.html

    r1624 r2499  
    171171    } 
    172172 
     173    function test_12_Layer_Grid_inittiles_newTile (t) { 
     174        t.plan( 6 ); 
     175        var map = new OpenLayers.Map($('map')); 
     176        layer = new OpenLayers.Layer.WMS(name, url, params, {newTile: true}); 
     177        map.addLayer(layer); 
     178        map.setCenter(new OpenLayers.LonLat(0,0),4); 
     179        t.eq( layer.grid.length, 8, "newTile Grid rows is correct at zoom 4." ); 
     180        t.eq( layer.grid[0].length, 6, "newTile Grid cols is correct at zoom 4." ); 
     181        var row = layer.grid[4]; 
     182        t.eq( row[3].bounds.right, 22.5, "newTile Grid bounds is correct at zoom 4." ); 
     183 
     184        map.setCenter(new OpenLayers.LonLat(-10,10),9); 
     185        t.eq( layer.grid.length, 8, "newTile Grid rows is correct at zoom 9." ); 
     186        t.eq( layer.grid[0].length, 7, "newTile Grid cols is correct at zoom 9." ); 
     187        var row = layer.grid[2]; 
     188        t.eq( row[2].bounds.left, -11.25, "newTile Grid bounds is correct at zoom 9." ); 
     189         
     190    } 
    173191 
    174192    function test_99_Layer_Grid_destroy (t) { 
     
    182200        t.eq( layer.grid, null, "layer.grid is null after destroy" ); 
    183201        t.eq( layer.tileSize, null, "layer.tileSize is null after destroy" ); 
    184  
    185202 
    186203    //test with tile creation