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

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Tue Aug 16 22:13:07 EDT 2011


Author: tschaub
Date: 2011-08-16 19:13:06 -0700 (Tue, 16 Aug 2011)
New Revision: 12253

Modified:
   trunk/openlayers/lib/OpenLayers/Handler/Path.js
   trunk/openlayers/tests/Handler/Path.html
Log:
Making freehand drawing work on touch devices.  Thanks jorix for the excellent patch. r=me (closes #3456)

Modified: trunk/openlayers/lib/OpenLayers/Handler/Path.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Handler/Path.js	2011-08-17 01:07:59 UTC (rev 12252)
+++ trunk/openlayers/lib/OpenLayers/Handler/Path.js	2011-08-17 02:13:06 UTC (rev 12253)
@@ -417,6 +417,10 @@
         var stopDown = this.stopDown;
         if(this.freehandMode(evt)) {
             stopDown = true;
+            if (this.touch) {
+                this.modifyFeature(evt.xy, !!this.lastUp);
+                OpenLayers.Event.stop(evt);
+            }
         }
         if (!this.touch && (!this.lastDown ||
                             !this.passesTolerance(this.lastDown, evt.xy,

Modified: trunk/openlayers/tests/Handler/Path.html
===================================================================
--- trunk/openlayers/tests/Handler/Path.html	2011-08-17 01:07:59 UTC (rev 12252)
+++ trunk/openlayers/tests/Handler/Path.html	2011-08-17 02:13:06 UTC (rev 12253)
@@ -1301,6 +1301,81 @@
         
         map.destroy();
     }
+
+    function test_set_freehand(t) {
+        t.plan(5);
+        var map = new OpenLayers.Map("map", {
+            resolutions: [1]
+        });
+        var layer = new OpenLayers.Layer.Vector("foo", {
+            maxExtent: new OpenLayers.Bounds(-10, -10, 10, 10),
+            isBaseLayer: true
+        });
+        map.addLayer(layer);
+        var control = new OpenLayers.Control({});
+
+        var geo, pointsCount;        
+        var handler = new OpenLayers.Handler.Path(control, {
+                done: function(g) {
+                    geo = g;
+                },
+                point: function() {
+                    pointsCount++;
+                }
+            },
+            {freehand: true}
+        );
+        control.handler = handler;
+        map.addControl(control);
+        map.setCenter(new OpenLayers.LonLat(0, 0), 0);
+
+        handler.activate();
+
+        geo = null;
+        pointsCount = 0;
+        // Using mouse events
+        handler.mousemove(
+                {type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+        handler.mousedown(
+                {type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
+        handler.mousemove(
+                {type: "mousemove", xy: new OpenLayers.Pixel(1, 1)});
+        handler.mousemove(
+                {type: "mousemove", xy: new OpenLayers.Pixel(2, 2)});
+        handler.mouseup(
+                {type: "mouseup", xy: new OpenLayers.Pixel(2, 2)});
+        t.ok(geo != null, "feature drawn when mouseup");
+        t.eq(pointsCount, 2, "two points have been added");
+
+        handler.deactivate();
+        var geoMouse = geo;
+        
+        handler.activate();
+        
+        geo = null;
+        pointsCount = 0;
+        // Using touch events
+        handler.touchstart(
+                {type: "touchstart", xy: new OpenLayers.Pixel(0, 0)});
+        try {
+            handler.touchmove(
+                    {type: "touchmove", xy: new OpenLayers.Pixel(1, 1)});
+            handler.touchmove(
+                    {type: "touchmove", xy: new OpenLayers.Pixel(2, 2)});
+            handler.touchend(
+                    {type: "touchend"});
+        } catch(err) {
+            t.fail("occurred errors using touch events");
+        }
+        t.ok(geo != null, "feature drawn when touchend");
+        t.eq(pointsCount, 2, "two points have been added");
+        
+        t.geom_eq(geo, geoMouse, 
+            "geometry obtained using the mouse and touch events are the same");
+
+        map.destroy();
+    }
+
   </script>
 </head>
 <body>



More information about the Commits mailing list