VB.NET Add Square to Map

Topics: Windows Forms
Jul 21, 2011 at 3:25 PM


I'm new to GMAP.Net and its a very good tool, but I have a little problem. 
I would like to add a square to my Map. But anywhere is a problem... No square on Map....

Private Sub ToolStripButton1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
       Dim Point1 As New PointLatLng
        Dim Point2 As New PointLatLng

        GMapControl1.PolygonsEnabled = True

        Dim Area As GMapPolygon
        Area.Points.Add(New PointLatLng(52.293939, 9.282338))
        Area.Points.Add(New PointLatLng(52.293229, 9.281131))
        Dim Layer_Polygons As GMapOverlay
End Sub

 Can anybody help me please... ????

Jul 21, 2011 at 6:28 PM

In main:

Friend Layer_Polygon As GMapOverlay

Private Sub Form_Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Layer_Polygon = New GMapOverlay(MainMap, "Polygons")

After button click:

Dim This_Point as new PointLatLng(51.000, 9.000)
Dim polygonPoints As New List(Of PointLatLng)()

        Dim myTestPolygon As GMapPolygon
        myTestPolygon = New GMapPolygon(polygonPoints, "SquarePolygon")


But for a square you need at least 4 Points.

Code isnt' cheked but should work.

Jul 22, 2011 at 10:01 AM



Very great !!!!! 
This code works ! 


Many Thanks to you "robbeede"

Jul 22, 2011 at 10:05 AM

Sorry, I have another question. 

How I can add the name of this square, that I can see the name in the Map ?

Can you help me please again ?



Jul 23, 2011 at 9:48 AM

1.) hmm.. you can add a marker with a name and tooltip to show it.

Polygon itselfs has no possibilty for it.

2.) You can add Properties like name,.. in Gmap.NET.WindowsForms.GMapPolygon.cs

3.) in GMap.Overlay.cs you can add some graphical things, like drawstring(...

public string MyPolygonName;

      /// <summary>
      /// draw polygons, override to draw custom
      /// </summary>
      /// <param name="g"></param>
      protected virtual void DrawPolygons(Graphics g)
... g.Drawstring(.., MyPolygonName); ... }
Not sure if this the best way, but i think this should work.

Jul 23, 2011 at 11:10 AM

Hmm... Thanks. 

But this is code for C++, isnt it ? 
I need for VB.Net because I don't have the files GMAP.Overlay.cs in my VB.


Jul 23, 2011 at 11:30 AM

create custom overlay, and render whatever you want

Jul 23, 2011 at 12:26 PM

I still do not know how to inherit a Custom Polygon or Route, see discussion below:



to KKIT,

the code you can find in the SourceCode of GMap.Windowsforms.dll, you can change it there and make your own release. But the better way is to create Custom Overlay.

Dec 8, 2011 at 5:58 PM

in c# how gonna be ?