[fusion-commits] r2268 - in trunk: . lib/OpenLayers widgets

svn_fusion at osgeo.org svn_fusion at osgeo.org
Wed Nov 3 16:29:09 EDT 2010


Author: madair
Date: 2010-11-03 13:29:09 -0700 (Wed, 03 Nov 2010)
New Revision: 2268

Modified:
   trunk/fusion.cfg
   trunk/lib/OpenLayers/OpenLayers.js
   trunk/widgets/CursorPosition.js
Log:
re #412: switch CursorPosition.js to use the OpenLayers MousePosition control, override the formatOutput method and include MousePosition in the fusion build of OpenLayers

Modified: trunk/fusion.cfg
===================================================================
--- trunk/fusion.cfg	2010-11-01 21:48:26 UTC (rev 2267)
+++ trunk/fusion.cfg	2010-11-03 20:29:09 UTC (rev 2268)
@@ -43,6 +43,12 @@
 OpenLayers/Control/DrawFeature.js
 OpenLayers/Control/Measure.js
 OpenLayers/Control/ScaleLine.js
+OpenLayers/Control/MousePosition.js
+OpenLayers/Filter.js
+OpenLayers/Filter/FeatureId.js
+OpenLayers/Filter/Spatial.js
+OpenLayers/Filter/Logical.js
+OpenLayers/Filter/Comparison.js
 OpenLayers/Format/GML/v2.js
 OpenLayers/Format/GML/v3.js
 OpenLayers/Format/WFSCapabilities.js

Modified: trunk/lib/OpenLayers/OpenLayers.js
===================================================================
--- trunk/lib/OpenLayers/OpenLayers.js	2010-11-01 21:48:26 UTC (rev 2267)
+++ trunk/lib/OpenLayers/OpenLayers.js	2010-11-03 20:29:09 UTC (rev 2268)
@@ -11078,6 +11078,223 @@
     CLASS_NAME: "OpenLayers.Control.ArgParser"
 });
 /* ======================================================================
+    OpenLayers/Control/MousePosition.js
+   ====================================================================== */
+
+/* Copyright (c) 2006-2010 by OpenLayers Contributors (see authors.txt for 
+ * full list of contributors). Published under the Clear BSD license.  
+ * See http://svn.openlayers.org/trunk/openlayers/license.txt for the
+ * full text of the license. */
+
+
+/**
+ * @requires OpenLayers/Control.js
+ */
+
+/**
+ * Class: OpenLayers.Control.MousePosition
+ * The MousePosition control displays geographic coordinates of the mouse
+ * pointer, as it is moved about the map.
+ *
+ * Inherits from:
+ *  - <OpenLayers.Control>
+ */
+OpenLayers.Control.MousePosition = OpenLayers.Class(OpenLayers.Control, {
+    
+    /**
+     * APIProperty: autoActivate
+     * {Boolean} Activate the control when it is added to a map.  Default is
+     *     true.
+     */
+    autoActivate: true,
+
+    /** 
+     * Property: element
+     * {DOMElement} 
+     */
+    element: null,
+    
+    /** 
+     * APIProperty: prefix
+     * {String}
+     */
+    prefix: '',
+    
+    /** 
+     * APIProperty: separator
+     * {String}
+     */
+    separator: ', ',
+    
+    /** 
+     * APIProperty: suffix
+     * {String}
+     */
+    suffix: '',
+    
+    /** 
+     * APIProperty: numDigits
+     * {Integer}
+     */
+    numDigits: 5,
+    
+    /** 
+     * APIProperty: granularity
+     * {Integer} 
+     */
+    granularity: 10,
+
+    /**
+     * APIProperty: emptyString 
+     * {String} Set this to some value to set when the mouse is outside the
+     *     map.
+     */
+    emptyString: null,
+    
+    /** 
+     * Property: lastXy
+     * {<OpenLayers.Pixel>}
+     */
+    lastXy: null,
+
+    /**
+     * APIProperty: displayProjection
+     * {<OpenLayers.Projection>} The projection in which the 
+     * mouse position is displayed
+     */
+    displayProjection: null, 
+    
+    /**
+     * Constructor: OpenLayers.Control.MousePosition
+     * 
+     * Parameters:
+     * options - {Object} Options for control.
+     */
+    initialize: function(options) {
+        OpenLayers.Control.prototype.initialize.apply(this, arguments);
+    },
+
+    /**
+     * Method: destroy
+     */
+     destroy: function() {
+         this.deactivate();
+         OpenLayers.Control.prototype.destroy.apply(this, arguments);
+     },
+
+    /**
+     * APIMethod: activate
+     */
+    activate: function() {
+        if (OpenLayers.Control.prototype.activate.apply(this, arguments)) {
+            this.map.events.register('mousemove', this, this.redraw);
+            this.map.events.register('mouseout', this, this.reset);
+            this.redraw();
+            return true;
+        } else {
+            return false;
+        }
+    },
+    
+    /**
+     * APIMethod: deactivate
+     */
+    deactivate: function() {
+        if (OpenLayers.Control.prototype.deactivate.apply(this, arguments)) {
+            this.map.events.unregister('mousemove', this, this.redraw);
+            this.map.events.unregister('mouseout', this, this.reset);
+            this.element.innerHTML = "";
+            return true;
+        } else {
+            return false;
+        }
+    },
+
+    /**
+     * Method: draw
+     * {DOMElement}
+     */    
+    draw: function() {
+        OpenLayers.Control.prototype.draw.apply(this, arguments);
+
+        if (!this.element) {
+            this.div.left = "";
+            this.div.top = "";
+            this.element = this.div;
+        }
+        
+        return this.div;
+    },
+   
+    /**
+     * Method: redraw  
+     */
+    redraw: function(evt) {
+
+        var lonLat;
+
+        if (evt == null) {
+            this.reset();
+            return;
+        } else {
+            if (this.lastXy == null ||
+                Math.abs(evt.xy.x - this.lastXy.x) > this.granularity ||
+                Math.abs(evt.xy.y - this.lastXy.y) > this.granularity)
+            {
+                this.lastXy = evt.xy;
+                return;
+            }
+
+            lonLat = this.map.getLonLatFromPixel(evt.xy);
+            if (!lonLat) { 
+                // map has not yet been properly initialized
+                return;
+            }    
+            if (this.displayProjection) {
+                lonLat.transform(this.map.getProjectionObject(), 
+                                 this.displayProjection );
+            }      
+            this.lastXy = evt.xy;
+            
+        }
+        
+        var newHtml = this.formatOutput(lonLat);
+
+        if (newHtml != this.element.innerHTML) {
+            this.element.innerHTML = newHtml;
+        }
+    },
+
+    /**
+     * Method: reset
+     */
+    reset: function(evt) {
+        if (this.emptyString != null) {
+            this.element.innerHTML = this.emptyString;
+        }
+    },
+
+    /**
+     * Method: formatOutput
+     * Override to provide custom display output
+     *
+     * Parameters:
+     * lonLat - {<OpenLayers.LonLat>} Location to display
+     */
+    formatOutput: function(lonLat) {
+        var digits = parseInt(this.numDigits);
+        var newHtml =
+            this.prefix +
+            lonLat.lon.toFixed(digits) +
+            this.separator + 
+            lonLat.lat.toFixed(digits) +
+            this.suffix;
+        return newHtml;
+    },
+
+    CLASS_NAME: "OpenLayers.Control.MousePosition"
+});
+/* ======================================================================
     OpenLayers/Control/PanZoom.js
    ====================================================================== */
 

Modified: trunk/widgets/CursorPosition.js
===================================================================
--- trunk/widgets/CursorPosition.js	2010-11-01 21:48:26 UTC (rev 2267)
+++ trunk/widgets/CursorPosition.js	2010-11-03 20:29:09 UTC (rev 2268)
@@ -77,10 +77,16 @@
             this.domObj.innerHTML = '';
             this.domObj.appendChild(this.domSpan);
         } 
-
-        this.enable = Fusion.Widget.CursorPosition.prototype.enable;
-        this.disable = Fusion.Widget.CursorPosition.prototype.enable;
+        this.displayProjection = json.DisplayProjection ? new OpenLayers.Projection(json.DisplayProjection[0]) : null;
         
+        this.control = new OpenLayers.Control.MousePosition({
+        		div: this.domObj,
+        		formatOutput: OpenLayers.Function.bind(this.formatHTML, this),
+        		emptyString: this.emptyText,
+        		displayProjection: this.displayProjection
+        });
+        this.getMap().oMapOL.addControl(this.control);
+
         this.getMap().registerForEvent(Fusion.Event.MAP_LOADED, OpenLayers.Function.bind(this.setUnits, this));
         this.registerParameter('Units');
         
@@ -97,56 +103,41 @@
         }
     },
     
-    enable: function() {
-        this.mouseMoveWatcher = OpenLayers.Function.bind(this.mouseMove, this);
-        this.mouseOutWatcher = OpenLayers.Function.bind(this.mouseOut, this);
-
-        this.getMap().observeEvent('mousemove', this.mouseMoveWatcher);
-        this.getMap().observeEvent('mouseout', this.mouseOutWatcher);
-    },
-    
-    disable: function() {
-        this.getMap().stopObserveEvent('mousemove', this.mouseMoveWatcher);
-        this.getMap().stopObserveEvent('mouseout', this.mouseOutWatcher);
-    },
-    
-    mouseOut: function(e) {
-        this.domSpan.innerHTML = this.emptyText;
-    },
-    
-    mouseMove: function(e) {
-        var map = this.getMap();
-        var p = map.getEventPosition(e);
-        if (this.units != Fusion.PIXELS) {
-            p = map.pixToGeo(p.x, p.y);
-            if (p) {
+    formatHTML: function(p) {
+    	
+    	if (!this.displayProjection) {
+    	/* old code for converting between units */
                 if (this.units != Fusion.UNKNOWN) {
-                    var convFactor = map.getMetersPerUnit();
-                    p.x = Fusion.fromMeter(this.units, p.x * convFactor);
-                    p.y = Fusion.fromMeter(this.units, p.y * convFactor);
+                    var convFactor = this.getMap().getMetersPerUnit();
+                    p.lon = Fusion.fromMeter(this.units, p.lon * convFactor);
+                    p.lat = Fusion.fromMeter(this.units, p.lat * convFactor);
                 }
                 if (this.precision >= 0) {
                     var factor = Math.pow(10,this.precision);
-                    p.x = Math.round(p.x * factor)/factor;
-                    p.y = Math.round(p.y * factor)/factor;
+                    p.lon = Math.round(p.lon * factor)/factor;
+                    p.lat = Math.round(p.lat * factor)/factor;
                 }
-            }
-        }
-        if (p) {
-            var unitAbbr = Fusion.unitAbbr(this.units);
-            this.domSpan.innerHTML = this.template.replace('{x}',p.x).replace('{y}',p.y).replace('{units}', unitAbbr).replace('{units}', unitAbbr);
-        }
+      }
+				var unitAbbr = Fusion.unitAbbr(this.units);
+				var innerHTML = this.template.replace('{x}',p.lon.toFixed(this.precision));
+				innerHTML = innerHTML.replace('{y}',p.lat.toFixed(this.precision));
+				innerHTML = innerHTML.replace('{units}', unitAbbr).replace('{units}', unitAbbr);
+				return innerHTML;
     },
 
     setUnits: function() {
-      if (this.units == Fusion.UNKNOWN) {
-        this.setParameter('Units',this.getMap().getUnits());
-      }
+				if (this.units == Fusion.UNKNOWN) {
+					this.setParameter('Units',this.getMap().getUnits());
+				}
     },
 
     setParameter: function(param, value) {
         if (param == 'Units') {
-            this.units = Fusion.unitFromName(value);
+        	var unitName = value;
+        	if (this.displayProjection) {
+        		unitName = this.displayProjection.getUnits();
+        	}
+          this.units = Fusion.unitFromName(unitName);
         }
     }
 });



More information about the fusion-commits mailing list