[OpenLayers-Commits] r12158 - in trunk/openlayers: lib/OpenLayers tests

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Wed Jul 6 03:22:32 EDT 2011


Author: ahocevar
Date: 2011-07-06 00:22:31 -0700 (Wed, 06 Jul 2011)
New Revision: 12158

Modified:
   trunk/openlayers/lib/OpenLayers/Map.js
   trunk/openlayers/tests/Map.html
Log:
adjusting dx and dy instad of not moving the map at all when we reach the restrictedExtent. p=me,elemoine, r=elemoine (closes #3388)

Modified: trunk/openlayers/lib/OpenLayers/Map.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Map.js	2011-07-05 16:26:40 UTC (rev 12157)
+++ trunk/openlayers/lib/OpenLayers/Map.js	2011-07-06 07:22:31 UTC (rev 12158)
@@ -1674,8 +1674,6 @@
      * dy - {Number}
      */
     moveByPx: function(dx, dy) {
-        dx = Math.round(dx);
-        dy = Math.round(dy);
         var hw = this.size.w / 2;
         var hh = this.size.h / 2;
         var x = hw + dx;
@@ -1689,15 +1687,13 @@
             // wrapping the date line makes no sense for restricted extents
             wrapDateLine = false;
         }
-        var valid = y <= this.maxPx.y - yRestriction &&
-                    y >= this.minPx.y + yRestriction;
-        var minX = this.minPx.x, maxX = this.maxPx.x;
-        if (!wrapDateLine) {
-            valid = valid &&
+        dx = wrapDateLine ||
                     x <= this.maxPx.x - xRestriction &&
-                    x >= this.minPx.x + xRestriction;
-        }
-        if (valid) {
+                    x >= this.minPx.x + xRestriction ? Math.round(dx) : 0;
+        dy = y <= this.maxPx.y - yRestriction &&
+                    y >= this.minPx.y + yRestriction ? Math.round(dy) : 0;
+        var minX = this.minPx.x, maxX = this.maxPx.x;
+        if (dx || dy) {
             if (!this.dragging) {
                 this.dragging = true;
                 this.events.triggerEvent("movestart");

Modified: trunk/openlayers/tests/Map.html
===================================================================
--- trunk/openlayers/tests/Map.html	2011-07-05 16:26:40 UTC (rev 12157)
+++ trunk/openlayers/tests/Map.html	2011-07-06 07:22:31 UTC (rev 12158)
@@ -1824,6 +1824,26 @@
         map.destroy();
     }
 
+    // test for http://trac.osgeo.org/openlayers/ticket/3388
+    function test_moveByPx_restrictedExtent(t) {
+        t.plan(2);
+
+        var map = new OpenLayers.Map({
+            div: 'map',
+            restrictedExtent: new OpenLayers.Bounds(-22.5,-11.25,22.5,11.25),
+            layers: [
+                new OpenLayers.Layer('name', {isBaseLayer: true})
+            ]
+        });
+
+        map.zoomToExtent(new OpenLayers.Bounds(-11.25, 0, 11.25, 11.25));
+
+        map.moveByPx(-10, -10);
+        t.eq(map.layerContainerDiv.style.left, '10px', 'layer container left correct');
+        t.eq(map.layerContainerDiv.style.top, '0px', 'layer container top correct');
+    }
+
+
   </script>
 </head>
 <body>



More information about the Commits mailing list