[OpenLayers-Commits] r3911 - in sandbox/camptocamp/feature: lib/OpenLayers lib/OpenLayers/Control lib/OpenLayers/Layer tests tests/Control tests/Format tests/Handler

commits at openlayers.org commits at openlayers.org
Mon Aug 20 09:18:59 EDT 2007


Author: pgiraud
Date: 2007-08-20 09:18:58 -0400 (Mon, 20 Aug 2007)
New Revision: 3911

Modified:
   sandbox/camptocamp/feature/lib/OpenLayers/Control/DragPan.js
   sandbox/camptocamp/feature/lib/OpenLayers/Control/LayerSwitcher.js
   sandbox/camptocamp/feature/lib/OpenLayers/Handler.js
   sandbox/camptocamp/feature/lib/OpenLayers/Layer/Grid.js
   sandbox/camptocamp/feature/tests/Control/test_DragPan.html
   sandbox/camptocamp/feature/tests/Format/test_XML.html
   sandbox/camptocamp/feature/tests/Handler/test_Drag.html
   sandbox/camptocamp/feature/tests/test_Handler.html
Log:
merge r3882:HEAD from trunk

Modified: sandbox/camptocamp/feature/lib/OpenLayers/Control/DragPan.js
===================================================================
--- sandbox/camptocamp/feature/lib/OpenLayers/Control/DragPan.js	2007-08-20 12:12:45 UTC (rev 3910)
+++ sandbox/camptocamp/feature/lib/OpenLayers/Control/DragPan.js	2007-08-20 13:18:58 UTC (rev 3911)
@@ -21,51 +21,51 @@
     type: OpenLayers.Control.TYPE_TOOL,
     
     /**
+     * Property: panned
+     * {Boolean} The map moved.
+     */
+    panned: false,
+    
+    /**
      * Method: draw
      * Creates a Drag handler, using <OpenLayers.Control.PanMap.panMap> and
      * <OpenLayers.Control.PanMap.panMapDone> as callbacks.
      */    
     draw: function() {
-        this.handler = new OpenLayers.Handler.Drag( this,
-                            {"move": this.panMap, "up": this.panMapDone } );
+        this.handler = new OpenLayers.Handler.Drag(this,
+                            {"move": this.panMap, "done": this.panMapDone});
     },
 
     /**
     * Method: panMap
     *
     * Parameters:
-    * xy - {<OpenLayers.Pixel>} Pixel of the up position
+    * xy - {<OpenLayers.Pixel>} Pixel of the mouse position
     */
-    panMap: function (xy) {
-        var deltaX = this.handler.start.x - xy.x;
-        var deltaY = this.handler.start.y - xy.y;
+    panMap: function(xy) {
+        this.panned = true;
+        var deltaX = this.handler.last.x - xy.x;
+        var deltaY = this.handler.last.y - xy.y;
         var size = this.map.getSize();
         var newXY = new OpenLayers.Pixel(size.w / 2 + deltaX,
                                          size.h / 2 + deltaY);
-        var newCenter = this.map.getLonLatFromViewPortPx( newXY ); 
-        this.map.setCenter(newCenter, null, true);
-        // this assumes xy won't be changed inside Handler.Drag
-        // a safe bet for now, and saves us the extra call to clone().
-        this.handler.start = xy;
+        var newCenter = this.map.getLonLatFromViewPortPx( newXY );
+        this.map.setCenter(newCenter, null, this.handler.dragging);
     },
     
     /**
-    * Method: panMapDone
-    * 
-    * Parameters:
-    * xy - {<OpenLayers.Pixel>} Pixel of the up position
-    */
-    panMapDone: function (xy) {
-        var deltaX = this.handler.start.x - xy.x;
-        var deltaY = this.handler.start.y - xy.y;
-        var size = this.map.getSize();
-        var newXY = new OpenLayers.Pixel(size.w / 2 + deltaX,
-                                         size.h / 2 + deltaY);
-        var newCenter = this.map.getLonLatFromViewPortPx( newXY ); 
-        this.map.setCenter(newCenter, null, false);
-        // this assumes xy won't be changed inside Handler.Drag
-        // a safe bet for now, and saves us the extra call to clone().
-        this.handler.start = xy;
+     * Method: panMapDone
+     * Finish the panning operation.  Only call setCenter (through <panMap>)
+     *     if the map has actually been moved.
+     *
+     * Parameters:
+     * xy - {<OpenLayers.Pixel>} Pixel of the mouse position
+     */
+    panMapDone: function(xy) {
+        if(this.panned) {
+            this.panMap(xy);
+            this.panned = false;
+        }
     },
 
     CLASS_NAME: "OpenLayers.Control.DragPan"

Modified: sandbox/camptocamp/feature/lib/OpenLayers/Control/LayerSwitcher.js
===================================================================
--- sandbox/camptocamp/feature/lib/OpenLayers/Control/LayerSwitcher.js	2007-08-20 12:12:45 UTC (rev 3910)
+++ sandbox/camptocamp/feature/lib/OpenLayers/Control/LayerSwitcher.js	2007-08-20 13:18:58 UTC (rev 3911)
@@ -535,13 +535,13 @@
      * evt - {Event}
      */
     mouseDown: function(evt) {
-        this.mouseDown = true;
+        this.isMouseDown = true;
         this.ignoreEvent(evt);
     },
 
     /** 
      * Method: mouseUp
-     * If the 'mouseDown' flag has been set, that means that the drag was 
+     * If the 'isMouseDown' flag has been set, that means that the drag was 
      *   started from within the LayerSwitcher control, and thus we can 
      *   ignore the mouseup. Otherwise, let the Event continue.
      *  
@@ -549,8 +549,8 @@
      * evt - {Event} 
      */
     mouseUp: function(evt) {
-        if (this.mouseDown) {
-            this.mouseDown = false;
+        if (this.isMouseDown) {
+            this.isMouseDown = false;
             this.ignoreEvent(evt);
         }
     },

Modified: sandbox/camptocamp/feature/lib/OpenLayers/Handler.js
===================================================================
--- sandbox/camptocamp/feature/lib/OpenLayers/Handler.js	2007-08-20 12:12:45 UTC (rev 3910)
+++ sandbox/camptocamp/feature/lib/OpenLayers/Handler.js	2007-08-20 13:18:58 UTC (rev 3911)
@@ -214,8 +214,10 @@
      * Deconstruct the handler.
      */
     destroy: function () {
+        // unregister event listeners
+        this.deactivate();
         // eliminate circular references
-        this.control = this.map = null;
+        this.control = this.map = null;        
     },
 
     CLASS_NAME: "OpenLayers.Handler"
@@ -245,3 +247,4 @@
  */
 OpenLayers.Handler.MOD_ALT   = 4;
 
+

Modified: sandbox/camptocamp/feature/lib/OpenLayers/Layer/Grid.js
===================================================================
--- sandbox/camptocamp/feature/lib/OpenLayers/Layer/Grid.js	2007-08-20 12:12:45 UTC (rev 3910)
+++ sandbox/camptocamp/feature/lib/OpenLayers/Layer/Grid.js	2007-08-20 13:18:58 UTC (rev 3911)
@@ -28,6 +28,15 @@
      */
     grid: null,
 
+    /**
+     * APIProperty: singleTile
+     * {Boolean} Moves the layer into single-tile mode, meaning that one tile 
+     *     will be loaded. The tile's size will be determined by the 'ratio'
+     *     property. When the tile is dragged such that it does not cover the 
+     *     entire viewport, it is reloaded.
+     */
+    singleTile: false,
+
     /** APIProperty: ratio
      *  {Float} Used only when in single-tile mode, this specifies the 
      *          ratio of the size of the single tile to the size of the map.

Modified: sandbox/camptocamp/feature/tests/Control/test_DragPan.html
===================================================================
--- sandbox/camptocamp/feature/tests/Control/test_DragPan.html	2007-08-20 12:12:45 UTC (rev 3910)
+++ sandbox/camptocamp/feature/tests/Control/test_DragPan.html	2007-08-20 13:18:58 UTC (rev 3911)
@@ -2,13 +2,76 @@
 <head>
   <script src="../../lib/OpenLayers.js"></script>
   <script type="text/javascript"><!--
-    var map; 
+    var map, control, layer; 
+
+    function init_map() {
+        control = new OpenLayers.Control.DragPan();
+        map = new OpenLayers.Map("map", {controls:[control]});
+        layer = new OpenLayers.Layer.WMS( "OpenLayers WMS", 
+                    "http://labs.metacarta.com/wms/vmap0",
+                    {layers: 'basic'} );
+        map.addLayer(layer); 
+        map.zoomToMaxExtent();
+        map.zoomIn();
+        control.activate();
+        return [map, control];
+    }    
     function test_Control_DragPan_constructor (t) {
         t.plan( 1 );
     
         control = new OpenLayers.Control.DragPan();
         t.ok( control instanceof OpenLayers.Control.DragPan, "new OpenLayers.Control returns object" );
     }
+    function test_Control_DragPan_drag (t) {
+        t.plan(4);
+        var data = init_map();
+        map = data[0]; control = data[1];
+        res = map.baseLayer.resolutions[map.getZoom()];
+        t.eq(map.center.lat, 0, "Lat is 0 before drag");
+        t.eq(map.center.lon, 0, "Lon is 0 before drag");
+        map.events.triggerEvent('mousedown', {'type':'mousedown', 'xy':new OpenLayers.Pixel(0,0), 'which':1});
+        map.events.triggerEvent('mousemove', {'type':'mousemove', 'xy':new OpenLayers.Pixel(5,5), 'which':1});
+        map.events.triggerEvent('mouseup', {'type':'mouseup', 'xy':new OpenLayers.Pixel(5,5), 'which':1});
+        
+        t.eq(map.getCenter().lat, res * 5, "Lat is " + (res * 5) + " after drag");
+        t.eq(map.getCenter().lon, res * -5, "Lon is " + (res * -5) + " after drag");
+    }
+    function test_Control_DragPan_click(t) {
+        t.plan(1);
+        var control = new OpenLayers.Control.DragPan();
+        var map = new OpenLayers.Map("map", {controls:[control]});
+        var layer = new OpenLayers.Layer.WMS("OpenLayers WMS", 
+                                        "http://labs.metacarta.com/wms/vmap0",
+                                        {layers: 'basic'});
+        map.addLayer(layer); 
+        map.zoomToMaxExtent();
+        map.zoomIn();
+        control.activate();
+        map.setCenter = function() {
+            t.ok(false, "map.setCenter should not be called here");
+        };
+        var xy = new OpenLayers.Pixel(0, 0);
+        var down = {
+            'type': 'mousedown',
+            'xy': xy,
+            'which': 1
+        };
+        var move = {
+            'type': 'mousemove',
+            'xy': xy,
+            'which': 1
+        };
+        var up = {
+            'type': 'mouseup',
+            'xy': xy,
+            'which': 1
+        };
+        map.events.triggerEvent('mousedown', down);
+        map.events.triggerEvent('mousemove', move);
+        map.events.triggerEvent('mouseup', up);
+        t.ok(true, "clicking without moving the mouse does not call setCenter");
+    }
+    
   // -->
   </script>
 </head>

Modified: sandbox/camptocamp/feature/tests/Format/test_XML.html
===================================================================
--- sandbox/camptocamp/feature/tests/Format/test_XML.html	2007-08-20 12:12:45 UTC (rev 3910)
+++ sandbox/camptocamp/feature/tests/Format/test_XML.html	2007-08-20 13:18:58 UTC (rev 3911)
@@ -18,7 +18,7 @@
         '<' + '/ol:root>';
 
     function test_Format_XML_constructor(t) { 
-        t.plan(window.ActiveXObject ? 5 : 4); 
+        t.plan(5); 
          
         var options = {'foo': 'bar'}; 
         var format = new OpenLayers.Format.XML(options); 
@@ -27,10 +27,8 @@
         t.eq(format.foo, "bar", "constructor sets options correctly"); 
         t.eq(typeof format.read, "function", "format has a read function"); 
         t.eq(typeof format.write, "function", "format has a write function");
-        
-        if(format.xmldom) {
-            t.ok(true, "format only has xmldom in browsers with ActiveX");
-        }
+
+        t.ok(!window.ActiveXObject || format.xmldom, "browsers with activeX must have xmldom");
     }
     
     function test_Format_XML_read(t) {

Modified: sandbox/camptocamp/feature/tests/Handler/test_Drag.html
===================================================================
--- sandbox/camptocamp/feature/tests/Handler/test_Drag.html	2007-08-20 12:12:45 UTC (rev 3910)
+++ sandbox/camptocamp/feature/tests/Handler/test_Drag.html	2007-08-20 13:18:58 UTC (rev 3911)
@@ -83,7 +83,7 @@
     }
 
     function test_Handler_Drag_callbacks(t) {
-        t.plan(25);
+        t.plan(30);
         
         var map = new OpenLayers.Map('map', {controls: []});
 
@@ -141,6 +141,12 @@
         map.events.triggerEvent("mousedown", testEvents.down);
         t.ok(handler.started, "mousedown sets the started flag to true");
         t.ok(!handler.dragging, "mouse down sets the dragging flag to false");
+        t.ok(handler.start.x == testEvents.down.xy.x &&
+             handler.start.y == testEvents.down.xy.y,
+             "mouse down sets handler.start correctly");
+        t.ok(handler.last.x == testEvents.down.xy.x &&
+             handler.last.y == testEvents.down.xy.y,
+             "mouse down sets handler.last correctly");
         OpenLayers.Event.isLeftClick = oldIsLeftClick;
         OpenLayers.Event.stop = oldStop;
         handler.checkModifiers = oldCheckModifiers;
@@ -156,7 +162,23 @@
         handler.started = true;
         map.events.triggerEvent("mousemove", testEvents.move);
         t.ok(handler.dragging, "mousemove sets the dragging flag to true");
+        t.ok(handler.start.x == testEvents.down.xy.x &&
+             handler.start.y == testEvents.down.xy.y,
+             "mouse move leaves handler.start alone");
+        t.ok(handler.last.x == testEvents.move.xy.x &&
+             handler.last.y == testEvents.move.xy.y,
+             "mouse move sets handler.last correctly");
         
+        // a second move with the same evt.xy should not trigger move callback
+        // if it does, the test page will complain about a bad plan number
+        var oldMove = handler.callbacks.move;
+        handler.callbacks.move = function() {
+            t.ok(false,
+                 "a second move with the same evt.xy should not trigger a move callback");
+        }
+        map.events.triggerEvent("mousemove", testEvents.move);
+        handler.callbacks.move = oldMove;
+        
         // test mouseup
         handler.started = false;
         map.events.triggerEvent("mouseup", {xy: {x: null, y: null}});
@@ -170,6 +192,7 @@
         testEvents.done = testEvents.up;
         map.events.triggerEvent("mouseup", testEvents.up);
         t.ok(!this.started, "mouseup sets the started flag to false");
+        t.ok(!this.dragging, "mouseup sets the dragging flag to false");
         
         // test mouseout
         handler.started = false;

Modified: sandbox/camptocamp/feature/tests/test_Handler.html
===================================================================
--- sandbox/camptocamp/feature/tests/test_Handler.html	2007-08-20 12:12:45 UTC (rev 3910)
+++ sandbox/camptocamp/feature/tests/test_Handler.html	2007-08-20 13:18:58 UTC (rev 3911)
@@ -104,11 +104,15 @@
     }
     
     function test_Handler_destroy(t) {
-        t.plan(4);
+        t.plan(5);
         var map = new OpenLayers.Map('map');
         var control = new OpenLayers.Control();
         map.addControl(control);
         var handler = new OpenLayers.Handler(control);
+        var deactivated = false;
+        handler.deactivate = function() {
+            deactivated = true;
+        };
         t.ok(handler.control,
              "handler has a control prior to destroy");
         t.ok(handler.map,
@@ -118,6 +122,8 @@
              "hanlder.control is null after destroy");
         t.eq(handler.map, null,
              "handler.map is null after destroy");
+        t.ok(deactivated,
+             "handler.deactivate is called by destroy");
     }
     
     function test_Handler_checkModifiers(t) {



More information about the Commits mailing list