Beispiel #1
0
        /// <summary>
        /// Finds the "best" tile from queue
        /// </summary>
        public virtual GeoSpatialDownloadRequest GetClosestDownloadRequest()
        {
            GeoSpatialDownloadRequest closestRequest = null;
            GeoSpatialDownloadRequest firstRequest   = null;
            double largestArea = double.MinValue;

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

                    BoundingBox bb = new BoundingBox((float)curRequest.Boundary.South,
                                                     (float)curRequest.Boundary.North,
                                                     (float)curRequest.Boundary.West,
                                                     (float)curRequest.Boundary.East,
                                                     (float)m_camera.WorldRadius,
                                                     (float)m_camera.WorldRadius + 300000f);
                    if (!m_camera.ViewFrustum.Intersects(bb))
                    {
                        deletionList.Add(curRequest);
                        continue;
                    }

                    double screenArea = bb.CalcRelativeScreenArea(m_camera);
                    if (screenArea > largestArea)
                    {
                        largestArea    = screenArea;
                        closestRequest = curRequest;
                    }
                    if (firstRequest != null)
                    {
                        firstRequest = curRequest;
                    }
                }
            }

            // Remove requests that point to invisible tiles
            foreach (GeoSpatialDownloadRequest req in deletionList)
            {
                m_downloadRequests.Remove(req.ToString());
                //if (req.QuadTile != null)
                //    req.QuadTile.DownloadRequest = null;
            }
            deletionList.Clear();

            if (closestRequest == null && firstRequest != null)
            {
                closestRequest = firstRequest;
            }

            return(closestRequest);
        }