Differenze tra le versioni di "Utilizzare una DrawingArea con gb.map anziché una MapView"

Da Gambas-it.org - Wikipedia.
 
(5 versioni intermedie di uno stesso utente non sono mostrate)
Riga 1: Riga 1:
Mostreremo di seguito un semplice codice esemplificativo, nel quale si farà uso di una ''DrawingArea'' anziché dell'oggetto ''MapView''.
+
#REDIRECT [[Utilizzare_una_DrawingArea_o_una_ImageView_con_gb.map_anziché_una_MapView]]
 
 
Bisognerà ovviamente attivare il Componente ''gb.map'' . <SUP>&#091;[[#Note|Nota 1]]&#093;</sup>
 
Private DrawingArea1 As DrawingArea
 
Private hMap As New Map   
 
Private x As Integer
 
Private y As Integer
 
Private mp As New MapPoint(35.864483, 12.867534)
 
Private pt As New Point
 
 
 
 
 
'''Public''' Sub _New()   
 
 
 
  With hMap
 
    .AddTile("GoogleMaps", "https&#058;//khms{s}.google.it/kh/v={version}&src=app&x={x}&y={y}&z={z}&s=Galile", ["version": "900"]).SubDomains = ["0", "1", "2"]
 
    .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"]
 
<BR>Al riguardo vedere: [[Conoscere_la_versione_più_recente_di_Google_Maps_satellite|Conoscere la versione più recente di Google Maps satellite]]
 

Versione attuale delle 22:33, 25 apr 2021