How to draw circle on the MAP using GMAP.NET in C#

后端 未结 8 1876
鱼传尺愫
鱼传尺愫 2020-12-21 11:06

I am using GMAP.NET in c#. I am able to display the map on the form, now i am trying to draw a CIRCLE mouse by clicking on a certian point, keeping the left mouse button an

8条回答
  •  没有蜡笔的小新
    2020-12-21 11:26

    If you want to use the typical GDI features associated with the drawing class, you can simply inherit the GMapMarker class. This allows you to draw simple shapes, like circles, and create custom properties (for instance, one that will calculate the radius in miles of the shape):

    public class GMapPoint : GMap.NET.WindowsForms.GMapMarker
    {
        private PointLatLng point_;
        private float size_;
        public PointLatLng Point
        {
            get
            {
                return point_;
            }
            set
            {
                point_ = value;
            }
        }
        public GMapPoint(PointLatLng p, int size)
            : base(p)
        {
            point_ = p;
            size_ = size;
        }
    
        public override void OnRender(Graphics g)
        {
            g.FillRectangle(Brushes.Black, LocalPosition.X, LocalPosition.Y, size_, size_); 
            //OR 
            g.DrawEllipse(Pens.Black, LocalPosition.X, LocalPosition.Y, size_, size_);
            //OR whatever you need
    
        }
     }
    

    To draw points on the map:

            GMapOverlay points_ = new GMapOverlay("pointCollection");
            points_.Markers.Add(new GMapPoint(new PointLatLng(35.06, -106.36), 10));
    
            gMapControl1.Overlays.Add(points_);
    

    (And because I had some questions about it) Since we are inhereting from the markers class, we can still take advantage of the tooltiptext capability:

            GMapPoint pnt = new GMapPoint(new PointLatLng(35.06, -106.36), 10);
            pnt.Size = new Size(10,10);
            pnt.ToolTipText = "Text Here";
            pnt.ToolTipMode = MarkerTooltipMode.Always;
            points_.AddMarker(pnt);
    

提交回复
热议问题