public void Render(DrawArgs drawArgs) { const int screenMargin = 10; m_renderPosition = new Vector2(drawArgs.screenWidth - HalfWidth - screenMargin, drawArgs.screenHeight - screenMargin); ImageAccessor logoAccessor = null; // 显示下载进度条 for (int i = 0; i < DrawArgs.DownloadQueue.ActiveDownloads.Count; i++) { DownloadRequest request = (DownloadRequest)DrawArgs.DownloadQueue.ActiveDownloads[i]; GeoSpatialDownloadRequest geoRequest = request as GeoSpatialDownloadRequest; if (geoRequest == null) { continue; } RenderProgress(drawArgs, geoRequest); RenderRectangle(drawArgs, geoRequest); ImageTileRequest imageRequest = geoRequest as ImageTileRequest; if (imageRequest == null) { continue; } QuadTile qt = imageRequest.QuadTile; if (qt.QuadTileArgs.ImageAccessor.ServerLogoPath != null) { logoAccessor = qt.QuadTileArgs.ImageAccessor; } } if (logoAccessor != null) { RenderLogo(drawArgs, logoAccessor); } }
/// <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); }
public virtual GeoSpatialDownloadRequest RequestTexture(DrawArgs drawArgs, GeographicBoundingBox geoBox, int level) { ImageTileInfo info = GetImageTileInfo(geoBox, level); GeoSpatialDownloadRequest request = GetDownloadRequest(geoBox, info); if (!request.IsComplete) { m_downloadQueue.AddToDownloadQueue(drawArgs, request); } return(request); }
//显示下载进度条 protected virtual void RenderProgress(DrawArgs drawArgs, GeoSpatialDownloadRequest request) { const int height = 4; const int spacing = 2; if (m_progressBar == null) { m_progressBar = new ProgressBar(HalfWidth * 2 * 4 / 5, height); // 4/5 of icon width } m_progressBar.Draw(drawArgs, m_renderPosition.X, m_renderPosition.Y - height, request.Progress, request.Color); m_renderPosition.Y -= height + spacing; }
/// <summary> /// Removes a request from the download queue. /// </summary> public virtual void RemoveFromDownloadQueue(GeoSpatialDownloadRequest removeRequest) { lock (m_downloadRequests.SyncRoot) { string key = removeRequest.ToString(); GeoSpatialDownloadRequest request = (GeoSpatialDownloadRequest)m_downloadRequests[key]; if (request != null) { m_downloadRequests.Remove(key); //if (request.QuadTile != null) // request.QuadTile.DownloadRequest = null; } } }
public bool Contains(GeoSpatialDownloadRequest request) { bool result = m_downloadRequests.Contains(request); if (!result) { for (int i = 0; i < MaxConcurrentDownloads; i++) { if (m_activeDownloads[i] == request) { result = true; break; } } } return(result); }
public virtual void AddToDownloadQueue(DrawArgs drawArgs, GeoSpatialDownloadRequest newRequest) { string key = newRequest.ToString(); lock (m_downloadRequests.SyncRoot) { if (m_downloadRequests.Contains(key)) { return; } m_downloadRequests.Add(key, newRequest); if (m_downloadRequests.Count >= this._maxQueueSize) { //remove spatially farthest request GeoSpatialDownloadRequest farthestRequest = null; Angle curDistance = Angle.Zero; Angle farthestDistance = Angle.Zero; foreach (GeoSpatialDownloadRequest curRequest in m_downloadRequests.Values) { curDistance = SMath.SphericalDistance( curRequest.CenterLatitude, curRequest.CenterLongitude, drawArgs.WorldCamera.Latitude, drawArgs.WorldCamera.Longitude); if (curDistance > farthestDistance) { farthestRequest = curRequest; farthestDistance = curDistance; } } m_downloadRequests.Remove(farthestRequest.ToString()); } } ServiceDownloadQueue(); }
/// <summary> /// Render a rectangle around an image tile in the specified color /// </summary> public void RenderRectangle(DrawArgs drawArgs, GeoSpatialDownloadRequest request) { int color = request.Color; // Render terrain download rectangle float radius = (float)drawArgs.WorldCamera.WorldRadius; Vector3 northWestV = MathEngine.SphericalToCartesian(request.North, request.West, radius); Vector3 southWestV = MathEngine.SphericalToCartesian(request.South, request.West, radius); Vector3 northEastV = MathEngine.SphericalToCartesian(request.North, request.East, radius); Vector3 southEastV = MathEngine.SphericalToCartesian(request.South, request.East, radius); downloadRectangle[0].X = northWestV.X; downloadRectangle[0].Y = northWestV.Y; downloadRectangle[0].Z = northWestV.Z; downloadRectangle[0].Color = color; downloadRectangle[1].X = southWestV.X; downloadRectangle[1].Y = southWestV.Y; downloadRectangle[1].Z = southWestV.Z; downloadRectangle[1].Color = color; downloadRectangle[2].X = southEastV.X; downloadRectangle[2].Y = southEastV.Y; downloadRectangle[2].Z = southEastV.Z; downloadRectangle[2].Color = color; downloadRectangle[3].X = northEastV.X; downloadRectangle[3].Y = northEastV.Y; downloadRectangle[3].Z = northEastV.Z; downloadRectangle[3].Color = color; downloadRectangle[4].X = downloadRectangle[0].X; downloadRectangle[4].Y = downloadRectangle[0].Y; downloadRectangle[4].Z = downloadRectangle[0].Z; downloadRectangle[4].Color = color; drawArgs.device.VertexFormat = CustomVertex.PositionColored.Format; drawArgs.device.DrawUserPrimitives(PrimitiveType.LineStrip, 4, downloadRectangle); }
public virtual void Dispose() { try { isInitialized = false; for (int i = 0; i < textures.Length; i++) { if (textures[i] != null && !textures[i].Disposed) { textures[i].Dispose(); textures[i] = null; } } textures = null; if (northWestChild != null) { northWestChild.Dispose(); northWestChild = null; } if (southWestChild != null) { southWestChild.Dispose(); southWestChild = null; } if (northEastChild != null) { northEastChild.Dispose(); northEastChild = null; } if (southEastChild != null) { southEastChild.Dispose(); southEastChild = null; } if(DownloadRequest != null) { QuadTileSet.RemoveFromDownloadQueue(DownloadRequest); DownloadRequest.Dispose(); DownloadRequest = null; } } catch { } }
/// <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; } } }
public virtual void AddToDownloadQueue(CameraBase camera, GeoSpatialDownloadRequest newRequest) { QuadTile key = newRequest.QuadTile; key.WaitingForDownload = 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(); }
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(); }
/// <summary> /// Render download indicator rectangles /// </summary> protected virtual void RenderProgress(DrawArgs drawArgs, GeoSpatialDownloadRequest request) { const int height = 4; const int spacing = 2; // Render progress bar if(m_progressBar==null) m_progressBar = new ProgressBar(HalfWidth*2 * 4/5, height); // 4/5 of icon width m_progressBar.Draw(drawArgs, m_renderPosition.X, m_renderPosition.Y-height, request.Progress, request.Color); m_renderPosition.Y -= height+spacing; }
/// <summary> /// Render a rectangle around an image tile in the specified color /// </summary> public void RenderRectangle(DrawArgs drawArgs, GeoSpatialDownloadRequest request) { int color = request.Color; // Render terrain download rectangle float radius = (float)drawArgs.WorldCamera.WorldRadius; Vector3 northWestV = MathEngine.SphericalToCartesian(request.North, request.West, radius); Vector3 southWestV = MathEngine.SphericalToCartesian(request.South, request.West, radius); Vector3 northEastV = MathEngine.SphericalToCartesian(request.North, request.East, radius); Vector3 southEastV = MathEngine.SphericalToCartesian(request.South, request.East, radius); downloadRectangle[0].X = northWestV.X; downloadRectangle[0].Y = northWestV.Y; downloadRectangle[0].Z = northWestV.Z; downloadRectangle[0].Color = color; downloadRectangle[1].X = southWestV.X; downloadRectangle[1].Y = southWestV.Y; downloadRectangle[1].Z = southWestV.Z; downloadRectangle[1].Color = color; downloadRectangle[2].X = southEastV.X; downloadRectangle[2].Y = southEastV.Y; downloadRectangle[2].Z = southEastV.Z; downloadRectangle[2].Color = color; downloadRectangle[3].X = northEastV.X; downloadRectangle[3].Y = northEastV.Y; downloadRectangle[3].Z = northEastV.Z; downloadRectangle[3].Color = color; downloadRectangle[4].X = downloadRectangle[0].X; downloadRectangle[4].Y = downloadRectangle[0].Y; downloadRectangle[4].Z = downloadRectangle[0].Z; downloadRectangle[4].Color = color; drawArgs.device.VertexFormat = CustomVertex.PositionColored.Format; drawArgs.device.DrawUserPrimitives(PrimitiveType.LineStrip, 4, downloadRectangle); }
public virtual void Dispose() { try { isInitialized = false; if (texture != null && !texture.Disposed) { texture.Dispose(); texture = null; } if (northWestChild != null) { northWestChild.Dispose(); northWestChild = null; } if (southWestChild != null) { southWestChild.Dispose(); southWestChild = null; } if (northEastChild != null) { northEastChild.Dispose(); northEastChild = null; } if (southEastChild != null) { southEastChild.Dispose(); southEastChild = null; } if (DownloadRequest != null) { QuadTileSet.RemoveFromDownloadQueue(DownloadRequest); DownloadRequest.Dispose(); DownloadRequest = null; } } catch {} }
/// <summary> /// Removes a request from the download queue. /// </summary> public virtual void RemoveFromDownloadQueue(GeoSpatialDownloadRequest removeRequest, bool serviceQueue) { lock (((System.Collections.IDictionary)m_downloadRequests).SyncRoot) { IGeoSpatialDownloadTile key = removeRequest.Tile; if (m_downloadRequests.ContainsKey(key)) { GeoSpatialDownloadRequest request = m_downloadRequests[key]; if (request != null) { m_downloadRequests.Remove(key); request.Tile.DownloadRequests.Remove(request); } } if (serviceQueue) ServiceDownloadQueue(); } }