forked from JonneyDong/JocationRelease
-
Notifications
You must be signed in to change notification settings - Fork 0
/
frmMap.cs
229 lines (226 loc) · 8.56 KB
/
frmMap.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LocationCleaned
{
[ComVisible(true)]
public partial class frmMap : Form
{
/// <summary>
/// 经纬度坐标
/// </summary>
public Location Location { get; set; } = new Location();
public frmMap()
{
InitializeComponent();
}
private void frmMap_Load(object sender, EventArgs e)
{
this.webBrowser1.ScriptErrorsSuppressed = true;
var text = @"<html xmlns='http://www.w3.org/1999/xhtml\'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<title>站点地图</title>
<style type='text/css'>
body, html, #allmap
{
width: 100%;
height: 100%;
overflow: hidden;
margin: 0;
}
#l-map
{
height: 100%;
width: 78%;
float: left;
border-right: 2px solid #bcbcbc;
}
#r-result
{
height: 100%;
width: 20%;
float: left;
}
</style>
<script type='text/javascript' src='http://api.map.baidu.com/api?v=3.0&ak=GjHGmPzAPs0hH6KIcpvmoAzt'></script>
</head>
<body>
<div id='allmap'>
</div>
<div style='float:right;position: absolute;
top: 1px;
left: 60px;background-color:;font-size: 12px;
line-height: 23px;'>
<div style='float:left'>请输入关键字搜索</div>
<div id='r-result' style='float:left'><input type='text' id='suggestId' size='20' value='' style='width:300px;' /></div>
<div id='searchResultPanel' style='border:1px solid #C0C0C0;width:300px;height:auto; display:none;'></div>
</div>
</body>
</html>
<script type='text/javascript'>
document.oncontextmenu=new Function('event.returnValue=false;'); document.onselectstart=new Function('event.returnValue=false;');
var marker;
var map = new BMap.Map('allmap'); // 创建Map实例
var point = new BMap.Point(114.05979, 22.545453); // 创建点坐标(经度,纬度)
map.centerAndZoom(point, 8); // 初始化地图,设置中心点坐标和地图大小级别
//map.addOverlay(new BMap.Marker(point)); // 给该坐标加一个红点标记
map.addControl(new BMap.NavigationControl()); // 添加平移缩放控件
map.addControl(new BMap.ScaleControl()); // 添加比例尺控件
map.addControl(new BMap.OverviewMapControl()); //添加缩略地图控件
map.addControl(new BMap.MapTypeControl()); //添加地图类型控件
map.enableScrollWheelZoom(); //启用滚轮放大缩小
var geoc = new BMap.Geocoder();
map.addEventListener('click', function (e) {
checkMaker();
point = new BMap.Point(e.point.lng, e.point.lat);
marker = new BMap.Marker(point);
map.addOverlay(marker);
var pt = e.point;
geoc.getLocation(pt, function (rs) {
var addComp = rs.addressComponents;
var address = [];
if (addComp.province.length > 0) {
address.push(addComp.province);
}
if (addComp.city.length > 0) {
address.push(addComp.city);
}
if (addComp.district.length > 0) {
address.push(addComp.district);
}
if (addComp.street.length > 0) {
address.push(addComp.street);
}
if (addComp.streetNumber.length > 0) {
address.push(addComp.streetNumber);
}
window.external.position(e.point.lat, e.point.lng, address.join(','));
});
});
function G(id) {
return document.getElementById(id);
}
var ac = new BMap.Autocomplete( //建立一个自动完成的对象
{
'input': 'suggestId'
, 'location': map
});
ac.addEventListener('onhighlight', function (e) { //鼠标放在下拉列表上的事件
var str = '';
var _value = e.fromitem.value;
var value = '';
if (e.fromitem.index > -1) {
value = _value.province + _value.city + _value.district + _value.street + _value.business;
}
str = 'FromItem<br />index = ' + e.fromitem.index + '<br />value = ' + value;
value = '';
if (e.toitem.index > -1) {
_value = e.toitem.value;
value = _value.province + _value.city + _value.district + _value.street + _value.business;
}
str += '<br />ToItem<br />index = ' + e.toitem.index + '<br />value = ' + value;
G('searchResultPanel').innerHTML = str;
});
var myValue;
ac.addEventListener('onconfirm', function (e) { //鼠标点击下拉列表后的事件
var _value = e.item.value;
myValue = _value.province + _value.city + _value.district + _value.street + _value.business;
G('searchResultPanel').innerHTML = 'onconfirm<br />index = ' + e.item.index + '<br />myValue = ' + myValue;
setPlace();
});
function setPlace() {
map.clearOverlays(); //清除地图上所有覆盖物
function myFun() {
var pp = local.getResults().getPoi(0).point; //获取第一个智能搜索的结果
checkMaker();
map.centerAndZoom(pp, 15);
marker=new BMap.Marker(pp);
map.addOverlay(marker); //添加标注
var pt = pp;
geoc.getLocation(pt, function (rs) {
var addComp = rs.addressComponents;
var address = [];
if (addComp.province.length > 0) {
address.push(addComp.province);
}
if (addComp.city.length > 0) {
address.push(addComp.city);
}
if (addComp.district.length > 0) {
address.push(addComp.district);
}
if (addComp.street.length > 0) {
address.push(addComp.street);
}
if (addComp.streetNumber.length > 0) {
address.push(addComp.streetNumber);
}
window.external.position(pp.lat, pp.lng, address.join(','));
});
}
var local = new BMap.LocalSearch(map, { //智能搜索
onSearchComplete: myFun
});
local.search(myValue);
}
function checkMaker() {
if (marker != null)
map.removeOverlay(marker);
};
function evaluatepoint(log,lat){
checkMaker();
point = new BMap.Point(log,lat);
map.centerAndZoom(point, 15);
marker = new BMap.Marker(point);
map.addOverlay(marker);
var pt = point;
geoc.getLocation(pt, function (rs) {
var addComp = rs.addressComponents;
var address = [];
if (addComp.province.length > 0) {
address.push(addComp.province);
}
if (addComp.city.length > 0) {
address.push(addComp.city);
}
if (addComp.district.length > 0) {
address.push(addComp.district);
}
if (addComp.street.length > 0) {
address.push(addComp.street);
}
if (addComp.streetNumber.length > 0) {
address.push(addComp.streetNumber);
}
window.external.position(pt.lat,pt.lng, address.join(','));
});
};</script>";
this.webBrowser1.DocumentText = text;
this.webBrowser1.ObjectForScripting = this;
}
public void position(string a_0, string a_1, string b_0)
{
this.label3.Text = (double.Parse( a_1) - 0.01169).ToString();
this.label4.Text = (double.Parse(a_0) - 0.00293).ToString();
this.label5.Text = b_0;
}
private void button1_Click(object sender, EventArgs e)
{
Location.Longitude = double.Parse(label3.Text);
Location.Latitude = double.Parse(label4.Text);
Close();
}
public void Alert(string msg)
{
MessageBox.Show(msg);
}
}
}