示例#1
0
 /// <summary>
 /// Removes a layer from the child layer list
 /// </summary>
 /// <param name="objectName">Name of object to remove</param>
 public virtual void Remove(string objectName)
 {
     lock (this.m_children.SyncRoot)
     {
         for (int i = 0; i < this.m_children.Count; i++)
         {
             RenderableObject ro = (RenderableObject)this.m_children[i];
             if (ro.Name.Equals(objectName))
             {
                 this.m_children.RemoveAt(i);
                 ro.Dispose();
                 ro.ParentList = null;
                 break;
             }
         }
     }
 }
示例#2
0
        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);
            }
        }
示例#3
0
        /// <summary>
        /// Sorts the children list according to priority
        /// TODO: Redesign the render tree to perhaps a list, to enable proper sorting
        /// </summary>
        public virtual void SortChildren()
        {
            int index = 0;

            while (index + 1 < m_children.Count)
            {
                RenderableObject a = (RenderableObject)m_children[index];
                RenderableObject b = (RenderableObject)m_children[index + 1];
                if (a.RenderPriority > b.RenderPriority)
                {
                    // Swap
                    m_children[index]     = b;
                    m_children[index + 1] = a;
                    index = 0;
                    continue;
                }
                index++;
            }
        }
示例#4
0
        ///<summary>
        /// 使照相机ZOOM到图层的位置。
        /// </summary>
        protected virtual void OnGotoClick(object sender, EventArgs e)
        {
            lock (this.ParentList.ChildObjects.SyncRoot)
            {
                for (int i = 0; i < this.ParentList.ChildObjects.Count; i++)
                {
                    RenderableObject ro = (RenderableObject)this.ParentList.ChildObjects[i];
                    if (ro.Name.Equals(name))
                    {
                        if (ro is QuadTileSet)
                        {
                            QuadTileSet qts = (QuadTileSet)ro;
                            DrawArgs.Camera.SetPosition((qts.North + qts.South) / 2, (qts.East + qts.West) / 2);
                            double perpendicularViewRange = (qts.North - qts.South > qts.East - qts.West ? qts.North - qts.South : qts.East - qts.West);
                            double altitude = qts.LayerRadius * Math.Sin(MathEngine.DegreesToRadians(perpendicularViewRange * 0.5));

                            DrawArgs.Camera.Altitude = altitude;

                            break;
                        }
                        else
                        {
                            double north = Convert.ToDouble(ro.MetaData["north"]);
                            double south = Convert.ToDouble(ro.MetaData["south"]);
                            double west  = Convert.ToDouble(ro.MetaData["west"]);
                            double east  = Convert.ToDouble(ro.MetaData["east"]);
                            DrawArgs.Camera.SetPosition((north + south) / 2, (west + east) / 2);
                        }
                        if (ro is Icon)
                        {
                            Icon ico = (Icon)ro;
                            DrawArgs.Camera.SetPosition(ico.Latitude, ico.Longitude);
                            DrawArgs.Camera.Altitude /= 2;

                            break;
                        }
                    }
                }
            }
        }
示例#5
0
        /// <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
            {
            }
        }
示例#6
0
        /// <summary>
        /// 刷新图标集合图层
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void refreshTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            if (isUpdating)
            {
                return;
            }
            isUpdating = true;
            try
            {
                for (int i = 0; i < this.ChildObjects.Count; i++)
                {
                    RenderableObject ro = (RenderableObject)this.ChildObjects[i];
                    if (ro != null && ro.IsOn && ro is Icon)
                    {
                        Icon icon = (Icon)ro;

                        if (icon.RefreshInterval == TimeSpan.MaxValue || icon.LastRefresh > System.DateTime.Now - icon.RefreshInterval)
                        {
                            continue;
                        }

                        object      key         = null;
                        IconTexture iconTexture = null;

                        if (icon.TextureFileName != null && icon.TextureFileName.Length > 0)
                        {
                            if (icon.TextureFileName.ToLower().StartsWith("http://") && icon.SaveFilePath != null)
                            {
                                //download it
                                try
                                {
                                    Qrst.Net.WebDownload webDownload = new Qrst.Net.WebDownload(icon.TextureFileName);
                                    webDownload.DownloadType = Qrst.Net.DownloadType.Unspecified;

                                    System.IO.FileInfo saveFile = new System.IO.FileInfo(icon.SaveFilePath);
                                    if (!saveFile.Directory.Exists)
                                    {
                                        saveFile.Directory.Create();
                                    }

                                    webDownload.DownloadFile(saveFile.FullName);
                                }
                                catch { }

                                iconTexture = (IconTexture)m_textures[icon.SaveFilePath];
                                if (iconTexture != null)
                                {
                                    IconTexture tempTexture = iconTexture;
                                    m_textures[icon.SaveFilePath] = new IconTexture(DrawArgs.Device, icon.SaveFilePath);
                                    tempTexture.Dispose();
                                }
                                else
                                {
                                    key         = icon.SaveFilePath;
                                    iconTexture = new IconTexture(DrawArgs.Device, icon.SaveFilePath);

                                    // New texture, cache it
                                    m_textures.Add(key, iconTexture);

                                    // Use default dimensions if not set
                                    if (icon.Width == 0)
                                    {
                                        icon.Width = iconTexture.Width;
                                    }
                                    if (icon.Height == 0)
                                    {
                                        icon.Height = iconTexture.Height;
                                    }
                                }
                            }
                            else
                            {
                                // Icon image from file
                                iconTexture = (IconTexture)m_textures[icon.TextureFileName];
                                if (iconTexture != null)
                                {
                                    IconTexture tempTexture = iconTexture;
                                    m_textures[icon.SaveFilePath] = new IconTexture(DrawArgs.Device, icon.TextureFileName);
                                    tempTexture.Dispose();
                                }
                                else
                                {
                                    key         = icon.SaveFilePath;
                                    iconTexture = new IconTexture(DrawArgs.Device, icon.TextureFileName);

                                    // New texture, cache it
                                    m_textures.Add(key, iconTexture);

                                    // Use default dimensions if not set
                                    if (icon.Width == 0)
                                    {
                                        icon.Width = iconTexture.Width;
                                    }
                                    if (icon.Height == 0)
                                    {
                                        icon.Height = iconTexture.Height;
                                    }
                                }
                            }
                        }
                        else
                        {
                            // Icon image from bitmap
                            if (icon.Image != null)
                            {
                                iconTexture = (IconTexture)m_textures[icon.Image];
                                if (iconTexture != null)
                                {
                                    IconTexture tempTexture = iconTexture;
                                    m_textures[icon.SaveFilePath] = new IconTexture(DrawArgs.Device, icon.Image);
                                    tempTexture.Dispose();
                                }
                                else
                                {
                                    key         = icon.SaveFilePath;
                                    iconTexture = new IconTexture(DrawArgs.Device, icon.Image);

                                    // New texture, cache it
                                    m_textures.Add(key, iconTexture);

                                    // Use default dimensions if not set
                                    if (icon.Width == 0)
                                    {
                                        icon.Width = iconTexture.Width;
                                    }
                                    if (icon.Height == 0)
                                    {
                                        icon.Height = iconTexture.Height;
                                    }
                                }
                            }
                        }

                        icon.LastRefresh = System.DateTime.Now;
                    }
                }
            }
            catch { }
            finally
            {
                isUpdating = false;
            }
        }
示例#7
0
 /// <summary>
 /// 添加一个Icon对象.
 /// </summary>
 public override void Add(RenderableObject ro)
 {
     m_children.Add(ro);
     isInitialized = false;
 }