[mapguide-commits] r5823 - in trunk/Tools/Maestro:
Maestro.Editors/MapDefinition Maestro.Editors/Properties
OSGeo.MapGuide.MaestroAPI/ObjectModels
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Fri May 20 07:31:31 EDT 2011
Author: jng
Date: 2011-05-20 04:31:31 -0700 (Fri, 20 May 2011)
New Revision: 5823
Modified:
trunk/Tools/Maestro/Maestro.Editors/MapDefinition/MapSettingsSectionCtrl.cs
trunk/Tools/Maestro/Maestro.Editors/Properties/Resources.Designer.cs
trunk/Tools/Maestro/Maestro.Editors/Properties/Resources.resx
trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/ObjectModels/LayerInterfaceExtensions.cs
Log:
#1698: Notify the user if some or all extents failed transformation to Map's Coordinate System
Modified: trunk/Tools/Maestro/Maestro.Editors/MapDefinition/MapSettingsSectionCtrl.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/MapDefinition/MapSettingsSectionCtrl.cs 2011-05-20 06:00:49 UTC (rev 5822)
+++ trunk/Tools/Maestro/Maestro.Editors/MapDefinition/MapSettingsSectionCtrl.cs 2011-05-20 11:31:31 UTC (rev 5823)
@@ -32,6 +32,7 @@
using OSGeo.MapGuide.ObjectModels.MapDefinition;
using System.Globalization;
using OSGeo.MapGuide.MaestroAPI.CoordinateSystem;
+using OSGeo.MapGuide.ObjectModels;
namespace Maestro.Editors.MapDefinition
{
@@ -239,39 +240,84 @@
}
}
}
- var env = Util.GetCombinedExtents(layers);
-
- _map.SetExtents(env.MinX, env.MinY, env.MaxX, env.MaxY);
+
+ var env = Util.GetCombinedExtents(_map, layers);
+ if (env != null)
+ {
+ _map.SetExtents(env.MinX, env.MinY, env.MaxX, env.MaxY);
+ MessageBox.Show(Properties.Resources.WarningMapExtentCalculation, Properties.Resources.TitleWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
+ }
+ else
+ {
+ MessageBox.Show(Properties.Resources.ErrorMapExtentCalculationFailed, Properties.Resources.TitleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
}
}
internal class Util
{
- public static IEnvelope GetCombinedExtents(IEnumerable<ILayerDefinition> layers)
+ public static IEnvelope GetCombinedExtents(IMapDefinition mapDef, IEnumerable<ILayerDefinition> layers)
{
Check.NotNull(layers, "layers");
IEnvelope env = null;
foreach (var layer in layers)
{
var e1 = layer.GetSpatialExtent(true);
- if (env == null)
+ var wkt = layer.GetCoordinateSystemWkt();
+ if (wkt != mapDef.CoordinateSystem)
{
- env = e1;
+ e1 = TransformEnvelope(e1, wkt, mapDef.CoordinateSystem);
}
+
+ if (e1 != null)
+ {
+ if (env == null)
+ {
+ env = e1;
+ }
+ else
+ {
+ if (e1.MinX < env.MinX)
+ env.MinX = e1.MinX;
+ if (e1.MinY < env.MinY)
+ env.MinY = e1.MinY;
+ if (e1.MaxX > env.MaxX)
+ env.MaxX = e1.MaxX;
+ if (e1.MaxY > env.MaxY)
+ env.MaxY = e1.MaxY;
+ }
+ }
else
{
- if (e1.MinX < env.MinX)
- env.MinX = e1.MinX;
- if (e1.MinY < env.MinY)
- env.MinY = e1.MinY;
- if (e1.MaxX > env.MaxX)
- env.MaxX = e1.MaxX;
- if (e1.MaxY > env.MaxY)
- env.MaxY = e1.MaxY;
+ System.Diagnostics.Trace.TraceWarning("Could not transform extent of layer " + layer.ResourceID + " to the map definition's coordinate system. Extents ignored");
}
}
return env;
}
+
+ private static IEnvelope TransformEnvelope(IEnvelope env, string srcCsWkt, string dstCsWkt)
+ {
+ try
+ {
+ var trans = new DefaultSimpleTransform(srcCsWkt, dstCsWkt);
+
+ var oldExt = env;
+
+ 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);
+
+ return ObjectFactory.CreateEnvelope(llx, lly, urx, ury);
+ }
+ catch
+ {
+ return null;
+ }
+ }
}
}
}
Modified: trunk/Tools/Maestro/Maestro.Editors/Properties/Resources.Designer.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/Properties/Resources.Designer.cs 2011-05-20 06:00:49 UTC (rev 5822)
+++ trunk/Tools/Maestro/Maestro.Editors/Properties/Resources.Designer.cs 2011-05-20 11:31:31 UTC (rev 5823)
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
-// Runtime Version:2.0.50727.4952
+// Runtime Version:2.0.50727.4959
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
@@ -547,6 +547,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);
+ }
+ }
+
internal static System.Drawing.Bitmap exclamation {
get {
object obj = ResourceManager.GetObject("exclamation", resourceCulture);
@@ -2540,6 +2549,15 @@
}
/// <summary>
+ /// Looks up a localized string similar to Warning.
+ /// </summary>
+ internal static string TitleWarning {
+ get {
+ return ResourceManager.GetString("TitleWarning", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to The selected column contains more than {0} different values, and thus cannot be used for theming with individual values.
/// </summary>
internal static string TooManyIndiviualValuesError {
@@ -2680,6 +2698,15 @@
}
/// <summary>
+ /// Looks up a localized string similar to Could not transform extents of one or more layers in this Map Definition. These extents have not been factored into the computed result..
+ /// </summary>
+ internal static string WarningMapExtentCalculation {
+ get {
+ return ResourceManager.GetString("WarningMapExtentCalculation", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to A widget named {0} already exists.
/// </summary>
internal static string WidgetNameExists {
Modified: trunk/Tools/Maestro/Maestro.Editors/Properties/Resources.resx
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/Properties/Resources.resx 2011-05-20 06:00:49 UTC (rev 5822)
+++ trunk/Tools/Maestro/Maestro.Editors/Properties/Resources.resx 2011-05-20 11:31:31 UTC (rev 5823)
@@ -1169,4 +1169,13 @@
<data name="InvalidConnection" xml:space="preserve">
<value>This is not a valid connection: {0}</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="TitleWarning" xml:space="preserve">
+ <value>Warning</value>
+ </data>
+ <data name="WarningMapExtentCalculation" xml:space="preserve">
+ <value>Could not transform extents of one or more layers in this Map Definition. These extents have not been factored into the computed result.</value>
+ </data>
</root>
\ No newline at end of file
Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/ObjectModels/LayerInterfaceExtensions.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/ObjectModels/LayerInterfaceExtensions.cs 2011-05-20 06:00:49 UTC (rev 5822)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/ObjectModels/LayerInterfaceExtensions.cs 2011-05-20 11:31:31 UTC (rev 5823)
@@ -219,6 +219,87 @@
return string.Empty;
}
+ public static IEnvelope GetSpatialExtent(this ILayerDefinition layer, bool allowFallbackToContextInformation, out string csWkt)
+ {
+ csWkt = null;
+ Check.NotNull(layer, "layer");
+ if (layer.CurrentConnection == null)
+ throw new System.Exception("No server set for object");
+
+ var conn = layer.CurrentConnection;
+ switch (layer.SubLayer.LayerType)
+ {
+ case LayerType.Vector:
+ {
+ IEnvelope env = null;
+ try
+ {
+ env = conn.FeatureService.GetSpatialExtent(layer.SubLayer.ResourceId, ((IVectorLayerDefinition)layer.SubLayer).FeatureName, ((IVectorLayerDefinition)layer.SubLayer).Geometry);
+ return env;
+ }
+ catch //Default to extents of active spatial context
+ {
+ var scList = conn.FeatureService.GetSpatialContextInfo(layer.SubLayer.ResourceId, true);
+ if (scList.SpatialContext.Count > 0)
+ {
+ var sc = scList.SpatialContext[0];
+ return ObjectFactory.CreateEnvelope(
+ Convert.ToDouble(sc.Extent.LowerLeftCoordinate.X),
+ Convert.ToDouble(sc.Extent.LowerLeftCoordinate.Y),
+ Convert.ToDouble(sc.Extent.UpperRightCoordinate.X),
+ Convert.ToDouble(sc.Extent.UpperRightCoordinate.Y));
+ }
+ return null;
+ }
+ }
+ case LayerType.Raster:
+ {
+ IEnvelope env = null;
+ try
+ {
+ env = conn.FeatureService.GetSpatialExtent(layer.SubLayer.ResourceId, ((IRasterLayerDefinition)layer.SubLayer).FeatureName, ((IRasterLayerDefinition)layer.SubLayer).Geometry);
+ return env;
+ }
+ catch //Default to extents of active spatial context
+ {
+ var scList = conn.FeatureService.GetSpatialContextInfo(layer.SubLayer.ResourceId, true);
+ if (scList.SpatialContext.Count > 0)
+ {
+ var sc = scList.SpatialContext[0];
+ return ObjectFactory.CreateEnvelope(
+ Convert.ToDouble(sc.Extent.LowerLeftCoordinate.X),
+ Convert.ToDouble(sc.Extent.LowerLeftCoordinate.Y),
+ Convert.ToDouble(sc.Extent.UpperRightCoordinate.X),
+ Convert.ToDouble(sc.Extent.UpperRightCoordinate.Y));
+ }
+ return null;
+ }
+ }
+ default:
+ {
+ int[] services = conn.Capabilities.SupportedServices;
+ if (Array.IndexOf(services, (int)ServiceType.Drawing) >= 0)
+ {
+ var sheet = ((IDrawingLayerDefinition)layer.SubLayer).Sheet;
+ var dws = (IDrawingSource)conn.ResourceService.GetResource(((IDrawingLayerDefinition)layer.SubLayer).ResourceId);
+
+ if (dws.Sheet != null)
+ {
+ //find matching sheet
+ foreach (var sht in dws.Sheet)
+ {
+ if (sheet.Equals(sht.Name))
+ {
+ return ObjectFactory.CreateEnvelope(sht.Extent.MinX, sht.Extent.MinY, sht.Extent.MaxX, sht.Extent.MaxY);
+ }
+ }
+ }
+ }
+ return null;
+ }
+ }
+ }
+
/// <summary>
/// Returns the spatial extent of the data.
/// This is calculated by asking the underlying featuresource for the minimum rectangle that
More information about the mapguide-commits
mailing list