如何在 VB.Net 中使用 GMap 创建圆圈
How to create circe whit GMap in VB.Net
我正在寻找可以在地图上创建圆圈的功能。我在 VB.Net 中使用 Gmap 库。是否存在一些可以在地图上的点周围创建一个圆的函数,例如半径为 500 米?
我找到了代码,但这不是我要找的代码:
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports GMap.NET
Imports GMap.NET.WindowsForms
Namespace Map
Public Class GMapMarkerCircle
Inherits GMapMarker
Private m_Radius As Integer
'In Meters
Public m_OutlinePen As Pen
Public m_FillBrush As Brush
Public m_Fill As Boolean
Public Sub New(p As PointLatLng, Radius As Integer, OutlinePen As Pen, FillBrush As Brush, Fill As Boolean)
MyBase.New(p)
m_OutlinePen = OutlinePen
m_FillBrush = FillBrush
m_Radius = Radius
m_Fill = Fill
End Sub
Public Overrides Sub OnRender(g As Graphics)
g.SmoothingMode = SmoothingMode.AntiAlias
Dim R As Integer = CInt((m_Radius) / Overlay.Control.MapProvider.Projection.GetGroundResolution(Overlay.Control.Zoom, Position.Lat)) * 2
If m_Fill = True Then
g.FillEllipse(m_FillBrush, New System.Drawing.Rectangle(LocalPosition.X - R \ 2, LocalPosition.Y - R \ 2, R, R))
End If
g.DrawEllipse(m_OutlinePen, New System.Drawing.Rectangle(LocalPosition.X - R \ 2, LocalPosition.Y - R \ 2, R, R))
End Sub
End Class
End Namespace
在应用中:
Dim CircleMarker As New GMapMarkerCircle(New GMap.NET.PointLatLng(ZemSirka, ZemDlzka), 660, New Pen(Color.Azure, 1), Brushes.LightSeaGreen, True)
Dim Overlay As New GMapOverlay("Circle")
Overlay.Markers.Add(CircleMarker)
GMapControl1.Overlays.Add(Overlay)
但是当我缩放时 in/out 地图圆圈消失了。
我有一个初学者的问题:有没有可能做半透明的画笔?
最后,我创建了适用于短距离的代码,例如:200,300,500 米。
Public Function toRad(ByVal deegres As Double)
Return deegres * (Math.PI / 180)
End Function
Public Function toDeg(ByVal radians As Double)
Return radians * (180 / Math.PI)
End Function
Private Function pivotRadius(ByVal Dlzka As Double, ByVal Sirka As Double, ByVal dist As Double)
Dim distance = (dist / earthRadius) / 1000
Dim lat As Double = toRad(Sirka)
Dim lng As Double = toRad(Dlzka)
Dim points As IList(Of PointLatLng) = New List(Of PointLatLng)()
Dim x As Integer = 0
While x < 360
Dim brng As Double = toRad(x)
Dim latRadians As Double = Math.Asin(Math.Sin(lat) * Math.Cos(distance) + Math.Cos(lat) * Math.Sin(distance) * Math.Cos(brng))
Dim lngRadians As Double = lng + (Math.Atan2(Math.Sin(brng) * Math.Sin(distance) * Math.Cos(lat), Math.Cos(distance) - Math.Sin(lat) * Math.Sin(latRadians)) / 1.6)
points.Add(New PointLatLng(toDeg(lngRadians), toDeg(latRadians)))
latRadians = 0
lngRadians = 0
x += 10
End While
Dim polyOverlay As New GMapOverlay("polygons")
Dim polygon As New GMapPolygon(points, "mypolygon")
polygon.Fill = New SolidBrush(Color.FromArgb(30, Color.Aqua))
polygon.Stroke = New Pen(Color.Blue, 1)
GMapControl1.Overlays.Clear()
GMapControl1.Overlays.Add(polyOverlay)
polyOverlay.Polygons.Add(polygon)
Return 0
End Function
我正在寻找可以在地图上创建圆圈的功能。我在 VB.Net 中使用 Gmap 库。是否存在一些可以在地图上的点周围创建一个圆的函数,例如半径为 500 米?
我找到了代码,但这不是我要找的代码:
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports GMap.NET
Imports GMap.NET.WindowsForms
Namespace Map
Public Class GMapMarkerCircle
Inherits GMapMarker
Private m_Radius As Integer
'In Meters
Public m_OutlinePen As Pen
Public m_FillBrush As Brush
Public m_Fill As Boolean
Public Sub New(p As PointLatLng, Radius As Integer, OutlinePen As Pen, FillBrush As Brush, Fill As Boolean)
MyBase.New(p)
m_OutlinePen = OutlinePen
m_FillBrush = FillBrush
m_Radius = Radius
m_Fill = Fill
End Sub
Public Overrides Sub OnRender(g As Graphics)
g.SmoothingMode = SmoothingMode.AntiAlias
Dim R As Integer = CInt((m_Radius) / Overlay.Control.MapProvider.Projection.GetGroundResolution(Overlay.Control.Zoom, Position.Lat)) * 2
If m_Fill = True Then
g.FillEllipse(m_FillBrush, New System.Drawing.Rectangle(LocalPosition.X - R \ 2, LocalPosition.Y - R \ 2, R, R))
End If
g.DrawEllipse(m_OutlinePen, New System.Drawing.Rectangle(LocalPosition.X - R \ 2, LocalPosition.Y - R \ 2, R, R))
End Sub
End Class
End Namespace
在应用中:
Dim CircleMarker As New GMapMarkerCircle(New GMap.NET.PointLatLng(ZemSirka, ZemDlzka), 660, New Pen(Color.Azure, 1), Brushes.LightSeaGreen, True)
Dim Overlay As New GMapOverlay("Circle")
Overlay.Markers.Add(CircleMarker)
GMapControl1.Overlays.Add(Overlay)
但是当我缩放时 in/out 地图圆圈消失了。 我有一个初学者的问题:有没有可能做半透明的画笔?
最后,我创建了适用于短距离的代码,例如:200,300,500 米。
Public Function toRad(ByVal deegres As Double)
Return deegres * (Math.PI / 180)
End Function
Public Function toDeg(ByVal radians As Double)
Return radians * (180 / Math.PI)
End Function
Private Function pivotRadius(ByVal Dlzka As Double, ByVal Sirka As Double, ByVal dist As Double)
Dim distance = (dist / earthRadius) / 1000
Dim lat As Double = toRad(Sirka)
Dim lng As Double = toRad(Dlzka)
Dim points As IList(Of PointLatLng) = New List(Of PointLatLng)()
Dim x As Integer = 0
While x < 360
Dim brng As Double = toRad(x)
Dim latRadians As Double = Math.Asin(Math.Sin(lat) * Math.Cos(distance) + Math.Cos(lat) * Math.Sin(distance) * Math.Cos(brng))
Dim lngRadians As Double = lng + (Math.Atan2(Math.Sin(brng) * Math.Sin(distance) * Math.Cos(lat), Math.Cos(distance) - Math.Sin(lat) * Math.Sin(latRadians)) / 1.6)
points.Add(New PointLatLng(toDeg(lngRadians), toDeg(latRadians)))
latRadians = 0
lngRadians = 0
x += 10
End While
Dim polyOverlay As New GMapOverlay("polygons")
Dim polygon As New GMapPolygon(points, "mypolygon")
polygon.Fill = New SolidBrush(Color.FromArgb(30, Color.Aqua))
polygon.Stroke = New Pen(Color.Blue, 1)
GMapControl1.Overlays.Clear()
GMapControl1.Overlays.Add(polyOverlay)
polyOverlay.Polygons.Add(polygon)
Return 0
End Function