[mapguide-commits] r8559 - in trunk/Tools/Maestro: Maestro.Editors/MapDefinition MaestroAPITests OSGeo.MapGuide.MaestroAPI.Tests OSGeo.MapGuide.MaestroAPI.Tests/Mapping OSGeo.MapGuide.ObjectModel.Tests OSGeo.MapGuide.ObjectModels/MapDefinition OSGeo.MapGuide.ObjectModels/MapDefinition/v1_0_0 OSGeo.MapGuide.ObjectModels/MapDefinition/v2_3_0 OSGeo.MapGuide.ObjectModels/MapDefinition/v2_4_0 OSGeo.MapGuide.ObjectModels/MapDefinition/v3_0_0

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Thu Mar 5 04:47:24 PST 2015


Author: jng
Date: 2015-03-05 04:47:24 -0800 (Thu, 05 Mar 2015)
New Revision: 8559

Modified:
   trunk/Tools/Maestro/Maestro.Editors/MapDefinition/MapDefinitionEditorCtrl.cs
   trunk/Tools/Maestro/Maestro.Editors/MapDefinition/MapLayersSectionCtrl.cs
   trunk/Tools/Maestro/Maestro.Editors/MapDefinition/MapSettingsSectionCtrl.cs
   trunk/Tools/Maestro/MaestroAPITests/RuntimeMapTests.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Tests/Mapping/RuntimeMapTests.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Tests/ResourceTests.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.ObjectModel.Tests/MapDefinitionTests.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.ObjectModels/MapDefinition/MapDefinitionInterfaces.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.ObjectModels/MapDefinition/v1_0_0/MapDefinitionImpl.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.ObjectModels/MapDefinition/v2_3_0/MapDefinitionImpl.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.ObjectModels/MapDefinition/v2_4_0/MapDefinitionImpl.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.ObjectModels/MapDefinition/v3_0_0/MapDefinitionImpl.cs
Log:
#2542: Fix auto-calculation of Map Definition extent

 - When a base layer is added to the Map Definition
 - When a Map Definition links to an external tile set

Note that the auto-calculation when a layer is added only applies if the Map Definition extent is empty (we no longer use the SetExtentsFromFirstAddedLayer property, which was used to control if auto-calculation should proceed)

Modified: trunk/Tools/Maestro/Maestro.Editors/MapDefinition/MapDefinitionEditorCtrl.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/MapDefinition/MapDefinitionEditorCtrl.cs	2015-03-04 15:16:41 UTC (rev 8558)
+++ trunk/Tools/Maestro/Maestro.Editors/MapDefinition/MapDefinitionEditorCtrl.cs	2015-03-05 12:47:24 UTC (rev 8559)
@@ -83,7 +83,6 @@
         {
             _edSvc = service;
             _map = _edSvc.GetEditedResource() as IMapDefinition;
-            _map.SetExtentsFromFirstAddedLayer = true;
 
             mapSettingsCtrl.Bind(service);
             mapLayersCtrl.Bind(service);

Modified: trunk/Tools/Maestro/Maestro.Editors/MapDefinition/MapLayersSectionCtrl.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/MapDefinition/MapLayersSectionCtrl.cs	2015-03-04 15:16:41 UTC (rev 8558)
+++ trunk/Tools/Maestro/Maestro.Editors/MapDefinition/MapLayersSectionCtrl.cs	2015-03-05 12:47:24 UTC (rev 8559)
@@ -840,7 +840,7 @@
                         groupName = group.Tag.Name + "(" + counter + ")";
                     }
                     _map.AddGroup(groupName);
-                    int layerCount = _map.GetLayerCount();
+                    int layerCount = _map.GetDynamicLayerCount();
                     foreach (var layer in group.Tag.BaseMapLayer)
                     {
                         //We an avoid a duplicate name check because the Map Definition should already ensure uniqueness
@@ -1352,10 +1352,10 @@
         /// <returns>The index of the layer below the current layer. Returns -1 if the current layer index is the bottom-most layer of the group</returns>
         private static int GetIndexOfLayerBelow(IMapDefinition mdf, int layerIndex, string group)
         {
-            if (layerIndex < mdf.GetLayerCount() - 1)
+            if (layerIndex < mdf.GetDynamicLayerCount() - 1)
             {
                 var list = new List<IMapLayer>(mdf.MapLayer);
-                for (int i = layerIndex + 1; i < mdf.GetLayerCount(); i++)
+                for (int i = layerIndex + 1; i < mdf.GetDynamicLayerCount(); i++)
                 {
                     if (list[i].Group == group)
                         return i;

Modified: trunk/Tools/Maestro/Maestro.Editors/MapDefinition/MapSettingsSectionCtrl.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/MapDefinition/MapSettingsSectionCtrl.cs	2015-03-04 15:16:41 UTC (rev 8558)
+++ trunk/Tools/Maestro/Maestro.Editors/MapDefinition/MapSettingsSectionCtrl.cs	2015-03-05 12:47:24 UTC (rev 8559)
@@ -24,6 +24,7 @@
 using Maestro.Shared.UI;
 using OSGeo.MapGuide.MaestroAPI;
 using OSGeo.MapGuide.ObjectModels.MapDefinition;
+using OSGeo.MapGuide.ObjectModels.TileSetDefinition;
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
@@ -242,6 +243,7 @@
             {
                 ids.Add(layer.ResourceId);
             }
+            IMapDefinition3 mdf3 = _map as IMapDefinition3;
             if (_map.BaseMap != null)
             {
                 foreach (var grp in _map.BaseMap.BaseMapLayerGroups)
@@ -252,6 +254,17 @@
                     }
                 }
             }
+            else if (mdf3 != null && !string.IsNullOrEmpty(mdf3.TileSetDefinitionID))
+            {
+                var tsd = (ITileSetDefinition)_service.CurrentConnection.ResourceService.GetResource(mdf3.TileSetDefinitionID);
+                foreach (var grp in tsd.BaseMapLayerGroups)
+                {
+                    foreach (var layer in grp.BaseMapLayer)
+                    {
+                        ids.Add(layer.ResourceId);
+                    }
+                }
+            }
             return ids;
         }
 

Modified: trunk/Tools/Maestro/MaestroAPITests/RuntimeMapTests.cs
===================================================================
--- trunk/Tools/Maestro/MaestroAPITests/RuntimeMapTests.cs	2015-03-04 15:16:41 UTC (rev 8558)
+++ trunk/Tools/Maestro/MaestroAPITests/RuntimeMapTests.cs	2015-03-05 12:47:24 UTC (rev 8559)
@@ -225,7 +225,7 @@
         {
             if (map.MapDefinition != mdf.ResourceID) return false;
             if (map.Groups.Count != mdf.GetGroupCount()) return false;
-            if (map.Layers.Count != mdf.GetLayerCount()) return false;
+            if (map.Layers.Count != mdf.GetDynamicLayerCount()) return false;
 
             foreach (var layer in map.Layers)
             {

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Tests/Mapping/RuntimeMapTests.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Tests/Mapping/RuntimeMapTests.cs	2015-03-04 15:16:41 UTC (rev 8558)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Tests/Mapping/RuntimeMapTests.cs	2015-03-05 12:47:24 UTC (rev 8559)
@@ -269,7 +269,7 @@
             var map = CreateTestMap();
             IMapDefinition mdf = ObjectFactory.CreateMapDefinition(new Version(1, 0, 0), "Test Map");
             map.UpdateMapDefinition(mdf);
-            Assert.AreEqual(0, mdf.GetLayerCount());
+            Assert.AreEqual(0, mdf.GetDynamicLayerCount());
             Assert.AreEqual(0, mdf.GetGroupCount());
             Assert.NotNull(mdf.BaseMap);
             var grp = mdf.BaseMap.GetFirstGroup();
@@ -283,7 +283,7 @@
         {
             var map = CreateTestMap();
             var mdf = map.ToMapDefinition(false);
-            Assert.AreEqual(0, mdf.GetLayerCount());
+            Assert.AreEqual(0, mdf.GetDynamicLayerCount());
             Assert.AreEqual(0, mdf.GetGroupCount());
             Assert.NotNull(mdf.BaseMap);
             var grp = mdf.BaseMap.GetFirstGroup();
@@ -292,7 +292,7 @@
             Assert.AreEqual("Base Layer Group", grp.Name);
 
             mdf = map.ToMapDefinition(true);
-            Assert.AreEqual(0, mdf.GetLayerCount());
+            Assert.AreEqual(0, mdf.GetDynamicLayerCount());
             Assert.AreEqual(0, mdf.GetGroupCount());
             Assert.NotNull(mdf.BaseMap);
             grp = mdf.BaseMap.GetFirstGroup();

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Tests/ResourceTests.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Tests/ResourceTests.cs	2015-03-04 15:16:41 UTC (rev 8558)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Tests/ResourceTests.cs	2015-03-05 12:47:24 UTC (rev 8559)
@@ -177,7 +177,7 @@
             var conn = new Mock<IServerConnection>();
             var mdf = ObjectFactory.CreateMapDefinition(new Version(1, 0, 0), "TestMapDefinitionLayerInsert");
             SetupMapDefinitionForTest(mdf);
-            int layerCount = mdf.GetLayerCount();
+            int layerCount = mdf.GetDynamicLayerCount();
 
             Assert.Throws<ArgumentException>(() => { mdf.InsertLayer(-1, null, "Hydro", "Library://UnitTests/Layers/HydrographicPolygons.LayerDefinition"); });
             Assert.Throws<ArgumentException>(() => { mdf.InsertLayer(layerCount + 1, null, "Hydro", "Library://UnitTests/Layers/HydrographicPolygons.LayerDefinition"); });
@@ -192,7 +192,7 @@
             Assert.AreEqual(0, mdf.GetIndex(layer));
             Assert.True(layer == mdf.GetLayerByName("Hydro"));
 
-            layerCount = mdf.GetLayerCount();
+            layerCount = mdf.GetDynamicLayerCount();
             IMapLayer layer1 = mdf.InsertLayer(layerCount, null, "Hydro2", "Library://UnitTests/Layers/HydrographicPolygons.LayerDefinition");
             Assert.AreEqual(layerCount, mdf.GetIndex(layer1));
             Assert.True(layer1 == mdf.GetLayerByName("Hydro2"));
@@ -204,7 +204,7 @@
             var conn = new Mock<IServerConnection>();
             var mdf = ObjectFactory.CreateMapDefinition(new Version(1, 0, 0), "TestMapDefinitionLayerAdd");
             SetupMapDefinitionForTest(mdf);
-            int layerCount = mdf.GetLayerCount();
+            int layerCount = mdf.GetDynamicLayerCount();
 
             Assert.Throws<ArgumentException>(() => { mdf.AddLayer("IDontExist", "Hydro", "Library://UnitTests/Layers/HydrographicPolygons.LayerDefinition"); });
             Assert.Throws<ArgumentException>(() => { mdf.AddLayer(null, "", ""); });
@@ -217,7 +217,7 @@
             IMapLayer layer = mdf.AddLayer(null, "Hydro", "Library://UnitTests/Layers/HydrographicPolygons.LayerDefinition");
             Assert.AreEqual(0, mdf.GetIndex(layer));
             Assert.True(layer == mdf.GetLayerByName("Hydro"));
-            Assert.AreEqual(layerCount + 1, mdf.GetLayerCount());
+            Assert.AreEqual(layerCount + 1, mdf.GetDynamicLayerCount());
         }
 
         [Test]
@@ -226,16 +226,16 @@
             var conn = new Mock<IServerConnection>();
             var mdf = ObjectFactory.CreateMapDefinition(new Version(1, 0, 0), "TestMapDefinitionLayerRemove");
             SetupMapDefinitionForTest(mdf);
-            int layerCount = mdf.GetLayerCount();
+            int layerCount = mdf.GetDynamicLayerCount();
 
             IMapLayer layer = mdf.AddLayer(null, "Hydro", "Library://UnitTests/Layers/HydrographicPolygons.LayerDefinition");
             Assert.AreEqual(0, mdf.GetIndex(layer));
             Assert.True(layer == mdf.GetLayerByName("Hydro"));
-            Assert.AreEqual(layerCount + 1, mdf.GetLayerCount());
+            Assert.AreEqual(layerCount + 1, mdf.GetDynamicLayerCount());
 
             mdf.RemoveLayer(layer);
             Assert.True(mdf.GetIndex(layer) < 0);
-            Assert.AreEqual(layerCount, mdf.GetLayerCount());
+            Assert.AreEqual(layerCount, mdf.GetDynamicLayerCount());
         }
 
         [Test]
@@ -244,7 +244,7 @@
             var conn = new Mock<IServerConnection>();
             var mdf = ObjectFactory.CreateMapDefinition(new Version(1, 0, 0), "TestMapDefinitionLayerReordering");
             SetupMapDefinitionForTest(mdf);
-            int layerCount = mdf.GetLayerCount();
+            int layerCount = mdf.GetDynamicLayerCount();
 
             Assert.Throws<ArgumentNullException>(() => { mdf.MoveDown(null); });
             Assert.Throws<ArgumentNullException>(() => { mdf.MoveUp(null); });
@@ -254,7 +254,7 @@
             IMapLayer layer = mdf.AddLayer(null, "Hydro", "Library://UnitTests/Layers/HydrographicPolygons.LayerDefinition");
             Assert.AreEqual(0, mdf.GetIndex(layer));
             Assert.True(layer == mdf.GetLayerByName("Hydro"));
-            Assert.AreEqual(layerCount + 1, mdf.GetLayerCount());
+            Assert.AreEqual(layerCount + 1, mdf.GetDynamicLayerCount());
 
             int value = mdf.MoveUp(layer);
             Assert.AreEqual(0, value); //Already at top
@@ -262,11 +262,11 @@
             Assert.AreEqual(1, value);
             mdf.SetBottomDrawOrder(layer);
             value = mdf.GetIndex(layer);
-            Assert.AreEqual(mdf.GetLayerCount() - 1, value);
+            Assert.AreEqual(mdf.GetDynamicLayerCount() - 1, value);
             value = mdf.MoveDown(layer);
-            Assert.AreEqual(mdf.GetLayerCount() - 1, value); //Already at bottom
+            Assert.AreEqual(mdf.GetDynamicLayerCount() - 1, value); //Already at bottom
             value = mdf.MoveUp(layer);
-            Assert.AreEqual(mdf.GetLayerCount() - 2, value);
+            Assert.AreEqual(mdf.GetDynamicLayerCount() - 2, value);
             mdf.SetTopDrawOrder(layer);
             value = mdf.GetIndex(layer);
             Assert.AreEqual(0, value);
@@ -278,7 +278,7 @@
             var conn = new Mock<IServerConnection>();
             var mdf = ObjectFactory.CreateMapDefinition(new Version(1, 0, 0), "TestMapDefinitionGroupAdd");
             SetupMapDefinitionForTest(mdf);
-            int layerCount = mdf.GetLayerCount();
+            int layerCount = mdf.GetDynamicLayerCount();
             int groupCount = mdf.GetGroupCount();
 
             Assert.Throws<ArgumentException>(() => { mdf.AddGroup(null); });
@@ -297,7 +297,7 @@
             var conn = new Mock<IServerConnection>();
             var mdf = ObjectFactory.CreateMapDefinition(new Version(1, 0, 0), "TestMapDefinitionGroupRemove");
             SetupMapDefinitionForTest(mdf);
-            int layerCount = mdf.GetLayerCount();
+            int layerCount = mdf.GetDynamicLayerCount();
             int groupCount = mdf.GetGroupCount();
 
             IMapLayerGroup group = mdf.AddGroup("Test");
@@ -579,7 +579,7 @@
 
             mdf.RemoveLayerGroupAndChildLayers("Group1");
             Assert.AreEqual(1, mdf.GetGroupCount());
-            Assert.AreEqual(1, mdf.GetLayerCount());
+            Assert.AreEqual(1, mdf.GetDynamicLayerCount());
             Assert.Null(mdf.GetLayerByName("Layer1"));
             Assert.Null(mdf.GetLayerByName("Layer2"));
             Assert.Null(mdf.GetLayerByName("Layer3"));

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.ObjectModel.Tests/MapDefinitionTests.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.ObjectModel.Tests/MapDefinitionTests.cs	2015-03-04 15:16:41 UTC (rev 8558)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.ObjectModel.Tests/MapDefinitionTests.cs	2015-03-05 12:47:24 UTC (rev 8559)
@@ -68,7 +68,7 @@
             Assert.AreEqual(5417109.9090669, extent.MinY);
             Assert.AreEqual(-9758770.5921973, extent.MaxX);
             Assert.AreEqual(5435129.2308673, extent.MaxY);
-            Assert.AreEqual(1, mdf.GetLayerCount());
+            Assert.AreEqual(1, mdf.GetDynamicLayerCount());
             Assert.NotNull(mdf.GetLayerByName("RoadCenterLines"));
             Assert.AreEqual(TileSourceType.External, mdf.TileSourceType);
             Assert.AreEqual("Library://UnitTests/TileSets/Sheboygan.TileSetDefinition", mdf.TileSetDefinitionID);

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.ObjectModels/MapDefinition/MapDefinitionInterfaces.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.ObjectModels/MapDefinition/MapDefinitionInterfaces.cs	2015-03-04 15:16:41 UTC (rev 8558)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.ObjectModels/MapDefinition/MapDefinitionInterfaces.cs	2015-03-05 12:47:24 UTC (rev 8559)
@@ -75,12 +75,6 @@
     public interface IMapDefinition : IResource, IMapDefinitionBase, INotifyPropertyChanged
     {
         /// <summary>
-        /// If true, the first layer added to this map definition will automatically set the extents
-        /// based on that layer's added extents. Default is false
-        /// </summary>
-        bool SetExtentsFromFirstAddedLayer { get; set; }
-
-        /// <summary>
         /// Gets or sets the name.
         /// </summary>
         /// <value>The name.</value>
@@ -328,7 +322,49 @@
     /// </summary>
     public static class MapDefinitionExtensions
     {
+        public static bool IsEmpty(this IEnvelope box2DType)
+        {
+            return box2DType == null ||
+                (box2DType.MaxX == 0.0 &&
+                box2DType.MaxY == 0.0 &&
+                box2DType.MinX == 0.0 &&
+                box2DType.MinY == 0.0);
+        }
+
         /// <summary>
+        /// Sets the extents of the map definition from the id of the the given layer definition
+        /// Does nothing if the extent is already set
+        /// </summary>
+        /// <param name="mdf"></param>
+        /// <param name="layerDefinitionId"></param>
+        public static void AutoSetExtentsFromLayer(this IMapDefinition mdf, string layerDefinitionId)
+        {
+            //Do nothing if this is false
+            if (!mdf.Extents.IsEmpty())
+                return;
+
+            var calc = mdf.ExtentCalculator;
+            if (calc != null)
+            {
+                var res = calc.GetLayerExtent(layerDefinitionId, mdf.CoordinateSystem);
+                if (res != null)
+                {
+                    //Set the coordinate system if empty
+                    if (string.IsNullOrEmpty(mdf.CoordinateSystem))
+                    {
+                        mdf.CoordinateSystem = res.LayerCoordinateSystem;
+                    }
+                    //Set the bounds if empty
+                    if (mdf.Extents.IsEmpty())
+                    {
+                        var env = res.Extent;
+                        mdf.SetExtents(env.MinX, env.MinY, env.MaxX, env.MaxY);
+                    }
+                }
+            }
+        }
+
+        /// <summary>
         /// Adds the specified finite display scale to the Map Definition
         /// </summary>
         /// <param name="map"></param>
@@ -534,7 +570,7 @@
         /// </summary>
         /// <param name="map"></param>
         /// <returns></returns>
-        public static int GetLayerCount(this IMapDefinition map)
+        public static int GetDynamicLayerCount(this IMapDefinition map)
         {
             Check.ArgumentNotNull(map, "map"); //NOXLATE
             return new List<IMapLayer>(map.MapLayer).Count;

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.ObjectModels/MapDefinition/v1_0_0/MapDefinitionImpl.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.ObjectModels/MapDefinition/v1_0_0/MapDefinitionImpl.cs	2015-03-04 15:16:41 UTC (rev 8558)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.ObjectModels/MapDefinition/v1_0_0/MapDefinitionImpl.cs	2015-03-05 12:47:24 UTC (rev 8559)
@@ -127,7 +127,6 @@
 #elif MDF_230
             this.versionField = "2.3.0"; //NOXLATE
 #endif
-            this.SetExtentsFromFirstAddedLayer = false;
         }
 
 #if MDF_240
@@ -137,10 +136,6 @@
 #else
         private static readonly Version RES_VERSION = new Version(1, 0, 0);
 #endif
-
-        [XmlIgnore]
-        public bool SetExtentsFromFirstAddedLayer { get; set; }
-
         private string _resId;
 
         [XmlIgnore]
@@ -300,10 +295,7 @@
             this.MapLayer.Insert(0, layer);
             OnPropertyChanged("MapLayer"); //NOXLATE
 
-            if (this.MapLayer.Count == 1) //First one
-            {
-                OnFirstLayerAdded(layer);
-            }
+            this.AutoSetExtentsFromLayer(layer.ResourceId);
 
             return layer;
         }
@@ -311,33 +303,6 @@
         [XmlIgnore]
         public ILayerExtentCalculator ExtentCalculator { get; set; }
 
-        private void OnFirstLayerAdded(MapLayerType layer)
-        {
-            //Do nothing if this is false
-            if (!this.SetExtentsFromFirstAddedLayer)
-                return;
-
-            var calc = this.ExtentCalculator;
-            if (calc != null)
-            {
-                var res = calc.GetLayerExtent(layer.ResourceId, this.CoordinateSystem);
-                if (res != null)
-                {
-                    //Set the coordinate system if empty
-                    if (string.IsNullOrEmpty(this.CoordinateSystem))
-                    {
-                        this.CoordinateSystem = res.LayerCoordinateSystem;
-                    }
-                    //Set the bounds if empty
-                    if (IsEmpty(this.Extents))
-                    {
-                        var env = res.Extent;
-                        ((IMapDefinition)this).SetExtents(env.MinX, env.MinY, env.MaxX, env.MaxY);
-                    }
-                }
-            }
-        }
-
         public IMapLayer InsertLayer(int index, string groupName, string layerName, string layerDefinitionId)
         {
             Check.ThatArgumentIsBetweenRange(index, 0, this.MapLayer.Count, true, "index (" + index + ") between [" + 0 + "," + this.MapLayer.Count + "]");
@@ -414,10 +379,7 @@
             }
             OnPropertyChanged("MapLayer"); //NOXLATE
 
-            if (this.MapLayer.Count == 1) //First one
-            {
-                OnFirstLayerAdded(layer);
-            }
+            this.AutoSetExtentsFromLayer(layer.ResourceId);
 
             return layer;
         }
@@ -941,6 +903,8 @@
             if (bl != null)
             {
                 this.BaseMapLayer.Insert(index, bl);
+                OnPropertyChanged("BaseMapLayer"); //NOXLATE
+                this.Parent.AutoSetExtentsFromLayer(layer.ResourceId);
             }
         }
 
@@ -958,6 +922,7 @@
             };
             this.BaseMapLayer.Add(layer);
             OnPropertyChanged("BaseMapLayer"); //NOXLATE
+            this.Parent.AutoSetExtentsFromLayer(resourceId);
             return layer;
         }
 

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.ObjectModels/MapDefinition/v2_3_0/MapDefinitionImpl.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.ObjectModels/MapDefinition/v2_3_0/MapDefinitionImpl.cs	2015-03-04 15:16:41 UTC (rev 8558)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.ObjectModels/MapDefinition/v2_3_0/MapDefinitionImpl.cs	2015-03-05 12:47:24 UTC (rev 8559)
@@ -128,7 +128,6 @@
 #elif MDF_230
             this.versionField = "2.3.0"; //NOXLATE
 #endif
-            this.SetExtentsFromFirstAddedLayer = false;
         }
 
 #if MDF_240
@@ -138,10 +137,6 @@
 #else
         private static readonly Version RES_VERSION = new Version(1, 0, 0);
 #endif
-
-        [XmlIgnore]
-        public bool SetExtentsFromFirstAddedLayer { get; set; }
-
         private string _resId;
 
         [XmlIgnore]
@@ -301,10 +296,7 @@
             this.MapLayer.Insert(0, layer);
             OnPropertyChanged("MapLayer"); //NOXLATE
 
-            if (this.MapLayer.Count == 1) //First one
-            {
-                OnFirstLayerAdded(layer);
-            }
+            this.AutoSetExtentsFromLayer(layer.ResourceId);
 
             return layer;
         }
@@ -312,33 +304,6 @@
         [XmlIgnore]
         public ILayerExtentCalculator ExtentCalculator { get; set; }
 
-        private void OnFirstLayerAdded(MapLayerType layer)
-        {
-            //Do nothing if this is false
-            if (!this.SetExtentsFromFirstAddedLayer)
-                return;
-
-            var calc = this.ExtentCalculator;
-            if (calc != null)
-            {
-                var res = calc.GetLayerExtent(layer.ResourceId, this.CoordinateSystem);
-                if (res != null)
-                {
-                    //Set the coordinate system if empty
-                    if (string.IsNullOrEmpty(this.CoordinateSystem))
-                    {
-                        this.CoordinateSystem = res.LayerCoordinateSystem;
-                    }
-                    //Set the bounds if empty
-                    if (IsEmpty(this.Extents))
-                    {
-                        var env = res.Extent;
-                        ((IMapDefinition)this).SetExtents(env.MinX, env.MinY, env.MaxX, env.MaxY);
-                    }
-                }
-            }
-        }
-
         public IMapLayer InsertLayer(int index, string groupName, string layerName, string layerDefinitionId)
         {
             Check.ThatArgumentIsBetweenRange(index, 0, this.MapLayer.Count, true, "index (" + index + ") between [" + 0 + "," + this.MapLayer.Count + "]");
@@ -415,10 +380,7 @@
             }
             OnPropertyChanged("MapLayer"); //NOXLATE
 
-            if (this.MapLayer.Count == 1) //First one
-            {
-                OnFirstLayerAdded(layer);
-            }
+            this.AutoSetExtentsFromLayer(layer.ResourceId);
 
             return layer;
         }

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.ObjectModels/MapDefinition/v2_4_0/MapDefinitionImpl.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.ObjectModels/MapDefinition/v2_4_0/MapDefinitionImpl.cs	2015-03-04 15:16:41 UTC (rev 8558)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.ObjectModels/MapDefinition/v2_4_0/MapDefinitionImpl.cs	2015-03-05 12:47:24 UTC (rev 8559)
@@ -129,7 +129,6 @@
 #elif MDF_230
             this.versionField = "2.3.0"; //NOXLATE
 #endif
-            this.SetExtentsFromFirstAddedLayer = false;
         }
 
 #if MDF_240
@@ -139,10 +138,6 @@
 #else
         private static readonly Version RES_VERSION = new Version(1, 0, 0);
 #endif
-
-        [XmlIgnore]
-        public bool SetExtentsFromFirstAddedLayer { get; set; }
-
         private string _resId;
 
         [XmlIgnore]
@@ -302,10 +297,7 @@
             this.MapLayer.Insert(0, layer);
             OnPropertyChanged("MapLayer"); //NOXLATE
 
-            if (this.MapLayer.Count == 1) //First one
-            {
-                OnFirstLayerAdded(layer);
-            }
+            this.AutoSetExtentsFromLayer(layer.ResourceId);
 
             return layer;
         }
@@ -313,33 +305,6 @@
         [XmlIgnore]
         public ILayerExtentCalculator ExtentCalculator { get; set; }
 
-        private void OnFirstLayerAdded(MapLayerType layer)
-        {
-            //Do nothing if this is false
-            if (!this.SetExtentsFromFirstAddedLayer)
-                return;
-
-            var calc = this.ExtentCalculator;
-            if (calc != null)
-            {
-                var res = calc.GetLayerExtent(layer.ResourceId, this.CoordinateSystem);
-                if (res != null)
-                {
-                    //Set the coordinate system if empty
-                    if (string.IsNullOrEmpty(this.CoordinateSystem))
-                    {
-                        this.CoordinateSystem = res.LayerCoordinateSystem;
-                    }
-                    //Set the bounds if empty
-                    if (IsEmpty(this.Extents))
-                    {
-                        var env = res.Extent;
-                        ((IMapDefinition)this).SetExtents(env.MinX, env.MinY, env.MaxX, env.MaxY);
-                    }
-                }
-            }
-        }
-
         public IMapLayer InsertLayer(int index, string groupName, string layerName, string layerDefinitionId)
         {
             Check.ThatArgumentIsBetweenRange(index, 0, this.MapLayer.Count, true, "index (" + index + ") between [" + 0 + "," + this.MapLayer.Count + "]");
@@ -416,10 +381,7 @@
             }
             OnPropertyChanged("MapLayer"); //NOXLATE
 
-            if (this.MapLayer.Count == 1) //First one
-            {
-                OnFirstLayerAdded(layer);
-            }
+            this.AutoSetExtentsFromLayer(layer.ResourceId);
 
             return layer;
         }

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.ObjectModels/MapDefinition/v3_0_0/MapDefinitionImpl.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.ObjectModels/MapDefinition/v3_0_0/MapDefinitionImpl.cs	2015-03-04 15:16:41 UTC (rev 8558)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.ObjectModels/MapDefinition/v3_0_0/MapDefinitionImpl.cs	2015-03-05 12:47:24 UTC (rev 8559)
@@ -109,7 +109,6 @@
         internal MapDefinition()
         {
             this.versionField = "3.0.0"; //NOXLATE
-            this.SetExtentsFromFirstAddedLayer = false;
         }
 
         string IMapDefinition3.TileSetDefinitionID
@@ -179,9 +178,6 @@
 
         private static readonly Version RES_VERSION = new Version(3, 0, 0);
 
-        [XmlIgnore]
-        public bool SetExtentsFromFirstAddedLayer { get; set; }
-
         private string _resId;
 
         [XmlIgnore]
@@ -334,45 +330,15 @@
 
             this.MapLayer.Insert(0, layer);
             OnPropertyChanged("MapLayer"); //NOXLATE
+            
+            this.AutoSetExtentsFromLayer(layer.ResourceId);
 
-            if (this.MapLayer.Count == 1) //First one
-            {
-                OnFirstLayerAdded(layer);
-            }
-
             return layer;
         }
 
         [XmlIgnore]
         public ILayerExtentCalculator ExtentCalculator { get; set; }
 
-        private void OnFirstLayerAdded(MapLayerType layer)
-        {
-            //Do nothing if this is false
-            if (!this.SetExtentsFromFirstAddedLayer)
-                return;
-
-            var calc = this.ExtentCalculator;
-            if (calc != null)
-            {
-                var res = calc.GetLayerExtent(layer.ResourceId, this.CoordinateSystem);
-                if (res != null)
-                {
-                    //Set the coordinate system if empty
-                    if (string.IsNullOrEmpty(this.CoordinateSystem))
-                    {
-                        this.CoordinateSystem = res.LayerCoordinateSystem;
-                    }
-                    //Set the bounds if empty
-                    if (IsEmpty(this.Extents))
-                    {
-                        var env = res.Extent;
-                        ((IMapDefinition)this).SetExtents(env.MinX, env.MinY, env.MaxX, env.MaxY);
-                    }
-                }
-            }
-        }
-
         public IMapLayer InsertLayer(int index, string groupName, string layerName, string layerDefinitionId)
         {
             Check.ThatArgumentIsBetweenRange(index, 0, this.MapLayer.Count, true, "index (" + index + ") between [" + 0 + "," + this.MapLayer.Count + "]");
@@ -449,10 +415,7 @@
             }
             OnPropertyChanged("MapLayer"); //NOXLATE
 
-            if (this.MapLayer.Count == 1) //First one
-            {
-                OnFirstLayerAdded(layer);
-            }
+            this.AutoSetExtentsFromLayer(layer.ResourceId);
 
             return layer;
         }



More information about the mapguide-commits mailing list