[mapguide-commits] r5482 - in sandbox/maestro-3.0: Maestro
Maestro.Editors/MapDefinition Maestro.Editors/Properties
OSGeo.MapGuide.MaestroAPI OSGeo.MapGuide.MaestroAPI/CoordinateSystem
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Wed Dec 22 01:37:17 EST 2010
Author: jng
Date: 2010-12-21 22:37:17 -0800 (Tue, 21 Dec 2010)
New Revision: 5482
Added:
sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/ISimpleTransform.cs
Modified:
sandbox/maestro-3.0/Maestro.Editors/MapDefinition/MapSettingsSectionCtrl.cs
sandbox/maestro-3.0/Maestro.Editors/Properties/Resources.Designer.cs
sandbox/maestro-3.0/Maestro.Editors/Properties/Resources.resx
sandbox/maestro-3.0/Maestro/Maestro_All.sln
sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/OSGeo.MapGuide.MaestroAPI.csproj
Log:
Fix #1578: Attempt re-projection of extents when changing coordinate systems in Map Editor. Note we're not using CS-Map due to the desire of maintaining Mono compatibility, but instead using a pre-existing coordinate transformation functionality of the TF.NET library we're using, so some transformations will fail.
Modified: sandbox/maestro-3.0/Maestro/Maestro_All.sln
===================================================================
--- sandbox/maestro-3.0/Maestro/Maestro_All.sln 2010-12-22 04:40:33 UTC (rev 5481)
+++ sandbox/maestro-3.0/Maestro/Maestro_All.sln 2010-12-22 06:37:17 UTC (rev 5482)
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 10.00
-# Visual C# Express 2008
+# Visual Studio 2008
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Maestro", "Maestro.csproj", "{E0C36475-2B70-4F6D-ACE0-8943167806DC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.Core", "..\Thirdparty\SharpDevelop\ICSharpCode.Core\ICSharpCode.Core.csproj", "{35CEF10F-2D4C-45F2-9DD1-161E0FEC583C}"
@@ -9,8 +9,6 @@
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Maestro.Base", "..\Maestro.Base\Maestro.Base.csproj", "{F1E2F468-5030-4DBA-968C-9620284AFAA1}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MaestroBaseTests", "..\MaestroBaseTests\MaestroBaseTests.csproj", "{CE5F281C-0162-4832-87BB-A677D13D116F}"
-EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MaestroFsPreview", "..\MaestroFsPreview\MaestroFsPreview.csproj", "{59BE5E18-17B6-431D-836E-C0AABA6D69E8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Maestro.AddIn.ExtendedObjectModels", "..\Maestro.AddIn.ExtendedObjectModels\Maestro.AddIn.ExtendedObjectModels.csproj", "{32BA7DF6-1AFA-441D-9231-5624C5920706}"
@@ -71,10 +69,6 @@
{F1E2F468-5030-4DBA-968C-9620284AFAA1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F1E2F468-5030-4DBA-968C-9620284AFAA1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F1E2F468-5030-4DBA-968C-9620284AFAA1}.Release|Any CPU.Build.0 = Release|Any CPU
- {CE5F281C-0162-4832-87BB-A677D13D116F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {CE5F281C-0162-4832-87BB-A677D13D116F}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {CE5F281C-0162-4832-87BB-A677D13D116F}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {CE5F281C-0162-4832-87BB-A677D13D116F}.Release|Any CPU.Build.0 = Release|Any CPU
{59BE5E18-17B6-431D-836E-C0AABA6D69E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{59BE5E18-17B6-431D-836E-C0AABA6D69E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{59BE5E18-17B6-431D-836E-C0AABA6D69E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
Modified: sandbox/maestro-3.0/Maestro.Editors/MapDefinition/MapSettingsSectionCtrl.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Editors/MapDefinition/MapSettingsSectionCtrl.cs 2010-12-22 04:40:33 UTC (rev 5481)
+++ sandbox/maestro-3.0/Maestro.Editors/MapDefinition/MapSettingsSectionCtrl.cs 2010-12-22 06:37:17 UTC (rev 5482)
@@ -31,6 +31,7 @@
using OSGeo.MapGuide.MaestroAPI;
using OSGeo.MapGuide.ObjectModels.MapDefinition;
using System.Globalization;
+using OSGeo.MapGuide.MaestroAPI.CoordinateSystem;
namespace Maestro.Editors.MapDefinition
{
@@ -152,7 +153,11 @@
_map.Extents.MaxY = d;
};
- _map.Extents.PropertyChanged += (sender, e) => { OnResourceChanged(); };
+ _map.Extents.PropertyChanged += (sender, e) =>
+ {
+ UpdateExtentsFromMap();
+ OnResourceChanged();
+ };
}
private void UpdateExtentsFromMap()
@@ -176,7 +181,35 @@
string cs = _service.GetCoordinateSystem();
if (!string.IsNullOrEmpty(cs))
{
+ string oldCs = txtCoordinateSystem.Text;
txtCoordinateSystem.Text = cs;
+ if (_map.Extents != null && !string.IsNullOrEmpty(oldCs) && !string.IsNullOrEmpty(cs) && !oldCs.Equals(cs))
+ {
+ //Transform current extents
+ try
+ {
+ var trans = new DefaultSimpleTransform(oldCs, cs);
+
+ var oldExt = _map.Extents;
+
+ double llx;
+ double lly;
+ double urx;
+ double ury;
+
+ trans.Transform(oldExt.MinX, oldExt.MinY, out llx, out lly);
+ trans.Transform(oldExt.MaxX, oldExt.MaxY, out urx, out ury);
+
+ _map.Extents.MinX = llx;
+ _map.Extents.MinY = lly;
+ _map.Extents.MaxX = urx;
+ _map.Extents.MaxY = ury;
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(string.Format(Properties.Resources.CoordinateTransformationFailed, ex.Message));
+ }
+ }
}
}
Modified: sandbox/maestro-3.0/Maestro.Editors/Properties/Resources.Designer.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Editors/Properties/Resources.Designer.cs 2010-12-22 04:40:33 UTC (rev 5481)
+++ sandbox/maestro-3.0/Maestro.Editors/Properties/Resources.Designer.cs 2010-12-22 06:37:17 UTC (rev 5482)
@@ -231,22 +231,22 @@
}
/// <summary>
- /// Looks up a localized string similar to "ColorName","NumOfColors","Type","CritVal","ColorNum","ColorLetter","R","G","B","SchemeType"
- ///"Accent",3,"qual",,1,"A",127,201,127,"Qualitative"
- ///,,,,2,"B",190,174,212,
- ///,,,,3,"C",253,192,134,
- ///"Accent",4,"qual",,1,"A",127,201,127,
- ///,,,,2,"B",190,174,212,
- ///,,,,3,"C",253,192,134,
- ///,,,,4,"D",255,255,153,
- ///"Accent",5,"qual",,1,"A",127,201,127,
- ///,,,,2,"B",190,174,212,
- ///,,,,3,"C",253,192,134,
- ///,,,,4,"D",255,255,153,
- ///,,,,5,"E",56,108,176,
- ///"Accent",6,"qual",,1,"A",127,201,127,
- ///,,,,2,"B",190,174,212,
- ///,,,,3,"C",253,192,134,
+ /// Looks up a localized string similar to "ColorName","NumOfColors","Type","CritVal","ColorNum","ColorLetter","R","G","B","SchemeType"
+ ///"Accent",3,"qual",,1,"A",127,201,127,"Qualitative"
+ ///,,,,2,"B",190,174,212,
+ ///,,,,3,"C",253,192,134,
+ ///"Accent",4,"qual",,1,"A",127,201,127,
+ ///,,,,2,"B",190,174,212,
+ ///,,,,3,"C",253,192,134,
+ ///,,,,4,"D",255,255,153,
+ ///"Accent",5,"qual",,1,"A",127,201,127,
+ ///,,,,2,"B",190,174,212,
+ ///,,,,3,"C",253,192,134,
+ ///,,,,4,"D",255,255,153,
+ ///,,,,5,"E",56,108,176,
+ ///"Accent",6,"qual",,1,"A",127,201,127,
+ ///,,,,2,"B",190,174,212,
+ ///,,,,3,"C",253,192,134,
///,, [rest of string was truncated]";.
/// </summary>
internal static string ColorBrewer {
@@ -350,6 +350,15 @@
}
}
+ /// <summary>
+ /// Looks up a localized string similar to Failed to transform coordinates: {0}.
+ /// </summary>
+ internal static string CoordinateTransformationFailed {
+ get {
+ return ResourceManager.GetString("CoordinateTransformationFailed", resourceCulture);
+ }
+ }
+
internal static System.Drawing.Bitmap cross {
get {
object obj = ResourceManager.GetObject("cross", resourceCulture);
Modified: sandbox/maestro-3.0/Maestro.Editors/Properties/Resources.resx
===================================================================
--- sandbox/maestro-3.0/Maestro.Editors/Properties/Resources.resx 2010-12-22 04:40:33 UTC (rev 5481)
+++ sandbox/maestro-3.0/Maestro.Editors/Properties/Resources.resx 2010-12-22 06:37:17 UTC (rev 5482)
@@ -1070,4 +1070,7 @@
<data name="SelectLayerFirst" xml:space="preserve">
<value>Please select the layer first</value>
</data>
+ <data name="CoordinateTransformationFailed" xml:space="preserve">
+ <value>Failed to transform coordinates: {0}</value>
+ </data>
</root>
\ No newline at end of file
Added: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/ISimpleTransform.cs
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/ISimpleTransform.cs (rev 0)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/ISimpleTransform.cs 2010-12-22 06:37:17 UTC (rev 5482)
@@ -0,0 +1,84 @@
+#region Disclaimer / License
+// Copyright (C) 2010, 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 System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace OSGeo.MapGuide.MaestroAPI.CoordinateSystem
+{
+ /// <summary>
+ /// A simple coordinate transformation interface
+ /// </summary>
+ public interface ISimpleTransform
+ {
+ /// <summary>
+ /// Transforms the specified point
+ /// </summary>
+ /// <param name="x">The X coordinate</param>
+ /// <param name="y">The Y coordinate</param>
+ /// <param name="tx">The transformed X coordinate</param>
+ /// <param name="ty">The transformed Y coordinate</param>
+ void Transform(double x, double y, out double tx, out double ty);
+ }
+
+ /// <summary>
+ /// A simple transform that wraps the NTS coordinate system transformation APIs
+ ///
+ /// This does not handle some of the more complex transformations like CS-Map can,
+ /// such as WGS84.PseudoMercator (required for Google/Yahoo/Bing underlays in fusion)
+ /// </summary>
+ public class DefaultSimpleTransform : ISimpleTransform
+ {
+ private Topology.CoordinateSystems.ICoordinateSystem _source;
+ private Topology.CoordinateSystems.ICoordinateSystem _target;
+ private Topology.CoordinateSystems.Transformations.ICoordinateTransformation _trans;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="DefaultSimpleTransform"/> class.
+ /// </summary>
+ /// <param name="sourceCsWkt">The source cs WKT.</param>
+ /// <param name="targetCsWkt">The target cs WKT.</param>
+ public DefaultSimpleTransform(string sourceCsWkt, string targetCsWkt)
+ {
+ var fact = new Topology.CoordinateSystems.CoordinateSystemFactory();
+ _source = fact.CreateFromWkt(sourceCsWkt);
+ _target = fact.CreateFromWkt(targetCsWkt);
+ var tfact = new Topology.CoordinateSystems.Transformations.CoordinateTransformationFactory();
+ _trans = tfact.CreateFromCoordinateSystems(_source, _target);
+ }
+
+ /// <summary>
+ /// Transforms the specified point
+ /// </summary>
+ /// <param name="x">The X coordinate</param>
+ /// <param name="y">The Y coordinate</param>
+ /// <param name="tx">The transformed X coordinate</param>
+ /// <param name="ty">The transformed Y coordinate</param>
+ public void Transform(double x, double y, out double tx, out double ty)
+ {
+ tx = Double.NaN;
+ ty = Double.NaN;
+
+ double [] pts = _trans.MathTransform.Transform(new double[] { x, y });
+ tx = pts[0];
+ ty = pts[1];
+ }
+ }
+}
Modified: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/OSGeo.MapGuide.MaestroAPI.csproj
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/OSGeo.MapGuide.MaestroAPI.csproj 2010-12-22 04:40:33 UTC (rev 5481)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/OSGeo.MapGuide.MaestroAPI.csproj 2010-12-22 06:37:17 UTC (rev 5482)
@@ -184,6 +184,7 @@
<Compile Include="CoordinateSystem\DegreeBasedCoordinateSystem.cs" />
<Compile Include="CoordinateSystem\CoordinateSystemBase.cs" />
<Compile Include="CoordinateSystem\FeetBasedCoordinateSystem.cs" />
+ <Compile Include="CoordinateSystem\ISimpleTransform.cs" />
<Compile Include="CoordinateSystem\MeterBasedCoordinateSystem.cs" />
<Compile Include="Exceptions\CustomPropertyNotFoundException.cs" />
<Compile Include="Exceptions\ExpressionException.cs" />
More information about the mapguide-commits
mailing list