Fix polyline support.
This commit is contained in:
parent
67153fccee
commit
9eb4c3b3c2
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace StaticMapLite\ElementPrinter\Polyline;
|
namespace StaticMapLite\ElementPrinter\Polyline;
|
||||||
|
|
||||||
|
use Imagine\Image\Point;
|
||||||
use StaticMapLite\Canvas\Canvas;
|
use StaticMapLite\Canvas\Canvas;
|
||||||
use StaticMapLite\Element\Polyline\Polyline;
|
use StaticMapLite\Element\Polyline\Polyline;
|
||||||
use StaticMapLite\Util;
|
use StaticMapLite\Util;
|
||||||
@ -25,41 +26,47 @@ class PolylinePrinter
|
|||||||
|
|
||||||
public function paint(Canvas $canvas): PolylinePrinter
|
public function paint(Canvas $canvas): PolylinePrinter
|
||||||
{
|
{
|
||||||
$polylineList = \Polyline::decode($this->polyline->getPolyline());
|
$pointList = $this->convertPolylineToPointList($canvas);
|
||||||
|
|
||||||
$sourceLatitude = null;
|
$color = $canvas->getImage()->palette()->color('f00');
|
||||||
$sourceLongitude = null;
|
|
||||||
$destinationLatitude = null;
|
|
||||||
$destinationLongitude = null;
|
|
||||||
|
|
||||||
$color = imagecolorallocate($canvas->getImage(), $this->polyline->getColorRed(), $this->polyline->getColorGreen(), $this->polyline->getColorBlue());
|
$startPoint = null;
|
||||||
imagesetthickness($canvas->getImage(), 5);
|
$endPoint = null;
|
||||||
//imageantialias($this->image, true);
|
|
||||||
|
|
||||||
while (!empty($polylineList)) {
|
while (!empty($pointList)) {
|
||||||
if (!$sourceLatitude) {
|
if (!$startPoint) {
|
||||||
$sourceLatitude = array_shift($polylineList);
|
$startPoint = array_pop($pointList);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$sourceLongitude) {
|
$endPoint = array_pop($pointList);
|
||||||
$sourceLongitude = array_shift($polylineList);
|
|
||||||
|
$canvas->getImage()->draw()->line($startPoint, $endPoint, $color, 3);
|
||||||
|
|
||||||
|
$startPoint = $endPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sourceX = floor(($canvas->getWidth() / 2) - $canvas->getTileSize() * ($canvas->getCenterX() - Util::lonToTile($sourceLongitude, $canvas->getZoom())));
|
|
||||||
$sourceY = floor(($canvas->getHeight() / 2) - $canvas->getTileSize() * ($canvas->getCenterY() - Util::latToTile($sourceLatitude, $canvas->getZoom())));
|
|
||||||
|
|
||||||
$destinationLatitude = array_shift($polylineList);
|
|
||||||
$destinationLongitude = array_shift($polylineList);
|
|
||||||
|
|
||||||
$destinationX = floor(($canvas->getWidth() / 2) - $canvas->getTileSize() * ($canvas->getCenterX() - Util::lonToTile($destinationLongitude, $canvas->getZoom())));
|
|
||||||
$destinationY = floor(($canvas->getHeight() / 2) - $canvas->getTileSize() * ($canvas->getCenterY() - Util::latToTile($destinationLatitude, $canvas->getZoom())));
|
|
||||||
|
|
||||||
imageline($canvas->getImage() , $sourceX, $sourceY , $destinationX, $destinationY, $color);
|
|
||||||
|
|
||||||
$sourceLatitude = $destinationLatitude;
|
|
||||||
$sourceLongitude = $destinationLongitude;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function convertPolylineToPointList(Canvas $canvas): array
|
||||||
|
{
|
||||||
|
$polylineList = \Polyline::decode($this->polyline->getPolyline());
|
||||||
|
|
||||||
|
$pointList = [];
|
||||||
|
|
||||||
|
while (!empty($polylineList)) {
|
||||||
|
$latitude = array_shift($polylineList);
|
||||||
|
$longitude = array_shift($polylineList);
|
||||||
|
|
||||||
|
$sourceX = floor(($canvas->getWidth() / 2) - $canvas->getTileSize() * ($canvas->getCenterX() - Util::lonToTile($longitude, $canvas->getZoom())));
|
||||||
|
$sourceY = floor(($canvas->getHeight() / 2) - $canvas->getTileSize() * ($canvas->getCenterY() - Util::latToTile($latitude, $canvas->getZoom())));
|
||||||
|
|
||||||
|
$point = new Point($sourceX, $sourceY);
|
||||||
|
|
||||||
|
$pointList[] = $point;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $pointList;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user