[mapguide-commits] r7078 - in branches/2.4/MgDev/Desktop: MapViewer MgDesktop

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Fri Oct 5 02:02:19 PDT 2012


Author: jng
Date: 2012-10-05 02:02:19 -0700 (Fri, 05 Oct 2012)
New Revision: 7078

Modified:
   branches/2.4/MgDev/Desktop/MapViewer/IMapViewer.cs
   branches/2.4/MgDev/Desktop/MapViewer/MgMapViewer.cs
   branches/2.4/MgDev/Desktop/MgDesktop/changelog.txt
Log:
mg-desktop: Implement a MapToScreenUnits viewer API to complement the existing ScreenToMapUnits API

Modified: branches/2.4/MgDev/Desktop/MapViewer/IMapViewer.cs
===================================================================
--- branches/2.4/MgDev/Desktop/MapViewer/IMapViewer.cs	2012-10-04 14:27:01 UTC (rev 7077)
+++ branches/2.4/MgDev/Desktop/MapViewer/IMapViewer.cs	2012-10-05 09:02:19 UTC (rev 7078)
@@ -471,10 +471,19 @@
         /// <summary>
         /// Converts the given coordinate in screen units to map units
         /// </summary>
-        /// <param name="x"></param>
-        /// <param name="y"></param>
+        /// <param name="x">The x coordinate in screen space</param>
+        /// <param name="y">The y coordinate in screen space</param>
         /// <returns></returns>
         PointF ScreenToMapUnits(double x, double y);
+
+        /// <summary>
+        /// Converts the given coordinate in map-space to coordinates in screen space. This is the inverse of
+        /// <see cref="M:OSGeo.MapGuide.Viewer.IMapViewer.ScreenToMapUnits" />
+        /// </summary>
+        /// <param name="x">The x coordinate in map space</param>
+        /// <param name="y">The y coordinate in map space</param>
+        /// <returns></returns>
+        Point MapToScreenUnits(double x, double y);
     }
 
     public class MgMapViewHistoryEntry

Modified: branches/2.4/MgDev/Desktop/MapViewer/MgMapViewer.cs
===================================================================
--- branches/2.4/MgDev/Desktop/MapViewer/MgMapViewer.cs	2012-10-04 14:27:01 UTC (rev 7077)
+++ branches/2.4/MgDev/Desktop/MapViewer/MgMapViewer.cs	2012-10-05 09:02:19 UTC (rev 7078)
@@ -2956,23 +2956,39 @@
             return ScreenToMapUnits(x, y, false);
         }
 
-        private PointF ScreenToMapUnits(double x, double y, bool allowOutsideWindow)
+        private PointF ScreenToMapUnits(double sx, double sy, bool allowOutsideWindow)
         {
             if (!allowOutsideWindow)
             {
-                if (x > this.Width - 1) x = this.Width - 1;
-                else if (x < 0) x = 0;
+                if (sx > this.Width - 1) sx = this.Width - 1;
+                else if (sx < 0) sx = 0;
 
-                if (y > this.Height - 1) y = this.Height - 1;
-                else if (y < 0) y = 0;
+                if (sy > this.Height - 1) sy = this.Height - 1;
+                else if (sy < 0) sy = 0;
             }
 
-            x = _extX1 + (_extX2 - _extX1) * (x / this.Width);
-            y = _extY1 - (_extY1 - _extY2) * (y / this.Height);
-            return new PointF((float)x, (float)y);
+            var mx = _extX1 + ((_extX2 - _extX1) * (sx / this.Width));
+            var my = _extY1 - ((_extY1 - _extY2) * (sy / this.Height));
+            return new PointF((float)mx, (float)my);
         }
 
         /// <summary>
+        /// Converts the specified map coordinates to screen coordinates
+        /// </summary>
+        /// <param name="mx"></param>
+        /// <param name="my"></param>
+        /// <returns></returns>
+        public Point MapToScreenUnits(double mx, double my)
+        {
+            //Equation derived from high-school mathematical inversion of the 
+            //ScreenToMapUnits formula :) Tests thus far indicate this formula
+            //is correct.
+            var sx = this.Width * ((mx - _extX1) / (_extX2 - _extX1));
+            var sy = this.Height * ((my - _extY1) / (_extY2 - _extY1));
+            return new Point(Convert.ToInt32(Math.Round(sx)), Convert.ToInt32(Math.Round(sy)));
+        }
+
+        /// <summary>
         /// Occurs when a property value changes.
         /// </summary>
         [Category("MapGuide Viewer")] //NOXLATE

Modified: branches/2.4/MgDev/Desktop/MgDesktop/changelog.txt
===================================================================
--- branches/2.4/MgDev/Desktop/MgDesktop/changelog.txt	2012-10-04 14:27:01 UTC (rev 7077)
+++ branches/2.4/MgDev/Desktop/MgDesktop/changelog.txt	2012-10-05 09:02:19 UTC (rev 7078)
@@ -3,6 +3,7 @@
  - MgdPlatform::Terminate() did not call MgdFdoConnectionPool::Cleanup() leaving that to the static initializer to cleanup. This caused problems for the GDAL provider if connection pooling is enabled. The call has been put into MgdPlatform::Terminate() and connection pooling for the GDAL provider has been re-enabled in Platform.ini
  - Add support for MapGuide's PreCacheMaps configuration property in Platform.ini
  - MgMapViewer is now an IMapComponent, and any properties tagged with MgComponentPropertyAttribute can be dynamically set by the AppLayout engine.
+ - New MapToScreenUnits viewer API to complement the existing ScreenToMapUnits API.
 
 Viewer Changelog:
  - Support for Localization



More information about the mapguide-commits mailing list