Example #1
0
        /// <summary>
        /// Finds the "best" tile from queue
        /// 从队列中寻找最佳的瓦片
        /// </summary>
        public virtual GeoSpatialDownloadRequest GetClosestDownloadRequest()
        {
            GeoSpatialDownloadRequest closestRequest = null;
            float largestArea = float.MinValue;

            lock (m_downloadRequests.SyncRoot)
            {
                foreach (GeoSpatialDownloadRequest curRequest in m_downloadRequests.Values)
                {
                    if (curRequest.IsDownloading)
                    {
                        continue;
                    }

                    QuadTile qt = curRequest.QuadTile;
                    if (!m_camera.ViewFrustum.Intersects(qt.BoundingBox))
                    {
                        continue;
                    }

                    float screenArea = qt.BoundingBox.CalcRelativeScreenArea(m_camera);
                    if (screenArea > largestArea)
                    {
                        largestArea    = screenArea;
                        closestRequest = curRequest;
                    }
                }
            }

            return(closestRequest);
        }
Example #2
0
 /// <summary>
 /// Removes a request from the download queue.
 /// 从下载队列中移除一个下载请求
 /// </summary>
 public virtual void RemoveFromDownloadQueue(GeoSpatialDownloadRequest removeRequest)
 {
     lock (m_downloadRequests.SyncRoot)
     {
         QuadTile key = removeRequest.QuadTile;
         GeoSpatialDownloadRequest request = (GeoSpatialDownloadRequest)m_downloadRequests[key];
         if (request != null)
         {
             m_downloadRequests.Remove(key);
             request.QuadTile.DownloadRequest = null;
         }
     }
 }
Example #3
0
        /// <summary>
        /// 渲染下载进度
        /// </summary>
        /// <param name="drawArgs"></param>
        /// <param name="request"></param>
        /// <param name="offset"></param>
        public void RenderDownloadProgress(DrawArgs drawArgs, GeoSpatialDownloadRequest request, int offset)
        {
            int halfIconHeight = 24;
            int halfIconWidth  = 24;

            Vector3 projectedPoint = new Vector3(DrawArgs.ParentControl.Width - halfIconWidth - 10, DrawArgs.ParentControl.Height - 34 - 4 * offset, 0.5f);

            // Render progress bar
            if (progressBar == null)
            {
                progressBar = new ProgressBar(40, 4);
            }
            progressBar.Draw(drawArgs, projectedPoint.X, projectedPoint.Y + 24, request.ProgressPercent, World.Settings.DownloadProgressColor.ToArgb());
            DrawArgs.Device.RenderState.ZBufferEnable = true;

            // Render server logo
            if (ServerLogoFilePath == null)
            {
                return;
            }

            if (m_iconTexture == null)
            {
                m_iconTexture = ImageHelper.LoadIconTexture(ServerLogoFilePath);
            }

            if (sprite == null)
            {
                using (Surface s = m_iconTexture.GetSurfaceLevel(0))
                {
                    SurfaceDescription desc = s.Description;
                    m_spriteSize = new Rectangle(0, 0, desc.Width, desc.Height);
                }

                this.sprite = new Sprite(DrawArgs.Device);
            }

            float scaleWidth  = (float)2.0f * halfIconWidth / m_spriteSize.Width;
            float scaleHeight = (float)2.0f * halfIconHeight / m_spriteSize.Height;

            this.sprite.Begin(SpriteFlags.AlphaBlend);
            this.sprite.Transform = Matrix.Transformation2D(new Vector2(0.0f, 0.0f), 0.0f, new Vector2(scaleWidth, scaleHeight),
                                                            new Vector2(0, 0),
                                                            0.0f, new Vector2(projectedPoint.X, projectedPoint.Y));

            this.sprite.Draw(m_iconTexture, m_spriteSize,
                             new Vector3(1.32f * 48, 1.32f * 48, 0), new Vector3(0, 0, 0),
                             World.Settings.DownloadLogoColor);
            this.sprite.End();
        }
Example #4
0
        /// <summary>
        /// 添加到下载队列(ZYM:20130706)
        /// </summary>
        /// <param name="camera"></param>
        /// <param name="newRequest"></param>
        public virtual void AddToDownloadQueue(CameraBase camera, GeoSpatialDownloadRequest newRequest)
        {
            QuadTile key = newRequest.QuadTile;

            key.IsWaitingForDownload = true;
            lock (m_downloadRequests.SyncRoot)
            {
                if (m_downloadRequests.Contains(key))
                {
                    return;
                }

                m_downloadRequests.Add(key, newRequest);

                if (m_downloadRequests.Count >= m_maxQueueSize)
                {
                    //remove spatially farthest request
                    GeoSpatialDownloadRequest farthestRequest = null;
                    Angle curDistance      = Angle.Zero;
                    Angle farthestDistance = Angle.Zero;
                    foreach (GeoSpatialDownloadRequest curRequest in m_downloadRequests.Values)
                    {
                        curDistance = MathEngine.SphericalDistance(
                            curRequest.QuadTile.CenterLatitude,
                            curRequest.QuadTile.CenterLongitude,
                            camera.Latitude,
                            camera.Longitude);

                        if (curDistance > farthestDistance)
                        {
                            farthestRequest  = curRequest;
                            farthestDistance = curDistance;
                        }
                    }

                    farthestRequest.Dispose();
                    farthestRequest.QuadTile.DownloadRequest = null;
                    m_downloadRequests.Remove(farthestRequest.QuadTile);
                }
            }

            ServiceDownloadQueue();
        }