[OpenLayers-Commits] r10820 - in sandbox/tschaub/donut: examples lib/OpenLayers/Handler

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Mon Oct 11 18:37:37 EDT 2010


Author: tschaub
Date: 2010-10-11 15:37:36 -0700 (Mon, 11 Oct 2010)
New Revision: 10820

Modified:
   sandbox/tschaub/donut/examples/donut.html
   sandbox/tschaub/donut/examples/donut.js
   sandbox/tschaub/donut/lib/OpenLayers/Handler/Polygon.js
Log:
Re-trigger sketchcomplete so other listeners can be notified when interior ring drawing completes.

Modified: sandbox/tschaub/donut/examples/donut.html
===================================================================
--- sandbox/tschaub/donut/examples/donut.html	2010-10-11 22:13:13 UTC (rev 10819)
+++ sandbox/tschaub/donut/examples/donut.html	2010-10-11 22:37:36 UTC (rev 10820)
@@ -12,6 +12,10 @@
                 font-size: 9px;
                 bottom: 2px;
             }
+            #output {
+                margin: 1em;
+                font-size: 0.9em;
+            }
         </style>
     </head>
     <body>
@@ -35,7 +39,7 @@
                 <label for="polygonToggle">draw polygon</label>
             </li>
         </ul>
-        
+        <div id="output"></div>
         <div id="docs">
             <p>
                 To digitize holes in polygons, hold down the <code>Alt</code> 

Modified: sandbox/tschaub/donut/examples/donut.js
===================================================================
--- sandbox/tschaub/donut/examples/donut.js	2010-10-11 22:13:13 UTC (rev 10819)
+++ sandbox/tschaub/donut/examples/donut.js	2010-10-11 22:37:36 UTC (rev 10820)
@@ -15,6 +15,17 @@
 );
 map.addControl(draw);
 
+// optionally listen for sketch events on the layer
+map.layers[1].events.on({
+    sketchmodified: function(event) {
+        document.getElementById("output").innerHTML = "modified " + event.feature.id;
+    },
+    sketchcomplete: function(event) {
+        document.getElementById("output").innerHTML = "completed " + event.feature.id;
+    }
+})
+
+// add behavior to UI elements
 function toggleControl(element) {
     if (element.value === "polygon" && element.checked) {
         draw.activate();
@@ -22,5 +33,4 @@
         draw.deactivate();
     }
 }
-
 document.getElementById("noneToggle").checked = true;
\ No newline at end of file

Modified: sandbox/tschaub/donut/lib/OpenLayers/Handler/Polygon.js
===================================================================
--- sandbox/tschaub/donut/lib/OpenLayers/Handler/Polygon.js	2010-10-11 22:13:13 UTC (rev 10819)
+++ sandbox/tschaub/donut/lib/OpenLayers/Handler/Polygon.js	2010-10-11 22:37:36 UTC (rev 10820)
@@ -190,7 +190,7 @@
     cancel: function() {
         if (this.drawingHole) {
             this.polygon.geometry.removeComponent(this.line.geometry);
-            this.restoreFeature();
+            this.restoreFeature(true);
         }
         return OpenLayers.Handler.Path.prototype.cancel.apply(this, arguments);
     },
@@ -198,8 +198,12 @@
     /**
      * Method: restoreFeature
      * Move the feature from the sketch layer to the target layer.
+     *
+     * Properties: 
+     * cancel - {Boolean} Cancel drawing.  If falsey, the "sketchcomplete" event
+     *     will be fired.
      */
-    restoreFeature: function() {
+    restoreFeature: function(cancel) {
         this.control.layer.events.unregister(
             "sketchcomplete", this, this.finalizeInteriorRing
         );
@@ -208,7 +212,19 @@
         );
         this.layer.removeFeatures([this.polygon], {silent: true});
         this.control.layer.addFeatures([this.polygon], {silent: true});
-        this.drawingHole = false;        
+        this.drawingHole = false;
+        if (!cancel) {
+            // Re-trigger "sketchcomplete" so other listeners can do their
+            // business.  While this is somewhat sloppy (if a listener is 
+            // registered with registerPriority - not common - between the start
+            // and end of a single ring drawing - very uncommon - it will be 
+            // called twice).
+            // TODO: In 3.0, collapse sketch handlers into geometry specific
+            // drawing controls.
+            this.control.layer.events.triggerEvent(
+                "sketchcomplete", {feature : this.polygon}
+            );
+        }
     },
 
     /**



More information about the Commits mailing list