We split the grid init into a seperate function, and use that as the
controlling mechanism, to reduce code duplication between Grid/KaMap/other layers that need a different grid origin. r=euzuro (Closes #1349) git-svn-id: http://svn.openlayers.org/trunk/openlayers@6231 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -299,6 +299,43 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
|||||||
this.removeExcessTiles(1,1);
|
this.removeExcessTiles(1,1);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method: calculateGridLayout
|
||||||
|
* Generate parameters for the grid layout. This
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* bounds - {<OpenLayers.Bound>}
|
||||||
|
* extent - {<OpenLayers.Bounds>}
|
||||||
|
* resolution - {Number}
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* Object containing properties tilelon, tilelat, tileoffsetlat,
|
||||||
|
* tileoffsetlat, tileoffsetx, tileoffsety
|
||||||
|
*/
|
||||||
|
calculateGridLayout: function(bounds, extent, resolution) {
|
||||||
|
var tilelon = resolution * this.tileSize.w;
|
||||||
|
var tilelat = resolution * this.tileSize.h;
|
||||||
|
|
||||||
|
var offsetlon = bounds.left - extent.left;
|
||||||
|
var tilecol = Math.floor(offsetlon/tilelon) - this.buffer;
|
||||||
|
var tilecolremain = offsetlon/tilelon - tilecol;
|
||||||
|
var tileoffsetx = -tilecolremain * this.tileSize.w;
|
||||||
|
var tileoffsetlon = extent.left + tilecol * tilelon;
|
||||||
|
|
||||||
|
var offsetlat = bounds.top - (extent.bottom + tilelat);
|
||||||
|
var tilerow = Math.ceil(offsetlat/tilelat) + this.buffer;
|
||||||
|
var tilerowremain = tilerow - offsetlat/tilelat;
|
||||||
|
var tileoffsety = -tilerowremain * this.tileSize.h;
|
||||||
|
var tileoffsetlat = extent.bottom + tilerow * tilelat;
|
||||||
|
|
||||||
|
return {
|
||||||
|
tilelon: tilelon, tilelat: tilelat,
|
||||||
|
tileoffsetlon: tileoffsetlon, tileoffsetlat: tileoffsetlat,
|
||||||
|
tileoffsetx: tileoffsetx, tileoffsety: tileoffsety
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method: initGriddedTiles
|
* Method: initGriddedTiles
|
||||||
*
|
*
|
||||||
@@ -318,23 +355,17 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
|||||||
|
|
||||||
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 tilelat = resolution * this.tileSize.h;
|
|
||||||
|
|
||||||
var offsetlon = bounds.left - extent.left;
|
var tileLayout = this.calculateGridLayout(bounds, extent, resolution);
|
||||||
var tilecol = Math.floor(offsetlon/tilelon) - this.buffer;
|
|
||||||
var tilecolremain = offsetlon/tilelon - tilecol;
|
|
||||||
var tileoffsetx = -tilecolremain * this.tileSize.w;
|
|
||||||
var tileoffsetlon = extent.left + tilecol * tilelon;
|
|
||||||
|
|
||||||
var offsetlat = bounds.top - (extent.bottom + tilelat);
|
var tileoffsetx = Math.round(tileLayout.tileoffsetx); // heaven help us
|
||||||
var tilerow = Math.ceil(offsetlat/tilelat) + this.buffer;
|
var tileoffsety = Math.round(tileLayout.tileoffsety);
|
||||||
var tilerowremain = tilerow - offsetlat/tilelat;
|
|
||||||
var tileoffsety = -tilerowremain * this.tileSize.h;
|
|
||||||
var tileoffsetlat = extent.bottom + tilerow * tilelat;
|
|
||||||
|
|
||||||
tileoffsetx = Math.round(tileoffsetx); // heaven help us
|
var tileoffsetlon = tileLayout.tileoffsetlon;
|
||||||
tileoffsety = Math.round(tileoffsety);
|
var tileoffsetlat = tileLayout.tileoffsetlat;
|
||||||
|
|
||||||
|
var tilelon = tileLayout.tilelon;
|
||||||
|
var tilelat = tileLayout.tilelat;
|
||||||
|
|
||||||
this.origin = new OpenLayers.Pixel(tileoffsetx, tileoffsety);
|
this.origin = new OpenLayers.Pixel(tileoffsetx, tileoffsety);
|
||||||
|
|
||||||
|
|||||||
@@ -114,16 +114,21 @@ OpenLayers.Layer.KaMap = OpenLayers.Class(OpenLayers.Layer.Grid, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method: initGriddedTiles
|
* Method: calculateGridLayout
|
||||||
|
* ka-Map uses the center point of the map as an origin for
|
||||||
|
* its tiles. Override calculateGridLayout to center tiles
|
||||||
|
* correctly for this case.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* bounds - {<OpenLayers.Bound>}
|
||||||
|
* extent - {<OpenLayers.Bounds>}
|
||||||
|
* resolution - {Number}
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* Object containing properties tilelon, tilelat, tileoffsetlat,
|
||||||
|
* tileoffsetlat, tileoffsetx, tileoffsety
|
||||||
*/
|
*/
|
||||||
initGriddedTiles:function(bounds) {
|
calculateGridLayout: function(bounds, extent, resolution) {
|
||||||
|
|
||||||
var viewSize = this.map.getSize();
|
|
||||||
var minRows = Math.ceil(viewSize.h/this.tileSize.h) + Math.max(1, 2*this.buffer);
|
|
||||||
var minCols = Math.ceil(viewSize.w/this.tileSize.w) + Math.max(1, 2*this.buffer);
|
|
||||||
|
|
||||||
var extent = this.map.getMaxExtent();
|
|
||||||
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;
|
||||||
|
|
||||||
@@ -139,67 +144,11 @@ OpenLayers.Layer.KaMap = OpenLayers.Class(OpenLayers.Layer.Grid, {
|
|||||||
var tileoffsety = -(tilerowremain+1) * this.tileSize.h;
|
var tileoffsety = -(tilerowremain+1) * this.tileSize.h;
|
||||||
var tileoffsetlat = tilerow * tilelat;
|
var tileoffsetlat = tilerow * tilelat;
|
||||||
|
|
||||||
tileoffsetx = Math.round(tileoffsetx); // heaven help us
|
return {
|
||||||
tileoffsety = Math.round(tileoffsety);
|
tilelon: tilelon, tilelat: tilelat,
|
||||||
|
tileoffsetlon: tileoffsetlon, tileoffsetlat: tileoffsetlat,
|
||||||
this.origin = new OpenLayers.Pixel(tileoffsetx,tileoffsety);
|
tileoffsetx: tileoffsetx, tileoffsety: tileoffsety
|
||||||
|
|
||||||
var startX = tileoffsetx;
|
|
||||||
var startLon = tileoffsetlon;
|
|
||||||
|
|
||||||
var rowidx = 0;
|
|
||||||
|
|
||||||
do {
|
|
||||||
var row = this.grid[rowidx++];
|
|
||||||
if (!row) {
|
|
||||||
row = [];
|
|
||||||
this.grid.push(row);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tileoffsetlon = startLon;
|
|
||||||
tileoffsetx = startX;
|
|
||||||
|
|
||||||
var colidx = 0;
|
|
||||||
|
|
||||||
do {
|
|
||||||
var tileBounds =
|
|
||||||
new OpenLayers.Bounds(tileoffsetlon,
|
|
||||||
tileoffsetlat,
|
|
||||||
tileoffsetlon + tilelon,
|
|
||||||
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 = row[colidx++];
|
|
||||||
if (!tile) {
|
|
||||||
tile = this.addTile(tileBounds, px);
|
|
||||||
this.addTileMonitoringHooks(tile);
|
|
||||||
row.push(tile);
|
|
||||||
} else {
|
|
||||||
tile.moveTo(tileBounds, px, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
tileoffsetlon += tilelon;
|
|
||||||
tileoffsetx += this.tileSize.w;
|
|
||||||
} while (tileoffsetlon <= bounds.right + tilelon * this.buffer
|
|
||||||
|| colidx < minCols)
|
|
||||||
|
|
||||||
tileoffsetlat -= tilelat;
|
|
||||||
tileoffsety += this.tileSize.h;
|
|
||||||
} while(tileoffsetlat >= bounds.bottom - tilelat * this.buffer
|
|
||||||
|| rowidx < minRows)
|
|
||||||
|
|
||||||
//shave off exceess rows and colums
|
|
||||||
this.removeExcessTiles(rowidx, colidx);
|
|
||||||
|
|
||||||
//now actually draw the tiles
|
|
||||||
this.spiralTileLoad();
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user