markers rotation-bearing

Topics: Windows Forms
Mar 5, 2012 at 12:58 PM
Edited Mar 5, 2012 at 12:59 PM

This function is still not working, am i right?

Coordinator
Mar 5, 2012 at 1:09 PM

it works in last release

Mar 5, 2012 at 9:04 PM
Edited Mar 5, 2012 at 9:05 PM

i don't think so. I tried to do rotate with google marker and it's not work. Lines about bearing in class GMarkerGoogle.cs are also commented.

Mar 6, 2012 at 3:14 PM

I would really like to use rotation, so please for reply radioman

Coordinator
Mar 6, 2012 at 3:25 PM

use latest release

Mar 6, 2012 at 4:41 PM
Edited Mar 6, 2012 at 4:41 PM

Hot Build (0750e7861198) ??

Coordinator
Mar 6, 2012 at 5:06 PM

http://greatmaps.codeplex.com/releases/view/20235

Mar 7, 2012 at 5:23 AM

the rotation has been work but this bearing for all of marker. how to make only 1 marker rotate??

thanks

Mar 8, 2012 at 1:01 PM

tnx radioman,

i see that rotation works using Point and FillPolygon, but is possible to rotate custom marker (image)?

Mar 8, 2012 at 11:47 PM
nemonemo wrote:

tnx radioman,

i see that rotation works using Point and FillPolygon, but is possible to rotate custom marker (image)?

its possible with custom marker. I have try it.

Mar 9, 2012 at 11:37 AM

hi xaberius

i try to rotate my marker, but it's not work correctly...

my class of marker:

public class GMapMarkerImage : GMapMarker
    {
        public System.Drawing.Image image;
        float bearing;
        public float Bearing
        {
            set { bearing = value; }
            get { return bearing; }
        }

        public GMapMarkerImage(PointLatLng p)
            : base(p)
        {
            image = System.Windows.Forms.Properties.Resources.truck;
            Size = new System.Drawing.Size(image.Width, image.Height);
            Offset = new Point(-image.Width / 2, -image.Height / 2);
        }

        public override void OnRender(Graphics g)
        {
            g.RotateTransform(this.Bearing - Overlay.Control.Bearing);
            g.DrawImage(image, LocalPosition.X , LocalPosition.Y, Size.Width, Size.Height);
            g.ResetTransform();
        }
}

 

Can you tell me, what i done wrong ??

Coordinator
Mar 9, 2012 at 12:05 PM

check the source of demos...

Mar 9, 2012 at 6:07 PM

In source i noticed only rotation of polygons and not rotation of image :/

Coordinator
Mar 9, 2012 at 6:34 PM

man, there is no difference...

Mar 9, 2012 at 8:09 PM

so if is no difference, why is not works if i replace only that line g.FillPolygon(Brushes.Lime, Arrow);

with this g.DrawImage(Resources.truck, LocalPosition.X, LocalPosition.Y);

Mar 10, 2012 at 9:00 AM

video of detail the problem, after custom marker set to bearing=90...

video

Coordinator
Mar 10, 2012 at 10:15 AM

what exactly version do you use and your code?

Mar 10, 2012 at 10:37 AM
Edited Mar 10, 2012 at 10:39 AM

I use this version greatmaps-dbfffa5b4adc

 

 

namespace GMap.NET.WindowsForms.Markers
{
    using System.Drawing;

#if !PocketPC
    using System.Windows.Forms.Properties;
#else
   using GMap.NET.WindowsMobile.Properties;
#endif

    public class GMapMarkerGoogleGreen : GMapMarker
    {
        public float? Bearing;

        static readonly System.Drawing.Size SizeSt = new System.Drawing.Size(Resources.truck.Width, Resources.truck.Height);

        public GMapMarkerGoogleGreen(PointLatLng p)
            : base(p)
        {
            Size = SizeSt;
            Offset = new Point(-10, -34);
        }

        //static readonly Point[] Arrow = new Point[] { new Point(-7, 7), new Point(0, -22), new Point(7, 7), new Point(0, 2) };

        public override void OnRender(Graphics g)
        {
#if !PocketPC
            if (!Bearing.HasValue)
            {
                g.DrawImageUnscaled(Resources.shadow50, LocalPosition.X, LocalPosition.Y);
            }
            g.TranslateTransform(ToolTipPosition.X, ToolTipPosition.Y);

            if (Bearing.HasValue)
            {
                g.RotateTransform(Bearing.Value - Overlay.Control.Bearing);
                g.DrawImage(Resources.truck, LocalPosition.X, LocalPosition.Y);
            }

            g.ResetTransform();

            if (!Bearing.HasValue)
            {
                g.DrawImageUnscaled(Resources.bigMarkerGreen, LocalPosition.X, LocalPosition.Y);
            }
#else
            DrawImageUnscaled(g, Resources.shadow50, LocalPosition.X, LocalPosition.Y);
            DrawImageUnscaled(g, Resources.marker, LocalPosition.X, LocalPosition.Y);
#endif
        }
    }
}

 

-------------

creating marker....


 

PointLatLng pos = new PointLatLng(46.533151895492, 15.6565582752228);

GMapMarkerGoogleGreen marker = new GMapMarkerGoogleGreen(pos);
marker.ToolTipMode = MarkerTooltipMode.OnMouseOver;
marker.Bearing = bearing;
markers.Markers.Add(marker);
Coordinator
Mar 10, 2012 at 11:57 AM

try edit this line to:

g.DrawImage(Resources.truck, LocalPosition.X, LocalPosition.Y); =>  g.DrawImage(Resources.truck, 0, 0);

Coordinator
Mar 10, 2012 at 12:05 PM
Edited Mar 10, 2012 at 12:05 PM

p.s. the idea of object rotation is to g.Translate to it's global rotation point and render at it's local rotation point

Mar 10, 2012 at 8:03 PM

works, tnx ;)

Apr 22, 2012 at 2:19 AM

What should I do to the latest version of the code has earned bearing?

http://greatmaps.codeplex.com/SourceControl/changeset/changes/2c56ffb53626

 

I uncommented body set "Bearing" properties, but worked is not correct.

Coordinator
Apr 22, 2012 at 9:31 AM

there is is no easy fix

Apr 22, 2012 at 12:38 PM
radioman wrote:

there is is no easy fix

I want to try to do it.

If not hard, about what the problem is?

When I code in a property uncommented Bearing, the card does not start to rotate relative to the marker center of the screen, and with respect to the lower right corner of the map visible, which becomes the center.

Coordinator
Apr 22, 2012 at 2:02 PM

well the problem is that rotation calculation is wrong, and you need somehow to make it correct..

Apr 23, 2012 at 3:58 AM

Made to map rotates. But now we have to make a turn marker. Further, the modified code.

GMapControl.cs in GMap.NET.WindowsPresentation

protected override void OnRender(DrawingContext drawingContext)
      {
        if(!Core.IsStarted)
            return;

        drawingContext.DrawRectangle(EmptyMapBackground, null, new Rect(RenderSize));

        if (IsRotated)
            drawingContext.PushTransform(rotationMatrix);

        if (MapScaleTransform != null)
        {
            drawingContext.PushTransform(MapScaleTransform);
            drawingContext.PushTransform(MapTranslateTransform);
            {
                DrawMap(drawingContext);

                #if DEBUG
                drawingContext.DrawLine(VirtualCenterCrossPen, new Point(-20, 0), new Point(20, 0));
                drawingContext.DrawLine(VirtualCenterCrossPen, new Point(0, -20), new Point(0, 20));
                #endif
            }
            drawingContext.Pop();
            drawingContext.Pop();
        }
        else
        {
            drawingContext.PushTransform(MapTranslateTransform);
            {
                DrawMap(drawingContext);
                #if DEBUG
                drawingContext.DrawLine(VirtualCenterCrossPen, new Point(-20, 0), new Point(20, 0));
                drawingContext.DrawLine(VirtualCenterCrossPen, new Point(0, -20), new Point(0, 20));
                #endif
            }
            drawingContext.Pop();
        }

        if (IsRotated)
        drawingContext.Pop();
        
        // selection
        if(!SelectedArea.IsEmpty)
        {
            GPoint p1 = FromLatLngToLocal(SelectedArea.LocationTopLeft);
            GPoint p2 = FromLatLngToLocal(SelectedArea.LocationRightBottom);

            long x1 = p1.X;
            long y1 = p1.Y;
            long x2 = p2.X;
            long y2 = p2.Y;

            if(SelectionUseCircle)
            {
                drawingContext.DrawEllipse(SelectedAreaFill, SelectionPen, new System.Windows.Point(x1 + (x2 - x1) / 2, y1 + (y2 - y1) / 2), (x2 - x1) / 2, (y2 - y1) / 2);
            }
            else
            {
                drawingContext.DrawRoundedRectangle(SelectedAreaFill, SelectionPen, new Rect(x1, y1, x2 - x1, y2 - y1), 5, 5);
            }
        }

        if(ShowCenter)
        {
            drawingContext.DrawLine(CenterCrossPen, new System.Windows.Point((ActualWidth / 2) - 5, ActualHeight / 2), new System.Windows.Point((ActualWidth / 2) + 5, ActualHeight / 2));
            drawingContext.DrawLine(CenterCrossPen, new System.Windows.Point(ActualWidth / 2, (ActualHeight / 2) - 5), new System.Windows.Point(ActualWidth / 2, (ActualHeight / 2) + 5));
        }

        #region -- copyright --

        if(Copyright != null)
        {
            drawingContext.DrawText(Copyright, new System.Windows.Point(5, ActualHeight - Copyright.Height - 5));
        }

        #endregion

        base.OnRender(drawingContext);
      }

 

public float Bearing
      {
         get
         {
            return Core.bearing;
         }
         set
         {
             if (Core.bearing != value)
             {
                 bool resize = Core.bearing == 0;
                 Core.bearing = value;

                 UpdateRotationMatrix();

                 if (value != 0 && value % 360 != 0)
                 {
                     Core.IsRotated = true;

                     //if (Core.tileRectBearing.Size == Core.tileRect.Size)
                     //{
                     //    Core.tileRectBearing = Core.tileRect;
                     //    Core.tileRectBearing.Inflate(1, 1);
                     //}
                 }
                 else
                 {
                     Core.IsRotated = false;
                     Core.tileRectBearing = Core.tileRect;
                 }

             //    if (resize)
             //    {
             //        Core.OnMapSizeChanged((int)ActualWidth, (int)ActualHeight);
             //    }

                 //Core_OnMapZoomChanged();

                 InvalidateVisual();
             }
         }
      }

Coordinator
Jan 14, 2015 at 6:48 PM
bearing should be ok now
Marked as answer by radioman on 1/14/2015 at 11:48 AM
Jan 15, 2015 at 2:17 AM
Congratulations!...
Coordinator
Jan 15, 2015 at 3:06 PM
p.s. marker rotation demo [left menu, Live->FlightRadar] and GMarkerArrow.cs
Jun 23, 2015 at 11:00 AM
Hi,
Sorry to reopen this thread....but iam new to this GMap....can anyone answer me......I tried the radioman code....but null exception at overlay.control.bearing is coming. how to overcome that....
thanks in advance...