This commit is contained in:
Malte Hübner 2017-09-30 19:45:24 +02:00
parent 233b291df8
commit 653b6c1877
4 changed files with 57 additions and 27 deletions

View File

@ -0,0 +1,53 @@
<?php
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;
class ExtraMarkerPrinter
{
/** @var Marker $marker */
protected $marker = null;
public function __construct()
{
}
public function setMarker(AbstractMarker $marker): ExtraMarkerPrinter
{
$this->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;
}
}

View File

@ -3,6 +3,7 @@
namespace StaticMapLite\ElementPrinter\Marker; namespace StaticMapLite\ElementPrinter\Marker;
use StaticMapLite\Canvas\Canvas; use StaticMapLite\Canvas\Canvas;
use StaticMapLite\Element\Marker\AbstractMarker;
use StaticMapLite\Element\Marker\ExtraMarker; use StaticMapLite\Element\Marker\ExtraMarker;
use StaticMapLite\Element\Marker\Marker; use StaticMapLite\Element\Marker\Marker;
use StaticMapLite\Util; use StaticMapLite\Util;
@ -50,37 +51,13 @@ class MarkerPrinter
} }
public function setMarker(Marker $marker): MarkerPrinter public function setMarker(AbstractMarker $marker): MarkerPrinter
{ {
$this->marker = $marker; $this->marker = $marker;
return $this; 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 public function paint(Canvas $canvas): MarkerPrinter
{ {
$markerFilename = ''; $markerFilename = '';

View File

@ -6,6 +6,7 @@ use StaticMapLite\Canvas\Canvas;
use StaticMapLite\CanvasTilePainter\CanvasTilePainter; use StaticMapLite\CanvasTilePainter\CanvasTilePainter;
use StaticMapLite\Element\Marker\AbstractMarker; use StaticMapLite\Element\Marker\AbstractMarker;
use StaticMapLite\Element\Polyline\Polyline; use StaticMapLite\Element\Polyline\Polyline;
use StaticMapLite\ElementPrinter\Marker\ExtraMarkerPrinter;
use StaticMapLite\ElementPrinter\Marker\MarkerPrinter; use StaticMapLite\ElementPrinter\Marker\MarkerPrinter;
use StaticMapLite\ElementPrinter\Polyline\PolylinePrinter; use StaticMapLite\ElementPrinter\Polyline\PolylinePrinter;
use StaticMapLite\TileResolver\CachedTileResolver; use StaticMapLite\TileResolver\CachedTileResolver;
@ -148,7 +149,7 @@ class Printer
public function placeMarkers() public function placeMarkers()
{ {
$printer = new MarkerPrinter(); $printer = new ExtraMarkerPrinter();
foreach ($this->markers as $marker) { foreach ($this->markers as $marker) {
$printer $printer

View File

@ -28,7 +28,6 @@
require_once '../vendor/autoload.php'; require_once '../vendor/autoload.php';
use StaticMapLite\Element\Marker\ExtraMarker; use StaticMapLite\Element\Marker\ExtraMarker;
use StaticMapLite\Element\Marker\Marker;
use StaticMapLite\Element\Polyline\Polyline; use StaticMapLite\Element\Polyline\Polyline;
use StaticMapLite\Printer; use StaticMapLite\Printer;