/// <summary>
        ///
        /// </summary>
        /// <param name="newList"></param>
        /// <param name="curList"></param>
        private void compareRefreshLists(RenderableObjectList newList, RenderableObjectList curList)
        {
            ArrayList addList = new ArrayList();
            ArrayList delList = new ArrayList();

            foreach (RenderableObject newObject in newList.ChildObjects)
            {
                bool foundObject = false;
                foreach (RenderableObject curObject in curList.ChildObjects)
                {
                    string xmlSource = curObject.MetaData["XmlSource"] as string;

                    if (xmlSource != null && xmlSource == m_DataSource && newObject.Name == curObject.Name)
                    {
                        foundObject = true;
                        updateRenderable(curObject, newObject);
                        break;
                    }
                }

                if (!foundObject)
                {
                    addList.Add(newObject);
                }
            }

            foreach (RenderableObject curObject in curList.ChildObjects)
            {
                bool foundObject = false;
                foreach (RenderableObject newObject in newList.ChildObjects)
                {
                    string xmlSource = newObject.MetaData["XmlSource"] as string;
                    if (xmlSource != null && xmlSource == m_DataSource && newObject.Name == curObject.Name)
                    {
                        foundObject = true;
                        break;
                    }
                }

                if (!foundObject)
                {
                    string src = (string)curObject.MetaData["XmlSource"];

                    if (src != null || src == m_DataSource)
                    {
                        delList.Add(curObject);
                    }
                }
            }

            foreach (RenderableObject o in addList)
            {
                curList.Add(o);
            }

            foreach (RenderableObject o in delList)
            {
                curList.Remove(o);
            }
        }
        /// <summary>
        /// Enables layer with specified name
        /// 使图层或图层列表可以用。
        /// </summary>
        /// <returns>False if layer not found.</returns>
        public virtual bool Enable(string name)
        {
            if (name == null || name.Length == 0)
            {
                return(true);
            }

            string lowerName = name.ToLower();

            foreach (RenderableObject ro in m_children)
            {
                if (ro.Name.ToLower() == lowerName)
                {
                    ro.IsOn = true;
                    return(true);
                }

                RenderableObjectList rol = ro as RenderableObjectList;
                if (rol == null)
                {
                    continue;
                }

                // Recurse down
                if (rol.Enable(name))
                {
                    rol.isOn = true;
                    return(true);
                }
            }

            return(false);
        }
        /// <summary>
        /// 添加一个子图层到这个图层列表。
        /// Add a child object to this layer.
        /// </summary>
        public virtual void Add(RenderableObject ro)
        {
            lock (this.m_children.SyncRoot)
            {
                RenderableObjectList dupList   = null;
                RenderableObject     duplicate = null;
                ro.ParentList = this;
                foreach (RenderableObject childRo in m_children)
                {
                    if (childRo is RenderableObjectList && childRo.Name == ro.Name)
                    {
                        dupList = (RenderableObjectList)childRo;
                        break;
                    }
                    else if (childRo.Name == ro.Name)
                    {
                        duplicate = childRo;
                        break;
                    }
                }

                if (dupList != null)
                {
                    RenderableObjectList rol = (RenderableObjectList)ro;

                    foreach (RenderableObject childRo in rol.ChildObjects)
                    {
                        dupList.Add(childRo);
                    }
                }
                else
                {
                    if (duplicate != null)
                    {
                        for (int i = 1; i < 100; i++)
                        {//TODO:ZYM-20130707发现,需要解决工具加载时图层列表中出现多个相同名称的问题
                            ro.Name = string.Format("{0} [{1}]", duplicate.Name, i);
                            bool found = false;
                            foreach (RenderableObject childRo in m_children)
                            {
                                if (childRo.Name == ro.Name)
                                {
                                    found = true;
                                    break;
                                }
                            }
                            if (!found)
                            {
                                break;
                            }
                        }
                    }
                    m_children.Add(ro);
                }
                SortChildren();
            }
        }
Example #4
0
        /// <summary>
        /// 删除一个图层。
        /// </summary>
        public virtual void Delete()
        {
            RenderableObjectList list = this.ParentList;
            string xmlConfigFile      = (string)this.MetaData["XmlSource"];

            if (this.ParentList.Name == "Earth")
            {
                string message = "是否删除图层 '" + this.Name + "' ?";
                if (DialogResult.Yes != MessageBox.Show(message, "删除图层", MessageBoxButtons.YesNo, MessageBoxIcon.Warning,
                                                        MessageBoxDefaultButton.Button2))
                {
                    return;
                }
                this.ParentList.Remove(this);
            }
            else
            {
                MessageBox.Show("无法删除当前子图层", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                throw new Exception("无法删除此图层");
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="oldRenderable"></param>
        /// <param name="newRenderable"></param>
        private void updateRenderable(RenderableObject oldRenderable, RenderableObject newRenderable)
        {
            if (oldRenderable is Icon && newRenderable is Icon)
            {
                Icon oldIcon = (Icon)oldRenderable;
                Icon newIcon = (Icon)newRenderable;

                oldIcon.SetPosition((float)newIcon.Latitude, (float)newIcon.Longitude, (float)newIcon.Altitude);
            }
            else if (oldRenderable is GCP && newRenderable is GCP)
            {
                GCP oldGCP = (GCP)oldRenderable;
                GCP newGCP = (GCP)newRenderable;

                oldGCP.SetPosition((float)newGCP.Latitude, (float)newGCP.Longitude, (float)newGCP.Altitude);
            }
            else if (oldRenderable is RenderableObjectList && newRenderable is RenderableObjectList)
            {
                RenderableObjectList oldList = (RenderableObjectList)oldRenderable;
                RenderableObjectList newList = (RenderableObjectList)newRenderable;

                compareRefreshLists(newList, oldList);
            }
        }