From 653b6c187777fb7741520501b519bac114513a49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malte=20Hu=CC=88bner?= Date: Sat, 30 Sep 2017 19:45:24 +0200 Subject: [PATCH] WIP. --- .../Marker/ExtraMarkerPrinter.php | 53 +++++++++++++++++++ src/ElementPrinter/Marker/MarkerPrinter.php | 27 +--------- src/Printer.php | 3 +- web/staticmap.php | 1 - 4 files changed, 57 insertions(+), 27 deletions(-) create mode 100644 src/ElementPrinter/Marker/ExtraMarkerPrinter.php diff --git a/src/ElementPrinter/Marker/ExtraMarkerPrinter.php b/src/ElementPrinter/Marker/ExtraMarkerPrinter.php new file mode 100644 index 0000000..10b7732 --- /dev/null +++ b/src/ElementPrinter/Marker/ExtraMarkerPrinter.php @@ -0,0 +1,53 @@ +marker = $marker; + + return $this; + } + + public function paint(Canvas $canvas): ExtraMarkerPrinter + { + $extramarkersImgUrl = __DIR__.'/../../../images/extramarkers.png'; + $extramarkers = imagecreatefrompng($extramarkersImgUrl); + + $markerImage = imagecreatetruecolor(75, 100); + $trans_colour = imagecolorallocatealpha($markerImage, 0, 0, 0, 127); + imagefill($markerImage, 0, 0, $trans_colour); + + $destX = floor(($canvas->getWidth() / 2) - $canvas->getTileSize() * ($canvas->getCenterX() - Util::lonToTile($this->marker->getLongitude(), $canvas->getZoom()))); + $destY = floor(($canvas->getHeight() / 2) - $canvas->getTileSize() * ($canvas->getCenterY() - Util::latToTile($this->marker->getLatitude(), $canvas->getZoom()))); + + $markerWidth = imagesx($markerImage); + $markerHeight = imagesy($markerImage); + + $destX -= $markerWidth / 2; + $destY -= $markerHeight; + + + imagecopy($markerImage, $extramarkers, 0, 0, 0, 0, $markerWidth, $markerHeight); + + imagecopy($canvas->getImage(), $markerImage, $destX, $destY, 0, 0, imagesx($markerImage), imagesy($markerImage)); + + return $this; + } +} diff --git a/src/ElementPrinter/Marker/MarkerPrinter.php b/src/ElementPrinter/Marker/MarkerPrinter.php index 1a3af80..c22227f 100644 --- a/src/ElementPrinter/Marker/MarkerPrinter.php +++ b/src/ElementPrinter/Marker/MarkerPrinter.php @@ -3,6 +3,7 @@ namespace StaticMapLite\ElementPrinter\Marker; use StaticMapLite\Canvas\Canvas; +use StaticMapLite\Element\Marker\AbstractMarker; use StaticMapLite\Element\Marker\ExtraMarker; use StaticMapLite\Element\Marker\Marker; use StaticMapLite\Util; @@ -50,37 +51,13 @@ class MarkerPrinter } - public function setMarker(Marker $marker): MarkerPrinter + public function setMarker(AbstractMarker $marker): MarkerPrinter { $this->marker = $marker; return $this; } - /** - public function placeExtraMarker(ExtraMarker $extraMarker) - { - $extramarkers = imagecreatefrompng($this->markerBaseDir . '/../extramarkers.png'); - - $markerImage = imagecreatetruecolor(75, 100); - $trans_colour = imagecolorallocatealpha($markerImage, 0, 0, 0, 127); - imagefill($markerImage, 0, 0, $trans_colour); - - $destX = floor(($this->width / 2) - $this->tileSize * ($this->centerX - Util::lonToTile($extraMarker->getLongitude(), $this->zoom))); - $destY = floor(($this->height / 2) - $this->tileSize * ($this->centerY - Util::latToTile($extraMarker->getLatitude(), $this->zoom))); - - $markerWidth = imagesx($markerImage); - $markerHeight = imagesy($markerImage); - - $destX -= $markerWidth / 2; - $destY -= $markerHeight; - - - imagecopy($markerImage, $extramarkers, 0, 0, 0, 0, $markerWidth, $markerHeight); - - imagecopy($this->canvas->getImage(), $markerImage, $destX, $destY, 0, 0, imagesx($markerImage), imagesy($markerImage)); - } -**/ public function paint(Canvas $canvas): MarkerPrinter { $markerFilename = ''; diff --git a/src/Printer.php b/src/Printer.php index d48ff85..5c628af 100644 --- a/src/Printer.php +++ b/src/Printer.php @@ -6,6 +6,7 @@ use StaticMapLite\Canvas\Canvas; use StaticMapLite\CanvasTilePainter\CanvasTilePainter; use StaticMapLite\Element\Marker\AbstractMarker; use StaticMapLite\Element\Polyline\Polyline; +use StaticMapLite\ElementPrinter\Marker\ExtraMarkerPrinter; use StaticMapLite\ElementPrinter\Marker\MarkerPrinter; use StaticMapLite\ElementPrinter\Polyline\PolylinePrinter; use StaticMapLite\TileResolver\CachedTileResolver; @@ -148,7 +149,7 @@ class Printer public function placeMarkers() { - $printer = new MarkerPrinter(); + $printer = new ExtraMarkerPrinter(); foreach ($this->markers as $marker) { $printer diff --git a/web/staticmap.php b/web/staticmap.php index 30d3ac0..b4c519e 100644 --- a/web/staticmap.php +++ b/web/staticmap.php @@ -28,7 +28,6 @@ require_once '../vendor/autoload.php'; use StaticMapLite\Element\Marker\ExtraMarker; -use StaticMapLite\Element\Marker\Marker; use StaticMapLite\Element\Polyline\Polyline; use StaticMapLite\Printer;