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);
|
||||
},
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
@@ -318,23 +355,17 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
||||
|
||||
var extent = this.map.getMaxExtent();
|
||||
var resolution = this.map.getResolution();
|
||||
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 tileLayout = this.calculateGridLayout(bounds, extent, resolution);
|
||||
|
||||
var tileoffsetx = Math.round(tileLayout.tileoffsetx); // heaven help us
|
||||
var tileoffsety = Math.round(tileLayout.tileoffsety);
|
||||
|
||||
var tileoffsetlon = tileLayout.tileoffsetlon;
|
||||
var tileoffsetlat = tileLayout.tileoffsetlat;
|
||||
|
||||
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;
|
||||
|
||||
tileoffsetx = Math.round(tileoffsetx); // heaven help us
|
||||
tileoffsety = Math.round(tileoffsety);
|
||||
var tilelon = tileLayout.tilelon;
|
||||
var tilelat = tileLayout.tilelat;
|
||||
|
||||
this.origin = new OpenLayers.Pixel(tileoffsetx, tileoffsety);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user