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>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<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/style.css" type="text/css">
|
||||||
<link rel="stylesheet" href="../theme/default/google.css" type="text/css">
|
<link rel="stylesheet" href="../theme/default/google.css" type="text/css">
|
||||||
<link rel="stylesheet" href="style.css" type="text/css">
|
<link rel="stylesheet" href="style.css" type="text/css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1 id="title">Tile Extent</h1>
|
<h1 id="title">Tile Origin</h1>
|
||||||
<div id="tags">
|
<div id="tags">
|
||||||
grid, tileExtent
|
grid, tileOrigin
|
||||||
</div>
|
</div>
|
||||||
<p id="shortdesc">
|
<p id="shortdesc">
|
||||||
Demonstrates the use of the tileExtent property to differentiate
|
Demonstrates the use of the tileExtent property to differentiate
|
||||||
@@ -23,14 +23,14 @@
|
|||||||
a particular tile lattice. In this case, the layer's
|
a particular tile lattice. In this case, the layer's
|
||||||
<code>maxExtent</code> does not align with that tile lattice.
|
<code>maxExtent</code> does not align with that tile lattice.
|
||||||
To configure the layer with a tile extent that conforms to the
|
To configure the layer with a tile extent that conforms to the
|
||||||
tile extent configured on the server, use the layer's
|
tile origin configured on the server, use the layer's
|
||||||
<code>tileExtent</code> property.
|
<code>tileOrigin</code> property.
|
||||||
</p><p>
|
</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
|
source to see how this is done
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<script src="../lib/OpenLayers.js"></script>
|
<script src="../lib/OpenLayers.js"></script>
|
||||||
<script src="tile-extent.js"></script>
|
<script src="tile-origin.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -8,7 +8,7 @@ var map = new OpenLayers.Map({
|
|||||||
"Global Imagery",
|
"Global Imagery",
|
||||||
"http://maps.opengeo.org/geowebcache/service/wms",
|
"http://maps.opengeo.org/geowebcache/service/wms",
|
||||||
{layers: "bluemarble"},
|
{layers: "bluemarble"},
|
||||||
{tileExtent: new OpenLayers.Bounds(-180, -90, 180, 90)}
|
{tileOrigin: new OpenLayers.LonLat(-180, -90)}
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
center: new OpenLayers.LonLat(-110, 45),
|
center: new OpenLayers.LonLat(-110, 45),
|
||||||
@@ -26,10 +26,24 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
|||||||
tileSize: null,
|
tileSize: null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* APIProperty: tileExtent
|
* Property: tileOriginCorner
|
||||||
* {<OpenLayers.Bounds>}
|
* {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".
|
||||||
*/
|
*/
|
||||||
tileExtent: null,
|
tileOriginCorner: "bl",
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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``.
|
||||||
|
*/
|
||||||
|
tileOrigin: null,
|
||||||
|
|
||||||
/** APIProperty: tileOptions
|
/** APIProperty: tileOptions
|
||||||
* {Object} optional configuration options for <OpenLayers.Tile> instances
|
* {Object} optional configuration options for <OpenLayers.Tile> instances
|
||||||
@@ -315,32 +329,32 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Method: calculateGridLayout
|
* Method: calculateGridLayout
|
||||||
* Generate parameters for the grid layout. This
|
* Generate parameters for the grid layout.
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* bounds - {<OpenLayers.Bound>}
|
* bounds - {<OpenLayers.Bound>}
|
||||||
* extent - {<OpenLayers.Bounds>}
|
* origin - {<OpenLayers.LonLat>}
|
||||||
* resolution - {Number}
|
* resolution - {Number}
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* Object containing properties tilelon, tilelat, tileoffsetlat,
|
* Object containing properties tilelon, tilelat, tileoffsetlat,
|
||||||
* tileoffsetlat, tileoffsetx, tileoffsety
|
* tileoffsetlat, tileoffsetx, tileoffsety
|
||||||
*/
|
*/
|
||||||
calculateGridLayout: function(bounds, extent, resolution) {
|
calculateGridLayout: function(bounds, origin, resolution) {
|
||||||
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 - origin.lon;
|
||||||
var tilecol = Math.floor(offsetlon/tilelon) - this.buffer;
|
var tilecol = Math.floor(offsetlon/tilelon) - this.buffer;
|
||||||
var tilecolremain = offsetlon/tilelon - tilecol;
|
var tilecolremain = offsetlon/tilelon - tilecol;
|
||||||
var tileoffsetx = -tilecolremain * this.tileSize.w;
|
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 tilerow = Math.ceil(offsetlat/tilelat) + this.buffer;
|
||||||
var tilerowremain = tilerow - offsetlat/tilelat;
|
var tilerowremain = tilerow - offsetlat/tilelat;
|
||||||
var tileoffsety = -tilerowremain * this.tileSize.h;
|
var tileoffsety = -tilerowremain * this.tileSize.h;
|
||||||
var tileoffsetlat = extent.bottom + tilerow * tilelat;
|
var tileoffsetlat = origin.lat + tilerow * tilelat;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
tilelon: tilelon, tilelat: tilelat,
|
tilelon: tilelon, tilelat: tilelat,
|
||||||
@@ -350,6 +364,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
|
* Method: initGriddedTiles
|
||||||
*
|
*
|
||||||
@@ -367,10 +407,10 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
|||||||
var minCols = Math.ceil(viewSize.w/this.tileSize.w) +
|
var minCols = Math.ceil(viewSize.w/this.tileSize.w) +
|
||||||
Math.max(1, 2 * this.buffer);
|
Math.max(1, 2 * this.buffer);
|
||||||
|
|
||||||
var extent = this.getMaxExtent();
|
var origin = this.getTileOrigin();
|
||||||
var resolution = this.map.getResolution();
|
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 tileoffsetx = Math.round(tileLayout.tileoffsetx); // heaven help us
|
||||||
var tileoffsety = Math.round(tileLayout.tileoffsety);
|
var tileoffsety = Math.round(tileLayout.tileoffsety);
|
||||||
@@ -452,7 +492,7 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
|||||||
* {OpenLayers.Bounds}
|
* {OpenLayers.Bounds}
|
||||||
*/
|
*/
|
||||||
getMaxExtent: function() {
|
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);
|
t.plan(4);
|
||||||
|
|
||||||
var dummy = new OpenLayers.Layer(null, {isBaseLayer: true});
|
var dummy = new OpenLayers.Layer(null, {isBaseLayer: true});
|
||||||
@@ -392,7 +392,7 @@
|
|||||||
var constrained = new OpenLayers.Layer.WMS(
|
var constrained = new OpenLayers.Layer.WMS(
|
||||||
null, "http://example.com/wms-c",
|
null, "http://example.com/wms-c",
|
||||||
{layers: "constrained"},
|
{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({
|
var map = new OpenLayers.Map({
|
||||||
div: "map",
|
div: "map",
|
||||||
|
|||||||
Reference in New Issue
Block a user