Rotate Custom Marker

Topics: Windows Forms
Oct 24, 2011 at 2:45 PM

I have a custom marker in my GPS application and need to rotate it to the direction that the GPS bearing is pointing to.  I've searched over this forum and tried some code examples but haven't been able to successfully do this.  I'm using VB.Net 2010.  Can someone provide me with a quick example with a marker and changing it's bearing to a degree?

Coordinator
Oct 24, 2011 at 2:52 PM

try: GMapMarkerGoogleRed from demos

marker.Bearing = 10;

Feb 23, 2012 at 8:11 PM

use this code

 

public class GMapMarkerImage : GMapMarker
    {
        public System.Drawing.Image Image;
        public double Heading;

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

        public override void OnRender(Graphics g)
        {
            Point Aircraft_Position = new Point(LocalPosition.X - 32, LocalPosition.Y - 32);
            Point Center = new Point(Aircraft_Position.X + 32, Aircraft_Position.Y + 32);
            Rotate_Image(g, Exam_GMap.Properties.Resources.Airplane_64, Aircraft_Position, Center, (float)Heading, 1);
        }

        protected void Rotate_Image(Graphics pe, Image img, Point ptImg, Point ptRot, float angle_deg, float scaleFactor)
        {
            double beta = 0;     // Angle between the Horizontal line and the line (Left upper corner - Rotation point)
            double d = 0;        // Distance between Left upper corner and Rotation point)       
            float deltaX = 0;    // X componant of the corrected translation
            float deltaY = 0;    // Y componant of the corrected translation

            double angle_rad = (angle_deg * Math.PI / 180);
            // Compute the correction translation coeff
            if (ptImg != ptRot)
            {
                //
                if (ptRot.X != 0)
                {
                    beta = Math.Atan((double)ptRot.Y / (double)ptRot.X);
                }

                d = Math.Sqrt((ptRot.X * ptRot.X) + (ptRot.Y * ptRot.Y));

                // Computed offset
                deltaX = (float)(d * (Math.Cos(angle_rad - beta) - Math.Cos(angle_rad) * Math.Cos(angle_rad + beta) - Math.Sin(angle_rad) * Math.Sin(angle_rad + beta)));
                deltaY = (float)(d * (Math.Sin(beta - angle_rad) + Math.Sin(angle_rad) * Math.Cos(angle_rad + beta) - Math.Cos(angle_rad) * Math.Sin(angle_rad + beta)));
            }

            // Rotate image support
            pe.RotateTransform(angle_deg);

            // Dispay image
            pe.DrawImage(img, (ptImg.X + deltaX) * scaleFactor, (ptImg.Y + deltaY) * scaleFactor, img.Width * scaleFactor, img.Height * scaleFactor);

            // Put image support as found
            pe.RotateTransform(-angle_deg);

        }
    }