Ejemplo n.º 1
0
 private static void SetupMapDefinitionForTest(IMapDefinition mdf)
 {
     mdf.AddGroup("Group1");
     mdf.AddLayer("Group1", "Parcels", "Library://UnitTests/Layers/Parcels.LayerDefinition");
     mdf.AddLayer("Group1", "Rail", "Library://UnitTests/Layers/Rail.LayerDefinition");
     mdf.AddGroup("Group2");
 }
Ejemplo n.º 2
0
        public void TestMapDefinitionNestedGroupDelete()
        {
            var conn = new Mock <IServerConnection>();
            var caps = new Mock <IConnectionCapabilities>();

            foreach (var rt in Enum.GetValues(typeof(ResourceTypes)))
            {
                caps.Setup(c => c.GetMaxSupportedResourceVersion(rt.ToString())).Returns(new Version(1, 0, 0));
            }
            conn.Setup(c => c.Capabilities).Returns(caps.Object);
            IMapDefinition mdf = Utility.CreateMapDefinition(conn.Object, "Test");

            /*
             *
             * [G] Group1
             *  [L] Layer1
             *  [G] Group2
             *     [L] Layer2
             *     [G] Group3
             *        [L] Layer3
             * [G] Group4
             *  [L] Layer4
             *
             */
            var grp1 = mdf.AddGroup("Group1");
            var grp2 = mdf.AddGroup("Group2");
            var grp3 = mdf.AddGroup("Group3");
            var grp4 = mdf.AddGroup("Group4");

            grp3.Group = "Group2";
            grp2.Group = "Group1";

            var lyr1 = mdf.AddLayer("Group1", "Layer1", "Library://Test.LayerDefinition");
            var lyr2 = mdf.AddLayer("Group2", "Layer2", "Library://Test.LayerDefinition");
            var lyr3 = mdf.AddLayer("Group3", "Layer3", "Library://Test.LayerDefinition");
            var lyr4 = mdf.AddLayer("Group4", "Layer4", "Library://Test.LayerDefinition");

            //Delete group 1. Expect the following structure

            /*
             * [G] Group4
             *  [L] Layer4
             */

            mdf.RemoveLayerGroupAndChildLayers("Group1");
            Assert.Equal(1, mdf.GetGroupCount());
            Assert.Equal(1, mdf.GetDynamicLayerCount());
            Assert.Null(mdf.GetLayerByName("Layer1"));
            Assert.Null(mdf.GetLayerByName("Layer2"));
            Assert.Null(mdf.GetLayerByName("Layer3"));
            Assert.NotNull(mdf.GetLayerByName("Layer4"));
            Assert.Null(mdf.GetGroupByName("Group1"));
            Assert.Null(mdf.GetGroupByName("Group2"));
            Assert.Null(mdf.GetGroupByName("Group3"));
            Assert.NotNull(mdf.GetGroupByName("Group4"));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Updates and replaces the layer/group structure of the specified Map Definition with the
        /// layer/group structure of this Runtime Map
        /// </summary>
        /// <param name="newMdf"></param>
        public void UpdateMapDefinition(IMapDefinition newMdf)
        {
            newMdf.RemoveAllLayers();
            newMdf.RemoveAllGroups();
            newMdf.RemoveBaseMap();

            var baseGroups = new List<RuntimeMapGroup>();

            newMdf.CoordinateSystem = this.CoordinateSystem;
            newMdf.Extents = this.MapExtent;

            //Add dynamic groups
            for (int i = this.Groups.Count - 1; i >= 0; i--)
            {
                //Deal with base groups later
                if (this.Groups[i].Type == RuntimeMapGroup.kBaseMap)
                {
                    baseGroups.Add(this.Groups[i]);
                    continue;
                }

                var rtGroup = this.Groups[i];
                var newGroup = newMdf.AddGroup(rtGroup.Name);
                newGroup.Group = rtGroup.Group;
                newGroup.ExpandInLegend = rtGroup.ExpandInLegend;
                newGroup.LegendLabel = rtGroup.LegendLabel;
                newGroup.ShowInLegend = rtGroup.ShowInLegend;
                newGroup.Visible = rtGroup.Visible;
            }

            var baseLayers = new List<RuntimeMapLayer>();

            //Populate dynamic layers. Loop in reverse order so that they are added in correct draw order
            for (int i = this.Layers.Count - 1; i >= 0; i--)
            {
                //Deal with base layers later
                if (this.Layers[i].Type == RuntimeMapLayer.kBaseMap)
                {
                    baseLayers.Add(this.Layers[i]);
                    continue;
                }

                var rtLayer = this.Layers[i];
                var newLayer = newMdf.AddLayer(rtLayer.Group, rtLayer.Name, rtLayer.LayerDefinitionID);
                newLayer.ExpandInLegend = rtLayer.ExpandInLegend;
                newLayer.LegendLabel = rtLayer.LegendLabel;
                newLayer.Selectable = rtLayer.Selectable;
                newLayer.ShowInLegend = rtLayer.ShowInLegend;
                newLayer.Visible = rtLayer.Visible;
            }

            if (baseLayers.Count > 0 && baseGroups.Count > 0)
            {
                newMdf.InitBaseMap();

                //Add finite scales first
                for (int i = _finiteDisplayScales.Length - 1; i >= 0; i--)
                {
                    newMdf.BaseMap.AddFiniteDisplayScale(_finiteDisplayScales[i]);
                }

                var baseGroupsByName = new Dictionary<string, IBaseMapGroup>();

                //Now groups
                for (int i = baseGroups.Count - 1; i >= 0; i--)
                {
                    var rtGroup = baseGroups[i];
                    var newGroup = newMdf.BaseMap.AddBaseLayerGroup(rtGroup.Name);
                    newGroup.ExpandInLegend = rtGroup.ExpandInLegend;
                    newGroup.LegendLabel = rtGroup.LegendLabel;
                    newGroup.ShowInLegend = rtGroup.ShowInLegend;
                    newGroup.Visible = rtGroup.Visible;

                    baseGroupsByName.Add(newGroup.Name, newGroup);
                }

                //Then layers. Loop in reverse order so that they are added in correct draw order
                for (int i = baseLayers.Count - 1; i >= 0; i--)
                {
                    var rtLayer = baseLayers[i];
                    //Should always happen
                    if (baseGroupsByName.ContainsKey(rtLayer.Group))
                    {
                        var newLayer = baseGroupsByName[rtLayer.Group].AddLayer(rtLayer.Name, rtLayer.LayerDefinitionID);
                        newLayer.ExpandInLegend = rtLayer.ExpandInLegend;
                        newLayer.LegendLabel = rtLayer.LegendLabel;
                        newLayer.Selectable = rtLayer.Selectable;
                        newLayer.ShowInLegend = rtLayer.ShowInLegend;
                    }
                }
            }
        }
Ejemplo n.º 4
0
 private static void SetupMapDefinitionForTest(IMapDefinition mdf)
 {
     mdf.AddGroup("Group1");
     mdf.AddLayer("Group1", "Parcels", "Library://UnitTests/Layers/Parcels.LayerDefinition");
     mdf.AddLayer("Group1", "Rail", "Library://UnitTests/Layers/Rail.LayerDefinition");
     mdf.AddGroup("Group2");
 }