[go: up one dir, main page]

Menu

[r1]: / omgm / img.php  Maximize  Restore  History

Download this file

149 lines (110 with data), 3.4 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
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?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);
}
?>