Add Polyline object.

This commit is contained in:
Malte Hübner 2017-05-26 17:28:30 +02:00
parent 5bbf9c6283
commit aae0ada3c6
2 changed files with 51 additions and 18 deletions

View File

@ -0,0 +1,40 @@
<?php
namespace StaticMapLite\Element\Polyline;
class Polyline
{
protected $polyline = null;
protected $colorRed = 0;
protected $colorGreen = 0;
protected $colorBlue = 0;
public function __construct(string $polyline, int $colorRed, int $colorGreen, int $colorBlue)
{
$this->polyline = $polyline;
$this->colorRed = $colorRed;
$this->colorGreen = $colorGreen;
$this->colorBlue = $colorBlue;
}
public function getPolyline(): string
{
return $this->polyline;
}
public function getColorRed(): int
{
return $this->colorRed;
}
public function getColorGreen(): int
{
return $this->colorGreen;
}
public function getColorBlue(): int
{
return $this->colorBlue;
}
}

View File

@ -4,6 +4,7 @@ namespace StaticMapLite;
use StaticMapLite\Canvas\Canvas; use StaticMapLite\Canvas\Canvas;
use StaticMapLite\Element\Marker\Marker; use StaticMapLite\Element\Marker\Marker;
use StaticMapLite\Element\Polyline\Polyline;
use StaticMapLite\TileResolver\CachedTileResolver; use StaticMapLite\TileResolver\CachedTileResolver;
class Printer class Printer
@ -34,29 +35,29 @@ class Printer
'extension' => '.png', 'extension' => '.png',
'shadow' => false, 'shadow' => false,
'offsetImage' => '0,-19', 'offsetImage' => '0,-19',
'offsetShadow' => false 'offsetShadow' => false,
), ),
// openlayers std markers // openlayers std markers
'ol-marker' => array('regex' => '/^ol-marker(|-blue|-gold|-green)+$/', 'ol-marker' => array('regex' => '/^ol-marker(|-blue|-gold|-green)+$/',
'extension' => '.png', 'extension' => '.png',
'shadow' => '../marker_shadow.png', 'shadow' => '../marker_shadow.png',
'offsetImage' => '-10,-25', 'offsetImage' => '-10,-25',
'offsetShadow' => '-1,-13' 'offsetShadow' => '-1,-13',
), ),
// taken from http://www.visual-case.it/cgi-bin/vc/GMapsIcons.pl // taken from http://www.visual-case.it/cgi-bin/vc/GMapsIcons.pl
'ylw' => array('regex' => '/^(pink|purple|red|ltblu|ylw)-pushpin$/', 'ylw' => array('regex' => '/^(pink|purple|red|ltblu|ylw)-pushpin$/',
'extension' => '.png', 'extension' => '.png',
'shadow' => '../marker_shadow.png', 'shadow' => '../marker_shadow.png',
'offsetImage' => '-10,-32', 'offsetImage' => '-10,-32',
'offsetShadow' => '-1,-13' 'offsetShadow' => '-1,-13',
), ),
// http://svn.openstreetmap.org/sites/other/StaticMap/symbols/0.png // http://svn.openstreetmap.org/sites/other/StaticMap/symbols/0.png
'ojw' => array('regex' => '/^bullseye$/', 'ojw' => array('regex' => '/^bullseye$/',
'extension' => '.png', 'extension' => '.png',
'shadow' => false, 'shadow' => false,
'offsetImage' => '-20,-20', 'offsetImage' => '-20,-20',
'offsetShadow' => false 'offsetShadow' => false,
) ),
); );
@ -95,11 +96,9 @@ class Printer
return $this; return $this;
} }
public function addPolyline(string $polylineString, int $colorRed, int $colorGreen, int $colorBlue): Printer public function addPolyline(Polyline $polyline): Printer
{ {
$polyline = ['polyline' => $polylineString, 'colorRed' => $colorRed, 'colorGreen' => $colorGreen, 'colorBlue' => $colorBlue]; $this->polylines[] = $polyline;
array_push($this->polylines, $polyline);
return $this; return $this;
} }
@ -253,22 +252,16 @@ class Printer
public function placePolylines() public function placePolylines()
{ {
// loop thru marker array /** @var Polyline $polyline */
foreach ($this->polylines as $polyline) { foreach ($this->polylines as $polyline) {
// set some local variables $polylineList = \Polyline::decode($polyline->getPolyline());
$polylineString = $polyline['polyline'];
$colorRed = $polyline['colorRed'];
$colorGreen = $polyline['colorGreen'];
$colorBlue = $polyline['colorBlue'];
$polylineList = \Polyline::decode($polylineString);
$sourceLatitude = null; $sourceLatitude = null;
$sourceLongitude = null; $sourceLongitude = null;
$destinationLatitude = null; $destinationLatitude = null;
$destinationLongitude = null; $destinationLongitude = null;
$color = imagecolorallocate($this->canvas->getImage(), $colorRed, $colorGreen, $colorBlue); $color = imagecolorallocate($this->canvas->getImage(), $polyline->getColorRed(), $polyline->getColorGreen(), $polyline->getColorBlue());
imagesetthickness($this->image, 3); imagesetthickness($this->image, 3);
//imageantialias($this->image, true); //imageantialias($this->image, true);