infostreams / mbtiles-php Goto Github PK
View Code? Open in Web Editor NEWThis project forked from zverik/mbtiles-php
PHP backend for reading tiles from mbtiles databases
License: MIT License
This project forked from zverik/mbtiles-php
PHP backend for reading tiles from mbtiles databases
License: MIT License
https://www.mapbox.com/developers/api/maps/#tilejson
Note webpage is required.
I have done a 'best effort' of server_url from
$server_url = $protocol . "://" . $_SERVER["HTTP_HOST"] . dirname($_SERVER["REQUEST_URI"]);
I got mbtiles-php running with nginx. You might want to mention somewhere (readme or wiki) that the rewrite rule in the .htacess file has to be set in the nginx config.
For example, if you put the files (.htaccess, tileserver.php and mbtiles) in /mbtiles-php/ of your document root, then the following lines have to be added to the nginx configuration file:
...
location /mbtiles-php/ {
try_files $uri /mbtiles-php/tileserver.php$is_args$args;
}
...
you might want to mention as well that sqlite has to be enabled in the php.ini
...
extension=pdo_sqlite.so
...
I created an mbtiles files with TileMill (Version 0.10.1 (v0.10.1), napa1.mbtiles.
I cloned your project and placed therein the napa1.mbtiles.
I then created a file /var/www/localhost/htdocs/test.html with the following:
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'/>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script> -->
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<div id='map' ></div>
<script type="text/javascript">
// set up the map
var map = new L.Map('map');
// url to the tile server
var url = 'http://themis/mbtiles-php/napa1.mbtiles/{z}/{x}/{y}.png';
//tms:true is required for the TileMill databases
var layer = new L.TileLayer(url, {minZoom:15, maxZoom:19, tms:true });
// set the viewport
map.setView({lat: 38.297619, lng: -122.296316}, 15);
//add layer to the map
map.addLayer(layer);
</script>
</body>
</html>
The output is only a gray screen showing the zoom widget. Firebug has this output:
[07:04:03.305] GET http://themis/test.html [HTTP/1.1 304 Not Modified 2ms]
[07:04:03.400] GET http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.css [HTTP/1.1 304 Not Modified 25ms]
[07:04:03.401] GET http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.js [HTTP/1.1 304 Not Modified 33ms]
[07:04:03.470] GET http://themis/mbtiles-php/napa1.mbtiles/15/5252/20163.png [HTTP/1.1 404 Not Found 1ms]
[07:04:03.470] GET http://themis/mbtiles-php/napa1.mbtiles/15/5252/20162.png [HTTP/1.1 404 Not Found 1ms]
[07:04:03.471] GET http://themis/mbtiles-php/napa1.mbtiles/15/5251/20163.png [HTTP/1.1 404 Not Found 2ms]
[07:04:03.472] GET http://themis/mbtiles-php/napa1.mbtiles/15/5253/20163.png [HTTP/1.1 404 Not Found 2ms]
[07:04:03.472] GET http://themis/mbtiles-php/napa1.mbtiles/15/5251/20162.png [HTTP/1.1 404 Not Found 2ms]
[07:04:03.473] GET http://themis/mbtiles-php/napa1.mbtiles/15/5253/20162.png [HTTP/1.1 404 Not Found 2ms]
[07:04:03.474] GET http://themis/mbtiles-php/napa1.mbtiles/15/5252/20164.png [HTTP/1.1 404 Not Found 2ms]
[07:04:03.475] GET http://themis/mbtiles-php/napa1.mbtiles/15/5252/20161.png [HTTP/1.1 404 Not Found 3ms]
[07:04:03.475] GET http://themis/mbtiles-php/napa1.mbtiles/15/5251/20164.png [HTTP/1.1 404 Not Found 3ms]
[07:04:03.476] GET http://themis/mbtiles-php/napa1.mbtiles/15/5253/20164.png [HTTP/1.1 404 Not Found 3ms]
[07:04:03.476] GET http://themis/mbtiles-php/napa1.mbtiles/15/5251/20161.png [HTTP/1.1 404 Not Found 3ms]
[07:04:03.477] GET http://themis/mbtiles-php/napa1.mbtiles/15/5253/20161.png [HTTP/1.1 404 Not Found 4ms]
[07:04:03.477] GET http://themis/mbtiles-php/napa1.mbtiles/15/5250/20163.png [HTTP/1.1 404 Not Found 4ms]
[07:04:03.478] GET http://themis/mbtiles-php/napa1.mbtiles/15/5254/20163.png [HTTP/1.1 404 Not Found 4ms]
[07:04:03.479] GET http://themis/mbtiles-php/napa1.mbtiles/15/5250/20162.png [HTTP/1.1 404 Not Found 5ms]
[07:04:03.479] GET http://themis/mbtiles-php/napa1.mbtiles/15/5254/20162.png [HTTP/1.1 404 Not Found 5ms]
[07:04:03.480] GET http://themis/mbtiles-php/napa1.mbtiles/15/5250/20164.png [HTTP/1.1 404 Not Found 4ms]
[07:04:03.480] GET http://themis/mbtiles-php/napa1.mbtiles/15/5254/20164.png [HTTP/1.1 404 Not Found 5ms]
[07:04:03.481] GET http://themis/mbtiles-php/napa1.mbtiles/15/5250/20161.png [HTTP/1.1 404 Not Found 6ms]
[07:04:03.481] GET http://themis/mbtiles-php/napa1.mbtiles/15/5254/20161.png [HTTP/1.1 404 Not Found 6ms]
Here's the log of my install:
themis htdocs # pwd
/var/www/localhost/htdocs
themis htdocs # git clone https://github.com/infostreams/mbtiles-php.git
Cloning into 'mbtiles-php'...
remote: Counting objects: 85, done.
remote: Compressing objects: 100% (45/45), done.
remote: Total 85 (delta 42), reused 79 (delta 39)
Unpacking objects: 100% (85/85), done.
themis htdocs # cp /home/jlpoole/napa1.mbtiles mbtiles-php
themis htdocs # chown -R apache:apache mbtiles-php
themis htdocs # ls -la mbtiles-php
total 52024
drwxr-xr-x 3 apache apache 4096 Sep 29 07:12 .
drwxr-xr-x 7 root root 4096 Sep 29 07:11 ..
drwxr-xr-x 7 apache apache 4096 Sep 29 07:11 .git
-rw-r--r-- 1 apache apache 23 Sep 29 07:11 .gitignore
-rw-r--r-- 1 apache apache 190 Sep 29 07:11 .htaccess
-rw-r--r-- 1 apache apache 53159936 Sep 29 07:12 napa1.mbtiles
-rw-r--r-- 1 apache apache 899 Sep 29 07:11 README
-rw-r--r-- 1 apache apache 1106 Sep 29 07:11 server-setup.md
-rw-r--r-- 1 apache apache 21092 Sep 29 07:11 tileserver.php
themis htdocs #
I've also tried ommitting the ".mbtiles" suffix, and no change
var url = 'http://themis/mbtiles-php/napa1/{z}/{x}/{y}.png';
I have spent hours trying various things which I'm not going to pollute this posting with and cannot get the tiles to appear. Could you provide a sample file, e.g. test.html, that is proven to work and/or further instructions?
I can make the napa1.mbtiles available if you'd like to test using what I have. Alternatively, can you make available a known mbtiles file that works?
Thank you.
I put the .php file and the .htaccess file in the same directory as my mbtiles file (http://maps.ecodiv.org/tiles), but now when going to that folder in my webbrowser, I get a 403 permission error. Any idea where I should look for?
Hello,
first of al thank you for this piece of software. It works wonderfully. I noticed today that the server does not support @2x
images. I created a map and it worked perfectly on desktop, but when I tried to load it in tablets and smartphones no tiles were visible. Remore debugging showed a list of 404 errors about missing *@2x.png
tiles.
Any help would be much appreciated
I get the following error:
2014/07/16 15:54:08 [error] 148#0: *323 FastCGI sent in stderr: "PHP message: PHP Warning: preg_match(): Compilation failed: invalid range in character class at offset 16 in [path to mbtiles-php]/example/server/tileserver.php on line 737
PHP message: PHP Warning: preg_match(): Compilation failed: invalid range in character class at offset 16 in [path to mbtiles-php]/example/server/tileserver.php on line 737
PHP message: PHP Warning: preg_match(): Compilation failed: invalid range in character class at offset 16 in [path to mbtiles-php]/example/server/tileserver.php on line 737
PHP message: PHP Warning: preg_match(): Compilation failed: invalid range in character class at offset 16 in [path to mbtiles-php]/example/server/tileserver.php on line 737
PHP message: PHP Warning: preg_match(): Compilation failed: invalid range in character class at offset 10 in [path to mbtiles-php]/example/server/tileserver.php on line 737
PHP message: PHP Warning: preg_match(): Compilation failed: invalid range in character class at offset 10 in [path to mbtiles-php]/example/server/tileserver.php on line 737
PHP message: PHP Warning: preg_match(): Compilation failed: invalid range in character class at offset 10 in [path to mbtiles-php]/example/server/tileserver.php on line 737
PHP message: PHP Warning: preg_match(): Compilation failed: invalid range in character class at offset 10 in [path to mbtiles-php]/example/server/tileserver.php on line 737
This warning reffers to the following line in tileserver.php.
...
if (preg_match('@^' . $url_regex . '$@', $request, $p_values)) {
...
I googled the warning and found this on stackoverflow. After a small change in tileserver.php, everything was working.
...
$_identifier = '[\w\d\s-_]+';
#$_identifier = '[\w\d_-\s]+';
$_number = '\d+';
...
I have read that PHP 5.5 requires the hyphen to be escaped or moved to the end of the list if you want it to match a literal hyphen. I don't know a lot about php and this might not be the proper way to solve the problem... (I just know how to read code and how to use google ๐)
First, thank you for both the wonderful code and the great examples. I'm not much of a javascript programmer, but I was able to start with your examples and, with a little reference on MapBox, get the maps behaving EXACTLY the way I wanted them to. On Localhost.
When I moved my code up to my GoDaddy, it didn't work. I can access the page, and a WMS basemap works fine. But nothing that depends on mbtiles. I've checked, and both pdo_sqlite and GD extensions are installed. Any other thoughts? Is there a minimum php release? My account was running php 5.3.24, I believe. It's definitely running Apache.
I have copied the the project and put it under a Apache server. Trying to run the example file but its returning the following error
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at [email protected] to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
Apache/2.4.9 (Win64) PHP/5.5.12 Server at localhost Port 80
Hi, I would like to use some of the features available in mapbox.js dealing with geojson files. Is there any possibility for mbtiles-php to serve the geojson just like the tilejson from and .mbtiles file?
Thank you very much!
we are trying to publish some maps in a 1and1 server
but we have several problems
htaccess works fine (i think)
but i don't know if there's any missing or depreceated php module
perhaps it helps http://atnight.ws/code/info.php5
1and1 is a very unconfortable hosting service with infinite limited capabilities (but cheap).
Perhaps could be interesting recommend a hosting service working fine with this code.
First off, I've not actually run the PHP script, I've just been converting it to python (at aidanhs/mbtiles-py). I noticed two caching issues:
header("Expires: " . gmdate('D, d M Y H:i:s', time()+$expires))
Per http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.21 I think this needs the GMT part on it.
protected function etag($type) {
return sha1(sprintf("%s-%s-%s-%s-%s-%s", $this->tileset, $this->x, $this->y, $this->z, $type, filemtime($this->getMBTilesName())));
}
ETag values should be surrounded by double quotes.
Hi!
Recently we have made a complete rewrite of the project:
https://github.com/klokantech/tileserver-php
Some of the code is inspired by your clean PHP code. Can you please make a short review of our source codes and give us some feedback regarding the project in general?
Maybe it is a time to merge the two PHP projects... I am keen to hear from you.
Petr
Iโm not sure if this is caused by tilemill, leaflet or mbtiles-php, but I get black tiles in areas where there is no tile data. It seems this should rather be transparent areas.
Hello I'm having issues using mbtiles-php inside a symlinked folder.
The main issue is related to line 607:
$here = str_replace("\\", "/", realpath(rtrim(dirname(__FILE__), '/')) . "/");
FILE resolves symlinks and so does realpath. This prevent the route to be resolved...
I actually solved changing this line to:
$here = str_replace("\\", "/", rtrim(dirname($_SERVER["SCRIPT_FILENAME"]), '/') . "/");
ie. replacing __FILE__
with $_SERVER["SCRIPT_FILENAME"]
and removing any reference to realpath()
.
Of course this dirty workaround fixes the issue on paths containing symlink, but breaks the program on "normal" paths...
Hi
I've been trying to deploy the php tileserver in my domain root and it wouldn't work. However if I put it in a separate folder, the serving works just fine.
Interestingly when the server is running from the root, the tilejson is served with tile addresses as such: http://tiles.eveningscode.com//cyclemap2/{z}/{x}/{y}.png
notice the double // after the domain root.
Am I doing something wrong in the configuration perhaps?
Best regards,
Peter
I've been trying to load tiles from a .mbtiles file using mbtiles-php without much success.
I followed the instructions and installed a foo.mbtiles file on the same folder as .htaccess and tileserver.php. I have GD and PDO enabled on my server. Here's the code:
$(window).load(function() {
var map = L.map('map').setView([74.2343, -54.43534], 14);
L.tileLayer('./tiles/foo.mbtiles/{z}/{x}/{y}.png', {
maxZoom: 19
}).addTo(map);
});
I'm getting several of these on my console:
Failed to load resource: the server responded with a status of 404 (Not Found)
http://43.000.00.0/tiles/foo.mbtiles/13/3888/3139.png
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.