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à porre sul ''Form'' una ''DrawingArea'', uno ''Slider'', un ''LCDLabel'' per lo zoom e due ''RadioButton'' per scegliere il sistema di riferimento delle coordinate, altresì attivare i Componenti ''gb.map'' e ''gb.qt5'' e ''gb.qt5.ext'' . <SUP>&#091;[[#Note|Nota 1]]&#093;</sup>
+
Bisognerà ovviamente attivare il Componente ''gb.map'' . <SUP>&#091;[[#Note|Nota 1]]&#093;</sup>
 
  Private DrawingArea1 As DrawingArea
 
  Private DrawingArea1 As DrawingArea
Private LCDLabel1 As LCDLabel
 
Private RadioButton1 As RadioButton
 
Private RadioButton2 As RadioButton
 
 
  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
Private coo As Boolean
 
 
    
 
    
 
    
 
    
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 = Me.W * 0.007
+
     .X = 0
    .Y = Me.H * 0.01
+
     .Y = 0
    .W = Me.W * 0.96
 
    .H = Me.H * 0.95
 
  End With
 
  With LCDLabel1 = New LCDLabel(Me)
 
    .X = Me.W * 0.967
 
    .Y = Me.H * 0.04
 
    .W = Me.W * 0.02
 
    .H = Me.H * 0.02
 
    .Alignment = Align.Right
 
    .Foreground = Color.Red
 
    .Font.Size = 18
 
    .Font.Bold = True
 
  End With
 
  With RadioButton1 = New RadioButton(Me)
 
    .X = Me.W * 0.97
 
    .Y = Me.H * 0.2
 
    .W = Me.W * 0.04
 
    .H = Me.H * 0.02
 
    .Text = "sess."
 
    .Value = True
 
  End With
 
  With RadioButton2 = New RadioButton(Me)
 
    .X = Me.W * 0.97
 
     .Y = RadioButton1.Y + RadioButton1.H
 
    .W = Me.W * 0.04
 
    .H = Me.H * 0.02
 
    .Text = "decm."
 
 
   End With
 
   End With
 
    
 
    
Riga 62: Riga 32:
 
  '''Public''' Sub Form_Open()
 
  '''Public''' Sub Form_Open()
 
    
 
    
  With Slider1 = New Slider(Me) As "Slider1"
+
   hMap.Zoom = 6  
    .X = Me.W * 0.975
+
   Me.Text = "Zoom: " & CStr(6)
    .Y = Me.H * 0.07
 
    .Value = 6
 
    .MaxValue = 18
 
    .MinValue = 6
 
  End With   
 
 
 
   hMap.Zoom = Slider1.Value  
 
    
 
  DrawingArea1.Refresh()
 
 
    
 
    
 
  '''End'''
 
  '''End'''
Riga 78: Riga 39:
 
    
 
    
 
  '''Public''' Sub DrawingArea1_Draw()
 
  '''Public''' Sub DrawingArea1_Draw()
 
 
  Dim lat, lon As String
 
  Dim sla, slo As String
 
 
    
 
    
 
   With hMap
 
   With hMap
 
     .Width = Paint.W
 
     .Width = Paint.W
 
     .Height = Paint.H
 
     .Height = Paint.H
 +
    .Center = mp
 
     .Draw()
 
     .Draw()
 
   End With
 
   End With
 
 
  lat = hMap.PixelToMapPointRel(pt).Lat
 
  lon = hMap.PixelToMapPointRel(pt).Lon
 
  sla = CStr(lat)
 
  slo = CStr(lon)
 
 
 
  If coo Then
 
    With Paint
 
      .Brush = Paint.Color(Color.Red)
 
      .Font.Size = 16
 
      .Ellipse(x - 1, y - 1, 4, 4)
 
      .Font.Size = 8
 
      If RadioButton1.Value Then
 
        sla = Geo.DecToSex(lat, 1)
 
        slo = Geo.DecToSex(lon, 2)
 
      Endif
 
      .Text(" " & sla & "\n " & slo, x, y, 120, 20)
 
      .Fill
 
      .End
 
    End With
 
  Endif
 
 
    
 
    
 
   DrawingArea1.Refresh()
 
   DrawingArea1.Refresh()
Riga 125: Riga 63:
 
    
 
    
 
   With hMap   
 
   With hMap   
     .Center.Lat -= ((my ^ 0) * my) / ((Slider1.Value * 10) / (Slider1.Value - c[Slider1.Value - 1]))
+
     .Center.Lat -= ((my ^ 0) * my) / ((hMap.Zoom * 10) / (hMap.Zoom - c[hMap.Zoom - 1]))
     .Center.Lon += ((mx ^ 0) * mx) / ((Slider1.Value * 10) / (Slider1.Value - c[Slider1.Value - 1]))
+
     .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(Mouse.X, Mouse.Y)
+
   pt = Point(Mouse.X, Mouse.Y)
   x = Mouse.X   
+
 
   y = Mouse.Y
+
  Me.Text = "Lat. " & Format(hMap.PixelToMapPointRel(pt).Lat, "0.000000") &
   coo = False
+
            "  Lon. " & Format(hMap.PixelToMapPointRel(pt).Lon, "0.000000") &
 
+
            "  -  Zoom: " & CStr(hMap.Zoom)
 +
 
 +
   x = pt.X   
 +
   y = pt.Y
 +
    
 
  '''End'''
 
  '''End'''
 
    
 
    
 
   
 
   
  '''Public''' Sub DrawingArea1_MouseUp()
+
  '''Public''' Sub DrawingArea1_MouseWheel()
 +
 
 +
  pt = Point(Mouse.X, Mouse.Y)
 +
  mp.Lat = hMap.PixelToMapPointRel(pt).Lat
 +
  mp.Lon = hMap.PixelToMapPointRel(pt).Lon
 
    
 
    
<FONT Color=gray>' ''Se si clicca con il tasto destro del mouse, vengono stampate sulla mappa''
+
   If Mouse.Delta > 0 Then  
' ''le coordinate geografiche del punto, ove si è cliccato:''</font>
+
     hMap.Zoom += 1
   If Mouse.Right Then
+
  Else
     pt = pt(Mouse.X, Mouse.Y)
+
     hMap.Zoom -= 1
     mp = MapPoint(hMap.PixelToMapPointRel(pt).Lat, hMap.PixelToMapPointRel(pt).Lon)
 
    coo = True
 
 
   Endif
 
   Endif
 
+
  Me.Text = "Zoom: " & CStr(hMap.Zoom)
'''End'''
 
 
 
'''Public''' Sub Slider1_Change()
 
 
 
  hMap.Zoom = Slider1.Value
 
  LCDLabel1.Value = Slider1.Value
 
  coo = False
 
 
    
 
    
 
  '''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": "894"]
+
[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