diff --git a/src/Canvas/Canvas.php b/src/Canvas/Canvas.php index 9f0ad30..4ec543f 100644 --- a/src/Canvas/Canvas.php +++ b/src/Canvas/Canvas.php @@ -2,18 +2,26 @@ namespace StaticMapLite\Canvas; -class Canvas +class Canvas implements CanvasInterface { protected $image = null; + /** @var int $tileSize */ protected $tileSize = 256; + /** @var int $width */ protected $width = 0; + + /** @var int $height */ protected $height = 0; + /** @var float $centerX */ protected $centerX = 0; + + /** @var float $centerY */ protected $centerY = 0; + /** @var int $zoom */ protected $zoom = 0; public function __construct(int $width, int $height, int $zoom, float $centerX, float $centerY) diff --git a/src/Canvas/CanvasInterface.php b/src/Canvas/CanvasInterface.php new file mode 100644 index 0000000..9af8db9 --- /dev/null +++ b/src/Canvas/CanvasInterface.php @@ -0,0 +1,14 @@ +tileResolver->fetch($this->canvas->getZoom(), $x, $y); if ($tileData) { - $tileImage = imagecreatefromstring($tileData); + $tileImage = $this->createTile($tileData); } else { - $tileImage = imagecreate($this->canvas->getTileSize(), $this->canvas->getTileSize()); - $color = imagecolorallocate($tileImage, 255, 255, 255); - @imagestring($tileImage, 1, 127, 127, 'err', $color); + $tileImage = $this->createErrorTile(); } $destX = ($x - $startX) * $this->canvas->getTileSize() + $offsetX; @@ -67,4 +66,18 @@ class CanvasTilePainter return $this; } -} \ No newline at end of file + + protected function createTile(string $tileData) + { + return imagecreatefromstring($tileData); + } + + protected function createErrorTile() + { + $tileImage = imagecreate($this->canvas->getTileSize(), $this->canvas->getTileSize()); + $color = imagecolorallocate($tileImage, 255, 255, 255); + @imagestring($tileImage, 1, 127, 127, 'err', $color); + + return $tileImage; + } +} diff --git a/src/CanvasTilePainter/CanvasTilePainterInterface.php b/src/CanvasTilePainter/CanvasTilePainterInterface.php new file mode 100644 index 0000000..7bad61e --- /dev/null +++ b/src/CanvasTilePainter/CanvasTilePainterInterface.php @@ -0,0 +1,10 @@ +tileCacheBaseDir . '/' . str_replace(['http://', 'https://'], '', $url); } - public function checkTileCache(string $url) + protected function checkTileCache(string $url) { $filename = $this->tileUrlToFilename($url); @@ -41,7 +42,7 @@ class CachedTileResolver extends TileResolver return false; } - public function writeTileToCache($url, $data): CachedTileResolver + protected function writeTileToCache($url, $data): CachedTileResolver { $filename = $this->tileUrlToFilename($url); @@ -52,7 +53,7 @@ class CachedTileResolver extends TileResolver return $this; } - public function mkdir_recursive($pathname, $mode): bool + protected function mkdir_recursive($pathname, $mode): bool { is_dir(dirname($pathname)) || $this->mkdir_recursive(dirname($pathname), $mode); return is_dir($pathname) || @mkdir($pathname, $mode); diff --git a/src/TileResolver/TileResolver.php b/src/TileResolver/TileResolver.php index b98eb29..4944439 100644 --- a/src/TileResolver/TileResolver.php +++ b/src/TileResolver/TileResolver.php @@ -4,11 +4,13 @@ namespace StaticMapLite\TileResolver; use Curl\Curl; -class TileResolver +class TileResolver implements TileResolverInterface { - protected $tileLayerUrl = null; + /** @var string $tileLayerUrl */ + protected $tileLayerUrl; - protected $curl = null; + /** @var Curl $curl */ + protected $curl; public function __construct() { diff --git a/src/TileResolver/TileResolverInterface.php b/src/TileResolver/TileResolverInterface.php new file mode 100644 index 0000000..c4a45b6 --- /dev/null +++ b/src/TileResolver/TileResolverInterface.php @@ -0,0 +1,10 @@ +