Image Marker Class, and Other Markers as Time Allows

Topics: Windows Forms
Oct 8, 2009 at 7:06 PM

Here is a Class for an Image Maker where the image can be called from a file or an embdedded resource.

Note: The image is centered on the point lat/lng and image size set by Size (height,width)

Create a new class GmapMarkerImage in GMap.NET.WindowsForms.Markers and add the following if you want to add it to Gmap Windows Forms.

namespace GMap.NET.WindowsForms.Markers
{
    using System.Drawing;
    using System.Drawing.Drawing2D;
    
    public class GMapMarkerImage : GMapMarker
    {
        public System.Drawing.Image Image;

        public GMapMarkerImage(PointLatLng p)
            : base(p)
        {
            TTBorder.Width = 2;
            TTBorder.LineJoin = LineJoin.Round;
            TTBorder.StartCap = LineCap.RoundAnchor;
            TTFormat.Alignment = StringAlignment.Center;
            TTFormat.LineAlignment = StringAlignment.Center;
        }

        public override void OnRender(Graphics g)
        {
            g.DrawImage(Image, System.Convert.ToInt32(LocalPosition.X - Size.Width / 2), System.Convert.ToInt32(LocalPosition.Y - Size.Height / 2), Size.Width, Size.Height);
        }
    }
}

 

 

 

 

Coordinator
Oct 8, 2009 at 7:49 PM

p.s. there is property Offset, its purpose is to avoid LocalPosition.X - Size.Width / 2), System.Convert.ToInt32(LocalPosition.Y - Size.Height / 2),

just set Offset = new Point(Size.Width / 2, Size.Height / 2);

then you can just render image at g.DrawImage(Image, LocalPosition.X, LocalPosition.Y, Size.Width, Size.Height);

Oct 9, 2009 at 12:50 PM

Hi, Yes I was aware of the offset but in my case 99.9% of the time I use an image it is always centered at the point.

Less typing at coding time......Lazy:)

Cheers

 

Coordinator
Oct 9, 2009 at 1:43 PM

i see ;}

Oct 10, 2009 at 8:06 AM

Sorry, I could not find the TTBorder and TTFormat, where can I found it?

Oct 10, 2009 at 10:38 AM

Oops my bad,  that should be;

namespace GMap.NET.WindowsForms.Markers
{
    using System.Drawing;
    using System.Drawing.Drawing2D;
    
    public class GMapMarkerImage : GMapMarker
    {
        public System.Drawing.Image Image;

        public GMapMarkerImage(PointLatLng p) : base(p)
        {
        }

        public override void OnRender(Graphics g)
        {
            g.DrawImage(Image, System.Convert.ToInt32(LocalPosition.X - Size.Width / 2), System.Convert.ToInt32(LocalPosition.Y - Size.Height / 2), Size.Width, Size.Height);
        }
    }
}


Cheers

Oct 10, 2009 at 12:07 PM

Thanks for letting me know.

Sumvel

Feb 23, 2012 at 9:10 PM

Hi

After making a GMapMarkerImage ,ToolTipText not showing !!!!!!

Why?????

 

Only when set ToolTipMode property to MarkerTooltipMode.Always , ToolTipText  Will be dispaly.

Please help me

thanks