Oliwer11 Oliwer11 - 4 months ago 66
Vb.net Question

How to create circe whit GMap in VB.Net

I'm looking for some function which can create a circle on map. I'm using Gmap library in VB.Net. Exist some function which can create a circle around of point on map, for examle with 500 meters radius ?

I found a code, but it isn't what I'm exactly looking for :

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


And in app:

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)


But when I zoom in/out the map circle disappears.
I have one beginners question: is any possibility to do Brushes semitransparent ?

Answer

Finally I create code which works fine for short distances for examle: 200,300,500 meters.

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
Comments