Differenze tra le versioni di "Ottenere un file pdf dalla mappa mostrata da una MapView"

Da Gambas-it.org - Wikipedia.
 
Riga 7: Riga 7:
 
  Private mp As New MapPoint(41.8902142, 12.4900422)
 
  Private mp As New MapPoint(41.8902142, 12.4900422)
 
   
 
   
  '''Public''' Sub Form_Open()
+
  Public Sub Form_Open()
 
   
 
   
 
   With Me
 
   With Me
Riga 32: Riga 32:
 
   End With
 
   End With
 
   
 
   
  '''End'''
+
  End
 
   
 
   
  '''Public''' Sub MapView1_MouseUp()
+
   
 +
Public Sub MapView1_MouseUp()
 
   
 
   
 
  <FONT Color=gray>' ''Se si clicca con il tasto destro del mouse sulla mappa, si avvia la stampa su un file .pdf:''</font>
 
  <FONT Color=gray>' ''Se si clicca con il tasto destro del mouse sulla mappa, si avvia la stampa su un file .pdf:''</font>
 
   If Mouse.Right Then Printer1.Print
 
   If Mouse.Right Then Printer1.Print
 
   
 
   
  '''End'''
+
  End
 +
 
   
 
   
  '''Public''' Sub Printer1_Draw() <FONT Color=gray>' ''Esegue la stampa su un file .pdf della mappa mostrata:''</font>
+
  Public Sub Printer1_Draw() <FONT Color=gray>' ''Esegue la stampa su un file .pdf della mappa mostrata:''</font>
 
   
 
   
 
   With MapView1.Map
 
   With MapView1.Map
Riga 49: Riga 51:
 
   End With
 
   End With
 
   
 
   
  '''End'''
+
  End
  
 
===Uso delle risorse della Classe "Cairo"===
 
===Uso delle risorse della Classe "Cairo"===
Riga 56: Riga 58:
 
   
 
   
 
   
 
   
  '''Public''' Sub Form_Open()
+
  Public Sub Form_Open()
 
    
 
    
 
   With Me
 
   With Me
Riga 72: Riga 74:
 
   End With
 
   End With
 
   
 
   
  '''End'''
+
  End
 +
 
   
 
   
  '''Public''' Sub MapView1_MouseUp()
+
  Public Sub MapView1_MouseUp()
 
   
 
   
 
   If Mouse.Left Then Return  
 
   If Mouse.Left Then Return  
Riga 88: Riga 91:
 
   CreaPDF(im)
 
   CreaPDF(im)
 
   
 
   
  '''End'''
+
  End
 +
 
   
 
   
  '''Private''' Procedure CreaPDF(imago As Image)
+
  Private Procedure CreaPDF(imago As Image)
 
   
 
   
 
   Dim pdf As CairoPdfSurface
 
   Dim pdf As CairoPdfSurface
Riga 106: Riga 110:
 
   End With  
 
   End With  
 
   
 
   
  '''End'''
+
  End
  
  
  
 
=Note=
 
=Note=
[1] Riguardo alla creazione di un file pdf con la Classe "Printer", vedere anche: [[Printer#Stampare_in_un_file_.pdf_o_.ps|Stampare in un file .pdf]]
+
[1] Riguardo alla creazione di un file pdf con la Classe "Printer", vedere anche: [[Stampare_in_Gambas#Stampare_in_un_file_PDF|Stampare in un file .pdf]]

Versione attuale delle 05:24, 18 gen 2024

Per ottenere la stampa su un file PDF della mappa mostrata dalla MapView, è possibile adottare almeno un paio di modalità.

Uso delle risorse della Classe "Printer"

Mostriamo un esempio: [Nota 1]

Private MapView1 As MapView
Private Printer1 As Printer
Private mp As New MapPoint(41.8902142, 12.4900422)

Public Sub Form_Open()

 With Me
   .W = Screen.AvailableWidth
   .H = Screen.AvailableHeight
   .Arrangement = Arrange.Fill
 End With

 With MapView1 = New MapView(Me) As "MapView1"
' Imposta un "Raster Tiles Server" remoto:
   .Map.AddTile("opentopo", "https://a.tile.opentopomap.org/{z}/{x}/{y}.png")
   .Map.Zoom = 15
' Imposta il centro della mappa visualizzata specificandone preliminarmente le coordinate geografiche:
   .Map.Center = mp
 End With

 With Printer1 = New Printer As "Printer1"
   .Resolution = Desktop.Resolution
   .Paper = .A4
   .Orientation = .Landscape
' Stampa su un file .pdf (crea un file .pdf):
   .OutputFile = "/tmp/file.pdf"
   .Print
 End With

End


Public Sub MapView1_MouseUp()

' Se si clicca con il tasto destro del mouse sulla mappa, si avvia la stampa su un file .pdf:
 If Mouse.Right Then Printer1.Print

End


Public Sub Printer1_Draw() ' Esegue la stampa su un file .pdf della mappa mostrata:

 With MapView1.Map
   .Width = MapView1.W
   .Height = MapView1.H
   .Draw()
 End With

End

Uso delle risorse della Classe "Cairo"

In tal caso è necessario attivare anche il Componente "gb.cairo".

Private MapView1 As MapView


Public Sub Form_Open()
 
 With Me
   .W = (297.0 * Desktop.Resolution) / 25.4
   .H = (210.0 * Desktop.Resolution) / 25.4
   .Arrangement = Arrange.Fill
 End With

 With MapView1 = New MapView(Me) As "MapView1"
' Imposta un "Raster Tiles Server" remoto:
   .Map.AddTile("opentopo", "https://a.tile.opentopomap.org/{z}/{x}/{y}.png")
   .Map.Zoom = 15
' Imposta il centro della mappa visualizzata specificandone preliminarmente le coordinate geografiche:
   .Map.Center = New MapPoint(41.8902142, 12.4900422)
 End With

End


Public Sub MapView1_MouseUp()

 If Mouse.Left Then Return 

 Dim im As New Image(MapView1.W, MapView1.H, Color.White, Image.Standard)

 With Paint
   .Begin(im)
   MapView1.Map.Draw()
   .End
 End With

 CreaPDF(im)

End


Private Procedure CreaPDF(imago As Image)

 Dim pdf As CairoPdfSurface
 
' Specifica la superficie grafica da creare per disegnarvi sopra, dimensionandola in "millimetri":
 pdf = New CairoPdfSurface("/tmp/file.pdf", (297.0 * Desktop.Resolution) / 25.4, (210.0 * Desktop.Resolution) / 25.4)
 
' Inizia il disegno sulla superficie impostata:
 With Cairo
   .Begin(pdf)
   .Source = Cairo.ImagePattern(imago, 0, 0)
   .Paint
' Termina il disegno dell'immagine:
   .End
 End With 

End


Note

[1] Riguardo alla creazione di un file pdf con la Classe "Printer", vedere anche: Stampare in un file .pdf