Does anyone understand the gb.Map component?
Posted
#1
(In Topic #363)
Regular

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:-
Then I added some code based upon an example I found from a French guy, which I've called showMethod1:-
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:-
Again, this code doesn't look much like anything in the user documentation. I also can't see any manual reference to:-
Code (gambas)
- 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.
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:-
Code (gambas)
- MapView1.Map.Zoom = 15
- 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)
- hCircle = MapPoint(51.063, -0.326)
- .AddCircle("hoop", hCircle, 50, Color.red, 1, 1, Color.Blue)
Posted
Regular

The exclamation point (! or 'bang') looks like a dictionary access operator that I used to see in VB/VBA.
https://social.msdn.microsoft.com/Forums/en-US/1393df69-929e-49c6-93b0-5cb0fa7a6430/what-is-a-operator
vb.net - What does this { ! } mean in the specific line of code? - Stack Overflow
I was never fond of it myself, and went out of my way to use the other syntax.
Steve S
PS – thanks for sharing, will be watching where you get with the map component…
_________________
stevedee said
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:-
Posted
Regular

sjsepan said
…The exclamation point (! or 'bang') looks like a dictionary access operator…
Thanks Steve, that's another clue.
I'm familiar with "!" being using to access fields in a database, like this extract from one of my old Gambas projects:-
… but I don't think I've ever seen it used in Gambas beyond that. Maybe "!" can be used to access the elements in a collection or an array? I cant see anything about this in the documentation, so I'll have to experiment.
Posted
Regular

sjsepan said
The exclamation point (! or 'bang') looks like a dictionary access operator…
You are spot-on Steve.
Generally, there are 3 collection types in computer science; array, set & dictionary
In Gambas (& VB) a Collection is basically a Dictionary, and we can use the "!" as follows:-
Code (gambas)
- Cars["Ford"] = "black"
- Cars["Skoda"] = "blue"
- Cars["Jaguar"] = "red"
…or use this method:-
Code (gambas)
Posted
Regular

The first step is to select a map. I'm using a free "Hike & Bike" OpenStreetMap, and the terms & conditions require me to display a copyright message:-
MapView1.Map.AddTile("openstreet", "https://tiles.wmflabs.org/hikebike/\{z}/{x}/{y}.png").Copyright = "© OpenStreetMap Contributors"
This one line of code is all you need to display a world map which can be zoomed using the display controls.
To plot data (such as a route recorded on a gps device) the data needs to be prepared as a series of MapPoints, where each point consists of a Latitude and a Longitude which must be added to a Gambas collection:-
Code (gambas)
- myRoute.Add(MapPoint(fLat1, fLon1))
- myRoute.Add(MapPoint(fLat2, fLon2))
We need to add a MapShape layer & give it a simple string name (a key):-
Code (gambas)
- MapView1.Map.AddShape("outdoors")
It would be nice to have a balloon shaped flag at the start of route. This also needs a key/name, so lets call it "starter":-
When the map is displayed, I'd like it centred on my starting point:-
Code (gambas)
- MapView1.Map.Center = MapView1.Map["outdoors"]["starter"].Points
…which simply centres the map at "starter" on the "outdoor" MapShape layer.
Now we can plot the route data in myRoute as a series of linked red lines, giving it a key/name ("walkies"):-
Code (gambas)
- MapView1.Map["outdoors"].AddPolyLine("walkies", myRoute, Color.Red)
One final touch is to zoom in to get a more "local" view:-
Code (gambas)
- MapView1.Map.Zoom = 14
I will post an example project under Project Showcase for anyone interested.
Posted
Regular

Europaeus sum !
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Regular

vuott said
…from Wiki of italian Gambas Forum…
Many thanks vuott, that looks like a great resource.
This image shows an English translation of topics:-
1 guest and 0 members have just viewed this.





