[fusion-commits] r2465 - trunk/widgets

svn_fusion at osgeo.org svn_fusion at osgeo.org
Mon Nov 21 21:54:26 EST 2011


Author: liuar
Date: 2011-11-21 18:54:26 -0800 (Mon, 21 Nov 2011)
New Revision: 2465

Modified:
   trunk/widgets/CursorPosition.js
Log:
Fix ticket #467 Display units as degrees shows incorrect x/y values in Fusion.

Modified: trunk/widgets/CursorPosition.js
===================================================================
--- trunk/widgets/CursorPosition.js	2011-11-21 17:06:46 UTC (rev 2464)
+++ trunk/widgets/CursorPosition.js	2011-11-22 02:54:26 UTC (rev 2465)
@@ -104,39 +104,53 @@
     },
     
     formatHTML: function(p) {
-    	
-    	if (!this.displayProjection) {
-    	/* old code for converting between units */
-                if (this.units != Fusion.UNKNOWN) {
-                    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.lon = Math.round(p.lon * factor)/factor;
-                    p.lat = Math.round(p.lat * factor)/factor;
-                }
-      }
-				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;
+        if (!this.displayProjection) {
+            var mapProj = this.getMap().projection;
+            var mapUnit = mapProj.getUnits();
+
+            // convertion from linear units to degree unit.
+            if(this.units == Fusion.DEGREES && mapUnit != 'dd' && mapUnit != 'degrees' ) {
+                // coordinate transformation from map CS to EPSG:4326.
+                var dest = new OpenLayers.Projection("GEOGCS[\"LL84\",DATUM[\"WGS84\",SPHEROID[\"WGS84\",6378137.000,298.25722293]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.01745329251994]]");
+                p = p.transform(this.getMap().projection, dest);
+            }
+            //else
+            //{
+                // TODO: convertion from degree unit to linear units
+            //}
+            
+            /* old code for converting between units */
+            else if (this.units != Fusion.UNKNOWN) {
+                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.lon = Math.round(p.lon * factor)/factor;
+                p.lat = Math.round(p.lat * factor)/factor;
+            }
+        }
+        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') {
-        	var unitName = value;
-        	if (this.displayProjection) {
-        		unitName = this.displayProjection.getUnits();
-        	}
+            var unitName = value;
+            if (this.displayProjection) {
+                unitName = this.displayProjection.getUnits();
+            }
           this.units = Fusion.unitFromName(unitName);
         }
     }



More information about the fusion-commits mailing list