C# Gmap.net控件的使用
来源:互联网 发布:python程序化交易 编辑:程序博客网 时间:2024/06/09 20:01
1,首先要先添加引用Gmap.net的动态链接库.dll文件
2,初始化地图信息
public void MapShow() { try { System.Net.IPHostEntry ela = System.Net.Dns.GetHostEntry("www.google.com.hk"); } catch { gMap_control.Manager.Mode = AccessMode.ServerAndCache; MessageBox.Show("No internet connection avaible, going to CacheOnly mode.", "GMap.NET Demo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } gMap_control.CacheLocation = Environment.CurrentDirectory + "\\GMapCache\\"; //缓存位置 MyInvoke my = new MyInvoke(Init); this.BeginInvoke(my); }
public delegate void MyInvoke(); public void Init() { gMap_control.MinZoom = 4; //最小比例 gMap_control.MaxZoom = 22; //最大比例 gMap_control.Zoom = 4; gMap_control.DragButton = System.Windows.Forms.MouseButtons.Left; //左键拖拽地图 gMap_control.Position = new PointLatLng(32.064, 118.704); //地图中心位置:南京 }
gMap_control.MapProvider = GMapProviders.GoogleChinaMap; //google china 地图 new Thread(MapShow).Start();
3,添加一个market
GMapOverlay MyMarkss = new GMapOverlay(this.gMap_control, "MyMarkss"); GMapMarkerGoogleGreen gn = new GMapMarkerGoogleGreen(gMap_control.Position); MyMarkss.Markers.Add(gn); this.gMap_control.Overlays.Add(MyMarkss); gn.ToolTipMode = MarkerTooltipMode.Always; gn.ToolTipText = "提示信息"
4,添加一个自定义的market
class GMapMarkerDirection : GMapMarker { public float Ang; private Image image; public Image Image { get { return image; } set { image = value; if (image != null) { this.Size = new Size(image.Width, image.Height); } } } public GMapMarkerDirection(PointLatLng p, Image image, float angle) : base(p) { Ang = angle - 90; if (Ang > 360) { Ang -= 360; } if (Ang < 0) { Ang += 360; } Image = image; Size = new System.Drawing.Size(image.Width, image.Height); Offset = new System.Drawing.Point(-Size.Width / 2, -Size.Height / 2); } public override void OnRender(Graphics g) { g.DrawImageUnscaled(RotateImage(Image, Ang), LocalPosition.X, LocalPosition.Y); } private Bitmap RotateImage(Image image, float angle) { if (image == null) throw new ArgumentNullException("image"); const double pi2 = Math.PI / 2.0; double oldWidth = (double)image.Width; double oldHeight = (double)image.Height; double theta = ((double)angle) * Math.PI / 180.0; double locked_theta = theta; while (locked_theta < 0.0) locked_theta += 2 * Math.PI; double newWidth, newHeight; int nWidth, nHeight; #region Explaination of the calculations #endregion double adjacentTop, oppositeTop; double adjacentBottom, oppositeBottom; if ((locked_theta >= 0.0 && locked_theta < pi2) || (locked_theta >= Math.PI && locked_theta < (Math.PI + pi2))) { adjacentTop = Math.Abs(Math.Cos(locked_theta)) * oldWidth; oppositeTop = Math.Abs(Math.Sin(locked_theta)) * oldWidth; adjacentBottom = Math.Abs(Math.Cos(locked_theta)) * oldHeight; oppositeBottom = Math.Abs(Math.Sin(locked_theta)) * oldHeight; } else { adjacentTop = Math.Abs(Math.Sin(locked_theta)) * oldHeight; oppositeTop = Math.Abs(Math.Cos(locked_theta)) * oldHeight; adjacentBottom = Math.Abs(Math.Sin(locked_theta)) * oldWidth; oppositeBottom = Math.Abs(Math.Cos(locked_theta)) * oldWidth; } newWidth = adjacentTop + oppositeBottom; newHeight = adjacentBottom + oppositeTop; nWidth = (int)Math.Ceiling(newWidth); nHeight = (int)Math.Ceiling(newHeight); Bitmap rotatedBmp = new Bitmap(nWidth, nHeight); using (Graphics g = Graphics.FromImage(rotatedBmp)) { Point[] points; if (locked_theta >= 0.0 && locked_theta < pi2) { points = new Point[] { new Point( (int) oppositeBottom, 0 ), new Point( nWidth, (int) oppositeTop ), new Point( 0, (int) adjacentBottom ) }; } else if (locked_theta >= pi2 && locked_theta < Math.PI) { points = new Point[] { new Point( nWidth, (int) oppositeTop ), new Point( (int) adjacentTop, nHeight ), new Point( (int) oppositeBottom, 0 ) }; } else if (locked_theta >= Math.PI && locked_theta < (Math.PI + pi2)) { points = new Point[] { new Point( (int) adjacentTop, nHeight ), new Point( 0, (int) adjacentBottom ), new Point( nWidth, (int) oppositeTop ) }; } else { points = new Point[] { new Point( 0, (int) adjacentBottom ), new Point( (int) oppositeBottom, 0 ), new Point( (int) adjacentTop, nHeight ) }; } g.DrawImage(image, points); } return rotatedBmp; } }
Image image = Image.FromFile(Application.StartupPath + "\\markert.png");//location是坐标,image是market图片,max是旋转角度GMapMarkerDirection MyMarkss = new GMapMarkerDirection(location, image, max); GMapMarkerGoogleGreen gn = new GMapMarkerGoogleGreen(gMap_control.Position); MyMarkss.Markers.Add(gn); this.gMap_control.Overlays.Add(MyMarkss); gn.ToolTipMode = MarkerTooltipMode.Always; gn.ToolTipText = "提示信息"
5,在两点之间画线
PointLatLng star = new PointLatLng();PointLatLng end= new PointLatLng();List<PointLatLng> list = new List<PointLatLng>();list.Add(star);list.Add(end);GMapOverlay routes = new GMapOverlay(this.gMap_control, "routes");this.gMap_control.Overlays.Add(routes);//添加到图层列表中 GMapRoute route = new GMapRoute(list, "action");routes.Routes.Add(route);
6,计算A点在B点的方向
double angleOfLine = Math.Atan2((end.Lng - star.Lng), (end.Lat - star.Lat)) * 180 / Math.PI; int max = (int)angleOfLine; if (max > 360) { max -= 360; } if (max < 0) { max += 360; }
0 0
- C# Gmap.net控件的使用
- Winform下的地图开发控件(GMap.NET)使用心得
- Winform 下的地图开发控件(GMap.NET)使用心得
- 在开发中使用GMap.Net 控件的心得一
- 在开发中使用GMap.Net 控件的心得一
- GMap.NET地图开发控件使用心得
- 基于地图开发控件GMap.Net 使用
- GMap.Net使用(2)之控件添加
- 强大的在线地图控件GMap.NET
- 添加GMap.NET 控件的dll步骤
- 基于GMap.Net的天地图使用
- Winform下的地图开发控件(GMap.NET)使用心得转载学习
- C#|GMap.NET控件基本使用-高德地图
- C#在Winform中使用GMap.Net地图开发控件在离线模式下绘制两点路线
- GMap.net控件学习记录
- 在开发中使用GMap.Net的心得二
- 在开发中使用GMap.Net的心得三
- GMap.net控件无法加载到工具栏
- 饼图和圆环图控件Pie & Donut chart控件介绍及下载
- Spring 3整合Quartz 2实现定时任务二:动态添加任务
- Android消息推送机制
- 软件架构的定义及其理解
- 【菁菁报表】常规报表的制作过程
- C# Gmap.net控件的使用
- linux和windows双系统启动顺序
- 数据库设计三大范式
- Spring 3整合Quartz 2实现定时任务三:动态暂停 恢复 修改和删除任务
- 关于java的jar包不得不说两句
- 你在用C++编程时遇到的最多的几个汉字是啥?
- 如何修复U盘里的文件
- h264 图像、帧、片、NALU
- parent,son深刻理解this,super关键字