circle in a point

Topics: Windows Forms
Feb 5, 2012 at 2:52 PM

Hi there,

I would like to ask you, how can I draw a circle in a specific point according the latitude and longitude?

 

thank you

Feb 5, 2012 at 3:08 PM

create custom marker

Feb 5, 2012 at 4:57 PM

thanks for your reply radioman,

Can you help me to create a custom marker?I don't have much experience using GMAP.NET.

Thanks radioman

Feb 6, 2012 at 3:07 PM

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using GMap.NET.WindowsForms;
    using GMap.NET;

namespace GMapEnhanced
    {

        public class GMapMarkerCircle : GMapMarkerBase
        {
            #region Properties

            /// <summary>
            /// The pen for the outer circle
            /// </summary>
            public Pen OuterPen { get; set; }

            /// <summary>
            /// The brush for the inner circle
            /// </summary>
            public Brush InnerBrush { get; set; }

            /// <summary>
            /// The brush for the Text
            /// </summary>
            public Brush TextBrush { get; set; }

            /// <summary>
            /// The font for the text
            /// </summary>
            public Font TextFont { get; set; }

            /// <summary>
            /// The text to display inside of the marker
            /// </summary>
            public String Text { get; set; }

            private int diameter = 10;
            /// <summary>
            /// The size of the circle
            /// </summary>
            public int CircleDiameter
            {
                get
                {
                    return this.diameter;
                }
                set
                {
                    diameter = value;
                    this.Size = new System.Drawing.Size(diameter, diameter);
                    Offset = new System.Drawing.Point(-Size.Width / 2, -Size.Height / 2);
                }
            }


            #endregion

            /// <summary>
            /// Constructor
            /// </summary>
            /// <param name="outer">The pen for the outer ring</param>
            /// <param name="inner">The brush for the inner circle.</param>
            /// <param name="diameter">The diameter in pixel of the whole circle</param>
            /// <param name="text">The text in the marker.</param>
            public GMapMarkerCircle(PointLatLng p, Pen outer, Brush inner, int diam, String text)
                : base(p)
            {
                OuterPen = outer;
                InnerBrush = inner;
                CircleDiameter = diam;
                this.Text = text;
                this.TextFont = new Font("Arial", (int)(diameter / 2));
                this.TextBrush = Brushes.Black;
                Offset = new System.Drawing.Point(-Size.Width / 2, -Size.Height / 2);
            }

            /// <summary>
            /// Constructor
            /// </summary>
            /// <param name="p">The LatLongPoint of the marker.</param>
            /// <param name="outer">The pen for the outer ring</param>
            /// <param name="inner">The brush for the inner circle.</param>
            /// <param name="diameter">The diameter in pixel of the whole circle</param>
            /// <param name="textBrush">The brush for the text.</param>
            public GMapMarkerCircle(PointLatLng p, Pen outer, Brush inner, int diam, String text, Brush textBrush)
                : this(p, outer, inner, diam, text)
            {
                this.TextBrush = textBrush;
            }

            /// <summary>
            /// Constructor
            /// </summary>
            /// <param name="p">The LatLongPoint of the marker.</param>
            /// <param name="outer">The pen for the outer ring</param>
            /// <param name="inner">The brush for the inner circle.</param>
            /// <param name="diameter">The diameter in pixel of the whole circle</param>
            /// <param name="textBrush">The brush for the text.</param>
            public GMapMarkerCircle(PointLatLng p, Pen outer, Brush inner, int diam, String text, Brush textBrush, Font textFont)
                : this(p, outer, inner, diam, text, textBrush)
            {
                this.TextFont = textFont;
            }

            /// <summary>
            /// Render a circle
            /// </summary>
            /// <param name="g"></param>
            public override void OnRender(Graphics g)
            {
                g.FillEllipse(InnerBrush, new Rectangle(LocalPosition.X, LocalPosition.Y, diameter, diameter));
                g.DrawEllipse(OuterPen, new Rectangle(LocalPosition.X, LocalPosition.Y, diameter, diameter));

                if (!String.IsNullOrEmpty(this.Text))
                {
                    SizeF sizeOfString = g.MeasureString(this.Text, this.TextFont);
                    int x = (LocalPosition.X + diameter / 2) - (int)(sizeOfString.Width / 2);
                    int y = (LocalPosition.Y + diameter / 2) - (int)(sizeOfString.Height / 2);
                    g.DrawString(this.Text, this.TextFont, this.TextBrush, x, y);
                }
            }
        }
    }

 

Sorry, the codeplex "Insert Code Snippet" tool does not work at the moment, so I can't format the code.

Feb 6, 2012 at 7:10 PM

Thank you for your reply Xandolph

Feb 9, 2012 at 5:20 PM

Hi achille19, did you able to draw the circle, I am looking for the same thing can you kindly share the code if you successfuly able to draw the circle on the selected point

Feb 12, 2012 at 6:52 PM

Hello austin. I will try it these days and if I find it I will post it here.

Feb 12, 2012 at 10:21 PM

I have developed an event that is design an ellipse in the map.Unfortunately, i cannot see the ellipse on the GMap.ne.The code is the following:

 

 private void btnCircle_Click(object sender, EventArgs e)
        {
           
            int x,y,width,height;
            g = gMapControl1.CreateGraphics();

               // it is finding the point of the Marker
            x =overlayTransmitter.Markers[0].LocalPosition.X;
            y =overlayTransmitter.Markers[0].LocalPosition.Y;
            width = 40;
            height = 40;
            g.DrawEllipse(pen, x, y, width, height);
            gMapControl1.Refresh();
        }

Can you tell me what is wrong?

Thanks folks

Feb 12, 2012 at 10:28 PM

everything ;}

Feb 12, 2012 at 10:35 PM

thanks for your reply radioman.

Can you tell me more about my problem?

Feb 13, 2012 at 7:37 AM

check the source of demos...

Feb 18, 2012 at 11:24 AM

Hi achille 19, did you able to draw the circle. If not then download the latest source code and there is a class GMapMarkerCircle.cs under Demo.WindowsForms.CustomMarkers. Simply execute the latest source code in VS2010 and double click on any location and you will  see a white cirle would be there.

Well thats not what I want, what I want is select a point and move the mouse to a certain point and then draw the cirle I hope this will help me to achive what I need.

Thanks to radioman again for his awsome work.....

 

Regards

 

Mar 22, 2012 at 7:15 PM
austin wrote:

Hi achille 19, did you able to draw the circle. If not then download the latest source code and there is a class GMapMarkerCircle.cs under Demo.WindowsForms.CustomMarkers. Simply execute the latest source code in VS2010 and double click on any location and you will  see a white cirle would be there.

Well thats not what I want, what I want is select a point and move the mouse to a certain point and then draw the cirle I hope this will help me to achive what I need.

Thanks to radioman again for his awsome work.....

 

Regards

 


Austin, did you by any chance implement the ability to draw a circle while dragging? That is the same functionality I am looking for...