Skip to content
This repository has been archived by the owner on Jun 25, 2024. It is now read-only.

Commit

Permalink
Custom template implementation #31
Browse files Browse the repository at this point in the history
  • Loading branch information
daliborjanak committed Mar 7, 2016
1 parent 709ed4f commit 8f2b068
Showing 1 changed file with 30 additions and 19 deletions.
49 changes: 30 additions & 19 deletions tileserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -74,6 +75,10 @@ public function __construct() {
$this->config['baseUrls'] = is_array($envBaseUrls) ?
$envBaseUrls : explode(',', $envBaseUrls);
}
$envTemplate = getenv('template');
if($envBaseUrls !== FALSE){
$this->config['template'] = $envTemplate;
}
}

/**
Expand Down Expand Up @@ -516,28 +521,34 @@ public function getInfo() {
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>';
}

}
Expand Down

0 comments on commit 8f2b068

Please sign in to comment.