[mapguide-commits] r7529 - in trunk/Tools/Maestro: Maestro.Base/Commands/SiteExplorer Maestro.Editors/Common Maestro.Editors/MapDefinition Maestro.LiveMapEditor Maestro.MapViewer OSGeo.MapGuide.MaestroAPI OSGeo.MapGuide.MaestroAPI/Mapping OSGeo.MapGuide.MaestroAPI.Local OSGeo.MapGuide.MaestroAPI.Native

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Mon May 27 08:51:06 PDT 2013


Author: jng
Date: 2013-05-27 08:51:06 -0700 (Mon, 27 May 2013)
New Revision: 7529

Added:
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/CsHelper.cs
Modified:
   trunk/Tools/Maestro/Maestro.Base/Commands/SiteExplorer/TestResourceCompatibilityCommand.cs
   trunk/Tools/Maestro/Maestro.Editors/Common/RepositoryView.cs
   trunk/Tools/Maestro/Maestro.Editors/MapDefinition/LiveMapDefinitionEditorCtrl.cs
   trunk/Tools/Maestro/Maestro.Editors/MapDefinition/LiveMapEditorRepositoryView.Designer.cs
   trunk/Tools/Maestro/Maestro.Editors/MapDefinition/MapSettingsSectionCtrl.cs
   trunk/Tools/Maestro/Maestro.LiveMapEditor/MainForm.cs
   trunk/Tools/Maestro/Maestro.LiveMapEditor/MapSettingsDialog.Designer.cs
   trunk/Tools/Maestro/Maestro.LiveMapEditor/MapSettingsDialog.cs
   trunk/Tools/Maestro/Maestro.LiveMapEditor/MapSettingsDialog.resx
   trunk/Tools/Maestro/Maestro.LiveMapEditor/Program.cs
   trunk/Tools/Maestro/Maestro.LiveMapEditor/Strings.Designer.cs
   trunk/Tools/Maestro/Maestro.LiveMapEditor/Strings.resx
   trunk/Tools/Maestro/Maestro.MapViewer/MapViewer.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Local/LocalConnection.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeConnection.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeCoordinateSystem.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeCoordinateSystemCatalog.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/ConnectionProviderRegistry.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/IServerConnection.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMap.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/OSGeo.MapGuide.MaestroAPI.csproj
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/PlatformConnectionBase.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Utility.cs
Log:
This submission includes the following changes:
 - Expose assembly path in ConnectionProviderEntry. Allow ConnectionProviderEntry objects to be accessed by provider name
 - Fix GetViewExtent() in MapViewer. Might need to check mg-desktop implementation as well, seeing the core viewer logic is mostly identical.
 - Introduce a new IMpuCalculator interface for calculating meters-per-unit values. Update IServerConnection to include a new GetCalculator() method that returns an IMpuCalculator instance.
 - Introduce a new CsHelper static class in the Maestro API. This serves as an application-level override for MPU calculators and coordinate system catalogs. The idea of this class is that where possible, we would prefer to tap into mg-desktop's coordinate system services, thus wherever mg-desktop is available to us we'd set the default calculator and coordinate system catalog in the CsHelper. Various parts of the Maestro API that need to do MPU calculations or coordinate transformations have been updated to check whether a default calculator/catalog has been set. If one has been set, it uses that. Currently, nothing sets the default calculator/catalog due to a little as-yet-unsolved problem of needing to call MapGuideApi.MgInitializeWebTier or MgdPlatform.Initialize in order to have the MapGuide coordinate system APIs in a good working state before we can even set the default calculator/catalog. When we figure out this solution to this problem, the code is already in place f
 or use to choose the preferred calculator/catalog.
 - RuntimeMap additions to facilitate Live Map Definition Editor support:
   - Add a new CoordSysAndExtentsChangedFromFirstLayer event.
   - Add a new ComputeCoordSysAndExtentsOnFirstLayerAdded property. If true, and the first layer has been added, the map's extents and coordinate system are computed based on the layer's extents and spatial context (just like the Map Definition). Once these computed value have been assigned, the new CoordSysAndExtentsChangedFromFirstLayer event is raised.
   - Also update coordinate system and extents in the UpdateMapDefinition() method
 - #2018: Live Map Definition editor improvements:
   - Map Settings Dialog:
     - Fix cs/extents/color not actually being applied
     - Support background extent computation (like the Map Definition editor)
     - Allow extents to be set based on current viewer extents
     - Remove the requirement of the coordinate system needing to be set, as we can auto-assign one on the first layer added
     - Do not show this dialog when a the New Map command is invoked. Go directly to loading a blank RuntimeMap
   - Fix a small usability problem where the beginning of dragging an item does not actually select the item, thus causing the code that handles the drag/drop to not work.

Modified: trunk/Tools/Maestro/Maestro.Base/Commands/SiteExplorer/TestResourceCompatibilityCommand.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Commands/SiteExplorer/TestResourceCompatibilityCommand.cs	2013-05-27 12:26:35 UTC (rev 7528)
+++ trunk/Tools/Maestro/Maestro.Base/Commands/SiteExplorer/TestResourceCompatibilityCommand.cs	2013-05-27 15:51:06 UTC (rev 7529)
@@ -300,5 +300,10 @@
         public event RequestEventHandler RequestDispatched;
 
         public event EventHandler SessionIDChanged;
+
+        public IMpuCalculator GetCalculator()
+        {
+            throw new NotImplementedException();
+        }
     }
 }

Modified: trunk/Tools/Maestro/Maestro.Editors/Common/RepositoryView.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/Common/RepositoryView.cs	2013-05-27 12:26:35 UTC (rev 7528)
+++ trunk/Tools/Maestro/Maestro.Editors/Common/RepositoryView.cs	2013-05-27 15:51:06 UTC (rev 7529)
@@ -43,9 +43,15 @@
         public RepositoryView()
         {
             InitializeComponent();
+            this.SelectOnDrag = false;
         }
 
         /// <summary>
+        /// Determines whether a node that is dragged causes it to be selected
+        /// </summary>
+        public bool SelectOnDrag { get; set; }
+
+        /// <summary>
         /// Raises the Load event
         /// </summary>
         /// <param name="e"></param>
@@ -162,6 +168,15 @@
 
         private void trvRepository_ItemDrag(object sender, ItemDragEventArgs e)
         {
+            var node = e.Item as TreeNode;
+            if (node != null)
+            {
+                if (node != trvRepository.SelectedNode && this.SelectOnDrag)
+                {
+                    trvRepository.SelectedNode = node;
+                }
+            }
+
             var h = this.ItemDrag;
             if (h != null)
                 h(this, e);

Modified: trunk/Tools/Maestro/Maestro.Editors/MapDefinition/LiveMapDefinitionEditorCtrl.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/MapDefinition/LiveMapDefinitionEditorCtrl.cs	2013-05-27 12:26:35 UTC (rev 7528)
+++ trunk/Tools/Maestro/Maestro.Editors/MapDefinition/LiveMapDefinitionEditorCtrl.cs	2013-05-27 15:51:06 UTC (rev 7529)
@@ -33,6 +33,7 @@
 using OSGeo.MapGuide.MaestroAPI.Resource;
 using Maestro.MapViewer.Model;
 using Maestro.Editors.MapDefinition.Live;
+using Maestro.MapViewer;
 
 namespace Maestro.Editors.MapDefinition
 {
@@ -86,6 +87,11 @@
             viewer.RefreshMap();
         }
 
+        /// <summary>
+        /// Gets the viewer
+        /// </summary>
+        public IMapViewer Viewer { get { return viewer; } }
+
         private RuntimeMap _rtMap;
         private IMapDefinition _shadowCopy;
         private IMappingService _mapSvc;
@@ -115,6 +121,16 @@
                 ResourceTypes.FeatureSource
             });
 
+            ReloadViewer();
+        }
+
+        public void RebuildRuntimeMap()
+        {
+            _rtMap = _mapSvc.CreateMap(_shadowCopy);
+        }
+
+        public void ReloadViewer()
+        {
             viewer.LoadMap(_rtMap);
         }
 

Modified: trunk/Tools/Maestro/Maestro.Editors/MapDefinition/LiveMapEditorRepositoryView.Designer.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/MapDefinition/LiveMapEditorRepositoryView.Designer.cs	2013-05-27 12:26:35 UTC (rev 7528)
+++ trunk/Tools/Maestro/Maestro.Editors/MapDefinition/LiveMapEditorRepositoryView.Designer.cs	2013-05-27 15:51:06 UTC (rev 7529)
@@ -81,6 +81,7 @@
             // 
             resources.ApplyResources(this.repoView, "repoView");
             this.repoView.Name = "repoView";
+            this.repoView.SelectOnDrag = true;
             this.repoView.ItemSelected += new System.EventHandler(this.repoView_ItemSelected);
             this.repoView.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(this.repoView_ItemDrag);
             // 

Modified: trunk/Tools/Maestro/Maestro.Editors/MapDefinition/MapSettingsSectionCtrl.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/MapDefinition/MapSettingsSectionCtrl.cs	2013-05-27 12:26:35 UTC (rev 7528)
+++ trunk/Tools/Maestro/Maestro.Editors/MapDefinition/MapSettingsSectionCtrl.cs	2013-05-27 15:51:06 UTC (rev 7529)
@@ -230,7 +230,6 @@
                     MessageBox.Show(Strings.ErrorMapExtentCalculationFailed, Strings.TitleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
-
         }
     }
 }

Modified: trunk/Tools/Maestro/Maestro.LiveMapEditor/MainForm.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.LiveMapEditor/MainForm.cs	2013-05-27 12:26:35 UTC (rev 7528)
+++ trunk/Tools/Maestro/Maestro.LiveMapEditor/MainForm.cs	2013-05-27 15:51:06 UTC (rev 7529)
@@ -26,6 +26,7 @@
 using System.Text;
 using System.Windows.Forms;
 using OSGeo.MapGuide.MaestroAPI;
+using OSGeo.MapGuide.MaestroAPI.CoordinateSystem;
 using Maestro.Editors.Generic;
 using Maestro.Editors.MapDefinition;
 using OSGeo.MapGuide.ObjectModels;
@@ -83,8 +84,8 @@
             ClearExistingEditor();
 
             var mdf = ObjectFactory.CreateMapDefinition(_conn, Strings.NewMap);
-            var diag = new MapSettingsDialog(_conn, mdf);
-            if (diag.ShowDialog() == System.Windows.Forms.DialogResult.OK)
+            var diag = new MapSettingsDialog(_conn, mdf, null);
+            //if (diag.ShowDialog() == System.Windows.Forms.DialogResult.OK)
             {
                 //Start off in the session, so the editor service knows this is a new resource
                 mdf.ResourceID = "Session:" + _conn.SessionID + "//NewMap.MapDefinition";
@@ -96,6 +97,8 @@
 
         private void LoadMapDefinitionForEditing(IMapDefinition mdf)
         {
+            CleanupExistingMap();
+
             if (mdf.BaseMap != null)
             {
                 if (mdf.BaseMap.GroupCount > 0)
@@ -106,10 +109,31 @@
 
             _mapEditor = new LiveMapDefinitionEditorCtrl();
             _mapEditor.Bind(new ResourceEditorService(mdf.ResourceID, _conn));
+            _mapEditor.Map.ComputeCoordSysAndExtentsOnFirstLayerAdded = _mapEditor.EditorService.IsNew;
+            if (_mapEditor.EditorService.IsNew)
+            {
+                _mapEditor.Map.CoordSysAndExtentsChangedFromFirstLayer += OnMapCoordSysAndExtentsChangedFromFirstLayer;
+            }
             _mapEditor.Dock = DockStyle.Fill;
             rootPanel.Controls.Add(_mapEditor);
         }
 
+        private void CleanupExistingMap()
+        {
+            if (_mapEditor != null)
+            {
+                if (_mapEditor.Map != null)
+                {
+                    _mapEditor.Map.CoordSysAndExtentsChangedFromFirstLayer -= OnMapCoordSysAndExtentsChangedFromFirstLayer;
+                }
+            }
+        }
+
+        void OnMapCoordSysAndExtentsChangedFromFirstLayer(object sender, EventArgs e)
+        {
+            _mapEditor.ReloadViewer();
+        }
+
         private void DoOpen()
         {
             ClearExistingEditor();
@@ -187,8 +211,18 @@
                 return;
 
             _mapEditor.SyncMap();
-            var diag = new MapSettingsDialog(_conn, _mapEditor.GetMapDefinition());
-            diag.ShowDialog();
+            var diag = new MapSettingsDialog(_conn, _mapEditor.GetMapDefinition(), _mapEditor.Viewer);
+            if (diag.ShowDialog() == System.Windows.Forms.DialogResult.OK)
+            {
+                CleanupExistingMap();
+                _mapEditor.RebuildRuntimeMap();
+                _mapEditor.Map.ComputeCoordSysAndExtentsOnFirstLayerAdded = _mapEditor.EditorService.IsNew;
+                if (_mapEditor.EditorService.IsNew)
+                {
+                    _mapEditor.Map.CoordSysAndExtentsChangedFromFirstLayer += OnMapCoordSysAndExtentsChangedFromFirstLayer;
+                }
+                _mapEditor.ReloadViewer();
+            }
         }
 
         private void aboutToolStripMenuItem_Click(object sender, EventArgs e)

Modified: trunk/Tools/Maestro/Maestro.LiveMapEditor/MapSettingsDialog.Designer.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.LiveMapEditor/MapSettingsDialog.Designer.cs	2013-05-27 12:26:35 UTC (rev 7528)
+++ trunk/Tools/Maestro/Maestro.LiveMapEditor/MapSettingsDialog.Designer.cs	2013-05-27 15:51:06 UTC (rev 7529)
@@ -29,7 +29,6 @@
         private void InitializeComponent()
         {
             System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MapSettingsDialog));
-            this.cmbBackgroundColor = new Maestro.Editors.Common.ColorComboBox();
             this.btnPickCs = new System.Windows.Forms.Button();
             this.txtCoordinateSystem = new System.Windows.Forms.TextBox();
             this.groupBox2 = new System.Windows.Forms.GroupBox();
@@ -47,15 +46,12 @@
             this.label2 = new System.Windows.Forms.Label();
             this.btnCancel = new System.Windows.Forms.Button();
             this.btnOK = new System.Windows.Forms.Button();
+            this.btnSetZoom = new System.Windows.Forms.Button();
+            this.btnUseCurrentView = new System.Windows.Forms.Button();
+            this.cmbBackgroundColor = new Maestro.Editors.Common.ColorComboBox();
             this.groupBox2.SuspendLayout();
             this.SuspendLayout();
             // 
-            // cmbBackgroundColor
-            // 
-            this.cmbBackgroundColor.FormattingEnabled = true;
-            resources.ApplyResources(this.cmbBackgroundColor, "cmbBackgroundColor");
-            this.cmbBackgroundColor.Name = "cmbBackgroundColor";
-            // 
             // btnPickCs
             // 
             resources.ApplyResources(this.btnPickCs, "btnPickCs");
@@ -166,11 +162,32 @@
             this.btnOK.UseVisualStyleBackColor = true;
             this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
             // 
+            // btnSetZoom
+            // 
+            resources.ApplyResources(this.btnSetZoom, "btnSetZoom");
+            this.btnSetZoom.Name = "btnSetZoom";
+            this.btnSetZoom.Click += new System.EventHandler(this.btnSetZoom_Click);
+            // 
+            // btnUseCurrentView
+            // 
+            resources.ApplyResources(this.btnUseCurrentView, "btnUseCurrentView");
+            this.btnUseCurrentView.Name = "btnUseCurrentView";
+            this.btnUseCurrentView.UseVisualStyleBackColor = true;
+            this.btnUseCurrentView.Click += new System.EventHandler(this.btnUseCurrentView_Click);
+            // 
+            // cmbBackgroundColor
+            // 
+            this.cmbBackgroundColor.FormattingEnabled = true;
+            resources.ApplyResources(this.cmbBackgroundColor, "cmbBackgroundColor");
+            this.cmbBackgroundColor.Name = "cmbBackgroundColor";
+            // 
             // MapSettingsDialog
             // 
             resources.ApplyResources(this, "$this");
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.ControlBox = false;
+            this.Controls.Add(this.btnUseCurrentView);
+            this.Controls.Add(this.btnSetZoom);
             this.Controls.Add(this.btnOK);
             this.Controls.Add(this.btnCancel);
             this.Controls.Add(this.cmbBackgroundColor);
@@ -207,6 +224,8 @@
         private System.Windows.Forms.Label label2;
         private System.Windows.Forms.Button btnCancel;
         private System.Windows.Forms.Button btnOK;
+        private System.Windows.Forms.Button btnSetZoom;
+        private System.Windows.Forms.Button btnUseCurrentView;
 
     }
 }
\ No newline at end of file

Modified: trunk/Tools/Maestro/Maestro.LiveMapEditor/MapSettingsDialog.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.LiveMapEditor/MapSettingsDialog.cs	2013-05-27 12:26:35 UTC (rev 7528)
+++ trunk/Tools/Maestro/Maestro.LiveMapEditor/MapSettingsDialog.cs	2013-05-27 15:51:06 UTC (rev 7529)
@@ -30,6 +30,8 @@
 using System.Globalization;
 using OSGeo.MapGuide.ObjectModels;
 using Maestro.Editors.Common;
+using Maestro.Editors.MapDefinition;
+using Maestro.MapViewer;
 
 namespace Maestro.LiveMapEditor
 {
@@ -37,11 +39,13 @@
     {
         private IMapDefinition _mdf;
         private IServerConnection _conn;
+        private IMapViewer _viewer;
 
-        public MapSettingsDialog(IServerConnection conn, IMapDefinition mdf)
+        public MapSettingsDialog(IServerConnection conn, IMapDefinition mdf, IMapViewer viewer)
         {
             InitializeComponent();
             _conn = conn;
+            _viewer = viewer;
             txtCoordinateSystem.Text = mdf.CoordinateSystem;
             var ext = mdf.Extents;
             txtLowerX.Text = ext.MinX.ToString(CultureInfo.InvariantCulture);
@@ -51,6 +55,7 @@
             cmbBackgroundColor.ResetColors();
             cmbBackgroundColor.CurrentColor = mdf.BackgroundColor;
             _mdf = mdf;
+            btnUseCurrentView.Visible = (_viewer != null);
         }
 
         private void btnCancel_Click(object sender, EventArgs e)
@@ -67,6 +72,7 @@
 
         private bool ValidateSettings()
         {
+            /*
             if (string.IsNullOrEmpty(txtCoordinateSystem.Text))
             {
                 MessageBox.Show(Strings.ErrCoordSysRequired);
@@ -75,8 +81,10 @@
             else
             {
                 _mdf.CoordinateSystem = txtCoordinateSystem.Text;
-            }
+            }*/
 
+            _mdf.CoordinateSystem = txtCoordinateSystem.Text;
+
             double llx;
             double lly;
             double urx;
@@ -94,6 +102,8 @@
                 _mdf.Extents = ObjectFactory.CreateEnvelope(llx, lly, urx, ury);
             }
 
+            _mdf.BackgroundColor = cmbBackgroundColor.CurrentColor;
+
             return true;
         }
 
@@ -108,5 +118,44 @@
                 }
             }
         }
+
+        private void btnSetZoom_Click(object sender, EventArgs e)
+        {
+            var diag = new ExtentCalculationDialog(_mdf);
+            if (diag.ShowDialog() == DialogResult.OK)
+            {
+                var env = diag.Extents;
+                if (env != null)
+                {
+                    _mdf.SetExtents(env.MinX, env.MinY, env.MaxX, env.MaxY);
+                    txtLowerX.Text = env.MinX.ToString(CultureInfo.InvariantCulture);
+                    txtLowerY.Text = env.MinY.ToString(CultureInfo.InvariantCulture);
+                    txtUpperX.Text = env.MaxX.ToString(CultureInfo.InvariantCulture);
+                    txtUpperY.Text = env.MaxY.ToString(CultureInfo.InvariantCulture);
+                }
+                else
+                {
+                    MessageBox.Show(Strings.ErrorMapExtentCalculationFailed, Strings.TitleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
+                }
+            }
+        }
+
+        private void btnUseCurrentView_Click(object sender, EventArgs e)
+        {
+            if (_viewer != null)
+            {
+                double minX;
+                double minY;
+                double maxX;
+                double maxY;
+                _viewer.GetViewExtent(out minX, out minY, out maxX, out maxY);
+                var ext = ObjectFactory.CreateEnvelope(minX, minY, maxX, maxY);
+                _mdf.Extents = ext;
+                txtLowerX.Text = ext.MinX.ToString(CultureInfo.InvariantCulture);
+                txtLowerY.Text = ext.MinY.ToString(CultureInfo.InvariantCulture);
+                txtUpperX.Text = ext.MaxX.ToString(CultureInfo.InvariantCulture);
+                txtUpperY.Text = ext.MaxY.ToString(CultureInfo.InvariantCulture);
+            }
+        }
     }
 }

Modified: trunk/Tools/Maestro/Maestro.LiveMapEditor/MapSettingsDialog.resx
===================================================================
--- trunk/Tools/Maestro/Maestro.LiveMapEditor/MapSettingsDialog.resx	2013-05-27 12:26:35 UTC (rev 7528)
+++ trunk/Tools/Maestro/Maestro.LiveMapEditor/MapSettingsDialog.resx	2013-05-27 15:51:06 UTC (rev 7529)
@@ -117,29 +117,6 @@
   <resheader name="writer">
     <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
   </resheader>
-  <assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
-  <data name="cmbBackgroundColor.Location" type="System.Drawing.Point, System.Drawing">
-    <value>140, 51</value>
-  </data>
-  <data name="cmbBackgroundColor.Size" type="System.Drawing.Size, System.Drawing">
-    <value>121, 21</value>
-  </data>
-  <assembly alias="mscorlib" name="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
-  <data name="cmbBackgroundColor.TabIndex" type="System.Int32, mscorlib">
-    <value>25</value>
-  </data>
-  <data name=">>cmbBackgroundColor.Name" xml:space="preserve">
-    <value>cmbBackgroundColor</value>
-  </data>
-  <data name=">>cmbBackgroundColor.Type" xml:space="preserve">
-    <value>Maestro.Editors.Common.ColorComboBox, Maestro.Editors, Version=5.0.0.6640, Culture=neutral, PublicKeyToken=f526c48929fda856</value>
-  </data>
-  <data name=">>cmbBackgroundColor.Parent" xml:space="preserve">
-    <value>$this</value>
-  </data>
-  <data name=">>cmbBackgroundColor.ZOrder" xml:space="preserve">
-    <value>2</value>
-  </data>
   <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
   <data name="btnPickCs.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
     <value>Top, Right</value>
@@ -147,12 +124,14 @@
   <data name="btnPickCs.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
     <value>NoControl</value>
   </data>
+  <assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
   <data name="btnPickCs.Location" type="System.Drawing.Point, System.Drawing">
     <value>393, 23</value>
   </data>
   <data name="btnPickCs.Size" type="System.Drawing.Size, System.Drawing">
     <value>28, 23</value>
   </data>
+  <assembly alias="mscorlib" name="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
   <data name="btnPickCs.TabIndex" type="System.Int32, mscorlib">
     <value>24</value>
   </data>
@@ -169,7 +148,7 @@
     <value>$this</value>
   </data>
   <data name=">>btnPickCs.ZOrder" xml:space="preserve">
-    <value>3</value>
+    <value>5</value>
   </data>
   <data name="txtCoordinateSystem.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
     <value>Top, Left, Right</value>
@@ -193,7 +172,7 @@
     <value>$this</value>
   </data>
   <data name=">>txtCoordinateSystem.ZOrder" xml:space="preserve">
-    <value>4</value>
+    <value>6</value>
   </data>
   <data name="groupBox2.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
     <value>Top, Left, Right</value>
@@ -466,7 +445,7 @@
     <value>$this</value>
   </data>
   <data name=">>groupBox2.ZOrder" xml:space="preserve">
-    <value>5</value>
+    <value>7</value>
   </data>
   <data name="label3.AutoSize" type="System.Boolean, mscorlib">
     <value>True</value>
@@ -496,7 +475,7 @@
     <value>$this</value>
   </data>
   <data name=">>label3.ZOrder" xml:space="preserve">
-    <value>6</value>
+    <value>8</value>
   </data>
   <data name="label2.AutoSize" type="System.Boolean, mscorlib">
     <value>True</value>
@@ -526,11 +505,14 @@
     <value>$this</value>
   </data>
   <data name=">>label2.ZOrder" xml:space="preserve">
-    <value>7</value>
+    <value>9</value>
   </data>
   <data name="btnCancel.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
     <value>Bottom, Right</value>
   </data>
+  <data name="btnCancel.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
+    <value>NoControl</value>
+  </data>
   <data name="btnCancel.Location" type="System.Drawing.Point, System.Drawing">
     <value>346, 182</value>
   </data>
@@ -553,11 +535,14 @@
     <value>$this</value>
   </data>
   <data name=">>btnCancel.ZOrder" xml:space="preserve">
-    <value>1</value>
+    <value>3</value>
   </data>
   <data name="btnOK.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
     <value>Bottom, Right</value>
   </data>
+  <data name="btnOK.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
+    <value>NoControl</value>
+  </data>
   <data name="btnOK.Location" type="System.Drawing.Point, System.Drawing">
     <value>265, 182</value>
   </data>
@@ -580,8 +565,92 @@
     <value>$this</value>
   </data>
   <data name=">>btnOK.ZOrder" xml:space="preserve">
+    <value>2</value>
+  </data>
+  <data name="btnSetZoom.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
+    <value>Bottom, Left</value>
+  </data>
+  <data name="btnSetZoom.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
+    <value>NoControl</value>
+  </data>
+  <data name="btnSetZoom.Location" type="System.Drawing.Point, System.Drawing">
+    <value>17, 182</value>
+  </data>
+  <data name="btnSetZoom.Size" type="System.Drawing.Size, System.Drawing">
+    <value>96, 23</value>
+  </data>
+  <data name="btnSetZoom.TabIndex" type="System.Int32, mscorlib">
+    <value>28</value>
+  </data>
+  <data name="btnSetZoom.Text" xml:space="preserve">
+    <value>Calculate Extent</value>
+  </data>
+  <data name=">>btnSetZoom.Name" xml:space="preserve">
+    <value>btnSetZoom</value>
+  </data>
+  <data name=">>btnSetZoom.Type" xml:space="preserve">
+    <value>System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </data>
+  <data name=">>btnSetZoom.Parent" xml:space="preserve">
+    <value>$this</value>
+  </data>
+  <data name=">>btnSetZoom.ZOrder" xml:space="preserve">
+    <value>1</value>
+  </data>
+  <data name="btnUseCurrentView.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
+    <value>Bottom, Left</value>
+  </data>
+  <data name="btnUseCurrentView.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
+    <value>NoControl</value>
+  </data>
+  <data name="btnUseCurrentView.Location" type="System.Drawing.Point, System.Drawing">
+    <value>119, 182</value>
+  </data>
+  <data name="btnUseCurrentView.Size" type="System.Drawing.Size, System.Drawing">
+    <value>80, 23</value>
+  </data>
+  <data name="btnUseCurrentView.TabIndex" type="System.Int32, mscorlib">
+    <value>29</value>
+  </data>
+  <data name="btnUseCurrentView.Text" xml:space="preserve">
+    <value>Current View</value>
+  </data>
+  <data name="btnUseCurrentView.Visible" type="System.Boolean, mscorlib">
+    <value>False</value>
+  </data>
+  <data name=">>btnUseCurrentView.Name" xml:space="preserve">
+    <value>btnUseCurrentView</value>
+  </data>
+  <data name=">>btnUseCurrentView.Type" xml:space="preserve">
+    <value>System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </data>
+  <data name=">>btnUseCurrentView.Parent" xml:space="preserve">
+    <value>$this</value>
+  </data>
+  <data name=">>btnUseCurrentView.ZOrder" xml:space="preserve">
     <value>0</value>
   </data>
+  <data name="cmbBackgroundColor.Location" type="System.Drawing.Point, System.Drawing">
+    <value>140, 51</value>
+  </data>
+  <data name="cmbBackgroundColor.Size" type="System.Drawing.Size, System.Drawing">
+    <value>121, 21</value>
+  </data>
+  <data name="cmbBackgroundColor.TabIndex" type="System.Int32, mscorlib">
+    <value>25</value>
+  </data>
+  <data name=">>cmbBackgroundColor.Name" xml:space="preserve">
+    <value>cmbBackgroundColor</value>
+  </data>
+  <data name=">>cmbBackgroundColor.Type" xml:space="preserve">
+    <value>Maestro.Editors.Common.ColorComboBox, Maestro.Editors, Version=5.0.0.6640, Culture=neutral, PublicKeyToken=f526c48929fda856</value>
+  </data>
+  <data name=">>cmbBackgroundColor.Parent" xml:space="preserve">
+    <value>$this</value>
+  </data>
+  <data name=">>cmbBackgroundColor.ZOrder" xml:space="preserve">
+    <value>4</value>
+  </data>
   <metadata name="$this.Localizable" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     <value>True</value>
   </metadata>
@@ -591,6 +660,9 @@
   <data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing">
     <value>433, 217</value>
   </data>
+  <data name="$this.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
+    <value>NoControl</value>
+  </data>
   <data name="$this.StartPosition" type="System.Windows.Forms.FormStartPosition, System.Windows.Forms">
     <value>CenterParent</value>
   </data>

Modified: trunk/Tools/Maestro/Maestro.LiveMapEditor/Program.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.LiveMapEditor/Program.cs	2013-05-27 12:26:35 UTC (rev 7528)
+++ trunk/Tools/Maestro/Maestro.LiveMapEditor/Program.cs	2013-05-27 15:51:06 UTC (rev 7529)
@@ -25,6 +25,9 @@
 using OSGeo.MapGuide.ExtendedObjectModels;
 using Maestro.Editors.Preview;
 using System.Diagnostics;
+using System.Reflection;
+using OSGeo.MapGuide.MaestroAPI;
+using OSGeo.MapGuide.MaestroAPI.CoordinateSystem;
 
 namespace Maestro.LiveMapEditor
 {
@@ -56,10 +59,48 @@
             //property is set
             ResourcePreviewerFactory.RegisterPreviewer("Maestro.LocalNative", new LocalMapPreviewer(new StubPreviewer(), urlLauncher)); //NOXLATE
 
+            //Can't use this code, it requires a call to MgdPlatform.Initialize which we can't call indirectly :(
+            /*
+            //Try to tap into mg-desktop coordinate system services if possible
+            try
+            {
+                var provEntry = ConnectionProviderRegistry.FindProvider("Maestro.Local"); //NOXLATE
+                if (provEntry != null)
+                {
+                    string path = provEntry.AssemblyPath;
+                    Assembly asm = Assembly.LoadFrom(path); //NOXLATE
+                    if (asm != null)
+                    {
+                        Type mpuType = asm.GetType("OSGeo.MapGuide.MaestroAPI.Native.LocalNativeMpuCalculator"); //NOXLATE
+                        Type catType = asm.GetType("OSGeo.MapGuide.MaestroAPI.Native.LocalNativeCoordinateSystemCatalog"); //NOXLATE
+
+                        if (mpuType != null && catType != null)
+                        {
+                            IMpuCalculator calc = (IMpuCalculator)Activator.CreateInstance(mpuType);
+                            ICoordinateSystemCatalog csCatalog = (ICoordinateSystemCatalog)Activator.CreateInstance(catType);
+
+                            CsHelper.DefaultCalculator = calc;
+                            CsHelper.DefaultCatalog = csCatalog;
+                            Debug.WriteLine("Using mg-desktop coordinate system services where possible");
+                        }
+                    }
+                }
+                else
+                {
+                    Debug.WriteLine("No mg-desktop coordinate system services to tap into. Using default services");
+                }
+            }
+            catch (Exception ex)
+            {
+
+            }
+             */
+
             var login = new Login.LoginDialog();
             if (login.ShowDialog() == DialogResult.OK)
             {
                 var conn = login.Connection;
+
                 //TODO: Validate connection capabilities
                 Application.Run(new MainForm(conn));
             }

Modified: trunk/Tools/Maestro/Maestro.LiveMapEditor/Strings.Designer.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.LiveMapEditor/Strings.Designer.cs	2013-05-27 12:26:35 UTC (rev 7528)
+++ trunk/Tools/Maestro/Maestro.LiveMapEditor/Strings.Designer.cs	2013-05-27 15:51:06 UTC (rev 7529)
@@ -1,7 +1,7 @@
 //------------------------------------------------------------------------------
 // <auto-generated>
 //     This code was generated by a tool.
-//     Runtime Version:4.0.30319.17929
+//     Runtime Version:4.0.30319.18047
 //
 //     Changes to this file may cause incorrect behavior and will be lost if
 //     the code is regenerated.
@@ -97,6 +97,15 @@
         }
         
         /// <summary>
+        ///   Looks up a localized string similar to Could not transform extents of any layer in this Map Definition. You will have to specify the extents manually..
+        /// </summary>
+        internal static string ErrorMapExtentCalculationFailed {
+            get {
+                return ResourceManager.GetString("ErrorMapExtentCalculationFailed", resourceCulture);
+            }
+        }
+        
+        /// <summary>
         ///   Looks up a localized string similar to New Map.
         /// </summary>
         internal static string NewMap {
@@ -115,6 +124,15 @@
         }
         
         /// <summary>
+        ///   Looks up a localized string similar to Error.
+        /// </summary>
+        internal static string TitleError {
+            get {
+                return ResourceManager.GetString("TitleError", resourceCulture);
+            }
+        }
+        
+        /// <summary>
         ///   Looks up a localized string similar to Tiled Map Support.
         /// </summary>
         internal static string TitleTiledMap {

Modified: trunk/Tools/Maestro/Maestro.LiveMapEditor/Strings.resx
===================================================================
--- trunk/Tools/Maestro/Maestro.LiveMapEditor/Strings.resx	2013-05-27 12:26:35 UTC (rev 7528)
+++ trunk/Tools/Maestro/Maestro.LiveMapEditor/Strings.resx	2013-05-27 15:51:06 UTC (rev 7529)
@@ -129,12 +129,18 @@
   <data name="ErrInvalidExtents" xml:space="preserve">
     <value>Extents are invalid or empty</value>
   </data>
+  <data name="ErrorMapExtentCalculationFailed" xml:space="preserve">
+    <value>Could not transform extents of any layer in this Map Definition. You will have to specify the extents manually.</value>
+  </data>
   <data name="NewMap" xml:space="preserve">
     <value>New Map</value>
   </data>
   <data name="TiledMapNote" xml:space="preserve">
     <value>Because this map has tiled layers, the RenderMap API will be used instead of the normal RenderDynamicOverlay API for map images</value>
   </data>
+  <data name="TitleError" xml:space="preserve">
+    <value>Error</value>
+  </data>
   <data name="TitleTiledMap" xml:space="preserve">
     <value>Tiled Map Support</value>
   </data>

Modified: trunk/Tools/Maestro/Maestro.MapViewer/MapViewer.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.MapViewer/MapViewer.cs	2013-05-27 12:26:35 UTC (rev 7528)
+++ trunk/Tools/Maestro/Maestro.MapViewer/MapViewer.cs	2013-05-27 15:51:06 UTC (rev 7529)
@@ -1688,10 +1688,11 @@
         
         public void GetViewExtent(out double minX, out double minY, out double maxX, out double maxY)
         {
+            //NOTE: Something strange about the AJAX viewer code we grafted this from. Y2 is not the max Y, Y1 is the max Y.
             minX = _extX1;
-            minY = _extY1;
+            minY = _extY2;
             maxX = _extX2;
-            maxY = _extY2;
+            maxY = _extY1;
         }
 
         private bool PruneHistoryEntriesFromCurrentView()

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/ConnectionProviderRegistry.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/ConnectionProviderRegistry.cs	2013-05-27 12:26:35 UTC (rev 7528)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/ConnectionProviderRegistry.cs	2013-05-27 15:51:06 UTC (rev 7529)
@@ -55,18 +55,24 @@
         /// you pass in
         /// </summary>
         public bool HasGlobalState { get; private set; }
+        /// <summary>
+        /// Gets the path of the assembly containing the provider implementation
+        /// </summary>
+        public string AssemblyPath { get; private set; }
 
         /// <summary>
         /// Initializes a new instance of the <see cref="ConnectionProviderEntry"/> class.
         /// </summary>
         /// <param name="name">The name.</param>
         /// <param name="desc">The desc.</param>
+        /// <param name="asmPath">The assembly path</param>
         /// <param name="multiPlatform">if set to <c>true</c> [multi platform].</param>
-        public ConnectionProviderEntry(string name, string desc, bool multiPlatform)
+        internal ConnectionProviderEntry(string name, string desc, string asmPath, bool multiPlatform)
         {
             this.Name = name;
             this.Description = desc;
             this.IsMultiPlatform = multiPlatform;
+            this.AssemblyPath = asmPath;
         }
     }
 
@@ -176,7 +182,7 @@
                             IServerConnection conn = (IServerConnection)impl.InvokeMember(null, flags, null, null, new object[] { initParams });
                             return conn;
                         });
-                        _providers.Add(new ConnectionProviderEntry(name, desc, attr[0].IsMultiPlatform));
+                        _providers.Add(new ConnectionProviderEntry(name, desc, dll, attr[0].IsMultiPlatform));
                         _callCount[name] = 0;
                     }
                 }
@@ -335,11 +341,12 @@
             return CreateConnection(provider, initP);
         }
 
-        private static ConnectionProviderEntry FindProvider(string provider)
+        public static ConnectionProviderEntry FindProvider(string provider)
         {
+            string cmp = provider.ToUpper();
             foreach (var prv in _providers)
             {
-                if (prv.Name == provider)
+                if (prv.Name == cmp)
                     return prv;
             }
 

Added: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/CsHelper.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/CsHelper.cs	                        (rev 0)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/CsHelper.cs	2013-05-27 15:51:06 UTC (rev 7529)
@@ -0,0 +1,78 @@
+#region Disclaimer / License
+// Copyright (C) 2013, Jackie Ng
+// http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie at gmail.com
+// 
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// 
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+// 
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+// 
+#endregion
+using OSGeo.MapGuide.MaestroAPI.CoordinateSystem;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using System.Text;
+
+namespace OSGeo.MapGuide.MaestroAPI
+{
+    /// <summary>
+    /// An interface for calculating meters-per-unit values
+    /// </summary>
+    public interface IMpuCalculator
+    {
+        /// <summary>
+        /// Calculates the meters-per-unit value
+        /// </summary>
+        /// <param name="csWkt">The coordinate system wkt</param>
+        /// <param name="units">The number of units</param>
+        /// <returns></returns>
+        double Calculate(string csWkt, double units);
+    }
+
+    /// <summary>
+    /// Provides application-level overrides for coordinate system related functionality.
+    /// </summary>
+    public static class CsHelper
+    {
+        private static IMpuCalculator sm_defaultCalculator;
+
+        /// <summary>
+        /// Gets or sets the default calculator
+        /// </summary>
+        public static IMpuCalculator DefaultCalculator
+        {
+            get { return sm_defaultCalculator; }
+            set
+            {
+                sm_defaultCalculator = value;
+                Debug.WriteLineIf((value != null), "Registered default MPU calculator: " + value.GetType().ToString());
+            }
+        }
+
+        private static ICoordinateSystemCatalog sm_defaultCatalog;
+
+        /// <summary>
+        /// Gets or sets the default catalog
+        /// </summary>
+        public static ICoordinateSystemCatalog DefaultCatalog
+        {
+            get { return sm_defaultCatalog; }
+            set
+            { 
+                sm_defaultCatalog = value;
+                Debug.WriteLineIf((value != null), "Registered default CS catalog: " + value.GetType().ToString());
+            }
+        }
+    }
+}

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/IServerConnection.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/IServerConnection.cs	2013-05-27 12:26:35 UTC (rev 7528)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/IServerConnection.cs	2013-05-27 15:51:06 UTC (rev 7529)
@@ -204,6 +204,12 @@
         /// Raised when a outbound request has been dispatched
         /// </summary>
         event RequestEventHandler RequestDispatched;
+
+        /// <summary>
+        /// Returns a meters-per-unit calculator
+        /// </summary>
+        /// <returns></returns>
+        IMpuCalculator GetCalculator();
     }
 
     /// <summary>

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMap.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMap.cs	2013-05-27 12:26:35 UTC (rev 7528)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMap.cs	2013-05-27 15:51:06 UTC (rev 7529)
@@ -132,6 +132,12 @@
         /// </summary>
         public IServerConnection CurrentConnection { get; private set; }
 
+        /// <summary>
+        /// If set to true. The first layer added to this map will automatically compute the map's extents and coordinate system
+        /// based on the first layer.
+        /// </summary>
+        public bool ComputeCoordSysAndExtentsOnFirstLayerAdded { get; set; }
+
         internal Version SiteVersion { get; private set; }
 
         /// <summary>
@@ -159,6 +165,7 @@
         /// <param name="conn"></param>
         protected internal RuntimeMap(IServerConnection conn)
         {
+            this.ComputeCoordSysAndExtentsOnFirstLayerAdded = false;
             this.StrictSelection = true;
             this.IsDirty = false;
             _disableChangeTracking = true;
@@ -1482,8 +1489,44 @@
             TrackChange(layer.ObjectId, true, Change.ChangeType.removed, string.Empty);
         }
 
+        /// <summary>
+        /// Raised when <see cref="P:OSGeo.MapGuide.MaestroAPI.Mapping.RuntimeMap.ComputeCoordSysAndExtentsOnFirstLayerAdded"/> is true
+        /// and the first layer was added the map extents and coordinate system were successfully computed from that layer
+        /// </summary>
+        public event EventHandler CoordSysAndExtentsChangedFromFirstLayer;
+
         internal void OnLayerAdded(RuntimeMapLayer layer)
         {
+            if (this.ComputeCoordSysAndExtentsOnFirstLayerAdded && this.Layers.Count == 1)
+            {
+                Debug.WriteLine("Computing map extents and CS based on first layer added");
+                try
+                {
+                    ILayerDefinition layerDef = (ILayerDefinition)this.ResourceService.GetResource(layer.LayerDefinitionID);
+                    string wkt;
+                    IEnvelope env = layerDef.GetSpatialExtent(true, out wkt);
+
+                    this.MapExtent = env;
+                    this.CoordinateSystem = wkt;
+                    if (CsHelper.DefaultCalculator != null)
+                    {
+                        this.MetersPerUnit = CsHelper.DefaultCalculator.Calculate(wkt, 1.0);
+                    }
+                    else
+                    {
+                        var calc = this.CurrentConnection.GetCalculator();
+                        this.MetersPerUnit = calc.Calculate(wkt, 1.0);
+                    }
+                    Debug.WriteLine("Computed map extents and CS");
+                    var h = this.CoordSysAndExtentsChangedFromFirstLayer;
+                    if (h != null)
+                        h(this, EventArgs.Empty);
+                }
+                catch (Exception ex)
+                {
+                    Debug.WriteLine("Uh-Oh: " + ex.ToString());
+                }
+            }
             //Fix the draw order of this layer that was added
             
             //???
@@ -1679,6 +1722,9 @@
 
             var baseGroups = new List<RuntimeMapGroup>();
 
+            newMdf.CoordinateSystem = this.CoordinateSystem;
+            newMdf.Extents = this.MapExtent;
+
             //Add dynamic groups
             for (int i = this.Groups.Count - 1; i >= 0; i--)
             {

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/OSGeo.MapGuide.MaestroAPI.csproj
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/OSGeo.MapGuide.MaestroAPI.csproj	2013-05-27 12:26:35 UTC (rev 7528)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/OSGeo.MapGuide.MaestroAPI.csproj	2013-05-27 15:51:06 UTC (rev 7529)
@@ -247,6 +247,7 @@
     <Compile Include="IO\NsDoc.cs" />
     <Compile Include="Mapping\Collections.cs" />
     <Compile Include="Mapping\NsDoc.cs" />
+    <Compile Include="CsHelper.cs" />
     <Compile Include="NsDoc.cs" />
     <Compile Include="ObjectModels\CommonTypes.cs" />
     <Compile Include="ObjectModels\IFdoSpatialContext.cs" />

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/PlatformConnectionBase.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/PlatformConnectionBase.cs	2013-05-27 12:26:35 UTC (rev 7528)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/PlatformConnectionBase.cs	2013-05-27 15:51:06 UTC (rev 7529)
@@ -1885,6 +1885,26 @@
             catch { return 1.0; }
         }
 
+        class DefaultCalculator : IMpuCalculator
+        {
+            private PlatformConnectionBase _conn;
+
+            public DefaultCalculator(PlatformConnectionBase conn)
+            {
+                _conn = conn;
+            }
+
+            public double Calculate(string csWkt, double units)
+            {
+                return _conn.InferMPU(csWkt, units);
+            }
+        }
+
+        public virtual IMpuCalculator GetCalculator()
+        {
+            return new DefaultCalculator(this);
+        }
+
         /// <summary>
         /// Creates the map group.
         /// </summary>
@@ -1996,7 +2016,11 @@
         public RuntimeMap CreateMap(string runtimeMapResourceId, string baseMapDefinitionId)
         {
             var mdf = (IMapDefinition)GetResource(baseMapDefinitionId);
-            var mpu = InferMPU(mdf.CoordinateSystem, 1.0);
+            double mpu = 1.0;
+            if (CsHelper.DefaultCalculator != null)
+                mpu = CsHelper.DefaultCalculator.Calculate(mdf.CoordinateSystem, 1.0);
+            else
+                mpu = InferMPU(mdf.CoordinateSystem, 1.0);
             return CreateMap(runtimeMapResourceId, mdf, mpu);
         }
 
@@ -2054,7 +2078,11 @@
         /// <returns></returns>
         public RuntimeMap CreateMap(string runtimeMapResourceId, IMapDefinition mdf)
         {
-            var mpu = InferMPU(mdf.CoordinateSystem, 1.0);
+            double mpu = 1.0;
+            if (CsHelper.DefaultCalculator != null)
+                mpu = CsHelper.DefaultCalculator.Calculate(mdf.CoordinateSystem, 1.0);
+            else
+                mpu = InferMPU(mdf.CoordinateSystem, 1.0);
             return CreateMap(runtimeMapResourceId, mdf, mpu);
         }
 

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Utility.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Utility.cs	2013-05-27 12:26:35 UTC (rev 7528)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Utility.cs	2013-05-27 15:51:06 UTC (rev 7529)
@@ -943,7 +943,15 @@
         {
             try
             {
-                var trans = new DefaultSimpleTransform(srcCsWkt, dstCsWkt);
+                ISimpleTransform trans = null;
+                if (CsHelper.DefaultCatalog != null)
+                {
+                    trans = CsHelper.DefaultCatalog.CreateTransform(srcCsWkt, dstCsWkt);
+                }
+                else
+                {
+                    trans = new DefaultSimpleTransform(srcCsWkt, dstCsWkt);
+                }
 
                 var oldExt = env;
 
@@ -1421,9 +1429,9 @@
         }
 
         /// <summary>
-        /// Replaces all references of the given resource id
+        /// Replaces all references of the given resource id.
         /// </summary>
-        /// <param name="doc">A resource document</param>
+        /// <param name="doc">A resource document. Any replacements will modify the XmlDocument that is passed in</param>
         /// <param name="srcId">The resource id to replace</param>
         /// <param name="dstId">The resource id to replace with</param>
         /// <returns>true if a replacement was made. false if no replacements were made</returns>

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Local/LocalConnection.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Local/LocalConnection.cs	2013-05-27 12:26:35 UTC (rev 7528)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Local/LocalConnection.cs	2013-05-27 15:51:06 UTC (rev 7529)
@@ -96,17 +96,6 @@
             get { return PROVIDER_NAME; }
         }
 
-        public static ConnectionProviderEntry ProviderInfo
-        {
-            get
-            {
-                return new ConnectionProviderEntry(
-                    PROVIDER_NAME,
-                    "Connection using the MapGuide Desktop API", //LOCALIZEME
-                    false);
-            }
-        }
-
         public override System.Collections.Specialized.NameValueCollection CloneParameters
         {
             get 
@@ -951,6 +940,15 @@
             throw new UnsupportedServiceTypeException(st);
         }
 
+        private LocalNativeMpuCalculator m_calc;
+
+        public override IMpuCalculator GetCalculator()
+        {
+            if (null == m_calc)
+                m_calc = new LocalNativeMpuCalculator();
+            return m_calc;
+        }
+
         private ICoordinateSystemCatalog m_coordsys = null;
 
         public OSGeo.MapGuide.MaestroAPI.CoordinateSystem.ICoordinateSystemCatalog CoordinateSystemCatalog
@@ -1072,11 +1070,6 @@
             }
         }
 
-        protected override double InferMPU(string csWkt, double units)
-        {
-            return base.InferMPU(csWkt, units);
-        }
-
         public override Mapping.RuntimeMap OpenMap(string runtimeMapResourceId)
         {
             throw new NotSupportedException();

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeConnection.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeConnection.cs	2013-05-27 12:26:35 UTC (rev 7528)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeConnection.cs	2013-05-27 15:51:06 UTC (rev 7529)
@@ -164,25 +164,6 @@
 			}
 		}
 
-        protected override double InferMPU(string csWkt, double units)
-        {
-            try
-            {
-                MgCoordinateSystemFactory csFact = new MgCoordinateSystemFactory();
-                MgCoordinateSystem cs = csFact.Create(csWkt);
-                return cs.ConvertCoordinateSystemUnitsToMeters(units);
-            }
-            catch (MgException ex) //Not implemented due to wrapping Proj.4?
-            {
-                ex.Dispose();
-                return base.InferMPU(csWkt, units);
-            }
-            catch (Exception) //Binding to assembly with pre-refactored CS API?
-            {
-                return base.InferMPU(csWkt, units);
-            }
-        }
-
         private void LogMethodCall(string method, bool success, params object[] values)
         {
             string[] strValues = new string[values.Length];
@@ -492,7 +473,16 @@
             }
 		}
 
+        private LocalNativeMpuCalculator m_calc;
 
+        public override IMpuCalculator GetCalculator()
+        {
+            if (null == m_calc)
+                m_calc = new LocalNativeMpuCalculator();
+            return m_calc;
+        }
+
+
         private ICoordinateSystemCatalog m_coordsys = null;
         //TODO: Figure out a strategy for cache invalidation 
         

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeCoordinateSystem.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeCoordinateSystem.cs	2013-05-27 12:26:35 UTC (rev 7528)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeCoordinateSystem.cs	2013-05-27 15:51:06 UTC (rev 7529)
@@ -25,6 +25,19 @@
 
 namespace OSGeo.MapGuide.MaestroAPI.Native
 {
+    public class LocalNativeMpuCalculator : IMpuCalculator
+    {
+        private MgCoordinateSystemFactory _csFact;
+
+        public LocalNativeMpuCalculator() { _csFact = new MgCoordinateSystemFactory(); }
+
+        public double Calculate(string csWkt, double units)
+        {
+            MgCoordinateSystem cs = _csFact.Create(csWkt);
+            return cs.ConvertCoordinateSystemUnitsToMeters(units);
+        }
+    }
+
     public class LocalNativeCoordinateSystemDefinition : CoordinateSystemDefinitionBase
     {
         internal LocalNativeCoordinateSystemDefinition() : base() { }

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeCoordinateSystemCatalog.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeCoordinateSystemCatalog.cs	2013-05-27 12:26:35 UTC (rev 7528)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeCoordinateSystemCatalog.cs	2013-05-27 15:51:06 UTC (rev 7529)
@@ -30,7 +30,7 @@
         private string m_coordLib = null;
         internal OSGeo.MapGuide.MgCoordinateSystemFactory m_cf;
 
-        internal LocalNativeCoordinateSystemCatalog()
+        public LocalNativeCoordinateSystemCatalog()
         {
             m_cf = new MgCoordinateSystemFactory();
         }



More information about the mapguide-commits mailing list