using Hydro.MapView; using Hydro.MapView.Common; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Threading.Tasks; //using System.Web.UI.Design.WebControls; using System.Windows.Forms; using static Hydro.MapView.MapViewEnum; namespace Hydro.MapUI { public partial class DMap : Panel { private bool _needPaintAll; private Bitmap buffer; public DrawDelegate DrawNet = null; public DrawDelegate DrawNetNew = null; //绘制辅助线 public DrawDelegate DrawAuxiliary = null; public MouseDelegate onMouseDown = null; public MouseDelegate onMouseMove = null; public MouseDelegate onMouseUp = null; public MouseDelegate onMouseWheel = null; private bool Inited = false; public DMap() { InitializeComponent(); DoubleBuffered = true; } //补充参数 public void Init(TContainer TC, DrawDelegate[] Draws, MouseDelegate[] MouseEvents) { this.TC = TC; this.DrawNet = Draws[0]; this.DrawNetNew = Draws[1]; this.DrawAuxiliary = Draws[2]; this.onMouseDown = MouseEvents[0]; this.onMouseMove = MouseEvents[1]; this.onMouseUp = MouseEvents[2]; this.onMouseWheel = MouseEvents[3]; this.Inited = true; } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (!Inited) return; if (float.IsInfinity(mapOption.zoom)) return; _needPaintAll = false; if (buffer == null || buffer.Width != Width || buffer.Height != Height) { buffer?.Dispose(); buffer = new Bitmap(Width, Height); } // 使用缓存绘制,避免在每次重绘时重新计算所有要绘制的元素 using (var bufferG = Graphics.FromImage(buffer)) //using (var bufferG = e.Graphics) { // 先将控件的背景填充为白色 bufferG.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; bufferG.Clear(Color.Transparent); bufferG.TranslateTransform(Width / 2, Height / 2); bufferG.ScaleTransform(mapOption.zoom, -mapOption.zoom); bufferG.TranslateTransform(-mapOption.Center.X, -mapOption.Center.Y); //BookMark :绘制地图事件 DrawNet(bufferG, _Template); if (_newTemplate?.network != null) DrawNetNew(bufferG, _newTemplate); DrawAuxiliary(bufferG,null); } // 将生成的画布绘制到控件上 e.Graphics.DrawImage(buffer, 0, 0); } protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); if (Inited) onMouseDown(e); } protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (Inited) onMouseMove(e); } protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); if (Inited) onMouseUp(e); } protected override void OnMouseWheel(MouseEventArgs e) { base.OnMouseWheel(e); if (Inited) onMouseWheel(e); } } }