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:
@@ -1,15 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>OpenLayers Tile Extent Example</title>
|
||||
<title>OpenLayers Tile Origin Example</title>
|
||||
<link rel="stylesheet" href="../theme/default/style.css" type="text/css">
|
||||
<link rel="stylesheet" href="../theme/default/google.css" type="text/css">
|
||||
<link rel="stylesheet" href="style.css" type="text/css">
|
||||
</head>
|
||||
<body>
|
||||
<h1 id="title">Tile Extent</h1>
|
||||
<h1 id="title">Tile Origin</h1>
|
||||
<div id="tags">
|
||||
grid, tileExtent
|
||||
grid, tileOrigin
|
||||
</div>
|
||||
<p id="shortdesc">
|
||||
Demonstrates the use of the tileExtent property to differentiate
|
||||
@@ -23,14 +23,14 @@
|
||||
a particular tile lattice. In this case, the layer's
|
||||
<code>maxExtent</code> does not align with that tile lattice.
|
||||
To configure the layer with a tile extent that conforms to the
|
||||
tile extent configured on the server, use the layer's
|
||||
<code>tileExtent</code> property.
|
||||
tile origin configured on the server, use the layer's
|
||||
<code>tileOrigin</code> property.
|
||||
</p><p>
|
||||
View the <a href="tile-extent.js" target="_blank">tile-extent.js</a>
|
||||
View the <a href="tile-origin.js" target="_blank">tile-origin.js</a>
|
||||
source to see how this is done
|
||||
</p>
|
||||
</div>
|
||||
<script src="../lib/OpenLayers.js"></script>
|
||||
<script src="tile-extent.js"></script>
|
||||
<script src="tile-origin.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -8,7 +8,7 @@ var map = new OpenLayers.Map({
|
||||
"Global Imagery",
|
||||
"http://maps.opengeo.org/geowebcache/service/wms",
|
||||
{layers: "bluemarble"},
|
||||
{tileExtent: new OpenLayers.Bounds(-180, -90, 180, 90)}
|
||||
{tileOrigin: new OpenLayers.LonLat(-180, -90)}
|
||||
)
|
||||
],
|
||||
center: new OpenLayers.LonLat(-110, 45),
|
||||
@@ -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;
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -380,7 +380,7 @@
|
||||
|
||||
}
|
||||
|
||||
function test_tileExtent(t) {
|
||||
function test_tileOrigin(t) {
|
||||
t.plan(4);
|
||||
|
||||
var dummy = new OpenLayers.Layer(null, {isBaseLayer: true});
|
||||
@@ -392,7 +392,7 @@
|
||||
var constrained = new OpenLayers.Layer.WMS(
|
||||
null, "http://example.com/wms-c",
|
||||
{layers: "constrained"},
|
||||
{buffer: 0, isBaseLayer: false, tileExtent: new OpenLayers.Bounds(-180, -90, 180, 90)}
|
||||
{buffer: 0, isBaseLayer: false, tileOrigin: new OpenLayers.LonLat(-180, -90)}
|
||||
);
|
||||
var map = new OpenLayers.Map({
|
||||
div: "map",
|
||||
|
||||
Reference in New Issue
Block a user