@@ -64,6 +64,8 @@ class GisVisualization
6464 /** The height of the GIS visualization. */
6565 private int $ height ;
6666
67+ private int $ border ;
68+
6769 private string $ spatialColumn ;
6870
6971 private string $ labelColumn ;
@@ -153,11 +155,11 @@ private function __construct(
153155 private int $ pos = 0 ,
154156 ) {
155157 $ this ->width = $ options ->width ;
156-
157158 $ this ->height = $ options ->height ;
158159
159- $ this ->spatialColumn = $ options ->spatialColumn ;
160+ $ this ->border = $ options ->border ;
160161
162+ $ this ->spatialColumn = $ options ->spatialColumn ;
161163 $ this ->labelColumn = $ options ->labelColumn ;
162164
163165 $ this ->data = is_string ($ sqlOrData )
@@ -378,24 +380,29 @@ public function asOl(): array
378380 */
379381 public function toFileAsPdf (string $ fileName ): void
380382 {
381- // create pdf
382- $ pdf = new TCPDF ('' , 'pt ' , Config::getInstance ()->config ->PDFDefaultPageSize , true , 'UTF-8 ' , false );
383+ $ fileName = $ this ->sanitizeName ($ fileName , 'pdf ' );
384+ $ pdf = $ this ->createPdf (Config::getInstance ()->config ->PDFDefaultPageSize ?? 'A4 ' );
385+ $ this ->prepareDataSet ($ this ->data , 'pdf ' , $ pdf );
386+
387+ $ pdf ->Output ($ fileName , 'D ' );
388+ }
383389
384- // disable header and footer
390+ private function createPdf (string $ format ): TCPDF
391+ {
392+ $ pdf = new TCPDF (
393+ orientation: 'P ' ,
394+ unit: 'mm ' ,
395+ format: $ format ,
396+ unicode: true ,
397+ encoding: 'UTF-8 ' ,
398+ diskcache: false ,
399+ );
385400 $ pdf ->setPrintHeader (false );
386401 $ pdf ->setPrintFooter (false );
387-
388- //set auto page breaks
389402 $ pdf ->setAutoPageBreak (false );
390-
391- // add a page
392403 $ pdf ->AddPage ();
393404
394- $ this ->prepareDataSet ($ this ->data , 'pdf ' , $ pdf );
395-
396- // sanitize file name
397- $ fileName = $ this ->sanitizeName ($ fileName , 'pdf ' );
398- $ pdf ->Output ($ fileName , 'D ' );
405+ return $ pdf ;
399406 }
400407
401408 /**
@@ -444,11 +451,9 @@ private function scaleDataSet(array $data): ScaleData|null
444451 return null ;
445452 }
446453
447- $ border = 15 ;
448-
449454 // effective width and height of the plot
450- $ plotWidth = $ this ->width - 2 * $ border ;
451- $ plotHeight = $ this ->height - 2 * $ border ;
455+ $ plotWidth = $ this ->width - 2 * $ this -> border ;
456+ $ plotHeight = $ this ->height - 2 * $ this -> border ;
452457
453458 // scale the visualization
454459 $ xRatio = ($ extent ->maxX - $ extent ->minX ) / $ plotWidth ;
@@ -460,10 +465,10 @@ private function scaleDataSet(array $data): ScaleData|null
460465 // Center plot
461466 $ x = $ ratio === 0.0 || $ xRatio < $ yRatio
462467 ? ($ extent ->maxX + $ extent ->minX - $ this ->width / $ scale ) / 2
463- : $ extent ->minX - ($ border / $ scale );
468+ : $ extent ->minX - ($ this -> border / $ scale );
464469 $ y = $ ratio === 0.0 || $ xRatio >= $ yRatio
465470 ? ($ extent ->maxY + $ extent ->minY - $ this ->height / $ scale ) / 2
466- : $ extent ->minY - ($ border / $ scale );
471+ : $ extent ->minY - ($ this -> border / $ scale );
467472
468473 return new ScaleData (scale: $ scale , offsetX: $ x , offsetY: $ y , height: $ this ->height );
469474 }
0 commit comments