Mercurial > hg > batmud > gmap2
changeset 114:cf4401e20357 gmap2
"Temporarily" add overlay back.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 08 Mar 2014 20:43:35 +0200 |
parents | ef9c0a193334 |
children | 571f552e3176 |
files | overlay.php |
diffstat | 1 files changed, 92 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/overlay.php Sat Mar 08 20:43:35 2014 +0200 @@ -0,0 +1,92 @@ +<?php +$cachepath = "cache/"; +$fontfile = "tools/lucon.ttf"; +$tilesize = 256; + +$vzoom = isset($_GET["zoom"]) ? intval($_GET["zoom"]) - 1 : 1; +$zoom = pow(2, $vzoom - 5); +$xc = intval($_GET["x"]); +$yc = intval($_GET["y"]); + + + +$cachefile = $cachepath."bl_".$zoom."_".$xc."_".$yc.".png"; +$mtime = @filemtime($cachefile); +if ($mtime !== FALSE && time() - $mtime < 7*24*60*60) +{ +} + + +$im = @imagecreate($tilesize, $tilesize); + +$transparent = imagecolorallocate($im,0,0,255); +$alpha = imagecolorallocatealpha($im,0,0,0,64); +$black = imagecolorallocate($im,0,0,0); +imagecolortransparent($im,$transparent); +$white = imagecolorallocate($im,255,255,255); + +imagefilledrectangle($im, 0,0, $tilesize,$tilesize, $transparent); + +$fontsize = array(); +$fontsize[ 8] = 7; +$fontsize[16] = 13; +$fontsize[32] = 26; + +$labelsize = array(); +$labelsize[ 4] = 7; +$labelsize[ 8] = 8; +$labelsize[16] = 9; +$labelsize[32] = 12; + + +function chkcoords($xoffs, $yoffs) +{ + global $xorig, $yorig, $tilesize; + + return + $xoffs > $xorig - $tilesize && $xoffs < $xorig + ($tilesize*2) && + $yoffs > $yorig - $tilesize && $yoffs < $yorig + ($tilesize*2); +} + +$xorig = $xc * $tilesize; +$yorig = $yc * $tilesize; + + +$file = fopen("overlay.txt", "r"); +while ($data = fgetcsv($file, 160, ",")) +{ + $xoffs = $data[0] * $zoom; + $yoffs = $data[1] * $zoom; + $char = $data[2]; + + if (chkcoords($xoffs, $yoffs)) + { + if ($zoom>=8) imagefilledrectangle($im,$xoffs-$xorig,$yoffs-$yorig,$xoffs-$xorig+$zoom-1,$yoffs-$yorig+$zoom-1,$black); + if ($zoom>=8) imagettftext($im,$fontsize[$zoom],0,$xoffs-$xorig+$fontsize[$zoom]/4,$yoffs-$yorig+$fontsize[$zoom],$white,$fontfile,$char); + // imagechar($im,$fontsize[$zoom],$xoffs-$xorig,$yoffs-$yorig,$char,$white); + } +} +fclose($file); + + +$file = fopen("overlaylabels.txt", "r"); +while ($data = fgetcsv($file, 160, ",")) +{ + $xoffs = $data[0] * $zoom; + $yoffs = $data[1] * $zoom; + $char = $data[2]; + + if (chkcoords($xoffs, $yoffs) && $zoom >= 4) + { + $box = imagettfbbox($labelsize[$zoom], 0, $fontfile, $char); + imagefilledrectangle($im,$xoffs-$xorig+$box[6],$yoffs-$yorig+$box[7]+5,$xoffs-$xorig+$box[2],$yoffs-$yorig+$box[3]+5,$alpha); + imagettftext($im,$labelsize[$zoom],0,$xoffs-$xorig,$yoffs-$yorig+5,$white,"./lucon.ttf",$char); + //imagestring($im,1,$xoffs-$xorig,$yoffs-$yorig,$char,$white); + } +} +fclose($file); + + +header("Content-type: image/png"); +imagepng($im); +?>