Custom marker and refresh;

Topics: Windows Forms
Jun 9, 2013 at 5:59 PM
Edited Jun 9, 2013 at 6:03 PM
Hello boys,
I have a custom marker that show on video marker.tag like in this image
Image

If I upgrade the marker position and update the map everything ok but if I update the tag field of the marker my label on the screen is not updated.
Do you have any suggestions for me???

Thanks
Jun 9, 2013 at 9:23 PM
I have tried using this function, but the markers do not update.....
 public void refreshmarker()
        {
             GMapMarkerRect[] marks = new GMapMarkerRect[gMapControl1.Overlays[0].Markers.Count];
            for (int i = 0; i < gMapControl1.Overlays[0].Markers.Count; i++)
             {
                 marks[i] = punti.Markers[i] as GMapMarkerRect;
                 
                 //textBox1.Text += "Marks" + marks[i].Tag.ToString()+Environment.NewLine;
                 //textBox1.Text += "Marks" + marks[i].Tag.ToString() + Environment.NewLine;
             }
             punti.Markers.Clear();
             
             for (int i = 0; i < marks.Length; i++)
             {
                 punti.Markers.Add(marks[i]);
                 //textBox1.Text += "Marks" + punti.Markers[i].Tag.ToString() + Environment.NewLine;
                 //marks[i] = punti.Markers[i] as GMapMarkerRect;
                 //textBox1.Text += "Marks" + marks[i].Tag.ToString()+Environment.NewLine;   
             }
             
             gMapControl1.Refresh();
             
        }
Coordinator
Jun 10, 2013 at 6:28 AM
marker.YourText = "new text";
map.Invalidate();
// done
Jun 10, 2013 at 7:46 AM
Edited Jun 10, 2013 at 10:27 AM
Hello Radioman, after the changes if I read the text property of the tag it is correct but unfortunately also by invoking the invalidate method of the marker map is redrawn on the screen and always shows the old text.

Before
Image

After
Image


Maybe I have to use a newer version.
I'm using the dlls of 17/10/2011! They go well?

Thanks again and congratulations for your work ....

I enclose code of refresh and rendering of marker
REFRESH
 public void aggiornamarker(string nome, double Lat, double Lng,int altitudine,string descrizione, DateTime datetime, int id)
        {
            GMapMarkerRect marker = null;
            marker = punti.Markers[id] as GMapMarkerRect;
              marker.Position = new PointLatLng(Lat, Lng);
               marker.Tag = nome;
               marker.altitudine = altitudine;
               marker.descrizione = descrizione;
               marker.dataetempo = datetime;

               gMapControl1.Invalidate();
               gMapControl1.Refresh();
            
        }
Class Marker
public class GMapMarkerRect : GMap.NET.WindowsForms.GMapMarker
        {
            #region Properties
            Bitmap img = Properties.Resources.wp;
            /// <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; }

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

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

            /// <summary>
            /// The text to display inside of the marker 
            /// </summary>
            public DateTime dataetempo { 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 GMapMarkerRect(PointLatLng p, Pen outer, Brush inner, int diam, String text)
                : base(p)
            {
                
                OuterPen = outer;
                InnerBrush = inner;
                CircleDiameter = diam;
                //int width = (int)g.MeasureString(aString, control.Font).Width;
                this.Text = text;
                this.TextFont = new Font("Arial", 8);
                this.TextBrush = Brushes.Black;
                
                Size = img.Size;
                Offset = new System.Drawing.Point(-Size.Width / 2, -Size.Height / 2-1);
                //Offset = new System.Drawing.Point(-Size.Width / 2, -Size.Height / 2);

                
                
            }




            /// <summary>
            /// Render a circle
            /// </summary>
            /// <param name="g"></param>
            public override void OnRender(Graphics g)
            {

                g.DrawImage(img, LocalPosition.X, LocalPosition.Y, Size.Width, Size.Height);
                var textSizew = (int)g.MeasureString(Text, this.TextFont).Width;
                var textSizeh = (int)g.MeasureString(Text, this.TextFont).Height;
                Rectangle bordo = new Rectangle();
                bordo.Width = textSizew+1;
                bordo.Height = textSizeh+3;
                bordo.X = LocalPosition.X -bordo.Width/2 + Size.Width/2 ;
                bordo.Y = LocalPosition.Y-bordo.Height-1;
               // MessageBox.Show(bordo.Width.ToString() + " " + bordo.Height.ToString() + " " + bordo.X.ToString() + " " + bordo.Y.ToString() + " " + Size.Height.ToString());
                g.FillRectangle(InnerBrush, bordo);
                g.DrawRectangle(OuterPen, bordo);
                if (!String.IsNullOrEmpty(this.Text))
                {
                    SizeF sizeOfString = g.MeasureString(this.Text, this.TextFont);
                    int x = (LocalPosition.X - bordo.Width / 2 + Size.Width / 2);
                    int y = (LocalPosition.Y - bordo.Height);
                    g.DrawString(this.Text, this.TextFont, this.TextBrush, x, y);
                }
                
              
            }
            
        }
Coordinator
Jun 10, 2013 at 11:47 AM
i don't know about old versions, but it's working in the latest
Jun 10, 2013 at 1:20 PM
Edited Jun 10, 2013 at 1:23 PM
Sorry Radioman I made a big fat stupid mistake...
in refresh i change tag field of marker
public void aggiornamarker(string nome, double Lat, double Lng,int altitudine,string descrizione, DateTime datetime, int id)
        {
            GMapMarkerRect marker = null;
            marker = punti.Markers[id] as GMapMarkerRect;
              marker.Position = new PointLatLng(Lat, Lng);
               ----------------------------------------
               marker.Tag = nome;  //WRONG
               marker.Text = nome; // RIGHT
               ----------------------------------------
               marker.altitudine = altitudine;
               marker.descrizione = descrizione;
               marker.dataetempo = datetime;

               gMapControl1.Invalidate();
               gMapControl1.Refresh();
            
        }
but in the class marker the text that I show on screen is in the Text field....... that nervousness
public class GMapMarkerRect : GMap.NET.WindowsForms.GMapMarker
        {
            #region Properties
            Bitmap img = Properties.Resources.wp;
            /// <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; }
            -----------------------------------------------------------------------------
 
            /// <summary>
            /// The text to display inside of the marker 
            /// </summary>
            public String descrizione { get; set; }

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

            /// <summary>
            /// The text to display inside of the marker 
            /// </summary>
            public DateTime dataetempo { 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 GMapMarkerRect(PointLatLng p, Pen outer, Brush inner, int diam, String text)
                : base(p)
            {
                
                OuterPen = outer;
                InnerBrush = inner;
                CircleDiameter = diam;
                //int width = (int)g.MeasureString(aString, control.Font).Width;
                this.Text = text;
                this.TextFont = new Font("Arial", 8);
                this.TextBrush = Brushes.Black;
                
                Size = img.Size;
                Offset = new System.Drawing.Point(-Size.Width / 2, -Size.Height / 2-1);
                //Offset = new System.Drawing.Point(-Size.Width / 2, -Size.Height / 2);

                
                
            }




            /// <summary>
            /// Render a circle
            /// </summary>
            /// <param name="g"></param>
            public override void OnRender(Graphics g)
            {

                g.DrawImage(img, LocalPosition.X, LocalPosition.Y, Size.Width, Size.Height);
                var textSizew = (int)g.MeasureString(Text, this.TextFont).Width;
                var textSizeh = (int)g.MeasureString(Text, this.TextFont).Height;
                Rectangle bordo = new Rectangle();
                bordo.Width = textSizew+1;
                bordo.Height = textSizeh+3;
                bordo.X = LocalPosition.X -bordo.Width/2 + Size.Width/2 ;
                bordo.Y = LocalPosition.Y-bordo.Height-1;
               // MessageBox.Show(bordo.Width.ToString() + " " + bordo.Height.ToString() + " " + bordo.X.ToString() + " " + bordo.Y.ToString() + " " + Size.Height.ToString());
                g.FillRectangle(InnerBrush, bordo);
                g.DrawRectangle(OuterPen, bordo);
                if (!String.IsNullOrEmpty(this.Text))
                {
                    SizeF sizeOfString = g.MeasureString(this.Text, this.TextFont);
                    int x = (LocalPosition.X - bordo.Width / 2 + Size.Width / 2);
                    int y = (LocalPosition.Y - bordo.Height);
                    g.DrawString(this.Text, this.TextFont, this.TextBrush, x, y);
                }
                
              
            }
            
        }
Thanks Again now it is perfect :))))
Coordinator
Jun 10, 2013 at 1:22 PM
;}
Jul 16, 2013 at 8:17 PM
Edited Jul 16, 2013 at 9:07 PM
Hi Radioman,

Do you know why the program goes to the 'public override void OnRender(Graphics g)' sometime 5 time after an OnMapZoomChanged event?
It dose only once when I first open the form.

Can it be avoided?

Many Thanks,

Jeno
Coordinator
Jul 17, 2013 at 1:50 PM
zooming load tiles, tile loaded -> refresh