[mapguide-commits] r6310 - in trunk/Tools/Maestro: MaestroAPITests OSGeo.MapGuide.MaestroAPI OSGeo.MapGuide.MaestroAPI/Mapping OSGeo.MapGuide.MaestroAPI/Services SDK/SamplesWeb/SamplesWeb/Tasks

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Thu Dec 8 06:22:22 EST 2011


Author: jng
Date: 2011-12-08 03:22:21 -0800 (Thu, 08 Dec 2011)
New Revision: 6310

Modified:
   trunk/Tools/Maestro/MaestroAPITests/RuntimeMapTests.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMap.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapLayer.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/PlatformConnectionBase.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Services/IMappingService.cs
   trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/AddThemedDistrictsLayer.aspx.cs
   trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/AddTracksLayer.aspx.cs
   trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/ModifyParcelsFilter.aspx.cs
   trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/ToggleParcelsLayer.aspx.cs
Log:
Delegate RuntimeMapLayer creation to IMappingService implementations. This should be the last breaking API change before the final 4.0 release. The web sample has also been updated to use the modified APIs

Modified: trunk/Tools/Maestro/MaestroAPITests/RuntimeMapTests.cs
===================================================================
--- trunk/Tools/Maestro/MaestroAPITests/RuntimeMapTests.cs	2011-12-08 10:18:25 UTC (rev 6309)
+++ trunk/Tools/Maestro/MaestroAPITests/RuntimeMapTests.cs	2011-12-08 11:22:21 UTC (rev 6310)
@@ -726,7 +726,7 @@
             Assert.NotNull(map.Groups["Group2"]);
             Assert.Null(map.Groups["Group3"]);
 
-            var layer = new RuntimeMapLayer(map, (ILayerDefinition)resSvc.GetResource("Library://UnitTests/Layers/HydrographicPolygons.LayerDefinition"));
+            var layer = mapSvc.CreateMapLayer(map, (ILayerDefinition)resSvc.GetResource("Library://UnitTests/Layers/HydrographicPolygons.LayerDefinition"));
             layer.Group = "Group1";
 
             map.Layers.Insert(0, layer);
@@ -735,7 +735,7 @@
             Assert.True(map.Layers["HydrographicPolygons"] == map.Layers[0]);
             Assert.NotNull(map.Layers.GetByObjectId(layer.ObjectId));
 
-            var layer2 = new RuntimeMapLayer(map, (ILayerDefinition)resSvc.GetResource("Library://UnitTests/Layers/Parcels.LayerDefinition"));
+            var layer2 = mapSvc.CreateMapLayer(map, (ILayerDefinition)resSvc.GetResource("Library://UnitTests/Layers/Parcels.LayerDefinition"));
             map.Layers.Insert(0, layer2);
             layer2.Group = "Group1"; //Intentional
 
@@ -751,7 +751,7 @@
             //The important one
             Assert.True(map.Layers[0].DisplayOrder < map.Layers[1].DisplayOrder);
 
-            var layer3 = new RuntimeMapLayer(map, (ILayerDefinition)resSvc.GetResource("Library://UnitTests/Layers/Rail.LayerDefinition"));
+            var layer3 = mapSvc.CreateMapLayer(map, (ILayerDefinition)resSvc.GetResource("Library://UnitTests/Layers/Rail.LayerDefinition"));
             layer3.Group = "Group2";
             map.Layers.Insert(0, layer3);
             Assert.AreEqual(3, map.Layers.Count);
@@ -850,7 +850,7 @@
             Assert.NotNull(map.Groups["Group2"]);
             Assert.Null(map.Groups["Group3"]);
 
-            var layer = new RuntimeMapLayer(map, (ILayerDefinition)resSvc.GetResource("Library://UnitTests/Layers/HydrographicPolygons.LayerDefinition"));
+            var layer = mapSvc.CreateMapLayer(map, (ILayerDefinition)resSvc.GetResource("Library://UnitTests/Layers/HydrographicPolygons.LayerDefinition"));
             layer.Group = "Group1";
 
             map.Layers.Add(layer);
@@ -859,7 +859,7 @@
             Assert.True(map.Layers["HydrographicPolygons"] == map.Layers[0]);
             Assert.NotNull(map.Layers.GetByObjectId(layer.ObjectId));
 
-            var layer2 = new RuntimeMapLayer(map, (ILayerDefinition)resSvc.GetResource("Library://UnitTests/Layers/Parcels.LayerDefinition"));
+            var layer2 = mapSvc.CreateMapLayer(map, (ILayerDefinition)resSvc.GetResource("Library://UnitTests/Layers/Parcels.LayerDefinition"));
             map.Layers.Add(layer2);
             layer2.Group = "Group1"; //Intentional
 
@@ -875,7 +875,7 @@
             //The important one
             Assert.True(map.Layers[0].DisplayOrder < map.Layers[1].DisplayOrder);
 
-            var layer3 = new RuntimeMapLayer(map, (ILayerDefinition)resSvc.GetResource("Library://UnitTests/Layers/Rail.LayerDefinition"));
+            var layer3 = mapSvc.CreateMapLayer(map, (ILayerDefinition)resSvc.GetResource("Library://UnitTests/Layers/Rail.LayerDefinition"));
             layer3.Group = "Group2";
             map.Layers.Add(layer3);
             Assert.AreEqual(3, map.Layers.Count);

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMap.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMap.cs	2011-12-08 10:18:25 UTC (rev 6309)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMap.cs	2011-12-08 11:22:21 UTC (rev 6310)
@@ -244,7 +244,12 @@
             this.DataExtent = mdf.Extents.Clone();
             this.BackgroundColor = mdf.BackgroundColor;
             this.CoordinateSystem = mdf.CoordinateSystem;
-            
+
+            if (Array.IndexOf(this.CurrentConnection.Capabilities.SupportedServices, (int)ServiceType.Mapping) < 0)
+                throw new InvalidOperationException("The Map Definition originates from an incompatible IServerConnection implementation");
+
+            IMappingService mappingSvc = (IMappingService)this.CurrentConnection.GetService((int)ServiceType.Mapping);
+
             //TODO: infer real mpu from coordinate system
 
             //If a setup helper exists, use it to get required layers in a single
@@ -267,7 +272,7 @@
             //Load map layers
             foreach (var layer in mdf.MapLayer)
             {
-                var rtl = new RuntimeMapLayer(this, layer, GetLayerDefinition(layer.ResourceId));
+                var rtl = mappingSvc.CreateMapLayer(this, layer);
                 this.Layers.Add(rtl);
             }
 
@@ -288,7 +293,8 @@
                     {
                         foreach (var layer in group.BaseMapLayer)
                         {
-                            var rtl = new RuntimeMapLayer(this, layer, GetLayerDefinition(layer.ResourceId)) { Visible = true };
+                            var rtl = mappingSvc.CreateMapLayer(this, layer);
+                            rtl.Visible = true;
                             rtl.Type = RuntimeMapLayer.kBaseMap;
                             this.Layers.Add(rtl);
                         }
@@ -919,12 +925,19 @@
 
             while (mapLayerCount-- > 0)
             {
-                RuntimeMapLayer t = new RuntimeMapLayer(this);
-                t.Deserialize(d);
+                RuntimeMapLayer t = DeserializeLayer(d);
                 this.Layers.Add(t);
             }
         }
 
+        private RuntimeMapLayer DeserializeLayer(MgBinaryDeserializer d)
+        {
+            //TODO: Review when we split to specific implementations
+            RuntimeMapLayer t = new RuntimeMapLayer(this);
+            t.Deserialize(d);
+            return t;
+        }
+
         /// <summary>
         /// Gets the selection set
         /// </summary>

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapLayer.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapLayer.cs	2011-12-08 10:18:25 UTC (rev 6309)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapLayer.cs	2011-12-08 11:22:21 UTC (rev 6310)
@@ -112,7 +112,7 @@
         /// </summary>
         /// <param name="parent">The parent.</param>
         /// <param name="ldf">The LDF.</param>
-        public RuntimeMapLayer(RuntimeMap parent, ILayerDefinition ldf)
+        internal RuntimeMapLayer(RuntimeMap parent, ILayerDefinition ldf)
             : this(parent)
         {
             Check.NotNull(ldf, "ldf");
@@ -138,6 +138,7 @@
 
             this.ExpandInLegend = false;
             this.Name = ResourceIdentifier.GetName(ldf.ResourceID);
+            this.LegendLabel = this.Name;
             this.Selectable = true;
             this.ShowInLegend = true;
             this.Visible = true;
@@ -150,7 +151,7 @@
         /// </summary>
         /// <param name="parent">The parent.</param>
         /// <param name="source">The source.</param>
-        public RuntimeMapLayer(RuntimeMap parent, IMapLayer source)
+        internal RuntimeMapLayer(RuntimeMap parent, IMapLayer source)
             : this(parent, source, (ILayerDefinition)parent.CurrentConnection.ResourceService.GetResource(source.ResourceId))
         {
             _disableChangeTracking = false;

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/PlatformConnectionBase.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/PlatformConnectionBase.cs	2011-12-08 10:18:25 UTC (rev 6309)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/PlatformConnectionBase.cs	2011-12-08 11:22:21 UTC (rev 6310)
@@ -38,6 +38,7 @@
 using OSGeo.MapGuide.MaestroAPI.Feature;
 using GeoAPI.Geometries;
 using OSGeo.MapGuide.ObjectModels.LoadProcedure;
+using OSGeo.MapGuide.ObjectModels.LayerDefinition;
 
 namespace OSGeo.MapGuide.MaestroAPI
 {
@@ -1721,6 +1722,39 @@
         }
 
         /// <summary>
+        /// Creates a new runtime map layer from the specified Layer Definition
+        /// </summary>
+        /// <param name="parent">The parent runtime map. The runtime map must have been created or opened from this same service instance</param>
+        /// <param name="ldf">The layer definition</param>
+        /// <returns></returns>
+        public virtual RuntimeMapLayer CreateMapLayer(RuntimeMap parent, ILayerDefinition ldf)
+        {
+            //TODO: Review when we decide to split the implementations
+            return new RuntimeMapLayer(parent, ldf);
+        }
+
+        /// <summary>
+        /// Creates a new runtime map layer from the specified <see cref="T:OSGeo.MapGuide.ObjectModels.MapDefinition.IBaseMapLayer"/> instance
+        /// </summary>
+        /// <param name="parent">The parent runtime map. The runtime map must have been created or opened from this same service instance</param>
+        /// <param name="source">The map definition layer</param>
+        /// <returns></returns>
+        public RuntimeMapLayer CreateMapLayer(RuntimeMap parent, IBaseMapLayer source)
+        {
+            ILayerDefinition layerDef = (ILayerDefinition)GetResource(source.ResourceId);
+            var rtLayer = CreateMapLayer(parent, layerDef);
+
+            //These may not match, so set them here
+            rtLayer.ExpandInLegend = source.ExpandInLegend;
+            rtLayer.LegendLabel = source.LegendLabel;
+            rtLayer.Name = source.Name;
+            rtLayer.Selectable = source.Selectable;
+            rtLayer.ShowInLegend = source.ShowInLegend;
+            
+            return rtLayer;
+        }
+
+        /// <summary>
         /// Creates a new runtime map instance from an existing map definition. Meters per unit
         /// is calculated from the Coordinate System WKT of the map definition.
         /// </summary>

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Services/IMappingService.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Services/IMappingService.cs	2011-12-08 10:18:25 UTC (rev 6309)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Services/IMappingService.cs	2011-12-08 11:22:21 UTC (rev 6310)
@@ -23,6 +23,7 @@
 using OSGeo.MapGuide.ObjectModels.MapDefinition;
 using OSGeo.MapGuide.MaestroAPI.Mapping;
 using System.Drawing;
+using OSGeo.MapGuide.ObjectModels.LayerDefinition;
 
 namespace OSGeo.MapGuide.MaestroAPI.Services
 {
@@ -43,6 +44,22 @@
     public interface IMappingService : IService
     {
         /// <summary>
+        /// Creates a new runtime map layer from the specified Layer Definition
+        /// </summary>
+        /// <param name="parent">The parent runtime map. The runtime map must have been created or opened from this same service instance</param>
+        /// <param name="ldf">The layer definition</param>
+        /// <returns></returns>
+        RuntimeMapLayer CreateMapLayer(RuntimeMap parent, ILayerDefinition ldf);
+
+        /// <summary>
+        /// Creates a new runtime map layer from the specified <see cref="T:OSGeo.MapGuide.ObjectModels.MapDefinition.IBaseMapLayer"/> instance
+        /// </summary>
+        /// <param name="parent">The parent runtime map. The runtime map must have been created or opened from this same service instance</param>
+        /// <param name="source">The map definition layer</param>
+        /// <returns></returns>
+        RuntimeMapLayer CreateMapLayer(RuntimeMap parent, IBaseMapLayer source);
+
+        /// <summary>
         /// Creates a new runtime map instance from an existing map definition.
         /// </summary>
         /// <param name="mapDef"></param>

Modified: trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/AddThemedDistrictsLayer.aspx.cs
===================================================================
--- trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/AddThemedDistrictsLayer.aspx.cs	2011-12-08 10:18:25 UTC (rev 6309)
+++ trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/AddThemedDistrictsLayer.aspx.cs	2011-12-08 11:22:21 UTC (rev 6310)
@@ -69,7 +69,7 @@
                 CreateDistrictsLayer(conn, fsId, layerId);
 
                 ILayerDefinition layerDef = (ILayerDefinition)conn.ResourceService.GetResource(layerId);
-                RuntimeMapLayer layer = new RuntimeMapLayer(rtMap, layerDef);
+                RuntimeMapLayer layer = mpSvc.CreateMapLayer(rtMap, layerDef);
 
                 layer.Name = "ThemedDistricts";
                 layer.Group = "";

Modified: trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/AddTracksLayer.aspx.cs
===================================================================
--- trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/AddTracksLayer.aspx.cs	2011-12-08 10:18:25 UTC (rev 6309)
+++ trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/AddTracksLayer.aspx.cs	2011-12-08 11:22:21 UTC (rev 6310)
@@ -81,7 +81,7 @@
                 CreateTracksLayer(conn, fsId, layerId);
 
                 ILayerDefinition layerDef = (ILayerDefinition)conn.ResourceService.GetResource(layerId);
-                RuntimeMapLayer layer = new RuntimeMapLayer(rtMap, layerDef);
+                RuntimeMapLayer layer = mpSvc.CreateMapLayer(rtMap, layerDef);
 
                 layer.Group = groupName;
                 layer.LegendLabel = "Tracks";

Modified: trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/ModifyParcelsFilter.aspx.cs
===================================================================
--- trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/ModifyParcelsFilter.aspx.cs	2011-12-08 10:18:25 UTC (rev 6309)
+++ trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/ModifyParcelsFilter.aspx.cs	2011-12-08 11:22:21 UTC (rev 6310)
@@ -80,7 +80,7 @@
                 ldf.ResourceID = ldfId;
 
                 //Create our replacement layer and apply the same properties from the old one
-                RuntimeMapLayer replace = new RuntimeMapLayer(rtMap, ldf);
+                RuntimeMapLayer replace = mpSvc.CreateMapLayer(rtMap, ldf);
                 replace.ExpandInLegend = layer.ExpandInLegend;
                 replace.Group = layer.Group;
                 replace.LegendLabel = layer.LegendLabel;

Modified: trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/ToggleParcelsLayer.aspx.cs
===================================================================
--- trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/ToggleParcelsLayer.aspx.cs	2011-12-08 10:18:25 UTC (rev 6309)
+++ trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/ToggleParcelsLayer.aspx.cs	2011-12-08 11:22:21 UTC (rev 6310)
@@ -77,7 +77,7 @@
                 }
 
                 ILayerDefinition layerDef = (ILayerDefinition)conn.ResourceService.GetResource("Library://Samples/Sheboygan/Layers/Parcels.LayerDefinition");
-                RuntimeMapLayer layer = new RuntimeMapLayer(rtMap, layerDef);
+                RuntimeMapLayer layer = mpSvc.CreateMapLayer(rtMap, layerDef);
 
                 layer.Group = group.Name;
                 layer.LegendLabel = "Parcels";



More information about the mapguide-commits mailing list