Changeset 7667
- Timestamp:
- 08/01/08 14:25:28 (4 months ago)
- Files:
-
- trunk/openlayers/lib/OpenLayers/Tile.js (modified) (5 diffs)
- trunk/openlayers/lib/OpenLayers/Tile/Image.js (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openlayers/lib/OpenLayers/Tile.js
r6495 r7667 80 80 */ 81 81 isLoading: false, 82 83 /**84 * Property: isBackBuffer85 * {Boolean} Is this tile a back buffer tile?86 */87 isBackBuffer: false,88 89 /**90 * Property: lastRatio91 * {Float} Used in transition code only. This is the previous ratio92 * of the back buffer tile resolution to the map resolution. Compared93 * with the current ratio to determine if zooming occurred.94 */95 lastRatio: 1,96 97 /**98 * Property: isFirstDraw99 * {Boolean} Is this the first time the tile is being drawn?100 * This is used to force resetBackBuffer to synchronize101 * the backBufferTile with the foreground tile the first time102 * the foreground tile loads so that if the user zooms103 * before the layer has fully loaded, the backBufferTile for104 * tiles that have been loaded can be used.105 */106 isFirstDraw: true,107 108 /**109 * Property: backBufferTile110 * {<OpenLayers.Tile>} A clone of the tile used to create transition111 * effects when the tile is moved or changes resolution.112 */113 backBufferTile: null,114 82 115 83 /** TBD 3.0 -- remove 'url' from the list of parameters to the constructor. … … 158 126 */ 159 127 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 }167 128 this.layer = null; 168 129 this.bounds = null; … … 172 133 this.events.destroy(); 173 134 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 }180 135 }, 181 136 … … 222 177 // The only case where we *wouldn't* want to draw the tile is if the 223 178 // 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 264 181 //clear tile's contents and mark as not drawn 265 182 this.clear(); 266 183 267 return drawTile;184 return this.shouldDraw; 268 185 }, 269 186 … … 336 253 return bounds; 337 254 }, 338 339 /**340 * Method: startTransition341 * Prepare the tile for a transition effect. To be342 * implemented by subclasses.343 */344 startTransition: function() {},345 346 /**347 * Method: resetBackBuffer348 * Triggered by two different events, layer loadend, and tile loadend.349 * In any of these cases, we check to see if we can hide the350 * backBufferTile yet and update its parameters to match the351 * foreground tile.352 *353 * Basic logic:354 * - If the backBufferTile hasn't been drawn yet, reset it355 * - If layer is still loading, show foreground tile but don't hide356 * the backBufferTile yet357 * - If layer is done loading, reset backBuffer tile and show358 * foreground tile359 */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 extents366 // before rendering it367 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 },381 255 382 256 /** trunk/openlayers/lib/OpenLayers/Tile/Image.js
r7599 r7667 38 38 */ 39 39 frame: null, 40 41 40 42 41 /** … … 45 44 */ 46 45 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, 47 78 48 79 /** TBD 3.0 - reorder the parameters to the init function to remove … … 94 125 } 95 126 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 96 136 OpenLayers.Tile.prototype.destroy.apply(this, arguments); 97 137 }, … … 136 176 this.bounds = this.getBoundsFromBaseLayer(this.position); 137 177 } 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; 140 219 } 141 220 … … 149 228 150 229 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 } 151 266 }, 152 267
