2016-10-01 11 views
0

작은 차량 추적 프로젝트에 Gmap.net API를 사용하고 있습니다. 이 프로젝트는 Windows 형태의 C#입니다. 위도, 경도, 속도, 제목 및 일부 기타 정보와 같은 기기의 정보가 표시됩니다. 제목 정보는도 (0 ~ 359)입니다. 차량이 화살표 기호가있는 방향으로 움직이고 있음을 어떻게 나타낼 수 있습니까?Gmap.Net에서 차량 이동 방향을 표시하는 방법

+0

를 추가하는 방법입니다. 아마도 다음 페이지의 삼각형 중 하나가 도움이 될 것입니다 : https://www.google.com/search?q=types+of+triangles&espv=2&biw=1680&bih=944&tbm=isch&tbo=u&source=univ&sa=X&sqi=2&ved=0ahUKEwjHh4Tnr7nPAhWCKyYKHUqNAcsQsAQIGw – jdweng

답변

0

이것은 사소한 것처럼 보이지 않습니다. 한 가지 옵션은 단순히 비트 맵 이미지를 사용하고 필요에 따라 이미지를 회전하는 것입니다. 좀 더 유연성과 속도가 필요했고이 작업을 수행하기 위해 드로잉 기능을 사용했습니다.

로컬 좌표 (픽셀)를 사용하여지도에 다각형을 그릴 수 있다고 가정하면 수동으로 일부 표시기를 그릴 수 있습니다. 예를 들어,이 코드 : Rotate bunch of points thourgh an origin)

enter image description here

회전 기능이 포스트로부터의 변동이다

int position_size = 20; 
GPoint gp = FromLatLngToLocal(longlatposition); 

Point[] pnts = new Point[4]; 
pnts[0] = new Point((int)gp.X - (position_size * 2), (int)gp.Y + (position_size * 2)); 
pnts[1] = new Point((int)gp.X, (int)gp.Y - (position_size * 4)); 
pnts[2] = new Point((int)gp.X + (position_size * 2), (int)gp.Y + (position_size * 2)); 
pnts[3] = new Point((int)gp.X, (int)gp.Y + position_size); 

float heading_ = 45; //this is where you define how much to rotate 
pnts = Rotate(pnts, new PointF(gp.X, gp.Y), heading_); 

g.FillPolygon(new SolidBrush(color), pnts); 

이 보이는 화살표 당길 것이다.

private static PointF[] Rotate(PointF[] point, PointF pivot, double angleDegree) 
{ 
     double angle = angleDegree * Math.PI/180; 
     double cos = Math.Cos(angle); 
     double sin = Math.Sin(angle); 

     PointF[] rotated = new PointF[point.Length]; 

     for (int i = 0; i < point.Length; i++) 
     { 
      float dx = point[i].X - pivot.X; 
      float dy = point[i].Y - pivot.Y; 

      double x = (cos * dx) - (sin * dy) + pivot.X; 
      double y = (sin * dx) + (cos * dy) + pivot.Y; 

      rotated[i] = new PointF((float)x, (float)y); 
     } 

     return rotated; 
} 

이제 GMap 플러그인을 사용하여 모든 것을 통합했습니다. 당신이 이것을 할 수있는 몇 가지 방법이 있습니다. 개인적으로 GMap 소스 코드를 수정하기로 결정한 이유는 픽셀 좌표로 작업 할 때 유연성이 가장 크기 때문입니다. 또 다른 옵션은 소스를 수정하고 싶지 않다는 가정하에 새 폴리곤 오버레이를 만들고 새 위치와 제목을 표시 할 때 포인트를 업데이트하는 것입니다. 폴리곤 오버레이는 1ng의 위도로 좌표를 취합니다. 특히 위치 표시기를 다른 모든 것으로 확장하지 않으려는 경우에는 전환을 제대로 수행해야합니다.

이 정보가 도움이되기를 바랍니다.

2

나는이 스레드가 거의 1 년 된 것을 알고 있지만 이것은 보트의 방향에 따라 회전하는 보트 표시자를 만드는 방법입니다. 또한 확대/축소 수준에 따라 보트를 다르게 그립니다.

의견이 부족하여 죄송합니다.

Namespace GMap.NET.WindowsForms.Markers 

Public Class GMapMarkerBoat 
    Inherits GMapMarker 
    Public Brush As Brush 
    Public boatHeading As Double 

    Public Sub New(ic As SEAS_DATA.ImageCluster, b As Brush) 
     MyBase.New(ic.LatLong) 
     boatHeading = ic.IMU_Heading 

     Brush = b 

     'Size of the marker 
     Size = New Size(8, 8) 

    End Sub 

    Public Overrides Sub OnRender(g As Graphics) 

     Dim newSize As Size 
     Dim maxZoomLevel As Integer = SEAS_Forms.frmMain.myMap.MaxZoom 

     Select Case SEAS_Forms.frmMain.myMap.Zoom 
      Case maxZoomLevel 
       newSize = New Size(Size.Width * 2, Size.Height * 2) 
      Case maxZoomLevel - 1 To maxZoomLevel 
       newSize = New Size(CInt(Size.Width * 1.5), CInt(Size.Height * 1.5)) 
      Case maxZoomLevel - 2 To maxZoomLevel - 1 
       newSize = Size 
      Case SEAS_Forms.frmMain.myMap.MinZoom To maxZoomLevel - 2 
       newSize = New Size(CInt(Size.Width/2), CInt(Size.Height/2)) 
     End Select 

     'boat 
     Dim boat(4) As PointF 

     boat(0).X = CSng(-newSize.Width/2) 
     boat(0).Y = CSng(-newSize.Height/2) 
     boat(1).X = (boat(0).X + newSize.Width) 
     boat(1).Y = boat(0).Y 
     boat(3).X = boat(0).X 
     boat(3).Y = (boat(0).Y + newSize.Height) 
     boat(2).X = boat(1).X 
     boat(2).Y = boat(3).Y 
     boat(4).X = CSng(boat(0).X - newSize.Width/2) 
     boat(4).Y = CSng(boat(0).Y + newSize.Width/2) 

     If SEAS_Forms.frmMain.myMap.Zoom > maxZoomLevel - 4 Then 
      boat = TransformAndRotate(boatHeading, boat) 'simplified rotation and transformation matrix 
     Else 
      boat = TransformAndRotate(0, boat) 
     End If 

     'start drawing here 
     Select Case SEAS_Forms.frmMain.myMap.Zoom 
      Case maxZoomLevel - 3 To maxZoomLevel 
       g.FillPolygon(Brush, boat) 
      Case SEAS_Forms.frmMain.myMap.MinZoom To maxZoomLevel - 3 
       Dim newRect As New RectangleF(boat(0).X, boat(0).Y, newSize.Width, newSize.Height) 
       g.FillEllipse(Brush, newRect) 
     End Select 

    End Sub 

    Private Function TransformAndRotate(heading As Double, points() As PointF) As PointF() 

     Dim cosRot As Double = Math.Cos((heading + 90) * Math.PI/180) 
     Dim sinRot As Double = Math.Sin((heading + 90) * Math.PI/180) 

     For i = 0 To points.Length - 1 
      Dim x As Single = points(i).X 
      Dim y As Single = points(i).Y 
      points(i).X = CSng((LocalPosition.X) + (x * cosRot - y * sinRot)) 'simplified rotation and transformation matrix 
      points(i).Y = CSng((LocalPosition.Y) + (x * sinRot + y * cosRot)) 
     Next 

     Return points 
    End Function 

End Class 

End Namespace 

전달중인 사용자 지정 클래스 개체 (ic As ImageCluster)에는 PointLatLng 및 머리글에 대한 속성이 있습니다. 여기

내가 긴 이등변 삼각형을 확인하고 이동 방향 차량으로 회전 마커

'add the marker to the overlay 
newOverlay.Markers.Add(New GMap.NET.WindowsForms.Markers.GMapMarkerBoat(ic, Brushes.Red)) 
관련 문제