Does anyone understand the gb.Map component?
Posted: Tuesday 14th January 2020 8:02pm
I've spent a few hours this rainy afternoon taking my first look as this Map component.
I often struggle with Gambas documentation because I'm really thick, so I'm looking for advice. I started with a new project and just dragged a MapView onto the main form. The first bit of code is quite easy:-
I then re-wrote the code as showMethod2, which also works:-
However, zooming the map and drawing polylines & circles is more straightforward:-
I often struggle with Gambas documentation because I'm really thick, so I'm looking for advice. I started with a new project and just dragged a MapView onto the main form. The first bit of code is quite easy:-
Public Sub Form_Open()
MapView1.Map.AddTile("openstreet", "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png").Copyright = "OpenStreetMap Contributors"
showMethod {1/2/3}
MapView1.Map.Zoom = 15
End
Then I added some code based upon an example I found from a French guy, which I've called showMethod1:-Public Sub showMethod1()
MapView1.Map.AddShape("downtown")
MapView1.Map!downtown.AddPoint("church", MapPoint(51.059, -0.33))
MapView1.Map.Center = MapView1.Map!downtown!church.Points
End
This code works, but I have 2 problems with it; I don't think I have ever seen the "!" used this way, and the autocomplete doesn't seem to recognise the "Points" method (...at least I assume its a method).I then re-wrote the code as showMethod2, which also works:-
Public Sub showMethod2()
MapView1.Map.AddShape("downtown")
MapView1.Map["downtown"].AddPoint("church", MapPoint(51.059, -0.33))
MapView1.Map.Center = MapView1.Map["downtown"]["church"].Points
End
Again, this code doesn't look much like anything in the user documentation. I also can't see any manual reference to:-MapPoint(51.059, -0.33)
...which seems to be the undocumented default Method to setup the Lat & Lon Properties. So for displayMethod3 I created a new instance of MapPoint and set these two properties individually.Public Sub showMethod3()
Dim myPoint As New MapPoint
myPoint.Lat = 51.059
myPoint.Lon = -0.33
MapView1.Map.AddShape("downtown")
MapView1.Map["downtown"].AddPoint("church", myPoint)
MapView1.Map.Center = MapView1.Map["downtown"]["church"].Points
End
So your views & comments would be appreciated, even if it turns out I've missed something important in the documentation.However, zooming the map and drawing polylines & circles is more straightforward:-
MapView1.Map.Zoom = 15
Public Sub SetArea()
Dim hPolyLine As New MapPoint[]
With MapView1.Map.AddShape("Poly")
hPolyLine = [MapPoint(51.063, -0.326), MapPoint(51.058, -0.325), MapPoint(51.058, -0.333), MapPoint(51.063, -0.334), MapPoint(51.064, -0.330), MapPoint(51.063, -0.326)]
.AddPolyLine("manor", hPolyLine)
End With
End
Public Sub DrawCircle()
Dim hCircle As New MapPoint
With MapView1.Map.AddShape("ring")
hCircle = MapPoint(51.063, -0.326)
.AddCircle("hoop", hCircle, 50, Color.red, 1, 1, Color.Blue)
End With
End