前段时间想用GMap.Net实现航程轨迹的描绘,但是因为刚接触摸不着头脑,扣了好久,感叹自己会的太少,想做的太多!
我就直接介绍代码吧!
在地图上描点无非是找到一点然后在此点放一个标志,这个标志定义成一个类
public class GMapMarkerCircle : GMapMarker
{
/// <summary>
/// specifies how the outline is painted
/// </summary>
public Pen Stroke = new Pen(Color.FromArgb(155, Color.Gray));
/// <summary>
/// background color
/// </summary>
//public Brush Fill = new SolidBrush(Color.FromArgb(155, Color.Red));
public Brush Fill;
/// <summary>
/// is filled
/// </summary>
public bool IsFilled = true;
public GMapMarkerCircle(PointLatLng p, Brush f)
: base(p)
{
Fill = f;
IsHitTestVisible = false;
}
public override void OnRender(Graphics g)
{
int R = 8;
if (IsFilled)
{
g.FillEllipse(Fill, new System.Drawing.Rectangle(LocalPosition.X - R / 2, LocalPosition.Y - R / 2, R, R));
}
g.DrawEllipse(Stroke, new System.Drawing.Rectangle(LocalPosition.X - R / 2, LocalPosition.Y - R / 2, R, R));
}
public override void Dispose()
{
if (Stroke != null)
{
Stroke.Dispose();
Stroke = null;
}
if (Fill != null)
{
Fill.Dispose();
Fill = null;
}
base.Dispose();
}
}
然后进行调用,代码如下
pointMove = new PointLatLng(yStation, xStation);
DrawrouteBetweenTowPoint(pointMove, Fill);
其中,yStation和xStation是double xStation = 0, yStation = 0
函数定义,
private void DrawrouteBetweenTowPoint(PointLatLng pointLatLng, Brush Fill)
{
gMap.Overlays.Add(trackOverlay);
GMapMarkerCircle circle = new GMapMarkerCircle(pointLatLng,Fill);
trackOverlay.Markers.Add(circle);
}