User Tools

Site Tools


k24:k24.8:k24.8.1:start

24.8.1 Projects

The free map material from openstreetmap.org (OSM) is used for the two projects presented. In a displayed map - shown in a MapView - you can zoom the map section in 18 steps with the mouse wheel and move the displayed map area with a permanent click on the map.

24.8.1.1 Prerequisites

There are three prerequisites for displaying a map:

  • Accurate knowledge of the geographic coordinates of the location on Earth to be displayed - preferably as latitude and longitude in decimal degrees.
  • Selection of a suitable zoom factor from the interval [1..18], which determines the size of the map section.
  • Active internet connection to retrieve the (pre-)calculated maps from the server.

24.8.1.2 Project GeoMap1

The presented project implements a viewer for maps from OSM.

OBG
Figure 24.8.1.2.1: GeoMap1 - Hanseatic City Osterburg in Saxony/Anhalt

The source code for the project is given in full:

[1] ' Gambas class file
[2]
[3] Public Sub Form_Open()
[4]   FMain.Center
[5]   FMain.Caption = "GeoMap - Daten von OpenStreetMap"
[6]   btnHelp.Value = True
[7]   ShowMap()
[8] End ' Form_Open()
[9]
[10] Public Sub ShowMap()
[11]   Dim iZoom As Integer
[12]   Dim fLatitude, fLongitude As Float
[13]   Dim sCacheName, sTileName, sTilePattern As String
[14]   Dim cArguments As New Collection
[15]
[16] ' Initialisierung
[17]   iZoom = 13
[18]   sTileName = "OpenStreetMap"
[19]   sTilePattern = "85.30.190.241/{z}/{x}/{y}.png"
[20]   cArguments = Null
[21]   sCacheName = Null
[22]   fLatitude = 52.7905  ' °Breite Osterburg
[23]   fLongitude = 11.7531 ' °Länge Osterburg
[24]
[25]   MapView1.Map.AddTile(sTileName, sTilePattern, cArguments, sCacheName)
[26]   MapView1.Map[sTileName].Copyright = " © OpenStreetMap"
[27]   MapView1.Map[sTileName].Visible = True ' optional; Standard-Einstellung ist TRUE
[28]   MapView1.Map.AddShape("P1")
[29]   MapView1.Map!P1.AddPoint("Osterburg", MapPoint(fLatitude, fLongitude))
[30]   MapView1.Map.Center = MapPoint(fLatitude, fLongitude)
[31] ' MapView1.Map.Center = MapView1.Map!P1!Osterburg.Points ' Alternative
[32]   MapView1.Map.Zoom = iZoom
[33]   MapView1.AllowEffect = True
[34] End ' ShowMap()
[35]
[36] Public Sub btnHelp_Click()
[37]   ShowHelp()
[38] End ' btnHelp_Click()
[39]
[40] Public Sub ShowHelp()
[41]   Dim sMessage As String
[42]
[43]   sMessage = "<hr><b>Hinweise zum Einsatz der Komponente Map</b><hr>"
[44]   sMessage &= "» Verschieben der Karte mit gedrückter linker Maustaste<br>"
[45]   sMessage &= "» Zoomen mit dem Maus-Rad<br>"
[46]   sMessage &= "» Zoomen mit dem Schieberegler<hr>"
[47]   sMessage &= "» Die Tastenkombination ALT+B beendet das Programm<hr>"
[48]   sMessage &= "▪ Entwickler der Komponente <i>gb.map</i>  ist Fabien Bodard"
[49]   sMessage &= "<br>▪ EMail: gambix@users.sourceforge.net<hr>"
[50]   Message.Info(sMessage)
[51] End ' ShowHelp()
[52]
[53] Public Sub btnClose_Click()
[54]   FMain.Close
[55] End ' btnClose_Click()

Notes:

  • In line 19, the adequate IP address is used instead of the URL {s}.tile.openstreetmap.org. This is only advantageous if there are problems with the DNS server in connection with intermediary routers.<x ul>*</x> If you want to print out the displayed map - a corresponding class for this is being developed by F. Bodard - or use it in another context, then you must display a copyright notice on the map in line 26 in order to comply with the licence conditions! * The map tiles are stored in the directory ~/.cache/gb.map/MyMapCache/.
  • For detailed information on the arguments and the cache, see the documentation.

Help is displayed when the programme is started:


Figure 24.8.1.2.2: Programme Help

24.8.1.3 GeoMap2 project

The second project is an adaptation of the MapView programme example by Fabien Bodard - the developer of the Map component - from the Gambas sample collection.

In addition to displaying a map, you can switch on a magnifying glass function with the CTRL key:

Lens
Figure 24.8.1.3.1: GeoMap2 with magnifying glass

The archives for both projects are in the download directory.

Download

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.
k24/k24.8/k24.8.1/start.txt · Last modified: by 127.0.0.1