256) {$imagesamplesize=64;} $minutes=''; $minutes=$_GET['minutes'];//Zeitfenster zur Anzeige if($minutes=='') {$minutes=30*24*60;}//1 Monat $lat_deg=lat_deg($xtile, $ytile, $zoom);//Startpunkt x $lat=convertPosToInteger($lat_deg, true); $lon_deg=lon_deg($xtile, $ytile, $zoom);//Startpunkt y $lon=convertPosToInteger($lon_deg, false); $numberOfTilesRow=1; for($i=0; $i<$zoom; $i++) {$numberOfTilesRow=$numberOfTilesRow*2;}//Potenz, Anzahl der Tiles in einer Richtung $unten=lat_deg(0,$numberOfTilesRow,$zoom); $unten=convertPosToInteger($unten,true); $unten=stretchLat($unten);//$unten=-179.9999096052 $oben=lat_deg(0,0,$zoom); $oben=convertPosToInteger($oben,true); $oben=stretchLat($oben);//$oben=197.99999096052 //print $oben-$unten.'
'; //print $numberOfTilesRow.'
'; $bildHoeheStretch=($oben-$unten)/($numberOfTilesRow); //print 'bildHoeheStretch '.$bildHoeheStretch.'
'; $startpunktYStretch=($oben-$unten)-(($numberOfTilesRow)-($ytile))*$bildHoeheStretch; $endpunktYStretch= ($oben-$unten)-(($numberOfTilesRow)-($ytile+1))*$bildHoeheStretch; //print $startpunktYStretch.'
'; //print $endpunktYStretch.'
'; $bildBreite=360000000/$numberOfTilesRow; $bildHoehe=$bildBreite/2; $endpunktX=round($lon+$bildBreite); $endpunktY=round($lat+$bildHoehe); /* echo "xtile ".$xtile." ytile ".$ytile." lat_deg ".$lat_deg." lon_deg ".$lon_deg."
"; echo "lat ".$lat." lon ".$lon."
"; echo "numberOfTilesRow ".$numberOfTilesRow." bildBreite ".$bildBreite." endpunktX ".$endpunktX." endpunktY ".$endpunktY."
"; echo $lat." ".$endpunktY." ".$lon." ".$endpunktX."

"; echo "lon_ ".$lon." lat_ ".$lat."
"; echo "endx".$endpunktX." endy".$endpunktY."
"; */ $result = $db->query("SELECT * FROM PosSpeed WHERE Lat>=".$lat." AND Lat<".$endpunktY." AND Lon>=".$lon." AND Lon<".$endpunktX." AND Time>".(time()-$minutes*60)); //$result = $db->query("SELECT * FROM PosSpeed WHERE Lat>=".$lat." AND Lat<".$endpunktY." AND Lon>=".$lon." AND Lon<".$endpunktX); $i=0; $arr=array(); $imageArray=array(array(array())); foreach($result as $row) { //echo "result found lon ".$row['Lon']." lat ".$row['Lat']." speed ".$row['Speed']." time ".$row['Time']."
"; $xpixel=$row['Lon']-$lon; $xpixel=$xpixel*$imagesamplesize/$bildBreite; $xpixel=round($xpixel); //echo "xpixel: ".$xpixel."
"; /* $ypixel=$row['Lat']-$lat; $ypixel=$ypixel*$imagesamplesize; $ypixel=$ypixel/$bildHoehe; $ypixel=round($ypixel); //echo "ypixel: ".$ypixel."
"; */ ///* $ypixel=$row['Lat']; //echo '

'.$ypixel.'
'; if($ypixel<90000000) { $ypixel=stretchLat($ypixel); //echo 'gestreckt '.$ypixel.'
'; $ypixel=$oben-$ypixel; //echo 'skala '.$ypixel.'
'; //$ypixel=$ypixel+$bildHoeheStretch*($ytile); //echo $ypixel.'
'; } else { $ypixel=stretchLat($ypixel); //echo 'gestreckt '.$ypixel.'
'; $ypixel=-$ypixel; //$ypixel=$ypixel+$bildHoeheStretch*($ytile-$numberOfTilesRow/2); $ypixel=$ypixel+$oben; //echo 'skala '.$ypixel.'
'; } $ypixel=$ypixel-$startpunktYStretch; $ypixel=$ypixel*$imagesamplesize/$bildHoeheStretch; //$ypixel=$ypixel/($oben-$unten)*$imagesamplesize; //echo $ypixel.'
'; $ypixel=round($ypixel); //echo 'xpixel '.$xpixel.'
'; //echo 'ypixel '.$ypixel.'
'; $imageArray[$xpixel][$ypixel]=array($imageArray[$xpixel][$ypixel][0]+$row['Speed'],$imageArray[$xpixel][$ypixel][1]+1); $imageArray[2][4]=array(0,1,2); $arr[$i]=Array($xpixel,$ypixel,$row['Speed']); //echo $imageArray[$xpixel][$ypixel][0]; //echo $imageArray[$xpixel][$ypixel][1]; $i++; //echo '

i: '.$i.'

'; } //echo "

Ausgabe des Arrays
"; $im = imagecreate($imagesamplesize,$imagesamplesize); $black = imagecolorallocate($im, 0, 0, 0); // Make the background transparent imagecolortransparent($im, $black); for($i=0;$i<$imagesamplesize;$i++) { for($j=0;$j<$imagesamplesize;$j++) { if($imageArray[$i][$j][1]>0) { //echo $imageArray[$i][$j][0]/$imageArray[$i][$j][1]; //echo $a[0]." : ".$a[1]." : ".$a[2]." : ".$a[3]."
"; //Farbe bestimmen $speed=$imageArray[$i][$j][0]/$imageArray[$i][$j][1]; if($speed>120) {$gb=120;} $r=0; $b=0; $g=0; if($speed<=60) { $r=250-(250/60)*$speed; $b=(250/60)*$speed; } else { $b=250-(250/60)*($speed-60); $g=(250/60)*($speed-60); } $col = imagecolorallocate($im, $r,$g,$b); /*imagesetpixel($im,$i-1,$j-1,$col); imagesetpixel($im,$i-1,$j,$col); imagesetpixel($im,$i-1,$j+1,$col); imagesetpixel($im,$i,$j-1,$col);*/ imagesetpixel($im,$i,$j,$col); /*imagesetpixel($im,$i,$j+1,$col); imagesetpixel($im,$i+1,$j-1,$col); imagesetpixel($im,$i+1,$j,$col); imagesetpixel($im,$i+1,$j+1,$col);*/ } } } $imb=imagecreate(256,256); $black = imagecolorallocate($imb, 0, 0, 0); imagecolortransparent($imb, $black); imagecopyresized($imb, $im, 0, 0, 0, 0, 256, 256, $imagesamplesize, $imagesamplesize); header('Content-type: image/png'); imagepng($imb,NULL,9); imagedestroy($im); // close the database connection $db = NULL; function stretchLat($pLat)//Eingabe internes Integer Format, Ausgabe Deg als real { //print $pLat.'
'; if($pLat<90000000) { //print 'kleiner
'; $pLat=90000000-$pLat; while(strlen($pLat)<9) { $pLat="0".$pLat; } $pLat=substr($pLat,0,3).".".substr($pLat,3); } else { //print 'groesser
'; $pLat=$pLat-90000000; while(strlen($pLat)<9) { $pLat="0".$pLat; } $pLat='-'.substr($pLat,0,3).".".substr($pLat,3); } //print $pLat.'
'; $pLat=$pLat*pi()/180; $pLat=log(tan($pLat)+sqrt(tan($pLat)*tan($pLat)+1)); $pLat=$pLat*180/pi(); //$pLat=120.0; //print $pLat; //$pLat=convertPosToInteger(substr($pLat,0),true); return $pLat; } function radToDeg($deg)//Eingabe Rad als real, Ausgabe Deg als real { return $deg*180/pi(); } function lon_deg($xtile, $ytile, $zoom) { //Tile numbers to lon./lat. $n = pow(2, $zoom); return $xtile / $n * 360.0 - 180.0; } function lat_deg($xtile, $ytile, $zoom) { //Tile numbers to lon./lat. $n = pow(2, $zoom); return rad2deg(atan(sinh(pi() * (1 - 2 * $ytile / $n)))); } function convertPosToInteger($x, $lat)//Eingabe Pos als String wie real, boolean $lat=true falls lat, falls lon dann false, Ausgabe internes neunstelliges Format als Integer { //echo "convertPosToInteger(".$x.")

"; //Vorzeichen erkennen $sngx="+"; if(substr($x,0,1)=="-") { $sngx="-"; $x=substr($x,1); } //echo "Vorzeichen erkannt: ".$x."

"; //Komma eliminieren if(substr($x,1,1)=="."||strlen($x)==1) { $x="00".substr($x,0,1).substr($x,2); } if(substr($x,2,1)=="."||strlen($x)==2) { $x="0".substr($x,0,2).substr($x,3); } if(substr($x,3,1)=="."||(strlen($x)==3&&substr($x,2,1)!=".")) { $x=substr($x,0,3).substr($x,4); } //echo "Komma eliminiert: ".$x."

"; //Laenge auf 9 begrenzen $x=substr($x,0,9); //echo "Laenge begrenzt: ".$x."

"; //Verlaengern auf 9 if(strlen($x)<9) { $suffix="0"; for($i=1; $i<9-strlen($x); $i++) { $suffix=$suffix."0"; } $x=$x.$suffix; } //echo "Verlaengert auf 9: ".$x."

"; //jetzt haben wir eine neunstellige Zahl, die nur aus Ziffern besteht ggf. mit fuehrenden Nullen if($lat)//Latitude { if($sngx=="-") { $base=90000000; $x=$base+$x; } else//$sngx=="+" { $base=90000000; $x=$base-$x; } } else//Longitude { $base=180000000; if($sngx=="+") {$x=$base+$x;} else//$sngx=="-" {$x=$base-$x;} } /*//Verlaengern auf 9 if(strlen($x)<9) { $praefix="0"; for($i=1; $i<9-strlen($x); $i++) { $praefix=$praefix."0"; } $x=$praefix.$x; } //echo "Verlaengert auf 9: ".$x."

"; //jetzt haben wir eine neunstellige Zahl, die nur aus Ziffern besteht ggf. mit fuehrenden Nullen*/ return $x; }//END convertPosToInteger function ohneFuehrendeNullen($x) { while(strlen($x)>1&&substr($x,0,1)==0) {$x=substr($x,1);} return $x; } ?>