<?php
# header('Content-Type: text/plain');
//explanation: https://gist.github.com/tmcw/4954720
//source: https://github.com/timwaters/whoots/blob/master/whoots.rb
function get_tile_bbox($x,$y,$z) {
$merc1 = get_merc_coords($x * 256, $y * 256, $z);
$merc2 = get_merc_coords(($x + 1) * 256, ($y + 1) * 256, $z);
$min_x = $merc1['merc_x']; $min_y = $merc1['merc_y'];
$max_x = $merc2['merc_x']; $max_y = $merc2['merc_y'];
return $min_x.",".$min_y.",".$max_x.",".$max_y;
}
function get_merc_coords($x,$y,$z) {
$resolution =
(2 *
pi() *
6378137 /
256) /
(pow(2,
$z));
# echo 'resolution: '.$resolution . "n";
$merc_x =
($x *
$resolution -
2 *
pi() *
6378137 /
2.0);
$merc_y =
($y *
$resolution -
2 *
pi() *
6378137 /
2.0);
return compact('merc_x',
'merc_y');
}
$bbox = get_tile_bbox($x,$y,$zoom);
header('Location: http://apollo.cdngiportal.co.za/erdas-iws/ogc/wms/CDNGI_PORTAL_BACKDROP?FORMAT=image/jpeg&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&LAYERS=CDNGI_50K_1stEdition_Mosaic&STYLES=&SRS=EPSG:3857&WIDTH=256&HEIGHT=256&BBOX='.
$bbox);