mirror of
https://github.com/klokantech/tileserver-php.git
synced 2025-08-05 14:18:13 +02:00
Add prefix to mbtiles, return 204 on no tile
This adds a configuration option for a prefix to the mbtiles, so you can store the tiles in other locations. It also changes the no tile found 404 to a 204, as the mapbox team will be doing: https://github.com/mapbox/mapbox-gl-js/issues/1800#issuecomment-236190808
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
global $config;
|
global $config;
|
||||||
$config['serverTitle'] = 'Maps hosted with TileServer-php v2.0';
|
$config['serverTitle'] = 'Maps hosted with TileServer-php v2.0';
|
||||||
$config['availableFormats'] = array('png', 'jpg', 'jpeg', 'gif', 'webp', 'pbf', 'hybrid');
|
$config['availableFormats'] = array('png', 'jpg', 'jpeg', 'gif', 'webp', 'pbf', 'hybrid');
|
||||||
|
$config['mbtilesPrefix'] = './';
|
||||||
//$config['template'] = 'template.php';
|
//$config['template'] = 'template.php';
|
||||||
//$config['baseUrls'] = array('t0.server.com', 't1.server.com');
|
//$config['baseUrls'] = array('t0.server.com', 't1.server.com');
|
||||||
|
|
||||||
@@ -86,7 +87,7 @@ class Server {
|
|||||||
*/
|
*/
|
||||||
public function setDatasets() {
|
public function setDatasets() {
|
||||||
$mjs = glob('*/metadata.json');
|
$mjs = glob('*/metadata.json');
|
||||||
$mbts = glob('*.mbtiles');
|
$mbts = glob($this->config['mbtilesPrefix'] . '*.mbtiles');
|
||||||
if ($mjs) {
|
if ($mjs) {
|
||||||
foreach (array_filter($mjs, 'is_readable') as $mj) {
|
foreach (array_filter($mjs, 'is_readable') as $mj) {
|
||||||
$layer = $this->metadataFromMetadataJson($mj);
|
$layer = $this->metadataFromMetadataJson($mj);
|
||||||
@@ -139,7 +140,7 @@ class Server {
|
|||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function isDBLayer($layer) {
|
public function isDBLayer($layer) {
|
||||||
if (is_file($layer . '.mbtiles')) {
|
if (is_file($this->config['mbtilesPrefix'] . $layer . '.mbtiles')) {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
} else {
|
} else {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@@ -310,7 +311,7 @@ class Server {
|
|||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function isModified($filename) {
|
public function isModified($filename) {
|
||||||
$filename = $filename . '.mbtiles';
|
$filename = $this->config['mbtilesPrefix'] . $filename . '.mbtiles';
|
||||||
$lastModifiedTime = filemtime($filename);
|
$lastModifiedTime = filemtime($filename);
|
||||||
$eTag = md5($lastModifiedTime);
|
$eTag = md5($lastModifiedTime);
|
||||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $lastModifiedTime) . ' GMT');
|
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $lastModifiedTime) . ' GMT');
|
||||||
@@ -338,7 +339,7 @@ class Server {
|
|||||||
header('HTTP/1.1 304 Not Modified');
|
header('HTTP/1.1 304 Not Modified');
|
||||||
die;
|
die;
|
||||||
}
|
}
|
||||||
$this->DBconnect($tileset . '.mbtiles');
|
$this->DBconnect($this->config['mbtilesPrefix'] . $tileset . '.mbtiles');
|
||||||
$z = floatval($z);
|
$z = floatval($z);
|
||||||
$y = floatval($y);
|
$y = floatval($y);
|
||||||
$x = floatval($x);
|
$x = floatval($x);
|
||||||
@@ -412,7 +413,8 @@ class Server {
|
|||||||
public function getCleanTile($scale = 1, $format = 'png') {
|
public function getCleanTile($scale = 1, $format = 'png') {
|
||||||
switch ($format) {
|
switch ($format) {
|
||||||
case 'pbf':
|
case 'pbf':
|
||||||
header('HTTP/1.1 404 Not Found');
|
header('Access-Control-Allow-Origin: *');
|
||||||
|
header('HTTP/1.1 204 No Content');
|
||||||
header('Content-Type: application/json; charset=utf-8');
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
echo '{"message":"Tile does not exist"}';
|
echo '{"message":"Tile does not exist"}';
|
||||||
break;
|
break;
|
||||||
@@ -453,7 +455,7 @@ class Server {
|
|||||||
$y = pow(2, $z) - 1 - $y;
|
$y = pow(2, $z) - 1 - $y;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$this->DBconnect($tileset . '.mbtiles');
|
$this->DBconnect($this->config['mbtilesPrefix'] . $tileset . '.mbtiles');
|
||||||
|
|
||||||
$query = 'SELECT grid FROM grids WHERE tile_column = ' . $x . ' AND '
|
$query = 'SELECT grid FROM grids WHERE tile_column = ' . $x . ' AND '
|
||||||
. 'tile_row = ' . $y . ' AND zoom_level = ' . $z;
|
. 'tile_row = ' . $y . ' AND zoom_level = ' . $z;
|
||||||
@@ -618,7 +620,7 @@ class Json extends Server {
|
|||||||
$metadata['tilejson'] = '2.0.0';
|
$metadata['tilejson'] = '2.0.0';
|
||||||
$metadata['scheme'] = 'xyz';
|
$metadata['scheme'] = 'xyz';
|
||||||
if ($this->isDBLayer($metadata['basename'])) {
|
if ($this->isDBLayer($metadata['basename'])) {
|
||||||
$this->DBconnect($metadata['basename'] . '.mbtiles');
|
$this->DBconnect($this->config['mbtilesPrefix'] . $metadata['basename'] . '.mbtiles');
|
||||||
$res = $this->db->query('SELECT name FROM sqlite_master WHERE name="grids";');
|
$res = $this->db->query('SELECT name FROM sqlite_master WHERE name="grids";');
|
||||||
if ($res) {
|
if ($res) {
|
||||||
foreach ($this->config['baseUrls'] as $url) {
|
foreach ($this->config['baseUrls'] as $url) {
|
||||||
|
Reference in New Issue
Block a user