mirror of
https://github.com/klokantech/tileserver-php.git
synced 2025-08-03 21:27:52 +02:00
Better router. TileServer now uses .js and .css files from maptiler.com.
This commit is contained in:
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
# Restrictions for data crawlers
|
# Restrictions for data crawlers
|
||||||
Options -Indexes
|
Options -Indexes
|
||||||
Options +FollowSymLinks
|
#Options +FollowSymLinks
|
||||||
Options -MultiViews
|
#Options -MultiViews
|
||||||
|
|
||||||
# Optional CORS header for cross-domain origin access to all data
|
# Optional CORS header for cross-domain origin access to all data
|
||||||
#<ifModule mod_headers.c>
|
#<ifModule mod_headers.c>
|
||||||
@@ -20,8 +20,6 @@ RewriteEngine on
|
|||||||
#some hostings require RewriteBase e.g. 1&1.com
|
#some hostings require RewriteBase e.g. 1&1.com
|
||||||
#RewriteBase /
|
#RewriteBase /
|
||||||
#RewriteBase /folder/
|
#RewriteBase /folder/
|
||||||
|
|
||||||
AcceptPathInfo on
|
|
||||||
|
|
||||||
# WMTS RESTful
|
# WMTS RESTful
|
||||||
# ------------
|
# ------------
|
||||||
@@ -48,4 +46,4 @@ RewriteRule .* - [E=HTTP_IF_NONE_MATCH:%{HTTP:If-None-Match}]
|
|||||||
RewriteCond %{REQUEST_FILENAME} !-f
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
RewriteCond %{REQUEST_FILENAME} !-d
|
RewriteCond %{REQUEST_FILENAME} !-d
|
||||||
RewriteCond $1 !^(tileserver\.php)
|
RewriteCond $1 !^(tileserver\.php)
|
||||||
RewriteRule ^(.*)$ tileserver.php/$1 [L]
|
RewriteRule ^(.*)$ tileserver.php?/$1 [L,QSA]
|
@@ -18,16 +18,13 @@ Router::serve(array(
|
|||||||
'/:string.json' => 'Json:getJson',
|
'/:string.json' => 'Json:getJson',
|
||||||
'/:string.jsonp' => 'Json:getJsonp',
|
'/:string.jsonp' => 'Json:getJsonp',
|
||||||
'/:string/:number/:number/:number.grid.json' => 'Json:getUTFGrid',
|
'/:string/:number/:number/:number.grid.json' => 'Json:getUTFGrid',
|
||||||
'/wmts/' => 'Wmts:getCapabilities',
|
'/wmts' => 'Wmts:get',
|
||||||
'/wmts' => 'Wmts:getTile',
|
|
||||||
'/wmts/1.0.0/WMTSCapabilities.xml' => 'Wmts:getCapabilities',
|
'/wmts/1.0.0/WMTSCapabilities.xml' => 'Wmts:getCapabilities',
|
||||||
'/:string/:number/:number/:number.:string' => 'Wmts:getTile',
|
'/:string/:number/:number/:number.:string' => 'Wmts:getTile',
|
||||||
'/tms' => 'Tms:getCapabilities',
|
'/tms' => 'Tms:getCapabilities',
|
||||||
'/tms/' => 'Tms:getCapabilities',
|
'/tms/:string' => 'Tms:getLayerCapabilities',
|
||||||
'/:string/tms' => 'Tms:getLayerCapabilities',
|
|
||||||
'/:string/tms/' => 'Tms:getLayerCapabilities',
|
|
||||||
'/:string/tms/:number/:number/:number.:string' => 'Tms:getTile',
|
'/:string/tms/:number/:number/:number.:string' => 'Tms:getTile',
|
||||||
));
|
));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Server base
|
* Server base
|
||||||
@@ -63,16 +60,6 @@ class Server {
|
|||||||
*/
|
*/
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
$this->config = $GLOBALS['config'];
|
$this->config = $GLOBALS['config'];
|
||||||
if (!isset($this->config['baseUrls'])) {
|
|
||||||
//TODO if contains tileserver.php add to path
|
|
||||||
$ru = explode('/', $_SERVER['REQUEST_URI']);
|
|
||||||
$this->config['baseUrls'][0] = $_SERVER['HTTP_HOST'];
|
|
||||||
if (isset($ru[2]) && (!empty($ru[2]) || $ru[2] !== 'tms')) {
|
|
||||||
//autodetection for http://server/ or http://server/directory
|
|
||||||
//subdirectories must be specified $config['baseUrls']
|
|
||||||
$this->config['baseUrls'][0] = $this->config['baseUrls'][0] . '/' . $ru[1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -96,10 +83,10 @@ class Server {
|
|||||||
} else {
|
} else {
|
||||||
$e = 1;
|
$e = 1;
|
||||||
}
|
}
|
||||||
if (isset($e)) {
|
// if (isset($e)) {
|
||||||
echo 'Server: No JSON or MBtiles file with metadata';
|
// echo 'Server: No JSON or MBtiles file with metadata';
|
||||||
die;
|
// die;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -125,14 +112,11 @@ class Server {
|
|||||||
* @param string $key
|
* @param string $key
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function getGlobal($key) {
|
public function getGlobal($isKey) {
|
||||||
$keys[] = $key;
|
$get = $_GET;
|
||||||
$keys[] = strtolower($key);
|
foreach ($get as $key => $value) {
|
||||||
$keys[] = strtoupper($key);
|
if(strtolower($isKey) == strtolower($key)){
|
||||||
$keys[] = ucfirst($key);
|
return $value;
|
||||||
foreach ($keys as $key) {
|
|
||||||
if (isset($_GET[$key])) {
|
|
||||||
return $_GET[$key];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@@ -419,9 +403,9 @@ class Server {
|
|||||||
$maps = array_merge($this->fileLayer, $this->dbLayer);
|
$maps = array_merge($this->fileLayer, $this->dbLayer);
|
||||||
header('Content-Type: text/html;charset=UTF-8');
|
header('Content-Type: text/html;charset=UTF-8');
|
||||||
echo '<!DOCTYPE html><html><head><meta charset="UTF-8"><title>' . $this->config['serverTitle'] . '</title>';
|
echo '<!DOCTYPE html><html><head><meta charset="UTF-8"><title>' . $this->config['serverTitle'] . '</title>';
|
||||||
echo '<link rel="stylesheet" type="text/css" href="http://maptilercdn.s3.amazonaws.com/tileserver.css" />
|
echo '<link rel="stylesheet" type="text/css" href="//tileserver.com/v1/index.css" />
|
||||||
<script src="http://maptilercdn.s3.amazonaws.com/tileserver.js"></script><body>
|
<script src="//tileserver.com/v1/index.js"></script><body>
|
||||||
<script>tileserver("http://' . $this->config['baseUrls'][0] . '/index.jsonp","http://' . $this->config['baseUrls'][0] . '/tms/","http://' . $this->config['baseUrls'][0] . '/wmts/");</script>
|
<script>tileserver(null,"http://' . $this->config['baseUrls'][0] . '/tms/","http://' . $this->config['baseUrls'][0] . '/wmts/");</script>
|
||||||
<h1>Welcome to ' . $this->config['serverTitle'] . '</h1>
|
<h1>Welcome to ' . $this->config['serverTitle'] . '</h1>
|
||||||
<p>This server distributes maps to desktop, web, and mobile applications.</p>
|
<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>';
|
<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>';
|
||||||
@@ -609,6 +593,18 @@ class Wmts extends Server {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests request from url and call method
|
||||||
|
*/
|
||||||
|
public function get(){
|
||||||
|
$request = $this->getGlobal('Request');
|
||||||
|
if($request !== FALSE && $request == 'gettile'){
|
||||||
|
$this->getTile();
|
||||||
|
}else{
|
||||||
|
$this->getCapabilities();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns tilesets getCapabilities
|
* Returns tilesets getCapabilities
|
||||||
*/
|
*/
|
||||||
@@ -1069,10 +1065,11 @@ class Wmts extends Server {
|
|||||||
if ($request) {
|
if ($request) {
|
||||||
if (strpos('/', $_GET['Format']) !== FALSE) {
|
if (strpos('/', $_GET['Format']) !== FALSE) {
|
||||||
$format = explode('/', $_GET['Format']);
|
$format = explode('/', $_GET['Format']);
|
||||||
|
$format = $format[1];
|
||||||
} else {
|
} else {
|
||||||
$format = $this->getGlobal('Format');
|
$format = $this->getGlobal('Format');
|
||||||
}
|
}
|
||||||
parent::getTile($this->getGlobal('Layer'), $this->getGlobal('TileMatrix'), $this->getGlobal('TileRow'), $this->getGlobal('TileCol'), $format[1]);
|
parent::getTile($this->getGlobal('Layer'), $this->getGlobal('TileMatrix'), $this->getGlobal('TileRow'), $this->getGlobal('TileCol'), $format);
|
||||||
} else {
|
} else {
|
||||||
parent::getTile($this->layer, $this->z, $this->y, $this->x, $this->ext);
|
parent::getTile($this->layer, $this->z, $this->y, $this->x, $this->ext);
|
||||||
}
|
}
|
||||||
@@ -1137,7 +1134,7 @@ class Tms extends Server {
|
|||||||
$srs = "EPSG:3857";
|
$srs = "EPSG:3857";
|
||||||
echo '<TileMap title="' . $title . '" srs="' . $srs
|
echo '<TileMap title="' . $title . '" srs="' . $srs
|
||||||
. '" type="InvertedTMS" ' . 'profile="global-' . $profile
|
. '" type="InvertedTMS" ' . 'profile="global-' . $profile
|
||||||
. '" href="http://' . $this->config['baseUrls'][0] . '/' . $basename . '/tms" />';
|
. '" href="http://' . $this->config['baseUrls'][0] . '/tms/' . $basename . '" />';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo '</TileMaps></TileMapService>';
|
echo '</TileMaps></TileMapService>';
|
||||||
@@ -1333,7 +1330,7 @@ class Router {
|
|||||||
/**
|
/**
|
||||||
* @param array $routes
|
* @param array $routes
|
||||||
*/
|
*/
|
||||||
public static function serve($routes) {
|
public static function serve($routes) {
|
||||||
$request_method = strtolower($_SERVER['REQUEST_METHOD']);
|
$request_method = strtolower($_SERVER['REQUEST_METHOD']);
|
||||||
$path_info = '/';
|
$path_info = '/';
|
||||||
if (!empty($_SERVER['PATH_INFO'])) {
|
if (!empty($_SERVER['PATH_INFO'])) {
|
||||||
@@ -1347,17 +1344,20 @@ class Router {
|
|||||||
}
|
}
|
||||||
$discovered_handler = null;
|
$discovered_handler = null;
|
||||||
$regex_matches = array();
|
$regex_matches = array();
|
||||||
if (isset($routes[$path_info])) {
|
|
||||||
$discovered_handler = $routes[$path_info];
|
if ($routes) {
|
||||||
} else if ($routes) {
|
|
||||||
$tokens = array(
|
$tokens = array(
|
||||||
':string' => '([a-zA-Z]+)',
|
':string' => '([a-zA-Z]+)',
|
||||||
':number' => '([0-9]+)',
|
':number' => '([0-9]+)',
|
||||||
':alpha' => '([a-zA-Z0-9-_]+)'
|
':alpha' => '([a-zA-Z0-9-_]+)'
|
||||||
);
|
);
|
||||||
|
global $config;
|
||||||
foreach ($routes as $pattern => $handler_name) {
|
foreach ($routes as $pattern => $handler_name) {
|
||||||
$pattern = strtr($pattern, $tokens);
|
$pattern = strtr($pattern, $tokens);
|
||||||
if (preg_match('#^/?' . $pattern . '/?$#', $path_info, $matches)) {
|
if (preg_match('#/?' . $pattern . '/?$#', $path_info, $matches)) {
|
||||||
|
if(!isset($config['baseUrls'])){
|
||||||
|
$config['baseUrls'][0] = $_SERVER['HTTP_HOST'].preg_replace('#/?'.$pattern.'/?$#', '', $path_info);
|
||||||
|
}
|
||||||
$discovered_handler = $handler_name;
|
$discovered_handler = $handler_name;
|
||||||
$regex_matches = $matches;
|
$regex_matches = $matches;
|
||||||
break;
|
break;
|
||||||
@@ -1379,9 +1379,9 @@ class Router {
|
|||||||
$handler_instance = $discovered_handler();
|
$handler_instance = $discovered_handler();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//default page
|
echo 'Router: No route'; die;
|
||||||
$handler_instance = new Server;
|
//$handler_instance = new Server;
|
||||||
$handler_instance->getHtml();
|
//$handler_instance->getHtml();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user