Differenze tra le versioni di "Utilizzare una DrawingArea con gb.map anziché una MapView"
Da Gambas-it.org - Wikipedia.
Riga 1: | Riga 1: | ||
Mostreremo di seguito un semplice codice esemplificativo, nel quale si farà uso di una ''DrawingArea'' anziché dell'oggetto ''MapView''. | Mostreremo di seguito un semplice codice esemplificativo, nel quale si farà uso di una ''DrawingArea'' anziché dell'oggetto ''MapView''. | ||
− | Bisognerà | + | Bisognerà ovviamente attivare il Componente ''gb.map'' . <SUP>[[[#Note|Nota 1]]]</sup> |
Private DrawingArea1 As DrawingArea | Private DrawingArea1 As DrawingArea | ||
− | |||
− | |||
− | |||
Private hMap As New Map | Private hMap As New Map | ||
Private x As Integer | Private x As Integer | ||
Riga 11: | Riga 8: | ||
Private mp As MapPoint | Private mp As MapPoint | ||
Private pt As New Point | Private pt As New Point | ||
− | |||
Riga 23: | Riga 19: | ||
With Me | With Me | ||
.W = Desktop.W | .W = Desktop.W | ||
− | .H = Desktop.H | + | .H = Desktop.H |
+ | .Arrangement = Arrange.Fill | ||
End With | End With | ||
With DrawingArea1 = New DrawingArea(Me) As "DrawingArea1" | With DrawingArea1 = New DrawingArea(Me) As "DrawingArea1" | ||
− | .X = | + | .X = 0 |
− | + | .Y = 0 | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | .Y = | ||
− | |||
− | |||
− | |||
End With | End With | ||
Riga 62: | Riga 32: | ||
'''Public''' Sub Form_Open() | '''Public''' Sub Form_Open() | ||
− | + | hMap.Zoom = 6 | |
− | + | Me.Text = "Zoom: " & CStr(6) | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | hMap.Zoom = | ||
− | |||
− | |||
'''End''' | '''End''' | ||
Riga 78: | Riga 39: | ||
'''Public''' Sub DrawingArea1_Draw() | '''Public''' Sub DrawingArea1_Draw() | ||
− | |||
− | |||
− | |||
With hMap | With hMap | ||
.Width = Paint.W | .Width = Paint.W | ||
.Height = Paint.H | .Height = Paint.H | ||
+ | .Center = mp | ||
.Draw() | .Draw() | ||
End With | End With | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
DrawingArea1.Refresh() | DrawingArea1.Refresh() | ||
Riga 125: | Riga 63: | ||
With hMap | With hMap | ||
− | .Center.Lat -= ((my ^ 0) * my) / (( | + | .Center.Lat -= ((my ^ 0) * my) / ((hMap.Zoom * 10) / (hMap.Zoom - c[hMap.Zoom - 1])) |
− | .Center.Lon += ((mx ^ 0) * mx) / (( | + | .Center.Lon += ((mx ^ 0) * mx) / ((hMap.Zoom * 10) / (hMap.Zoom - c[hMap.Zoom - 1])) |
End With | End With | ||
Riga 137: | Riga 75: | ||
'''Public''' Sub DrawingArea1_MouseDown() | '''Public''' Sub DrawingArea1_MouseDown() | ||
− | pt = | + | pt = Point(Mouse.X, Mouse.Y) |
− | x = | + | |
− | y = | + | Me.Text = "Lat. " & Format(hMap.PixelToMapPointRel(pt).Lat, "0.000000") & |
− | + | " Lon. " & Format(hMap.PixelToMapPointRel(pt).Lon, "0.000000") & | |
− | + | " - Zoom: " & CStr(hMap.Zoom) | |
+ | |||
+ | x = pt.X | ||
+ | y = pt.Y | ||
+ | |||
'''End''' | '''End''' | ||
− | '''Public''' Sub | + | '''Public''' Sub DrawingArea1_MouseWheel() |
+ | |||
+ | pt = Point(Mouse.X, Mouse.Y) | ||
+ | mp.Lat = hMap.PixelToMapPointRel(pt).Lat | ||
+ | mp.Lon = hMap.PixelToMapPointRel(pt).Lon | ||
− | + | If Mouse.Delta > 0 Then | |
− | + | hMap.Zoom += 1 | |
− | If Mouse. | + | Else |
− | + | hMap.Zoom -= 1 | |
− | |||
− | |||
Endif | Endif | ||
− | + | Me.Text = "Zoom: " & CStr(hMap.Zoom) | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
'''End''' | '''End''' | ||
− | |||
Riga 171: | Riga 106: | ||
---- | ---- | ||
=Note= | =Note= | ||
− | [1] Qualora la mappa non appaia, verificare la versione GoogleMap, ed eventualmente modificarla in questo punto: ["version": " | + | [1] Qualora la mappa non appaia, verificare la versione GoogleMap, ed eventualmente modificarla in questo punto: ["version": "900"] |
<BR>Al riguardo vedere: [[Conoscere_la_versione_più_recente_di_Google_Maps_satellite|Conoscere la versione più recente di Google Maps satellite]] | <BR>Al riguardo vedere: [[Conoscere_la_versione_più_recente_di_Google_Maps_satellite|Conoscere la versione più recente di Google Maps satellite]] |
Versione delle 09:03, 24 apr 2021
Mostreremo di seguito un semplice codice esemplificativo, nel quale si farà uso di una DrawingArea anziché dell'oggetto MapView.
Bisognerà ovviamente attivare il Componente gb.map . [Nota 1]
Private DrawingArea1 As DrawingArea Private hMap As New Map Private x As Integer Private y As Integer Private mp As MapPoint Private pt As New Point Public Sub _New() With hMap .AddTile("GoogleMaps", "https://khms{s}.google.it/kh/v={version}&src=app&x={x}&y={y}&z={z}&s=Galile", ["version": "900"]).SubDomains = ["0", "1", "2"] mp = MapPoint(35.864483, 12.867534) .Center = mp End With With Me .W = Desktop.W .H = Desktop.H .Arrangement = Arrange.Fill End With With DrawingArea1 = New DrawingArea(Me) As "DrawingArea1" .X = 0 .Y = 0 End With End Public Sub Form_Open() hMap.Zoom = 6 Me.Text = "Zoom: " & CStr(6) End Public Sub DrawingArea1_Draw() With hMap .Width = Paint.W .Height = Paint.H .Center = mp .Draw() End With DrawingArea1.Refresh() End Public Sub DrawingArea1_MouseMove() Dim c As New Single[18] Dim mx, my As Short c = [0, 0, 0, 0, 0, 5, 6.4, 7.6, 8.8, 9.9, 10.9, 11.9, 12.94, 13.96, 14.98, 15.98, 16.99, 17.994] mx = (x - Mouse.X) my = (y - Mouse.Y) With hMap .Center.Lat -= ((my ^ 0) * my) / ((hMap.Zoom * 10) / (hMap.Zoom - c[hMap.Zoom - 1])) .Center.Lon += ((mx ^ 0) * mx) / ((hMap.Zoom * 10) / (hMap.Zoom - c[hMap.Zoom - 1])) End With x = Mouse.X y = Mouse.Y End Public Sub DrawingArea1_MouseDown() pt = Point(Mouse.X, Mouse.Y) Me.Text = "Lat. " & Format(hMap.PixelToMapPointRel(pt).Lat, "0.000000") & " Lon. " & Format(hMap.PixelToMapPointRel(pt).Lon, "0.000000") & " - Zoom: " & CStr(hMap.Zoom) x = pt.X y = pt.Y End Public Sub DrawingArea1_MouseWheel()
pt = Point(Mouse.X, Mouse.Y) mp.Lat = hMap.PixelToMapPointRel(pt).Lat mp.Lon = hMap.PixelToMapPointRel(pt).Lon If Mouse.Delta > 0 Then hMap.Zoom += 1 Else hMap.Zoom -= 1 Endif Me.Text = "Zoom: " & CStr(hMap.Zoom) End
Note
[1] Qualora la mappa non appaia, verificare la versione GoogleMap, ed eventualmente modificarla in questo punto: ["version": "900"]
Al riguardo vedere: Conoscere la versione più recente di Google Maps satellite