Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Updates the group name references of all layers belonging to a particular group
        /// </summary>
        /// <param name="map">The map.</param>
        /// <param name="oldGroupName">Old name of the group.</param>
        /// <param name="newGroupName">New name of the group.</param>
        public static void UpdateDynamicGroupName(this IMapDefinition map, string oldGroupName, string newGroupName)
        {
            Check.NotNull(map, "map");                    //NOXLATE
            Check.NotEmpty(oldGroupName, "oldGroupName"); //NOXLATE
            Check.NotEmpty(newGroupName, "newGroupName"); //NOXLATE
            var layers = map.GetLayersForGroup(oldGroupName);
            var groups = map.GetGroupsForGroup(oldGroupName);

            foreach (var l in layers)
            {
                l.Group = newGroupName;
            }
            foreach (var g in groups)
            {
                g.Group = newGroupName;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Updates the group name references of all layers belonging to a particular group
        /// </summary>
        /// <param name="map">The map.</param>
        /// <param name="oldGroupName">Old name of the group.</param>
        /// <param name="newGroupName">New name of the group.</param>
        public static void UpdateDynamicGroupName(this IMapDefinition map, string oldGroupName, string newGroupName)
        {
            Check.ArgumentNotNull(map, nameof(map));
            Check.ArgumentNotEmpty(oldGroupName, nameof(oldGroupName));
            Check.ArgumentNotEmpty(newGroupName, nameof(newGroupName));
            var layers = map.GetLayersForGroup(oldGroupName);
            var groups = map.GetGroupsForGroup(oldGroupName);

            foreach (var l in layers)
            {
                l.Group = newGroupName;
            }
            foreach (var g in groups)
            {
                g.Group = newGroupName;
            }
        }
Ejemplo n.º 4
0
 public override System.Collections.IEnumerable GetChildren(TreePath treePath)
 {
     if (treePath.IsEmpty())
     {
         foreach (var layer in _map.GetLayersWithoutGroups())
         {
             yield return(new LayerItem(layer));
         }
         foreach (var group in _map.MapLayerGroup)
         {
             if (string.IsNullOrEmpty(group.Group))
             {
                 yield return(new GroupItem(group));
             }
         }
     }
     else
     {
         var gitem = treePath.LastNode as GroupItem;
         if (gitem != null)
         {
             var group = gitem.Tag;
             foreach (var l in _map.GetLayersForGroup(group.Name))
             {
                 yield return(new LayerItem(l));
             }
             foreach (var g in _map.MapLayerGroup)
             {
                 if (g.Group == group.Name)
                 {
                     yield return(new GroupItem(g));
                 }
             }
         }
         else
         {
             yield break;
         }
     }
 }