1
0
mirror of https://github.com/klokantech/tileserver-php.git synced 2025-08-05 22:27:46 +02:00

Remove old aray syntax

This commit is contained in:
Dalibor Janak
2020-07-28 22:34:22 +02:00
parent b266dc2a6e
commit 43e3cadb87
2 changed files with 64 additions and 64 deletions

View File

@@ -41,7 +41,7 @@ Requirements:
------------- -------------
- Apache webserver (with mod_rewrite / .htaccess supported) - 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) (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. 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 the TileServer.php Server should display you a welcome message and further
instructions. instructions.
@@ -70,15 +70,15 @@ Supported protocols:
-------------------- --------------------
- OpenGIS WMTS 1.0.0 - OpenGIS WMTS 1.0.0
The Open Geospatial Consortium (OGC) Web Map Tile Service (WMTS) The Open Geospatial Consortium (OGC) Web Map Tile Service (WMTS)
Both KVP and RESTful version 1.0.0: Both KVP and RESTful version 1.0.0:
http://www.opengeospatial.org/standards/wmts/ http://www.opengeospatial.org/standards/wmts/
Target is maximal compliance to the standard. Target is maximal compliance to the standard.
Exposed at http://[...]/wmts Exposed at http://[...]/wmts
- OSGeo TMS 1.0.0 - OSGeo TMS 1.0.0
The OSGeo Tile Maps Service, but with inverted y-coordinates: The OSGeo Tile Maps Service, but with inverted y-coordinates:
@@ -90,7 +90,7 @@ Supported protocols:
flipped y-axis. flipped y-axis.
Exposed at http://[...]/tms Exposed at http://[...]/tms
- TileJSON - TileJSON
Metadata about the individual maps in a ready to use form for web 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. and with support for JSONP access.
Exposed at http://[...]/layer.json or .jsonp Exposed at http://[...]/layer.json or .jsonp
- Direct access with XYZ tile requests (to existing tiles in a directory - Direct access with XYZ tile requests (to existing tiles in a directory
or to .mbtiles) or to .mbtiles)
Compatible with Google Maps API / Bing SDK / OpenStreetMap clients. Compatible with Google Maps API / Bing SDK / OpenStreetMap clients.
Exposed at http://[...]/layer/z/x/y.ext 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/ Example https://www.mapbox.com/demo/visiblemap/
Specification https://github.com/mapbox/utfgrid-spec Specification https://github.com/mapbox/utfgrid-spec
Exposed at http://[...]/layer/z/x/y.grid.json 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). - 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/ Example http://osm2vectortiles.tileserver.com/
TileJSON can be used in MapBox Studio Classic, MapBox SDKs/APIs, OpenLayers, etc. TileJSON can be used in MapBox Studio Classic, MapBox SDKs/APIs, OpenLayers, etc.
Exposed at http://[...]/layer/z/x/y.pbf Exposed at http://[...]/layer/z/x/y.pbf
- Retina / HighDPI routing with 512 tiles - Retina / HighDPI routing with 512 tiles
Use @2x suffix in url for JSONs and tiles. For example http://tileserver.maptiler.com/grandcanyon@2x.json 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: The supported WMTS requests includes:
GetCapabilities RESTful/KVP: GetCapabilities RESTful/KVP:
http://[...]/1.0.0/WMTSCapabilities.xml http://[...]/1.0.0/WMTSCapabilities.xml
http://[...]?service=wmts&request=getcapabilities&version=1.0.0 http://[...]?service=wmts&request=getcapabilities&version=1.0.0
GetTile RESTful/KVP: 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]
@@ -248,17 +248,17 @@ Tested WMTS/TMS clients
BSD License BSD License
----------- -----------
Copyright (C) 2015 Klokan Technologies GmbH (http://www.klokantech.com/) Copyright (C) 2020 MapTiler AG (https://www.maptiler.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
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 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, 2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation 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 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 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED

View File

@@ -1,20 +1,20 @@
<?php <?php
/* /*
* TileServer.php project * TileServer-PHP project
* ====================== * ======================
* https://github.com/klokantech/tileserver-php/ * https://github.com/maptiler/tileserver-php/
* Copyright (C) 2016 - Klokan Technologies GmbH * Copyright (C) 2020 - MapTiler AG
*/ */
global $config; global $config;
$config['serverTitle'] = 'Maps hosted with TileServer-php v2.0'; $config['serverTitle'] = 'Maps hosted with TileServer-php v2.0';
$config['availableFormats'] = array('png', 'jpg', 'jpeg', 'gif', 'webp', 'pbf', 'hybrid'); $config['availableFormats'] = ['png', 'jpg', 'jpeg', 'gif', 'webp', 'pbf', 'hybrid'];
$config['dataRoot'] = ''; $config['dataRoot'] = '';
//$config['template'] = 'template.php'; //$config['template'] = 'template.php';
//$config['baseUrls'] = array('t0.server.com', 't1.server.com'); //$config['baseUrls'] = ['t0.server.com', 't1.server.com'];
Router::serve(array( Router::serve([
'/' => 'Server:getHtml', '/' => 'Server:getHtml',
'/maps' => 'Server:getInfo', '/maps' => 'Server:getInfo',
'/html' => 'Server:getHtml', '/html' => 'Server:getHtml',
@@ -29,7 +29,7 @@ Router::serve(array(
'/:alpha/: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',
)); ]);
/** /**
* Server base * Server base
@@ -46,13 +46,13 @@ class Server {
* Datasets stored in file structure * Datasets stored in file structure
* @var array * @var array
*/ */
public $fileLayer = array(); public $fileLayer = [];
/** /**
* Datasets stored in database * Datasets stored in database
* @var array * @var array
*/ */
public $dbLayer = array(); public $dbLayer = [];
/** /**
* PDO database connection * PDO database connection
@@ -182,7 +182,7 @@ class Server {
* @return object * @return object
*/ */
public function metadataFromMbtiles($mbt) { public function metadataFromMbtiles($mbt) {
$metadata = array(); $metadata = [];
$this->DBconnect($mbt); $this->DBconnect($mbt);
$result = $this->db->query('select * from metadata'); $result = $this->db->query('select * from metadata');
@@ -220,7 +220,7 @@ class Server {
$e = -180 + 360 * ((1 + $resultdata[0]['e']) / pow(2, $metadata['maxzoom'])); $e = -180 + 360 * ((1 + $resultdata[0]['e']) / pow(2, $metadata['maxzoom']));
$n = $this->row2lat($resultdata[0]['n'], $metadata['maxzoom']); $n = $this->row2lat($resultdata[0]['n'], $metadata['maxzoom']);
$s = $this->row2lat($resultdata[0]['s'] - 1, $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); $mbt = explode('.', $mbt);
$metadata['basename'] = $mbt[0]; $metadata['basename'] = $mbt[0];
@@ -246,7 +246,7 @@ class Server {
*/ */
public function metadataValidation($metadata) { public function metadataValidation($metadata) {
if (!array_key_exists('bounds', $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'])) { } elseif (!is_array($metadata['bounds'])) {
$metadata['bounds'] = array_map('floatval', explode(',', $metadata['bounds'])); $metadata['bounds'] = array_map('floatval', explode(',', $metadata['bounds']));
} }
@@ -277,7 +277,7 @@ class Server {
$metadata['scale'] = 1; $metadata['scale'] = 1;
} }
if(!array_key_exists('tiles', $metadata)){ if(!array_key_exists('tiles', $metadata)){
$tiles = array(); $tiles = [];
foreach ($this->config['baseUrls'] as $url) { foreach ($this->config['baseUrls'] as $url) {
$url = '' . $this->config['protocol'] . '://' . $url . '/' . $url = '' . $this->config['protocol'] . '://' . $url . '/' .
$metadata['basename'] . '/{z}/{x}/{y}'; $metadata['basename'] . '/{z}/{x}/{y}';
@@ -297,7 +297,7 @@ class Server {
*/ */
public function DBconnect($tileset) { public function DBconnect($tileset) {
try { 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) { } catch (Exception $exc) {
echo $exc->getTraceAsString(); echo $exc->getTraceAsString();
die; die;
@@ -388,7 +388,7 @@ class Server {
$mime .= $ext; $mime .= $ext;
}else{ }else{
//detect image type from file //detect image type from file
$mimetypes = array('gif', 'jpeg', 'png'); $mimetypes = ['gif', 'jpeg', 'png'];
$mime .= $mimetypes[exif_imagetype($name) - 1]; $mime .= $mimetypes[exif_imagetype($name) - 1];
} }
header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Origin: *');
@@ -792,15 +792,15 @@ class Wmts extends Server {
$tileMatrix[$i]['pixel_size'], $tileMatrix[$i]['pixel_size'],
$tileMatrix[$i]['tile_size'] $tileMatrix[$i]['tile_size']
); );
$tileMatrix[$i]['matrix_size'] = array( $tileMatrix[$i]['matrix_size'] = [
$tileExtent[2] + 1, $tileExtent[2] + 1,
$tileExtent[1] + 1 $tileExtent[1] + 1
); ];
} }
if(!isset($tileMatrix[$i]['origin']) && isset($tileMatrix[$i]['extent'])){ if(!isset($tileMatrix[$i]['origin']) && isset($tileMatrix[$i]['extent'])){
$tileMatrix[$i]['origin'] = array( $tileMatrix[$i]['origin'] = [
$tileMatrix[$i]['extent'][0], $tileMatrix[$i]['extent'][3] $tileMatrix[$i]['extent'][0], $tileMatrix[$i]['extent'][3]
); ];
} }
// Origins of geographic coordinate systems are setting in opposite order // Origins of geographic coordinate systems are setting in opposite order
if (isset($proj4) && $proj4['proj'] === 'longlat') { if (isset($proj4) && $proj4['proj'] === 'longlat') {
@@ -811,7 +811,7 @@ class Wmts extends Server {
} }
if(!isset($tileMatrix[$i]['tile_size'])){ if(!isset($tileMatrix[$i]['tile_size'])){
$tileSize = 256 * (int) $layer['scale']; $tileSize = 256 * (int) $layer['scale'];
$tileMatrix[$i]['tile_size'] = array($tileSize, $tileSize); $tileMatrix[$i]['tile_size'] = [$tileSize, $tileSize];
} }
} }
@@ -827,12 +827,12 @@ class Wmts extends Server {
* @return array * @return array
*/ */
public function tilesOfExtent($extent, $origin, $pixel_size, $tile_size) { 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[0] - $origin[0], $pixel_size[0] * $tile_size[0]),
$this->minsample($extent[1] - $origin[1], $pixel_size[1] * $tile_size[1]), $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[2] - $origin[0], $pixel_size[0] * $tile_size[0]),
$this->maxsample($extent[3] - $origin[1], $pixel_size[1] * $tile_size[1]), $this->maxsample($extent[3] - $origin[1], $pixel_size[1] * $tile_size[1]),
); ];
return $tiles; return $tiles;
} }
@@ -851,19 +851,19 @@ class Wmts extends Server {
*/ */
public function getMercatorTileMatrixSet($maxZoom = 18){ public function getMercatorTileMatrixSet($maxZoom = 18){
$denominatorBase = 559082264.0287178; $denominatorBase = 559082264.0287178;
$extent = array(-20037508.34,-20037508.34,20037508.34,20037508.34); $extent = [-20037508.34,-20037508.34,20037508.34,20037508.34];
$tileMatrixSet = array(); $tileMatrixSet = [];
for($i = 0; $i <= $maxZoom; $i++){ for($i = 0; $i <= $maxZoom; $i++){
$matrixSize = pow(2, $i); $matrixSize = pow(2, $i);
$tileMatrixSet[] = array( $tileMatrixSet[] = [
'extent' => $extent, 'extent' => $extent,
'id' => (string) $i, 'id' => (string) $i,
'matrix_size' => array($matrixSize, $matrixSize), 'matrix_size' => [$matrixSize, $matrixSize],
'origin' => array($extent[0], $extent[3]), 'origin' => [$extent[0], $extent[3]],
'scale_denominator' => $denominatorBase / pow(2, $i), 'scale_denominator' => $denominatorBase / pow(2, $i),
'tile_size' => array(256, 256) 'tile_size' => [256, 256]
); ];
} }
return $this->getTileMatrixSet('GoogleMapsCompatible', $tileMatrixSet, 'EPSG:3857'); return $this->getTileMatrixSet('GoogleMapsCompatible', $tileMatrixSet, 'EPSG:3857');
@@ -874,26 +874,26 @@ class Wmts extends Server {
* @return string Xml * @return string Xml
*/ */
public function getWGS84TileMatrixSet(){ public function getWGS84TileMatrixSet(){
$extent = array(-180.000000, -90.000000, 180.000000, 90.000000); $extent = [-180.000000, -90.000000, 180.000000, 90.000000];
$scaleDenominators = array(279541132.01435887813568115234, 139770566.00717943906784057617, $scaleDenominators = [279541132.01435887813568115234, 139770566.00717943906784057617,
69885283.00358971953392028809, 34942641.50179485976696014404, 17471320.75089742988348007202, 69885283.00358971953392028809, 34942641.50179485976696014404, 17471320.75089742988348007202,
8735660.37544871494174003601, 4367830.18772435747087001801, 2183915.09386217873543500900, 8735660.37544871494174003601, 4367830.18772435747087001801, 2183915.09386217873543500900,
1091957.54693108936771750450, 545978.77346554468385875225, 272989.38673277234192937613, 1091957.54693108936771750450, 545978.77346554468385875225, 272989.38673277234192937613,
136494.69336638617096468806, 68247.34668319308548234403, 34123.67334159654274117202, 136494.69336638617096468806, 68247.34668319308548234403, 34123.67334159654274117202,
17061.83667079825318069197, 8530.91833539912659034599, 4265.45916769956329517299, 17061.83667079825318069197, 8530.91833539912659034599, 4265.45916769956329517299,
2132.72958384978574031265); 2132.72958384978574031265];
$tileMatrixSet = array(); $tileMatrixSet = [];
for($i = 0; $i <= 17; $i++){ for($i = 0; $i <= 17; $i++){
$matrixSize = pow(2, $i); $matrixSize = pow(2, $i);
$tileMatrixSet[] = array( $tileMatrixSet[] = [
'extent' => $extent, 'extent' => $extent,
'id' => (string) $i, 'id' => (string) $i,
'matrix_size' => array($matrixSize * 2, $matrixSize), 'matrix_size' => [$matrixSize * 2, $matrixSize],
'origin' => array($extent[3], $extent[0]), 'origin' => [$extent[3], $extent[0]],
'scale_denominator' => $scaleDenominators[$i], 'scale_denominator' => $scaleDenominators[$i],
'tile_size' => array(256, 256) 'tile_size' => [256, 256]
); ];
} }
return $this->getTileMatrixSet('WGS84', $tileMatrixSet, 'EPSG:4326'); return $this->getTileMatrixSet('WGS84', $tileMatrixSet, 'EPSG:4326');
@@ -1192,7 +1192,7 @@ class Tms extends Server {
} }
} else { } else {
$srs = 'EPSG:3857'; $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; $initRes = 156543.03392804062;
} }
$mime = ($m['format'] == 'jpg') ? 'image/jpeg' : 'image/png'; $mime = ($m['format'] == 'jpg') ? 'image/jpeg' : 'image/png';
@@ -1253,14 +1253,14 @@ class Router {
} }
} }
$discovered_handler = null; $discovered_handler = null;
$regex_matches = array(); $regex_matches = [];
if ($routes) { if ($routes) {
$tokens = array( $tokens = [
':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);
@@ -1281,7 +1281,7 @@ class Router {
$discoverered_class = explode(':', $discovered_handler); $discoverered_class = explode(':', $discovered_handler);
$discoverered_method = explode(':', $discovered_handler); $discoverered_method = explode(':', $discovered_handler);
$handler_instance = new $discoverered_class[0]($regex_matches); $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 { } else {
$handler_instance = new $discovered_handler($regex_matches); $handler_instance = new $discovered_handler($regex_matches);
} }