OpenLayers OpenLayers

Changeset 2091

Show
Ignore:
Timestamp:
12/22/06 13:35:04 (2 years ago)
Author:
crschmidt
Message:

Commit a number of improvements to grid handling from #449. This adds
support for buffer:0 on grids, and includes changes to Remove extra
rows and columns from the grid in _initTiles when reusing an existing
grid, which is a fix to #357 and #436.

Files:

Legend:

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

    r1721 r2091  
    108108                this._initTiles(); 
    109109            } else { 
     110                var buffer = (this.buffer) ? this.buffer*1.5 : 1; 
    110111                while (true) { 
    111112                    var tlLayer = this.grid[0][0].position; 
    112113                    var tlViewPort =  
    113114                        this.map.getViewPortPxFromLayerPx(tlLayer); 
    114                     if (tlViewPort.x > -this.tileSize.w * (this.buffer - 1)) { 
     115                    if (tlViewPort.x > -this.tileSize.w * (buffer - 1)) { 
    115116                        this.shiftColumn(true); 
    116                     } else if (tlViewPort.x < -this.tileSize.w * this.buffer) { 
     117                    } else if (tlViewPort.x < -this.tileSize.w * buffer) { 
    117118                        this.shiftColumn(false); 
    118                     } else if (tlViewPort.y > -this.tileSize.h * (this.buffer - 1)) { 
     119                    } else if (tlViewPort.y > -this.tileSize.h * (buffer - 1)) { 
    119120                        this.shiftRow(true); 
    120                     } else if (tlViewPort.y < -this.tileSize.h * this.buffer) { 
     121                    } else if (tlViewPort.y < -this.tileSize.h * buffer) { 
    121122                        this.shiftRow(false); 
    122123                    } else { 
    123124                        break; 
    124125                    } 
     126                }; 
     127                if (this.buffer == 0) { 
     128                    for (var r=0, rl=this.grid.length; r<rl; r++) { 
     129                        var row = this.grid[r]; 
     130                        for (var c=0, cl=row.length; c<cl; c++) { 
     131                            var tile = row[c]; 
     132                            if (!tile.drawn && tile.bounds.intersectsBounds(bounds, false)) { 
     133                                tile.draw(); 
     134                            } 
     135                        } 
     136                    } 
    125137                } 
    126138            } 
     
    154166     */ 
    155167    _initTiles:function() { 
     168         
     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 
    156171        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         
    157175        var bounds = this.map.getExtent(); 
    158176        var extent = this.map.getMaxExtent(); 
     
    217235                tileoffsetlon += tilelon;        
    218236                tileoffsetx += this.tileSize.w; 
    219             } while (tileoffsetlon <= bounds.right + tilelon * this.buffer)   
    220              
     237            } while ((tileoffsetlon <= bounds.right + tilelon * this.buffer) 
     238                     || colidx < minCols)   
     239              
    221240            tileoffsetlat -= tilelat; 
    222241            tileoffsety += this.tileSize.h; 
    223         } while(tileoffsetlat >= bounds.bottom - tilelat * this.buffer) 
    224  
     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(); 
     259            } 
     260        } 
     261         
    225262        //now actually draw the tiles 
    226263        this.spiralTileLoad(); 
     
    326363                var row = this.grid[iRow]; 
    327364                for(var iCol=0; iCol < row.length; iCol++) { 
    328                     OpenLayers.Util.clearArray(row[iCol]); 
     365                    row[iCol].destroy(); 
    329366                } 
     367            this.grid = []; 
    330368            } 
    331369        } 
  • trunk/openlayers/lib/OpenLayers/Tile.js

    r2017 r2091  
    7070    */ 
    7171    draw:function() { 
    72         this.drawn = true; 
     72        this.clear(); 
     73        return ((this.layer.displayOutsideMaxExtent 
     74                || (this.layer.maxExtent 
     75                    && this.bounds.intersectsBounds(this.layer.maxExtent, false))) 
     76                && !(this.layer.buffer == 0 
     77                     && !this.bounds.intersectsBounds(this.layer.map.getExtent(), false))); 
    7378    }, 
    7479     
  • trunk/openlayers/lib/OpenLayers/Tile/Image.js

    r1721 r2091  
    4444     */ 
    4545    draw:function() { 
    46         OpenLayers.Tile.prototype.draw.apply(this, arguments); 
    47  
     46        if (this.layer != this.layer.map.baseLayer && this.layer.reproject) { 
     47            this.bounds = this.getBoundsFromBaseLayer(this.position); 
     48        } 
     49        if (!OpenLayers.Tile.prototype.draw.apply(this, arguments)) { 
     50            return false;     
     51        } 
    4852        if (this.imgDiv == null) { 
    4953            this.initImgDiv(); 
    5054        } 
    51         if (this.layer != this.layer.map.baseLayer && this.layer.reproject) { 
    52             this.bounds = this.getBoundsFromBaseLayer(this.position); 
     55         
     56        this.url = this.layer.getURL(this.bounds); 
     57   
     58        if (this.layer.alpha) { 
     59            OpenLayers.Util.modifyAlphaImageDiv(this.imgDiv, 
     60                    null, this.position, this.size, this.url); 
     61        } else { 
     62            this.imgDiv.src = this.url; 
     63            OpenLayers.Util.modifyDOMElement(this.imgDiv, 
     64                    null, this.position, this.size) ; 
    5365        } 
    54  
    55         this.url = this.layer.getURL(this.bounds); 
    56         this.imgDiv.style.display = "none"; 
    57         if (this.layer.displayOutsideMaxExtent || (this.layer.maxExtent &&  
    58             (this.bounds.intersectsBounds(this.layer.maxExtent,false)) 
    59             )) {  
    60             if (this.layer.alpha) { 
    61                 OpenLayers.Util.modifyAlphaImageDiv(this.imgDiv, 
    62                         null, this.position, this.size, this.url); 
    63             } else { 
    64                 this.imgDiv.src = this.url; 
    65                 OpenLayers.Util.modifyDOMElement(this.imgDiv, 
    66                         null, this.position, this.size) ; 
    67             } 
    68         } 
     66        this.drawn = true; 
     67        return true; 
    6968    }, 
    7069 
  • trunk/openlayers/lib/OpenLayers/Tile/WFS.js

    r2029 r2091  
    5858     */ 
    5959    draw:function() { 
    60         if (this.drawn) { 
    61             this.clear(); 
     60        if (!OpenLayers.Tile.prototype.draw.apply(this, arguments)) { 
     61            return false;     
    6262        } 
    63         OpenLayers.Tile.prototype.draw.apply(this, arguments); 
    64         if (this.layer.displayOutsideMaxExtent || (this.layer.maxExtent &&  
    65             this.layer.maxExtent.intersectsBounds(this.bounds, false))) {  
    66             this.loadFeaturesForRegion(this.requestSuccess); 
    67         }          
     63        this.loadFeaturesForRegion(this.requestSuccess); 
     64        this.drawn = true; 
     65        return true; 
    6866    }, 
    6967 
  • trunk/openlayers/tests/test_Tile_Image.html

    r1908 r2091  
    7474        tile = new OpenLayers.Tile.Image(layer, position, new OpenLayers.Bounds(-185,-90,-180,90), url, size); 
    7575        tile.draw() 
    76         t.eq(tile.imgDiv.src, "", "Images against side of maxextent don't load"); 
     76        t.eq(tile.imgDiv, null, "Images against side of maxextent don't load"); 
    7777        tile = new OpenLayers.Tile.Image(layer, position, new OpenLayers.Bounds(-181,-91,180,90), url, size); 
    7878        tile.draw() 
     
    145145    }  
    146146    function test_04_Tile_Image_Display_After_Move(t) { 
    147         t.plan(3); 
     147        t.plan(2); 
    148148        var position = new OpenLayers.Pixel(20,30); 
    149149        var bounds = new OpenLayers.Bounds(1,2,3,4); 
     
    158158        tile.draw(); 
    159159        tile.moveTo(new OpenLayers.Bounds(-185,-90,-180,-80), new OpenLayers.Pixel(-180,-85), true); 
    160         t.delay_call( 1, function() { t.eq(tile.imgDiv.style.display, 'none', "Tile display is set to none.") } ); 
     160        t.delay_call( 1, function() { t.eq(tile.imgDiv, null, "Tile imgDiv is null.") } ); 
    161161        var layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",  
    162162            "http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'}, {'alpha':true}); 
     
    165165        tile.draw(); 
    166166        tile.moveTo(new OpenLayers.Bounds(-185,-90,-180,-80), new OpenLayers.Pixel(-180,-85), true) 
    167         t.ok(tile.imgDiv.firstChild.src != tile.url, "Check to make sure that the alpha image URL really is different"); 
    168         t.delay_call( 1, function() { t.eq(tile.imgDiv.style.display, 'none', "Alpha tile display is set to none.") } ); 
     167        t.delay_call( 1, function() { t.eq(tile.imgDiv, null, "Alpha tile imgDiv is null.") } ); 
    169168         
    170169    }