[fusion-commits] r1370 - trunk/widgets

svn_fusion at osgeo.org svn_fusion at osgeo.org
Thu Apr 10 13:24:30 EDT 2008


Author: madair
Date: 2008-04-10 13:24:30 -0400 (Thu, 10 Apr 2008)
New Revision: 1370

Modified:
   trunk/widgets/SelectRadius.js
   trunk/widgets/SelectRadiusValue.js
Log:
closes #49: radius units are the same as map units, disable SelectRadiusValue when SelectRadius is not activated

Modified: trunk/widgets/SelectRadius.js
===================================================================
--- trunk/widgets/SelectRadius.js	2008-04-09 17:50:36 UTC (rev 1369)
+++ trunk/widgets/SelectRadius.js	2008-04-10 17:24:30 UTC (rev 1370)
@@ -29,12 +29,13 @@
  * perform a selection by radius from a point
  * 
  * **********************************************************************/
+Fusion.Event.RADIUS_WIDGET_ACTIVATED = Fusion.Event.lastEventId++;
 
 Fusion.Widget.SelectRadius = Class.create();
 Fusion.Widget.SelectRadius.prototype = {
     selectionType: 'INTERSECTS',
     nTolerance : 3, //default pixel tolernace for a point click
-    defaultRadius: 20,
+    defaultRadius: 20,    //this is in map units
     initialize : function(widgetTag) {
         //console.log('Select.initialize');
         Object.inheritFrom(this, Fusion.Widget.prototype, [widgetTag, true]);
@@ -42,6 +43,7 @@
         Object.inheritFrom(this, Fusion.Tool.Canvas.prototype, []);
         
         this.asCursor = ['auto'];
+        this.isDigitizing = false;
 
         var json = widgetTag.extension;
         this.selectionType = json.SelectionType ? json.SelectionType[0] : 'INTERSECTS';
@@ -70,6 +72,8 @@
                 this.radiusTip.style.zIndex = 101;
             }
         }
+        
+        this.registerEventID(Fusion.Event.RADIUS_WIDGET_ACTIVATED);
     },
     
     setRadius: function(r) {
@@ -107,6 +111,7 @@
         }
         /*map units for tool tip*/
         this.units = this.getMap().getAllMaps()[0].units;
+        this.triggerEvent(Fusion.Event.RADIUS_WIDGET_ACTIVATED, true);
     },
 
     /**
@@ -115,10 +120,11 @@
      * as a widget in the map
      **/
     deactivate : function() {
-         this.deactivateCanvas();
-         this.getMap().setCursor('auto');
-         /*icon button*/
-         this._oButton.deactivateTool();
+        this.deactivateCanvas();
+        this.getMap().setCursor('auto');
+        /*icon button*/
+        this._oButton.deactivateTool();
+        this.triggerEvent(Fusion.Event.RADIUS_WIDGET_ACTIVATED, false);
     },
     
     /**
@@ -129,11 +135,11 @@
      * @param e Event the event that happened on the mapObj
      */
     mouseDown: function(e) {
-        //console.log('SelectRadius.mouseDown');
+        //console.log('SelectRadius.mouseDown'+this.isDigitizing);
         if (Event.isLeftClick(e)) {
             var p = this.getMap().getEventPosition(e);
             var point = this.getMap().pixToGeo(p.x, p.y);
-            var radius = this.getMap().pixToGeoMeasure(this.defaultRadius);
+            var radius = this.defaultRadius;
             
             if (!this.isDigitizing) {
                 this.circle.setCenter(point.x, point.y);
@@ -148,7 +154,7 @@
             var size = Element.getDimensions(this.radiusTip);
             this.radiusTip.style.top = (p.y - size.height*2) + 'px';
             this.radiusTip.style.left = p.x + 'px';
-            var r = this.getMap().pixToGeoMeasure(this.circle.radius);
+            var r = this.circle.radius;
             if (this.units == 'm' || this.units == 'ft') {
                 r = Math.round(r * 100)/100;
             }
@@ -164,7 +170,7 @@
      * @param e Event the event that happened on the mapObj
      */
     mouseMove: function(e) {
-        //console.log('SelectRadius.mouseMove');
+        //console.log('SelectRadius.mouseMove'+this.isDigitizing);
         if (!this.isDigitizing) {
             return;
         }
@@ -175,7 +181,7 @@
         var center = this.circle.center;
         
         var radius = Math.sqrt(Math.pow(center.x-point.x,2) + Math.pow(center.y-point.y,2));
-        if (map.geoToPixMeasure(radius) > this.nTolerance) {
+        if (radius > this.nTolerance) {
             this.circle.setRadius(radius);
         }
         this.clearContext();
@@ -186,7 +192,7 @@
             var size = Element.getDimensions(this.radiusTip);
             this.radiusTip.style.top = (p.y - size.height*2) + 'px';
             this.radiusTip.style.left = p.x + 'px';
-            var r = map.pixToGeoMeasure(this.circle.radius);
+            var r = this.circle.radius;
             if (this.units == 'm' || this.units == 'ft') {
                 r = Math.round(r * 100)/100;
             }
@@ -196,9 +202,9 @@
     },
     
     mouseUp: function(e) {
+        //console.log('SelectRadius.mouseUp'+this.isDigitizing);
         if (this.isDigitizing) {
             this.event = e;
-            //this.circle.draw(this.context);
             this.clearContext();
             this.isDigitizing = false;
             var center = this.circle.center;

Modified: trunk/widgets/SelectRadiusValue.js
===================================================================
--- trunk/widgets/SelectRadiusValue.js	2008-04-09 17:50:36 UTC (rev 1369)
+++ trunk/widgets/SelectRadiusValue.js	2008-04-10 17:24:30 UTC (rev 1370)
@@ -47,15 +47,16 @@
         this.label = json.Label ? json.Label[0] : '';
         this.className = json.ClassName ? json.ClassName[0] : '';
         
-        /* a container for the widget */
-        //this.domObj = document.createElement('div');
-        //this.domObj.className = this.className;
-        
+        this.getMap().registerForEvent(Fusion.Event.MAP_LOADED, this.mapLoaded.bind(this));
+        this.getMap().registerForEvent(Fusion.Event.MAP_EXTENTS_CHANGED, this.mapExtentsChanged.bind(this));
+    },
+    
+    draw: function() {
         /* put in the label */
+        var units = this.getMap().getAllMaps()[0].units;
         this.domLabel = document.createElement('label');
         this.domLabel.className = this.className;
-        this.domLabel.innerHTML = this.label;
-        //this.domObj.appendChild(label);
+        this.domLabel.innerHTML = this.label + '(' + units + ')';
         
         /* put in the input */
         this.input = document.createElement('input');
@@ -65,21 +66,32 @@
         /* put into page */
         this.domObj.appendChild(this.domLabel);
         Event.observe(this.input, 'blur', this.onBlur.bind(this));
-        this.getMap().registerForEvent(Fusion.Event.MAP_LOADED, this.mapLoaded.bind(this));
-        this.getMap().registerForEvent(Fusion.Event.MAP_EXTENTS_CHANGED, this.mapExtentsChanged.bind(this));
-        
     },
     
     mapLoaded: function() {
+        this.draw();
+        this.input.disabled = true;
         var widgets = Fusion.getWidgetsByType('SelectRadius');
         for (var i=0; i<widgets.length; i++) {
-            if (widgets[i].sName == this.radiusWidgetName) {
+            if (widgets[i].widgetTag.name == this.radiusWidgetName) {
                 this.widget = widgets[i];
+                this.widget.registerForEvent(Fusion.Event.RADIUS_WIDGET_ACTIVATED, this.dependantEnable.bind(this));
+                break;
             }
         }
         this.updateFromWidgetValue();
     },
     
+    dependantEnable: function(eventId, active) {
+        if (this.widget) {
+            if (active) {
+                this.input.disabled = false;
+            } else {
+                this.input.disabled = true;
+            }
+        }
+    },
+    
     mapExtentsChanged: function() {
         this.updateWidgetValue();
     },
@@ -90,14 +102,14 @@
     
     updateWidgetValue: function() {
         if (this.widget) {
-            var radius = this.getMap().geoToPixMeasure(this.input.getValue());
+            var radius = this.input.getValue();
             this.widget.setRadius(radius);
         }
     },
     
     updateFromWidgetValue: function() {
         if (this.widget) {
-            this.input.value = this.getMap().pixToGeoMeasure(this.widget.getRadius());
+            this.input.value = this.widget.getRadius();
         }
     }
 };
\ No newline at end of file



More information about the fusion-commits mailing list