Add some TileResolvers.

This commit is contained in:
Malte Hübner 2017-05-26 16:32:08 +02:00
parent 11e15874df
commit 8504b38d5c
3 changed files with 51 additions and 12 deletions

View File

@ -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()

View File

@ -0,0 +1,25 @@
<?php
namespace StaticMapLite\TileResolver;
class CachedTileResolver extends TileResolver
{
public function fetch(string $url): string
{
/*
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;
*/
throw new \Exception('Not implemented');
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace StaticMapLite\TileResolver;
class TileResolver
{
public function fetch(string $url): string
{
$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);
return $tile;
}
}