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); }
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 RenderableObjectList && newRenderable is RenderableObjectList) { RenderableObjectList oldList = (RenderableObjectList)oldRenderable; RenderableObjectList newList = (RenderableObjectList)newRenderable; compareRefreshLists(newList, oldList); } }
/// <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 { throw new Exception("无法删除此图层"); } }
/// <summary> /// Add a child object to this layer. /// 添加一个 孩子 到这个图层。 /// </summary> public virtual void Add(RenderableObject ro) { try { 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++) { 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(); } } catch { } }