diff --git a/examples/tile-extent.html b/examples/tile-origin.html similarity index 76% rename from examples/tile-extent.html rename to examples/tile-origin.html index 4f69243853..cd01f09dca 100644 --- a/examples/tile-extent.html +++ b/examples/tile-origin.html @@ -1,15 +1,15 @@ - OpenLayers Tile Extent Example + OpenLayers Tile Origin Example -

Tile Extent

+

Tile Origin

- grid, tileExtent + grid, tileOrigin

Demonstrates the use of the tileExtent property to differentiate @@ -23,14 +23,14 @@

Tile Extent

a particular tile lattice. In this case, the layer's maxExtent 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 - tileExtent property. + tile origin configured on the server, use the layer's + tileOrigin property.

- View the tile-extent.js + View the tile-origin.js source to see how this is done

- + diff --git a/examples/tile-extent.js b/examples/tile-origin.js similarity index 86% rename from examples/tile-extent.js rename to examples/tile-origin.js index 953b2e1db4..61c5b8ea3e 100644 --- a/examples/tile-extent.js +++ b/examples/tile-origin.js @@ -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), diff --git a/lib/OpenLayers/Layer/Grid.js b/lib/OpenLayers/Layer/Grid.js index c31d195f0e..cc1e07372e 100644 --- a/lib/OpenLayers/Layer/Grid.js +++ b/lib/OpenLayers/Layer/Grid.js @@ -24,12 +24,26 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, { * {} */ tileSize: null, + + /** + * Property: tileOriginCorner + * {String} If the property is not provided, the tile origin + * will be derived from the layer's . The corner of the + * 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 - * {} + * APIProperty: tileOrigin + * {} 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 + * . Default is ``null``. */ - tileExtent: null, + tileOrigin: null, /** APIProperty: tileOptions * {Object} optional configuration options for 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 - {} - * extent - {} + * origin - {} * 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 + * property is supplied, that will be returned. Otherwise, the origin + * will be derived from the layer's property. In this case, + * the tile origin will be the corner of the given by the + * property. + * + * Returns: + * {} 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; }, /** diff --git a/tests/Layer/WMS.html b/tests/Layer/WMS.html index ec3e153863..f17b56a354 100644 --- a/tests/Layer/WMS.html +++ b/tests/Layer/WMS.html @@ -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",