From 06876513e757759764ca5945feb83e479d5eb7db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malte=20Hu=CC=88bner?= Date: Wed, 14 Feb 2018 19:37:28 +0100 Subject: [PATCH] Extract CopyrightPrinter. --- src/CopyrightPrinter/CopyrightPrinter.php | 42 +++++++++++++++ .../CopyrightPrinterInterface.php | 8 +++ src/Printer/AbstractPrinter.php | 3 -- src/Printer/Printer.php | 52 +++++++++++-------- web/staticmap.php | 2 +- 5 files changed, 80 insertions(+), 27 deletions(-) create mode 100644 src/CopyrightPrinter/CopyrightPrinter.php create mode 100644 src/CopyrightPrinter/CopyrightPrinterInterface.php diff --git a/src/CopyrightPrinter/CopyrightPrinter.php b/src/CopyrightPrinter/CopyrightPrinter.php new file mode 100644 index 0000000..086cf73 --- /dev/null +++ b/src/CopyrightPrinter/CopyrightPrinter.php @@ -0,0 +1,42 @@ +canvas = $canvas; + + return $this; + } + + public function printCopyright(): CopyrightPrinterInterface + { + $logo = imagecreatefrompng($this->osmLogo); + + $logoWidth = imagesx($logo); + $logoHeight = imagesy($logo); + + imagecopy( + $this->canvas->getImage(), + $logo, + imagesx($this->canvas->getImage()) - $logoWidth, + imagesy($this->canvas->getImage()) - $logoHeight, + 0, + 0, + $logoWidth, + $logoHeight + ); + + return $this; + } +} diff --git a/src/CopyrightPrinter/CopyrightPrinterInterface.php b/src/CopyrightPrinter/CopyrightPrinterInterface.php new file mode 100644 index 0000000..109799c --- /dev/null +++ b/src/CopyrightPrinter/CopyrightPrinterInterface.php @@ -0,0 +1,8 @@ +centerX = Util::lonToTile($this->longitude, $this->zoom); $this->centerY = Util::latToTile($this->latitude, $this->zoom); $this->offsetX = floor((floor($this->centerX) - $this->centerX) * $this->tileSize); $this->offsetY = floor((floor($this->centerY) - $this->centerY) * $this->tileSize); + + return $this; } - public function createBaseMap() + public function createBaseMap(): Printer { $this->canvas = new Canvas( $this->width, @@ -113,9 +116,11 @@ class Printer extends AbstractPrinter ->setTileResolver($this->tileResolver) ->paint() ; + + return $this; } - public function placeMarkers() + public function placeMarkers(): Printer { $printer = new ExtraMarkerPrinter(); @@ -125,9 +130,11 @@ class Printer extends AbstractPrinter ->paint($this->canvas) ; } + + return $this; } - public function placePolylines() + public function placePolylines(): Printer { $printer = new PolylinePrinter(); @@ -138,25 +145,14 @@ class Printer extends AbstractPrinter ->paint($this->canvas) ; } + + return $this; } - public function copyrightNotice() - { - $logoImg = imagecreatefrompng($this->osmLogo); - imagecopy($this->canvas->getImage(), $logoImg, imagesx($this->canvas->getImage()) - imagesx($logoImg), imagesy($this->canvas->getImage()) - imagesy($logoImg), 0, 0, imagesx($logoImg), imagesy($logoImg)); - } - public function sendHeader() - { - header('Content-Type: image/png'); - $expires = 60 * 60 * 24 * 14; - header("Pragma: public"); - header("Cache-Control: maxage=" . $expires); - header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT'); - } - - public function makeMap() + public function makeMap(): Printer { $this->initCoords(); + $this->createBaseMap(); if (count($this->polylines)) { @@ -167,9 +163,20 @@ class Printer extends AbstractPrinter $this->placeMarkers(); } - if ($this->osmLogo) { - $this->copyrightNotice(); - } + $this->printCopyright(); + + return $this; + } + + protected function printCopyright(): Printer + { + $cp = new CopyrightPrinter(); + $cp + ->setCanvas($this->canvas) + ->printCopyright() + ; + + return $this; } public function showMap() @@ -188,7 +195,6 @@ class Printer extends AbstractPrinter ; } } else { - // no cache, make map, send headers and deliver png $this->makeMap(); $output = new ImageOutput(); diff --git a/web/staticmap.php b/web/staticmap.php index ebfd411..cc42fa3 100644 --- a/web/staticmap.php +++ b/web/staticmap.php @@ -74,7 +74,7 @@ if ($polylines) { } } -print $printer->showMap(); +$printer->showMap();