User Tools

Site Tools


Sidebar

Network and communication

k24:k24.8:k24.8.4:start

24.8.4 Alternatives

There are at least three alternatives to using the Map component:

1. calling the standard browser from a Gambas programme, passing it the openstreetmap.org page with the desired map (latitude and longitude, zoom) as the URL:

Public Sub btnShowMap_Click()
  Desktop.Open("http://www.openstreetmap.org/?lat=52.78979&lon=11.75280&zoom=15&amp")
End ' btnShowMap_Click()

2. you use the WebView component in a separate Gambas form, to which you pass the page from openstreetmap.org with the desired map (latitude, longitude, zoom) as the URL:

OBG
Figure 24.8.4.1: OSM map (Hanseatic city of Osterburg in Saxony/Anhalt)

Yes - this is the full source code:

' Gambas class file
 
Public Sub Form_Open()
  FMain.Center
  WebView1.Url = "http://www.openstreetmap.org/?lat=52.78979&lon=11.75280&zoom=14&amp"
End ' Form_Open()
 
Public Sub btnClose_Click()
  FMain.Close
End ' btnClose_Click()

If you only need map tiles, for example to assemble them into a map and use them further, you can work on the console with the programme wget. However, do not forget to provide the imported image in png format with an appropriate copyright notice in a text field!

Kachel
Figure 24.8.4.2: Map tile as 256×256-pixel graphic with inserted copyright text

hans@linux:~$ wget http://85.30.190.241/13/4363/2676.png -P $HOME/OSM-Karten
 
--2013-05-01 09:40:41--  http://85.30.190.241/13/4363/2676.png
Verbindungsaufbau zu 85.30.190.241:80... verbunden.
HTTP-Anforderung gesendet, warte auf Antwort... 200 OK
Länge: 26533 (26K) [image/png]
In »»/home/hans/OSM-Karten/2676.png«« speichern.
 
100%[======================================>] 26.533      --.-K/s   in 0,1s
 
2013-05-01 09:40:42 (267 KB/s) - »»/home/hans/OSM-Karten/2676.png«« gespeichert [26533/26533]
 
hans@linux:~$

The syntax for the URL in the wget command:

http://a.tile.openstreetmap.org/ZOOM/xTILE/yTILE.png
http://85.30.190.241/ZOOM/X-TILE/Y-TILE.png

necessarily requires the calculation of the map tile coordinates xTile and yTile from the latitude, longitude values and the specification of the desired zoom factor. The following source code can be used for the calculation:

Public Function LatLonZoom2xyTile(fLatitudeDeg As Float,fLongitudeDeg As Float,iZoom As Integer) As Integer[]
  Dim n As Integer
  Dim fXTile, fYTile, fLatitudeRad, fSecans As Float
  Dim aMatrix As New String[]
 
  fLatitudeRad = Rad(fLatitudeDeg)
  fSecans = 1 / Cos(fLatitudeRad)
 
  n = 2 ^ iZoom
  aMatrix.Add(Str(iZoom))
  fXTile = n * ((fLongitudeDeg + 180) / 360)
  aMatrix.Add(Int(fXTile))
  fYTile = n * (1 - (Log(Tan(fLatitudeRad) + fSecans) / Pi)) / 2 ' Log() in Gambas -> ln() mit Basis = e
  aMatrix.Add(Int(fYTile))
 
  Return aMatrix
 
End ' LatLonZoom2xyTile(...) As Integer[]
 
Public Sub btnBerechnungKachelKoordinaten_Click()
  Dim iXTile, iYTile, iZoom As Integer
  Dim fLatitude, fLongitude As Float
  Dim sTileServer As String
  Dim aMatrix As New String[]
  Dim aTileServer As String[] = ["a", "b", "c"]
 
  Randomize
  sTileServer = aTileServer[CInt(Rnd(0, 3))]
' Realität: Server-Auswahl im Content Delivery Network (CDN). Wird eine Anfrage an das CDN gesendet,
' dann wählt das Request-Routing-System einen geeigneten Replica-Server aus.
 
  iZoom = 13
  fLatitude = 52.78979   ' Breite  52,78979°
  fLongitude = 11.75280  ' Länge   11,75280°
 
  aMatrix = LatLonZoom2xyTile(fLatitude, fLongitude, iZoom)
 
  Print "Ort = Osterburg"
  Print "Geografische Breite = " & fLatitude & "°"
  Print "Geografische Länge = " & fLongitude & "°"
  Print
  Print "Kachel-Server = " & sTileServer
  Print "Zoom = " & aMatrix[0]
  Print "xTile = " & aMatrix[1]
  Print "yTile = " & aMatrix[2]
  Print "-------------------------------------------------------------'"
  Print "Zoom = " & izoom
  Print "xTile = " & Geo.MapPointToTile(MapPoint(fLatitude, fLongitude), iZoom).X ' 4363
  Print "yTile = " & Geo.MapPointToTile(MapPoint(fLatitude, fLongitude), iZoom).Y ' 2676
 
End ' btnBerechnungKachelKoordinaten_Click()

A much snappier way is to use the Geo.MapPointToTile(..) method of the Map.Geo class directly in the last two lines, which internally uses the calculations in the LatLonZoom2xyTile(..) function.

Here follows a script to insert a copyright text into a tile image:

#!/bin/bash
#
# Quelle1: http://wiki.ubuntuusers.de/ImageMagick
# Quelle2: http://pecita.eu/police-en.php
# Wasserzeichentext in alle Bilder aus diesen Verzeichnis einfuegen
# Der Wasserzeichentext wird unten links ins Bild eingesetzt
# Sie koennen folgende Parameter anpassen:
Textabstandvonlinks=10
Textabstandvonunten=20
Schriftgroesse=30
Schriftart="Pecita.otf"
Schriftfarbe="red"
# Moegliche Farben koennen aufgelistet werden mit dem Befehl: convert -list color
Wasserzeichentext="© OpenStreetMap"
# Programmbeginn
echo "Textabstand von links: $Textabstandvonlinks"
echo "Textabstand von unten: $Textabstandvonunten"
echo "Schriftgoesse: $Schriftgroesse"
echo "Schriftart: $Schriftart"
echo "Schriftfarbe: $Schriftfarbe"
echo "Wasserzeichentext: $Wasserzeichentext"
echo " "
ls -1 *png | while read file;
do {
horizontal=`identify -verbose $file | grep Geometry: | awk {'print $2'} |cut -d"x" -f 1`
vertikal=`identify -verbose $file | grep Geometry: | awk {'print $2'} |cut -d"x" -f 2`
X=$Textabstandvonlinks
Y=$(($vertikal - $Textabstandvonunten))
convert -font $Schriftart -pointsize $Schriftgroesse -fill $Schriftfarbe -draw "text $X, \
        $Y '$Wasserzeichentext'" "$file" "`basename c_"$file"`";
echo "Bearbeite Datei $file"
}
done
echo "Wasserzeichen erfolgreich eingearbeitet."
echo
echo "Konsole schließen mit Enter!"
read dummy;
exit
# Programmende

Download

The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k24/k24.8/k24.8.4/start.txt · Last modified: 16.08.2022 (external edit)

Page Tools