百度地图API(一)

时间:2021-10-29 22:43:51

开题

  百度地图API已经做了好久了,自己一个人做完的这个项目,一直想记录的,拖延症爆发,一直到现在,而且前面MVC还没写完,主要是卡在授权,底层和页面功能都明白了,但是就是授权,整个项目的开始没搞懂,也够郁闷的,也就把MVC放放,一边看,一边写吧,先把API写完~

百度地图控件

  项目是用的WPF,地图控件用的到WPF的UserControl,结构如下

百度地图API(一)

  其中BaiduMap_WPF是项目,BaiduMapControl是百度地图控件,EntityAgent是定义的实体,SimpleMvvmToolkit-WPF是小型Mvvm,为什么没有EF?是因为数据获取是通过WebService的方法获取的坐标信息,因此省略了一些东西,不过这本来就是主要写百度地图API,有没有都无所谓。

  地图控件的文件比较多,大体分为:

百度地图API(一)

  其中,MapBase文件夹定义的是各种控件基础类,MapLayer文件夹定义的是各种覆盖物基础类,MapService文件夹定义的是各种地图服务的基础类,最后的MapTools文件夹定义的是地图上各种控件基础类,BaiduMap.xaml是百度地图WPF的用户控件UserControl。

MapBase

  类Point,点

百度地图API(一)百度地图API(一)
 1     /// <summary>
 2     /// 3     /// </summary>
 4     public class Point
 5     {
 6         /// <summary>
 7         /// 构造函数
 8         /// </summary>
 9         /// <param name="m_lng">经度</param>
10         /// <param name="m_lat">纬度</param>
11         public Point(string m_lng, string m_lat)
12         {
13             lng = m_lng;
14             lat = m_lat;
15         }
16 
17         #region 字段
18 
19         string lng;
20         string lat;
21 
22         #endregion
23 
24 
25         #region 属性
26 
27         /// <summary>
28         /// 经度
29         /// </summary>
30         public string Lng
31         {
32             get { return lng; }
33             set { lng = value; }
34         }
35 
36         /// <summary>
37         /// 纬度
38         /// </summary>
39         public string Lat
40         {
41             get { return lat; }
42             set { lat = value; }
43         }
44 
45         #endregion
46     }
View Code

  枚举MapControlType,控件的类型

百度地图API(一)百度地图API(一)
 1     /// <summary>
 2     /// 控件的类型
 3     /// </summary>
 4     public enum MapControlType
 5     {
 6         NavigationControl,//平移缩放控件
 7         OverviewMapControl,//缩略图控件
 8         ScaleControl,//比例尺控件
 9         MapTypeControl,//地图类型控件
10         CopyrightControl //版权控件
11     }
View Code

  类MapControl,地图控件,需要注意的是在每个私有方法中,w.InvokeScript("");引号中的方法,是html的js方法,放在api.js文件中。

百度地图API(一)百度地图API(一)
  1     /// <summary>
  2     /// 地图控件类
  3     /// </summary>
  4     public class MapControl
  5     {
  6         #region properties
  7 
  8         /// <summary>
  9         /// 地图中心的经度
 10         /// </summary>
 11         private string map_lng;
 12 
 13         /// <summary>
 14         /// 地图中心的纬度
 15         /// </summary>
 16         private string map_lat;
 17 
 18         /// <summary>
 19         /// 地图的层数
 20         /// </summary>
 21         private int map_size;
 22 
 23         #endregion
 24 
 25         private MapControlType m_type;
 26 
 27         /// <summary>
 28         /// 构造函数 -- 清除所有
 29         /// </summary>
 30         public MapControl()
 31         { 
 32         }
 33 
 34         /// <summary>
 35         /// 构造函数
 36         /// </summary>
 37         /// <param name="type"></param>
 38         public MapControl(MapControlType type)
 39         {
 40             m_type = type;
 41         }
 42 
 43         /// <summary>
 44         /// 构造函数 - - 地图中心移动
 45         /// </summary>
 46         /// <param name="_lat"></param>
 47         /// <param name="_lng"></param>
 48         /// <param name="_mapSize"></param>
 49         public MapControl(string _lng,string _lat,int _mapSize)
 50         {
 51             map_lat = _lat;
 52             map_lng = _lng;
 53             map_size = _mapSize;
 54         }
 55 
 56         #region 公共方法
 57 
 58         /// <summary>
 59         /// 将地图中心移动到指定位置
 60         /// </summary>
 61         /// <param name="w"></param>
 62         public void MoveMapTo(WebBrowser w)
 63         {
 64             w.InvokeScript("MoveMapTo", new Object[] { map_lng, map_lat, map_size });
 65         }
 66 
 67         /// <summary>
 68         /// 清除所有覆盖物
 69         /// </summary>
 70         /// <param name="w"></param>
 71         public void ClearAllOverlay(WebBrowser w)
 72         {
 73             w.InvokeScript("ClearAllOverlay");
 74         }
 75 
 76 
 77         public void AddMapControl(WebBrowser w)
 78         {
 79 
 80         }
 81 
 82         /// <summary>
 83         /// 向地图添加地图控件的方法
 84         /// </summary>
 85         public void AddControl(WebBrowser w)
 86         {
 87             switch (m_type)
 88             {
 89                 case MapControlType.NavigationControl:
 90                     AddNavigationControl(w);//添加平移缩放控件
 91                     break;
 92                 case MapControlType.MapTypeControl:
 93                     AddMapTypeControl(w);//添加地图类型控件
 94                     break;
 95                 case MapControlType.ScaleControl:
 96                     AddScaleControl(w);//添加比例尺控件
 97                     break;
 98                 case MapControlType.OverviewMapControl:
 99                     AddOverviewMapControl(w);//添加缩略图控件
100                     break;
101                 case MapControlType.CopyrightControl:
102                     AddCopyrightControl(w);//添加版权控件
103                     break;
104             }
105         }
106 
107         #endregion
108 
109         #region 私有方法 加载各种控件
110 
111         /// <summary>
112         /// 加载版权控件
113         /// </summary>
114         /// <param name="w"></param>
115         private void AddCopyrightControl(WebBrowser w)
116         {
117             w.InvokeScript("AddCopyrightControl");
118         }
119 
120         private void AddOverviewMapControl(WebBrowser w)
121         {
122             w.InvokeScript("AddOverviewMapControl");
123         }
124 
125         private void AddScaleControl(WebBrowser w)
126         {
127             w.InvokeScript("AddScaleControl");
128         }
129 
130         private void AddMapTypeControl(WebBrowser w)
131         {
132             w.InvokeScript("AddMapTypeControl");
133         }
134 
135         private void AddNavigationControl(WebBrowser w)
136         {
137             w.InvokeScript("AddNavigationControl");
138         }
139 
140         
141         #endregion
142     }
View Code

MapLayer覆盖物

  类Cirle,圆,地图上添加一个圆形覆盖物

百度地图API(一)百度地图API(一)
 1     /// <summary>
 2     /// 圆类,用于向地图添加一个圆
 3     /// </summary>
 4     public class Cirle
 5     {
 6         #region 字段
 7 
 8         /// <summary>
 9         /// 坐标
10         /// </summary>
11         private MapBase.Point m_point;
12 
13         /// <summary>
14         /// 半径
15         /// </summary>
16         private int m_r;
17 
18         #endregion
19 
20         #region 属性
21 
22         /// <summary>
23         /// 坐标
24         /// </summary>
25         private MapBase.Point Point
26         {
27             get
28             {
29                 return m_point;
30             }
31             set
32             {
33                 m_point = value;
34             }
35         }
36 
37         /// <summary>
38         /// 半径
39         /// </summary>
40         private int Radius
41         {
42             get
43             {
44                 return m_r;
45             }
46             set
47             {
48                 m_r = value;
49             }
50         }
51 
52         #endregion
53 
54         #region 构造函数
55 
56         public Cirle(MapBase.Point _point, int _radius)
57         {
58             m_point = _point;
59             m_r = _radius;
60         }
61 
62         #endregion
63 
64         #region 公共函数
65 
66         /// <summary>
67         /// 添加圆
68         /// </summary>
69         /// <param name="w"></param>
70         public void AddCirle(WebBrowser w)
71         {
72             w.InvokeScript("AddCirle", new Object[] { this.Point.Lng, this.Point.Lat, this.Radius });
73         }
74 
75         #endregion
76     }
View Code

  类InfoWindow,消息窗口

百度地图API(一)百度地图API(一)
 1     /// <summary>
 2     /// 信息窗口类,用于在地图上构建信息窗口
 3     /// </summary>
 4     public class InfoWindow
 5     {
 6 
 7         #region 字段
 8         private string m_content;
 9         private Point m_point;
10         private Maker m_maker;
11         #endregion
12 
13         #region 属性
14         public Point Point
15         {
16             get { return m_point; }
17             set { m_point = value; }
18         }
19         public string Content
20         {
21             get { return m_content; }
22             set { m_content = value; }
23         }
24         #endregion
25 
26         #region 构造函数
27         //根据坐标创建信息窗口
28         public InfoWindow(string content, Point point)
29         {
30             m_content = content;
31             m_point = point;
32         }
33         //根据Maker创建信息窗口
34         public InfoWindow(string content, Maker maker)
35         {
36             m_content = content;
37             m_maker = maker;
38         }
39         #endregion
40 
41         public void AddInfoWindow(WebBrowser w)
42         {
43             if (this.Point == null)
44             {
45                 w.InvokeScript("AddWindowMaker", new Object[] { this.m_maker.Point.Lng, this.m_point.Lat, this.Content });
46             }
47             else
48             {
49                 w.InvokeScript("AddInfoWindow", new Object[] { this.Point.Lng, this.Point.Lat, this.Content });
50             }
51         }
52     }
View Code

  类Label,标签

百度地图API(一)百度地图API(一)
 1     /// <summary>
 2     /// 地图标签类,用于为地图添加标签
 3     /// </summary>
 4     public class Label
 5     {
 6         #region 字段
 7         private string m_content;
 8         private Maker m_maker;
 9         private MapBase.Point m_point;
10         #endregion
11 
12         #region 属性
13         public string Content
14         {
15             get { return m_content; }
16             set { m_content = value; }
17         }
18         public MapBase.Point Point
19         {
20             get { return m_point; }
21             set { m_point = value; }
22         }
23         public Maker Maker
24         {
25             get { return m_maker; }
26             set { m_maker = value; }
27         }
28         #endregion
29 
30         #region 构造函数
31 
32         public Label(string _lng, string _lat, string _content)
33         {
34             m_point = new MapBase.Point(_lng, _lat);
35             m_content = _content;
36         }
37 
38         public Label(MapBase.Point point, string content)
39         {
40             m_point = point;
41             m_content = content;
42         }
43 
44         public Label(Maker maker, string content)
45         {
46             m_maker = maker;
47             m_content = content;
48         }
49         #endregion
50 
51         #region 公共方法
52 
53         public void AddLabel(WebBrowser w)
54         {
55             w.InvokeScript("AddLabel", new Object[] { this.Point.Lng, this.Point.Lat, this.Content });
56         }
57 
58         #endregion
59     }
View Code

  类Marker,覆盖物

百度地图API(一)百度地图API(一)
  1     /// <summary>
  2     /// 地图覆盖物Maker类
  3     /// </summary>
  4     public class Maker
  5     {
  6         #region 字段
  7 
  8         private Point m_point;//坐标
  9         private MakerType m_type;//标注点类型
 10         private InfoWindow m_info;//信息窗口
 11         private Label m_label;//标签
 12         private WebBrowser m_w;
 13 
 14         #endregion
 15 
 16         #region 构造函数
 17         //普通和动画类型标注点的构造函数
 18         public Maker(Point point, MakerType type)
 19         {
 20             m_point = point;
 21             m_type = type;
 22         }
 23         //信息窗口类型的标注点的构造函数
 24         public Maker(Point point, MakerType type, InfoWindow info)
 25         {
 26             m_point = point;
 27             m_type = type;
 28             m_info = info;
 29         }
 30         //标签类型的标注点的构造函数
 31         public Maker(Point point, MakerType type, Label label)
 32         {
 33             m_point = point;
 34             m_type = type;
 35             m_label = label;
 36         }
 37         #endregion
 38 
 39         #region 公共方法
 40 
 41         public void EnableDrag()
 42         {
 43             this.m_w.InvokeScript("OpenMakerDraging");
 44         }
 45 
 46         public void DisableDrag()
 47         {
 48             this.m_w.InvokeScript("CloseMakerDraging");
 49         }
 50         /// <summary>
 51         /// 向地图添加一个标注点
 52         /// </summary>
 53         /// <param name="point">地理坐标</param>
 54         public void AddMaker(WebBrowser w)
 55         {
 56             this.m_w = w;
 57             switch (m_type)
 58             {
 59                 case MakerType.Normal:
 60                     AddNormalMaker(w, m_point);//添加普通标注点
 61                     break;
 62                 case MakerType.Animation:
 63                     AddAnimationMaker(w, m_point);//添加动画标注点
 64                     break;
 65                 case MakerType.WithInfoWinfow:
 66                     AddWindowMaker(w, m_point);//添加含信息窗口标注点
 67                     break;
 68                 case MakerType.WithLabel:
 69                     AddLabelMaker(w, m_point);//添加含信息窗口标注点
 70                     break;
 71             }
 72         }
 73 
 74         #endregion
 75 
 76         #region 私有方法
 77         /// <summary>
 78         /// 用于处理不同类型标注点的方法
 79         /// </summary>
 80         /// <param name="w">webBrowser</param>
 81         /// <param name="point">坐标</param>
 82         private void AddLabelMaker(WebBrowser w, MapBase.Point point)
 83         {
 84             string labelContent = m_label.Content;
 85             w.InvokeScript("AddLabelMaker", new Object[] { point.Lng, point.Lat, labelContent });
 86         }
 87 
 88         private void AddWindowMaker(WebBrowser w, MapBase.Point point)
 89         {
 90             string labelContent = m_label.Content;
 91             w.InvokeScript("AddWindowMaker", new Object[] { point.Lng, point.Lat, labelContent });
 92         }
 93 
 94         private void AddAnimationMaker(WebBrowser w, MapBase.Point point)
 95         {
 96             w.InvokeScript("AddAnimationMaker", new Object[] { point.Lng, point.Lat });
 97         }
 98 
 99         private void AddNormalMaker(WebBrowser w, MapBase.Point point)
100         {
101             w.InvokeScript("AddNormalMaker", new Object[] { point.Lng, point.Lat });
102         }
103         #endregion
104 
105         #region 属性
106         public Point Point
107         {
108             get { return m_point; }
109             set { m_point = value; }
110         }
111         #endregion
112     }
View Code

  枚举MarkerType,覆盖物类型

百度地图API(一)百度地图API(一)
1     public enum MakerType
2     {
3         Normal,//普通标注点
4         Animation,//动画标注点
5         WithInfoWinfow,//含有信息窗口的标注点
6         WithLabel//含有标签的标注点
7     }
View Code

  类UserMarker,人覆盖物(自定义覆盖物)

百度地图API(一)百度地图API(一)
  1     /// <summary>
  2     /// 地图覆盖物UserMarker类
  3     /// </summary>
  4     public class UserMarker
  5     {
  6         #region
  7 
  8         /// <summary>
  9         /// 坐标
 10         /// </summary>
 11         private MapBase.Point _point;
 12 
 13         /// <summary>
 14         /// 标注点类型
 15         /// </summary>
 16         //private MakerType _type;
 17 
 18         /// <summary>
 19         /// 信息窗口内容
 20         /// </summary>
 21         private string UserInfo;
 22 
 23         /// <summary>
 24         /// 姓名
 25         /// </summary>
 26         private string UserName;
 27 
 28         /// <summary>
 29         /// 
 30         /// </summary>
 31         private WebBrowser _w;
 32 
 33         #endregion
 34 
 35         /// <summary>
 36         /// 构造函数- 选择人员
 37         /// </summary>
 38         /// <param name="_userName"></param>
 39         public UserMarker(string _userName)
 40         {
 41             UserName = _userName;
 42         }
 43 
 44         /// <summary>
 45         /// 构造函数- 人员
 46         /// </summary>
 47         /// <param name="point"></param>
 48         /// <param name="_userName"></param>
 49         public UserMarker(Point point,string _userName,string _info)
 50         {
 51             _point = point;
 52             UserName = _userName;
 53             UserInfo = _info;
 54         }
 55 
 56         #region Methods
 57 
 58         public void EnableDrag()
 59         {
 60             this._w.InvokeScript("OpenMakerDraging");
 61         }
 62 
 63         public void DisableDrag()
 64         {
 65             this._w.InvokeScript("CloseMakerDraging");
 66         }
 67 
 68         /// <summary>
 69         /// 添加人
 70         /// </summary>
 71         /// <param name="w"></param>
 72         public void AddUserMarker(WebBrowser w)
 73         {
 74             this._w = w;
 75             w.InvokeScript("AddUserMarker", new Object[] { _point.Lng, _point.Lat, UserName, UserInfo });
 76         }
 77 
 78         /// <summary>
 79         /// 选择外访员
 80         /// </summary>
 81         /// <param name="w"></param>
 82         public void SelectedUserMarker(WebBrowser w)
 83         {
 84             this._w = w;
 85             w.InvokeScript("SelectedUserMarker", new Object[] { UserName });
 86         }
 87 
 88         public event PropertyChangedEventHandler PropertyChanged;
 89 
 90         protected void OnPropertyChanged(PropertyChangedEventArgs name)
 91         {
 92             if (PropertyChanged != null)
 93             {
 94                 PropertyChanged(this, name);
 95             }
 96         }
 97 
 98         #endregion
 99 
100         #region 属性
101 
102         /// <summary>
103         /// 坐标
104         /// </summary>
105         public BaiduMapControl.MapBase.Point Point
106         {
107             get { return _point; }
108             set { _point = value; }
109         }
110 
111         private System.Windows.UIElement shape;
112         public System.Windows.UIElement Shape
113         {
114             get
115             {
116                 return shape;
117             }
118             set
119             {
120                 if (shape != value)
121                 {
122                     shape = value;
123                     OnPropertyChanged(Shape_PropertyChangedEventArgs);
124                 }
125             }
126         }
127 
128         static readonly PropertyChangedEventArgs Shape_PropertyChangedEventArgs = new PropertyChangedEventArgs("Shape");
129 
130         #endregion
131     }
View Code

MapService地图服务

  类DrivingRoute,行驶路线

百度地图API(一)百度地图API(一)
 1     /// <summary>
 2     /// 行驶路线
 3     /// </summary>
 4     public class DrivingRoute
 5     {
 6         #region 字段
 7         private string m_start;
 8         private string m_end;
 9         #endregion
10 
11         #region 构造函数
12 
13         /// <summary>
14         /// 定义行驶路线
15         /// </summary>
16         /// <param name="start"></param>
17         /// <param name="end"></param>
18         public DrivingRoute(string start, string end)
19         {
20             this.m_start = start;
21             this.m_end = end;
22         }
23 
24         #endregion
25 
26         #region 公共函数
27 
28         /// <summary>
29         /// 得到行驶路线
30         /// </summary>
31         /// <param name="w"></param>
32         public void GetDrivingRoute(WebBrowser w)
33         {
34             w.InvokeScript("GetDrivingRoute", new Object[] { m_start, m_end });
35         }
36         #endregion
37     }
View Code

  类Geocoder,地理编码

百度地图API(一)百度地图API(一)
  1     /// <summary>
  2     /// 地理编码
  3     /// </summary>
  4     public class Geocoder
  5     {
  6         #region 字段
  7 
  8         /// <summary>
  9         /// 坐标
 10         /// </summary>
 11         private MapBase.Point m_point;
 12 
 13         /// <summary>
 14         /// 地理位置
 15         /// </summary>
 16         private string m_address;
 17 
 18         /// <summary>
 19         /// 地址位置数组
 20         /// </summary>
 21         private string[] AddressArray;
 22 
 23         /// <summary>
 24         /// 地址位置列表
 25         /// </summary>
 26         private List<string> AddressList = new List<string>();
 27 
 28         /// <summary>
 29         /// 城市名称
 30         /// </summary>
 31         private string CityOrProvinceName;
 32 
 33         #endregion
 34 
 35         #region 构造函数
 36 
 37         /// <summary>
 38         /// 构造函数 - 地理位置
 39         /// </summary>
 40         /// <param name="point"></param>
 41         /// <param name="addressList"></param>
 42         public Geocoder(string lng,string lat,List<string> addressList,string _cityOrProvinceName)
 43         {
 44             CityOrProvinceName = _cityOrProvinceName;
 45             this.m_point = new MapBase.Point(lng,lat);
 46             AddressArray = new string[addressList.Count];
 47             AddressList.Clear();
 48             for (int i = 0; i < addressList.Count; i++)
 49             {
 50                 AddressArray[i] = addressList[i];
 51                 AddressList.Add(addressList[i]);
 52             }
 53         }
 54 
 55         /// <summary>
 56         /// 构造函数 - 坐标解析地理位置
 57         /// </summary>
 58         /// <param name="point"></param>
 59         public Geocoder(MapBase.Point point)
 60         {
 61             this.m_point = point;
 62         }
 63 
 64         /// <summary>
 65         /// 构造函数 - 地理位置解析坐标
 66         /// </summary>
 67         /// <param name="address"></param>
 68         public Geocoder(string address)
 69         {
 70             this.m_address = address;
 71         }
 72 
 73         #endregion
 74 
 75         #region 公共方法
 76 
 77         /// <summary>
 78         /// 连接到人
 79         /// </summary>
 80         /// <param name="w"></param>
 81         public void GetAddresses(WebBrowser w)
 82         {
 83             w.InvokeScript("GetAddresses", new Object[] { m_point.Lng, m_point.Lat, AddressArray});
 84         }
 85 
 86         /// <summary>
 87         /// 
 88         /// </summary>
 89         /// <param name="w"></param>
 90         public void GetAddressList(WebBrowser w)
 91         {
 92             try
 93             {
 94                 foreach (var addr in AddressList)
 95                 {
 96                     w.InvokeScript("GetSingleAddress", new Object[] { m_point.Lng, m_point.Lat, addr, CityOrProvinceName });
 97                 }
 98             }
 99             catch (Exception)
100             {
101             }
102         }
103         //public string DecodePoint(WebBrowser w)
104         //{
105         //    w.InvokeScript("GetByPoint", new Object[] { m_point.Lng, m_point.Lat });
106         //    return w.GetElementById("geo").InnerText;
107         //}
108 
109         //public MapBase.Point DecodeAddress(WebBrowser w)
110         //{
111         //    w.InvokeScript("GetByAddress", new Object[] { m_address });
112         //    return new MapBase.Point(w.Document.GetElementById("lng").InnerText, w.Document.GetElementById("lat").InnerText);
113         //}
114 
115         #endregion
116     }
View Code

  类LocalSearch,地图搜索

百度地图API(一)百度地图API(一)
 1     /// <summary>
 2     /// 地图搜索类,用于提供地图搜索支持
 3     /// </summary>
 4     public class LocalSearch
 5     {
 6         public void LocalSeach(string keywords, WebBrowser w)
 7         {
 8             w.InvokeScript("LocalSearch", new Object[] { keywords });
 9         }
10 
11         public void SearchNearby(string keywords, string center, WebBrowser w)
12         {
13             w.InvokeScript("SearchNearby", new Object[] { keywords, center });
14         }
15 
16         public void SearchInBounds(string keywords, WebBrowser w)
17         {
18             w.InvokeScript("SearchInBounds", new Object[] { keywords });
19         }
20     }
View Code

  类TransitRoute,中继路线

百度地图API(一)百度地图API(一)
 1     public class TransitRoute
 2     {
 3         #region 字段
 4         private string m_start;
 5         private string m_end;
 6         #endregion
 7 
 8         #region 构造函数
 9         public TransitRoute(string start, string end)
10         {
11             this.m_start = start;
12             this.m_end = end;
13         }
14 
15         #endregion
16 
17         #region 公共函数
18         public void GetTransitRoute(WebBrowser w)
19         {
20             w.InvokeScript("TransitRoute", new Object[] { m_start, m_end });
21         }
22         #endregion
23     }
View Code

  类UserRoute,外出路线

百度地图API(一)百度地图API(一)
 1     /// <summary>
 2     /// 外出路线
 3     /// </summary>
 4     public class UserRoute
 5     {
 6         #region 字段
 7 
 8         /// <summary>
 9         /// 坐标字符串
10         /// </summary>
11         public string allArray;
12 
13         #endregion
14 
15         /// <summary>
16         /// 构造函数 - 外出路径
17         /// </summary>
18         /// <param name="_pointList">坐标列表</param>
19         public UserRoute(List<Point> _pointList)
20         {
21             int i = 0;
22             foreach (var _point in _pointList)
23             {
24                 allArray = allArray + _point.Lng + ",";
25                 if (i != (_pointList.Count) - 1)
26                 {
27                     allArray = allArray + _point.Lat + ",";
28                 }
29                 else
30                 {
31                     allArray = allArray + _point.Lat;
32                 }
33                 i++;
34             }
35         }
36 
37         /// <summary>
38         /// 构造函数 - 清空路径
39         /// </summary>
40         public UserRoute()
41         {
42  
43         }
44 
45         /// <summary>
46         /// 添加路线
47         /// </summary>
48         /// <param name="w"></param>
49         public void AddUserRoute(WebBrowser w)
50         {
51             try
52             {
53                 w.InvokeScript("AddUserRoute", new Object[] { allArray });
54             }
55             catch (Exception)
56             {
57             }
58         }
59 
60         /// <summary>
61         /// 清空所有路线
62         /// </summary>
63         /// <param name="w"></param>
64         public void ClearAllUserRoute(WebBrowser w)
65         {
66             w.InvokeScript("ClearAllUserRoute");
67         }
68     }
View Code

  类WalkingRoute,步行路线

百度地图API(一)百度地图API(一)
 1     /// <summary>
 2     /// 步行路线
 3     /// </summary>
 4     public class WalkingRoute
 5     {
 6         #region 字段
 7         private string m_start;
 8         private string m_end;
 9         #endregion
10 
11         #region 构造函数
12         public WalkingRoute(string start, string end)
13         {
14             this.m_start = start;
15             this.m_end = end;
16         }
17 
18         #endregion
19 
20         #region 公共函数
21         public void GetWalkingRoute(WebBrowser w)
22         {
23             w.InvokeScript("Walking", new Object[] { m_start, m_end });
24         }
25         #endregion
26     }
View Code

MapTools地图工具

  枚举MapToolsState,工具状态

百度地图API(一)百度地图API(一)
1     /// <summary>
2     /// 工具状态
3     /// </summary>
4     public enum MapToolsState
5     {
6         Open,//开启
7         Close//关闭
8     }
View Code

  类DisanceTool,距离工具

百度地图API(一)百度地图API(一)
 1     /// <summary>
 2     /// 距离工具
 3     /// </summary>
 4     public class DistanceTool
 5     {
 6         //构造函数
 7         private WebBrowser w;
 8 
 9         public DistanceTool(MapToolsState state)
10         {
11             this.state = state;//为属性赋值
12         }
13         public void AddDistanceTool(WebBrowser w)
14         {
15 
16             this.w = w;
17             switch (state)
18             {
19                 case MapToolsState.Open:
20                     this.Open();
21                     break;
22                 case MapToolsState.Close:
23                     this.Close();
24                     break;
25             }
26         }
27 
28         public void Open()
29         {
30             if (this.state == MapToolsState.Close)
31             {
32                 w.InvokeScript("DistanceToolOpen");
33             }
34         }
35 
36         public void Close()
37         {
38             if (this.state == MapToolsState.Open)
39             {
40                 w.InvokeScript("DistanceToolClose");
41             }
42         }
43         //属性
44         MapToolsState state { get; set; }
45     }
View Code

  类DragAndZoomTool,拖拽工具

百度地图API(一)百度地图API(一)
 1     /// <summary>
 2     /// 拖拽改变地图大小工具
 3     /// </summary>
 4     public class DragAndZoomTool
 5     {
 6         //构造函数
 7         private WebBrowser w;
 8         public DragAndZoomTool(MapToolsState state)
 9         {
10             this.state = state;//为属性赋值
11         }
12 
13         //公共方法
14         public void AddDragAndZoomTool(WebBrowser w)
15         {
16             this.w = w;
17             switch (this.state)
18             {
19                 case MapToolsState.Open:
20                     this.Open();
21                     break;
22                 case MapToolsState.Close:
23                     this.Close();
24                     break;
25             }
26         }
27 
28         public void Open()
29         {
30             w.InvokeScript("DragAndZoomOpen");
31         }
32 
33         public void Close()
34         {
35             w.InvokeScript("DragAndZoomClose");
36         }
37         //属性
38         MapToolsState state { get; set; }
39     }
View Code

  类DrawingManager,绘图工具

百度地图API(一)百度地图API(一)
 1     /// <summary>
 2     /// 绘图工具
 3     /// </summary>
 4     public class DrawingManager
 5     {
 6 
 7         public WebBrowser w;
 8 
 9         #region 构造函数
10         public DrawingManager(MapToolsState state)
11         {
12             this.state = state;
13         }
14         //方法
15         public void AddDrawingManager(WebBrowser w)
16         {
17             this.w = w;
18             switch (this.state)
19             {
20                 case MapToolsState.Open:
21                     this.Open();
22                     break;
23                 case MapToolsState.Close:
24                     this.Close();
25                     break;
26             }
27         }
28         #endregion
29 
30         #region 公共方法
31         public void Open()
32         {
33             w.InvokeScript("DrawingManagerOpen");
34         }
35 
36         public void Close()
37         {
38             w.InvokeScript("DrawingManagerClose");
39         }
40         #endregion
41 
42         #region 属性
43         MapToolsState state { get; set; }
44         #endregion
45 
46     }
View Code

Waiting

  这篇先到这,下篇在具体写功能的实现,因为下一篇内容也比较多,所以就分开写~