<?php
include "gm.php";
$zoom = $_GET["zoom"];
$tileX = $_GET["x"];
$tileY = $_GET["y"];
$value = Google_Tile_Factors( $zoom );
$tile = Google_Tile_Calc( $value, $tileY, $tileX ) ;
header ('Content-type: image/png');
$tileImage = "uploads/imagetiles/".$zoom."/x".$tileX."_y".$tileY.".png";
if( file_exists($tileImage) ){
$im = imagecreatefrompng($tileImage);
imagepng($im);
imagedestroy($im);
}
else{
$im = @imagecreatetruecolor(256, 256) or die('Cannot Initialize new GD image stream');
imagesavealpha($im, true);
$trans_colour = imagecolorallocatealpha($im, 0, 0, 0, 127);
imagefill($im, 0, 0, $trans_colour);
$text_color = imagecolorallocate($im, 233, 14, 91);
$strArr = array(
"X=".$tileX . ", Y=".$tileY.", ZOOM=".$zoom,
"latN: ".$tile["LATN"],
"lngW: ".$tile["LNGW"],
"latS: ".$tile["LATS"],
"lngE: ".$tile["LNGE"],
"pixN: ".$tile["PYN"],
"pixW: ".$tile["PXW"],
"pixS: ".$tile["PYS"],
"pixE: ".$tile["PXE"]
);
$y = 5;
foreach($strArr as $str){
imagestring($im, 2, 5, $y, $str , $text_color);
$y = $y+15;
}
imagerectangle($im, 0, 0, 255, 255, $text_color);
imagepng($im);
imagedestroy($im);
}
function output($str){
global $outputImg;
if(!$outputImg)
echo $str."\n";
}
function outputObj($obj){
global $outputImg;
if(!$outputImg)
print_r($obj);
}
function drawRoute($im, $color, $polygon){
imagepolygon ( $im , $polygon , count($polygon) / 2 , $color );
}
/*
function createPolygon($zoom, $pointsLngLat, $top, $left){
$points = array();
foreach($pointsLngLat as $pointLngLat){
$point = Google_RelPix($pointLngLat[1], $pointLngLat[0], $zoom);
$x = $point[0] - $top;
$y = $point[1] - $left;
// swap axes
$points[] = $y;
$points[] = $x;
}
return $points;
}
*/
function insideImage($tile, $bbox){
$inside = true;
if( $bbox["minLng"] > $tile["LNGE"] || $bbox["maxLng"] < $tile["LNGW"] ||
$bbox["maxLat"] < $tile["LATS"] || $bbox["minLat"] > $tile["LATN"]){
$inside = false;
}
return $inside;
}
function parseToPoints($routeStr, $zoom, $top, $left){
$parts = split(":", $routeStr);
$pointsLngLat = array();
$polygon = array();
$minLat = 90;
$maxLat = -90;
$minLng = 180;
$maxLng = -180;
foreach($parts as $part){
$parsed = split(",", $part);
$lng = $parsed[1];
$lat = $parsed[2];
$pointsLngLat[] = array($lng, $lat);
$point = Google_RelPix($lat, $lng, $zoom);
$x = $point[0] - $top;
$y = $point[1] - $left;
// swap axes
$polygon[] = $y;
$polygon[] = $x;
if( $lat > $maxLat ) $maxLat = $lat;
if( $lat < $minLat ) $minLat = $lat;
if( $lng > $maxLng ) $maxLng = $lng;
if( $lng < $minLng ) $minLng = $lng;
}
return array( array("minLat"=>$minLat,"maxLat"=>$maxLat,"minLng"=>$minLng,"maxLng"=>$maxLng), $pointsLngLat, $polygon);
}
function drawPoint($lat, $lng, $zoom, $top, $left, $im, $color){
$point = Google_RelPix($lat, $lng, $zoom);
imagestring($im, 2,10, 150, $point[0].",".$point[1] , $color);
$x = $point[0] - $top;
$y = $point[1] - $left;
imagestring($im, 2,10, 165, $x.",".$y , $color);
imagearc($im, $y, $x, 20, 20, 0, 360, $color);
}
?>