cloudflight
2024-07-06 d907f85dd2d7ebf702ffd478fcf5d47c2a29560c
Hydraulic/Hydro.MapUI/Map/DMap.cs
@@ -24,6 +24,9 @@
        
        public DrawDelegate DrawNet = null;
        public DrawDelegate DrawNetNew = null;
        public DrawDelegate DrawBackGroundPic = null;
        //绘制辅助线
        public DrawDelegate DrawAuxiliary = null;
@@ -31,8 +34,11 @@
        public MouseDelegate onMouseMove = null;
        public MouseDelegate onMouseUp = null;
        public MouseDelegate onMouseWheel = null;
        public DrawingMode drawingMode = DrawingMode.All;
        private bool Inited = false;
        public DrawingStatus Status = DrawingStatus.Ready;
        public DMap()
        {
            InitializeComponent();
@@ -44,19 +50,22 @@
            this.TC = TC;
            this.DrawNet = Draws[0];
            this.DrawNetNew = Draws[1];
            this.DrawAuxiliary = Draws[2];
            this.DrawBackGroundPic = Draws[2];
            this.DrawAuxiliary = Draws[3];
            this.onMouseDown = MouseEvents[0];
            this.onMouseMove = MouseEvents[1];
            this.onMouseUp = MouseEvents[2];
            this.onMouseWheel = MouseEvents[3];
            this.Inited = true;
            this.Status=DrawingStatus.Ready;
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            this.Status= DrawingStatus.drawingBase;
            base.OnPaint(e);
            if (!Inited) return;
            if (float.IsInfinity(mapOption.zoom)) return;
            if (!Inited) { this.Status = DrawingStatus.Ready; return; }
            if (float.IsInfinity(mapOption.zoom)) { this.Status = DrawingStatus.Ready; return; }
            _needPaintAll = false;
            if (buffer == null || buffer.Width != Width || buffer.Height != Height)
@@ -65,30 +74,32 @@
                buffer = new Bitmap(Width, Height);
            }
            // 使用缓存绘制,避免在每次重绘时重新计算所有要绘制的元素
            var bufferG = Graphics.FromImage(buffer);
            // 先将控件的背景填充为白色
            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);
            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);
            this.Status = DrawingStatus.drawingPic;
            DrawBackGroundPic(bufferG, _Template);
            this.Status = DrawingStatus.drawingNet;
            //BookMark    :绘制地图事件
            DrawNet(bufferG, _Template);
                //BookMark    :绘制地图事件
                DrawNet(bufferG, _Template);
            this.Status = DrawingStatus.drawingNetNew;
            if (_newTemplate?.network != null) DrawNetNew(bufferG, _newTemplate);
                if (_newTemplate?.network != null) DrawNetNew(bufferG, _newTemplate);
                DrawAuxiliary(bufferG,null);
            }
            this.Status = DrawingStatus.drawingOthers;
            DrawAuxiliary(bufferG, null);
            // 将生成的画布绘制到控件上
            e.Graphics.DrawImage(buffer, 0, 0);
            bufferG.Dispose();
            this.Status = DrawingStatus.Ready;
        }
        protected override void OnMouseDown(MouseEventArgs e)