';
echo '';
From 2e3633872017ff7cc4a15c70c99410e439fea90d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dalibor=20Jan=C3=A1k?=
Date: Fri, 4 Mar 2016 13:20:46 +0100
Subject: [PATCH 39/74] Removed dependency of GlobalMercator class closes #74
---
tileserver.php | 172 +++++++------------------------------------------
1 file changed, 22 insertions(+), 150 deletions(-)
diff --git a/tileserver.php b/tileserver.php
index 49c12e0..cb197db 100644
--- a/tileserver.php
+++ b/tileserver.php
@@ -978,7 +978,6 @@ public function getCapabilities() {
$customtileMatrixSets = '';
//layers
- $mercator = new GlobalMercator();
foreach ($layers as $m) {
$basename = $m['basename'];
@@ -1000,10 +999,6 @@ public function getCapabilities() {
);
} else {
$tileMatrixSet = 'GoogleMapsCompatible';
-
- list( $minx, $miny ) = $mercator->LatLonToMeters($bounds[1], $bounds[0]);
- list( $maxx, $maxy ) = $mercator->LatLonToMeters($bounds[3], $bounds[2]);
- $bounds3857 = array($minx, $miny, $maxx, $maxy);
}
$wmtsHost = substr($m['tiles'][0], 0, strpos($m['tiles'][0], $m['basename']));
@@ -1129,10 +1124,12 @@ public function getCapabilities() {
$srs = 'EPSG:4326';
} else {
$srs = 'EPSG:3857';
- echo '';
}
+ $url = $this->config['protocol'] . '://' . $this->config['baseUrls'][0]
+ . '/tms/' . $basename;
+ echo '';
}
echo '';
}
@@ -1154,31 +1151,35 @@ public function getLayerCapabilities() {
$bounds = $m['bounds'];
if ($m['profile'] == 'geodetic') {
$srs = 'EPSG:4326';
- $originx = -180.0;
- $originy = -90.0;
- $initialResolution = 0.703125;
+ $initRes = 0.703125;
+ } elseif ($m['profile'] == 'custom') {
+ $srs = $m['crs'];
+ $bounds = $m['extent'];
+ if(isset($m['tile_matrix'][0]['pixel_size'][0])){
+ $initRes = $m['tile_matrix'][0]['pixel_size'][0];
+ }else{
+ $initRes = 1;
+ }
} else {
$srs = 'EPSG:3857';
- $originx = -20037508.342789;
- $originy = -20037508.342789;
- $mercator = new GlobalMercator();
- list( $minx, $miny ) = $mercator->LatLonToMeters($bounds[1], $bounds[0]);
- list( $maxx, $maxy ) = $mercator->LatLonToMeters($bounds[3], $bounds[2]);
- $bounds = array($minx, $miny, $maxx, $maxy);
- $initialResolution = 156543.03392804062;
+ $bounds = array(-20037508.34,-20037508.34,20037508.34,20037508.34);
+ $initRes = 156543.03392804062;
}
$mime = ($m['format'] == 'jpg') ? 'image/jpeg' : 'image/png';
header("Content-type: application/xml");
- echo '
+ $serviceUrl = $this->config['protocol'] . '://' . $this->config['baseUrls'][0] . '/' . $m['basename'];
+ echo '' . htmlspecialchars($title) . '' . htmlspecialchars($description) . '' . $srs . '
-
+ ';
for ($zoom = $m['minzoom']; $zoom < $m['maxzoom'] + 1; $zoom++) {
- echo '';
+ $res = $initRes / pow(2, $zoom);
+ $url = $this->config['protocol'] . '://' . $this->config['baseUrls'][0] . '/' . $m['basename'] . '/' . $zoom;
+ echo '';
}
echo'';
}
@@ -1189,135 +1190,6 @@ public function getLayerCapabilities() {
public function getTile() {
parent::renderTile($this->layer, $this->z, $this->y, $this->x, $this->ext);
}
-
-}
-
-/*
- GlobalMapTiles - part of Aggregate Map Tools
- Version 1.0
- Copyright (c) 2009 The Bivings Group
- All rights reserved.
- Author: John Bafford
-
- http://www.bivings.com/
- http://bafford.com/softare/aggregate-map-tools/
-
- Based on GDAL2Tiles / globalmaptiles.py
- Original python version Copyright (c) 2008 Klokan Petr Pridal. All rights reserved.
- http://www.klokan.cz/projects/gdal2tiles/
-
- Permission is hereby granted, free of charge, to any person obtaining a
- copy of this software and associated documentation files (the "Software"),
- to deal in the Software without restriction, including without limitation
- the rights to use, copy, modify, merge, publish, distribute, sublic ense,
- and/or sell copies of the Software, and to permit persons to whom the
- Software is furnished to do so, subject to the following conditions:
-
- The abov
- e copyright notice and this permission notice shall be included
- in all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- DEALINGS IN THE SOFTWARE.
- */
-
-class GlobalMercator {
-
- var $tileSize;
- var $initialResolution;
- var $originShift;
-
-//Initialize the TMS Global Mercator pyramid
- function __construct($tileSize = 256) {
- $this->tileSize = $tileSize;
- $this->initialResolution = 2 * M_PI * 6378137 / $this->tileSize;
-# 156543.03392804062 for tileSize 256 Pixels
- $this->originShift = 2 * M_PI * 6378137 / 2.0;
-# 20037508.342789244
- }
-
-//Converts given lat/lon in WGS84 Datum to XY in Spherical Mercator EPSG:900913
- function LatLonToMeters($lat, $lon) {
- $mx = $lon * $this->originShift / 180.0;
- $my = log(tan((90 + $lat) * M_PI / 360.0)) / (M_PI / 180.0);
-
- $my *= $this->originShift / 180.0;
-
- return array($mx, $my);
- }
-
-//Converts XY point from Spherical Mercator EPSG:900913 to lat/lon in WGS84 Datum
- function MetersToLatLon($mx, $my) {
- $lon = ($mx / $this->originShift) * 180.0;
- $lat = ($my / $this->originShift) * 180.0;
-
- $lat = 180 / M_PI * (2 * atan(exp($lat * M_PI / 180.0)) - M_PI / 2.0);
-
- return array($lat, $lon);
- }
-
-//Converts pixel coordinates in given zoom level of pyramid to EPSG:900913
- function PixelsToMeters($px, $py, $zoom) {
- $res = $this->Resolution($zoom);
- $mx = $px * $res - $this->originShift;
- $my = $py * $res - $this->originShift;
-
- return array($mx, $my);
- }
-
-//Converts EPSG:900913 to pyramid pixel coordinates in given zoom level
- function MetersToPixels($mx, $my, $zoom) {
- $res = $this->Resolution($zoom);
-
- $px = ($mx + $this->originShift) / $res;
- $py = ($my + $this->originShift) / $res;
-
- return array($px, $py);
- }
-
-//Returns a tile covering region in given pixel coordinates
- function PixelsToTile($px, $py) {
- $tx = ceil($px / $this->tileSize) - 1;
- $ty = ceil($py / $this->tileSize) - 1;
-
- return array($tx, $ty);
- }
-
-//Returns tile for given mercator coordinates
- function MetersToTile($mx, $my, $zoom) {
- list($px, $py) = $this->MetersToPixels($mx, $my, $zoom);
-
- return $this->PixelsToTile($px, $py);
- }
-
-//Returns bounds of the given tile in EPSG:900913 coordinates
- function TileBounds($tx, $ty, $zoom) {
- list($minx, $miny) = $this->PixelsToMeters($tx * $this->tileSize, $ty * $this->tileSize, $zoom);
- list($maxx, $maxy) = $this->PixelsToMeters(($tx + 1) * $this->tileSize, ($ty + 1) * $this->tileSize, $zoom);
-
- return array($minx, $miny, $maxx, $maxy);
- }
-
-//Returns bounds of the given tile in latutude/longitude using WGS84 datum
- function TileLatLonBounds($tx, $ty, $zoom) {
- $bounds = $this->TileBounds($tx, $ty, $zoom);
-
- list($minLat, $minLon) = $this->MetersToLatLon($bounds[0], $bounds[1]);
- list($maxLat, $maxLon) = $this->MetersToLatLon($bounds[2], $bounds[3]);
-
- return array($minLat, $minLon, $maxLat, $maxLon);
- }
-
-//Resolution (meters/pixel) for given zoom level (measured at Equator)
- function Resolution($zoom) {
- return $this->initialResolution / (1 < $zoom);
- }
-
}
/**
From 7320f426a14991b4eec9bf8129dfa230f38609df Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dalibor=20Jan=C3=A1k?=
Date: Fri, 4 Mar 2016 13:28:05 +0100
Subject: [PATCH 40/74] Autodetection fix or warning in router, closes #49
---
tileserver.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tileserver.php b/tileserver.php
index cb197db..ffe9c94 100644
--- a/tileserver.php
+++ b/tileserver.php
@@ -1207,7 +1207,7 @@ public static function serve($routes) {
$config['protocol'] = ( isset($_SERVER["HTTPS"]) or $_SERVER['SERVER_PORT'] == '443') ? "https" : "http";
if (!empty($_SERVER['PATH_INFO'])) {
$path_info = $_SERVER['PATH_INFO'];
- } else if (!empty($_SERVER['ORIG_PATH_INFO']) && $_SERVER['ORIG_PATH_INFO'] !== '/tileserver.php') {
+ } else if (!empty($_SERVER['ORIG_PATH_INFO']) && strpos($_SERVER['ORIG_PATH_INFO'], 'tileserver.php') === false) {
$path_info = $_SERVER['ORIG_PATH_INFO'];
} else if (!empty($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], '/tileserver.php') !== false) {
$path_info = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
@@ -1255,7 +1255,7 @@ public static function serve($routes) {
}
} else {
if (!isset($config['baseUrls'][0])) {
- $config['baseUrls'][0] = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '?';
+ $config['baseUrls'][0] = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
}
if (strpos($_SERVER['REQUEST_URI'], '=') != FALSE) {
$kvp = explode('=', $_SERVER['REQUEST_URI']);
From 709ed4ffce69733bb25bae4fa116309c27ed9b02 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dalibor=20Jan=C3=A1k?=
Date: Mon, 7 Mar 2016 14:00:29 +0100
Subject: [PATCH 41/74] Revert "Fix of utfgid detection"
This reverts commit 8f6a2ced68af2f85a4fb7882d3b9fe78c618fd75.
---
tileserver.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tileserver.php b/tileserver.php
index ffe9c94..cc5ec5d 100644
--- a/tileserver.php
+++ b/tileserver.php
@@ -600,7 +600,7 @@ public function metadataTileJson($metadata) {
$metadata['scheme'] = 'xyz';
if ($this->isDBLayer($metadata['basename'])) {
$this->DBconnect($metadata['basename'] . '.mbtiles');
- $res = $this->db->query('SELECT * FROM grids LIMIT 1;');
+ $res = $this->db->query('SELECT name FROM sqlite_master WHERE name="grids";');
if ($res) {
foreach ($this->config['baseUrls'] as $url) {
$grids[] = '' . $this->config['protocol'] . '://' . $url . '/' . $metadata['basename'] . '/{z}/{x}/{y}.grid.json';
From 8f2b068c4fa6492a416b352a3fb3e034426e0f65 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dalibor=20Jan=C3=A1k?=
Date: Mon, 7 Mar 2016 14:39:28 +0100
Subject: [PATCH 42/74] Custom template implementation #31
---
tileserver.php | 49 ++++++++++++++++++++++++++++++-------------------
1 file changed, 30 insertions(+), 19 deletions(-)
diff --git a/tileserver.php b/tileserver.php
index cc5ec5d..be05887 100644
--- a/tileserver.php
+++ b/tileserver.php
@@ -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 @@ public function __construct() {
$this->config['baseUrls'] = is_array($envBaseUrls) ?
$envBaseUrls : explode(',', $envBaseUrls);
}
+ $envTemplate = getenv('template');
+ if($envBaseUrls !== FALSE){
+ $this->config['template'] = $envTemplate;
+ }
}
/**
@@ -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 '' . $this->config['serverTitle'] . '';
- echo '
-
-
-
Welcome to ' . $this->config['serverTitle'] . '
-
This server distributes maps to desktop, web, and mobile applications.
-
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.
';
- if (!isset($maps)) {
- echo '
No maps available yet
-
- Ready to go - just upload some maps into directory:' . getcwd() . '/ on this server.
-
Note: The maps can be a directory with tiles in XYZ format with metadata.json file.
- You can easily convert existing geodata (GeoTIFF, ECW, MrSID, etc) to this tile structure with MapTiler Cluster or open-source projects such as GDAL2Tiles or MapTiler or simply upload any maps in MBTiles format made by TileMill. Helpful is also the mbutil tool. Serving directly from .mbtiles files is supported, but with decreased performance.
This server distributes maps to desktop, web, and mobile applications.
+
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.
';
+ if (!isset($maps)) {
+ echo '
No maps available yet
+
+ Ready to go - just upload some maps into directory:' . getcwd() . '/ on this server.
+
Note: The maps can be a directory with tiles in XYZ format with metadata.json file.
+ You can easily convert existing geodata (GeoTIFF, ECW, MrSID, etc) to this tile structure with MapTiler Cluster or open-source projects such as GDAL2Tiles or MapTiler or simply upload any maps in MBTiles format made by TileMill. Helpful is also the mbutil tool. Serving directly from .mbtiles files is supported, but with decreased performance.
';
+ } else {
+ echo '
';
+ foreach ($maps as $map) {
+ echo "
" . $map['name'] . '
';
+ }
+ echo '
';
}
- echo '
';
+ echo '';
}
- echo '';
}
}
From 6b4fb0fec75c9334d503207bc9cb01d990124e07 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dalibor=20Jan=C3=A1k?=
Date: Mon, 7 Mar 2016 14:57:29 +0100
Subject: [PATCH 43/74] WMTS url to tiles simplified for fastest tile serving
---
tileserver.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tileserver.php b/tileserver.php
index be05887..883e05d 100644
--- a/tileserver.php
+++ b/tileserver.php
@@ -1013,8 +1013,8 @@ public function getCapabilities() {
}
$wmtsHost = substr($m['tiles'][0], 0, strpos($m['tiles'][0], $m['basename']));
- $resourceUrlTemplate = $wmtsHost . 'wmts/' . $basename
- . '/{TileMatrixSet}/{TileMatrix}/{TileCol}/{TileRow}';
+ $resourceUrlTemplate = $wmtsHost . $basename
+ . '/{TileMatrix}/{TileCol}/{TileRow}';
if(strlen($format) <= 4){
$resourceUrlTemplate .= '.' . $format;
}
From 2dfd2fcb5fe333c9e430a38a10892edde4418619 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dalibor=20Jan=C3=A1k?=
Date: Mon, 21 Mar 2016 10:59:29 +0100
Subject: [PATCH 44/74] Max zoom of Mercator TileMatrixSet is affected with max
of layers maxzoom (closes #76)
---
tileserver.php | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/tileserver.php b/tileserver.php
index 883e05d..882cfd6 100644
--- a/tileserver.php
+++ b/tileserver.php
@@ -830,14 +830,15 @@ private function maxsample($x, $f){
/**
* Default TileMetrixSet for Pseudo Mercator projection 3857
+ * @param ?number $maxZoom
* @return string TileMatrixSet xml
*/
- public function getMercatorTileMatrixSet(){
+ public function getMercatorTileMatrixSet($maxZoom = 18){
$denominatorBase = 559082264.0287178;
$extent = array(-20037508.34,-20037508.34,20037508.34,20037508.34);
$tileMatrixSet = array();
- for($i = 0; $i <= 18; $i++){
+ for($i = 0; $i <= $maxZoom; $i++){
$matrixSize = pow(2, $i);
$tileMatrixSet[] = array(
'extent' => $extent,
@@ -1010,6 +1011,7 @@ public function getCapabilities() {
);
} else {
$tileMatrixSet = 'GoogleMapsCompatible';
+ $maxMercatorZoom = max(18, $maxMercatorZoom, $m['maxzoom']);
}
$wmtsHost = substr($m['tiles'][0], 0, strpos($m['tiles'][0], $m['basename']));
@@ -1044,7 +1046,7 @@ public function getCapabilities() {
}
// Print PseudoMercator TileMatrixSet
- echo $this->getMercatorTileMatrixSet();
+ echo $this->getMercatorTileMatrixSet($maxMercatorZoom);
// Print WGS84 TileMatrixSet
echo $this->getWGS84TileMatrixSet();
From c158bcbe57779177ae4a6204bc6c7dcc7ebdaf5a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dalibor=20Jan=C3=A1k?=
Date: Mon, 21 Mar 2016 13:40:33 +0100
Subject: [PATCH 45/74] Minor warning with some php configurations fixed.
---
tileserver.php | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/tileserver.php b/tileserver.php
index 882cfd6..2c4a37b 100644
--- a/tileserver.php
+++ b/tileserver.php
@@ -1,5 +1,8 @@
$extent,
@@ -988,6 +991,7 @@ public function getCapabilities() {
';
$customtileMatrixSets = '';
+ $maxMercatorZoom = 18;
//layers
foreach ($layers as $m) {
@@ -1011,7 +1015,7 @@ public function getCapabilities() {
);
} else {
$tileMatrixSet = 'GoogleMapsCompatible';
- $maxMercatorZoom = max(18, $maxMercatorZoom, $m['maxzoom']);
+ $maxMercatorZoom = max($maxMercatorZoom, $m['maxzoom']);
}
$wmtsHost = substr($m['tiles'][0], 0, strpos($m['tiles'][0], $m['basename']));
From bb48534fe3c2e720973c82f9dbdff792c3eaa418 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dalibor=20Jan=C3=A1k?=
Date: Mon, 21 Mar 2016 13:42:53 +0100
Subject: [PATCH 46/74] Removing of useless code.
---
tileserver.php | 3 ---
1 file changed, 3 deletions(-)
diff --git a/tileserver.php b/tileserver.php
index 2c4a37b..b2b929f 100644
--- a/tileserver.php
+++ b/tileserver.php
@@ -1,8 +1,5 @@
Date: Mon, 18 Apr 2016 21:25:38 +0300
Subject: [PATCH 47/74] Faster and ~70% smaller empty png tile
---
tileserver.php | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/tileserver.php b/tileserver.php
index b2b929f..55a1f74 100644
--- a/tileserver.php
+++ b/tileserver.php
@@ -420,10 +420,8 @@ public function getCleanTile($scale = 1, $format = 'png') {
default:
header('Access-Control-Allow-Origin: *');
header('Content-type: image/png');
- $a = '';
- for($i=1; $i < 338; $i++){$a .= 'A';}
- echo base64_decode('iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAYAAABccqhmAAABFUl'
- . 'EQVR42u3BMQEAAADCoPVP7WsIo' . $a . 'eAMBPAAB2ClDBAAAAABJRU5ErkJggg');
+ // 256x256 transparent optimised png tile
+ echo hex2bin('89504e470d0a1a0a0000000d494844520000010000000100010300000066bc3a2500000003504c5445000000a77a3dda0000000174524e530040e6d8660000001f494441541819edc1010d000000c220fba77e0e37600000000000000000e70221000001f5a2bd040000000049454e44ae426082');
break;
}
die;
From f834ec7fd9e37ef72abf9571ceecf55ac2897c96 Mon Sep 17 00:00:00 2001
From: Petr Pridal
Date: Sat, 23 Apr 2016 00:08:21 +0200
Subject: [PATCH 48/74] Deploy to OpenShift via travis
---
.travis.yml | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/.travis.yml b/.travis.yml
index 89e1027..7ce7828 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -7,3 +7,10 @@ php:
- hhvm
script:
- php tileserver.php
+deploy:
+ provider: openshift
+ user: osm2vectortiles@klokantech.com
+ secure: U6KRa+Zcflmz1Imu3cH88Svo2uEvwDXPJqXKG5j0ZzttdritF7nH9ZCu6+XHHrdeWR+KjE31QjWnywA5kp9amJIApd3EJjSkIvAPQr56t+9JXYP7d2L45jQAPXs+eaKgJWwnDELfBdAkM/ChHkmrRWM0NVDiUwvQ1wQbbipBVG8=
+ domain: tileserver
+ app: php
+ skip_cleanup: true
From 86a1c68888e3bfd1c43bcebbd3818b529cf2d0b9 Mon Sep 17 00:00:00 2001
From: Petr Pridal
Date: Sat, 23 Apr 2016 00:34:40 +0200
Subject: [PATCH 49/74] Update .travis.yml
---
.travis.yml | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/.travis.yml b/.travis.yml
index 7ce7828..6445712 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -10,7 +10,8 @@ script:
deploy:
provider: openshift
user: osm2vectortiles@klokantech.com
- secure: U6KRa+Zcflmz1Imu3cH88Svo2uEvwDXPJqXKG5j0ZzttdritF7nH9ZCu6+XHHrdeWR+KjE31QjWnywA5kp9amJIApd3EJjSkIvAPQr56t+9JXYP7d2L45jQAPXs+eaKgJWwnDELfBdAkM/ChHkmrRWM0NVDiUwvQ1wQbbipBVG8=
+ password:
+ secure: hiWKBaqh/CMdnQ2qxsRSKYAnk4tP/q2J50TaO+2sH09x+0Q85ygfICCDrEx457xqmGW0e4zZPsL83mMPvGt5KJO6g9DIncj6BFhpZA0ysnRJ3X1fczTiVN5hQfqNpa+/YIrQ0whu1Ur/IfdYTtvArYhuAPeigCloumGk9gNgSIQ=
domain: tileserver
app: php
skip_cleanup: true
From 4b53b4c351d89658fb6aa09e6aa2ae7a2f8f7afc Mon Sep 17 00:00:00 2001
From: Petr Pridal
Date: Tue, 3 May 2016 17:15:54 +0200
Subject: [PATCH 50/74] Sample MBTiles file for OpenShift deploy
---
.travis.yml | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/.travis.yml b/.travis.yml
index 6445712..703955d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -7,6 +7,12 @@ php:
- hhvm
script:
- php tileserver.php
+after_success:
+ - wget https://github.com/klokantech/tileserver-php/releases/download/v0.1/grandcanyon.mbtiles
+ - git config --global user.email "travis@localhost.localdomain"
+ - git config --global user.name "Travis CI"
+ - git add --all
+ - git commit -am "Travis change"
deploy:
provider: openshift
user: osm2vectortiles@klokantech.com
From ef5de0607dac23cb890977b9f1d037a7689888ec Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dalibor=20Jan=C3=A1k?=
Date: Tue, 3 May 2016 22:48:23 +0200
Subject: [PATCH 51/74] Unpack empty png tile PHP 5.2 compatible
---
tileserver.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tileserver.php b/tileserver.php
index 55a1f74..daa0689 100644
--- a/tileserver.php
+++ b/tileserver.php
@@ -421,7 +421,7 @@ public function getCleanTile($scale = 1, $format = 'png') {
header('Access-Control-Allow-Origin: *');
header('Content-type: image/png');
// 256x256 transparent optimised png tile
- echo hex2bin('89504e470d0a1a0a0000000d494844520000010000000100010300000066bc3a2500000003504c5445000000a77a3dda0000000174524e530040e6d8660000001f494441541819edc1010d000000c220fba77e0e37600000000000000000e70221000001f5a2bd040000000049454e44ae426082');
+ echo unpack('H', '89504e470d0a1a0a0000000d494844520000010000000100010300000066bc3a2500000003504c5445000000a77a3dda0000000174524e530040e6d8660000001f494441541819edc1010d000000c220fba77e0e37600000000000000000e70221000001f5a2bd040000000049454e44ae426082');
break;
}
die;
From c28d188e0d9dcf4376e5f0ffa6f566005dec097f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dalibor=20Jan=C3=A1k?=
Date: Tue, 3 May 2016 23:21:40 +0200
Subject: [PATCH 52/74] Empty tile response for jpg and webp
---
tileserver.php | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/tileserver.php b/tileserver.php
index daa0689..a282b00 100644
--- a/tileserver.php
+++ b/tileserver.php
@@ -416,6 +416,18 @@ public function getCleanTile($scale = 1, $format = 'png') {
header('Content-Type: application/json; charset=utf-8');
echo '{"message":"Tile does not exist"}';
break;
+ case 'webp':
+ default:
+ header('Access-Control-Allow-Origin: *');
+ header('Content-type: image/webp');
+ echo base64_decode('UklGRhIAAABXRUJQVlA4TAYAAAAvQWxvAGs=');
+ break;
+ case 'jpg':
+ default:
+ header('Access-Control-Allow-Origin: *');
+ header('Content-type: image/jpg');
+ echo base64_decode('/9j/2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkICQkKDA8MCgsOCwkJDRENDg8QEBEQCgwSExIQEw8QEBD/yQALCAABAAEBAREA/8wABgAQEAX/2gAIAQEAAD8A0s8g/9k=');
+ break;
case 'png':
default:
header('Access-Control-Allow-Origin: *');
From e4148733ed1ae179e2c820c011ed47679b33b92e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dalibor=20Jan=C3=A1k?=
Date: Tue, 3 May 2016 23:36:31 +0200
Subject: [PATCH 53/74] Empty tile response for jpg and webp
---
tileserver.php | 2 --
1 file changed, 2 deletions(-)
diff --git a/tileserver.php b/tileserver.php
index a282b00..7b3b57d 100644
--- a/tileserver.php
+++ b/tileserver.php
@@ -417,13 +417,11 @@ public function getCleanTile($scale = 1, $format = 'png') {
echo '{"message":"Tile does not exist"}';
break;
case 'webp':
- default:
header('Access-Control-Allow-Origin: *');
header('Content-type: image/webp');
echo base64_decode('UklGRhIAAABXRUJQVlA4TAYAAAAvQWxvAGs=');
break;
case 'jpg':
- default:
header('Access-Control-Allow-Origin: *');
header('Content-type: image/jpg');
echo base64_decode('/9j/2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkICQkKDA8MCgsOCwkJDRENDg8QEBEQCgwSExIQEw8QEBD/yQALCAABAAEBAREA/8wABgAQEAX/2gAIAQEAAD8A0s8g/9k=');
From f7613e04a10c2ca64e95336d4c4169962c4ad6c2 Mon Sep 17 00:00:00 2001
From: Petr Pridal
Date: Wed, 4 May 2016 19:19:33 +0200
Subject: [PATCH 54/74] Updated default title of the page
---
tileserver.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tileserver.php b/tileserver.php
index 7b3b57d..52a078b 100644
--- a/tileserver.php
+++ b/tileserver.php
@@ -8,7 +8,7 @@
*/
global $config;
-$config['serverTitle'] = 'TileServer-php v1';
+$config['serverTitle'] = 'Maps hosted with TileServer-php v2.0';
$config['availableFormats'] = array('png', 'jpg', 'jpeg', 'gif', 'webp', 'pbf', 'hybrid');
//$config['template'] = 'template.php';
//$config['baseUrls'] = array('t0.server.com', 't1.server.com');
From 058df85c2e2c5cc4b6e536ad70cd24625705a329 Mon Sep 17 00:00:00 2001
From: Petr Pridal
Date: Thu, 5 May 2016 12:18:20 +0200
Subject: [PATCH 55/74] Readme mentions MVT vector tiles (pbf requests)
---
README.md | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index c6a986c..f44f1ef 100644
--- a/README.md
+++ b/README.md
@@ -91,13 +91,13 @@ Supported protocols:
Exposed at http://[...]/tms
-- TileJSON.js
+- TileJSON
Metadata about the individual maps in a ready to use form for web
clients following the standard http://mapbox.com/developers/tilejson/
and with support for JSONP access.
- Exposed at http://[...]/layer.jsonp
+ Exposed at http://[...]/layer.json or .jsonp
- Direct access with XYZ tile requests (to existing tiles in a directory
or to .mbtiles)
@@ -113,6 +113,12 @@ Supported protocols:
Exposed at http://[...]/layer/z/x/y.grid.json
+- MapBox Vector Tiles (for MBTiles generated by [MapBox Studio Classic](https://www.mapbox.com/mapbox-studio-classic/) or by [OSM2VectorTiles](http://osm2vectortiles.org/) project).
+
+ Example http://osm2vectortiles.tileserver.com/
+ TileJSON can be used in MapBox Studio Classic, MapBox SDKs/APIs, OpenLayers, etc.
+
+ Exposed at http://[...]/layer/z/x/y.pbf
To use the OGC WMTS standard point your client (desktop or web) to the URL
of 'directory' where you installed tileserver.php project with suffix "wmts".
From 7405ec3dc3b927378df95fedf564b6f901ef58c3 Mon Sep 17 00:00:00 2001
From: Mark Furland
Date: Fri, 26 Aug 2016 11:12:43 -0400
Subject: [PATCH 56/74] 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
---
tileserver.php | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/tileserver.php b/tileserver.php
index 52a078b..87b4eb6 100644
--- a/tileserver.php
+++ b/tileserver.php
@@ -10,6 +10,7 @@
global $config;
$config['serverTitle'] = 'Maps hosted with TileServer-php v2.0';
$config['availableFormats'] = array('png', 'jpg', 'jpeg', 'gif', 'webp', 'pbf', 'hybrid');
+$config['mbtilesPrefix'] = './';
//$config['template'] = 'template.php';
//$config['baseUrls'] = array('t0.server.com', 't1.server.com');
@@ -86,7 +87,7 @@ public function __construct() {
*/
public function setDatasets() {
$mjs = glob('*/metadata.json');
- $mbts = glob('*.mbtiles');
+ $mbts = glob($this->config['mbtilesPrefix'] . '*.mbtiles');
if ($mjs) {
foreach (array_filter($mjs, 'is_readable') as $mj) {
$layer = $this->metadataFromMetadataJson($mj);
@@ -139,7 +140,7 @@ public function getGlobal($isKey) {
* @return boolean
*/
public function isDBLayer($layer) {
- if (is_file($layer . '.mbtiles')) {
+ if (is_file($this->config['mbtilesPrefix'] . $layer . '.mbtiles')) {
return TRUE;
} else {
return FALSE;
@@ -310,7 +311,7 @@ public function DBconnect($tileset) {
* @return boolean
*/
public function isModified($filename) {
- $filename = $filename . '.mbtiles';
+ $filename = $this->config['mbtilesPrefix'] . $filename . '.mbtiles';
$lastModifiedTime = filemtime($filename);
$eTag = md5($lastModifiedTime);
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $lastModifiedTime) . ' GMT');
@@ -338,7 +339,7 @@ public function renderTile($tileset, $z, $y, $x, $ext) {
header('HTTP/1.1 304 Not Modified');
die;
}
- $this->DBconnect($tileset . '.mbtiles');
+ $this->DBconnect($this->config['mbtilesPrefix'] . $tileset . '.mbtiles');
$z = floatval($z);
$y = floatval($y);
$x = floatval($x);
@@ -412,7 +413,8 @@ public function renderTile($tileset, $z, $y, $x, $ext) {
public function getCleanTile($scale = 1, $format = 'png') {
switch ($format) {
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');
echo '{"message":"Tile does not exist"}';
break;
@@ -453,7 +455,7 @@ public function renderUTFGrid($tileset, $z, $y, $x, $flip = TRUE) {
$y = pow(2, $z) - 1 - $y;
}
try {
- $this->DBconnect($tileset . '.mbtiles');
+ $this->DBconnect($this->config['mbtilesPrefix'] . $tileset . '.mbtiles');
$query = 'SELECT grid FROM grids WHERE tile_column = ' . $x . ' AND '
. 'tile_row = ' . $y . ' AND zoom_level = ' . $z;
@@ -618,7 +620,7 @@ public function metadataTileJson($metadata) {
$metadata['tilejson'] = '2.0.0';
$metadata['scheme'] = 'xyz';
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";');
if ($res) {
foreach ($this->config['baseUrls'] as $url) {
@@ -1147,7 +1149,7 @@ public function getCapabilities() {
} else {
$srs = 'EPSG:3857';
}
- $url = $this->config['protocol'] . '://' . $this->config['baseUrls'][0]
+ $url = $this->config['protocol'] . '://' . $this->config['baseUrls'][0]
. '/tms/' . $basename;
echo '
Date: Mon, 29 Aug 2016 19:06:51 +0200
Subject: [PATCH 57/74] Rename mbtilesPrefix to dataRoot
---
tileserver.php | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/tileserver.php b/tileserver.php
index 87b4eb6..8c57f41 100644
--- a/tileserver.php
+++ b/tileserver.php
@@ -10,7 +10,7 @@
global $config;
$config['serverTitle'] = 'Maps hosted with TileServer-php v2.0';
$config['availableFormats'] = array('png', 'jpg', 'jpeg', 'gif', 'webp', 'pbf', 'hybrid');
-$config['mbtilesPrefix'] = './';
+$config['dataRoot'] = '';
//$config['template'] = 'template.php';
//$config['baseUrls'] = array('t0.server.com', 't1.server.com');
@@ -87,7 +87,7 @@ public function __construct() {
*/
public function setDatasets() {
$mjs = glob('*/metadata.json');
- $mbts = glob($this->config['mbtilesPrefix'] . '*.mbtiles');
+ $mbts = glob($this->config['dataRoot'] . '*.mbtiles');
if ($mjs) {
foreach (array_filter($mjs, 'is_readable') as $mj) {
$layer = $this->metadataFromMetadataJson($mj);
@@ -140,7 +140,7 @@ public function getGlobal($isKey) {
* @return boolean
*/
public function isDBLayer($layer) {
- if (is_file($this->config['mbtilesPrefix'] . $layer . '.mbtiles')) {
+ if (is_file($this->config['dataRoot'] . $layer . '.mbtiles')) {
return TRUE;
} else {
return FALSE;
@@ -311,7 +311,7 @@ public function DBconnect($tileset) {
* @return boolean
*/
public function isModified($filename) {
- $filename = $this->config['mbtilesPrefix'] . $filename . '.mbtiles';
+ $filename = $this->config['dataRoot'] . $filename . '.mbtiles';
$lastModifiedTime = filemtime($filename);
$eTag = md5($lastModifiedTime);
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $lastModifiedTime) . ' GMT');
@@ -339,7 +339,7 @@ public function renderTile($tileset, $z, $y, $x, $ext) {
header('HTTP/1.1 304 Not Modified');
die;
}
- $this->DBconnect($this->config['mbtilesPrefix'] . $tileset . '.mbtiles');
+ $this->DBconnect($this->config['dataRoot'] . $tileset . '.mbtiles');
$z = floatval($z);
$y = floatval($y);
$x = floatval($x);
@@ -455,7 +455,7 @@ public function renderUTFGrid($tileset, $z, $y, $x, $flip = TRUE) {
$y = pow(2, $z) - 1 - $y;
}
try {
- $this->DBconnect($this->config['mbtilesPrefix'] . $tileset . '.mbtiles');
+ $this->DBconnect($this->config['dataRoot'] . $tileset . '.mbtiles');
$query = 'SELECT grid FROM grids WHERE tile_column = ' . $x . ' AND '
. 'tile_row = ' . $y . ' AND zoom_level = ' . $z;
@@ -620,7 +620,7 @@ public function metadataTileJson($metadata) {
$metadata['tilejson'] = '2.0.0';
$metadata['scheme'] = 'xyz';
if ($this->isDBLayer($metadata['basename'])) {
- $this->DBconnect($this->config['mbtilesPrefix'] . $metadata['basename'] . '.mbtiles');
+ $this->DBconnect($this->config['dataRoot'] . $metadata['basename'] . '.mbtiles');
$res = $this->db->query('SELECT name FROM sqlite_master WHERE name="grids";');
if ($res) {
foreach ($this->config['baseUrls'] as $url) {
From d7a4ad03c1a36a41e2347a0af86e7f0ff147d99f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dalibor=20Jan=C3=A1k?=
Date: Tue, 6 Dec 2016 17:58:22 +0100
Subject: [PATCH 58/74] Use https with X-Forwarded-Proto (issue #92)
---
tileserver.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tileserver.php b/tileserver.php
index 8c57f41..68d27e5 100644
--- a/tileserver.php
+++ b/tileserver.php
@@ -1228,7 +1228,7 @@ public static function serve($routes) {
$request_method = strtolower($_SERVER['REQUEST_METHOD']);
$path_info = '/';
global $config;
- $config['protocol'] = ( isset($_SERVER["HTTPS"]) or $_SERVER['SERVER_PORT'] == '443') ? "https" : "http";
+ $config['protocol'] = ((isset($_SERVER['HTTPS']) or $_SERVER['SERVER_PORT'] == '443') or $_SERVER['X-Forwarded-Proto']) == 'https' ? 'https' : 'http';
if (!empty($_SERVER['PATH_INFO'])) {
$path_info = $_SERVER['PATH_INFO'];
} else if (!empty($_SERVER['ORIG_PATH_INFO']) && strpos($_SERVER['ORIG_PATH_INFO'], 'tileserver.php') === false) {
From 758b6a1e4de2370ad28395562d86aef53e19f2ac Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dalibor=20Jan=C3=A1k?=
Date: Tue, 6 Dec 2016 18:10:06 +0100
Subject: [PATCH 59/74] Fix of X-Forwarded-Proto server variable (issue #92)
---
tileserver.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tileserver.php b/tileserver.php
index 68d27e5..877030a 100644
--- a/tileserver.php
+++ b/tileserver.php
@@ -1228,7 +1228,7 @@ public static function serve($routes) {
$request_method = strtolower($_SERVER['REQUEST_METHOD']);
$path_info = '/';
global $config;
- $config['protocol'] = ((isset($_SERVER['HTTPS']) or $_SERVER['SERVER_PORT'] == '443') or $_SERVER['X-Forwarded-Proto']) == 'https' ? 'https' : 'http';
+ $config['protocol'] = ((isset($_SERVER['HTTPS']) or $_SERVER['SERVER_PORT'] == '443') or $_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https' ? 'https' : 'http';
if (!empty($_SERVER['PATH_INFO'])) {
$path_info = $_SERVER['PATH_INFO'];
} else if (!empty($_SERVER['ORIG_PATH_INFO']) && strpos($_SERVER['ORIG_PATH_INFO'], 'tileserver.php') === false) {
From 5f314fef28a38d21fa4b83fa050f60c50632d63a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dalibor=20Jan=C3=A1k?=
Date: Tue, 6 Dec 2016 23:18:30 +0100
Subject: [PATCH 60/74] Fixed bug in condition with X-Forwarded-Proto
---
tileserver.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tileserver.php b/tileserver.php
index 877030a..0018538 100644
--- a/tileserver.php
+++ b/tileserver.php
@@ -1228,7 +1228,7 @@ public static function serve($routes) {
$request_method = strtolower($_SERVER['REQUEST_METHOD']);
$path_info = '/';
global $config;
- $config['protocol'] = ((isset($_SERVER['HTTPS']) or $_SERVER['SERVER_PORT'] == '443') or $_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https' ? 'https' : 'http';
+ $config['protocol'] = ((isset($_SERVER['HTTPS']) or $_SERVER['SERVER_PORT'] == '443') or $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') ? 'https' : 'http';
if (!empty($_SERVER['PATH_INFO'])) {
$path_info = $_SERVER['PATH_INFO'];
} else if (!empty($_SERVER['ORIG_PATH_INFO']) && strpos($_SERVER['ORIG_PATH_INFO'], 'tileserver.php') === false) {
From dc2452e781fee4708c2be2fe8364950116bd9a4c Mon Sep 17 00:00:00 2001
From: Matt Burke
Date: Thu, 6 Apr 2017 10:27:04 -0400
Subject: [PATCH 61/74] Fixed issue where tiles are not loaded if
HTTP_X_FORWARDED_PROTO is unset.
---
tileserver.php | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/tileserver.php b/tileserver.php
index 0018538..7b21dcb 100644
--- a/tileserver.php
+++ b/tileserver.php
@@ -65,7 +65,7 @@ class Server {
*/
public function __construct() {
$this->config = $GLOBALS['config'];
-
+
//Get config from enviroment
$envServerTitle = getenv('serverTitle');
if($envServerTitle !== FALSE){
@@ -73,7 +73,7 @@ public function __construct() {
}
$envBaseUrls = getenv('baseUrls');
if($envBaseUrls !== FALSE){
- $this->config['baseUrls'] = is_array($envBaseUrls) ?
+ $this->config['baseUrls'] = is_array($envBaseUrls) ?
$envBaseUrls : explode(',', $envBaseUrls);
}
$envTemplate = getenv('template');
@@ -1228,7 +1228,13 @@ public static function serve($routes) {
$request_method = strtolower($_SERVER['REQUEST_METHOD']);
$path_info = '/';
global $config;
- $config['protocol'] = ((isset($_SERVER['HTTPS']) or $_SERVER['SERVER_PORT'] == '443') or $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') ? 'https' : 'http';
+ $xForwarded = false;
+ if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
+ if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
+ $xForwarded = true;
+ }
+ }
+ $config['protocol'] = ((isset($_SERVER['HTTPS']) or $_SERVER['SERVER_PORT'] == '443') or $xForwarded) ? 'https' : 'http';
if (!empty($_SERVER['PATH_INFO'])) {
$path_info = $_SERVER['PATH_INFO'];
} else if (!empty($_SERVER['ORIG_PATH_INFO']) && strpos($_SERVER['ORIG_PATH_INFO'], 'tileserver.php') === false) {
From bb823a57ffc1c16713f3602e8df4ae967c4a3233 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dalibor=20Jan=C3=A1k?=
Date: Mon, 24 Apr 2017 15:26:57 +0200
Subject: [PATCH 62/74] 0.
---
.travis.yml | 2 ++
1 file changed, 2 insertions(+)
diff --git a/.travis.yml b/.travis.yml
index 703955d..06810c2 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -4,6 +4,8 @@ php:
- 5.4
- 5.5
- 5.6
+ - 7.0
+ - 7.1
- hhvm
script:
- php tileserver.php
From f75b1bbfa6a177b4c9290f488bfd82a206969b11 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dalibor=20Jan=C3=A1k?=
Date: Tue, 5 Dec 2017 15:31:40 +0100
Subject: [PATCH 63/74] Don't need trailing slash in dataroot
---
tileserver.php | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/tileserver.php b/tileserver.php
index 7b21dcb..98093d0 100644
--- a/tileserver.php
+++ b/tileserver.php
@@ -66,6 +66,11 @@ class Server {
public function __construct() {
$this->config = $GLOBALS['config'];
+ if($this->config['dataRoot'] != ''
+ && substr($this->config['dataRoot'], -1) != '/' ){
+ $this->config['dataRoot'] .= '/';
+ }
+
//Get config from enviroment
$envServerTitle = getenv('serverTitle');
if($envServerTitle !== FALSE){
From d3ebdec555098e0fc8d62a09636c69ff31ebd641 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dalibor=20Jan=C3=A1k?=
Date: Mon, 19 Feb 2018 15:52:48 +0100
Subject: [PATCH 64/74] Strip incorrectly encoded property in OMT datasets
---
tileserver.php | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/tileserver.php b/tileserver.php
index 98093d0..3827fd2 100644
--- a/tileserver.php
+++ b/tileserver.php
@@ -637,7 +637,9 @@ public function metadataTileJson($metadata) {
if (array_key_exists('json', $metadata)) {
$mjson = json_decode(stripslashes($metadata['json']));
foreach ($mjson as $key => $value) {
- $metadata[$key] = $value;
+ if ($key != 'Layer'){
+ $metadata[$key] = $value;
+ }
}
unset($metadata['json']);
}
From e6af62e1919c9d3e7daf0c82e0a72875bde8de83 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dalibor=20Jan=C3=A1k?=
Date: Mon, 19 Feb 2018 15:59:44 +0100
Subject: [PATCH 65/74] Remove PHP 5.3 check from travis
---
.travis.yml | 1 -
1 file changed, 1 deletion(-)
diff --git a/.travis.yml b/.travis.yml
index 06810c2..dd8f16a 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,6 +1,5 @@
language: php
php:
- - 5.3
- 5.4
- 5.5
- 5.6
From dca0e642191e08097e66ed920a51dc68ec682d1c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dalibor=20Jan=C3=A1k?=
Date: Mon, 19 Feb 2018 16:15:14 +0100
Subject: [PATCH 66/74] Removed unused var in router
---
tileserver.php | 1 -
1 file changed, 1 deletion(-)
diff --git a/tileserver.php b/tileserver.php
index 3827fd2..6813e8d 100644
--- a/tileserver.php
+++ b/tileserver.php
@@ -1232,7 +1232,6 @@ class Router {
* @param array $routes
*/
public static function serve($routes) {
- $request_method = strtolower($_SERVER['REQUEST_METHOD']);
$path_info = '/';
global $config;
$xForwarded = false;
From 2a84c6271f732687e06ab71ca252cfc6a5425790 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dalibor=20Jan=C3=A1k?=
Date: Mon, 19 Feb 2018 16:31:18 +0100
Subject: [PATCH 67/74] Fix Undefined index SERVER_PORT router error in some
server configs
---
tileserver.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tileserver.php b/tileserver.php
index 6813e8d..350603e 100644
--- a/tileserver.php
+++ b/tileserver.php
@@ -1240,7 +1240,7 @@ public static function serve($routes) {
$xForwarded = true;
}
}
- $config['protocol'] = ((isset($_SERVER['HTTPS']) or $_SERVER['SERVER_PORT'] == '443') or $xForwarded) ? 'https' : 'http';
+ $config['protocol'] = ((isset($_SERVER['HTTPS']) or (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443)) or $xForwarded) ? 'https' : 'http';
if (!empty($_SERVER['PATH_INFO'])) {
$path_info = $_SERVER['PATH_INFO'];
} else if (!empty($_SERVER['ORIG_PATH_INFO']) && strpos($_SERVER['ORIG_PATH_INFO'], 'tileserver.php') === false) {
From 5ddbfa300a8bc84746ee3c19abba6b3638bca3d3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dalibor=20Jan=C3=A1k?=
Date: Mon, 2 Jul 2018 11:45:46 +0200
Subject: [PATCH 68/74] Updated readme with tile size, closes #129 and custom
CRS
---
README.md | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
index f44f1ef..d8dbec9 100644
--- a/README.md
+++ b/README.md
@@ -119,6 +119,9 @@ Supported protocols:
TileJSON can be used in MapBox Studio Classic, MapBox SDKs/APIs, OpenLayers, etc.
Exposed at http://[...]/layer/z/x/y.pbf
+
+- Retina / HighDPI routing with 512 tiles
+Use @2x suffix in url for JSONs and tiles. For example http://tileserver.maptiler.com/grandcanyon@2x.json
To use the OGC WMTS standard point your client (desktop or web) to the URL
of 'directory' where you installed tileserver.php project with suffix "wmts".
@@ -137,9 +140,12 @@ GetTile RESTful/KVP:
http://[...]/layer/[ANYTHING-OPTIONAL][z]/[x]/[y].[ext]
http://[...]?service=wmts&request=getTile&layer=[layer]&tilematrix=[z]&tilerow=[y]&tilecol=[y]&format=[ext]
-
+
Other example requests are mentioned in the .htaccess.
+TileServer-PHP supports all coordinates system. You have to define it with tilejson with specification on https://github.com/klokantech/tilejson-spec/tree/custom-projection/2.2.0
+Or use MapTiler to produce datasets with this specification.
+
Performance from the web clients
--------------------------------
@@ -174,9 +180,6 @@ Limits of actual implementation
-------------------------------
With intention, in this moment the project supports only:
-- Mercator tiles (a la OpenStreetMap) and Geodetic tiles (WGS84 unprojected)
- with known and described tiling scheme.
-- All tiles must be 256x256 pixels.
- We enforce and require XYZ (top-left origin) tiling schema (even for TMS).
Password protection
From d11963d43c28dab5be202bfd1586ad259b628ad7 Mon Sep 17 00:00:00 2001
From: Isaac Besora Vilardaga
Date: Mon, 7 Jan 2019 14:01:19 +0100
Subject: [PATCH 69/74] Removes body data from http 204 response
---
tileserver.php | 1 -
1 file changed, 1 deletion(-)
diff --git a/tileserver.php b/tileserver.php
index 350603e..ea730dc 100644
--- a/tileserver.php
+++ b/tileserver.php
@@ -421,7 +421,6 @@ public function getCleanTile($scale = 1, $format = 'png') {
header('Access-Control-Allow-Origin: *');
header('HTTP/1.1 204 No Content');
header('Content-Type: application/json; charset=utf-8');
- echo '{"message":"Tile does not exist"}';
break;
case 'webp':
header('Access-Control-Allow-Origin: *');
From 4c339b8d195b9842804199f073c869610d351b4d Mon Sep 17 00:00:00 2001
From: CodeLingoBot
Date: Wed, 3 Apr 2019 11:24:50 +1300
Subject: [PATCH 70/74] Change PHP keywords to comply with PSR2
Signed-off-by: CodeLingoBot
---
tileserver.php | 46 +++++++++++++++++++++++-----------------------
1 file changed, 23 insertions(+), 23 deletions(-)
diff --git a/tileserver.php b/tileserver.php
index ea730dc..d26b2d2 100644
--- a/tileserver.php
+++ b/tileserver.php
@@ -73,16 +73,16 @@ public function __construct() {
//Get config from enviroment
$envServerTitle = getenv('serverTitle');
- if($envServerTitle !== FALSE){
+ if($envServerTitle !== false){
$this->config['serverTitle'] = $envServerTitle;
}
$envBaseUrls = getenv('baseUrls');
- if($envBaseUrls !== FALSE){
+ if($envBaseUrls !== false){
$this->config['baseUrls'] = is_array($envBaseUrls) ?
$envBaseUrls : explode(',', $envBaseUrls);
}
$envTemplate = getenv('template');
- if($envBaseUrls !== FALSE){
+ if($envBaseUrls !== false){
$this->config['template'] = $envTemplate;
}
}
@@ -120,7 +120,7 @@ public function setParams($params) {
$this->x = $params[1];
$file = explode('.', $params[0]);
$this->y = $file[0];
- $this->ext = isset($file[1]) ? $file[1] : NULL;
+ $this->ext = isset($file[1]) ? $file[1] : null;
}
}
@@ -136,7 +136,7 @@ public function getGlobal($isKey) {
return $value;
}
}
- return FALSE;
+ return false;
}
/**
@@ -146,9 +146,9 @@ public function getGlobal($isKey) {
*/
public function isDBLayer($layer) {
if (is_file($this->config['dataRoot'] . $layer . '.mbtiles')) {
- return TRUE;
+ return true;
} else {
- return FALSE;
+ return false;
}
}
@@ -159,9 +159,9 @@ public function isDBLayer($layer) {
*/
public function isFileLayer($layer) {
if (is_dir($layer)) {
- return TRUE;
+ return true;
} else {
- return FALSE;
+ return false;
}
}
@@ -323,9 +323,9 @@ public function isModified($filename) {
header('Etag:' . $eTag);
if (@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $lastModifiedTime ||
@trim($_SERVER['HTTP_IF_NONE_MATCH']) == $eTag) {
- return TRUE;
+ return true;
} else {
- return FALSE;
+ return false;
}
}
@@ -339,7 +339,7 @@ public function isModified($filename) {
*/
public function renderTile($tileset, $z, $y, $x, $ext) {
if ($this->isDBLayer($tileset)) {
- if ($this->isModified($tileset) == TRUE) {
+ if ($this->isModified($tileset) == true) {
header('Access-Control-Allow-Origin: *');
header('HTTP/1.1 304 Not Modified');
die;
@@ -354,17 +354,17 @@ public function renderTile($tileset, $z, $y, $x, $ext) {
}
$result = $this->db->query('select tile_data as t from tiles where zoom_level=' . $z . ' and tile_column=' . $x . ' and tile_row=' . $y);
$data = $result->fetchColumn();
- if (!isset($data) || $data === FALSE) {
+ if (!isset($data) || $data === false) {
//if tile doesn't exist
//select scale of tile (for retina tiles)
$result = $this->db->query('select value from metadata where name="scale"');
$resultdata = $result->fetchColumn();
- $scale = isset($resultdata) && $resultdata !== FALSE ? $resultdata : 1;
+ $scale = isset($resultdata) && $resultdata !== false ? $resultdata : 1;
$this->getCleanTile($scale, $ext);
} else {
$result = $this->db->query('select value from metadata where name="format"');
$resultdata = $result->fetchColumn();
- $format = isset($resultdata) && $resultdata !== FALSE ? $resultdata : 'png';
+ $format = isset($resultdata) && $resultdata !== false ? $resultdata : 'png';
if ($format == 'jpg') {
$format = 'jpeg';
}
@@ -380,11 +380,11 @@ public function renderTile($tileset, $z, $y, $x, $ext) {
} elseif ($this->isFileLayer($tileset)) {
$name = './' . $tileset . '/' . $z . '/' . $x . '/' . $y;
$mime = 'image/';
- if($ext != NULL){
+ if($ext != null){
$name .= '.' . $ext;
}
if ($fp = @fopen($name, 'rb')) {
- if($ext != NULL){
+ if($ext != null){
$mime .= $ext;
}else{
//detect image type from file
@@ -450,9 +450,9 @@ public function getCleanTile($scale = 1, $format = 'png') {
* @param integer $y
* @param integer $x
*/
- public function renderUTFGrid($tileset, $z, $y, $x, $flip = TRUE) {
+ public function renderUTFGrid($tileset, $z, $y, $x, $flip = true) {
if ($this->isDBLayer($tileset)) {
- if ($this->isModified($tileset) == TRUE) {
+ if ($this->isModified($tileset) == true) {
header('HTTP/1.1 304 Not Modified');
}
if ($flip) {
@@ -466,7 +466,7 @@ public function renderUTFGrid($tileset, $z, $y, $x, $flip = TRUE) {
$result = $this->db->query($query);
$data = $result->fetch(PDO::FETCH_ASSOC);
- if ($data !== FALSE) {
+ if ($data !== false) {
$grid = gzuncompress($data['grid']);
$grid = substr(trim($grid), 0, -1);
@@ -756,7 +756,7 @@ public function __construct($params) {
*/
public function get() {
$request = $this->getGlobal('Request');
- if ($request !== FALSE && $request == 'gettile') {
+ if ($request !== false && $request == 'gettile') {
$this->getTile();
} else {
parent::setDatasets();
@@ -1079,7 +1079,7 @@ public function getCapabilities() {
public function getTile() {
$request = $this->getGlobal('Request');
if ($request) {
- if (strpos('/', $_GET['Format']) !== FALSE) {
+ if (strpos('/', $_GET['Format']) !== false) {
$format = explode('/', $_GET['Format']);
$format = $format[1];
} else {
@@ -1292,7 +1292,7 @@ public static function serve($routes) {
if (!isset($config['baseUrls'][0])) {
$config['baseUrls'][0] = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
}
- if (strpos($_SERVER['REQUEST_URI'], '=') != FALSE) {
+ if (strpos($_SERVER['REQUEST_URI'], '=') != false) {
$kvp = explode('=', $_SERVER['REQUEST_URI']);
$_GET['callback'] = $kvp[1];
$params[0] = 'index';
From 54254f8ef1bd279c95ac9846029a7fa85bc1495c Mon Sep 17 00:00:00 2001
From: Jorgen
Date: Thu, 11 Jul 2019 13:27:21 +0200
Subject: [PATCH 71/74] Resolved bug in transparent png tile
---
tileserver.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
mode change 100644 => 100755 tileserver.php
diff --git a/tileserver.php b/tileserver.php
old mode 100644
new mode 100755
index d26b2d2..96f53a0
--- a/tileserver.php
+++ b/tileserver.php
@@ -437,7 +437,7 @@ public function getCleanTile($scale = 1, $format = 'png') {
header('Access-Control-Allow-Origin: *');
header('Content-type: image/png');
// 256x256 transparent optimised png tile
- echo unpack('H', '89504e470d0a1a0a0000000d494844520000010000000100010300000066bc3a2500000003504c5445000000a77a3dda0000000174524e530040e6d8660000001f494441541819edc1010d000000c220fba77e0e37600000000000000000e70221000001f5a2bd040000000049454e44ae426082');
+ echo pack('H*', '89504e470d0a1a0a0000000d494844520000010000000100010300000066bc3a2500000003504c5445000000a77a3dda0000000174524e530040e6d8660000001f494441541819edc1010d000000c220fba77e0e37600000000000000000e70221000001f5a2bd040000000049454e44ae426082');
break;
}
die;
From 43e3cadb8768d718def5e43067767ec5420296c3 Mon Sep 17 00:00:00 2001
From: Dalibor Janak
Date: Tue, 28 Jul 2020 22:34:22 +0200
Subject: [PATCH 72/74] Remove old aray syntax
---
README.md | 42 ++++++++++++------------
tileserver.php | 86 +++++++++++++++++++++++++-------------------------
2 files changed, 64 insertions(+), 64 deletions(-)
diff --git a/README.md b/README.md
index d8dbec9..ce2e32c 100644
--- a/README.md
+++ b/README.md
@@ -41,7 +41,7 @@ Requirements:
-------------
- Apache webserver (with mod_rewrite / .htaccess supported)
-- PHP 5.2+ with SQLite module (php5-sqlite)
+- PHP 5.6+ with SQLite module (php5-sqlite)
(or another webserver implementing mod_rewrite rules and PHP)
@@ -50,7 +50,7 @@ Installation:
Download the project files as a [zip archive](https://github.com/klokantech/tileserver-php/archive/master.zip) or source code from GitHub and unpack it into a web-hosting of your choice.
-If you access the web address relevant to the installation directory,
+If you access the web address relevant to the installation directory,
the TileServer.php Server should display you a welcome message and further
instructions.
@@ -70,15 +70,15 @@ Supported protocols:
--------------------
- OpenGIS WMTS 1.0.0
-
+
The Open Geospatial Consortium (OGC) Web Map Tile Service (WMTS)
Both KVP and RESTful version 1.0.0:
http://www.opengeospatial.org/standards/wmts/
-
+
Target is maximal compliance to the standard.
-
+
Exposed at http://[...]/wmts
-
+
- OSGeo TMS 1.0.0
The OSGeo Tile Maps Service, but with inverted y-coordinates:
@@ -90,7 +90,7 @@ Supported protocols:
flipped y-axis.
Exposed at http://[...]/tms
-
+
- TileJSON
Metadata about the individual maps in a ready to use form for web
@@ -98,28 +98,28 @@ Supported protocols:
and with support for JSONP access.
Exposed at http://[...]/layer.json or .jsonp
-
+
- Direct access with XYZ tile requests (to existing tiles in a directory
or to .mbtiles)
Compatible with Google Maps API / Bing SDK / OpenStreetMap clients.
-
+
Exposed at http://[...]/layer/z/x/y.ext
-
-- MapBox UTFgrid request (for existing tiles in .mbtiles with UTFgrid support). Callback is supported
+
+- MapBox UTFgrid request (for existing tiles in .mbtiles with UTFgrid support). Callback is supported
Example https://www.mapbox.com/demo/visiblemap/
Specification https://github.com/mapbox/utfgrid-spec
-
+
Exposed at http://[...]/layer/z/x/y.grid.json
-
+
- MapBox Vector Tiles (for MBTiles generated by [MapBox Studio Classic](https://www.mapbox.com/mapbox-studio-classic/) or by [OSM2VectorTiles](http://osm2vectortiles.org/) project).
Example http://osm2vectortiles.tileserver.com/
TileJSON can be used in MapBox Studio Classic, MapBox SDKs/APIs, OpenLayers, etc.
Exposed at http://[...]/layer/z/x/y.pbf
-
+
- Retina / HighDPI routing with 512 tiles
Use @2x suffix in url for JSONs and tiles. For example http://tileserver.maptiler.com/grandcanyon@2x.json
@@ -132,12 +132,12 @@ If you have installed the project into a root directory of a domain, then the ad
The supported WMTS requests includes:
GetCapabilities RESTful/KVP:
-
+
http://[...]/1.0.0/WMTSCapabilities.xml
http://[...]?service=wmts&request=getcapabilities&version=1.0.0
-
+
GetTile RESTful/KVP:
-
+
http://[...]/layer/[ANYTHING-OPTIONAL][z]/[x]/[y].[ext]
http://[...]?service=wmts&request=getTile&layer=[layer]&tilematrix=[z]&tilerow=[y]&tilecol=[y]&format=[ext]
@@ -248,17 +248,17 @@ Tested WMTS/TMS clients
BSD License
-----------
-Copyright (C) 2015 Klokan Technologies GmbH (http://www.klokantech.com/)
+Copyright (C) 2020 MapTiler AG (https://www.maptiler.com/)
All rights reserved.
Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
+modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
- list of conditions and the following disclaimer.
+ list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
+ and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
diff --git a/tileserver.php b/tileserver.php
index d26b2d2..7270ce6 100644
--- a/tileserver.php
+++ b/tileserver.php
@@ -1,20 +1,20 @@
'Server:getHtml',
'/maps' => 'Server:getInfo',
'/html' => 'Server:getHtml',
@@ -29,7 +29,7 @@
'/:alpha/:number/:number/:alpha' => 'Wmts:getTile',
'/tms' => 'Tms:getCapabilities',
'/tms/:alpha' => 'Tms:getLayerCapabilities',
-));
+]);
/**
* Server base
@@ -46,13 +46,13 @@ class Server {
* Datasets stored in file structure
* @var array
*/
- public $fileLayer = array();
+ public $fileLayer = [];
/**
* Datasets stored in database
* @var array
*/
- public $dbLayer = array();
+ public $dbLayer = [];
/**
* PDO database connection
@@ -182,7 +182,7 @@ public function metadataFromMetadataJson($jsonFileName) {
* @return object
*/
public function metadataFromMbtiles($mbt) {
- $metadata = array();
+ $metadata = [];
$this->DBconnect($mbt);
$result = $this->db->query('select * from metadata');
@@ -220,7 +220,7 @@ public function metadataFromMbtiles($mbt) {
$e = -180 + 360 * ((1 + $resultdata[0]['e']) / pow(2, $metadata['maxzoom']));
$n = $this->row2lat($resultdata[0]['n'], $metadata['maxzoom']);
$s = $this->row2lat($resultdata[0]['s'] - 1, $metadata['maxzoom']);
- $metadata['bounds'] = implode(',', array($w, $s, $e, $n));
+ $metadata['bounds'] = implode(',', [$w, $s, $e, $n]);
}
$mbt = explode('.', $mbt);
$metadata['basename'] = $mbt[0];
@@ -246,7 +246,7 @@ public function row2lat($r, $zoom) {
*/
public function metadataValidation($metadata) {
if (!array_key_exists('bounds', $metadata)) {
- $metadata['bounds'] = array(-180, -85.06, 180, 85.06);
+ $metadata['bounds'] = [-180, -85.06, 180, 85.06];
} elseif (!is_array($metadata['bounds'])) {
$metadata['bounds'] = array_map('floatval', explode(',', $metadata['bounds']));
}
@@ -277,7 +277,7 @@ public function metadataValidation($metadata) {
$metadata['scale'] = 1;
}
if(!array_key_exists('tiles', $metadata)){
- $tiles = array();
+ $tiles = [];
foreach ($this->config['baseUrls'] as $url) {
$url = '' . $this->config['protocol'] . '://' . $url . '/' .
$metadata['basename'] . '/{z}/{x}/{y}';
@@ -297,7 +297,7 @@ public function metadataValidation($metadata) {
*/
public function DBconnect($tileset) {
try {
- $this->db = new PDO('sqlite:' . $tileset, '', '', array(PDO::ATTR_PERSISTENT => true));
+ $this->db = new PDO('sqlite:' . $tileset, '', '', [PDO::ATTR_PERSISTENT => true]);
} catch (Exception $exc) {
echo $exc->getTraceAsString();
die;
@@ -388,7 +388,7 @@ public function renderTile($tileset, $z, $y, $x, $ext) {
$mime .= $ext;
}else{
//detect image type from file
- $mimetypes = array('gif', 'jpeg', 'png');
+ $mimetypes = ['gif', 'jpeg', 'png'];
$mime .= $mimetypes[exif_imagetype($name) - 1];
}
header('Access-Control-Allow-Origin: *');
@@ -792,15 +792,15 @@ public function parseTileMatrix($layer, $tileMatrix){
$tileMatrix[$i]['pixel_size'],
$tileMatrix[$i]['tile_size']
);
- $tileMatrix[$i]['matrix_size'] = array(
+ $tileMatrix[$i]['matrix_size'] = [
$tileExtent[2] + 1,
$tileExtent[1] + 1
- );
+ ];
}
if(!isset($tileMatrix[$i]['origin']) && isset($tileMatrix[$i]['extent'])){
- $tileMatrix[$i]['origin'] = array(
+ $tileMatrix[$i]['origin'] = [
$tileMatrix[$i]['extent'][0], $tileMatrix[$i]['extent'][3]
- );
+ ];
}
// Origins of geographic coordinate systems are setting in opposite order
if (isset($proj4) && $proj4['proj'] === 'longlat') {
@@ -811,7 +811,7 @@ public function parseTileMatrix($layer, $tileMatrix){
}
if(!isset($tileMatrix[$i]['tile_size'])){
$tileSize = 256 * (int) $layer['scale'];
- $tileMatrix[$i]['tile_size'] = array($tileSize, $tileSize);
+ $tileMatrix[$i]['tile_size'] = [$tileSize, $tileSize];
}
}
@@ -827,12 +827,12 @@ public function parseTileMatrix($layer, $tileMatrix){
* @return array
*/
public function tilesOfExtent($extent, $origin, $pixel_size, $tile_size) {
- $tiles = array(
+ $tiles = [
$this->minsample($extent[0] - $origin[0], $pixel_size[0] * $tile_size[0]),
$this->minsample($extent[1] - $origin[1], $pixel_size[1] * $tile_size[1]),
$this->maxsample($extent[2] - $origin[0], $pixel_size[0] * $tile_size[0]),
$this->maxsample($extent[3] - $origin[1], $pixel_size[1] * $tile_size[1]),
- );
+ ];
return $tiles;
}
@@ -851,19 +851,19 @@ private function maxsample($x, $f){
*/
public function getMercatorTileMatrixSet($maxZoom = 18){
$denominatorBase = 559082264.0287178;
- $extent = array(-20037508.34,-20037508.34,20037508.34,20037508.34);
- $tileMatrixSet = array();
+ $extent = [-20037508.34,-20037508.34,20037508.34,20037508.34];
+ $tileMatrixSet = [];
for($i = 0; $i <= $maxZoom; $i++){
$matrixSize = pow(2, $i);
- $tileMatrixSet[] = array(
+ $tileMatrixSet[] = [
'extent' => $extent,
'id' => (string) $i,
- 'matrix_size' => array($matrixSize, $matrixSize),
- 'origin' => array($extent[0], $extent[3]),
+ 'matrix_size' => [$matrixSize, $matrixSize],
+ 'origin' => [$extent[0], $extent[3]],
'scale_denominator' => $denominatorBase / pow(2, $i),
- 'tile_size' => array(256, 256)
- );
+ 'tile_size' => [256, 256]
+ ];
}
return $this->getTileMatrixSet('GoogleMapsCompatible', $tileMatrixSet, 'EPSG:3857');
@@ -874,26 +874,26 @@ public function getMercatorTileMatrixSet($maxZoom = 18){
* @return string Xml
*/
public function getWGS84TileMatrixSet(){
- $extent = array(-180.000000, -90.000000, 180.000000, 90.000000);
- $scaleDenominators = array(279541132.01435887813568115234, 139770566.00717943906784057617,
+ $extent = [-180.000000, -90.000000, 180.000000, 90.000000];
+ $scaleDenominators = [279541132.01435887813568115234, 139770566.00717943906784057617,
69885283.00358971953392028809, 34942641.50179485976696014404, 17471320.75089742988348007202,
8735660.37544871494174003601, 4367830.18772435747087001801, 2183915.09386217873543500900,
1091957.54693108936771750450, 545978.77346554468385875225, 272989.38673277234192937613,
136494.69336638617096468806, 68247.34668319308548234403, 34123.67334159654274117202,
17061.83667079825318069197, 8530.91833539912659034599, 4265.45916769956329517299,
- 2132.72958384978574031265);
- $tileMatrixSet = array();
+ 2132.72958384978574031265];
+ $tileMatrixSet = [];
for($i = 0; $i <= 17; $i++){
$matrixSize = pow(2, $i);
- $tileMatrixSet[] = array(
+ $tileMatrixSet[] = [
'extent' => $extent,
'id' => (string) $i,
- 'matrix_size' => array($matrixSize * 2, $matrixSize),
- 'origin' => array($extent[3], $extent[0]),
+ 'matrix_size' => [$matrixSize * 2, $matrixSize],
+ 'origin' => [$extent[3], $extent[0]],
'scale_denominator' => $scaleDenominators[$i],
- 'tile_size' => array(256, 256)
- );
+ 'tile_size' => [256, 256]
+ ];
}
return $this->getTileMatrixSet('WGS84', $tileMatrixSet, 'EPSG:4326');
@@ -1192,7 +1192,7 @@ public function getLayerCapabilities() {
}
} else {
$srs = 'EPSG:3857';
- $bounds = array(-20037508.34,-20037508.34,20037508.34,20037508.34);
+ $bounds = [-20037508.34,-20037508.34,20037508.34,20037508.34];
$initRes = 156543.03392804062;
}
$mime = ($m['format'] == 'jpg') ? 'image/jpeg' : 'image/png';
@@ -1253,14 +1253,14 @@ public static function serve($routes) {
}
}
$discovered_handler = null;
- $regex_matches = array();
+ $regex_matches = [];
if ($routes) {
- $tokens = array(
+ $tokens = [
':string' => '([a-zA-Z]+)',
':number' => '([0-9]+)',
':alpha' => '([a-zA-Z0-9-_@\.]+)'
- );
+ ];
//global $config;
foreach ($routes as $pattern => $handler_name) {
$pattern = strtr($pattern, $tokens);
@@ -1281,7 +1281,7 @@ public static function serve($routes) {
$discoverered_class = explode(':', $discovered_handler);
$discoverered_method = explode(':', $discovered_handler);
$handler_instance = new $discoverered_class[0]($regex_matches);
- call_user_func(array($handler_instance, $discoverered_method[1]));
+ call_user_func([$handler_instance, $discoverered_method[1]]);
} else {
$handler_instance = new $discovered_handler($regex_matches);
}
From 7800af830a5f56c2d9aba30d2fc925284253839b Mon Sep 17 00:00:00 2001
From: David Eagles
Date: Fri, 24 Sep 2021 11:09:17 +1000
Subject: [PATCH 73/74] Modified WMTS Resource URL generation to support
hostnames that contain the layer name.
If the hostname contained the layer name (eg. https://layername.domain.com/layername/wmts) then the WMTS capabilities document contained an incorrect Resource URL because the hostname was stripped back to simply https://. This modification simply looks for the last occurrence of the layer name instead of the first when forming the Resource URL.
---
tileserver.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tileserver.php b/tileserver.php
index 7397e01..d4e12d4 100755
--- a/tileserver.php
+++ b/tileserver.php
@@ -1031,7 +1031,7 @@ public function getCapabilities() {
$maxMercatorZoom = max($maxMercatorZoom, $m['maxzoom']);
}
- $wmtsHost = substr($m['tiles'][0], 0, strpos($m['tiles'][0], $m['basename']));
+ $wmtsHost = substr($m['tiles'][0], 0, strrpos($m['tiles'][0], $m['basename']));
$resourceUrlTemplate = $wmtsHost . $basename
. '/{TileMatrix}/{TileCol}/{TileRow}';
if(strlen($format) <= 4){
From d0fdeaec69688dc500b652a23669d724d7d53df2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ji=C5=99=C3=AD=20Kom=C3=A1rek?=
Date: Sat, 30 Jul 2022 02:03:50 +0200
Subject: [PATCH 74/74] grammar check
---
README.md | 94 +++++++++++++++++++------------------------------------
1 file changed, 33 insertions(+), 61 deletions(-)
diff --git a/README.md b/README.md
index ce2e32c..89e756d 100644
--- a/README.md
+++ b/README.md
@@ -4,36 +4,23 @@ TileServer PHP: MapTiler and MBTiles maps via WMTS
[![Build Status](https://travis-ci.org/klokantech/tileserver-php.svg)](https://travis-ci.org/klokantech/tileserver-php)
[![Docker Hub](https://img.shields.io/badge/docker-hub-blue.svg)](https://hub.docker.com/r/klokantech/tileserver-php/)
-This server distributes maps to desktop, web, and mobile applications from
-a standard Apache+PHP web hosting.
+This server distributes maps to desktop, web, and mobile applications from a standard Apache+PHP web hosting.
-Try a live demo at: http://tileserver.maptiler.com/
+It is a free and open-source project implementing the OGC WMTS standard for pre-rendered map tiles made with any [map tiling software](https://www.maptiler.com/desktop/) like MapTiler Desktop, GDAL2Tiles, or any other MBTiles file.
-It is a free and open-source project implementing OGC WMTS standard for
-pre-rendered map tiles made with [MapTiler](http://www.maptiler.com/), GDAL2Tiles,
-or available as MBTiles files.
+It is the easiest and cheapest way how to serve zoomable maps in a standardized way - practically from any ordinary web hosting.
-It is the easiest and cheapest way how to serve zoomable maps in a
-standardized way - practically from any ordinary web hosting.
+It is easy to install - copy the project files to a PHP-enabled directory along with your map data.
-It is easy to install - just copy the project files to a PHP-enabled
-directory along with your map data.
-
-It comes with an online interface showing the list of the maps and step-by-step guides for online mapping libraries (Google Maps API, Leaflet, OpenLayers, OL3, MapBox JS, ArcGIS JS) and various desktop GIS software:
+It comes with an online interface showing the list of the maps and step-by-step guides for online mapping libraries (Google Maps API, Leaflet, OpenLayers, OL3, MapLibre GL JS, ArcGIS JS) and various desktop GIS software:
![tileserver-screenshot](https://f.cloud.github.com/assets/59284/1041807/a040160c-0fdb-11e3-8941-ab367b2a648d.png)
-This project is developed in PHP, not because it is the best language for
-development of web applications, but because it maximally simplify the
-deployment on large number of web hosting providers including various free
-web hostings.
+This project is developed in PHP, not because it is the best language for the development of web applications, but because it maximally simplifies the deployment on a large number of web hostings, including various free web hostings providers.
-Tiles are served directly by Apache with mod_rewrite rules as static files
-and therefore are very fast and with correct HTTP caching headers.
-Only XML metadata are delivered via PHP.
-MBTiles are served via PHP, and are therfore slower, unless they are unpacked with mbutil.
+Tiles are served directly by Apache with mod_rewrite rules as static files and therefore are very fast and with correct HTTP caching headers. Only XML metadata is delivered via PHP. MBTiles are served via PHP and are therefore slower unless they are unpacked with mbutil.
-[MapTiler](http://www.maptiler.com/) can render GeoTIFF, ECW, MrSID, GeoPDF into compatible map tiles. JPEG, PNG, GIF and TIFF with scanned maps or images without geolocation can be turned into standard map layers with the visual georeferencing functionality (http://youtu.be/eJxdCe9CNYg).
+[MapTiler](http://www.maptiler.com/) can render GeoTIFF, ECW, MrSID, GeoPDF into compatible map tiles. JPEG, PNG, GIF, and TIFF with scanned maps or images without geolocation can be turned into standard map layers with the visual georeferencing functionality (http://youtu.be/eJxdCe9CNYg).
[![MapTiler - mapping tiles](https://cloud.githubusercontent.com/assets/59284/3037911/583d7810-e0c6-11e3-877c-6a7747b80dd3.jpg)](http://www.maptiler.com/)
@@ -50,21 +37,13 @@ Installation:
Download the project files as a [zip archive](https://github.com/klokantech/tileserver-php/archive/master.zip) or source code from GitHub and unpack it into a web-hosting of your choice.
-If you access the web address relevant to the installation directory,
-the TileServer.php Server should display you a welcome message and further
-instructions.
+If you access the web address relevant to the installation directory, the TileServer.php Server should display you a welcome message and further instructions.
-Then you can upload to the web hosting your mapping data - a directory with
-tiles rendered with [MapTiler](http://www.maptiler.com/).
+Then you can upload to the web hosting your mapping data - a directory with tiles rendered with [MapTiler](http://www.maptiler.com/).
-Tiles produced by open-source GDAL2Tiles or MapTiler and tiles in .mbtiles
-files can be easily converted to required structure (XYZ with top-left origin
-and metadata.json file). The open-source utility [mbutil](https://github.com/mapbox/mbutil) produces
-exactly the required format.
+Tiles produced by open-source GDAL2Tiles or MapTiler Desktop and tiles in .mbtiles format can be easily converted to the required structure (XYZ with top-left origin and metadata.json file). The open-source utility [mbutil](https://github.com/mapbox/mbutil) produces exactly the required format.
-Direct reading of .mbtiles files is supported, but with decreased performance
-compared to the static files in a directory. The advantage is easier data management,
-especially upload over FTP or similar protocols.
+Direct reading of .mbtiles files is supported but with decreased performance compared to the static files in a directory. The advantage is easier data management, especially upload over FTP or similar protocols.
Supported protocols:
--------------------
@@ -123,8 +102,7 @@ Supported protocols:
- Retina / HighDPI routing with 512 tiles
Use @2x suffix in url for JSONs and tiles. For example http://tileserver.maptiler.com/grandcanyon@2x.json
-To use the OGC WMTS standard point your client (desktop or web) to the URL
-of 'directory' where you installed tileserver.php project with suffix "wmts".
+To use the OGC WMTS standard, point your client (desktop or web) to the URL of 'directory' where you installed tileserver.php project with suffix "wmts".
For example: http://www.example.com/directory/wmts
If you have installed the project into a root directory of a domain, then the address is: http://www.example.com/wmts
@@ -143,43 +121,35 @@ GetTile RESTful/KVP:
Other example requests are mentioned in the .htaccess.
-TileServer-PHP supports all coordinates system. You have to define it with tilejson with specification on https://github.com/klokantech/tilejson-spec/tree/custom-projection/2.2.0
+TileServer-PHP supports all coordinates systems. You have to define it with tilejson with specification on https://github.com/klokantech/tilejson-spec/tree/custom-projection/2.2.0
Or use MapTiler to produce datasets with this specification.
Performance from the web clients
--------------------------------
It is highly recommended to map several domain names to the service, such as:
+
http://a.example.com/, http://b.example.com/, http://c.example.com/.
-This can be done with DNS CNAME records pointing to your hosting.
-The reason for this is that traditionally browsers will not send more then two
-simultaneous http request to the same domain - with multiple domains for the
-same server you can better saturate the network and receive the maps faster.
+
+This can be done with DNS CNAME records pointing to your hosting. The reason for this is that traditionally browsers will not send more than two simultaneous HTTP requests to the same domain - with multiple domains for the same server, you can better saturate the network and receive the maps faster.
Performance
-----------
-In case the data are available in a form of directory with XYZ tiles, then
-Apache webserver is serving these files directly as WMTS RESTful or KVP.
+In case the data are available in the form of a directory with XYZ tiles, then the Apache webserver is serving these files directly as WMTS RESTful or KVP.
-This means performance is excellent, maps are delivered very fast and large
-number of concurrent visitors can be handled even with quite a low-end
-hardware or cheap/free web hosting providers.
+This means performance is excellent, maps are delivered very fast, and a large number of concurrent visitors can be handled even with quite low-end hardware or cheap/free web hosting providers.
-Mod_rewrite rules are utilized to ensure the HTTP requests defined in the OCG
-WMTS standard are served, and Apache preserve standard caching headers & eTag.
+Mod_rewrite rules are utilized to ensure the HTTP requests defined in the OCG WMTS standard are served, and Apache preserves standard caching headers & eTag.
-The performance should be significantly better then performance of any other
-tile caching project (such as TileCache.org or GeoWebCache).
+The performance should be significantly better than any other tile caching project (such as TileCache.org or GeoWebCache).
-Performance graph for "apache static" comparing other tile caching projects
-is available online at:
-http://code.google.com/p/mod-geocache/wiki/PreliminaryBenchmark
+Performance graph for "apache static" comparing other tile caching projects is available online at http://code.google.com/p/mod-geocache/wiki/PreliminaryBenchmark
Limits of actual implementation
-------------------------------
-With intention, in this moment the project supports only:
+With intention, at this moment, the project supports only:
- We enforce and require XYZ (top-left origin) tiling schema (even for TMS).
Password protection
@@ -210,22 +180,19 @@ TileServer.php can run without any problems over HTTPS, if required.
Microsoft Windows web-hosting
-----------------------------
-The TileServer.php should run on Windows-powered webservers with Apache
-installation if PHP 5.2+ and mod_rewrite are available.
+The TileServer.php should run on Windows-powered webservers with Apache installation if PHP 5.2+ and mod_rewrite are available.
-With the IIS webserver hosting, you may need PHP and IIRF module
-(http://iirf.codeplex.com/) and alter appropriately the rewrite rules.
+With the IIS webserver hosting, you may need PHP and IIRF module (http://iirf.codeplex.com/) and alter appropriately the rewrite rules.
Credits / Contributors
----------------------
-Project developed initially by Klokan Technologies GmbH, Switzerland in
-cooperation with National Oceanic and Atmospheric Administration - NOAA, USA.
+Project developed initially by Klokan Technologies GmbH, Switzerland, in cooperation with National Oceanic and Atmospheric Administration - NOAA, USA.
-- Petr Pridal - Klokan Technologies GmbH
+- Petr Pridal - Klokan Technologies GmbH
- Jason Woolard - NOAA
- Jon Sellars - NOAA
-- Dalibor Janak - Klokan Technologies GmbH
+- Dalibor Janak - Klokan Technologies GmbH
Tested WMTS/TMS clients
-----------------------
@@ -244,6 +211,11 @@ Tested WMTS/TMS clients
http://www.thecarbonproject.com/gaia.php
- MapBox.js - the loading of maps via TileJSON, interaction layer supported
https://www.mapbox.com/mapbox.js
+
+Alternative
+-----------
+
+If you need [map server with commercial support](https://www.maptiler.com/server/), explore the possibilities provided by the MapTiler Server.
BSD License
-----------