mirror of
https://github.com/klokantech/tileserver-php.git
synced 2025-08-29 17:20:04 +02:00
Compare commits
46 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
730ffa52f3 | ||
|
b7960baaaa | ||
|
8aa58cc6b9 | ||
|
250512168c | ||
|
6b5933e21f | ||
|
f5408fd108 | ||
|
dc26c831f1 | ||
|
28aba6f9e2 | ||
|
8f6a2ced68 | ||
|
79926b92fc | ||
|
3343f80e09 | ||
|
c660ab8f41 | ||
|
21d7a409fe | ||
|
abb4087942 | ||
|
0acdc04e32 | ||
|
765e0d9ea3 | ||
|
f9e801849e | ||
|
e66e577d5d | ||
|
ffedfde75e | ||
|
b783c59585 | ||
|
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 |
32
.htaccess
32
.htaccess
@@ -1,27 +1,33 @@
|
|||||||
# tileserver.php integration with Apache via .htaccess
|
# 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
|
#check htaccess functionality
|
||||||
DirectoryIndex tileserver.php
|
DirectoryIndex tileserver.php
|
||||||
|
|
||||||
RewriteEngine on
|
RewriteEngine on
|
||||||
|
|
||||||
#some hostings require RewriteBase e.g. 1&1.com
|
# Option: some hostings require RewriteBase e.g. 1&1.com
|
||||||
#RewriteBase /
|
#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
|
#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
|
# WMTS RESTful
|
||||||
# ------------
|
# ------------
|
||||||
# The file can be accessed directly:
|
# The file can be accessed directly:
|
||||||
|
9
.travis.yml
Normal file
9
.travis.yml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
language: php
|
||||||
|
php:
|
||||||
|
- 5.3
|
||||||
|
- 5.4
|
||||||
|
- 5.5
|
||||||
|
- 5.6
|
||||||
|
- hhvm
|
||||||
|
script:
|
||||||
|
- php tileserver.php
|
66
README.md
66
README.md
@@ -1,10 +1,13 @@
|
|||||||
=================================================
|
TileServer PHP: MapTiler and MBTiles maps via WMTS
|
||||||
TileServer PHP - OGC Web Map Tiling Server (WMTS)
|
==================================================
|
||||||
=================================================
|
|
||||||
|
[](https://travis-ci.org/klokantech/tileserver-php)
|
||||||
|
|
||||||
This server distributes maps to desktop, web, and mobile applications from
|
This server distributes maps to desktop, web, and mobile applications from
|
||||||
a standard Apache+PHP web hosting.
|
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
|
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,
|
pre-rendered map tiles made with [MapTiler](http://www.maptiler.com/), GDAL2Tiles,
|
||||||
or available as MBTiles files.
|
or available as MBTiles files.
|
||||||
@@ -13,9 +16,9 @@ It is the easiest and cheapest way how to serve zoomable maps in a
|
|||||||
standardized way - practically from any ordinary web hosting.
|
standardized way - practically from any ordinary web hosting.
|
||||||
|
|
||||||
It is easy to install - just copy the project files to a PHP-enabled
|
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,21 +30,24 @@ web hostings.
|
|||||||
Tiles are served directly by Apache with mod_rewrite rules as static files
|
Tiles are served directly by Apache with mod_rewrite rules as static files
|
||||||
and therefore are very fast and with correct HTTP caching headers.
|
and therefore are very fast and with correct HTTP caching headers.
|
||||||
Only XML metadata are delivered via PHP.
|
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:
|
Requirements:
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
- Apache webserver (with mod_rewrite / .htaccess supported)
|
- Apache webserver (with mod_rewrite / .htaccess supported)
|
||||||
- PHP 5.2+
|
- PHP 5.2+ with SQLite module (php5-sqlite)
|
||||||
|
|
||||||
(or anther webserver implementing mod_rewrite rules and PHP)
|
(or another webserver implementing mod_rewrite rules and PHP)
|
||||||
|
|
||||||
Installation:
|
Installation:
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
Download the project files as a zip archive or source code from GitHub and
|
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.
|
||||||
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
|
the TileServer.php Server should display you a welcome message and further
|
||||||
@@ -52,14 +58,12 @@ tiles rendered with [MapTiler](http://www.maptiler.com/).
|
|||||||
|
|
||||||
Tiles produced by open-source GDAL2Tiles or MapTiler and tiles in .mbtiles
|
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
|
files can be easily converted to required structure (XYZ with top-left origin
|
||||||
and metadata.json file).
|
and metadata.json file). The open-source utility [mbutil](https://github.com/mapbox/mbutil) produces
|
||||||
|
|
||||||
The OpenSource utility mbutil (https://github.com/mapbox/mbutil) produces
|
|
||||||
exactly the required format.
|
exactly the required format.
|
||||||
|
|
||||||
Direct reading of .mbtiles files is supported, but with decreased performance
|
Direct reading of .mbtiles files is supported, but with decreased performance
|
||||||
compared to the static files in a directory. Therefore the data management,
|
compared to the static files in a directory. The advantage is easier data management,
|
||||||
especially upload over FTP or similar protocols, is easier.
|
especially upload over FTP or similar protocols.
|
||||||
|
|
||||||
Supported protocols:
|
Supported protocols:
|
||||||
--------------------
|
--------------------
|
||||||
@@ -109,15 +113,11 @@ Supported protocols:
|
|||||||
Exposed at http://[...]/layer/z/x/y.grid.json
|
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".
|
of 'directory' where you installed tileserver.php project with suffix "wmts".
|
||||||
|
|
||||||
For example: http://www.example.com/directory/wmts
|
For example: http://www.example.com/directory/wmts
|
||||||
|
|
||||||
You can also install the project into a root directory of a virtual server:
|
If you have installed the project into a root directory of a domain, then the address is: http://www.example.com/wmts
|
||||||
Then the address is: http://www.example.com/wmts
|
|
||||||
|
|
||||||
Similarly for another end points.
|
|
||||||
|
|
||||||
The supported WMTS requests includes:
|
The supported WMTS requests includes:
|
||||||
|
|
||||||
@@ -131,7 +131,7 @@ GetTile RESTful/KVP:
|
|||||||
http://[...]/layer/[ANYTHING-OPTIONAL][z]/[x]/[y].[ext]
|
http://[...]/layer/[ANYTHING-OPTIONAL][z]/[x]/[y].[ext]
|
||||||
http://[...]?service=wmts&request=getTile&layer=[layer]&tilematrix=[z]&tilerow=[y]&tilecol=[y]&format=[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
|
Performance from the web clients
|
||||||
--------------------------------
|
--------------------------------
|
||||||
@@ -178,10 +178,10 @@ Password protection
|
|||||||
HTTP Simple Authentication can be easily added to the server.
|
HTTP Simple Authentication can be easily added to the server.
|
||||||
Edit the .htaccess and add these lines:
|
Edit the .htaccess and add these lines:
|
||||||
|
|
||||||
AuthUserFile /full/path/to/.htpasswd
|
AuthUserFile /full/path/to/.htpasswd
|
||||||
AuthType Basic
|
AuthType Basic
|
||||||
AuthName "Secure WMTS"
|
AuthName "Secure WMTS"
|
||||||
Require valid-user
|
Require valid-user
|
||||||
|
|
||||||
Create a file called .htpasswd with user:password format.
|
Create a file called .htpasswd with user:password format.
|
||||||
You can use a command-line utility:
|
You can use a command-line utility:
|
||||||
@@ -212,9 +212,10 @@ Credits / Contributors
|
|||||||
Project developed initially by Klokan Technologies GmbH, Switzerland in
|
Project developed initially by Klokan Technologies GmbH, Switzerland in
|
||||||
cooperation with National Oceanic and Atmospheric Administration - NOAA, USA.
|
cooperation with National Oceanic and Atmospheric Administration - NOAA, USA.
|
||||||
|
|
||||||
Petr Pridal - Klokan Technologies GmbH <petr.pridal@klokantech.com>
|
- Petr Pridal - Klokan Technologies GmbH <petr.pridal@klokantech.com>
|
||||||
Jason Woolard - NOAA <jason.woolard@noaa.gov>
|
- Jason Woolard - NOAA <jason.woolard@noaa.gov>
|
||||||
Jon Sellars - NOAA <jon.sellars@noaa.gov>
|
- Jon Sellars - NOAA <jon.sellars@noaa.gov>
|
||||||
|
- Dalibor Janak - Klokan Technologies GmbH <dalibor.janak@klokantech.com>
|
||||||
|
|
||||||
Tested WMTS/TMS clients
|
Tested WMTS/TMS clients
|
||||||
-----------------------
|
-----------------------
|
||||||
@@ -223,18 +224,21 @@ Tested WMTS/TMS clients
|
|||||||
http://www.qgis.org/
|
http://www.qgis.org/
|
||||||
- ESRI ArcGIS Desktop 10.1+ - native WMTS implementation supported
|
- ESRI ArcGIS Desktop 10.1+ - native WMTS implementation supported
|
||||||
http://www.esri.com/software/arcgis/arcgis-for-desktop
|
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
|
- ArcBruTiles plugin for ArcGIS 9.3+ - via TMS endpoint
|
||||||
http://arcbrutile.codeplex.com/
|
http://arcbrutile.codeplex.com/
|
||||||
- OpenLayers WMTS Layer - including parsing GetCapabilities
|
- OpenLayers WMTS Layer - including parsing GetCapabilities
|
||||||
http://www.openlayers.org/
|
http://www.openlayers.org/
|
||||||
- GAIA - native WMTS (issues with 3857 to be fixed)
|
- GAIA - native WMTS (issues with 3857 to be fixed)
|
||||||
http://www.thecarbonproject.com/gaia.php
|
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
|
BSD License
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
Copyright (C) 2012 Klokan Technologies GmbH
|
Copyright (C) 2015 Klokan Technologies GmbH (http://www.klokantech.com/)
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
258
tileserver.php
258
tileserver.php
@@ -9,21 +9,21 @@
|
|||||||
|
|
||||||
global $config;
|
global $config;
|
||||||
$config['serverTitle'] = 'TileServer-php v1';
|
$config['serverTitle'] = 'TileServer-php v1';
|
||||||
//$config['baseUrls'] = ['t0.server.com', 't1.server.com'];
|
//$config['baseUrls'] = array('t0.server.com', 't1.server.com');
|
||||||
|
|
||||||
Router::serve(array(
|
Router::serve(array(
|
||||||
'/' => 'Server:getHtml',
|
'/' => 'Server:getHtml',
|
||||||
'/test' => 'Server:getInfo',
|
'/test' => 'Server:getInfo',
|
||||||
'/html' => 'Server:getHtml',
|
'/html' => 'Server:getHtml',
|
||||||
|
'/:alpha/:number/:number/:number.grid.json' => 'Json:getUTFGrid',
|
||||||
'/:alpha.json' => 'Json:getJson',
|
'/:alpha.json' => 'Json:getJson',
|
||||||
'/:alpha.jsonp' => 'Json:getJsonp',
|
'/:alpha.jsonp' => 'Json:getJsonp',
|
||||||
'/:alpha/:number/:number/:number.:alpha.json' => 'Json:getUTFGrid',
|
|
||||||
'/wmts' => 'Wmts:get',
|
'/wmts' => 'Wmts:get',
|
||||||
'/wmts/1.0.0/WMTSCapabilities.xml' => 'Wmts:get',
|
'/wmts/1.0.0/WMTSCapabilities.xml' => 'Wmts:get',
|
||||||
'/wmts/:alpha/:number/:number/:number.:alpha' => 'Wmts:getTile',
|
'/wmts/:alpha/:number/:number/:alpha' => 'Wmts:getTile',
|
||||||
'/wmts/:alpha/:alpha/:number/:number/:number.:alpha' => 'Wmts:getTile',
|
'/wmts/:alpha/:alpha/:number/:number/:alpha' => 'Wmts:getTile',
|
||||||
'/wmts/:alpha/:alpha/:alpha/:number/:number/:number.:alpha' => 'Wmts:getTile',
|
'/wmts/:alpha/:alpha/:alpha/:number/:number/:alpha' => 'Wmts:getTile',
|
||||||
'/:alpha/:number/:number/:number.:alpha' => 'Wmts:getTile',
|
'/:alpha/:number/:number/:alpha' => 'Wmts:getTile',
|
||||||
'/tms' => 'Tms:getCapabilities',
|
'/tms' => 'Tms:getCapabilities',
|
||||||
'/tms/:alpha' => 'Tms:getLayerCapabilities',
|
'/tms/:alpha' => 'Tms:getLayerCapabilities',
|
||||||
));
|
));
|
||||||
@@ -71,13 +71,13 @@ class Server {
|
|||||||
$mjs = glob('*/metadata.json');
|
$mjs = glob('*/metadata.json');
|
||||||
$mbts = glob('*.mbtiles');
|
$mbts = glob('*.mbtiles');
|
||||||
if ($mjs) {
|
if ($mjs) {
|
||||||
foreach ($mjs as $mj) {
|
foreach (array_filter($mjs, 'is_readable') as $mj) {
|
||||||
$layer = $this->metadataFromMetadataJson($mj);
|
$layer = $this->metadataFromMetadataJson($mj);
|
||||||
array_push($this->fileLayer, $layer);
|
array_push($this->fileLayer, $layer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($mbts) {
|
if ($mbts) {
|
||||||
foreach ($mbts as $mbt) {
|
foreach (array_filter($mbts, 'is_readable') as $mbt) {
|
||||||
$this->dbLayer[] = $this->metadataFromMbtiles($mbt);
|
$this->dbLayer[] = $this->metadataFromMbtiles($mbt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -92,13 +92,12 @@ class Server {
|
|||||||
$this->layer = $params[1];
|
$this->layer = $params[1];
|
||||||
}
|
}
|
||||||
$params = array_reverse($params);
|
$params = array_reverse($params);
|
||||||
if (isset($params[3])) {
|
if (isset($params[2])) {
|
||||||
$this->z = $params[3];
|
$this->z = $params[2];
|
||||||
$this->x = $params[2];
|
$this->x = $params[1];
|
||||||
$this->y = $params[1];
|
$file = explode('.', $params[0]);
|
||||||
}
|
$this->y = $file[0];
|
||||||
if (isset($params[0])) {
|
$this->ext = isset($file[1]) ? $file[1] : NULL;
|
||||||
$this->ext = $params[0];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,7 +166,37 @@ class Server {
|
|||||||
|
|
||||||
$resultdata = $result->fetchAll();
|
$resultdata = $result->fetchAll();
|
||||||
foreach ($resultdata as $r) {
|
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);
|
$metadata = $this->metadataValidation($metadata);
|
||||||
$mbt = explode('.', $mbt);
|
$mbt = explode('.', $mbt);
|
||||||
@@ -175,6 +204,17 @@ class Server {
|
|||||||
return $metadata;
|
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
|
* Valids metaJSON
|
||||||
* @param object $metadata
|
* @param object $metadata
|
||||||
@@ -182,7 +222,6 @@ class Server {
|
|||||||
*/
|
*/
|
||||||
public function metadataValidation($metadata) {
|
public function metadataValidation($metadata) {
|
||||||
if (array_key_exists('bounds', $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']));
|
$metadata['bounds'] = array_map('floatval', explode(',', $metadata['bounds']));
|
||||||
} else {
|
} else {
|
||||||
$metadata['bounds'] = array(-180, -85.051128779807, 180, 85.051128779807);
|
$metadata['bounds'] = array(-180, -85.051128779807, 180, 85.051128779807);
|
||||||
@@ -190,8 +229,7 @@ class Server {
|
|||||||
if (!array_key_exists('profile', $metadata)) {
|
if (!array_key_exists('profile', $metadata)) {
|
||||||
$metadata['profile'] = 'mercator';
|
$metadata['profile'] = 'mercator';
|
||||||
}
|
}
|
||||||
// TODO: detect format, minzoom, maxzoom, thumb
|
// TODO: detect thumb / SQL for mbtiles
|
||||||
// scandir() for directory / SQL for mbtiles
|
|
||||||
if (array_key_exists('minzoom', $metadata))
|
if (array_key_exists('minzoom', $metadata))
|
||||||
$metadata['minzoom'] = intval($metadata['minzoom']);
|
$metadata['minzoom'] = intval($metadata['minzoom']);
|
||||||
else
|
else
|
||||||
@@ -203,11 +241,6 @@ class Server {
|
|||||||
if (!array_key_exists('format', $metadata)) {
|
if (!array_key_exists('format', $metadata)) {
|
||||||
$metadata['format'] = 'png';
|
$metadata['format'] = 'png';
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
if (!array_key_exists('thumb', $metadata )) {
|
|
||||||
$metadata['profile'] = 'mercator';
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
return $metadata;
|
return $metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,9 +290,10 @@ class Server {
|
|||||||
* @param integer $x
|
* @param integer $x
|
||||||
* @param string $ext
|
* @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->isDBLayer($tileset)) {
|
||||||
if ($this->isModified($tileset) == TRUE) {
|
if ($this->isModified($tileset) == TRUE) {
|
||||||
|
header('Access-Control-Allow-Origin: *');
|
||||||
header('HTTP/1.1 304 Not Modified');
|
header('HTTP/1.1 304 Not Modified');
|
||||||
die;
|
die;
|
||||||
}
|
}
|
||||||
@@ -274,7 +308,12 @@ 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);
|
$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();
|
$data = $result->fetchColumn();
|
||||||
if (!isset($data) || $data === FALSE) {
|
if (!isset($data) || $data === FALSE) {
|
||||||
$this->getCleanTile();
|
//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;
|
||||||
|
$this->getCleanTile($scale, $ext);
|
||||||
} else {
|
} else {
|
||||||
$result = $this->db->query('select value from metadata where name="format"');
|
$result = $this->db->query('select value from metadata where name="format"');
|
||||||
$resultdata = $result->fetchColumn();
|
$resultdata = $result->fetchColumn();
|
||||||
@@ -282,37 +321,73 @@ class Server {
|
|||||||
if ($format == 'jpg') {
|
if ($format == 'jpg') {
|
||||||
$format = 'jpeg';
|
$format = 'jpeg';
|
||||||
}
|
}
|
||||||
|
if ($format == 'pbf') {
|
||||||
|
header('Content-type: application/x-protobuf');
|
||||||
|
header('Content-Encoding:gzip');
|
||||||
|
} else {
|
||||||
header('Content-type: image/' . $format);
|
header('Content-type: image/' . $format);
|
||||||
|
}
|
||||||
|
header('Access-Control-Allow-Origin: *');
|
||||||
echo $data;
|
echo $data;
|
||||||
}
|
}
|
||||||
} elseif ($this->isFileLayer($tileset)) {
|
} elseif ($this->isFileLayer($tileset)) {
|
||||||
$name = './' . $tileset . '/' . $z . '/' . $x . '/' . $y . '.' . $ext;
|
$name = './' . $tileset . '/' . $z . '/' . $x . '/' . $y;
|
||||||
|
$mime = 'image/';
|
||||||
|
if($ext != NULL){
|
||||||
|
$name .= '.' . $ext;
|
||||||
|
}
|
||||||
if ($fp = @fopen($name, 'rb')) {
|
if ($fp = @fopen($name, 'rb')) {
|
||||||
header('Content-Type: image/' . $ext);
|
if($ext != NULL){
|
||||||
|
$mime .= $ext;
|
||||||
|
}else{
|
||||||
|
//detect image type from file
|
||||||
|
$mimetypes = array('gif', 'jpeg', 'png');
|
||||||
|
$mime .= $mimetypes[exif_imagetype($name) - 1];
|
||||||
|
}
|
||||||
|
header('Access-Control-Allow-Origin: *');
|
||||||
|
header('Content-Type: ' . $mime);
|
||||||
header('Content-Length: ' . filesize($name));
|
header('Content-Length: ' . filesize($name));
|
||||||
fpassthru($fp);
|
fpassthru($fp);
|
||||||
die;
|
die;
|
||||||
} else {
|
} 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;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
$this->getCleanTile($meta->scale, $ext);
|
||||||
} else {
|
} else {
|
||||||
echo 'Server: Unknown or not specified dataset';
|
header('HTTP/1.1 404 Not Found');
|
||||||
|
echo 'Server: Unknown or not specified dataset "'.$tileset.'"';
|
||||||
die;
|
die;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns clean tile
|
* Returns clean tile
|
||||||
|
* @param integer $scale Default 1
|
||||||
*/
|
*/
|
||||||
public function getCleanTile() {
|
public function getCleanTile($scale = 1, $format = 'png') {
|
||||||
$png = imagecreatetruecolor(256, 256);
|
switch ($format) {
|
||||||
|
case 'pbf':
|
||||||
|
header('HTTP/1.1 404 Not Found');
|
||||||
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
|
echo '{"message":"Tile does not exist"}';
|
||||||
|
die;
|
||||||
|
case 'png':
|
||||||
|
default:
|
||||||
|
$tileSize = 256 * $scale;
|
||||||
|
$png = imagecreatetruecolor($tileSize, $tileSize);
|
||||||
imagesavealpha($png, true);
|
imagesavealpha($png, true);
|
||||||
$trans_colour = imagecolorallocatealpha($png, 0, 0, 0, 127);
|
$trans_colour = imagecolorallocatealpha($png, 0, 0, 0, 127);
|
||||||
imagefill($png, 0, 0, $trans_colour);
|
imagefill($png, 0, 0, $trans_colour);
|
||||||
|
header('Access-Control-Allow-Origin: *');
|
||||||
header('Content-type: image/png');
|
header('Content-type: image/png');
|
||||||
imagepng($png);
|
imagepng($png);
|
||||||
die;
|
die;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns tile's UTFGrid
|
* Returns tile's UTFGrid
|
||||||
@@ -321,7 +396,7 @@ class Server {
|
|||||||
* @param integer $y
|
* @param integer $y
|
||||||
* @param integer $x
|
* @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->isDBLayer($tileset)) {
|
||||||
if ($this->isModified($tileset) == TRUE) {
|
if ($this->isModified($tileset) == TRUE) {
|
||||||
header('HTTP/1.1 304 Not Modified');
|
header('HTTP/1.1 304 Not Modified');
|
||||||
@@ -331,20 +406,22 @@ class Server {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$this->DBconnect($tileset . '.mbtiles');
|
$this->DBconnect($tileset . '.mbtiles');
|
||||||
$result = $this->db->query('SELECT grid FROM grids WHERE tile_column = ' . $x . ' AND tile_row = ' . $y . ' AND zoom_level = ' . $z);
|
|
||||||
if (!isset($result) || $result === FALSE) {
|
|
||||||
header('Access-Control-Allow-Origin: *');
|
|
||||||
echo '{}';
|
|
||||||
die;
|
|
||||||
} else {
|
|
||||||
$data = $result->fetchColumn();
|
|
||||||
|
|
||||||
$grid = gzuncompress($data);
|
$query = 'SELECT grid FROM grids WHERE tile_column = ' . $x . ' AND '
|
||||||
|
. 'tile_row = ' . $y . ' AND zoom_level = ' . $z;
|
||||||
|
$result = $this->db->query($query);
|
||||||
|
$data = $result->fetch(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
if ($data !== FALSE) {
|
||||||
|
$grid = gzuncompress($data['grid']);
|
||||||
$grid = substr(trim($grid), 0, -1);
|
$grid = substr(trim($grid), 0, -1);
|
||||||
|
|
||||||
//adds legend (data) to output
|
//adds legend (data) to output
|
||||||
$grid .= ',"data":{';
|
$grid .= ',"data":{';
|
||||||
$result = $this->db->query('SELECT key_name as key, key_json as json FROM grid_data WHERE zoom_level=' . $z . ' and tile_column=' . $x . ' and tile_row=' . $y);
|
$kquery = 'SELECT key_name as key, key_json as json FROM grid_data '
|
||||||
|
. 'WHERE zoom_level=' . $z . ' and '
|
||||||
|
. 'tile_column=' . $x . ' and tile_row=' . $y;
|
||||||
|
$result = $this->db->query($kquery);
|
||||||
while ($r = $result->fetch(PDO::FETCH_ASSOC)) {
|
while ($r = $result->fetch(PDO::FETCH_ASSOC)) {
|
||||||
$grid .= '"' . $r['key'] . '":' . $r['json'] . ',';
|
$grid .= '"' . $r['key'] . '":' . $r['json'] . ',';
|
||||||
}
|
}
|
||||||
@@ -352,14 +429,18 @@ class Server {
|
|||||||
header('Access-Control-Allow-Origin: *');
|
header('Access-Control-Allow-Origin: *');
|
||||||
|
|
||||||
if (isset($_GET['callback']) && !empty($_GET['callback'])) {
|
if (isset($_GET['callback']) && !empty($_GET['callback'])) {
|
||||||
header("Content-Type:text/javascript charset=utf-8");
|
header('Content-Type:text/javascript charset=utf-8');
|
||||||
echo $_GET['callback'] . '(' . $grid . ');';
|
echo $_GET['callback'] . '(' . $grid . ');';
|
||||||
} else {
|
} else {
|
||||||
header("Content-Type:text/javascript; charset=utf-8");
|
header('Content-Type:text/javascript; charset=utf-8');
|
||||||
echo $grid;
|
echo $grid;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
header('Access-Control-Allow-Origin: *');
|
||||||
|
echo '{}';
|
||||||
|
die;
|
||||||
}
|
}
|
||||||
} catch (PDOException $e) {
|
} catch (Exception $e) {
|
||||||
header('Content-type: text/plain');
|
header('Content-type: text/plain');
|
||||||
print 'Error querying the database: ' . $e->getMessage();
|
print 'Error querying the database: ' . $e->getMessage();
|
||||||
}
|
}
|
||||||
@@ -373,14 +454,15 @@ class Server {
|
|||||||
* Returns server info
|
* Returns server info
|
||||||
*/
|
*/
|
||||||
public function getInfo() {
|
public function getInfo() {
|
||||||
|
// echo $this->config['baseUrls'][0];die;
|
||||||
$this->setDatasets();
|
$this->setDatasets();
|
||||||
$maps = array_merge($this->fileLayer, $this->dbLayer);
|
$maps = array_merge($this->fileLayer, $this->dbLayer);
|
||||||
header('Content-Type: text/html;charset=UTF-8');
|
header('Content-Type: text/html;charset=UTF-8');
|
||||||
echo '<!DOCTYPE html><html><head><meta charset="UTF-8"><title>' . $this->config['serverTitle'] . '</title></head><body>';
|
echo '<!DOCTYPE html><html><head><meta charset="UTF-8"><title>' . $this->config['serverTitle'] . '</title></head><body>';
|
||||||
echo '<h1>' . $this->config['serverTitle'] . '</h1>';
|
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 '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 '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 'TMS service: <a href="//' . $this->config['baseUrls'][0] . '/tms">' . $this->config['baseUrls'][0] . '/tms</a>';
|
||||||
foreach ($maps as $map) {
|
foreach ($maps as $map) {
|
||||||
$extend = '[';
|
$extend = '[';
|
||||||
foreach ($map['bounds'] as $ext) {
|
foreach ($map['bounds'] as $ext) {
|
||||||
@@ -392,7 +474,7 @@ class Server {
|
|||||||
} else {
|
} else {
|
||||||
echo '<p>Available file tileset: ' . $map['basename'] . '<br>';
|
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>';
|
. $this->config['baseUrls'][0] . '/' . $map['basename'] . '.json</a><br>';
|
||||||
echo 'Bounds: ' . $extend . '</p>';
|
echo 'Bounds: ' . $extend . '</p>';
|
||||||
}
|
}
|
||||||
@@ -408,9 +490,9 @@ class Server {
|
|||||||
$maps = array_merge($this->fileLayer, $this->dbLayer);
|
$maps = array_merge($this->fileLayer, $this->dbLayer);
|
||||||
header('Content-Type: text/html;charset=UTF-8');
|
header('Content-Type: text/html;charset=UTF-8');
|
||||||
echo '<!DOCTYPE html><html><head><meta charset="UTF-8"><title>' . $this->config['serverTitle'] . '</title>';
|
echo '<!DOCTYPE html><html><head><meta charset="UTF-8"><title>' . $this->config['serverTitle'] . '</title>';
|
||||||
echo '<link rel="stylesheet" type="text/css" href="//tileserver.com/v1/index.css" />
|
echo '<link rel="stylesheet" type="text/css" href="//cdn.klokantech.com/tileviewer/v1/index.css" />
|
||||||
<script src="//tileserver.com/v1/index.js"></script><body>
|
<script src="//cdn.klokantech.com/tileviewer/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>
|
<h1>Welcome to ' . $this->config['serverTitle'] . '</h1>
|
||||||
<p>This server distributes maps to desktop, web, and mobile applications.</p>
|
<p>This server distributes maps to desktop, web, and mobile applications.</p>
|
||||||
<p>The mapping data are available as OpenGIS Web Map Tiling Service (OGC WMTS), OSGEO Tile Map Service (TMS), and popular XYZ urls described with TileJSON metadata.</p>';
|
<p>The mapping data are available as OpenGIS Web Map Tiling Service (OGC WMTS), OSGEO Tile Map Service (TMS), and popular XYZ urls described with TileJSON metadata.</p>';
|
||||||
@@ -490,19 +572,31 @@ class Json extends Server {
|
|||||||
$metadata['scheme'] = 'xyz';
|
$metadata['scheme'] = 'xyz';
|
||||||
$tiles = array();
|
$tiles = array();
|
||||||
foreach ($this->config['baseUrls'] as $url) {
|
foreach ($this->config['baseUrls'] as $url) {
|
||||||
$tiles[] = 'http://' . $url . '/' . $metadata['basename'] . '/{z}/{x}/{y}.' . $metadata['format'];
|
$url = '' . $this->config['protocol'] . '://' . $url . '/' .
|
||||||
|
$metadata['basename'] . '/{z}/{x}/{y}';
|
||||||
|
if(strlen($metadata['format']) <= 4){
|
||||||
|
$url .= '.' . $metadata['format'];
|
||||||
|
}
|
||||||
|
$tiles[] = $url;
|
||||||
}
|
}
|
||||||
$metadata['tiles'] = $tiles;
|
$metadata['tiles'] = $tiles;
|
||||||
if ($this->isDBLayer($metadata['basename'])) {
|
if ($this->isDBLayer($metadata['basename'])) {
|
||||||
$this->DBconnect($metadata['basename'] . '.mbtiles');
|
$this->DBconnect($metadata['basename'] . '.mbtiles');
|
||||||
$res = $this->db->query('SELECT grid FROM grids LIMIT 1');
|
$res = $this->db->query('SELECT * FROM grids LIMIT 1;');
|
||||||
if ($res) {
|
if ($res) {
|
||||||
foreach ($this->config['baseUrls'] as $url) {
|
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;
|
$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;
|
return $metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -535,7 +629,7 @@ class Json extends Server {
|
|||||||
echo 'TileServer: unknown map ' . $basename;
|
echo 'TileServer: unknown map ' . $basename;
|
||||||
die;
|
die;
|
||||||
}
|
}
|
||||||
return $output;
|
return stripslashes($output);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -544,7 +638,7 @@ class Json extends Server {
|
|||||||
public function getJson() {
|
public function getJson() {
|
||||||
parent::setDatasets();
|
parent::setDatasets();
|
||||||
header('Access-Control-Allow-Origin: *');
|
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') {
|
if ($this->callback !== 'grid') {
|
||||||
echo $this->callback . '(' . $this->createJson($this->layer) . ');'; die;
|
echo $this->callback . '(' . $this->createJson($this->layer) . ');'; die;
|
||||||
} else {
|
} else {
|
||||||
@@ -558,7 +652,7 @@ class Json extends Server {
|
|||||||
public function getJsonp() {
|
public function getJsonp() {
|
||||||
parent::setDatasets();
|
parent::setDatasets();
|
||||||
header('Access-Control-Allow-Origin: *');
|
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) . ');';
|
echo $this->callback . '(' . $this->createJson($this->layer) . ');';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -566,7 +660,7 @@ class Json extends Server {
|
|||||||
* Returns UTFGrid in JSON format
|
* Returns UTFGrid in JSON format
|
||||||
*/
|
*/
|
||||||
public function getUTFGrid() {
|
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 +737,7 @@ class Wmts extends Server {
|
|||||||
<ows:Operation name="GetCapabilities">
|
<ows:Operation name="GetCapabilities">
|
||||||
<ows:DCP>
|
<ows:DCP>
|
||||||
<ows:HTTP>
|
<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:Constraint name="GetEncoding">
|
||||||
<ows:AllowedValues>
|
<ows:AllowedValues>
|
||||||
<ows:Value>RESTful</ows:Value>
|
<ows:Value>RESTful</ows:Value>
|
||||||
@@ -651,7 +745,7 @@ class Wmts extends Server {
|
|||||||
</ows:Constraint>
|
</ows:Constraint>
|
||||||
</ows:Get>
|
</ows:Get>
|
||||||
<!-- add KVP binding in 10.1 -->
|
<!-- 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:Constraint name="GetEncoding">
|
||||||
<ows:AllowedValues>
|
<ows:AllowedValues>
|
||||||
<ows:Value>KVP</ows:Value>
|
<ows:Value>KVP</ows:Value>
|
||||||
@@ -664,14 +758,14 @@ class Wmts extends Server {
|
|||||||
<ows:Operation name="GetTile">
|
<ows:Operation name="GetTile">
|
||||||
<ows:DCP>
|
<ows:DCP>
|
||||||
<ows:HTTP>
|
<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:Constraint name="GetEncoding">
|
||||||
<ows:AllowedValues>
|
<ows:AllowedValues>
|
||||||
<ows:Value>RESTful</ows:Value>
|
<ows:Value>RESTful</ows:Value>
|
||||||
</ows:AllowedValues>
|
</ows:AllowedValues>
|
||||||
</ows:Constraint>
|
</ows:Constraint>
|
||||||
</ows:Get>
|
</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:Constraint name="GetEncoding">
|
||||||
<ows:AllowedValues>
|
<ows:AllowedValues>
|
||||||
<ows:Value>KVP</ows:Value>
|
<ows:Value>KVP</ows:Value>
|
||||||
@@ -694,8 +788,8 @@ class Wmts extends Server {
|
|||||||
$title = (array_key_exists('name', $m)) ? $m['name'] : $basename;
|
$title = (array_key_exists('name', $m)) ? $m['name'] : $basename;
|
||||||
$profile = $m['profile'];
|
$profile = $m['profile'];
|
||||||
$bounds = $m['bounds'];
|
$bounds = $m['bounds'];
|
||||||
$format = $m['format'];
|
$format = $m['format'] == 'hybrid' ? 'jpgpng' : $m['format'];
|
||||||
$mime = ($format == 'jpg') ? 'image/jpeg' : 'image/png';
|
$mime = ($format == 'jpg') ? 'image/jpeg' : 'image/' . $format;
|
||||||
if ($profile == 'geodetic') {
|
if ($profile == 'geodetic') {
|
||||||
$tileMatrixSet = "WGS84";
|
$tileMatrixSet = "WGS84";
|
||||||
} else {
|
} else {
|
||||||
@@ -704,6 +798,11 @@ class Wmts extends Server {
|
|||||||
list( $maxx, $maxy ) = $mercator->LatLonToMeters($bounds[3], $bounds[2]);
|
list( $maxx, $maxy ) = $mercator->LatLonToMeters($bounds[3], $bounds[2]);
|
||||||
$bounds3857 = array($minx, $miny, $maxx, $maxy);
|
$bounds3857 = array($minx, $miny, $maxx, $maxy);
|
||||||
}
|
}
|
||||||
|
$resourceUrlTemplate = $this->config['protocol'] . '://'
|
||||||
|
. $this->config['baseUrls'][0] . '/wmts/' . $basename . '/{TileMatrixSet}/{TileMatrix}/{TileCol}/{TileRow}';
|
||||||
|
if(strlen($format) <= 4){
|
||||||
|
$resourceUrlTemplate .= '.' . $format;
|
||||||
|
}
|
||||||
echo'
|
echo'
|
||||||
<Layer>
|
<Layer>
|
||||||
<ows:Title>' . $title . '</ows:Title>
|
<ows:Title>' . $title . '</ows:Title>
|
||||||
@@ -719,8 +818,7 @@ class Wmts extends Server {
|
|||||||
<TileMatrixSetLink>
|
<TileMatrixSetLink>
|
||||||
<TileMatrixSet>' . $tileMatrixSet . '</TileMatrixSet>
|
<TileMatrixSet>' . $tileMatrixSet . '</TileMatrixSet>
|
||||||
</TileMatrixSetLink>
|
</TileMatrixSetLink>
|
||||||
<ResourceURL format="' . $mime . '" resourceType="tile" template="http://'
|
<ResourceURL format="' . $mime . '" resourceType="tile" template="' . $resourceUrlTemplate . '"/>
|
||||||
. $this->config['baseUrls'][0] . '/wmts/' . $basename . '/{TileMatrixSet}/{TileMatrix}/{TileCol}/{TileRow}.' . $format . '"/>
|
|
||||||
</Layer>';
|
</Layer>';
|
||||||
}
|
}
|
||||||
echo '
|
echo '
|
||||||
@@ -1075,7 +1173,7 @@ class Wmts extends Server {
|
|||||||
</TileMatrix>
|
</TileMatrix>
|
||||||
</TileMatrixSet>
|
</TileMatrixSet>
|
||||||
</Contents>
|
</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>';
|
</Capabilities>';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1091,9 +1189,15 @@ class Wmts extends Server {
|
|||||||
} else {
|
} else {
|
||||||
$format = $this->getGlobal('Format');
|
$format = $this->getGlobal('Format');
|
||||||
}
|
}
|
||||||
parent::getTile($this->getGlobal('Layer'), $this->getGlobal('TileMatrix'), $this->getGlobal('TileRow'), $this->getGlobal('TileCol'), $format);
|
parent::renderTile(
|
||||||
|
$this->getGlobal('Layer'),
|
||||||
|
$this->getGlobal('TileMatrix'),
|
||||||
|
$this->getGlobal('TileRow'),
|
||||||
|
$this->getGlobal('TileCol'),
|
||||||
|
$format
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
parent::getTile($this->layer, $this->z, $this->y, $this->x, $this->ext);
|
parent::renderTile($this->layer, $this->z, $this->y, $this->x, $this->ext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1156,7 +1260,7 @@ class Tms extends Server {
|
|||||||
$srs = "EPSG:3857";
|
$srs = "EPSG:3857";
|
||||||
echo '<TileMap title="' . $title . '" srs="' . $srs
|
echo '<TileMap title="' . $title . '" srs="' . $srs
|
||||||
. '" type="InvertedTMS" ' . 'profile="global-' . $profile
|
. '" type="InvertedTMS" ' . 'profile="global-' . $profile
|
||||||
. '" href="http://' . $this->config['baseUrls'][0] . '/tms/' . $basename . '" />';
|
. '" href="' . $this->config['protocol'] . '://' . $this->config['baseUrls'][0] . '/tms/' . $basename . '" />';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo '</TileMaps></TileMapService>';
|
echo '</TileMaps></TileMapService>';
|
||||||
@@ -1194,7 +1298,7 @@ class Tms extends Server {
|
|||||||
}
|
}
|
||||||
$mime = ($m['format'] == 'jpg') ? 'image/jpeg' : 'image/png';
|
$mime = ($m['format'] == 'jpg') ? 'image/jpeg' : 'image/png';
|
||||||
header("Content-type: application/xml");
|
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>
|
<Title>' . htmlspecialchars($title) . '</Title>
|
||||||
<Abstract>' . htmlspecialchars($description) . '</Abstract>
|
<Abstract>' . htmlspecialchars($description) . '</Abstract>
|
||||||
<SRS>' . $srs . '</SRS>
|
<SRS>' . $srs . '</SRS>
|
||||||
@@ -1203,7 +1307,7 @@ class Tms extends Server {
|
|||||||
<TileFormat width="256" height="256" mime-type="' . $mime . '" extension="' . $m['format'] . '"/>
|
<TileFormat width="256" height="256" mime-type="' . $mime . '" extension="' . $m['format'] . '"/>
|
||||||
<TileSets profile="global-' . $m['profile'] . '">';
|
<TileSets profile="global-' . $m['profile'] . '">';
|
||||||
for ($zoom = $m['minzoom']; $zoom < $m['maxzoom'] + 1; $zoom++) {
|
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>';
|
echo'</TileSets></TileMap>';
|
||||||
}
|
}
|
||||||
@@ -1212,7 +1316,7 @@ class Tms extends Server {
|
|||||||
* Process getTile request
|
* Process getTile request
|
||||||
*/
|
*/
|
||||||
public function getTile() {
|
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 +1460,8 @@ class Router {
|
|||||||
public static function serve($routes) {
|
public static function serve($routes) {
|
||||||
$request_method = strtolower($_SERVER['REQUEST_METHOD']);
|
$request_method = strtolower($_SERVER['REQUEST_METHOD']);
|
||||||
$path_info = '/';
|
$path_info = '/';
|
||||||
|
global $config;
|
||||||
|
$config['protocol'] = ( isset($_SERVER["HTTPS"]) or $_SERVER['SERVER_PORT'] == '443') ? "https" : "http";
|
||||||
if (!empty($_SERVER['PATH_INFO'])) {
|
if (!empty($_SERVER['PATH_INFO'])) {
|
||||||
$path_info = $_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']) && $_SERVER['ORIG_PATH_INFO'] !== '/tileserver.php') {
|
||||||
@@ -1375,9 +1481,9 @@ class Router {
|
|||||||
$tokens = array(
|
$tokens = array(
|
||||||
':string' => '([a-zA-Z]+)',
|
':string' => '([a-zA-Z]+)',
|
||||||
':number' => '([0-9]+)',
|
':number' => '([0-9]+)',
|
||||||
':alpha' => '([a-zA-Z0-9-_]+)'
|
':alpha' => '([a-zA-Z0-9-_@\.]+)'
|
||||||
);
|
);
|
||||||
global $config;
|
//global $config;
|
||||||
foreach ($routes as $pattern => $handler_name) {
|
foreach ($routes as $pattern => $handler_name) {
|
||||||
$pattern = strtr($pattern, $tokens);
|
$pattern = strtr($pattern, $tokens);
|
||||||
if (preg_match('#/?' . $pattern . '/?$#', $path_info, $matches)) {
|
if (preg_match('#/?' . $pattern . '/?$#', $path_info, $matches)) {
|
||||||
|
Reference in New Issue
Block a user