[OpenLayers-Commits] r12280 - sandbox/camptocamp/clientzoom/lib/OpenLayers/Layer

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Mon Aug 29 04:29:35 EDT 2011


Author: erilem
Date: 2011-08-29 01:29:34 -0700 (Mon, 29 Aug 2011)
New Revision: 12280

Modified:
   sandbox/camptocamp/clientzoom/lib/OpenLayers/Layer/Grid.js
Log:
load tiles before applying "client zoom", panning still does not work when the layer div has been scaled

Modified: sandbox/camptocamp/clientzoom/lib/OpenLayers/Layer/Grid.js
===================================================================
--- sandbox/camptocamp/clientzoom/lib/OpenLayers/Layer/Grid.js	2011-08-25 20:55:04 UTC (rev 12279)
+++ sandbox/camptocamp/clientzoom/lib/OpenLayers/Layer/Grid.js	2011-08-29 08:29:34 UTC (rev 12280)
@@ -221,38 +221,13 @@
      */
     moveTo:function(bounds, zoomChanged, dragging) {
 
-        // if we know the server doesn't support the new resolution
-        // we apply "client zoom", that is transform the layer div,
-        // and return
+        var resolution = this.map.getResolution(),
+            availableResolution = this.getAvailableResolution();
 
-        var resolution = this.map.getResolution();
-        if(this.serverResolutions && OpenLayers.Util.indexOf(
-                               this.serverResolutions, resolution) === -1) {
-                //
-                // TODO
-                // - we should have a better way to find the base resolution,
-                //   currently we only support the case where non-supported
-                //   resolutions are at the end of the resolutions array.
-                // - verify whether HTTPRequest.moveTo should be called here
-                //   too
-                //
-
-            if(zoomChanged) {
-                var baseResolution = this.serverResolutions[
-                                         this.serverResolutions.length-1];
-                this.transformDiv(resolution, baseResolution);
-            }
-
-            return;
+        if(resolution !== availableResolution) {
+            bounds = this.map.calculateBounds(null, availableResolution);
         }
 
-        // reset the layer width, height, left, top, to deal with
-        // the case where the layer has been transformDivd
-        this.div.style.width = '100%';
-        this.div.style.height = '100%';
-        this.div.style.left = '0%';
-        this.div.style.top = '0%';
-
         OpenLayers.Layer.HTTPRequest.prototype.moveTo.apply(this, arguments);
         
         bounds = bounds || this.map.getExtent();
@@ -288,26 +263,69 @@
                 }
             }
         }
+
+        if(resolution !== availableResolution) {
+            if(zoomChanged) {
+                // apply "client zoom"
+                var scale = availableResolution / resolution;
+                this.transformDiv(scale);
+            }
+        } else {
+            // reset the layer width, height, left, top, to deal with
+            // the case where the layer has been transformDivd
+            this.div.style.width = '100%';
+            this.div.style.height = '100%';
+            this.div.style.left = '0%';
+            this.div.style.top = '0%';
+        }
     },
 
     /**
+     * Method: getAvailableResolution
+     * Return the server-supported resolution that is the closest to
+     *     the resolution passed as a parameter. If no resolution is
+     *     passed the map resolution is used.
+     *
+     * Parameters:
+     * resolution - {Number} The base resolution.
+     *
+     * Returns:
+     * {Number} The closest available resolution.
+     */
+    getAvailableResolution: function(resolution) {
+        resolution = resolution || this.map.getResolution();
+        if(this.serverResolutions &&
+           OpenLayers.Util.indexOf(this.serverResolutions, resolution) === -1) {
+            var i, serverResolution;
+            for(var i=this.serverResolutions.length-1; i>= 0; i--) {
+                serverResolution = this.serverResolutions[i];
+                if(serverResolution > resolution) {
+                    resolution = serverResolution;
+                    break;
+                }
+            }
+            if(i === -1) {
+                throw 'no appropriate resolution in serverResolutions';
+            }
+        }
+        return resolution;
+    },
+
+    /**
      * Method: transformDiv
      * Transform the layer div.
      *
      * Parameters:
-     * resolution - {Number} The target resolution.
-     * baseResolution - {Number} The base resolution.
+     * scale - {Number} The value by which the layer div is to
+     *     be scaled.
      */
-    transformDiv: function(resolution, baseResolution) {
+    transformDiv: function(scale) {
 
         //
         // TODO
-        // - transformDiv generates an error if the grid isn't initialized yet
         // - serverResolutions should be documented
         //
 
-        var scale = baseResolution / resolution;
-
         // scale the layer div
 
         this.div.style.width = 100 * scale + '%';
@@ -342,6 +360,7 @@
     moveByPx: function(dx, dy) {
         // do not move schedule move of gridded tiles if in single
         // tile or client zoom mode
+        // FIXME this must be fixed
         var resolution = this.map.getResolution();
         if (!this.singleTile &&
             (!this.serverResolutions ||
@@ -549,7 +568,7 @@
                       Math.max(1, 2 * this.buffer);
         
         var origin = this.getTileOrigin();
-        var resolution = this.map.getResolution();
+        var resolution = this.getAvailableResolution();
         
         var tileLayout = this.calculateGridLayout(bounds, origin, resolution);
 
@@ -816,7 +835,7 @@
         var grid = this.grid;
         var modelRow = grid[modelRowIndex];
 
-        var resolution = this.map.getResolution();
+        var resolution = this.getAvailableResolution();
         var deltaY = (prepend) ? -this.tileSize.h : this.tileSize.h;
         var deltaLat = resolution * -deltaY;
 
@@ -849,7 +868,7 @@
      */
     shiftColumn: function(prepend) {
         var deltaX = (prepend) ? -this.tileSize.w : this.tileSize.w;
-        var resolution = this.map.getResolution();
+        var resolution = this.getAvailableResolution();
         var deltaLon = resolution * deltaX;
 
         for (var i=0, len=this.grid.length; i<len; i++) {



More information about the Commits mailing list