From 8504b38d5c136717b57a22dcecfc5a1a0410b035 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malte=20Hu=CC=88bner?= Date: Fri, 26 May 2017 16:32:08 +0200 Subject: [PATCH] Add some TileResolvers. --- src/Printer.php | 19 +++++++------------ src/TileResolver/CachedTileResolver.php | 25 +++++++++++++++++++++++++ src/TileResolver/TileResolver.php | 19 +++++++++++++++++++ 3 files changed, 51 insertions(+), 12 deletions(-) create mode 100644 src/TileResolver/CachedTileResolver.php create mode 100644 src/TileResolver/TileResolver.php diff --git a/src/Printer.php b/src/Printer.php index 6291927..ccd663f 100644 --- a/src/Printer.php +++ b/src/Printer.php @@ -2,11 +2,15 @@ namespace StaticMapLite; +use StaticMapLite\TileResolver\TileResolver; + class Printer { protected $maxWidth = 1024; protected $maxHeight = 1024; + protected $tileResolver = null; + protected $tileSize = 256; protected $tileSrcUrl = array('mapnik' => 'http://tile.openstreetmap.org/{Z}/{X}/{Y}.png', 'osmarenderer' => 'http://otile1.mqcdn.com/tiles/1.0.0/osm/{Z}/{X}/{Y}.png', @@ -73,6 +77,8 @@ class Printer $this->width = 500; $this->height = 350; $this->maptype = $this->tileDefaultSrc; + + $this->tileResolver = new TileResolver(); } public function addMarker(string $markerType, float $latitude, float $longitude): Printer @@ -339,18 +345,7 @@ class Printer public function fetchTile($url) { - if ($this->useTileCache && ($cached = $this->checkTileCache($url))) return $cached; - $ch = curl_init(); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0"); - curl_setopt($ch, CURLOPT_URL, $url); - $tile = curl_exec($ch); - curl_close($ch); - if ($tile && $this->useTileCache) { - $this->writeTileToCache($url, $tile); - } - return $tile; - + return $this->tileResolver->fetch($url); } public function copyrightNotice() diff --git a/src/TileResolver/CachedTileResolver.php b/src/TileResolver/CachedTileResolver.php new file mode 100644 index 0000000..194c1e8 --- /dev/null +++ b/src/TileResolver/CachedTileResolver.php @@ -0,0 +1,25 @@ +useTileCache && ($cached = $this->checkTileCache($url))) return $cached; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0"); + curl_setopt($ch, CURLOPT_URL, $url); + $tile = curl_exec($ch); + curl_close($ch); + if ($tile && $this->useTileCache) { + $this->writeTileToCache($url, $tile); + } + return $tile; +*/ + + throw new \Exception('Not implemented'); + } +} diff --git a/src/TileResolver/TileResolver.php b/src/TileResolver/TileResolver.php new file mode 100644 index 0000000..c437702 --- /dev/null +++ b/src/TileResolver/TileResolver.php @@ -0,0 +1,19 @@ +