[mapguide-commits] r7996 - in trunk/Tools/Maestro: Maestro.Base/Commands/SiteExplorer Maestro.Editors Maestro.Editors/Preview OSGeo.MapGuide.MaestroAPI/ObjectModels

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Fri Mar 28 01:54:10 PDT 2014


Author: jng
Date: 2014-03-28 01:54:10 -0700 (Fri, 28 Mar 2014)
New Revision: 7996

Modified:
   trunk/Tools/Maestro/Maestro.Base/Commands/SiteExplorer/GetLayerSpatialContextCommand.cs
   trunk/Tools/Maestro/Maestro.Editors/Preview/ResourcePreviewEngine.cs
   trunk/Tools/Maestro/Maestro.Editors/Strings.Designer.cs
   trunk/Tools/Maestro/Maestro.Editors/Strings.resx
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/ObjectModels/LayerInterfaceExtensions.cs
Log:
#2415: Fix incorrect layer preview from a multi-SC feature source. The problem was that GetSpatialExtents() always used the extent of the first spatial context, and not the one with the matching name as specified by the geometry property. This submission fixes that, and unifies such logic into a new GetSpatialContext() extension method for ILayerDefinition, which the implementation of #2411 now uses.

Modified: trunk/Tools/Maestro/Maestro.Base/Commands/SiteExplorer/GetLayerSpatialContextCommand.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Commands/SiteExplorer/GetLayerSpatialContextCommand.cs	2014-03-21 14:20:46 UTC (rev 7995)
+++ trunk/Tools/Maestro/Maestro.Base/Commands/SiteExplorer/GetLayerSpatialContextCommand.cs	2014-03-28 08:54:10 UTC (rev 7996)
@@ -72,31 +72,21 @@
                                     if (ltype == LayerType.Vector ||
                                         ltype == LayerType.Raster)
                                     {
-                                        var sContexts = conn.FeatureService.GetSpatialContextInfo(ldf.SubLayer.ResourceId, false);
-                                        if (ltype == LayerType.Vector)
+                                        var sc = ldf.GetSpatialContext();
+                                        if (sc == null)
                                         {
-                                            IVectorLayerDefinition vl = (IVectorLayerDefinition)ldf.SubLayer;
-                                            var clsDef = conn.FeatureService.GetClassDefinition(vl.ResourceId, vl.FeatureName);
-                                            var geom = clsDef.FindProperty(vl.Geometry) as GeometricPropertyDefinition;
-                                            if (geom != null)
+                                            if (ltype == LayerType.Vector)
                                             {
-                                                var sc = FindSpatialContext(sContexts, geom.SpatialContextAssociation);
-                                                return sc;
+                                                IVectorLayerDefinition vl = (IVectorLayerDefinition)ldf.SubLayer;
+                                                throw new SpatialContextNotFoundException(string.Format(Strings.GeometryPropertyNotFound, vl.Geometry));
                                             }
-                                            throw new SpatialContextNotFoundException(string.Format(Strings.GeometryPropertyNotFound, vl.Geometry));
-                                        }
-                                        else if (ltype == LayerType.Raster)
-                                        {
-                                            IRasterLayerDefinition rl = (IRasterLayerDefinition)ldf.SubLayer;
-                                            var clsDef = conn.FeatureService.GetClassDefinition(rl.ResourceId, rl.FeatureName);
-                                            var geom = clsDef.FindProperty(rl.Geometry) as RasterPropertyDefinition;
-                                            if (geom != null)
+                                            else //Raster
                                             {
-                                                var sc = FindSpatialContext(sContexts, geom.SpatialContextAssociation);
-                                                return sc;
+                                                IRasterLayerDefinition rl = (IRasterLayerDefinition)ldf.SubLayer;
+                                                throw new SpatialContextNotFoundException(string.Format(Strings.RasterPropertyNotFound, rl.Geometry));
                                             }
-                                            throw new SpatialContextNotFoundException(string.Format(Strings.RasterPropertyNotFound, rl.Geometry));
                                         }
+                                        return sc;
                                     }
                                     else
                                     {
@@ -107,7 +97,6 @@
                                 {
                                     throw new SpatialContextNotFoundException(string.Format(Strings.NonApplicableLayerType, ldf.SubLayer.LayerType));
                                 }
-                                return null;
                             }, (res, ex) => {
                                 if (ex != null)
                                 {

Modified: trunk/Tools/Maestro/Maestro.Editors/Preview/ResourcePreviewEngine.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/Preview/ResourcePreviewEngine.cs	2014-03-21 14:20:46 UTC (rev 7995)
+++ trunk/Tools/Maestro/Maestro.Editors/Preview/ResourcePreviewEngine.cs	2014-03-28 08:54:10 UTC (rev 7996)
@@ -19,6 +19,7 @@
 #endregion
 using OSGeo.MapGuide.MaestroAPI;
 using OSGeo.MapGuide.MaestroAPI.Resource;
+using OSGeo.MapGuide.MaestroAPI.Schema;
 using OSGeo.MapGuide.ObjectModels;
 using OSGeo.MapGuide.ObjectModels.ApplicationDefinition;
 using OSGeo.MapGuide.ObjectModels.LayerDefinition;
@@ -117,19 +118,34 @@
             return url;
         }
 
-        static string CreateDebugWatermark(IMapDefinition2 mdf, IServerConnection conn)
+        static string CreateDebugWatermark(IMapDefinition2 mdf, IServerConnection conn, string layerSc)
         {
             //Tidy up the CS WKT so that it can display nicely in a watermark
             StringBuilder cleanCs = new StringBuilder(mdf.CoordinateSystem);
             cleanCs.Replace("[", "[\n");
             cleanCs.Replace("],", "],\n");
 
-            string message = string.Format(Strings.DebugWatermarkMessage,
-                mdf.Extents.MinX,
-                mdf.Extents.MinY,
-                mdf.Extents.MaxX,
-                mdf.Extents.MaxY,
-                cleanCs.ToString());
+            string message = null;
+
+            if (!string.IsNullOrEmpty(layerSc))
+            {
+                message = string.Format(Strings.DebugWatermarkMessageLayer,
+                    mdf.Extents.MinX,
+                    mdf.Extents.MinY,
+                    mdf.Extents.MaxX,
+                    mdf.Extents.MaxY,
+                    cleanCs.ToString(),
+                    layerSc);
+            }
+            else
+            {
+                message = string.Format(Strings.DebugWatermarkMessage,
+                    mdf.Extents.MinX,
+                    mdf.Extents.MinY,
+                    mdf.Extents.MaxX,
+                    mdf.Extents.MaxY,
+                    cleanCs.ToString());
+            }
             string watermarkXml = string.Format(Properties.Resources.TextWatermark, message);
             string resId = "Session:" + conn.SessionID + "//Debug.WatermarkDefinition";
             using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(watermarkXml)))
@@ -153,11 +169,13 @@
             if (extent == null)
                 throw new ApplicationException(Strings.FailedToCalculateFeatureSourceExtents);
 
+            string layerSc = GetLayerSpatialContext(ldf);
+
             //TODO: Based on the visible scales in this layer, size this extents accordingly
             var mdf = ObjectFactory.CreateMapDefinition(conn, Strings.PreviewMap, csWkt, extent);
             IMapDefinition2 mdf2 = mdf as IMapDefinition2;
             if (mdf2 != null && PreviewSettings.AddDebugWatermark)
-                CreateDebugWatermark(mdf2, conn);
+                CreateDebugWatermark(mdf2, conn, layerSc);
             
             var layer = mdf.AddLayer(null, layerName, ldf.ResourceID);
             conn.ResourceService.SaveResourceAs(mdf, mdfId);
@@ -165,6 +183,28 @@
             return mdf;
         }
 
+        private static string GetLayerSpatialContext(ILayerDefinition ldf)
+        {
+            var conn = ldf.CurrentConnection;
+            var rl = ldf.SubLayer as IRasterLayerDefinition;
+            var vl = ldf.SubLayer as IVectorLayerDefinition;
+            if (vl != null)
+            {
+                var cls = conn.FeatureService.GetClassDefinition(vl.ResourceId, vl.FeatureName);
+                var gp = cls.FindProperty(vl.Geometry) as GeometricPropertyDefinition;
+                if (gp != null)
+                    return gp.SpatialContextAssociation;
+            }
+            else if (rl != null)
+            {
+                var cls = conn.FeatureService.GetClassDefinition(rl.ResourceId, rl.FeatureName);
+                var rp = cls.FindProperty(rl.Geometry) as RasterPropertyDefinition;
+                if (rp != null)
+                    return rp.SpatialContextAssociation;
+            }
+            return null;
+        }
+
         private static void AttachPreviewCommands(IWebLayout wl)
         {
             var cmd = wl.CreateInvokeScriptCommand();
@@ -257,7 +297,7 @@
             var conn = mdf.CurrentConnection;
             IMapDefinition2 mdf2 = mdf as IMapDefinition2;
             if (mdf2 != null && PreviewSettings.AddDebugWatermark)
-                CreateDebugWatermark(mdf2, conn);
+                CreateDebugWatermark(mdf2, conn, null);
             conn.ResourceService.SaveResourceAs(mdf, mdfId);
 
             //if (PropertyService.Get(ConfigProperties.PreviewViewerType, "AJAX").Equals("AJAX")) //NOXLATE

Modified: trunk/Tools/Maestro/Maestro.Editors/Strings.Designer.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/Strings.Designer.cs	2014-03-21 14:20:46 UTC (rev 7995)
+++ trunk/Tools/Maestro/Maestro.Editors/Strings.Designer.cs	2014-03-28 08:54:10 UTC (rev 7996)
@@ -448,6 +448,15 @@
         }
         
         /// <summary>
+        ///   Looks up a localized string similar to MapGuide Debugging Information\n==============================\n\nMap Extents Min: ({0}, {1})\nMap Extents Max: ({2}, {3})\nMap Coordinate System: \n{4}\nLayer Spatial Context: {5}.
+        /// </summary>
+        internal static string DebugWatermarkMessageLayer {
+            get {
+                return ResourceManager.GetString("DebugWatermarkMessageLayer", resourceCulture);
+            }
+        }
+        
+        /// <summary>
         ///   Looks up a localized string similar to Delete Command.
         /// </summary>
         internal static string DeleteCommand {

Modified: trunk/Tools/Maestro/Maestro.Editors/Strings.resx
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/Strings.resx	2014-03-21 14:20:46 UTC (rev 7995)
+++ trunk/Tools/Maestro/Maestro.Editors/Strings.resx	2014-03-28 08:54:10 UTC (rev 7996)
@@ -1557,4 +1557,7 @@
   <data name="DebugWatermarkMessage" xml:space="preserve">
     <value>MapGuide Debugging Information\n==============================\n\nMap Extents Min: ({0}, {1})\nMap Extents Max: ({2}, {3})\nMap Coordinate System: \n{4}</value>
   </data>
+  <data name="DebugWatermarkMessageLayer" xml:space="preserve">
+    <value>MapGuide Debugging Information\n==============================\n\nMap Extents Min: ({0}, {1})\nMap Extents Max: ({2}, {3})\nMap Coordinate System: \n{4}\nLayer Spatial Context: {5}</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	2014-03-21 14:20:46 UTC (rev 7995)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/ObjectModels/LayerInterfaceExtensions.cs	2014-03-28 08:54:10 UTC (rev 7996)
@@ -195,7 +195,69 @@
             return string.Empty;
         }
 
+        static IFdoSpatialContext FindSpatialContext(FdoSpatialContextList spatialContexts, string scName)
+        {
+            foreach (IFdoSpatialContext sc in spatialContexts.SpatialContext)
+            {
+                if (sc.Name == scName)
+                    return sc;
+            }
+            return null;
+        }
+
         /// <summary>
+        /// Returns the associated spatial context for this Layer Definition
+        /// </summary>
+        /// <param name="layer"></param>
+        /// <returns></returns>
+        public static IFdoSpatialContext GetSpatialContext(this ILayerDefinition layer)
+        {
+            Check.NotNull(layer, "layer"); //NOXLATE
+            if (layer.CurrentConnection == null)
+                throw new System.Exception(OSGeo.MapGuide.MaestroAPI.Strings.ErrorNoServerConnectionAttached);
+
+            var conn = layer.CurrentConnection;
+            var ltype = layer.SubLayer.LayerType;
+            if (ltype == LayerType.Vector ||
+                ltype == LayerType.Raster)
+            {
+                var sContexts = conn.FeatureService.GetSpatialContextInfo(layer.SubLayer.ResourceId, false);
+                if (ltype == LayerType.Vector)
+                {
+                    IVectorLayerDefinition vl = (IVectorLayerDefinition)layer.SubLayer;
+                    var clsDef = conn.FeatureService.GetClassDefinition(vl.ResourceId, vl.FeatureName);
+                    var geom = clsDef.FindProperty(vl.Geometry) as GeometricPropertyDefinition;
+                    if (geom != null)
+                    {
+                        var sc = FindSpatialContext(sContexts, geom.SpatialContextAssociation);
+                        return sc;
+                    }
+                    return null;
+                }
+                else if (ltype == LayerType.Raster)
+                {
+                    IRasterLayerDefinition rl = (IRasterLayerDefinition)layer.SubLayer;
+                    var clsDef = conn.FeatureService.GetClassDefinition(rl.ResourceId, rl.FeatureName);
+                    var geom = clsDef.FindProperty(rl.Geometry) as RasterPropertyDefinition;
+                    if (geom != null)
+                    {
+                        var sc = FindSpatialContext(sContexts, geom.SpatialContextAssociation);
+                        return sc;
+                    }
+                    return null;
+                }
+                else
+                {
+                    return null;
+                }
+            }
+            else
+            {
+                return null;
+            }
+        }
+
+        /// <summary>
         /// Returns the spatial extent of the data.
         /// This is calculated by asking the underlying featuresource for the minimum rectangle that
         /// contains all the features in the specified table. If the <paramref name="allowFallbackToContextInformation"/>
@@ -222,14 +284,13 @@
                         IFdoSpatialContext activeSc = null;
                         try
                         {
-                            var scList = conn.FeatureService.GetSpatialContextInfo(layer.SubLayer.ResourceId, true);
-                            if (scList.SpatialContext.Count > 0)
+                            activeSc = layer.GetSpatialContext();
+                            if (activeSc != null)
                             {
-                                activeSc = scList.SpatialContext[0];
+                                //TODO: Check if ones like SQL Server will return the WKT, otherwise we'll need to bring in the
+                                //CS catalog to do CS code to WKT conversion.
+                                csWkt = activeSc.CoordinateSystemWkt;
                             }
-                            //TODO: Check if ones like SQL Server will return the WKT, otherwise we'll need to bring in the
-                            //CS catalog to do CS code to WKT conversion.
-                            csWkt = activeSc.CoordinateSystemWkt;
 
                             //This can fail if SpatialExtents() aggregate function is not supported
                             env = conn.FeatureService.GetSpatialExtent(layer.SubLayer.ResourceId, ((IVectorLayerDefinition)layer.SubLayer).FeatureName, ((IVectorLayerDefinition)layer.SubLayer).Geometry);



More information about the mapguide-commits mailing list