-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
35 lines (31 loc) · 1.04 KB
/
index.php
File metadata and controls
35 lines (31 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
// get tile identifier parameters
$z = intval($_GET['z']);
$x = intval($_GET['x']);
$y = intval($_GET['y']);
// check if the requested tile is rendered and stored locally
// (if not, this request will init the rendering process)
$ch_local = curl_init("http://localhost/hot/$z/$x/$y.png");
curl_setopt($ch_local, CURLOPT_CONNECTTIMEOUT, 0.5);
curl_setopt($ch_local, CURLOPT_TIMEOUT, 0.5);
curl_setopt($ch_local, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch_local);
// if no error occurred return locally rendered image, on timeout return openstreetmap tile
if (! curl_errno($ch_local)) {
header ('Content-Type: image/png');
echo $response;
} else {
$server = [];
$server[] = 'a.tile.openstreetmap.org';
$server[] = 'b.tile.openstreetmap.org';
$server[] = 'c.tile.openstreetmap.org';
$url = 'http://' . $server[array_rand($server)] . "/$z/$x/$y.png";
$ch = curl_init($url);
$fp = fopen($file, "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fflush($fp);
fclose($fp);
}