This commit is contained in:
Malte Hübner 2018-02-13 13:47:12 +01:00
parent 63f0d344ff
commit dc4cc81bbc
4 changed files with 73 additions and 287 deletions

View File

@ -2,6 +2,9 @@
namespace StaticMapLite\CanvasTilePainter;
use StaticMapLite\Canvas\Canvas;
use StaticMapLite\TileResolver\TileResolver;
interface CanvasTilePainterInterface
{
public function setCanvas(Canvas $canvas): CanvasTilePainterInterface;

View File

@ -2,21 +2,37 @@
namespace StaticMapLite\MapCache;
use StaticMapLite\Printer;
use StaticMapLite\Printer\PrinterInterface;
class MapCache
{
/** @var Printer $printer */
/** @var PrinterInterface $printer */
protected $printer;
public function __construct(Printer $printer)
{
/** @var bool $useMapCache */
protected $useMapCache = false;
/** @var string $mapCacheBaseDir */
protected $mapCacheBaseDir = '../cache/maps';
/** @var string $mapCacheID */
protected $mapCacheID = '';
/** @var string $mapCacheFile */
protected $mapCacheFile = '';
/** @var string $mapCacheExtension */
protected $mapCacheExtension = 'png';
public function __construct(PrinterInterface $printer)
{
$this->printer = $printer;
}
public function checkMapCache(): bool
{
$this->mapCacheID = md5($this->serializeParams());
$filename = $this->mapCacheIDToFilename();
return file_exists($filename);
@ -41,6 +57,9 @@ class MapCache
if (!$this->mapCacheFile) {
$this->mapCacheFile = $this->mapCacheBaseDir . "/" . $this->maptype . "/" . $this->zoom . "/cache_" . substr($this->mapCacheID, 0, 2) . "/" . substr($this->mapCacheID, 2, 2) . "/" . substr($this->mapCacheID, 4);
}
return $this->mapCacheFile . "." . $this->mapCacheExtension;
$filename = sprintf('%s.%s', $this->mapCacheFile, $this->mapCacheExtension);
return $filename;
}
}

View File

@ -39,21 +39,6 @@ abstract class AbstractPrinter
/** @var bool $useTileCache */
protected $useTileCache = true;
/** @var bool $useMapCache */
protected $useMapCache = false;
/** @var string $mapCacheBaseDir */
protected $mapCacheBaseDir = '../cache/maps';
/** @var string $mapCacheID */
protected $mapCacheID = '';
/** @var string $mapCacheFile */
protected $mapCacheFile = '';
/** @var string $mapCacheExtension */
protected $mapCacheExtension = 'png';
protected $zoom;
protected $lat;
@ -82,489 +67,267 @@ abstract class AbstractPrinter
/** @var array $polylines */
protected $polylines = [];
/**
* @return int
*/
public function getMaxWidth(): int
{
return $this->maxWidth;
}
/**
* @param int $maxWidth
* @return AbstractPrinter
*/
public function setMaxWidth(int $maxWidth): AbstractPrinter
{
$this->maxWidth = $maxWidth;
return $this;
}
/**
* @return int
*/
public function getMaxHeight(): int
{
return $this->maxHeight;
}
/**
* @param int $maxHeight
* @return AbstractPrinter
*/
public function setMaxHeight(int $maxHeight): AbstractPrinter
{
$this->maxHeight = $maxHeight;
return $this;
}
/**
* @return TileResolverInterface
*/
public function getTileResolver(): TileResolverInterface
{
return $this->tileResolver;
}
/**
* @param TileResolverInterface $tileResolver
* @return AbstractPrinter
*/
public function setTileResolver(TileResolverInterface $tileResolver): AbstractPrinter
{
$this->tileResolver = $tileResolver;
return $this;
}
/**
* @return CanvasInterface
*/
public function getCanvas(): CanvasInterface
{
return $this->canvas;
}
/**
* @param CanvasInterface $canvas
* @return AbstractPrinter
*/
public function setCanvas(CanvasInterface $canvas): AbstractPrinter
{
$this->canvas = $canvas;
return $this;
}
/**
* @return int
*/
public function getTileSize(): int
{
return $this->tileSize;
}
/**
* @param int $tileSize
* @return AbstractPrinter
*/
public function setTileSize(int $tileSize): AbstractPrinter
{
$this->tileSize = $tileSize;
return $this;
}
/**
* @return array
*/
public function getTileSrcUrl(): array
{
return $this->tileSrcUrl;
}
/**
* @param array $tileSrcUrl
* @return AbstractPrinter
*/
public function setTileSrcUrl(array $tileSrcUrl): AbstractPrinter
{
$this->tileSrcUrl = $tileSrcUrl;
return $this;
}
/**
* @return string
*/
public function getTileDefaultSrc(): string
{
return $this->tileDefaultSrc;
}
/**
* @param string $tileDefaultSrc
* @return AbstractPrinter
*/
public function setTileDefaultSrc(string $tileDefaultSrc): AbstractPrinter
{
$this->tileDefaultSrc = $tileDefaultSrc;
return $this;
}
/**
* @return string
*/
public function getOsmLogo(): string
{
return $this->osmLogo;
}
/**
* @param string $osmLogo
* @return AbstractPrinter
*/
public function setOsmLogo(string $osmLogo): AbstractPrinter
{
$this->osmLogo = $osmLogo;
return $this;
}
/**
* @return bool
*/
public function isUseTileCache(): bool
{
return $this->useTileCache;
}
/**
* @param bool $useTileCache
* @return AbstractPrinter
*/
public function setUseTileCache(bool $useTileCache): AbstractPrinter
{
$this->useTileCache = $useTileCache;
return $this;
}
/**
* @return bool
*/
public function isUseMapCache(): bool
{
return $this->useMapCache;
}
/**
* @param bool $useMapCache
* @return AbstractPrinter
*/
public function setUseMapCache(bool $useMapCache): AbstractPrinter
{
$this->useMapCache = $useMapCache;
return $this;
}
/**
* @return string
*/
public function getMapCacheBaseDir(): string
{
return $this->mapCacheBaseDir;
}
/**
* @param string $mapCacheBaseDir
* @return AbstractPrinter
*/
public function setMapCacheBaseDir(string $mapCacheBaseDir): AbstractPrinter
{
$this->mapCacheBaseDir = $mapCacheBaseDir;
return $this;
}
/**
* @return string
*/
public function getMapCacheID(): string
{
return $this->mapCacheID;
}
/**
* @param string $mapCacheID
* @return AbstractPrinter
*/
public function setMapCacheID(string $mapCacheID): AbstractPrinter
{
$this->mapCacheID = $mapCacheID;
return $this;
}
/**
* @return string
*/
public function getMapCacheFile(): string
{
return $this->mapCacheFile;
}
/**
* @param string $mapCacheFile
* @return AbstractPrinter
*/
public function setMapCacheFile(string $mapCacheFile): AbstractPrinter
{
$this->mapCacheFile = $mapCacheFile;
return $this;
}
/**
* @return string
*/
public function getMapCacheExtension(): string
{
return $this->mapCacheExtension;
}
/**
* @param string $mapCacheExtension
* @return AbstractPrinter
*/
public function setMapCacheExtension(string $mapCacheExtension): AbstractPrinter
{
$this->mapCacheExtension = $mapCacheExtension;
return $this;
}
/**
* @return mixed
*/
public function getZoom()
public function getZoom(): int
{
return $this->zoom;
}
/**
* @param mixed $zoom
* @return AbstractPrinter
*/
public function setZoom($zoom)
public function setZoom(int $zoom): AbstractPrinter
{
$this->zoom = $zoom;
return $this;
}
/**
* @return mixed
*/
public function getLat()
public function getLat(): float
{
return $this->lat;
}
/**
* @param mixed $lat
* @return AbstractPrinter
*/
public function setLat($lat)
public function setLat(float $lat): AbstractPrinter
{
$this->lat = $lat;
return $this;
}
/**
* @return mixed
*/
public function getLon()
public function getLon(): float
{
return $this->lon;
}
/**
* @param mixed $lon
* @return AbstractPrinter
*/
public function setLon($lon)
public function setLon(float $lon): AbstractPrinter
{
$this->lon = $lon;
return $this;
}
/**
* @return mixed
*/
public function getWidth()
public function getWidth(): int
{
return $this->width;
}
/**
* @param mixed $width
* @return AbstractPrinter
*/
public function setWidth($width)
public function setWidth($width): AbstractPrinter
{
$this->width = $width;
return $this;
}
/**
* @return mixed
*/
public function getHeight()
public function getHeight(): int
{
return $this->height;
}
/**
* @param mixed $height
* @return AbstractPrinter
*/
public function setHeight($height)
public function setHeight($height): AbstractPrinter
{
$this->height = $height;
return $this;
}
/**
* @return mixed
*/
public function getImage()
{
return $this->image;
}
/**
* @param mixed $image
* @return AbstractPrinter
*/
public function setImage($image)
public function setImage($image): AbstractPrinter
{
$this->image = $image;
return $this;
}
/**
* @return mixed
*/
public function getMaptype()
public function getMaptype(): string
{
return $this->maptype;
}
/**
* @param mixed $maptype
* @return AbstractPrinter
*/
public function setMaptype($maptype)
public function setMaptype(string $maptype): AbstractPrinter
{
$this->maptype = $maptype;
return $this;
}
/**
* @return mixed
*/
public function getCenterX()
public function getCenterX(): int
{
return $this->centerX;
}
/**
* @param mixed $centerX
* @return AbstractPrinter
*/
public function setCenterX($centerX)
public function setCenterX($centerX): AbstractPrinter
{
$this->centerX = $centerX;
return $this;
}
/**
* @return mixed
*/
public function getCenterY()
public function getCenterY(): int
{
return $this->centerY;
}
/**
* @param mixed $centerY
* @return AbstractPrinter
*/
public function setCenterY($centerY)
public function setCenterY(int $centerY): AbstractPrinter
{
$this->centerY = $centerY;
return $this;
}
/**
* @return mixed
*/
public function getOffsetX()
public function getOffsetX(): int
{
return $this->offsetX;
}
/**
* @param mixed $offsetX
* @return AbstractPrinter
*/
public function setOffsetX($offsetX)
public function setOffsetX(int $offsetX): AbstractPrinter
{
$this->offsetX = $offsetX;
return $this;
}
/**
* @return mixed
*/
public function getOffsetY()
public function getOffsetY(): int
{
return $this->offsetY;
}
/**
* @param mixed $offsetY
* @return AbstractPrinter
*/
public function setOffsetY($offsetY)
public function setOffsetY(int $offsetY): AbstractPrinter
{
$this->offsetY = $offsetY;
return $this;
}
/**
* @return array
*/
public function getMarkers(): array
{
return $this->markers;
}
/**
* @param array $markers
* @return AbstractPrinter
*/
public function setMarkers(array $markers): AbstractPrinter
{
$this->markers = $markers;
return $this;
}
/**
* @return array
*/
public function getPolylines(): array
{
return $this->polylines;
}
/**
* @param array $polylines
* @return AbstractPrinter
*/
public function setPolylines(array $polylines): AbstractPrinter
{
$this->polylines = $polylines;
return $this;
}
}

View File

@ -9,6 +9,7 @@ use StaticMapLite\Element\Polyline\Polyline;
use StaticMapLite\ElementPrinter\Marker\ExtraMarkerPrinter;
use StaticMapLite\ElementPrinter\Polyline\PolylinePrinter;
use StaticMapLite\TileResolver\CachedTileResolver;
use StaticMapLite\Util;
class Printer extends AbstractPrinter
{
@ -63,7 +64,7 @@ class Printer extends AbstractPrinter
return $this;
}
public function setZoom(int $zoom): Printer
public function setZoom(int $zoom): AbstractPrinter
{
$this->zoom = $zoom;
@ -74,7 +75,7 @@ class Printer extends AbstractPrinter
return $this;
}
public function setMapType(string $mapType): Printer
public function setMapType(string $mapType): AbstractPrinter
{
$this->maptype = $mapType;