Git Product home page Git Product logo

tileserver-php's Introduction

TileServer PHP: MapTiler and MBTiles maps via WMTS

Build Status Docker Hub

This server distributes maps to desktop, web, and mobile applications from a standard Apache+PHP web hosting.

It is a free and open-source project implementing the OGC WMTS standard for pre-rendered map tiles made with any map tiling software like MapTiler Desktop, GDAL2Tiles, or any other MBTiles file.

It is the easiest and cheapest way how to serve zoomable maps in a standardized way - practically from any ordinary web hosting.

It is easy to install - copy the project files to a PHP-enabled directory along with your map data.

It comes with an online interface showing the list of the maps and step-by-step guides for online mapping libraries (Google Maps API, Leaflet, OpenLayers, OL3, MapLibre GL JS, ArcGIS JS) and various desktop GIS software:

tileserver-screenshot

This project is developed in PHP, not because it is the best language for the development of web applications, but because it maximally simplifies the deployment on a large number of web hostings, including various free web hostings providers.

Tiles are served directly by Apache with mod_rewrite rules as static files and therefore are very fast and with correct HTTP caching headers. Only XML metadata is delivered via PHP. MBTiles are served via PHP and are therefore slower unless they are unpacked with mbutil.

MapTiler can render GeoTIFF, ECW, MrSID, GeoPDF into compatible map tiles. JPEG, PNG, GIF, and TIFF with scanned maps or images without geolocation can be turned into standard map layers with the visual georeferencing functionality (http://youtu.be/eJxdCe9CNYg).

MapTiler - mapping tiles

Requirements:

  • Apache webserver (with mod_rewrite / .htaccess supported)
  • PHP 5.6+ with SQLite module (php5-sqlite)

(or another webserver implementing mod_rewrite rules and PHP)

Installation:

Download the project files as a zip archive or source code from GitHub and unpack it into a web-hosting of your choice.

If you access the web address relevant to the installation directory, the TileServer.php Server should display you a welcome message and further instructions.

Then you can upload to the web hosting your mapping data - a directory with tiles rendered with MapTiler.

Tiles produced by open-source GDAL2Tiles or MapTiler Desktop and tiles in .mbtiles format can be easily converted to the required structure (XYZ with top-left origin and metadata.json file). The open-source utility mbutil produces exactly the required format.

Direct reading of .mbtiles files is supported but with decreased performance compared to the static files in a directory. The advantage is easier data management, especially upload over FTP or similar protocols.

Supported protocols:

To use the OGC WMTS standard, point your client (desktop or web) to the URL of 'directory' where you installed tileserver.php project with suffix "wmts". For example: http://www.example.com/directory/wmts

If you have installed the project into a root directory of a domain, then the address is: http://www.example.com/wmts

The supported WMTS requests includes:

GetCapabilities RESTful/KVP:

http://[...]/1.0.0/WMTSCapabilities.xml http://[...]?service=wmts&request=getcapabilities&version=1.0.0

GetTile RESTful/KVP:

http://[...]/layer/[ANYTHING-OPTIONAL][z]/[x]/[y].[ext] http://[...]?service=wmts&request=getTile&layer=[layer]&tilematrix=[z]&tilerow=[y]&tilecol=[y]&format=[ext]

Other example requests are mentioned in the .htaccess.

TileServer-PHP supports all coordinates systems. You have to define it with tilejson with specification on https://github.com/klokantech/tilejson-spec/tree/custom-projection/2.2.0 Or use MapTiler to produce datasets with this specification.

Performance from the web clients

It is highly recommended to map several domain names to the service, such as:

http://a.example.com/, http://b.example.com/, http://c.example.com/.

This can be done with DNS CNAME records pointing to your hosting. The reason for this is that traditionally browsers will not send more than two simultaneous HTTP requests to the same domain - with multiple domains for the same server, you can better saturate the network and receive the maps faster.

Performance

In case the data are available in the form of a directory with XYZ tiles, then the Apache webserver is serving these files directly as WMTS RESTful or KVP.

This means performance is excellent, maps are delivered very fast, and a large number of concurrent visitors can be handled even with quite low-end hardware or cheap/free web hosting providers.

Mod_rewrite rules are utilized to ensure the HTTP requests defined in the OCG WMTS standard are served, and Apache preserves standard caching headers & eTag.

The performance should be significantly better than any other tile caching project (such as TileCache.org or GeoWebCache).

Performance graph for "apache static" comparing other tile caching projects is available online at http://code.google.com/p/mod-geocache/wiki/PreliminaryBenchmark

Limits of actual implementation

With intention, at this moment, the project supports only:

  • We enforce and require XYZ (top-left origin) tiling schema (even for TMS).

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

Create a file called .htpasswd with user:password format. You can use a command-line utility:

$ htpasswd -c .htpasswd [your-user-login]

Or an online service:

http://www.htaccesstools.com/htpasswd-generator/

HTTPS / SSL support

TileServer.php can run without any problems over HTTPS, if required.

Microsoft Windows web-hosting

The TileServer.php should run on Windows-powered webservers with Apache installation if PHP 5.2+ and mod_rewrite are available.

With the IIS webserver hosting, you may need PHP and IIRF module (http://iirf.codeplex.com/) and alter appropriately the rewrite rules.

Credits / Contributors

Project developed initially by Klokan Technologies GmbH, Switzerland, in cooperation with National Oceanic and Atmospheric Administration - NOAA, USA.

Tested WMTS/TMS clients

Alternative

If you need map server with commercial support, explore the possibilities provided by the MapTiler Server.

BSD License

Copyright (C) 2020 MapTiler AG (https://www.maptiler.com/) All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

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 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

tileserver-php's People

Contributors

codelingobot avatar daliborjanak avatar david-eagles avatar eyensky avatar fil avatar ibesora avatar klokan avatar kurt-hectic avatar mburke-weatheranalytics avatar mtfurlan avatar ramunasd avatar scubajorgen avatar xkomczax avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tileserver-php's Issues

Retina / HighDPI routing

In case there is a dataset ending with @2x and another dataset without - the @2x should be hidden and in the TileJSON should be mentioned: autoscale:true
Example:
http://api.tiles.mapbox.com/v3/examples.map-20v6611k.jsonp
Such datasets serve two tile requests:
tile
https://d.tiles.mapbox.com/v3/examples.map-20v6611k/6/33/22.png
and
tile@2x
https://d.tiles.mapbox.com/v3/examples.map-20v6611k/6/33/[email protected]

Unfortunately - this is pretty bad way for implementing retina tiles - as made by MapBox.
Normally Google Maps and other libraries loads a 512x512 px png tile instead of the 256x256px for the same location - on the same tile index. This MapBox implementation is one level off - and still uses 256px tiles.

TileJSON url passed to the constructor

TileServer PHP now fully supports TileJSON, but it is not advertised in the user interface.

It is expected that TileServer PHP passes to the JavaScript constructor of user interface a variable 'tilejson' with a format similar to http://servername/path/%n.json, later the JavaScript will replace %n with the name of the selected layer.

support for UTFgrid

not really an issue, but an enchancement: to support UTFgrid, at least with mbtiles ?

GeoPackage storage

Implement serving from a GeoPackage storage (SQLite based) as a more general alternative to MBTiles allowing also support for non-speherical mercator coordinate systems.

PNG image from mbtiles file sometimes loads, sometimes not

I'm having trouble showing a tiled map from an mbtiles-file. Some images, especially at higher zoomlevels, don't get displayed sometimes. The behaviour seems random; the same image sometimes is displayed, and sometimes not.

If you reload an image several times, you will see that it sometimes shows up correctly, but sometimes nothing is shown.

http://myserver.com/tiles/tileserver.php?/pc4_multi/17/67546/43194.png

(I've removed the real url to the server; please contact me if you'd like to test.)

A little debugging shows that when it isn't displayed, no data is returned from the query on the mbtiles database: $data == FALSE in line 311.

Any idea what causes this problem or how to diagnose it further?

ArcBruTiles TMS and maps of small areas

The grandcanyon demo is not loading correctly - we should probably contact the author of ArcBruTiles and ask how to implement the TMS XML metadata.

Or is there somewhere a demo which does not not cover whole earth and it is loading ArcBruTiles well?

Implement WMTS TileMatrixSetLimits

This should be implemented:

  <TileMatrixSetLink>
    <TileMatrixSet>EPSG:4326</TileMatrixSet>
    <TileMatrixSetLimits>
      <TileMatrixLimits>
        <TileMatrix>EPSG:4326:0</TileMatrix>
        <MinTileRow>1</MinTileRow>
        <MaxTileRow>1</MaxTileRow>
        <MinTileCol>0</MinTileCol>
        <MaxTileCol>0</MaxTileCol>
      </TileMatrixLimits>
      <TileMatrixLimits>
        <TileMatrix>EPSG:4326:1</TileMatrix>
        <MinTileRow>1</MinTileRow>
        <MaxTileRow>1</MaxTileRow>
        <MinTileCol>0</MinTileCol>
        <MaxTileCol>0</MaxTileCol>
      </TileMatrixLimits>

...

All the required math is in globalmaptiles.py at http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/ we just need to port it to PHP.
This has been partly done already: http://bafford.com/software/aggregate-map-tools/GlobalMapTiles.php.txt

MBTiles with ZXY-OSM Format is Not Supported?

Hi, nice and awesome tool from you.. :)

I have a question.
Is it only supports MBTiles with TMS specification? --- The inverted Y one?

When I'm trying to use MBTiles with ZXY-OSM specification
(with normal Y from north to south), the map got upside down on each tile.

It seems TileServer.php automaticaly revert the Y order to the output:

  • When the source is ZXY-TMS MBTiles (the reverted Y), the output on the map is correct.
  • When the source is ZXY-OSM MBTiles (the normal Y), the output got upside down.

zxy-tms_mbtiles_resize
zxy-osm_mbtiles_resize

From my dummy-test MBTiles files, it would be seen like that.
The ZXY-TMS is got right, the ZXY-OSM got wrong. Both on z/x/y.jpg output and WMTS output.


It would be great if it supports both format, ZXY-TMS and ZXY-OSM in the future.

Because MBTiles will drop TMS format (inverted Y order, from south to north) in the future,
and start developing ZXY-OSM format (normal Y order from north to south).

As you can see here:
https://github.com/mapbox/mbtiles-spec#roadmap

"The MBTiles format will switch tile ordering to the XYZ schema popularized by OpenStreetMap and away from the Tile Map Service (TMS) specification."

URL encoding in tilejson

Dear all,

it seems the tiljson generation of tileserver-php has an issue with URLs. Tileserver escapes URL slashes (as per json_encode semantics), whereas the tilejson specs appear to require an unquoted string.

Here is an example of wax and leaflet failing to load a tileserver-php provided tilson map.

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>A simple map</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox.js/v1.6.3/mapbox.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox.js/v1.6.3/mapbox.css' rel='stylesheet' />
<style>
  body { margin:0; padding:0; }
  #map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>

<div id='map'></div>
<script>
var map = L.mapbox.map('map', 'http://tileserver.maptiler.com/grandcanyon.json')
    .setView([40, -74.50], 3);
</script>

</body>
</html>

The problem is

"tiles":["http:\/\/tileserver.maptiler.com\/grandcanyon\/{z}\/{x}\/{y}.png"]

Wihle the specs (https://github.com/mapbox/tilejson-spec/tree/master/2.1.0) require

"tiles": [
        "http://localhost:8888/admin/1.0.0/world-light,broadband/{z}/{x}/{y}.png"
    ],

The problem seems to be the json_encode in lines 519 and 529 of tilesever.php .

I do not know if this is a tileserver-php or leaflet and wax issue?
Timo (kurt)

Empty tiles should have for @2x layers 512x512px

Layers ending with @2x should return 512x512px empty tile instead of 256x256px.
It is about change of getCleanTile - probably passing width while knowing about retina.

http://tileserver.maptiler.com/grandcanyon@2x/12/769/1608.png
http://ol3js.org/en/master/examples/xyz-retina.html

The report is form @fredj:

Some retina tiles (those with a @2x in the name) do not have a correct size (256 instead of 512).
Example: http://tileserver.maptiler.com/grandcanyon@2x/12/769/1608.png

The wrong tiles appears to be only the "empty" one (transparent png)

The issue is visible with the ol3 example: http://ol3js.org/en/master/examples/xyz-retina.html but only with firefox (IndexSizeError in the console).

Installation Trouble

I copied my .mbtiles file to the tileserver directory. When I go to view them, I can only see the base map, not the map I created in Tile Mill.

#0 /var/www/XXX.com/maps/tileserver.php(254): PDO->__construct('sqlite:geograph...', '', '', Array)
#1 /var/www/XXX.com/maps/tileserver.php(165): Server->DBconnect('geography-class...')
#2 /var/www/XXX.com/maps/tileserver.php(81): Server->metadataFromMbtiles('geography-class...')
#3 /var/www/XXX.com/maps/tileserver.php(457): Server->setDatasets()
#4 [internal function]: Server->getHtml()
#5 /var/www/XXX.com/maps/tileserver.php(1452): call_user_func(Array)
#6 /var/www/XXX.com/maps/tileserver.php(29): Router::serve(Array)
#7 {main}

Does anyone know what I'm doing wrong? Thanks.

More user-friendly installation with a warning for missing .htaccess

It would be great to start to use index.php for the HTML interface.

This interface should also check the proper installation - including the test of URLs (already done in the tileserver.php) and of the availability of .htaccess file.

Ideas for proper .htacess tests:

  • check file by is_readable(".htaccess")
  • print_r(apache_get_modules()) will show you the loaded Apache modules (only if PHP runs as a module as well)
  • use "SetEnv TILESERVER ok" in .htaccess and "$indexUrl = getenv('TILESERVER');" in PHP.

GD module dependency

It seems there is a depency on the GD module of PHP just to serve an empty tile. Probably a string constant with a few bytes for 1x1PNG and JPEG would be faster and easier to make - in case functions like imagecreatetruecolor are not available on the server.

Limit for WIDTH and HEIGHT?

Tileserver works very well as a WMTS layer in QGIS but if I try to print the layer I am given a warning shown below and this does appear to be the case or at least the map tiles do not appear on the print out (are shown in composer)

Does Tileserver have a limit as per the warning below or is something else preventing printing of the tiles in QGIS?

Some WMS servers (e.g. UMN mapserver) have a limit for the WIDTH and HEIGHT parameter. Printing layers from such servers may exceed this limit. If this is the case, the WMS layer will not be printed

problems with utfgrid on shared server

hi!
congrats for this code, works fine on a normal vps but in a shared host from 1and1
i receive this message when I try to load an utfgrid
(i've used the recomended lines on the htaccess)

for example:

for this url, used on ol3 as a utfgrid source
http://atnight.ws/bcndynamics/tileserver/d0100.json
i receive this console error

Uncaught SyntaxError: Unexpected token <
d0100.json?callback=callbacks._12if3txcg7:1

** an example of a working tiles is this
http://atnight.ws/bcndynamics/tileserver/d0100/14/8288/6120.png
http://atnight.ws/bcndynamics/tileserver/d0100/14/8288/6120.grid.json

i'm not able to understand what's happening...
someone knows something about this error?

unexpected token _

Hi - I'm using tileserver with an uncustomized mapbox example and getting the error:

Uncaught SyntaxError: Unexpected token _
<img width="1637" alt="screen shot 2015-10-28 at 3 40 21 pm" src="https://cloud.githubusercontent.com/assets/520541/10800822/6648c6dc-7d8a-11e5-9dae-b346bb651d18.png">

Basically all I've done is download tileserver, serve it on a local MAMP server, drop an .mbtile file exported from tilemill into the tileserver directory, and load up tileserver.php, and click on the "preview" link under mapbox.

screen shot 2015-10-28 at 3 40 21 pm

See attached image.

Correct empty vector tile / pbf

The request out of the bounds of vector tiles or not found pbf blobs should respond with a proper empty pbf tile probably... related to existing implementation of vector tiles #42.

Large mbtiles

I'm using a 14GB mbtile file with tileserver and it seems it takes a lot of time to load the initial server page. With smaller files (around 1-2 GB) things are almost instant.

Thumb image to use the "center" metadata

Currently the thumb image seems to be taken "randomly" in the middle of the world and middle zoom… Isn't there a better way with which we could decide where it is? At least make it an existing tile?

Cache

Tileserver could be faster when it could be possible to create cache files of metadata. Idea:

  1. create variable in globalconfig 'cache' with values true or false (default could be false)
  2. if global cache is true, tileserver will generate cache files if they are requested:
    a) index.json
    b) layer1json, layer2.json etc.
    c) we can also cache wmts files to file like wmts/1.0.0/WMTSCapabilities.xml
  3. Create link for quick working with cache:
    www.server.dom/cache-clean - delete cache
    www.server.dom/cache-create - create cache

With this we can compute more metadata attributes in future.

We can store cache into root directory when tileserver.php is located and serve it via webserver or store it in folder 'cache' and serve it via script (first check if file exists, then return file or create and return).

TileServer-php checker

Create one single php file which will check if hosting is ready for installing tileserver. This script will do:

  • validate baseurl and display it
  • check mod rewrite
  • check support for sqlite
if (!extension_loaded('pdo_sqlite')) {
    # HTTP Error 500
    echo "PHP: PDO SQLite extension is not installed";
    die;
}
  • check version of php

GeoJSON editor integration

It would be great to integrate a functionality for:

  • create and edit basic vector data on top of a tileset (add and edit markers, geonames for place search, transcriptions, or basic vectorization - markers, polygon, lines + attributes). Something like an integrated http://geojson.io/ or it's rewrite in OL3)
  • allow import of vector data (drag & drop of GeoJSON/SHP/KML ...) a la geojson.io
  • allow export / download (client side generators) a la geojson.io
  • link existing online vector data (url to a geojson) to a tileset. Multiple vector data may be linked.

It seems to me the best storage for small vector data like these is a GeoJSON format saved on GIST or a GitHub repo. Alternative would be a local storage in PHP, but it has disadvantages in interoperability and advantages in independence.

sampe and software

-deleted-
sorry, i accidentally create new thread instead commenting on previous thread.

Error with tileserver.js on line 133

Hi,

I've installed tileserver-php and everything seems to be fine except a problem with the tileserver.js file.

In firebug I've got this error:
TypeError: a[f].tiles is undefined
.../Math.cos(k[1]_Math.PI/180))/Math.PI)/2_Math.pow(2,k[2]))),h=h.replace(/{z}/gi,k...

When I keep the tileserver.js file, I've got the blue header but nothing after just a white page. When I delete the call to this script in tileserver-php.php I can see the list of my maps.

Do you know what I should do to have the interface with all the maps like it is in the description of tileserver-php ?

Thanks

Arnaud

Custom template

Is it possible to allow TileServer to use a custom template by default? Idea: Set path to template in config variable e.g. $config['template'] = 'leaflet.php';
If it's not set TileServer will use default viewer.

In template will be added PHP variables for custom use:
$baseUrls (array) - url to tileserver from config variable
$serverTitle (string) - Title from config variable
$maps (array) - with metadata about layers

Error in retrieving metadata.json

First of all, let me say that the tileserver works (and it works amazingly fast):
I can import my pre-rendered tiles (mbtiles and folders) both in QGIS and with Leaflet, and everything looks great.

However all the times I try and load the tileserver.php, the server "homepage" with my tiles, I receive the following warnings and the page is empty:

  1. Chrome:
    Uncaught TypeError: Cannot read property '0' of undefined (tileserver.js:123)
  2. Firefox:
    TypeError: k is undefined (tileserver.js:123)

http://liber.isma.cnr.it/tileserver-php/

It appears to me that such a problem may be explained by my server errorlog which says:
PHP Warning: file_get_contents(tileserver/metadata.json): failed to open stream: No such file or directory in /var/www/html/SERVER/www/tileserver.php on line 151, referer: http://SERVER/
and as a result:
PHP Warning: array_key_exists() expects parameter 2 to be array, null given in /var/www/html/SERVER/www/tileserver.php on line 173, referer: http://SERVER/
PHP Warning: array_key_exists() expects parameter 2 to be array, null given in /var/www/html/SERVER/www/tileserver.php on line 177, referer: http://SERVER/

I cannot figure it out if this problem depends on my server misconfiguration (mod_write is enabled) or form something else.

All the best, and thank you for this awesome software

Prevent users from downloading MBTiles file

Is there any way to prevent users from downloading your .mbtiles file with this implementation? Normally, I would just add this to my .htaccess file:

<FilesMatch "\.(htaccess|mbtiles)$">
 Order Allow,Deny
 Deny from all
</FilesMatch>

But this is too restrictive as it blocks the streaming of tiles as well.

Thanks!

Strict standards error in PHP 5.4+ on function declarations

tilserver-php fails with > PHP 5.4 due to three functions not having the expected signatures.

The following patch seems to fix it.

568c568
<   public function getUTFGrid() {

---
>   public function getUTFGrid($tileset, $z, $y, $x, $flip = true) {
1085c1085,1086
<   public function getTile() {

---
>   public function getTile(  $tileset, $z, $y, $x, $flip = true)
>   {
1214c1215
<   public function getTile() {

---
>   public function getTile($tileset, $z, $y, $x, $ext) {

Error in coloring

The mbtiles are generated with TileMill from shapefiles, on the same region, with some predefined colors. Each time the online interface is refreshed, the maps are rendered in differents colors, like you can see on the two first screenshots.
With leaflet (or OL, ...), some tiles are rendered in a color and all with another, depending on the zoom factor (last screenshot).
This problem doesn't seem to happen with the tileserver.php from infostreams.

I use the last tileserver.php from github, with Nginx on Ubuntu 14.04.

screenshot_003
screenshot_002
screenshot_004

Not modified HTTP 302

The Conditional get (HTTP 302) - ETag as MD5 based on the modification time of the .mbtiles file.

CORS

Turn on by default.

Malformed UTFGrid (?)

By looking at recent changes of tileserver.php source code, .grid.json files are returned by the statement echo 'grid(' . $grid . ');';. This creates a grid(file.json) which apparently is not conform to the json file that one would expect (for instance, OpenLayers.Control.UTFGrid does not work with such a format).
Switching back to the earlier solution, echo $grid;, instead do the trick.

This is a working example with the proposed patch:
http://dev.isma.cnr.it/geo-ol/ol-tileserver.html
(move mouse on the group of houses near the park)

ciao

ArcGIS online issue with mbtiles layers

Hello,

I have noticed that ArcGIS online has a problem selecting the right layer when multiple mbtiles layers are made available by tileserver-php.

The map editor in ArcGIS allows to add an OGC WMTS layer. After inputting the URL to a WMTS service, it issues a getCapabilities an lets the user select from all available layers.
The issue is that ArcGIS seems to always load the first layer, no matter which one was actually selected. This is if I have "1-map, 2-map, 3-map" tile layers available, what is shown in the ArcGIS map is always "1-map", even though I selected 2-map or 3-map.

I have verified that what is requested by ArcGIS is actually the first layer, thus excluding that the mapserver somehow delivers the wrong content. (by checking webserver logs)
I have also verified that ArgGIS can in general correctly handle selecting one of multiple available layers (by pointing it to v2.suite.opengeo.org/geoserver/gwc/service/wmts/, where the selected layer is shown, no matter which one was selected).

I thus believe that ArcGIS somehow incorrectly parses the getCapabilities request of tileserver-php, or that some element ArgGIS requires is missing in the request.
Comparing a working and a non-working example of getCapabilities requests, I noticed differences in the "TileMatrixSetLimits" elements.

I do not know enough about the WMTS getCapabilities spec to tell what could trigger this behaviour.

Any clues why ArcGIS always requests the first layer from a tileserver-php server?

thanks a lot
kurt

Just getting a blank page with mbtiles

Hi,

I'm trying to get a map from an .mbtiles file generated by Tilemill, but when I load it to my localhost directory (where of course there are all your files) and open the browser I don't get anything at all .
So I tried using mbutils to create a directory with all the tiles and metadata.json, but again, putting all your files in that directory and opening the brower just gets me a blank page (though this time i do get your tileserver header and firebug detects an "invalid json string error").

Could you tell me what am I possibly missing? Thanks!

protocol not taken into account when generating service metadata

tileserver does not recognize if stuff is requested from it via http or https when generating the service metadata. This can be a problem with new browsers that do not like http content being pulled in when the original connection was https. (above all a problem when tileserver and map-using site run on the same domain).
This is, when I request https://mydomain/mymap.json, the service metadata has "grids":["http://mydomain/mymap/{z}/{x}/{y}.grid.json"] , causing the browser to request http stuff whereas the original request was https.. newer versions of chrome and FF do not like that and fail.

A patch against an earlier version of tileserver.php is attached

--- tileserver.php  Mon Aug  4 12:41:21 2014
+++ tileserver-new.php  Mon Aug  4 12:41:05 2014
@@ -412,7 +412,7 @@
     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>';
@@ -492,7 +492,7 @@
     $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'])) {
@@ -500,7 +500,7 @@
       $res = $this->db->query('SELECT grid FROM grids LIMIT 1');
       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;
       }
@@ -645,7 +645,7 @@
     <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>
@@ -653,7 +653,7 @@
             </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>
@@ -666,14 +666,14 @@
     <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>
@@ -721,7 +721,7 @@
       <TileMatrixSetLink>
         <TileMatrixSet>' . $tileMatrixSet . '</TileMatrixSet>
       </TileMatrixSetLink>
-      <ResourceURL format="' . $mime . '" resourceType="tile" template="http://'
+      <ResourceURL format="' . $mime . '" resourceType="tile" template="' . $config['protocol'] . '://'
       . $this->config['baseUrls'][0] . '/wmts/' . $basename . '/{TileMatrixSet}/{TileMatrix}/{TileCol}/{TileRow}.' . $format . '"/>
     </Layer>';
     }
@@ -1077,7 +1077,7 @@
       </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>';
   }

@@ -1158,7 +1158,7 @@
         $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>';
@@ -1196,7 +1196,7 @@
     }
     $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>
@@ -1205,7 +1205,7 @@
   <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>';
   }
@@ -1357,6 +1357,7 @@
    */
   public static function serve($routes) {
     $request_method = strtolower($_SERVER['REQUEST_METHOD']);
+   global $config;
    $config['protocol'] = ( isset($_SERVER["HTTPS"]) or $_SERVER['SERVER_PORT'] == '443') ? "https" : "http";
     $path_info = '/';
     if (!empty($_SERVER['PATH_INFO'])) {
@@ -1380,7 +1381,7 @@
           ':number' => '([0-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)) {

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.