[fusion-commits] r1388 - in trunk: MapGuide MapServer lib widgets

svn_fusion at osgeo.org svn_fusion at osgeo.org
Tue May 6 10:46:04 EDT 2008


Author: madair
Date: 2008-05-06 10:46:04 -0400 (Tue, 06 May 2008)
New Revision: 1388

Modified:
   trunk/MapGuide/MapGuide.js
   trunk/MapServer/MapServer.js
   trunk/lib/Map.js
   trunk/lib/fusion.js
   trunk/widgets/CursorPosition.js
   trunk/widgets/ViewSize.js
Log:
closes #2: add methods to get and set the MeterPerUnit value as returned by LoadMap (rather than using hard-coded values for meters per degree)

Modified: trunk/MapGuide/MapGuide.js
===================================================================
--- trunk/MapGuide/MapGuide.js	2008-04-29 17:31:05 UTC (rev 1387)
+++ trunk/MapGuide/MapGuide.js	2008-05-06 14:46:04 UTC (rev 1388)
@@ -216,8 +216,7 @@
             this._sResourceId = o.mapId;
             this._sMapname = o.mapName;
             this._sMapTitle = o.mapTitle;
-            this._fMetersperunit = o.metersPerUnit;
-            this.mapWidget._fMetersperunit = this._fMetersperunit;
+            this.mapWidget.setMetersPerUnit(o.metersPerUnit);
 
             this._oMaxExtent = OpenLayers.Bounds.fromArray(o.extent); 
 
@@ -284,7 +283,7 @@
             //set projection units and code if supplied
             //TODO: consider passing the metersPerUnit value into the framework
             //to allow for scaling that doesn't match any of the pre-canned units
-            this.units = this.getClosestUnits(o.metersPerUnit);
+            this.units = Fusion.getClosestUnits(o.metersPerUnit);
             
             //add in scales array if supplied
             if (o.FiniteDisplayScales && o.FiniteDisplayScales.length>0) {
@@ -319,22 +318,6 @@
         this.mapWidget._removeWorker();
     },
     
-    getClosestUnits: function(metrsPerUnit) {
-        
-        var units = "degrees";
-        var minDiff = 100000000;
-        for (var key in OpenLayers.INCHES_PER_UNIT)        
-        {
-            var newDiff = Math.abs((metrsPerUnit * 39.3701) - OpenLayers.INCHES_PER_UNIT[key]);
-            if(newDiff < minDiff)
-            {
-                minDiff = newDiff;
-                units = key;
-            }
-        }
-        return units;
-    },
-
 //TBD: this function not yet converted for OL    
     reloadMap: function() {
         

Modified: trunk/MapServer/MapServer.js
===================================================================
--- trunk/MapServer/MapServer.js	2008-04-29 17:31:05 UTC (rev 1387)
+++ trunk/MapServer/MapServer.js	2008-05-06 14:46:04 UTC (rev 1388)
@@ -222,8 +222,7 @@
             this._sMapFile = o.mapId;
             this._sMapname = o.mapName;
             this._sMapTitle = o.mapTitle;
-            this._fMetersperunit = o.metersPerUnit;
-            this.mapWidget._fMetersperunit = this._fMetersperunit;
+            this.mapWidget.setMetersPerUnit(o.metersPerUnit);
             this._sImageType = o.imagetype;
             this.metadata = o.metadata;
 
@@ -252,32 +251,19 @@
                 OpenLayers.DOTS_PER_INCH = o.dpi;
             }
 
+            //to allow for scaling that doesn't match any of the pre-canned units
+            this.units = Fusion.getClosestUnits(o.metersPerUnit);
+            
             var layerOptions = {
       				singleTile: true,
       				ratio: this.ratio,
+              units: this.units,
       				maxExtent : this._oMaxExtent,
               maxResolution : 'auto',
       				minScale : maxScale,	//OL interpretation of min/max scale is reversed from Fusion
       				maxScale : minScale
       			};
 
-            //set OpenLayer projection units and code if supplied (OL defaults units to degrees)
-            if (o.metersPerUnit == 0.0254)
-               layerOptions.units = 'inches';
-            else if (o.metersPerUnit == 0.3048)
-               layerOptions.units = 'ft';
-            else if (o.metersPerUnit == 1609.344)
-               layerOptions.units = 'mi';
-            else if (o.metersPerUnit == 1)
-               layerOptions.units = 'm';
-               //layerOptions.projection = 'EPSG:42304';  //TODO: not necessary, but can this be supplied by LoadMap?
-            else if (o.metersPerUnit == 1000)
-               layerOptions.units = 'km';
-            else if (o.metersPerUnit == 111118.7516)
-               layerOptions.units = 'dd';
-
-            //this.mapWidget.setMapOptions(oMapOptions);
-
             //create the OL layer for this Map layer
             var params = {
               layers: this.aVisibleLayers.join(' '),

Modified: trunk/lib/Map.js
===================================================================
--- trunk/lib/Map.js	2008-04-29 17:31:05 UTC (rev 1387)
+++ trunk/lib/Map.js	2008-05-06 14:46:04 UTC (rev 1388)
@@ -639,8 +639,36 @@
         return (nPixels*resolution);
     },
     
+  /**
+     *
+     * initializes the meters per unit values when a new map is loaded.  Some systems make different 
+     * assumptions for the conversion of degrees to meters so this makes sure both Fusion and
+     * OpenLayers are using the same value.
+     *
+     * @param metersPerUnit the value returned by LoadMap.php for meters per unit
+     */
+    setMetersPerUnit: function(metersPerUnit) {
+        if (this._fMetersperunit < 0) {
+            Fusion.initUnits(metersPerUnit);
+            this._fMetersperunit = metersPerUnit;
+        } else {
+            Fusion.reportError(new Fusion.Error(Fusion.Error.WARNING, 
+                                'meters per unit value already set'));
+        }
+    },
+    
     /**
      *
+     * returns the meters per unit value
+     *
+     * @return metersPerUnit the value as set when the map initialized
+     */
+    getMetersPerUnit: function() {
+        return this._fMetersperunit;
+    },
+    
+    /**
+     *
      * convert geographic into pixels.
      *
      * @param fGeo float distance in geographic units

Modified: trunk/lib/fusion.js
===================================================================
--- trunk/lib/fusion.js	2008-04-29 17:31:05 UTC (rev 1387)
+++ trunk/lib/fusion.js	2008-05-06 14:46:04 UTC (rev 1388)
@@ -904,6 +904,49 @@
         }
         return false;
     },
+    
+  /**
+     * initializes the meters per unit values when a new map is loaded.  Some systems make different 
+     * assumptions for the conversion of degrees to meters so this makes sure both Fusion and
+     * OpenLayers are using the same value.
+     *
+     * @param metersPerUnit the value returned by LoadMap.php for meters per unit
+     */
+    initUnits: function(metersPerUnit) {
+        var eps = 1000;
+        if (Math.abs(metersPerUnit-Fusion.aMeterPerUnit[Fusion.DEGREES]) < eps){
+            Fusion.aMeterPerUnit[Fusion.DEGREES] = metersPerUnit;
+            Fusion.aMeterPerUnit[Fusion.DECIMALDEGREES] = metersPerUnit;
+            Fusion.aMeterPerUnit[Fusion.DMX] = metersPerUnit;
+            var inverse = 1.0/metersPerUnit;
+            Fusion.aUnitPerMeter[Fusion.DEGREES] = inverse;
+            Fusion.aUnitPerMeter[Fusion.DECIMALDEGREES] = inverse;
+            Fusion.aUnitPerMeter[Fusion.DMX] = inverse;
+            
+            var inPerUnit = OpenLayers.INCHES_PER_UNIT.m * metersPerUnit;
+            OpenLayers.INCHES_PER_UNIT["dd"] = inPerUnit;
+            OpenLayers.INCHES_PER_UNIT["degrees"] = inPerUnit;
+        }
+    },
+    
+  /**
+     * find the OpenLayers units identifier given the Fusion metersPerUnit value
+     *
+     * @param metersPerUnit the value returned by LoadMap.php for meters per unit
+     */
+    getClosestUnits: function(metersPerUnit) {
+        var units = "degrees";
+        var minDiff = 100000000;
+        for (var key in OpenLayers.INCHES_PER_UNIT) {
+            var newDiff = Math.abs((metersPerUnit * 39.3701) - OpenLayers.INCHES_PER_UNIT[key]);
+            if(newDiff < minDiff)
+            {
+                minDiff = newDiff;
+                units = key;
+            }
+        }
+        return units;
+    },
 
     addWidgetStyleSheet: function(url) {
         var lnk = document.createElement('link');

Modified: trunk/widgets/CursorPosition.js
===================================================================
--- trunk/widgets/CursorPosition.js	2008-04-29 17:31:05 UTC (rev 1387)
+++ trunk/widgets/CursorPosition.js	2008-05-06 14:46:04 UTC (rev 1388)
@@ -110,8 +110,9 @@
             p = map.pixToGeo(p.x, p.y);
             if (p) {
                 if (this.units != Fusion.UNKNOWN) {
-                    p.x = Fusion.fromMeter(this.units, p.x * map._fMetersperunit);
-                    p.y = Fusion.fromMeter(this.units, p.y * map._fMetersperunit);
+                    var convFactor = map.getMetersPerUnit();
+                    p.x = Fusion.fromMeter(this.units, p.x * convFactor);
+                    p.y = Fusion.fromMeter(this.units, p.y * convFactor);
                 }
                 if (this.precision >= 0) {
                     var factor = Math.pow(10,this.precision);
@@ -122,7 +123,6 @@
         }
         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);
         }
     },

Modified: trunk/widgets/ViewSize.js
===================================================================
--- trunk/widgets/ViewSize.js	2008-04-29 17:31:05 UTC (rev 1387)
+++ trunk/widgets/ViewSize.js	2008-05-06 14:46:04 UTC (rev 1388)
@@ -68,8 +68,9 @@
             var gw = map.pixToGeoMeasure(p.w);
             var gh = map.pixToGeoMeasure(p.h);
             if (this.units != Fusion.UNKNOWN) {
-                gw = Fusion.fromMeter(this.units, gw * map._fMetersperunit);
-                gh = Fusion.fromMeter(this.units, gh * map._fMetersperunit);
+                var convFactor = map.getMetersPerUnit();
+                gw = Fusion.fromMeter(this.units, gw * convFactor);
+                gh = Fusion.fromMeter(this.units, gh * convFactor);
             }
             if (this.precision >= 0) {
                 var factor = Math.pow(10,this.precision);



More information about the fusion-commits mailing list