[fusion-commits] r2728 - trunk/lib

svn_fusion at osgeo.org svn_fusion at osgeo.org
Mon Jun 3 20:57:40 PDT 2013


Author: jng
Date: 2013-06-03 20:57:39 -0700 (Mon, 03 Jun 2013)
New Revision: 2728

Modified:
   trunk/lib/Map.js
Log:
#574: Add digitizer API for circles. Unlike other digitizer functions, the callback for this one does not receive an OpenLayers.Geometry instance. It receives a basic object with x, y and r properties for center (x,y) and radius (r) respectively.

Modified: trunk/lib/Map.js
===================================================================
--- trunk/lib/Map.js	2013-05-31 04:14:40 UTC (rev 2727)
+++ trunk/lib/Map.js	2013-06-04 03:57:39 UTC (rev 2728)
@@ -133,6 +133,7 @@
     DRAW_CONTROL_LINESTR: "FusionMapDrawLineString",
     DRAW_CONTROL_RECT: "FusionMapDrawRect",
     DRAW_CONTROL_POLY: "FusionMapDrawPoly",
+    DRAW_CONTROL_CIRCLE: "FusionMapDrawCircle",
     
     /** The DOM object that holds the map */
     _oDomObj: null,
@@ -1698,8 +1699,8 @@
     },
 
     executeFromContextMenu: function(widget) {
-     //console.log('executefromcontextmenu');
-     widget.activate(this.contextMenuPosition.x, this.contextMenuPosition.y);
+        //console.log('executefromcontextmenu');
+        widget.activate(this.contextMenuPosition.x, this.contextMenuPosition.y);
     },
     _getDigitizingLayer: function() {
         var layer = this.oMapOL.getLayer(this.ID_DIGITIZING_LAYER);
@@ -1722,11 +1723,18 @@
         this._deactivateDigitizer(this.DRAW_CONTROL_LINESTR, false, true);
         this._deactivateDigitizer(this.DRAW_CONTROL_RECT, false, true);
         this._deactivateDigitizer(this.DRAW_CONTROL_POLY, false, true);
+        this._deactivateDigitizer(this.DRAW_CONTROL_CIRCLE, false, true);
         this._triggerDigitizerDeactivated();
     },
     _onGeometryDigitized: function(evt, controlId, origCallback) {
         this._deactivateDigitizer(controlId, true, true);
-        origCallback(evt.feature.geometry);
+        if (controlId == this.DRAW_CONTROL_CIRCLE) {
+            var center = evt.feature.geometry.getCentroid();
+            var radius = evt.feature.geometry.bounds.getWidth() / 2;
+            origCallback({ x: center.x, y: center.y, r: radius });
+        } else {
+            origCallback(evt.feature.geometry);
+        }
     },
     _setDigitizationPrompt: function(prompt) {
         this.message.info(prompt + ' <a id="abortDigitizationLink" href="javascript:void(0)">' + OpenLayers.i18n("stop") + '</a>');
@@ -1979,7 +1987,44 @@
             this._setDigitizationPrompt(options.prompt);
         }
         this._activateDigitizer(ctrl, this.DRAW_CONTROL_POLY, callback);
-    }
+    },
+    /**
+     * Method: digitizeCircle
+     *
+     * Digitizes a circle and passes the value to a function for processing. Digitization can be cancelled via the cancelDigitization()
+     * method or via pressing the ESC key
+     *
+     * Parameters:
+     * options - {Object} digitization options
+     * callback - {Function} The callback function that will receive the digitized circle
+     *
+     * Return:
+     * {Object} - The circle structured { x, y, r }
+     */
+    digitizeCircle: function(options, callback) {
+        if (this.isDigitizing) {
+            this.cancelDigitization();
+        }
+        var ctrl = this.oMapOL.getControl(this.DRAW_CONTROL_CIRCLE);
+        if (ctrl == null) {
+            ctrl = new OpenLayers.Control.DrawFeature(
+                this._getDigitizingLayer(),
+                OpenLayers.Handler.RegularPolygon, {
+                    id: this.DRAW_CONTROL_CIRCLE,
+                    handlerOptions: {
+                        sides: 40,
+                        layerOptions: {
+                            styleMap: this.digitizingStyleMap
+                        }
+                    }
+                });
+            this.oMapOL.addControl(ctrl);
+        }
+        if (options && options.prompt) {
+            this._setDigitizationPrompt(options.prompt);
+        }
+        this._activateDigitizer(ctrl, this.DRAW_CONTROL_CIRCLE, callback);
+    },
 });
 
 /**



More information about the fusion-commits mailing list