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; namespace StaticMapLite\CanvasTilePainter;
use StaticMapLite\Canvas\Canvas;
use StaticMapLite\TileResolver\TileResolver;
interface CanvasTilePainterInterface interface CanvasTilePainterInterface
{ {
public function setCanvas(Canvas $canvas): CanvasTilePainterInterface; public function setCanvas(Canvas $canvas): CanvasTilePainterInterface;

View File

@ -2,21 +2,37 @@
namespace StaticMapLite\MapCache; namespace StaticMapLite\MapCache;
use StaticMapLite\Printer; use StaticMapLite\Printer\PrinterInterface;
class MapCache class MapCache
{ {
/** @var Printer $printer */ /** @var PrinterInterface $printer */
protected $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 public function checkMapCache(): bool
{ {
$this->mapCacheID = md5($this->serializeParams()); $this->mapCacheID = md5($this->serializeParams());
$filename = $this->mapCacheIDToFilename(); $filename = $this->mapCacheIDToFilename();
return file_exists($filename); return file_exists($filename);
@ -41,6 +57,9 @@ class MapCache
if (!$this->mapCacheFile) { 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); $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 */ /** @var bool $useTileCache */
protected $useTileCache = true; 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 $zoom;
protected $lat; protected $lat;
@ -82,489 +67,267 @@ abstract class AbstractPrinter
/** @var array $polylines */ /** @var array $polylines */
protected $polylines = []; protected $polylines = [];
/**
* @return int
*/
public function getMaxWidth(): int public function getMaxWidth(): int
{ {
return $this->maxWidth; return $this->maxWidth;
} }
/**
* @param int $maxWidth
* @return AbstractPrinter
*/
public function setMaxWidth(int $maxWidth): AbstractPrinter public function setMaxWidth(int $maxWidth): AbstractPrinter
{ {
$this->maxWidth = $maxWidth; $this->maxWidth = $maxWidth;
return $this; return $this;
} }
/**
* @return int
*/
public function getMaxHeight(): int public function getMaxHeight(): int
{ {
return $this->maxHeight; return $this->maxHeight;
} }
/**
* @param int $maxHeight
* @return AbstractPrinter
*/
public function setMaxHeight(int $maxHeight): AbstractPrinter public function setMaxHeight(int $maxHeight): AbstractPrinter
{ {
$this->maxHeight = $maxHeight; $this->maxHeight = $maxHeight;
return $this; return $this;
} }
/**
* @return TileResolverInterface
*/
public function getTileResolver(): TileResolverInterface public function getTileResolver(): TileResolverInterface
{ {
return $this->tileResolver; return $this->tileResolver;
} }
/**
* @param TileResolverInterface $tileResolver
* @return AbstractPrinter
*/
public function setTileResolver(TileResolverInterface $tileResolver): AbstractPrinter public function setTileResolver(TileResolverInterface $tileResolver): AbstractPrinter
{ {
$this->tileResolver = $tileResolver; $this->tileResolver = $tileResolver;
return $this; return $this;
} }
/**
* @return CanvasInterface
*/
public function getCanvas(): CanvasInterface public function getCanvas(): CanvasInterface
{ {
return $this->canvas; return $this->canvas;
} }
/**
* @param CanvasInterface $canvas
* @return AbstractPrinter
*/
public function setCanvas(CanvasInterface $canvas): AbstractPrinter public function setCanvas(CanvasInterface $canvas): AbstractPrinter
{ {
$this->canvas = $canvas; $this->canvas = $canvas;
return $this; return $this;
} }
/**
* @return int
*/
public function getTileSize(): int public function getTileSize(): int
{ {
return $this->tileSize; return $this->tileSize;
} }
/**
* @param int $tileSize
* @return AbstractPrinter
*/
public function setTileSize(int $tileSize): AbstractPrinter public function setTileSize(int $tileSize): AbstractPrinter
{ {
$this->tileSize = $tileSize; $this->tileSize = $tileSize;
return $this; return $this;
} }
/**
* @return array
*/
public function getTileSrcUrl(): array public function getTileSrcUrl(): array
{ {
return $this->tileSrcUrl; return $this->tileSrcUrl;
} }
/**
* @param array $tileSrcUrl
* @return AbstractPrinter
*/
public function setTileSrcUrl(array $tileSrcUrl): AbstractPrinter public function setTileSrcUrl(array $tileSrcUrl): AbstractPrinter
{ {
$this->tileSrcUrl = $tileSrcUrl; $this->tileSrcUrl = $tileSrcUrl;
return $this; return $this;
} }
/**
* @return string
*/
public function getTileDefaultSrc(): string public function getTileDefaultSrc(): string
{ {
return $this->tileDefaultSrc; return $this->tileDefaultSrc;
} }
/**
* @param string $tileDefaultSrc
* @return AbstractPrinter
*/
public function setTileDefaultSrc(string $tileDefaultSrc): AbstractPrinter public function setTileDefaultSrc(string $tileDefaultSrc): AbstractPrinter
{ {
$this->tileDefaultSrc = $tileDefaultSrc; $this->tileDefaultSrc = $tileDefaultSrc;
return $this; return $this;
} }
/**
* @return string
*/
public function getOsmLogo(): string public function getOsmLogo(): string
{ {
return $this->osmLogo; return $this->osmLogo;
} }
/**
* @param string $osmLogo
* @return AbstractPrinter
*/
public function setOsmLogo(string $osmLogo): AbstractPrinter public function setOsmLogo(string $osmLogo): AbstractPrinter
{ {
$this->osmLogo = $osmLogo; $this->osmLogo = $osmLogo;
return $this; return $this;
} }
/**
* @return bool
*/
public function isUseTileCache(): bool public function isUseTileCache(): bool
{ {
return $this->useTileCache; return $this->useTileCache;
} }
/**
* @param bool $useTileCache
* @return AbstractPrinter
*/
public function setUseTileCache(bool $useTileCache): AbstractPrinter public function setUseTileCache(bool $useTileCache): AbstractPrinter
{ {
$this->useTileCache = $useTileCache; $this->useTileCache = $useTileCache;
return $this; return $this;
} }
/** public function getZoom(): int
* @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()
{ {
return $this->zoom; return $this->zoom;
} }
/** public function setZoom(int $zoom): AbstractPrinter
* @param mixed $zoom
* @return AbstractPrinter
*/
public function setZoom($zoom)
{ {
$this->zoom = $zoom; $this->zoom = $zoom;
return $this; return $this;
} }
/** public function getLat(): float
* @return mixed
*/
public function getLat()
{ {
return $this->lat; return $this->lat;
} }
/** public function setLat(float $lat): AbstractPrinter
* @param mixed $lat
* @return AbstractPrinter
*/
public function setLat($lat)
{ {
$this->lat = $lat; $this->lat = $lat;
return $this; return $this;
} }
/** public function getLon(): float
* @return mixed
*/
public function getLon()
{ {
return $this->lon; return $this->lon;
} }
/** public function setLon(float $lon): AbstractPrinter
* @param mixed $lon
* @return AbstractPrinter
*/
public function setLon($lon)
{ {
$this->lon = $lon; $this->lon = $lon;
return $this; return $this;
} }
/** public function getWidth(): int
* @return mixed
*/
public function getWidth()
{ {
return $this->width; return $this->width;
} }
/** public function setWidth($width): AbstractPrinter
* @param mixed $width
* @return AbstractPrinter
*/
public function setWidth($width)
{ {
$this->width = $width; $this->width = $width;
return $this; return $this;
} }
/** public function getHeight(): int
* @return mixed
*/
public function getHeight()
{ {
return $this->height; return $this->height;
} }
/** public function setHeight($height): AbstractPrinter
* @param mixed $height
* @return AbstractPrinter
*/
public function setHeight($height)
{ {
$this->height = $height; $this->height = $height;
return $this; return $this;
} }
/**
* @return mixed
*/
public function getImage() public function getImage()
{ {
return $this->image; return $this->image;
} }
/** public function setImage($image): AbstractPrinter
* @param mixed $image
* @return AbstractPrinter
*/
public function setImage($image)
{ {
$this->image = $image; $this->image = $image;
return $this; return $this;
} }
/** public function getMaptype(): string
* @return mixed
*/
public function getMaptype()
{ {
return $this->maptype; return $this->maptype;
} }
/** public function setMaptype(string $maptype): AbstractPrinter
* @param mixed $maptype
* @return AbstractPrinter
*/
public function setMaptype($maptype)
{ {
$this->maptype = $maptype; $this->maptype = $maptype;
return $this; return $this;
} }
/** public function getCenterX(): int
* @return mixed
*/
public function getCenterX()
{ {
return $this->centerX; return $this->centerX;
} }
/** public function setCenterX($centerX): AbstractPrinter
* @param mixed $centerX
* @return AbstractPrinter
*/
public function setCenterX($centerX)
{ {
$this->centerX = $centerX; $this->centerX = $centerX;
return $this; return $this;
} }
/** public function getCenterY(): int
* @return mixed
*/
public function getCenterY()
{ {
return $this->centerY; return $this->centerY;
} }
/** public function setCenterY(int $centerY): AbstractPrinter
* @param mixed $centerY
* @return AbstractPrinter
*/
public function setCenterY($centerY)
{ {
$this->centerY = $centerY; $this->centerY = $centerY;
return $this; return $this;
} }
/** public function getOffsetX(): int
* @return mixed
*/
public function getOffsetX()
{ {
return $this->offsetX; return $this->offsetX;
} }
/** public function setOffsetX(int $offsetX): AbstractPrinter
* @param mixed $offsetX
* @return AbstractPrinter
*/
public function setOffsetX($offsetX)
{ {
$this->offsetX = $offsetX; $this->offsetX = $offsetX;
return $this; return $this;
} }
/** public function getOffsetY(): int
* @return mixed
*/
public function getOffsetY()
{ {
return $this->offsetY; return $this->offsetY;
} }
/** public function setOffsetY(int $offsetY): AbstractPrinter
* @param mixed $offsetY
* @return AbstractPrinter
*/
public function setOffsetY($offsetY)
{ {
$this->offsetY = $offsetY; $this->offsetY = $offsetY;
return $this; return $this;
} }
/**
* @return array
*/
public function getMarkers(): array public function getMarkers(): array
{ {
return $this->markers; return $this->markers;
} }
/**
* @param array $markers
* @return AbstractPrinter
*/
public function setMarkers(array $markers): AbstractPrinter public function setMarkers(array $markers): AbstractPrinter
{ {
$this->markers = $markers; $this->markers = $markers;
return $this; return $this;
} }
/**
* @return array
*/
public function getPolylines(): array public function getPolylines(): array
{ {
return $this->polylines; return $this->polylines;
} }
/**
* @param array $polylines
* @return AbstractPrinter
*/
public function setPolylines(array $polylines): AbstractPrinter public function setPolylines(array $polylines): AbstractPrinter
{ {
$this->polylines = $polylines; $this->polylines = $polylines;
return $this; return $this;
} }
} }

View File

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