[OpenLayers-Commits] r11799 - in sandbox/cmoullet/openlayers: . lib/OpenLayers/Handler tests/Handler

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Wed Mar 30 11:41:41 EDT 2011


Author: cmoullet
Date: 2011-03-30 08:41:40 -0700 (Wed, 30 Mar 2011)
New Revision: 11799

Modified:
   sandbox/cmoullet/openlayers/
   sandbox/cmoullet/openlayers/lib/OpenLayers/Handler/Path.js
   sandbox/cmoullet/openlayers/tests/Handler/Path.html
Log:
Merge with trunk



Property changes on: sandbox/cmoullet/openlayers
___________________________________________________________________
Modified: svn:mergeinfo
   - /sandbox/roberthl/openlayers:9745-9748
/trunk/openlayers:11161-11775,11777-11795
   + /sandbox/roberthl/openlayers:9745-9748
/trunk/openlayers:11161-11775,11777-11798

Modified: sandbox/cmoullet/openlayers/lib/OpenLayers/Handler/Path.js
===================================================================
--- sandbox/cmoullet/openlayers/lib/OpenLayers/Handler/Path.js	2011-03-30 15:30:47 UTC (rev 11798)
+++ sandbox/cmoullet/openlayers/lib/OpenLayers/Handler/Path.js	2011-03-30 15:41:40 UTC (rev 11799)
@@ -27,6 +27,15 @@
     line: null,
 
     /**
+     * APIProperty: maxVertices
+     * {Number} The maximum number of vertices which can be drawn by this
+     * handler. When the number of vertices reaches maxVertices, the
+     * geometry is automatically finalized. This property doesn't
+     * apply if freehand is set. Default is null.
+     */
+    maxVertices: null,
+
+    /**
      * Property: freehand
      * {Boolean} In freehand mode, the handler starts the path on mouse down,
      * adds a point for every mouse move, and finishes the path on mouse up.
@@ -328,6 +337,9 @@
                     }
                     this.addPoint(evt.xy);
                     this.lastUp = evt.xy;
+                    if(this.line.geometry.components.length === this.maxVertices + 1) {
+                        this.finishGeometry();
+                    }
                 }
             }
         }

Modified: sandbox/cmoullet/openlayers/tests/Handler/Path.html
===================================================================
--- sandbox/cmoullet/openlayers/tests/Handler/Path.html	2011-03-30 15:30:47 UTC (rev 11798)
+++ sandbox/cmoullet/openlayers/tests/Handler/Path.html	2011-03-30 15:41:40 UTC (rev 11799)
@@ -524,6 +524,43 @@
         map.destroy();     
     }
 
+    function test_maxVertices(t) {
+        t.plan(1);
+        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 log = {};
+        var doneCallback = function(evt) {
+            t.ok(evt, 'When maxVertices is reached, the geometry is finalized automatically');
+        };
+        var handler = new OpenLayers.Handler.Path(control, {'done': doneCallback}, {maxVertices: 2});
+        control.handler = handler;
+        map.addControl(control);
+        map.setCenter(new OpenLayers.LonLat(0, 0), 0);
+
+        // mock up feature drawing
+        handler.activate();
+        var evt = {xy: new OpenLayers.Pixel(0, 0)};
+        handler.mousemove(evt);
+        handler.mousedown(evt);
+        handler.mouseup(evt);
+        evt = {xy: new OpenLayers.Pixel(20, 20)};
+        handler.mousemove(evt);
+        handler.mousedown(evt);
+        handler.mouseup(evt);
+        evt = {xy: new OpenLayers.Pixel(40, 40)};
+        handler.mousemove(evt);
+        handler.mousedown(evt);
+        handler.mouseup(evt);
+        map.destroy();
+    }
+
     //
     // Sequence tests
     // 



More information about the Commits mailing list