How to draw circles.

Topics: Help
Dec 6, 2012 at 12:05 PM

YES , I have tried to convert the GMapMarkerCircle.cs code found in the demo source with this  c# to VB converter http://converter.telerik.com/ 

-I still cant draw circles, I am looking for a complete picece of VB code that shows how to draw a circle at lat/lng with X m radius that works with zoom. 

- Anyone out there that can help out ?

 

 

Dec 6, 2012 at 12:40 PM

Hello,

I am using this:

 

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 then:

Dim CircleMarker As New GMapMarkerCircle(New GMap.NET.PointLatLng(Latitude, Longitude), Distance, New Pen(PenColor, 4), Brushes.Transparent, True)
Dim Overlay As New GMapOverlay("Circle")
Overlay.Markers.Add(CircleMarker)

And then add the Overlay to the Map!

Michael

Dec 6, 2012 at 2:10 PM

Thank you MBDTeam 

It almost work's, it fails here look at the image ion the link below.

http://www.freebords.se/circle.jpg 

Dec 6, 2012 at 7:04 PM

You did not follow my advise. You ar trying to add the Circle to the Overlay. The circle is no overlay! Its a marker. SO:

Create a New Overlay or use an existing, add the marker(circle) to the overlay

Dim Overlay As New GMapOverlay("Circle")
Overlay.Markers.Add(CircleMarker)

and then you can add this overlay to the Maps overlay collection.

Michael

Dec 6, 2012 at 8:01 PM
Edited Dec 6, 2012 at 8:02 PM

Well..  "overlay is not accessible beqause of friend" is the major problem, look at the image URL in above post..  I have the latest DLL, maybe their is a difference there ??

Dec 6, 2012 at 8:21 PM

You can add Overlays in the constructor of the form of your control which hosts the GMap Control! Simply add an Overlay "Circles" to your GMap Control in the Constructor of the form and use it later, if you want to add a circle.