int IMapDefinition.MoveDownGroup(IMapLayerGroup group)
        {
            Check.ArgumentNotNull(group, nameof(group));
            var grp = group as MapLayerGroupType;

            if (grp != null)
            {
                var idx = this.MapLayerGroup.IndexOf(grp);
                if (idx < this.MapLayerGroup.Count - 1)
                {
                    int idst = idx + 1;

                    var src = this.MapLayerGroup[idx];
                    var dst = this.MapLayerGroup[idst];

                    this.MapLayerGroup[idx]  = dst;
                    this.MapLayerGroup[idst] = src;

                    OnPropertyChanged(nameof(MapLayerGroup));

                    return(idst);
                }
                else if (idx == this.MapLayerGroup.Count - 1)
                {
                    return(this.MapLayerGroup.Count - 1); //Unchanged
                }
            }

            return(-1);
        }
Exemple #2
0
        public void TestMapDefinitionGroupReordering()
        {
            var conn = new Mock <IServerConnection>();
            var mdf  = ObjectFactory.CreateMapDefinition(new Version(1, 0, 0), "TestMapDefinitionGroupReordering");

            SetupMapDefinitionForTest(mdf);
            int groupCount = mdf.GetGroupCount();

            Assert.Throws <ArgumentNullException>(() => { mdf.MoveDown(null); });
            Assert.Throws <ArgumentNullException>(() => { mdf.MoveUp(null); });
            Assert.Throws <ArgumentNullException>(() => { mdf.SetTopDrawOrder(null); });
            Assert.Throws <ArgumentNullException>(() => { mdf.SetBottomDrawOrder(null); });

            IMapLayerGroup group = mdf.AddGroup("Test");

            Assert.Equal(groupCount, mdf.GetIndex(group));
            Assert.True(group == mdf.GetGroupByName("Test"));
            Assert.Equal(groupCount + 1, mdf.GetGroupCount());

            int value = mdf.MoveUpGroup(group);

            Assert.Equal(groupCount - 1, value); //Already at top
            value = mdf.MoveDownGroup(group);
            Assert.Equal(groupCount, value);
        }
Exemple #3
0
        public GroupPropertiesCtrl(IMapDefinition map, IMapLayerGroup group)
            : this()
        {
            _init = true;
            try
            {
                _mdf = map;
                _el = group;
                group.PropertyChanged += new PropertyChangedEventHandler(OnGroupChanged);
                string currentName = group.Name;
                txtName.Text = currentName;
                //TextBoxBinder.BindText(txtName, group, "Name");
                /*
                IMapDefinition mdf = group.Parent;
                string currentName = group.Name;
                txtName.Text = currentName;
                txtName.TextChanged += (s, e) =>
                {
                    string newName = txtName.Text;
                    group.Name = newName;
                    mdf.UpdateDynamicGroupName(currentName, newName);
                    System.Diagnostics.Debug.WriteLine(string.Format("Updated group name {0} -> {1}", currentName, newName));
                    currentName = newName;
                };*/

                TextBoxBinder.BindText(txtLegendLabel, group, "LegendLabel");
            }
            finally
            {
                _init = false;
            }
        }
Exemple #4
0
        /// <summary>
        /// Removes a layer group and all layers associated with this group
        /// </summary>
        /// <param name="map"></param>
        /// <param name="groupName"></param>
        /// <returns>The number of layers removed. Returns 0 if the group is empty or does not exist</returns>
        public static int RemoveLayerGroupAndChildLayers(this IMapDefinition map, string groupName)
        {
            Check.NotNull(map, "map");              //NOXLATE
            Check.NotEmpty(groupName, "groupName"); //NOXLATE

            var            affectedParentGroups = new Dictionary <string, List <IMapLayerGroup> >();
            IMapLayerGroup group = null;

            foreach (var grp in map.MapLayerGroup)
            {
                if (grp.Name == groupName)
                {
                    group = grp;
                }

                string parentGroupName = grp.Group;
                if (!string.IsNullOrEmpty(parentGroupName))
                {
                    if (!affectedParentGroups.ContainsKey(parentGroupName))
                    {
                        affectedParentGroups[parentGroupName] = new List <IMapLayerGroup>();
                    }
                    affectedParentGroups[parentGroupName].Add(grp);
                }
            }

            if (group != null)
            {
                List <IMapLayer> layers = new List <IMapLayer>(map.GetLayersForGroup(groupName));

                int removed = 0;
                //Remove layers first
                foreach (var l in layers)
                {
                    map.RemoveLayer(l);
                    removed++;
                }
                //Then the group
                map.RemoveGroup(group);

                //Then see if any child groups are under this group and remove them too
                if (affectedParentGroups.ContainsKey(group.Name))
                {
                    for (int i = 0; i < affectedParentGroups[group.Name].Count; i++)
                    {
                        var removeMe = affectedParentGroups[group.Name][i];
                        removed += map.RemoveLayerGroupAndChildLayers(removeMe.Name);
                    }
                }

                return(removed);
            }
            return(0);
        }
        void IMapDefinition.RemoveGroup(IMapLayerGroup group)
        {
            Check.ArgumentNotNull(group, nameof(group));
            var grp = group as MapLayerGroupType;

            if (grp != null)
            {
                this.MapLayerGroup.Remove(grp);
                OnPropertyChanged(nameof(MapLayerGroup));
            }
        }
        int IMapDefinition.GetIndex(IMapLayerGroup group)
        {
            Check.ArgumentNotNull(group, nameof(group));
            var grp = group as MapLayerGroupType;

            if (grp != null)
            {
                return(this.MapLayerGroup.IndexOf(grp));
            }

            return(-1);
        }
Exemple #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RuntimeMapGroup"/> class.
        /// </summary>
        /// <param name="map">The map.</param>
        /// <param name="group">The group.</param>
        protected internal RuntimeMapGroup(RuntimeMap map, IMapLayerGroup group)
            : this(map, group.Name)
        {
            _disableChangeTracking = true;

            this.Group          = group.Group;
            this.ExpandInLegend = group.ExpandInLegend;
            this.LegendLabel    = group.LegendLabel;
            this.ShowInLegend   = group.ShowInLegend;
            this.Visible        = group.Visible;

            this.Type = kNormal;

            _disableChangeTracking = false;
        }
Exemple #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RuntimeMapGroup"/> class.
        /// </summary>
        /// <param name="map">The map.</param>
        /// <param name="group">The group.</param>
        protected internal RuntimeMapGroup(RuntimeMap map, IMapLayerGroup group)
            : this(map, group.Name)
        {
            _disableChangeTracking = true;

            this.Group = group.Group;
            this.ExpandInLegend = group.ExpandInLegend;
            this.LegendLabel = group.LegendLabel;
            this.ShowInLegend = group.ShowInLegend;
            this.Visible = group.Visible;

            this.Type = kNormal;

            _disableChangeTracking = false;
        }
 public GroupPropertiesCtrl(ITileSetDefinition map, IMapLayerGroup group)
     : this()
 {
     _init = true;
     try
     {
         _mdf = map;
         _el  = group;
         group.PropertyChanged += WeakEventHandler.Wrap <PropertyChangedEventHandler>(OnGroupChanged, (eh) => group.PropertyChanged -= eh);
         string currentName = group.Name;
         txtName.Text = currentName;
         TextBoxBinder.BindText(txtLegendLabel, group, nameof(group.LegendLabel));
     }
     finally
     {
         _init = false;
     }
 }
Exemple #10
0
        public void TestMapDefinitionGroupRemove()
        {
            var conn = new Mock <IServerConnection>();
            var mdf  = ObjectFactory.CreateMapDefinition(new Version(1, 0, 0), "TestMapDefinitionGroupRemove");

            SetupMapDefinitionForTest(mdf);
            int layerCount = mdf.GetDynamicLayerCount();
            int groupCount = mdf.GetGroupCount();

            IMapLayerGroup group = mdf.AddGroup("Test");

            Assert.Equal(groupCount + 1, mdf.GetGroupCount());
            Assert.NotNull(mdf.GetGroupByName("Test"));
            Assert.True(group == mdf.GetGroupByName("Test"));

            mdf.RemoveGroup(group);
            Assert.Equal(groupCount, mdf.GetGroupCount());
            Assert.Null(mdf.GetGroupByName("Test"));
        }
Exemple #11
0
        public void TestMapDefinitionGroupAdd()
        {
            var conn = new Mock <IServerConnection>();
            var mdf  = ObjectFactory.CreateMapDefinition(new Version(1, 0, 0), "TestMapDefinitionGroupAdd");

            SetupMapDefinitionForTest(mdf);
            int layerCount = mdf.GetDynamicLayerCount();
            int groupCount = mdf.GetGroupCount();

            Assert.Throws <ArgumentException>(() => { mdf.AddGroup(null); });
            Assert.Throws <ArgumentException>(() => { mdf.AddGroup(""); });
            Assert.Throws <ArgumentException>(() => { mdf.AddGroup("Group1"); });

            IMapLayerGroup group = mdf.AddGroup("Test");

            Assert.Equal(groupCount + 1, mdf.GetGroupCount());
            Assert.NotNull(mdf.GetGroupByName("Test"));
            Assert.True(group == mdf.GetGroupByName("Test"));
        }