This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using GMap.NET; | |
using GMap.NET.WindowsForms; | |
using GMap.NET.WindowsForms.Markers; | |
using System; | |
using System.Drawing; | |
using System.Drawing.Drawing2D; | |
namespace GMap_offline | |
{ | |
/// <summary> | |
/// used to override the drawing of the waypoint box bounding | |
/// </summary> | |
public class GMapMarkerPlane : GMapMarker | |
{ | |
private readonly Bitmap icon = Resource.planetracker; | |
float heading = 0; | |
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); | |
try | |
{ | |
g.RotateTransform(heading); | |
} | |
catch { } | |
g.DrawImageUnscaled(icon, icon.Width / -2, icon.Height / -2); | |
g.Transform = temp; | |
} | |
} | |
} |
For icon picture, create the icon and add it into resource folder.
private readonly Bitmap icon = Resources.planetracker;
In the declaration, create new layer name from GMapOverlay:
public static GMapOverlay routesoverlay;
Next, in main form create new layer and add it to the gmap:
routesoverlay = new GMapOverlay("routes");
gMap.Overlays.Add(routesoverlay);
and then, add the code below in the GPS heading function (use timer 1 second or more):
routesoverlay.Markers.Clear();
// Get the most up-to-date data received from the sensor.
var curMeas = vn200.CurrentMeasurements;
PointLatLng point = new PointLatLng((float)curMeas.LatitudeLongitudeAltitude.X,
(float)curMeas.LatitudeLongitudeAltitude.Y);
gMap.Position = point;
var plane = new GMapMarkerPlane(point, (float)curMeas.YawPitchRoll.YawInDegs);
routesoverlay.Markers.Add(plane);
and finally, the Plane Marker heading will following your heading data sensor.
Keyword: Rotate GMap.NET marker, C#, heading Marker, IMU, google map marker, GPS tracking heading marker.
Excellent!
ReplyDeleteExcellent.. I was searching for this
ReplyDeleteDoes anyone have any idea how to place the picture I added in the center of the coordinate I showed?
ReplyDeleteI can rotate the photo. There is no problem with that. but it was not centered in the coordinate I wanted. For example, the point I want is 0.0 but it always stands on it.
ReplyDeleteu never said what vn200 is what is it ?
ReplyDelete"vn200.CurrentMeasurements" is the heading data from IMU sensor V200 from Vectorav.
Delete