mirror of
https://github.com/klokantech/tileserver-php.git
synced 2025-08-24 15:12:59 +02:00
Compare commits
29 Commits
v1
...
vectortile
Author | SHA1 | Date | |
---|---|---|---|
|
f9e801849e | ||
|
e66e577d5d | ||
|
ffedfde75e | ||
|
dd8d884bc6 | ||
|
8b4a5142e8 | ||
|
53b379cd67 | ||
|
2bf8bf6d4b | ||
|
e4454b12be | ||
|
8002dbbb7d | ||
|
d4121d86d5 | ||
|
ea6e176ab3 | ||
|
b13b8d98c8 | ||
|
f08d72262d | ||
|
4250eff554 | ||
|
34ffddb765 | ||
|
5d2662a6a3 | ||
|
8dec7469f1 | ||
|
8170e02397 | ||
|
779e320dec | ||
|
e226ae2cc3 | ||
|
61c866a521 | ||
|
987f01c85e | ||
|
ed19c0a414 | ||
|
04a9abf170 | ||
|
c3e9b41110 | ||
|
6c840820f0 | ||
|
d4c1996815 | ||
|
3181142368 | ||
|
5fca96fd91 |
34
.htaccess
34
.htaccess
@@ -1,27 +1,33 @@
|
||||
# tileserver.php integration with Apache via .htaccess
|
||||
|
||||
# Restrictions for data crawlers
|
||||
#Options -Indexes
|
||||
|
||||
# Optional CORS header for cross-domain origin access to all data
|
||||
#<ifModule mod_headers.c>
|
||||
# Header set Access-Control-Allow-Origin *
|
||||
#</ifModule>
|
||||
|
||||
# Mapping of the WMTS standardized URLs to real files and XML capabilities to tileserver.php
|
||||
|
||||
#check htaccess functionality
|
||||
DirectoryIndex tileserver.php
|
||||
|
||||
RewriteEngine on
|
||||
|
||||
#some hostings require RewriteBase e.g. 1&1.com
|
||||
# Option: some hostings require RewriteBase e.g. 1&1.com
|
||||
#RewriteBase /
|
||||
#RewriteBase /server/
|
||||
#RewriteBase /directory/
|
||||
|
||||
#some hostings require -MultiViews e.g. 1&1.com
|
||||
# Option: some hostings require -MultiViews e.g. 1&1.com
|
||||
#Options -MultiViews
|
||||
|
||||
# Option: Restrictions for data crawlers
|
||||
#Options -Indexes
|
||||
|
||||
# Option: CORS header for cross-domain origin access to all data
|
||||
#<ifModule mod_headers.c>
|
||||
# Header set Access-Control-Allow-Origin *
|
||||
#</ifModule>
|
||||
|
||||
# Block direct downloading of .mbtiles
|
||||
<FilesMatch "\.mbtiles$">
|
||||
Order Allow,Deny
|
||||
Deny from all
|
||||
</FilesMatch>
|
||||
|
||||
# Mapping of the WMTS standardized URLs to real files and XML capabilities to tileserver.php
|
||||
|
||||
# WMTS RESTful
|
||||
# ------------
|
||||
# The file can be accessed directly:
|
||||
@@ -69,4 +75,4 @@ RewriteRule .* - [E=HTTP_IF_NONE_MATCH:%{HTTP:If-None-Match}]
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteCond $1 !^(tileserver\.php)
|
||||
RewriteRule ^(.*)$ tileserver.php?/$1 [L,QSA]
|
||||
RewriteRule ^(.*)$ tileserver.php?/$1 [L,QSA]
|
||||
|
60
README.md
60
README.md
@@ -1,10 +1,11 @@
|
||||
=================================================
|
||||
TileServer PHP - OGC Web Map Tiling Server (WMTS)
|
||||
=================================================
|
||||
TileServer PHP: MapTiler and MBTiles maps via WMTS
|
||||
==================================================
|
||||
|
||||
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 OGC WMTS standard for
|
||||
pre-rendered map tiles made with [MapTiler](http://www.maptiler.com/), GDAL2Tiles,
|
||||
or available as MBTiles files.
|
||||
@@ -13,9 +14,9 @@ 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 - just copy the project files to a PHP-enabled
|
||||
directory along with your map data containing metadata.json file.
|
||||
directory along with your map data.
|
||||
|
||||
It comes with an online interface showing the list of the maps and step-by-step guides for 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, MapBox JS, ArcGIS JS) and various desktop GIS software:
|
||||
|
||||

|
||||
|
||||
@@ -27,7 +28,11 @@ web hostings.
|
||||
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, unless they are unpacked with mbutil.
|
||||
MBTiles are served via PHP, and are therfore 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).
|
||||
|
||||
[](http://www.maptiler.com/)
|
||||
|
||||
Requirements:
|
||||
-------------
|
||||
@@ -40,8 +45,7 @@ Requirements:
|
||||
Installation:
|
||||
-------------
|
||||
|
||||
Download the project files as a zip archive or source code from GitHub and
|
||||
unpack it into a web-hosting of your choice.
|
||||
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
|
||||
@@ -52,14 +56,12 @@ 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 OpenSource utility mbutil (https://github.com/mapbox/mbutil) produces
|
||||
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. Therefore the data management,
|
||||
especially upload over FTP or similar protocols, is easier.
|
||||
compared to the static files in a directory. The advantage is easier data management,
|
||||
especially upload over FTP or similar protocols.
|
||||
|
||||
Supported protocols:
|
||||
--------------------
|
||||
@@ -109,15 +111,11 @@ Supported protocols:
|
||||
Exposed at http://[...]/layer/z/x/y.grid.json
|
||||
|
||||
|
||||
To use the OGC WMTS services point your client (desktop or web) to the URL
|
||||
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
|
||||
|
||||
You can also install the project into a root directory of a virtual server:
|
||||
Then the address is: http://www.example.com/wmts
|
||||
|
||||
Similarly for another end points.
|
||||
If you have installed the project into a root directory of a domain, then the address is: http://www.example.com/wmts
|
||||
|
||||
The supported WMTS requests includes:
|
||||
|
||||
@@ -131,7 +129,7 @@ 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]
|
||||
|
||||
Another example requests are mentioned in the .htaccess.
|
||||
Other example requests are mentioned in the .htaccess.
|
||||
|
||||
Performance from the web clients
|
||||
--------------------------------
|
||||
@@ -178,10 +176,10 @@ Password protection
|
||||
HTTP Simple Authentication can be easily added to the server.
|
||||
Edit the .htaccess and add these lines:
|
||||
|
||||
AuthUserFile /full/path/to/.htpasswd
|
||||
AuthType Basic
|
||||
AuthName "Secure WMTS"
|
||||
Require valid-user
|
||||
AuthUserFile /full/path/to/.htpasswd
|
||||
AuthType Basic
|
||||
AuthName "Secure WMTS"
|
||||
Require valid-user
|
||||
|
||||
Create a file called .htpasswd with user:password format.
|
||||
You can use a command-line utility:
|
||||
@@ -212,9 +210,10 @@ Credits / Contributors
|
||||
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@klokantech.com>
|
||||
Jason Woolard - NOAA <jason.woolard@noaa.gov>
|
||||
Jon Sellars - NOAA <jon.sellars@noaa.gov>
|
||||
- Petr Pridal - Klokan Technologies GmbH <petr.pridal@klokantech.com>
|
||||
- Jason Woolard - NOAA <jason.woolard@noaa.gov>
|
||||
- Jon Sellars - NOAA <jon.sellars@noaa.gov>
|
||||
- Dalibor Janak - Klokan Technologies GmbH <dalibor.janak@klokantech.com>
|
||||
|
||||
Tested WMTS/TMS clients
|
||||
-----------------------
|
||||
@@ -223,18 +222,21 @@ Tested WMTS/TMS clients
|
||||
http://www.qgis.org/
|
||||
- ESRI ArcGIS Desktop 10.1+ - native WMTS implementation supported
|
||||
http://www.esri.com/software/arcgis/arcgis-for-desktop
|
||||
- ESRI ArcGIS Online - loading via WMTS protocol
|
||||
http://www.arcgis.com/
|
||||
- ArcBruTiles plugin for ArcGIS 9.3+ - via TMS endpoint
|
||||
http://arcbrutile.codeplex.com/
|
||||
- OpenLayers WMTS Layer - including parsing GetCapabilities
|
||||
http://www.openlayers.org/
|
||||
- GAIA - native WMTS (issues with 3857 to be fixed)
|
||||
http://www.thecarbonproject.com/gaia.php
|
||||
- MapBox.js - the loading of maps via TileJSON
|
||||
- MapBox.js - the loading of maps via TileJSON, interaction layer supported
|
||||
https://www.mapbox.com/mapbox.js
|
||||
|
||||
BSD License
|
||||
-----------
|
||||
|
||||
Copyright (C) 2012 Klokan Technologies GmbH
|
||||
Copyright (C) 2015 Klokan Technologies GmbH (http://www.klokantech.com/)
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
|
161
tileserver.php
161
tileserver.php
@@ -71,13 +71,13 @@ class Server {
|
||||
$mjs = glob('*/metadata.json');
|
||||
$mbts = glob('*.mbtiles');
|
||||
if ($mjs) {
|
||||
foreach ($mjs as $mj) {
|
||||
foreach (array_filter($mjs, 'is_readable') as $mj) {
|
||||
$layer = $this->metadataFromMetadataJson($mj);
|
||||
array_push($this->fileLayer, $layer);
|
||||
}
|
||||
}
|
||||
if ($mbts) {
|
||||
foreach ($mbts as $mbt) {
|
||||
foreach (array_filter($mbts, 'is_readable') as $mbt) {
|
||||
$this->dbLayer[] = $this->metadataFromMbtiles($mbt);
|
||||
}
|
||||
}
|
||||
@@ -167,13 +167,54 @@ class Server {
|
||||
|
||||
$resultdata = $result->fetchAll();
|
||||
foreach ($resultdata as $r) {
|
||||
$metadata[$r['name']] = $r['value'];
|
||||
$value = preg_replace('/(\\n)+/','',$r['value']);
|
||||
$metadata[$r['name']] = addslashes($value);
|
||||
}
|
||||
if (!array_key_exists('minzoom', $metadata)
|
||||
|| !array_key_exists('maxzoom', $metadata)
|
||||
) {
|
||||
// autodetect minzoom and maxzoom
|
||||
$result = $this->db->query('select min(zoom_level) as min, max(zoom_level) as max from tiles');
|
||||
$resultdata = $result->fetchAll();
|
||||
if (!array_key_exists('minzoom', $metadata))
|
||||
$metadata['minzoom'] = $resultdata[0]['min'];
|
||||
if (!array_key_exists('maxzoom', $metadata))
|
||||
$metadata['maxzoom'] = $resultdata[0]['max'];
|
||||
}
|
||||
// autodetect format using JPEG magic number FFD8
|
||||
if (!array_key_exists('format', $metadata)) {
|
||||
$result = $this->db->query('select hex(substr(tile_data,1,2)) as magic from tiles limit 1');
|
||||
$resultdata = $result->fetchAll();
|
||||
$metadata['format'] = ($resultdata[0]['magic'] == 'FFD8')
|
||||
? 'jpg'
|
||||
: 'png';
|
||||
}
|
||||
// autodetect bounds
|
||||
if (!array_key_exists('bounds', $metadata)) {
|
||||
$result = $this->db->query('select min(tile_column) as w, max(tile_column) as e, min(tile_row) as s, max(tile_row) as n from tiles where zoom_level='.$metadata['maxzoom']);
|
||||
$resultdata = $result->fetchAll();
|
||||
$w = -180 + 360 * ($resultdata[0]['w'] / pow(2,$metadata['maxzoom']));
|
||||
$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 = $this->metadataValidation($metadata);
|
||||
$mbt = explode('.', $mbt);
|
||||
$metadata['basename'] = $mbt[0];
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert row number to latitude of the top of the row
|
||||
* @param integer $r
|
||||
* @param integer $zoom
|
||||
* @return integer
|
||||
*/
|
||||
public function row2lat($r, $zoom) {
|
||||
$y = $r / pow(2,$zoom-1) - 1;
|
||||
return rad2deg(2.0 * atan(exp(3.191459196*$y)) - 1.57079632679489661922);
|
||||
}
|
||||
|
||||
/**
|
||||
* Valids metaJSON
|
||||
@@ -182,7 +223,6 @@ class Server {
|
||||
*/
|
||||
public function metadataValidation($metadata) {
|
||||
if (array_key_exists('bounds', $metadata)) {
|
||||
// TODO: Calculate bounds from tiles if bounds is missing - with GlobalMercator
|
||||
$metadata['bounds'] = array_map('floatval', explode(',', $metadata['bounds']));
|
||||
} else {
|
||||
$metadata['bounds'] = array(-180, -85.051128779807, 180, 85.051128779807);
|
||||
@@ -190,8 +230,7 @@ class Server {
|
||||
if (!array_key_exists('profile', $metadata)) {
|
||||
$metadata['profile'] = 'mercator';
|
||||
}
|
||||
// TODO: detect format, minzoom, maxzoom, thumb
|
||||
// scandir() for directory / SQL for mbtiles
|
||||
// TODO: detect thumb / SQL for mbtiles
|
||||
if (array_key_exists('minzoom', $metadata))
|
||||
$metadata['minzoom'] = intval($metadata['minzoom']);
|
||||
else
|
||||
@@ -203,11 +242,6 @@ class Server {
|
||||
if (!array_key_exists('format', $metadata)) {
|
||||
$metadata['format'] = 'png';
|
||||
}
|
||||
/*
|
||||
if (!array_key_exists('thumb', $metadata )) {
|
||||
$metadata['profile'] = 'mercator';
|
||||
}
|
||||
*/
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
@@ -257,9 +291,10 @@ class Server {
|
||||
* @param integer $x
|
||||
* @param string $ext
|
||||
*/
|
||||
public function getTile($tileset, $z, $y, $x, $ext) {
|
||||
public function renderTile($tileset, $z, $y, $x, $ext) {
|
||||
if ($this->isDBLayer($tileset)) {
|
||||
if ($this->isModified($tileset) == TRUE) {
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header('HTTP/1.1 304 Not Modified');
|
||||
die;
|
||||
}
|
||||
@@ -274,7 +309,11 @@ class Server {
|
||||
$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) {
|
||||
$this->getCleanTile();
|
||||
//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;
|
||||
$this->getCleanTile($scale);
|
||||
} else {
|
||||
$result = $this->db->query('select value from metadata where name="format"');
|
||||
$resultdata = $result->fetchColumn();
|
||||
@@ -282,33 +321,55 @@ class Server {
|
||||
if ($format == 'jpg') {
|
||||
$format = 'jpeg';
|
||||
}
|
||||
header('Content-type: image/' . $format);
|
||||
if ($format == 'pbf') {
|
||||
header('Content-type: application/x-protobuf');
|
||||
header('Content-Encoding:gzip');
|
||||
} else {
|
||||
header('Content-type: image/' . $format);
|
||||
}
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
echo $data;
|
||||
}
|
||||
} elseif ($this->isFileLayer($tileset)) {
|
||||
$name = './' . $tileset . '/' . $z . '/' . $x . '/' . $y . '.' . $ext;
|
||||
if ($fp = @fopen($name, 'rb')) {
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header('Content-Type: image/' . $ext);
|
||||
header('Content-Length: ' . filesize($name));
|
||||
fpassthru($fp);
|
||||
die;
|
||||
} else {
|
||||
$this->getCleanTile();
|
||||
//scale of tile (for retina tiles)
|
||||
$meta = json_decode(file_get_contents($tileset.'/metadata.json'));
|
||||
if(!isset($meta->scale)){
|
||||
$meta->scale = 1;
|
||||
}
|
||||
if ($ext == 'pbf') {
|
||||
header('HTTP/1.1 404 Not Found');
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
echo '{"message":"Tile does not exist"}';
|
||||
die;
|
||||
}
|
||||
$this->getCleanTile($meta->scale);
|
||||
}
|
||||
} else {
|
||||
echo 'Server: Unknown or not specified dataset';
|
||||
header('HTTP/1.1 404 Not Found');
|
||||
echo 'Server: Unknown or not specified dataset "'.$tileset.'"';
|
||||
die;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns clean tile
|
||||
* @param integer $scale Default 1
|
||||
*/
|
||||
public function getCleanTile() {
|
||||
$png = imagecreatetruecolor(256, 256);
|
||||
public function getCleanTile($scale = 1) {
|
||||
$tileSize = 256 * $scale;
|
||||
$png = imagecreatetruecolor($tileSize, $tileSize);
|
||||
imagesavealpha($png, true);
|
||||
$trans_colour = imagecolorallocatealpha($png, 0, 0, 0, 127);
|
||||
imagefill($png, 0, 0, $trans_colour);
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header('Content-type: image/png');
|
||||
imagepng($png);
|
||||
die;
|
||||
@@ -321,7 +382,7 @@ class Server {
|
||||
* @param integer $y
|
||||
* @param integer $x
|
||||
*/
|
||||
public function getUTFGrid($tileset, $z, $y, $x, $flip = TRUE) {
|
||||
public function renderUTFGrid($tileset, $z, $y, $x, $flip = TRUE) {
|
||||
if ($this->isDBLayer($tileset)) {
|
||||
if ($this->isModified($tileset) == TRUE) {
|
||||
header('HTTP/1.1 304 Not Modified');
|
||||
@@ -373,14 +434,15 @@ class Server {
|
||||
* Returns server info
|
||||
*/
|
||||
public function getInfo() {
|
||||
// echo $this->config['baseUrls'][0];die;
|
||||
$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></head><body>';
|
||||
echo '<h1>' . $this->config['serverTitle'] . '</h1>';
|
||||
echo 'TileJSON service: <a href="' . $this->config['baseUrls'][0] . '/index.json">' . $this->config['baseUrls'][0] . '/index.json</a><br>';
|
||||
echo 'WMTS service: <a href="' . $this->config['baseUrls'][0] . '/wmts">' . $this->config['baseUrls'][0] . '/wmts</a><br>';
|
||||
echo 'TMS service: <a href="' . $this->config['baseUrls'][0] . '/tms">' . $this->config['baseUrls'][0] . '/tms</a>';
|
||||
echo 'TileJSON service: <a href="//' . $this->config['baseUrls'][0] . '/index.json">' . $this->config['baseUrls'][0] . '/index.json</a><br>';
|
||||
echo 'WMTS service: <a href="//' . $this->config['baseUrls'][0] . '/wmts">' . $this->config['baseUrls'][0] . '/wmts</a><br>';
|
||||
echo 'TMS service: <a href="//' . $this->config['baseUrls'][0] . '/tms">' . $this->config['baseUrls'][0] . '/tms</a>';
|
||||
foreach ($maps as $map) {
|
||||
$extend = '[';
|
||||
foreach ($map['bounds'] as $ext) {
|
||||
@@ -392,7 +454,7 @@ class Server {
|
||||
} else {
|
||||
echo '<p>Available file tileset: ' . $map['basename'] . '<br>';
|
||||
}
|
||||
echo 'Metadata: <a href="' . $this->config['baseUrls'][0] . '/' . $map['basename'] . '.json">'
|
||||
echo 'Metadata: <a href="//' . $this->config['baseUrls'][0] . '/' . $map['basename'] . '.json">'
|
||||
. $this->config['baseUrls'][0] . '/' . $map['basename'] . '.json</a><br>';
|
||||
echo 'Bounds: ' . $extend . '</p>';
|
||||
}
|
||||
@@ -410,7 +472,7 @@ class Server {
|
||||
echo '<!DOCTYPE html><html><head><meta charset="UTF-8"><title>' . $this->config['serverTitle'] . '</title>';
|
||||
echo '<link rel="stylesheet" type="text/css" href="//tileserver.com/v1/index.css" />
|
||||
<script src="//tileserver.com/v1/index.js"></script><body>
|
||||
<script>tileserver({index:"http://' . $this->config['baseUrls'][0] . '/index.json", tilejson:"http://' . $this->config['baseUrls'][0] . '/%n.json", tms:"http://' . $this->config['baseUrls'][0] . '/tms", wmts:"http://' . $this->config['baseUrls'][0] . '/wmts"});</script>
|
||||
<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>';
|
||||
@@ -490,19 +552,26 @@ class Json extends Server {
|
||||
$metadata['scheme'] = 'xyz';
|
||||
$tiles = array();
|
||||
foreach ($this->config['baseUrls'] as $url) {
|
||||
$tiles[] = 'http://' . $url . '/' . $metadata['basename'] . '/{z}/{x}/{y}.' . $metadata['format'];
|
||||
$tiles[] = '' . $this->config['protocol'] . '://' . $url . '/' . $metadata['basename'] . '/{z}/{x}/{y}.' . $metadata['format'];
|
||||
}
|
||||
$metadata['tiles'] = $tiles;
|
||||
if ($this->isDBLayer($metadata['basename'])) {
|
||||
$this->DBconnect($metadata['basename'] . '.mbtiles');
|
||||
$res = $this->db->query('SELECT grid 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[] = 'http://' . $url . '/' . $metadata['basename'] . '/{z}/{x}/{y}.grid.json';
|
||||
$grids[] = '' . $this->config['protocol'] . '://' . $url . '/' . $metadata['basename'] . '/{z}/{x}/{y}.grid.json';
|
||||
}
|
||||
$metadata['grids'] = $grids;
|
||||
}
|
||||
}
|
||||
if (array_key_exists('json', $metadata)) {
|
||||
$mjson = json_decode(stripslashes($metadata['json']));
|
||||
foreach ($mjson as $key => $value) {
|
||||
$metadata[$key] = $value;
|
||||
}
|
||||
unset($metadata['json']);
|
||||
}
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
@@ -535,7 +604,7 @@ class Json extends Server {
|
||||
echo 'TileServer: unknown map ' . $basename;
|
||||
die;
|
||||
}
|
||||
return $output;
|
||||
return stripslashes($output);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -544,7 +613,7 @@ class Json extends Server {
|
||||
public function getJson() {
|
||||
parent::setDatasets();
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header("Content-Type:application/javascript charset=utf-8");
|
||||
header("Content-Type: application/json; charset=utf-8");
|
||||
if ($this->callback !== 'grid') {
|
||||
echo $this->callback . '(' . $this->createJson($this->layer) . ');'; die;
|
||||
} else {
|
||||
@@ -558,7 +627,7 @@ class Json extends Server {
|
||||
public function getJsonp() {
|
||||
parent::setDatasets();
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header("Content-Type:text/javascript charset=utf-8");
|
||||
header("Content-Type: application/javascript; charset=utf-8");
|
||||
echo $this->callback . '(' . $this->createJson($this->layer) . ');';
|
||||
}
|
||||
|
||||
@@ -566,7 +635,7 @@ class Json extends Server {
|
||||
* Returns UTFGrid in JSON format
|
||||
*/
|
||||
public function getUTFGrid() {
|
||||
parent::getUTFGrid($this->layer, $this->z, $this->y, $this->x);
|
||||
parent::renderUTFGrid($this->layer, $this->z, $this->y, $this->x);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -643,7 +712,7 @@ class Wmts extends Server {
|
||||
<ows:Operation name="GetCapabilities">
|
||||
<ows:DCP>
|
||||
<ows:HTTP>
|
||||
<ows:Get xlink:href="http://' . $this->config['baseUrls'][0] . '/wmts/1.0.0/WMTSCapabilities.xml">
|
||||
<ows:Get xlink:href="' . $this->config['protocol'] . '://' . $this->config['baseUrls'][0] . '/wmts/1.0.0/WMTSCapabilities.xml">
|
||||
<ows:Constraint name="GetEncoding">
|
||||
<ows:AllowedValues>
|
||||
<ows:Value>RESTful</ows:Value>
|
||||
@@ -651,7 +720,7 @@ class Wmts extends Server {
|
||||
</ows:Constraint>
|
||||
</ows:Get>
|
||||
<!-- add KVP binding in 10.1 -->
|
||||
<ows:Get xlink:href="http://' . $this->config['baseUrls'][0] . '/wmts?">
|
||||
<ows:Get xlink:href="' . $this->config['protocol'] . '://' . $this->config['baseUrls'][0] . '/wmts?">
|
||||
<ows:Constraint name="GetEncoding">
|
||||
<ows:AllowedValues>
|
||||
<ows:Value>KVP</ows:Value>
|
||||
@@ -664,14 +733,14 @@ class Wmts extends Server {
|
||||
<ows:Operation name="GetTile">
|
||||
<ows:DCP>
|
||||
<ows:HTTP>
|
||||
<ows:Get xlink:href="http://' . $this->config['baseUrls'][0] . '/wmts/">
|
||||
<ows:Get xlink:href="' . $this->config['protocol'] . '://' . $this->config['baseUrls'][0] . '/wmts/">
|
||||
<ows:Constraint name="GetEncoding">
|
||||
<ows:AllowedValues>
|
||||
<ows:Value>RESTful</ows:Value>
|
||||
</ows:AllowedValues>
|
||||
</ows:Constraint>
|
||||
</ows:Get>
|
||||
<ows:Get xlink:href="http://' . $this->config['baseUrls'][0] . '/wmts?">
|
||||
<ows:Get xlink:href="' . $this->config['protocol'] . '://' . $this->config['baseUrls'][0] . '/wmts?">
|
||||
<ows:Constraint name="GetEncoding">
|
||||
<ows:AllowedValues>
|
||||
<ows:Value>KVP</ows:Value>
|
||||
@@ -719,7 +788,7 @@ class Wmts extends Server {
|
||||
<TileMatrixSetLink>
|
||||
<TileMatrixSet>' . $tileMatrixSet . '</TileMatrixSet>
|
||||
</TileMatrixSetLink>
|
||||
<ResourceURL format="' . $mime . '" resourceType="tile" template="http://'
|
||||
<ResourceURL format="' . $mime . '" resourceType="tile" template="' . $this->config['protocol'] . '://'
|
||||
. $this->config['baseUrls'][0] . '/wmts/' . $basename . '/{TileMatrixSet}/{TileMatrix}/{TileCol}/{TileRow}.' . $format . '"/>
|
||||
</Layer>';
|
||||
}
|
||||
@@ -1075,7 +1144,7 @@ class Wmts extends Server {
|
||||
</TileMatrix>
|
||||
</TileMatrixSet>
|
||||
</Contents>
|
||||
<ServiceMetadataURL xlink:href="http://' . $this->config['baseUrls'][0] . '/wmts/1.0.0/WMTSCapabilities.xml"/>
|
||||
<ServiceMetadataURL xlink:href="' . $this->config['protocol'] . '://' . $this->config['baseUrls'][0] . '/wmts/1.0.0/WMTSCapabilities.xml"/>
|
||||
</Capabilities>';
|
||||
}
|
||||
|
||||
@@ -1091,9 +1160,9 @@ class Wmts extends Server {
|
||||
} else {
|
||||
$format = $this->getGlobal('Format');
|
||||
}
|
||||
parent::getTile($this->getGlobal('Layer'), $this->getGlobal('TileMatrix'), $this->getGlobal('TileRow'), $this->getGlobal('TileCol'), $format);
|
||||
parent::renderTile($this->getGlobal('Layer'), $this->getGlobal('TileMatrix'), $this->getGlobal('TileRow'), $this->getGlobal('TileCol'), $format);
|
||||
} else {
|
||||
parent::getTile($this->layer, $this->z, $this->y, $this->x, $this->ext);
|
||||
parent::renderTile($this->layer, $this->z, $this->y, $this->x, $this->ext);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1156,7 +1225,7 @@ class Tms extends Server {
|
||||
$srs = "EPSG:3857";
|
||||
echo '<TileMap title="' . $title . '" srs="' . $srs
|
||||
. '" type="InvertedTMS" ' . 'profile="global-' . $profile
|
||||
. '" href="http://' . $this->config['baseUrls'][0] . '/tms/' . $basename . '" />';
|
||||
. '" href="' . $this->config['protocol'] . '://' . $this->config['baseUrls'][0] . '/tms/' . $basename . '" />';
|
||||
}
|
||||
}
|
||||
echo '</TileMaps></TileMapService>';
|
||||
@@ -1194,7 +1263,7 @@ class Tms extends Server {
|
||||
}
|
||||
$mime = ($m['format'] == 'jpg') ? 'image/jpeg' : 'image/png';
|
||||
header("Content-type: application/xml");
|
||||
echo '<TileMap version="1.0.0" tilemapservice="http://' . $this->config['baseUrls'][0] . '/' . $m['basename'] . '" type="InvertedTMS">
|
||||
echo '<TileMap version="1.0.0" tilemapservice="' . $this->config['protocol'] . '://' . $this->config['baseUrls'][0] . '/' . $m['basename'] . '" type="InvertedTMS">
|
||||
<Title>' . htmlspecialchars($title) . '</Title>
|
||||
<Abstract>' . htmlspecialchars($description) . '</Abstract>
|
||||
<SRS>' . $srs . '</SRS>
|
||||
@@ -1203,7 +1272,7 @@ class Tms extends Server {
|
||||
<TileFormat width="256" height="256" mime-type="' . $mime . '" extension="' . $m['format'] . '"/>
|
||||
<TileSets profile="global-' . $m['profile'] . '">';
|
||||
for ($zoom = $m['minzoom']; $zoom < $m['maxzoom'] + 1; $zoom++) {
|
||||
echo '<TileSet href="http://' . $this->config['baseUrls'] [0] . '/' . $m['basename'] . '/' . $zoom . '" units-per-pixel="' . $initialResolution / pow(2, $zoom) . '" order="' . $zoom . '" />';
|
||||
echo '<TileSet href="' . $this->config['protocol'] . '://' . $this->config['baseUrls'] [0] . '/' . $m['basename'] . '/' . $zoom . '" units-per-pixel="' . $initialResolution / pow(2, $zoom) . '" order="' . $zoom . '" />';
|
||||
}
|
||||
echo'</TileSets></TileMap>';
|
||||
}
|
||||
@@ -1212,7 +1281,7 @@ class Tms extends Server {
|
||||
* Process getTile request
|
||||
*/
|
||||
public function getTile() {
|
||||
parent::getTile($this->layer, $this->z, $this->y, $this->x, $this->ext);
|
||||
parent::renderTile($this->layer, $this->z, $this->y, $this->x, $this->ext);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1356,6 +1425,8 @@ class Router {
|
||||
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";
|
||||
if (!empty($_SERVER['PATH_INFO'])) {
|
||||
$path_info = $_SERVER['PATH_INFO'];
|
||||
} else if (!empty($_SERVER['ORIG_PATH_INFO']) && $_SERVER['ORIG_PATH_INFO'] !== '/tileserver.php') {
|
||||
@@ -1375,9 +1446,9 @@ class Router {
|
||||
$tokens = array(
|
||||
':string' => '([a-zA-Z]+)',
|
||||
':number' => '([0-9]+)',
|
||||
':alpha' => '([a-zA-Z0-9-_]+)'
|
||||
':alpha' => '([a-zA-Z0-9-_@]+)'
|
||||
);
|
||||
global $config;
|
||||
//global $config;
|
||||
foreach ($routes as $pattern => $handler_name) {
|
||||
$pattern = strtr($pattern, $tokens);
|
||||
if (preg_match('#/?' . $pattern . '/?$#', $path_info, $matches)) {
|
||||
|
Reference in New Issue
Block a user