pastebin

Paste Search Dynamic
Recent pastes
za topo historical wms tms
  1. <?php
  2. # header('Content-Type: text/plain');
  3.  
  4. $zoom = (int) htmlspecialchars($_GET["zoom"]);
  5. $x = (int) htmlspecialchars($_GET["x"]);
  6. $y = (int) htmlspecialchars($_GET["y"]);
  7.  
  8. //explanation: https://gist.github.com/tmcw/4954720
  9. $y = pow(2, $zoom)-$y-1;
  10.  
  11. //source: https://github.com/timwaters/whoots/blob/master/whoots.rb
  12. function get_tile_bbox($x,$y,$z) {
  13.   $merc1 = get_merc_coords($x * 256, $y * 256, $z);
  14.   $merc2 = get_merc_coords(($x + 1) * 256, ($y + 1) * 256, $z);
  15.  
  16.   $min_x = $merc1['merc_x']; $min_y = $merc1['merc_y'];
  17.   $max_x = $merc2['merc_x']; $max_y = $merc2['merc_y'];
  18.   return $min_x.",".$min_y.",".$max_x.",".$max_y;
  19. }
  20.  
  21. function get_merc_coords($x,$y,$z) {
  22.   $resolution = (2 * pi() * 6378137 / 256) / (pow(2,$z));
  23. #  echo 'resolution: '.$resolution . "n";
  24.   $merc_x = ($x * $resolution - 2 * pi() * 6378137 / 2.0);
  25.   $merc_y = ($y * $resolution - 2 * pi() * 6378137 / 2.0);
  26.   return compact('merc_x', 'merc_y');
  27. }
  28.  
  29. $bbox = get_tile_bbox($x,$y,$zoom);
  30.  
  31. 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);
Parsed in 0.066 seconds