[OpenLayers-Commits] r11033 - in trunk/openlayers: examples lib/OpenLayers/Layer tests/Layer

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Fri Jan 14 10:56:07 EST 2011


Author: tschaub
Date: 2011-01-14 07:56:07 -0800 (Fri, 14 Jan 2011)
New Revision: 11033

Added:
   trunk/openlayers/examples/tile-origin.html
   trunk/openlayers/examples/tile-origin.js
Removed:
   trunk/openlayers/examples/tile-extent.html
   trunk/openlayers/examples/tile-extent.js
Modified:
   trunk/openlayers/lib/OpenLayers/Layer/Grid.js
   trunk/openlayers/tests/Layer/WMS.html
Log:
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).

Deleted: trunk/openlayers/examples/tile-extent.html
===================================================================
--- trunk/openlayers/examples/tile-extent.html	2011-01-14 13:28:45 UTC (rev 11032)
+++ trunk/openlayers/examples/tile-extent.html	2011-01-14 15:56:07 UTC (rev 11033)
@@ -1,36 +0,0 @@
-<!DOCTYPE html>
-<html>
-    <head>
-        <title>OpenLayers Tile Extent 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>
-        <div id="tags">
-            grid, tileExtent
-        </div>
-        <p id="shortdesc">
-            Demonstrates the use of the tileExtent property to differentiate 
-            between the maximum extent and the tile extent for a layer.
-        </p>
-        <div id="map" class="smallmap"></div>
-        <div id="docs">
-            <p>
-                This example uses a layer that requests map tiles from a WMS
-                that only generates image responses for requests that align with
-                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.
-            </p><p>
-                View the <a href="tile-extent.js" target="_blank">tile-extent.js</a>
-                source to see how this is done
-            </p>
-        </div>
-        <script src="../lib/OpenLayers.js"></script>
-        <script src="tile-extent.js"></script>
-    </body>
-</html>

Deleted: trunk/openlayers/examples/tile-extent.js
===================================================================
--- trunk/openlayers/examples/tile-extent.js	2011-01-14 13:28:45 UTC (rev 11032)
+++ trunk/openlayers/examples/tile-extent.js	2011-01-14 15:56:07 UTC (rev 11033)
@@ -1,16 +0,0 @@
-var map = new OpenLayers.Map({
-    div: "map",
-    maxExtent: new OpenLayers.Bounds(-130, 30, -80, 55),
-    maxResolution: 360 / 256 / Math.pow(2, 4),
-    numZoomLevels: 12,
-    layers: [
-        new OpenLayers.Layer.WMS(
-            "Global Imagery",
-            "http://maps.opengeo.org/geowebcache/service/wms",
-            {layers: "bluemarble"},
-            {tileExtent: new OpenLayers.Bounds(-180, -90, 180, 90)}
-        )
-    ],
-    center: new OpenLayers.LonLat(-110, 45),
-    zoom: 0
-});

Copied: trunk/openlayers/examples/tile-origin.html (from rev 11031, trunk/openlayers/examples/tile-extent.html)
===================================================================
--- trunk/openlayers/examples/tile-origin.html	                        (rev 0)
+++ trunk/openlayers/examples/tile-origin.html	2011-01-14 15:56:07 UTC (rev 11033)
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <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 Origin</h1>
+        <div id="tags">
+            grid, tileOrigin
+        </div>
+        <p id="shortdesc">
+            Demonstrates the use of the tileExtent property to differentiate 
+            between the maximum extent and the tile extent for a layer.
+        </p>
+        <div id="map" class="smallmap"></div>
+        <div id="docs">
+            <p>
+                This example uses a layer that requests map tiles from a WMS
+                that only generates image responses for requests that align with
+                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 origin configured on the server, use the layer's 
+                <code>tileOrigin</code> property.
+            </p><p>
+                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-origin.js"></script>
+    </body>
+</html>

Copied: trunk/openlayers/examples/tile-origin.js (from rev 11031, trunk/openlayers/examples/tile-extent.js)
===================================================================
--- trunk/openlayers/examples/tile-origin.js	                        (rev 0)
+++ trunk/openlayers/examples/tile-origin.js	2011-01-14 15:56:07 UTC (rev 11033)
@@ -0,0 +1,16 @@
+var map = new OpenLayers.Map({
+    div: "map",
+    maxExtent: new OpenLayers.Bounds(-130, 30, -80, 55),
+    maxResolution: 360 / 256 / Math.pow(2, 4),
+    numZoomLevels: 12,
+    layers: [
+        new OpenLayers.Layer.WMS(
+            "Global Imagery",
+            "http://maps.opengeo.org/geowebcache/service/wms",
+            {layers: "bluemarble"},
+            {tileOrigin: new OpenLayers.LonLat(-180, -90)}
+        )
+    ],
+    center: new OpenLayers.LonLat(-110, 45),
+    zoom: 0
+});

Modified: trunk/openlayers/lib/OpenLayers/Layer/Grid.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Layer/Grid.js	2011-01-14 13:28:45 UTC (rev 11032)
+++ trunk/openlayers/lib/OpenLayers/Layer/Grid.js	2011-01-14 15:56:07 UTC (rev 11033)
@@ -24,12 +24,26 @@
      * {<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 @@
 
     /** 
      * 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 @@
         };
 
     },
+    
+    /**
+     * 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 @@
         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.Bounds}
      */
     getMaxExtent: function() {
-        return this.tileExtent || this.maxExtent;
+        return this.maxExtent;
     },
     
     /**

Modified: trunk/openlayers/tests/Layer/WMS.html
===================================================================
--- trunk/openlayers/tests/Layer/WMS.html	2011-01-14 13:28:45 UTC (rev 11032)
+++ trunk/openlayers/tests/Layer/WMS.html	2011-01-14 15:56:07 UTC (rev 11033)
@@ -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",



More information about the Commits mailing list