Changeset 3556
- Timestamp:
- 07/02/07 19:38:36 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sandbox/euzuro/untiled/lib/OpenLayers/Layer/Grid.js
r3447 r3556 23 23 /** @type Integer */ 24 24 buffer: 2, 25 26 /** @type Float */ 27 ratio: 1.5, 25 28 26 29 /** … … 125 128 OpenLayers.Layer.HTTPRequest.prototype.moveTo.apply(this, arguments); 126 129 127 if (bounds == null) { 128 bounds = this.map.getExtent(); 129 } 130 bounds = bounds || this.map.getExtent(); 131 130 132 if (bounds != null) { 131 133 134 // if grid is empty or zoom has changed, we *must* re-tile 135 var forceReTile = !this.grid.length || zoomChanged; 136 137 // total bounds of the tiles 138 var tilesBounds = this.getTilesBounds(); 139 132 140 if (this.singleTile) { 133 if (!dragging) { 134 if (!this.grid.length || 135 !this.getGridBounds().containsBounds(bounds, false)) { 136 this._initSingleTile(); 137 } 141 142 // We want to redraw whenever even the slightest part of the 143 // current bounds is not contained by our tile. 144 // (thus, we do not specify partial -- its default is false) 145 if ( forceReTile || 146 (!dragging && !tileBounds.containsBounds(bounds))) { 147 this._initSingleTile(bounds); 138 148 } 139 } else if (!this.grid.length || zoomChanged ||140 !this.getGridBounds().containsBounds(bounds, true)) {141 this._initTiles();142 149 } else { 143 var buffer = (this.buffer) ? this.buffer*1.5 : 1; 144 while (true) { 145 var tlLayer = this.grid[0][0].position; 146 var tlViewPort = 147 this.map.getViewPortPxFromLayerPx(tlLayer); 148 if (tlViewPort.x > -this.tileSize.w * (buffer - 1)) { 149 this.shiftColumn(true); 150 } else if (tlViewPort.x < -this.tileSize.w * buffer) { 151 this.shiftColumn(false); 152 } else if (tlViewPort.y > -this.tileSize.h * (buffer - 1)) { 153 this.shiftRow(true); 154 } else if (tlViewPort.y < -this.tileSize.h * buffer) { 155 this.shiftRow(false); 156 } else { 157 break; 158 } 159 }; 160 if (this.buffer == 0) { 161 for (var r=0, rl=this.grid.length; r<rl; r++) { 162 var row = this.grid[r]; 163 for (var c=0, cl=row.length; c<cl; c++) { 164 var tile = row[c]; 165 if (!tile.drawn && tile.bounds.intersectsBounds(bounds, false)) { 166 tile.draw(); 167 } 168 } 169 } 150 151 // if the bounds have changed such that they are not even 152 // *partially* contained by our tiles (IE user has 153 // programmatically panned to the other side of the earth) 154 // then we want to reTile (thus, partial true). 155 // 156 if (forceReTile || !tileBounds.containsBounds(bounds, true)) { 157 this._initGriddedTiles(bounds); 158 } else { 159 //we might have to shift our buffer tiles 160 this._moveGriddedTiles(); 170 161 } 171 162 } … … 197 188 /** 198 189 * @private 199 */ 200 _initSingleTile: function() { 190 * 191 * @param {OpenLayers.Bounds} bounds 192 */ 193 _initSingleTile: function(bounds) { 201 194 var mapSize = this.map.getSize(); 202 195 196 //determine new tile bounds 197 var center = bounds.getCenterLonLat(); 198 var tileWidth = bounds.getWidth() * this.ratio; 199 var tileHeight = bounds.getHeight() * this.ratio; 200 var tileBounds = 201 new OpenLayers.Bounds(center.lon - (tileWidth / 2), 202 center.lat - (tileHeight / 2), 203 center.lon + (tileWidth / 2), 204 center.lat + (tileHeight / 2)); 205 206 207 203 208 var lPX = -(this.buffer*mapSize.w); 204 209 var bPX = ((this.buffer+1)*mapSize.h); … … 216 221 } 217 222 218 if (!this.grid[0].length) { 219 this.grid[0][0] = this.addTile(tileBounds, px); 223 var tile = this.grid[0][0]; 224 if (!tile) { 225 tile = this.addTile(tileBounds, px); 226 tile.draw(); 227 this.grid[0][0] = tile; 220 228 } else { 221 this.grid[0][0].moveTo(tileBounds, px, false); 222 } 223 this.grid[0][0].draw(); 229 tile.moveTo(tileBounds, px, false); 230 } 224 231 }, 225 232 226 233 /** 227 234 * @private 228 */ 229 _initTiles:function() { 235 * 236 * @param {OpenLayers.Bounds} bounds 237 */ 238 _initGriddedTiles:function(bounds) { 230 239 231 240 // work out mininum number of rows and columns; this is the number of … … 235 244 var minCols = Math.ceil(viewSize.w/this.tileSize.w) + 1; 236 245 237 var bounds = this.map.getExtent();238 246 var extent = this.map.getMaxExtent(); 239 247 var resolution = this.map.getResolution(); … … 401 409 402 410 /** 411 * @param {OpenLayers.Bounds} bounds 412 */ 413 _moveGriddedTiles: function(bounds) { 414 var buffer = (this.buffer) ? this.buffer*1.5 : 1; 415 while (true) { 416 var tlLayer = this.grid[0][0].position; 417 var tlViewPort = 418 this.map.getViewPortPxFromLayerPx(tlLayer); 419 if (tlViewPort.x > -this.tileSize.w * (buffer - 1)) { 420 this.shiftColumn(true); 421 } else if (tlViewPort.x < -this.tileSize.w * buffer) { 422 this.shiftColumn(false); 423 } else if (tlViewPort.y > -this.tileSize.h * (buffer - 1)) { 424 this.shiftRow(true); 425 } else if (tlViewPort.y < -this.tileSize.h * buffer) { 426 this.shiftRow(false); 427 } else { 428 break; 429 } 430 }; 431 if (this.buffer == 0) { 432 for (var r=0, rl=this.grid.length; r<rl; r++) { 433 var row = this.grid[r]; 434 for (var c=0, cl=row.length; c<cl; c++) { 435 var tile = row[c]; 436 if (!tile.drawn && tile.bounds.intersectsBounds(bounds, false)) { 437 tile.draw(); 438 } 439 } 440 } 441 } 442 }, 443 444 /** 403 445 * addTile gives subclasses of Grid the opportunity to create an 404 446 * OpenLayer.Tile of their choosing. The implementer should initialize … … 424 466 425 467 if (this.map != null) { 426 this._initTiles(); 427 } 468 if (this.singleTile) { 469 this._initSingleTile(); 470 } else { 471 this._initGriddedTiles(); 472 } 473 } 474 428 475 }, 429 476
