mirror of
https://github.com/klokantech/tileserver-php.git
synced 2025-08-06 22:56:31 +02:00
Custom template implementation #31
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
global $config;
|
||||
$config['serverTitle'] = 'TileServer-php v1';
|
||||
$config['availableFormats'] = array('png', 'jpg', 'jpeg', 'gif', 'webp', 'pbf', 'hybrid');
|
||||
//$config['template'] = 'template.php';
|
||||
//$config['baseUrls'] = array('t0.server.com', 't1.server.com');
|
||||
|
||||
Router::serve(array(
|
||||
@@ -74,6 +75,10 @@ class Server {
|
||||
$this->config['baseUrls'] = is_array($envBaseUrls) ?
|
||||
$envBaseUrls : explode(',', $envBaseUrls);
|
||||
}
|
||||
$envTemplate = getenv('template');
|
||||
if($envBaseUrls !== FALSE){
|
||||
$this->config['template'] = $envTemplate;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -516,28 +521,34 @@ class Server {
|
||||
public function getHtml() {
|
||||
$this->setDatasets();
|
||||
$maps = array_merge($this->fileLayer, $this->dbLayer);
|
||||
header('Content-Type: text/html;charset=UTF-8');
|
||||
echo '<!DOCTYPE html><html><head><meta charset="UTF-8"><title>' . $this->config['serverTitle'] . '</title>';
|
||||
echo '<link rel="stylesheet" type="text/css" href="//cdn.klokantech.com/tileviewer/v1/index.css" />
|
||||
<script src="//cdn.klokantech.com/tileviewer/v1/index.js"></script><body>
|
||||
<script>tileserver({index:"' . $this->config['protocol'] . '://' . $this->config['baseUrls'][0] . '/index.json", tilejson:"' . $this->config['protocol'] . '://' . $this->config['baseUrls'][0] . '/%n.json", tms:"' . $this->config['protocol'] . '://' . $this->config['baseUrls'][0] . '/tms", wmts:"' . $this->config['protocol'] . '://' . $this->config['baseUrls'][0] . '/wmts"});</script>
|
||||
<h1>Welcome to ' . $this->config['serverTitle'] . '</h1>
|
||||
<p>This server distributes maps to desktop, web, and mobile applications.</p>
|
||||
<p>The mapping data are available as OpenGIS Web Map Tiling Service (OGC WMTS), OSGEO Tile Map Service (TMS), and popular XYZ urls described with TileJSON metadata.</p>';
|
||||
if (!isset($maps)) {
|
||||
echo '<h3 style="color:darkred;">No maps available yet</h3>
|
||||
<p style="color:darkred; font-style: italic;">
|
||||
Ready to go - just upload some maps into directory:' . getcwd() . '/ on this server.</p>
|
||||
<p>Note: The maps can be a directory with tiles in XYZ format with metadata.json file.<br/>
|
||||
You can easily convert existing geodata (GeoTIFF, ECW, MrSID, etc) to this tile structure with <a href="http://www.maptiler.com">MapTiler Cluster</a> or open-source projects such as <a href="http://www.klokan.cz/projects/gdal2tiles/">GDAL2Tiles</a> or <a href="http://www.maptiler.org/">MapTiler</a> or simply upload any maps in MBTiles format made by <a href="http://www.tilemill.com/">TileMill</a>. Helpful is also the <a href="https://github.com/mapbox/mbutil">mbutil</a> tool. Serving directly from .mbtiles files is supported, but with decreased performance.</p>';
|
||||
if (isset($this->config['template']) && file_exists($this->config['template'])) {
|
||||
$baseUrls = $this->config['baseUrls'];
|
||||
$serverTitle = $this->config['serverTitle'];
|
||||
include_once $this->config['template'];
|
||||
} else {
|
||||
echo '<ul>';
|
||||
foreach ($maps as $map) {
|
||||
echo "<li>" . $map['name'] . '</li>';
|
||||
header('Content-Type: text/html;charset=UTF-8');
|
||||
echo '<!DOCTYPE html><html><head><meta charset="UTF-8"><title>' . $this->config['serverTitle'] . '</title>';
|
||||
echo '<link rel="stylesheet" type="text/css" href="//cdn.klokantech.com/tileviewer/v1/index.css" />
|
||||
<script src="//cdn.klokantech.com/tileviewer/v1/index.js"></script><body>
|
||||
<script>tileserver({index:"' . $this->config['protocol'] . '://' . $this->config['baseUrls'][0] . '/index.json", tilejson:"' . $this->config['protocol'] . '://' . $this->config['baseUrls'][0] . '/%n.json", tms:"' . $this->config['protocol'] . '://' . $this->config['baseUrls'][0] . '/tms", wmts:"' . $this->config['protocol'] . '://' . $this->config['baseUrls'][0] . '/wmts"});</script>
|
||||
<h1>Welcome to ' . $this->config['serverTitle'] . '</h1>
|
||||
<p>This server distributes maps to desktop, web, and mobile applications.</p>
|
||||
<p>The mapping data are available as OpenGIS Web Map Tiling Service (OGC WMTS), OSGEO Tile Map Service (TMS), and popular XYZ urls described with TileJSON metadata.</p>';
|
||||
if (!isset($maps)) {
|
||||
echo '<h3 style="color:darkred;">No maps available yet</h3>
|
||||
<p style="color:darkred; font-style: italic;">
|
||||
Ready to go - just upload some maps into directory:' . getcwd() . '/ on this server.</p>
|
||||
<p>Note: The maps can be a directory with tiles in XYZ format with metadata.json file.<br/>
|
||||
You can easily convert existing geodata (GeoTIFF, ECW, MrSID, etc) to this tile structure with <a href="http://www.maptiler.com">MapTiler Cluster</a> or open-source projects such as <a href="http://www.klokan.cz/projects/gdal2tiles/">GDAL2Tiles</a> or <a href="http://www.maptiler.org/">MapTiler</a> or simply upload any maps in MBTiles format made by <a href="http://www.tilemill.com/">TileMill</a>. Helpful is also the <a href="https://github.com/mapbox/mbutil">mbutil</a> tool. Serving directly from .mbtiles files is supported, but with decreased performance.</p>';
|
||||
} else {
|
||||
echo '<ul>';
|
||||
foreach ($maps as $map) {
|
||||
echo "<li>" . $map['name'] . '</li>';
|
||||
}
|
||||
echo '</ul>';
|
||||
}
|
||||
echo '</ul>';
|
||||
echo '</body></html>';
|
||||
}
|
||||
echo '</body></html>';
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user