coding standards for Grid.js

git-svn-id: http://svn.openlayers.org/trunk/openlayers@890 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2006-07-06 01:51:14 +00:00
parent 353c7b810d
commit f14a6049c1
+27 -14
View File
@@ -16,7 +16,7 @@ OpenLayers.Layer.Grid.prototype =
/** this is an array of rows, each row is an array of tiles /** this is an array of rows, each row is an array of tiles
* *
* @type Array(Array()) */ * @type Array(Array) */
grid: null, grid: null,
/** asserts whether or not the layer's images have an alpha channel /** asserts whether or not the layer's images have an alpha channel
@@ -64,8 +64,9 @@ OpenLayers.Layer.Grid.prototype =
* @param {OpenLayers.Size} size * @param {OpenLayers.Size} size
*/ */
setTileSize: function (size) { setTileSize: function (size) {
if (size) if (size) {
this.tileSize = size.copyOf(); this.tileSize = size.copyOf();
}
}, },
/** This function is called whenever the map is moved. All the moving /** This function is called whenever the map is moved. All the moving
@@ -108,8 +109,13 @@ OpenLayers.Layer.Grid.prototype =
* @type OpenLayers.Bounds * @type OpenLayers.Bounds
*/ */
getGridBounds:function() { getGridBounds:function() {
var topLeftTile = this.grid[0][0]; var topLeftTile = this.grid[0][0];
var bottomRightTile = this.grid[this.grid.length-1][this.grid[0].length-1];
var bottom = this.grid.length - 1;
var right = this.grid[0].length - 1;
var bottomRightTile = this.grid[bottom][right];
return new OpenLayers.Bounds(topLeftTile.bounds.left, return new OpenLayers.Bounds(topLeftTile.bounds.left,
bottomRightTile.bounds.bottom, bottomRightTile.bounds.bottom,
bottomRightTile.bounds.right, bottomRightTile.bounds.right,
@@ -132,8 +138,8 @@ OpenLayers.Layer.Grid.prototype =
var bounds = this.map.getExtent(); var bounds = this.map.getExtent();
var extent = this.map.getMaxExtent(); var extent = this.map.getMaxExtent();
var resolution = this.map.getResolution(); var resolution = this.map.getResolution();
var tilelon = resolution*this.tileSize.w; var tilelon = resolution * this.tileSize.w;
var tilelat = resolution*this.tileSize.h; var tilelat = resolution * this.tileSize.h;
var offsetlon = bounds.left - extent.left; var offsetlon = bounds.left - extent.left;
var tilecol = Math.floor(offsetlon/tilelon); var tilecol = Math.floor(offsetlon/tilelon);
@@ -150,7 +156,7 @@ OpenLayers.Layer.Grid.prototype =
tileoffsetx = Math.round(tileoffsetx); // heaven help us tileoffsetx = Math.round(tileoffsetx); // heaven help us
tileoffsety = Math.round(tileoffsety); tileoffsety = Math.round(tileoffsety);
this.origin = new OpenLayers.Pixel(tileoffsetx,tileoffsety); this.origin = new OpenLayers.Pixel(tileoffsetx, tileoffsety);
var startX = tileoffsetx; var startX = tileoffsetx;
var startLon = tileoffsetlon; var startLon = tileoffsetlon;
@@ -160,16 +166,23 @@ OpenLayers.Layer.Grid.prototype =
this.grid.append(row); this.grid.append(row);
tileoffsetlon = startLon; tileoffsetlon = startLon;
tileoffsetx = startX; tileoffsetx = startX;
do { do {
var tileBounds = new OpenLayers.Bounds(tileoffsetlon, var tileBounds = new OpenLayers.Bounds(tileoffsetlon,
tileoffsetlat, tileoffsetlat,
tileoffsetlon+tilelon, tileoffsetlon + tilelon,
tileoffsetlat+tilelat); tileoffsetlat + tilelat);
var x = tileoffsetx;
x -= parseInt(this.map.layerContainerDiv.style.left);
var y = tileoffsety;
y -= parseInt(this.map.layerContainerDiv.style.top);
var px = new OpenLayers.Pixel(x, y);
var tile = this.addTile(tileBounds, px);
var tile = this.addTile(tileBounds,
new OpenLayers.Pixel(tileoffsetx - parseInt(this.map.layerContainerDiv.style.left),
tileoffsety - parseInt(this.map.layerContainerDiv.style.top))
);
tile.draw(this.alpha); tile.draw(this.alpha);
row.append(tile); row.append(tile);
@@ -278,7 +291,7 @@ OpenLayers.Layer.Grid.prototype =
* @returns The added OpenLayers.Tile * @returns The added OpenLayers.Tile
* @type OpenLayers.Tile * @type OpenLayers.Tile
*/ */
addTile:function(bounds,position) { addTile:function(bounds, position) {
// Should be implemented by subclasses // Should be implemented by subclasses
}, },