OpenLayers OpenLayers

Changeset 7667

Show
Ignore:
Timestamp:
08/01/08 14:25:28 (4 months ago)
Author:
pagameba
Message:

Refactor backBuffer tile code out of generic Tile base class into Tile.Image to make it nicer when subclassing Tile for other needs. (Closes #1645) r=elemoine.

Files:

Legend:

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

    r6495 r7667  
    8080     */ 
    8181    isLoading: false, 
    82      
    83     /** 
    84      * Property: isBackBuffer 
    85      * {Boolean} Is this tile a back buffer tile? 
    86      */ 
    87     isBackBuffer: false, 
    88      
    89     /** 
    90      * Property: lastRatio 
    91      * {Float} Used in transition code only.  This is the previous ratio 
    92      *     of the back buffer tile resolution to the map resolution.  Compared 
    93      *     with the current ratio to determine if zooming occurred. 
    94      */ 
    95     lastRatio: 1, 
    96  
    97     /** 
    98      * Property: isFirstDraw 
    99      * {Boolean} Is this the first time the tile is being drawn? 
    100      *     This is used to force resetBackBuffer to synchronize 
    101      *     the backBufferTile with the foreground tile the first time 
    102      *     the foreground tile loads so that if the user zooms 
    103      *     before the layer has fully loaded, the backBufferTile for 
    104      *     tiles that have been loaded can be used. 
    105      */ 
    106     isFirstDraw: true, 
    107          
    108     /** 
    109      * Property: backBufferTile 
    110      * {<OpenLayers.Tile>} A clone of the tile used to create transition 
    111      *     effects when the tile is moved or changes resolution. 
    112      */ 
    113     backBufferTile: null, 
    11482         
    11583    /** TBD 3.0 -- remove 'url' from the list of parameters to the constructor. 
     
    158126     */ 
    159127    destroy:function() { 
    160         if (OpenLayers.Util.indexOf(this.layer.SUPPORTED_TRANSITIONS,  
    161                 this.layer.transitionEffect) != -1) { 
    162             this.layer.events.unregister("loadend", this, this.resetBackBuffer); 
    163             this.events.unregister('loadend', this, this.resetBackBuffer);             
    164         } else { 
    165             this.events.unregister('loadend', this, this.showTile); 
    166         } 
    167128        this.layer  = null; 
    168129        this.bounds = null; 
     
    172133        this.events.destroy(); 
    173134        this.events = null; 
    174          
    175         /* clean up the backBufferTile if it exists */ 
    176         if (this.backBufferTile) { 
    177             this.backBufferTile.destroy(); 
    178             this.backBufferTile = null; 
    179         } 
    180135    }, 
    181136     
     
    222177        // The only case where we *wouldn't* want to draw the tile is if the  
    223178        // tile is outside its layer's maxExtent. 
    224         var drawTile = (withinMaxExtent || this.layer.displayOutsideMaxExtent); 
    225  
    226         if (OpenLayers.Util.indexOf(this.layer.SUPPORTED_TRANSITIONS, this.layer.transitionEffect) != -1) { 
    227             if (drawTile) { 
    228                 //we use a clone of this tile to create a double buffer for visual 
    229                 //continuity.  The backBufferTile is used to create transition 
    230                 //effects while the tile in the grid is repositioned and redrawn 
    231                 if (!this.backBufferTile) { 
    232                     this.backBufferTile = this.clone(); 
    233                     this.backBufferTile.hide(); 
    234                     // this is important.  It allows the backBuffer to place itself 
    235                     // appropriately in the DOM.  The Image subclass needs to put 
    236                     // the backBufferTile behind the main tile so the tiles can 
    237                     // load over top and display as soon as they are loaded. 
    238                     this.backBufferTile.isBackBuffer = true; 
    239                      
    240                     // potentially end any transition effects when the tile loads 
    241                     this.events.register('loadend', this, this.resetBackBuffer); 
    242                      
    243                     // clear transition back buffer tile only after all tiles in 
    244                     // this layer have loaded to avoid visual glitches 
    245                     this.layer.events.register("loadend", this, this.resetBackBuffer); 
    246                 } 
    247                 // run any transition effects 
    248                 this.startTransition(); 
    249             } else { 
    250                 // if we aren't going to draw the tile, then the backBuffer should 
    251                 // be hidden too! 
    252                 if (this.backBufferTile) { 
    253                     this.backBufferTile.clear(); 
    254                 } 
    255             } 
    256         } else { 
    257             if (drawTile && this.isFirstDraw) { 
    258                 this.events.register('loadend', this, this.showTile); 
    259                 this.isFirstDraw = false; 
    260             }    
    261         }     
    262         this.shouldDraw = drawTile; 
    263          
     179        this.shouldDraw = (withinMaxExtent || this.layer.displayOutsideMaxExtent); 
     180                 
    264181        //clear tile's contents and mark as not drawn 
    265182        this.clear(); 
    266183         
    267         return drawTile
     184        return this.shouldDraw
    268185    }, 
    269186     
     
    336253        return bounds; 
    337254    },         
    338      
    339     /**  
    340      * Method: startTransition 
    341      * Prepare the tile for a transition effect.  To be 
    342      *     implemented by subclasses. 
    343      */ 
    344     startTransition: function() {}, 
    345      
    346     /**  
    347      * Method: resetBackBuffer 
    348      * Triggered by two different events, layer loadend, and tile loadend. 
    349      *     In any of these cases, we check to see if we can hide the  
    350      *     backBufferTile yet and update its parameters to match the  
    351      *     foreground tile. 
    352      * 
    353      * Basic logic: 
    354      *  - If the backBufferTile hasn't been drawn yet, reset it 
    355      *  - If layer is still loading, show foreground tile but don't hide 
    356      *    the backBufferTile yet 
    357      *  - If layer is done loading, reset backBuffer tile and show  
    358      *    foreground tile 
    359      */ 
    360     resetBackBuffer: function() { 
    361         this.showTile(); 
    362         if (this.backBufferTile &&  
    363             (this.isFirstDraw || !this.layer.numLoadingTiles)) { 
    364             this.isFirstDraw = false; 
    365             // check to see if the backBufferTile is within the max extents 
    366             // before rendering it  
    367             var maxExtent = this.layer.maxExtent; 
    368             var withinMaxExtent = (maxExtent && 
    369                                    this.bounds.intersectsBounds(maxExtent, false)); 
    370             if (withinMaxExtent) { 
    371                 this.backBufferTile.position = this.position; 
    372                 this.backBufferTile.bounds = this.bounds; 
    373                 this.backBufferTile.size = this.size; 
    374                 this.backBufferTile.imageSize = this.layer.imageSize || this.size; 
    375                 this.backBufferTile.imageOffset = this.layer.imageOffset; 
    376                 this.backBufferTile.resolution = this.layer.getResolution(); 
    377                 this.backBufferTile.renderTile(); 
    378             } 
    379         } 
    380     }, 
    381255         
    382256    /**  
  • trunk/openlayers/lib/OpenLayers/Tile/Image.js

    r7599 r7667  
    3838     */  
    3939    frame: null,  
    40  
    4140     
    4241    /** 
     
    4544     */ 
    4645    layerAlphaHack: null, 
     46     
     47    /** 
     48     * Property: isBackBuffer 
     49     * {Boolean} Is this tile a back buffer tile? 
     50     */ 
     51    isBackBuffer: false, 
     52     
     53    /** 
     54     * Property: lastRatio 
     55     * {Float} Used in transition code only.  This is the previous ratio 
     56     *     of the back buffer tile resolution to the map resolution.  Compared 
     57     *     with the current ratio to determine if zooming occurred. 
     58     */ 
     59    lastRatio: 1, 
     60 
     61    /** 
     62     * Property: isFirstDraw 
     63     * {Boolean} Is this the first time the tile is being drawn? 
     64     *     This is used to force resetBackBuffer to synchronize 
     65     *     the backBufferTile with the foreground tile the first time 
     66     *     the foreground tile loads so that if the user zooms 
     67     *     before the layer has fully loaded, the backBufferTile for 
     68     *     tiles that have been loaded can be used. 
     69     */ 
     70    isFirstDraw: true, 
     71         
     72    /** 
     73     * Property: backBufferTile 
     74     * {<OpenLayers.Tile>} A clone of the tile used to create transition 
     75     *     effects when the tile is moved or changes resolution. 
     76     */ 
     77    backBufferTile: null, 
    4778 
    4879    /** TBD 3.0 - reorder the parameters to the init function to remove  
     
    94125        } 
    95126        this.frame = null;  
     127         
     128        /* clean up the backBufferTile if it exists */ 
     129        if (this.backBufferTile) { 
     130            this.backBufferTile.destroy(); 
     131            this.backBufferTile = null; 
     132        } 
     133         
     134        this.layer.events.unregister("loadend", this, this.resetBackBuffer); 
     135         
    96136        OpenLayers.Tile.prototype.destroy.apply(this, arguments); 
    97137    }, 
     
    136176            this.bounds = this.getBoundsFromBaseLayer(this.position); 
    137177        } 
    138         if (!OpenLayers.Tile.prototype.draw.apply(this, arguments)) { 
    139             return false;     
     178        var drawTile = OpenLayers.Tile.prototype.draw.apply(this, arguments); 
     179         
     180        if (OpenLayers.Util.indexOf(this.layer.SUPPORTED_TRANSITIONS, this.layer.transitionEffect) != -1) { 
     181            if (drawTile) { 
     182                //we use a clone of this tile to create a double buffer for visual 
     183                //continuity.  The backBufferTile is used to create transition 
     184                //effects while the tile in the grid is repositioned and redrawn 
     185                if (!this.backBufferTile) { 
     186                    this.backBufferTile = this.clone(); 
     187                    this.backBufferTile.hide(); 
     188                    // this is important.  It allows the backBuffer to place itself 
     189                    // appropriately in the DOM.  The Image subclass needs to put 
     190                    // the backBufferTile behind the main tile so the tiles can 
     191                    // load over top and display as soon as they are loaded. 
     192                    this.backBufferTile.isBackBuffer = true; 
     193                     
     194                    // potentially end any transition effects when the tile loads 
     195                    this.events.register('loadend', this, this.resetBackBuffer); 
     196                     
     197                    // clear transition back buffer tile only after all tiles in 
     198                    // this layer have loaded to avoid visual glitches 
     199                    this.layer.events.register("loadend", this, this.resetBackBuffer); 
     200                } 
     201                // run any transition effects 
     202                this.startTransition(); 
     203            } else { 
     204                // if we aren't going to draw the tile, then the backBuffer should 
     205                // be hidden too! 
     206                if (this.backBufferTile) { 
     207                    this.backBufferTile.clear(); 
     208                } 
     209            } 
     210        } else { 
     211            if (drawTile && this.isFirstDraw) { 
     212                this.events.register('loadend', this, this.showTile); 
     213                this.isFirstDraw = false; 
     214            }    
     215        }     
     216         
     217        if (!drawTile) { 
     218            return false; 
    140219        } 
    141220         
     
    149228         
    150229        return this.renderTile(); 
     230    }, 
     231     
     232    /**  
     233     * Method: resetBackBuffer 
     234     * Triggered by two different events, layer loadend, and tile loadend. 
     235     *     In any of these cases, we check to see if we can hide the  
     236     *     backBufferTile yet and update its parameters to match the  
     237     *     foreground tile. 
     238     * 
     239     * Basic logic: 
     240     *  - If the backBufferTile hasn't been drawn yet, reset it 
     241     *  - If layer is still loading, show foreground tile but don't hide 
     242     *    the backBufferTile yet 
     243     *  - If layer is done loading, reset backBuffer tile and show  
     244     *    foreground tile 
     245     */ 
     246    resetBackBuffer: function() { 
     247        this.showTile(); 
     248        if (this.backBufferTile &&  
     249            (this.isFirstDraw || !this.layer.numLoadingTiles)) { 
     250            this.isFirstDraw = false; 
     251            // check to see if the backBufferTile is within the max extents 
     252            // before rendering it  
     253            var maxExtent = this.layer.maxExtent; 
     254            var withinMaxExtent = (maxExtent && 
     255                                   this.bounds.intersectsBounds(maxExtent, false)); 
     256            if (withinMaxExtent) { 
     257                this.backBufferTile.position = this.position; 
     258                this.backBufferTile.bounds = this.bounds; 
     259                this.backBufferTile.size = this.size; 
     260                this.backBufferTile.imageSize = this.layer.imageSize || this.size; 
     261                this.backBufferTile.imageOffset = this.layer.imageOffset; 
     262                this.backBufferTile.resolution = this.layer.getResolution(); 
     263                this.backBufferTile.renderTile(); 
     264            } 
     265        } 
    151266    }, 
    152267