2016-10-19 2 views
0

dreht Ich verwende GMap.NET in C#.Wie man GMap.NET Marker in C#

Meine Anwendung sieht wie folgt aus ..

enter image description here

bekommen GPS-Protokolle aus CSV-Datei, auf der Karte markiert und zeigt Geschwindigkeit (km/h) und (Grad) auf der rechten Seite Richtung.

Ich habe eine Pfeilmarkierung PNG-Datei. Also, was ich tun möchte, ist, die Pfeilmarkierung in der Mitte der Karte zu setzen und sie so zu drehen, dass sie auf ihren Kurs verweist.

In JavaScript Google Map API hat ein Markersymbol die Eigenschaft rotation. Aber ich denke, das GMap.NET nicht. Ich habe den ganzen Tag gegoogelt, aber ich konnte es nicht herausfinden.

Bitte, sagen Sie mir, wie es geht ..

Antwort

0

Dieser Quellcode in den Missionsplaner enthalten (mit GMap)

public class GMapMarkerPlane : GMapMarker 
{ 
    const float rad2deg = (float)(180/Math.PI); 
    const float deg2rad = (float)(1.0/rad2deg); 

    private readonly Bitmap icon = Resources.HomePoint; 

    float heading = 0; 
    float cog = -1; 
    float target = -1; 
    float nav_bearing = -1; 
    float radius = -1; 

    public GMapMarkerPlane(PointLatLng p, float heading, float cog, float nav_bearing, float target, float radius) 
     : base(p) 
    { 
     this.heading = heading; 
     this.cog = cog; 
     this.target = target; 
     this.nav_bearing = nav_bearing; 
     this.radius = radius; 
     Size = icon.Size; 
    } 

    public GMapMarkerPlane(PointLatLng p, float heading) 
     : base(p) 
    { 
     this.heading = heading; 
     Size = icon.Size; 
    } 

    public override void OnRender(Graphics g) 
    { 
     Matrix temp = g.Transform; 
     g.TranslateTransform(LocalPosition.X, LocalPosition.Y); 

     g.RotateTransform(-Overlay.Control.Bearing); 

     int length = 500; 
     // anti NaN 
     try 
     { 
      g.DrawLine(new Pen(Color.Orange, 2), 0.0f, 0.0f, (float)Math.Cos((heading - 90) * deg2rad) * length, (float)Math.Sin((heading - 90) * deg2rad) * length); 
     } 
     catch 
     { 
     } 
     //g.DrawLine(new Pen(Color.Green, 2), 0.0f, 0.0f, (float)Math.Cos((nav_bearing - 90) * deg2rad) * length, (float)Math.Sin((nav_bearing - 90) * deg2rad) * length); 
     //g.DrawLine(new Pen(Color.Black, 2), 0.0f, 0.0f, (float)Math.Cos((cog - 90) * deg2rad) * length, (float)Math.Sin((cog - 90) * deg2rad) * length); 
     //g.DrawLine(new Pen(Color.Orange, 2), 0.0f, 0.0f, (float)Math.Cos((target - 90) * deg2rad) * length, (float)Math.Sin((target - 90) * deg2rad) * length); 
     // anti NaN 
     try 
     { 
      float desired_lead_dist = 100; 

      double width = 
       (Overlay.Control.MapProvider.Projection.GetDistance(Overlay.Control.FromLocalToLatLng(0, 0), 
        Overlay.Control.FromLocalToLatLng(Overlay.Control.Width, 0)) * 1000.0); 
      double m2pixelwidth = Overlay.Control.Width/width; 

      float alpha = ((desired_lead_dist * (float)m2pixelwidth)/radius) * rad2deg; 

      if (radius < -1 && alpha > 1) 
      { 
       // fixme 

       float p1 = (float)Math.Cos((cog) * deg2rad) * radius + radius; 

       float p2 = (float)Math.Sin((cog) * deg2rad) * radius + radius; 

       g.DrawArc(new Pen(Color.HotPink, 2), p1, p2, Math.Abs(radius) * 2, Math.Abs(radius) * 2, cog, alpha); 
      } 

      else if (radius > 1 && alpha > 1) 
      { 
       // correct 

       float p1 = (float)Math.Cos((cog - 180) * deg2rad) * radius + radius; 

       float p2 = (float)Math.Sin((cog - 180) * deg2rad) * radius + radius; 

       g.DrawArc(new Pen(Color.HotPink, 2), -p1, -p2, radius * 2, radius * 2, cog - 180, alpha); 
      } 
     } 
     catch 
     { 
     } 

     try 
     { 
      g.RotateTransform(heading); 
     } 
     catch 
     { 
     } 
     g.DrawImageUnscaled(icon, icon.Width/-2, icon.Height/-2); 

     g.Transform = temp; 
    } 
} 

und dann den Code in Ihrem getGPS hinzufügen fuction (kann benutzt du einen Thread oder Timer?

PointLatLng point = new PointLatLng(lat, lng);

var plane = new GMapMarkerPlane(point, heading);

objects.Markers.Add(plane);

Verwandte Themen