Differenze tra le versioni di "Utilizzare una DrawingArea con gb.map anziché una MapView"
Da Gambas-it.org - Wikipedia.
(Creata pagina con 'Mostreremo di seguito un semplice codice esemplificativo, nel quale si farà uso di una ''DrawingArea'' anziché ddell'oggetto ''MapView'' per mostrare la mappa di "''openstre...') |
|||
Riga 1: | Riga 1: | ||
− | Mostreremo di seguito un semplice codice esemplificativo, nel quale si farà uso di una ''DrawingArea'' anziché ddell'oggetto ''MapView'' | + | Mostreremo di seguito un semplice codice esemplificativo, nel quale si farà uso di una ''DrawingArea'' anziché ddell'oggetto ''MapView''. |
− | Bisognerà porre sul ''Form'' una ''DrawingArea'', uno ''Slider'' ed un ''ValueBox'' per lo zoom. Si dovrà, inoltre, attivare il | + | Bisognerà porre sul ''Form'' una ''DrawingArea'', uno ''Slider'' ed un ''ValueBox'' per lo zoom. Si dovrà, inoltre, attivare il Componenti ''gb.map'' e ''gb.qt5'' . |
Private hMap As New Map | Private hMap As New Map | ||
− | Private x As | + | Private x As Integer |
− | Private | + | Private y As Integer |
− | + | Private mp As MapPoint | |
− | + | Private pt As New Point | |
+ | Private initium As Boolean | ||
+ | |||
+ | |||
'''Public''' Sub _New() | '''Public''' Sub _New() | ||
− | + | ||
− | With hMap.AddTile(" | + | With hMap |
− | . | + | .AddTile("GoogleMaps", "https://khms{s}.google.it/kh/v={version}&src=app&x={x}&y={y}&z={z}&s=Galile", ["version": "800"]).SubDomains = ["0", "1", "2"] |
− | End With | + | mp = MapPoint(34.976001513175, 13.3154296875) |
− | + | .Center = mp | |
+ | .Center.Lat = 37 | ||
+ | .Center.Lon = 14 | ||
+ | End With | ||
+ | With Me | ||
+ | .W = Desktop.W | ||
+ | .H = Desktop.H | ||
+ | End With | ||
+ | With DrawingArea1 | ||
+ | .X = Me.W * 0.007 | ||
+ | .Y = Me.H * 0.01 | ||
+ | .W = Me.W * 0.96 | ||
+ | .H = Me.H * 0.95 | ||
+ | End With | ||
+ | With LCDLabel1 | ||
+ | .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 | ||
+ | |||
'''End''' | '''End''' | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | '''Public''' Sub Form_Open() | |
− | + | ||
− | + | With Slider1 | |
− | + | .X = Me.W * 0.975 | |
− | + | .Y = Me.H * 0.07 | |
− | With Slider1 | + | .Value = 6 |
− | .X = Me.W | + | .MaxValue = 18 |
− | .Y = | + | .MinValue = 6 |
− | .Value = | ||
− | .MaxValue = 18 | ||
− | .MinValue = | ||
End With | End With | ||
− | + | ||
hMap.Zoom = Slider1.Value | hMap.Zoom = Slider1.Value | ||
+ | |||
+ | DrawingArea1.Refresh() | ||
− | + | '''End''' | |
− | + | ||
− | + | ||
− | + | '''Public''' Sub DrawingArea1_Draw() | |
− | + | ||
− | + | Dim lat, lon As Float | |
− | + | ||
− | + | With hMap | |
− | + | .Width = Paint.W | |
− | + | .Height = Paint.H | |
− | + | .Draw() | |
− | + | End With | |
− | '''End''' | + | |
− | + | lat = hMap.PixelToMapPointRel(pt).Lat | |
− | + | lon = hMap.PixelToMapPointRel(pt).Lon | |
− | '''Public''' Sub DrawingArea1_Draw() | + | |
− | + | If initium Then | |
− | With hMap | + | With Paint |
− | .Width = | + | .Brush = Paint.Color(Color.Red) |
− | .Height = | + | .Font.Size = 16 |
− | .Draw() | + | .Ellipse(x - 1, y - 1, 4, 4) |
− | End With | + | .Font.Size = 8 |
− | + | .Text(" " & Geo.DecToSex(lat, 1) & "\n " & Geo.DecToSex(lon, 2), x, y, 120, 20) | |
− | + | .Fill | |
− | + | .End | |
− | + | End With | |
− | + | Endif | |
− | + | ||
− | + | DrawingArea1.Refresh() | |
− | + | ||
− | + | '''End''' | |
− | |||
− | |||
− | |||
− | '''End''' | ||
'''Public''' Sub DrawingArea1_MouseMove() | '''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 | With hMap | ||
− | .Center.Lat = | + | .Center.Lat -= ((my ^ 0) * my) / ((Slider1.Value * 10) / (Slider1.Value - c[Slider1.Value - 1])) |
− | .Center.Lon = | + | .Center.Lon += ((mx ^ 0) * mx) / ((Slider1.Value * 10) / (Slider1.Value - c[Slider1.Value - 1])) |
− | End With | + | End With |
x = Mouse.X | x = Mouse.X | ||
y = Mouse.Y | y = Mouse.Y | ||
− | DrawingArea1.Refresh() | + | DrawingArea1.Refresh() |
− | + | ||
− | '''End''' | + | '''End''' |
'''Public''' Sub DrawingArea1_MouseDown() | '''Public''' Sub DrawingArea1_MouseDown() | ||
+ | |||
+ | pt = pt(Mouse.X, Mouse.Y) | ||
x = Mouse.X | x = Mouse.X | ||
y = Mouse.Y | y = Mouse.Y | ||
+ | |||
+ | initium = True | ||
+ | |||
+ | '''End''' | ||
+ | |||
+ | '''Public''' Sub Slider1_Change() | ||
+ | |||
+ | hMap.Zoom = Slider1.Value | ||
+ | LCDLabel1.Value = Slider1.Value | ||
+ | initium = False | ||
+ | |||
+ | '''End''' | ||
+ | |||
+ | '''Public''' Sub DrawingArea1_MouseUp() | ||
+ | |||
+ | pt = pt(Mouse.X, Mouse.Y) | ||
+ | mp = MapPoint(hMap.PixelToMapPointRel(pt).Lat, hMap.PixelToMapPointRel(pt).Lon) | ||
+ | '''End''' | ||
+ | |||
+ | |||
+ | '''Public''' Sub Form_Close() | ||
+ | |||
+ | Quit | ||
+ | |||
'''End''' | '''End''' |
Versione delle 08:48, 11 ago 2018
Mostreremo di seguito un semplice codice esemplificativo, nel quale si farà uso di una DrawingArea anziché ddell'oggetto MapView.
Bisognerà porre sul Form una DrawingArea, uno Slider ed un ValueBox per lo zoom. Si dovrà, inoltre, attivare il Componenti gb.map e gb.qt5 .
Private hMap As New Map Private x As Integer Private y As Integer Private mp As MapPoint Private pt As New Point Private initium As Boolean 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": "800"]).SubDomains = ["0", "1", "2"] mp = MapPoint(34.976001513175, 13.3154296875) .Center = mp .Center.Lat = 37 .Center.Lon = 14 End With With Me .W = Desktop.W .H = Desktop.H End With With DrawingArea1 .X = Me.W * 0.007 .Y = Me.H * 0.01 .W = Me.W * 0.96 .H = Me.H * 0.95 End With With LCDLabel1 .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 End Public Sub Form_Open() With Slider1 .X = Me.W * 0.975 .Y = Me.H * 0.07 .Value = 6 .MaxValue = 18 .MinValue = 6 End With hMap.Zoom = Slider1.Value DrawingArea1.Refresh() End Public Sub DrawingArea1_Draw() Dim lat, lon As Float With hMap .Width = Paint.W .Height = Paint.H .Draw() End With lat = hMap.PixelToMapPointRel(pt).Lat lon = hMap.PixelToMapPointRel(pt).Lon If initium Then With Paint .Brush = Paint.Color(Color.Red) .Font.Size = 16 .Ellipse(x - 1, y - 1, 4, 4) .Font.Size = 8 .Text(" " & Geo.DecToSex(lat, 1) & "\n " & Geo.DecToSex(lon, 2), x, y, 120, 20) .Fill .End End With Endif 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) / ((Slider1.Value * 10) / (Slider1.Value - c[Slider1.Value - 1])) .Center.Lon += ((mx ^ 0) * mx) / ((Slider1.Value * 10) / (Slider1.Value - c[Slider1.Value - 1])) End With x = Mouse.X y = Mouse.Y DrawingArea1.Refresh() End Public Sub DrawingArea1_MouseDown() pt = pt(Mouse.X, Mouse.Y) x = Mouse.X y = Mouse.Y initium = True End Public Sub Slider1_Change() hMap.Zoom = Slider1.Value LCDLabel1.Value = Slider1.Value initium = False End Public Sub DrawingArea1_MouseUp() pt = pt(Mouse.X, Mouse.Y) mp = MapPoint(hMap.PixelToMapPointRel(pt).Lat, hMap.PixelToMapPointRel(pt).Lon) End Public Sub Form_Close() Quit End