Adding support for a tileOrigin property to all gridded layers. If working with a cache of tiles that don't align with the bottom left corner of the layer's maxExtent property, set the layer's tileOrigin property. This change also removes the tileExtent property (not in any release), favoring tileOrigin as the way to determine how the grid is aligned. r=ahocevar (closes #3011).
git-svn-id: http://svn.openlayers.org/trunk/openlayers@11033 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -24,12 +24,26 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
||||
* {<OpenLayers.Size>}
|
||||
*/
|
||||
tileSize: null,
|
||||
|
||||
/**
|
||||
* Property: tileOriginCorner
|
||||
* {String} If the <tileOrigin> property is not provided, the tile origin
|
||||
* will be derived from the layer's <maxExtent>. The corner of the
|
||||
* <maxExtent> used is determined by this property. Acceptable values
|
||||
* are "tl" (top left), "tr" (top right), "bl" (bottom left), and "br"
|
||||
* (bottom right). Default is "bl".
|
||||
*/
|
||||
tileOriginCorner: "bl",
|
||||
|
||||
/**
|
||||
* APIProperty: tileExtent
|
||||
* {<OpenLayers.Bounds>}
|
||||
* APIProperty: tileOrigin
|
||||
* {<OpenLayers.LonLat>} Optional origin for aligning the grid of tiles.
|
||||
* If provided, requests for tiles at all resolutions will be aligned
|
||||
* with this location (no tiles shall overlap this location). If
|
||||
* not provided, the grid of tiles will be aligned with the layer's
|
||||
* <maxExtent>. Default is ``null``.
|
||||
*/
|
||||
tileExtent: null,
|
||||
tileOrigin: null,
|
||||
|
||||
/** APIProperty: tileOptions
|
||||
* {Object} optional configuration options for <OpenLayers.Tile> instances
|
||||
@@ -315,32 +329,32 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
||||
|
||||
/**
|
||||
* Method: calculateGridLayout
|
||||
* Generate parameters for the grid layout. This
|
||||
* Generate parameters for the grid layout.
|
||||
*
|
||||
* Parameters:
|
||||
* bounds - {<OpenLayers.Bound>}
|
||||
* extent - {<OpenLayers.Bounds>}
|
||||
* origin - {<OpenLayers.LonLat>}
|
||||
* resolution - {Number}
|
||||
*
|
||||
* Returns:
|
||||
* Object containing properties tilelon, tilelat, tileoffsetlat,
|
||||
* tileoffsetlat, tileoffsetx, tileoffsety
|
||||
*/
|
||||
calculateGridLayout: function(bounds, extent, resolution) {
|
||||
calculateGridLayout: function(bounds, origin, resolution) {
|
||||
var tilelon = resolution * this.tileSize.w;
|
||||
var tilelat = resolution * this.tileSize.h;
|
||||
|
||||
var offsetlon = bounds.left - extent.left;
|
||||
var offsetlon = bounds.left - origin.lon;
|
||||
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 tileoffsetlon = origin.lon + tilecol * tilelon;
|
||||
|
||||
var offsetlat = bounds.top - (extent.bottom + tilelat);
|
||||
var offsetlat = bounds.top - (origin.lat + 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;
|
||||
var tileoffsetlat = origin.lat + tilerow * tilelat;
|
||||
|
||||
return {
|
||||
tilelon: tilelon, tilelat: tilelat,
|
||||
@@ -349,6 +363,32 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
||||
};
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: getTileOrigin
|
||||
* Determine the origin for aligning the grid of tiles. If a <tileOrigin>
|
||||
* property is supplied, that will be returned. Otherwise, the origin
|
||||
* will be derived from the layer's <maxExtent> property. In this case,
|
||||
* the tile origin will be the corner of the <maxExtent> given by the
|
||||
* <tileOriginCorner> property.
|
||||
*
|
||||
* Returns:
|
||||
* {<OpenLayers.LonLat>} The tile origin.
|
||||
*/
|
||||
getTileOrigin: function() {
|
||||
var origin = this.tileOrigin;
|
||||
if (!origin) {
|
||||
var extent = this.getMaxExtent();
|
||||
var edges = ({
|
||||
"tl": ["left", "top"],
|
||||
"tr": ["right", "top"],
|
||||
"bl": ["left", "bottom"],
|
||||
"br": ["right", "bottom"]
|
||||
})[this.tileOriginCorner];
|
||||
origin = new OpenLayers.LonLat(extent[edges[0]], extent[edges[1]]);
|
||||
}
|
||||
return origin;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: initGriddedTiles
|
||||
@@ -367,10 +407,10 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
||||
var minCols = Math.ceil(viewSize.w/this.tileSize.w) +
|
||||
Math.max(1, 2 * this.buffer);
|
||||
|
||||
var extent = this.getMaxExtent();
|
||||
var origin = this.getTileOrigin();
|
||||
var resolution = this.map.getResolution();
|
||||
|
||||
var tileLayout = this.calculateGridLayout(bounds, extent, resolution);
|
||||
var tileLayout = this.calculateGridLayout(bounds, origin, resolution);
|
||||
|
||||
var tileoffsetx = Math.round(tileLayout.tileoffsetx); // heaven help us
|
||||
var tileoffsety = Math.round(tileLayout.tileoffsety);
|
||||
@@ -452,7 +492,7 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
||||
* {OpenLayers.Bounds}
|
||||
*/
|
||||
getMaxExtent: function() {
|
||||
return this.tileExtent || this.maxExtent;
|
||||
return this.maxExtent;
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user