-
Notifications
You must be signed in to change notification settings - Fork 119
/
Copy pathBPOITipControl.cs
321 lines (310 loc) · 13.3 KB
/
BPOITipControl.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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using Newtonsoft.Json.Linq;
using BMap.NET.WindowsForm.BMapElements;
namespace BMap.NET.WindowsForm
{
/// <summary>
/// POI信息显示控件
/// </summary>
partial class BPOITipControl : UserControl
{
public event SearchNearbyStartedEventHandler SearchNearbyStarted;
public event DirectionStartedEventHandler DirecttionStarted;
/// <summary>
/// 选项卡
/// </summary>
int _tab_index = 0;
private BPOI _poi;
/// <summary>
/// 与之对应的POI
/// </summary>
public BPOI POI
{
get
{
return _poi;
}
set
{
_poi = value;
//
if (_poi.DataSource["name"] != null)
lnkName.Text = (string)_poi.DataSource["name"]; //具体json格式参见api文档
if (_poi.DataSource["address"] != null)
txtAddress.Text = (string)_poi.DataSource["address"];
if (_poi.DataSource["telephone"] != null)
txtPhone.Text = (string)_poi.DataSource["telephone"];
if (_poi.DataSource["detail_info"] != null && _poi.DataSource["detail_info"]["price"] != null)
txtPrice.Text = "人均:¥" + (string)_poi.DataSource["detail_info"]["price"];
if (_poi.DataSource["detail_info"] != null && _poi.DataSource["detail_info"]["tag"] != null)
txtTag.Text = (string)_poi.DataSource["detail_info"]["tag"];
}
}
/// <summary>
/// 当前建议搜索城市
/// </summary>
public string CurrentCity
{
get
{
return bPlaceBox.CurrentCity;
}
set
{
bPlaceBox.CurrentCity = value;
}
}
/// <summary>
/// 构造方法
/// </summary>
public BPOITipControl()
{
InitializeComponent();
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);
UpdateStyles();
}
#region 事件处理
/// <summary>
/// 控件加载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BPOITipControl_Load(object sender, EventArgs e)
{
//显示形状
GraphicsPath gp = new GraphicsPath();
gp.AddLine(new Point(0, 0), new Point(Width, 0));
gp.AddLine(new Point(Width, 0), new Point(Width, Height - 40));
gp.AddLine(new Point(Width / 3 + 20, Height - 40), new Point(Width, Height - 40));
gp.AddLine(new Point(Width / 3 + 20, Height - 40), new Point(Width / 3 - 40, Height));
gp.AddLine(new Point(Width / 3 - 40, Height), new Point(Width / 3 - 20, Height - 40));
gp.AddLine(new Point(Width / 3 - 20, Height - 40), new Point(0, Height - 40));
this.Region = new Region(gp);
}
/// <summary>
/// 重绘
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BPOITipControl_Paint(object sender, PaintEventArgs e)
{
e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
//边框
GraphicsPath gp = new GraphicsPath();
gp.AddLine(new Point(0, 0), new Point(Width - 1, 0));
gp.AddLine(new Point(Width - 1, 0), new Point(Width - 1, Height - 40 - 1));
gp.AddLine(new Point(Width / 3 + 20 - 1, Height - 40 - 1), new Point(Width - 1, Height - 40 - 1));
gp.AddLine(new Point(Width / 3 + 20 - 1, Height - 40 - 1), new Point(Width / 3 - 40, Height - 1));
gp.AddLine(new Point(Width / 3 - 40, Height - 1), new Point(Width / 3 - 20 + 1, Height - 40 - 1));
gp.AddLine(new Point(Width / 3 - 20 + 1, Height - 40 - 1), new Point(0, Height - 40 - 1));
gp.AddLine(new Point(0, 0), new Point(0, Height - 40 - 1));
e.Graphics.DrawPath(Pens.Gray, gp);
using (Pen p = new Pen(Color.FromArgb(150, Color.LightGray)))
{
e.Graphics.DrawLine(p, new Point(0, 194 -15), new Point(Width, 194 - 15));
e.Graphics.DrawLine(p, new Point(Width / 3, 194 + 26 - 15), new Point(Width / 3, 194 - 15));
e.Graphics.DrawLine(p, new Point(Width * 2 / 3, 194 + 26 - 15), new Point(Width * 2 / 3, 194 - 15));
e.Graphics.DrawImage(Properties.BMap.ico_destination, new Point(10, 194 + 5 - 15));
e.Graphics.DrawImage(Properties.BMap.ico_source, new Point(Width / 3 + 10, 194 + 5 - 15));
e.Graphics.DrawImage(Properties.BMap.ico_search_in_bound, new Rectangle(Width * 2 / 3 + 10, 194 + 5 - 15, 18, 18));
using (Font f = new Font("微软雅黑", 9))
{
if (_tab_index == 0) //到这里去
{
e.Graphics.DrawLine(p, new Point(Width / 3, 194 + 26 - 15), new Point(Width, 194 + 26 - 15));
e.Graphics.DrawString("到这里去", f, Brushes.Gray, new PointF(25, 194 + 5 - 15));
e.Graphics.DrawString("从这里出发", f, Brushes.Blue, new PointF(Width / 3 + 25, 194 + 5 - 15));
e.Graphics.DrawString("周边搜索", f, Brushes.Blue, new PointF(Width * 2 / 3 + 25, 194 + 5 - 15));
}
else if (_tab_index == 1) //从这里出发
{
e.Graphics.DrawLine(p, new Point(0, 194 + 26 - 15), new Point(Width / 3, 194 + 26 - 15));
e.Graphics.DrawLine(p, new Point(Width * 2 / 3, 194 + 26 - 15), new Point(Width, 194 + 26 - 15));
e.Graphics.DrawString("到这里去", f, Brushes.Blue, new PointF(25, 194 + 5 - 15));
e.Graphics.DrawString("从这里出发", f, Brushes.Gray, new PointF(Width / 3 + 25, 194 + 5 - 15));
e.Graphics.DrawString("周边搜索", f, Brushes.Blue, new PointF(Width * 2 / 3 + 25, 194 + 5 - 15));
}
else //周边搜索
{
e.Graphics.DrawLine(p, new Point(0, 194 + 26 - 15), new Point(Width * 2 / 3, 194 + 26 - 15));
e.Graphics.DrawString("到这里去", f, Brushes.Blue, new PointF(25, 194 + 5 - 15));
e.Graphics.DrawString("从这里出发", f, Brushes.Blue, new PointF(Width / 3 + 25, 194 + 5 - 15));
e.Graphics.DrawString("周边搜索", f, Brushes.Gray, new PointF(Width * 2 / 3 + 25, 194 + 5 - 15));
}
}
}
}
/// <summary>
/// 鼠标移动
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BPOITipControl_MouseMove(object sender, MouseEventArgs e)
{
if (new Rectangle(0, 194 - 15, Width, 26).Contains(e.Location))
{
Cursor = Cursors.Hand;
}
else
{
Cursor = Cursors.Arrow;
}
}
/// <summary>
/// 鼠标点击 选项卡
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BPOITipControl_Click(object sender, EventArgs e)
{
Point p = PointToClient(Cursor.Position);
if (new Rectangle(0, 194 - 15, Width / 3, 26).Contains(p)) //到这里去
{
_tab_index = 0;
lblPlace.Text = "起点";
lblPlace.Visible = true;
bPlaceBox.Visible = true;
btndriving.Visible = true;
btntransit.Visible = true;
txtNearby.Visible = false;
btnsearch.Visible = false;
lnknearby_bank.Visible = false;
lnknearby_bus_station.Visible = false;
lnknearby_eatting.Visible = false;
lnknearby_hospital.Visible = false;
lnknearby_hotel.Visible = false;
}
if (new Rectangle(Width / 3, 194 - 15, Width / 3, 26).Contains(p)) //从这里出发
{
_tab_index = 1;
lblPlace.Text = "终点";
lblPlace.Visible = true;
bPlaceBox.Visible = true;
btndriving.Visible = true;
btntransit.Visible = true;
txtNearby.Visible = false;
btnsearch.Visible = false;
lnknearby_bank.Visible = false;
lnknearby_bus_station.Visible = false;
lnknearby_eatting.Visible = false;
lnknearby_hospital.Visible = false;
lnknearby_hotel.Visible = false;
}
if (new Rectangle(Width * 2 / 3, 194 - 15, Width / 3, 26).Contains(p)) //周边搜索
{
_tab_index = 2;
lblPlace.Visible = false;
bPlaceBox.Visible = false;
btndriving.Visible = false;
btntransit.Visible = false;
txtNearby.Visible = true;
btnsearch.Visible = true;
lnknearby_bank.Visible = true;
lnknearby_bus_station.Visible = true;
lnknearby_eatting.Visible = true;
lnknearby_hospital.Visible = true;
lnknearby_hotel.Visible = true;
lnknearby_bank.Location = new Point(lnknearby_bank.Location.X, 232 - 15 + 7);
lnknearby_bus_station.Location = new Point(lnknearby_bus_station.Location.X, 232 - 15 + 7);
lnknearby_eatting.Location = new Point(lnknearby_eatting.Location.X, 232 - 15 + 7);
lnknearby_hospital.Location = new Point(lnknearby_hospital.Location.X, 232 - 15 + 7);
lnknearby_hotel.Location = new Point(lnknearby_hotel.Location.X, 232 - 15 + 7);
btnsearch.Location = new Point(btnsearch.Location.X, 225 - 15 + 7);
txtNearby.Location = new Point(txtNearby.Location.X, 226 - 15 + 7);
}
Invalidate();
}
/// <summary>
/// 关闭
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void pictureBox1_Click(object sender, EventArgs e)
{
Visible = false;
}
/// <summary>
/// POI界面的logo绘制
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void piclogo_Paint(object sender, PaintEventArgs e)
{
using (SolidBrush sb = new SolidBrush(Color.FromArgb(200, Color.White)))
{
e.Graphics.FillRectangle(sb, e.ClipRectangle);
}
}
/// <summary>
/// 公交导航
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btntransit_Click(object sender, EventArgs e)
{
if (DirecttionStarted != null)
{
if (_tab_index == 0) //到这里去
{
DirecttionStarted(bPlaceBox.QueryText, (string)_poi.DataSource["name"], RouteType.Transit);
}
else //从这里出发
{
DirecttionStarted((string)_poi.DataSource["name"], bPlaceBox.QueryText, RouteType.Transit);
}
}
}
/// <summary>
/// 驾车导航
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btndriving_Click(object sender, EventArgs e)
{
if (DirecttionStarted != null && bPlaceBox.QueryText != "")
{
if (_tab_index == 0) //到这里去
{
DirecttionStarted(bPlaceBox.QueryText, (string)_poi.DataSource["name"], RouteType.Driving);
}
else //从这里出发
{
DirecttionStarted((string)_poi.DataSource["name"], bPlaceBox.QueryText, RouteType.Driving);
}
}
}
/// <summary>
/// 周边搜索
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnsearch_Click(object sender, EventArgs e)
{
if (SearchNearbyStarted != null && txtNearby.Text != "")
{
SearchNearbyStarted(txtNearby.Text, _poi.Location);
}
}
/// <summary>
/// 快速周边搜索
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void lnk_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
if (SearchNearbyStarted != null)
{
SearchNearbyStarted((sender as LinkLabel).Text, _poi.Location);
}
}
#endregion
}
}