-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainForm.cs
274 lines (256 loc) · 9.05 KB
/
MainForm.cs
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Security.Permissions;
using System.Runtime.InteropServices;
using System.Collections;
namespace mapdemo2
{
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
[ComVisible(true)]
public partial class MainForm : Form
{
//Vertex[] vertexs;
//static int vexnumber=0;
//internal NodesCollection Nodes;
private static Graphic map=new Graphic();
public static MainForm fr1;
public static WebBrowser web1;
NodesCollection NC = new NodesCollection();//窗口内临时储存点集
//Node Snode;
internal static Graphic Map
{
get
{
return map;
}
set
{
map = value;
}
}
public MainForm()
{
InitializeComponent();
fr1 = this;
web1 = this.webBrowser1;
}
private void Form1_Load(object sender, EventArgs e)
{
string str_url = Application.StartupPath + "\\gdmcmap.html";
Uri url = new Uri(str_url);
//webBrowser1.Url = url;
webBrowser1.Navigate(url);
webBrowser1.ObjectForScripting = this;
}
//public void AddVex(string name, string tag, string note, double lng, double lat)
//{
// vertexs[vexnumber] = new Vertex(name, tag, note, lng, lat);
// vexnumber++;
// //comboBox2.Items.Add(pointname[t]);
// //comboBox1.Items.Add(b);//添加终点
// ////}
// string v = combox1select.ToString();//获取终点名
// textBox5.Text = " ";
// if (t == r1)
// {
// MessageBox.Show("各点分别为: \n");
// for (int i = 0; i < r1; i++)
// //Console.Write("V{0} ", i);
// MessageBox.Show("V" + i + pointname[i]);
// //Console.Write(" 假定第一个点是配送中心");
// MessageBox.Show(" 假定第一个点是配送中心");
// //Console.WriteLine("\n\n输入各点之间的距离(无通径的用个大整数表示)\n");
// MessageBox.Show("\n\n输入各点之间的距离(无通径的用个大整数表示)\n");
// }
//}
//导航
internal void Navigate(Node start,Node end)
{
webBrowser1.Document.InvokeScript("CarN", new object[] { start.Lng,start.Lat,end.Lng,end.Lat });
webBrowser1.Document.InvokeScript("WalkerN", new object[] { start.Lng, start.Lat, end.Lng, end.Lat });
}
//初始化标注工具
private Boolean InitilMarktool()
{
webBrowser1.Document.InvokeScript("f");
return true;
}
//添加标注点信息
public void AddInfo(string tag,string note,string name= "我的标注")
{
webBrowser1.Document.InvokeScript("CreateMarker", new object[] { tag, note,name });
}
//弹出标注信息窗口,js调用
public void ShowInfo()
{
frmMarker fr2 = new frmMarker();
fr2.ShowDialog();
}
//public Node Search(string Sname,string Stag,string Snote)
//{
// foreach(Node snode in map.Node.Nodes)
// {
// if(snode.Name==Sname||snode.Tag==Stag||snode.Note==Snote)
// {
// return snode;
// }
// }
// return null;
//}
public bool NodeSearch(string Sname, string Stag="", string Snote="")
{
NodesCollection nc = new NodesCollection();
//NodesCollection n = new NodesCollection();
//n = map.Node.Nodes;
foreach (Node snode1 in map.Node.Nodes)
{
nc.Add(snode1);
}
//nc = map.Node.Nodes;//临时储存点集
for (int i=nc.Count-1;i>=0;i--)
{
Node snode = nc[i];
if (snode.Name == Sname || snode.Tag == Stag || snode.Note == Snote)
{
NC.Add(snode);
nc.Remove(snode);
}
}
//string s = "";
//foreach (Node snode in nc)
//{
// if (snode.Name == Sname || snode.Tag == Stag || snode.Note == Snote)
// {
// NC.Add(snode);
// nc.Remove(snode);
// }
//}
return true;
}
internal Node SearchNode(string Sname)
{
NodesCollection nc = new NodesCollection();
foreach (Node snode1 in map.Node.Nodes)
{
nc.Add(snode1);
}
//nc = map.Node.Nodes;//临时储存点集
for (int i = nc.Count - 1; i >= 0; i--)
{
Node snode = nc[i];
if (snode.Name == Sname )
{
return snode;
}
}
return null;
}
internal bool EdgeSearch(string start,string end, EdgesCollection ec, Edge e1)
{
for(int i=ec.Count-1;i>=0;i--)
{
e1 = ec[i];
if (e1.Snode.Name == start && e1.Enode.Name == end)
{
return true;
}
}
return false;
}
//int[] print;//定义输入点到点距离大小的数组
int k = 0;//用于自增后读出print里的数据
internal void exchange(EdgesCollection edge)
{
int r = map.Node.Nodes.Count;//输入点数R
double[] a=new double[(r + 1) * (r + 1)];
for (int i = 0; i < r; i++)
{
for (int j = i + 1; j < r; j++)
{
MessageBox.Show(edge[k].Snode.Name + "到" + edge[k].Enode.Name + "的距离是:" + edge[k].Svalue);
a[i * r + j] = edge[k].Svalue;
if (k < r * (r - 1) / 2)
{
k++;
}
}
}
//----完善距离矩阵(距离矩阵其实可以是个上三角矩阵,
//----但为了处理方便,还是将其完整成一个对称阵)-----------
for (int i = 0; i < r; i++)
{
for (int j = 0; j < r; j++)
{
if (i == j)
{
a[i * r + j] = 0;
}
a[j * r + i] = a[i * r + j];
}
if (i == r - 1)
{
Marx m = new Marx(r, a);
string outs="";
m.Find_way();
m.Display(ref outs, comEnd.Text, map.Node.Nodes);
txtOutroute.Text = outs;
}
}
}
private void btnMarker_Click(object sender, EventArgs e)
{
InitilMarktool();
}
private void btnNavigate_Click(object sender, EventArgs e)
{
Navigate(SearchNode( comStart.Text),SearchNode( comEnd.Text));
exchange(map.Edge.Edges);
}
private void btnDistance_Click(object sender, EventArgs e)
{
webBrowser1.Document.InvokeScript("openGetDistance");
}
private void btnSearch_Click(object sender, EventArgs e)
{
webBrowser1.Document.InvokeScript("ClearSearch");
//Node SEnode = new Node();
NodeSearch(txtSearch.Text, txtSearch.Text, txtSearch.Text);
foreach(Node SEnode in NC)
{
if(SEnode!=null)
{
webBrowser1.Document.InvokeScript("addMapOverlay", new object[] {SEnode.Name,SEnode.Tag,SEnode.Note,SEnode.Lng,SEnode.Lat });
}
}
NC.Clear();
//map.Node.Nodes.IndexOf(Snode.Name = txtSearch.Text);
//string s="hah";
//webBrowser1.Document.InvokeScript("LocalSearch", new object[] { txtSearch.Text });
}
private void btnDsave_Click(object sender, EventArgs e)
{
EdgesCollection EC = map.Edge.Edges;
Edge edge = new Edge();
double svalue=double.Parse(txtDistance.Text);;
if (EdgeSearch(txtDstart.Text, txtDend.Text, EC,edge))
{
edge.Svalue = svalue;
}
else
{
if (SearchNode(txtDstart.Text)!=null && SearchNode(txtDend.Text)!=null)
{
edge = new Edge(SearchNode(txtDstart.Text), SearchNode(txtDend.Text));
edge.Svalue = svalue;
EC.Add(edge);
}
}
}
}
}