cloudflight
2024-05-06 71c956d53e25d73947ce14690fae74f3542da002
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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);
        }
 
    }
}