changeset 120:3b725e8ac51a gmap2

Make the overlay kludge work again.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 08 Mar 2014 21:30:32 +0200
parents 2f2937e8921f
children b7bdd9a4c807
files overlay.php
diffstat 1 files changed, 30 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/overlay.php	Sat Mar 08 21:30:21 2014 +0200
+++ b/overlay.php	Sat Mar 08 21:30:32 2014 +0200
@@ -1,6 +1,6 @@
 <?php
 $cachepath = "cache/";
-$fontfile = "tools/lucon.ttf";
+$fontfile = "./tools/lucon.ttf";
 $tilesize = 256;
 
 $vzoom = isset($_GET["zoom"]) ? intval($_GET["zoom"]) - 1 : 1;
@@ -9,23 +9,26 @@
 $yc = intval($_GET["y"]);
 
 
-
 $cachefile = $cachepath."bl_".$zoom."_".$xc."_".$yc.".png";
 $mtime = @filemtime($cachefile);
-if ($mtime !== FALSE && time() - $mtime < 7*24*60*60)
+if ($mtime !== FALSE || time() - $mtime < 7*24*60*60)
 {
+  header("Content-type: image/png");
+  readfile($cachefile);
+  exit;
 }
 
 
 $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);
+$c_trans = imagecolorallocate($im, 0,32,0);
+imagecolortransparent($im, $c_trans);
 
-imagefilledrectangle($im, 0,0, $tilesize,$tilesize, $transparent);
+$c_alpha = imagecolorallocatealpha($im, 0,0,0,64);
+$c_black = imagecolorallocate($im, 0,0,0);
+$c_white = imagecolorallocate($im, 255,255,255);
+
+imagefilledrectangle($im, 0,0, $tilesize,$tilesize, $c_trans);
 
 $fontsize = array();
 $fontsize[ 8] = 7;
@@ -51,6 +54,7 @@
 $xorig = $xc * $tilesize;
 $yorig = $yc * $tilesize;
 
+$flag = FALSE;
 
 $file = fopen("overlay.txt", "r");
 while ($data = fgetcsv($file, 160, ","))
@@ -61,9 +65,13 @@
   
   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);      
+    if ($zoom >= 8)
+    {
+      imagefilledrectangle($im,$xoffs-$xorig,$yoffs-$yorig,$xoffs-$xorig+$zoom-1,$yoffs-$yorig+$zoom-1,$c_black);
+      imagettftext($im,$fontsize[$zoom],0,$xoffs-$xorig+$fontsize[$zoom]/4,$yoffs-$yorig+$fontsize[$zoom], $c_white, $fontfile, $char);
+      imagechar($im,$fontsize[$zoom],$xoffs-$xorig,$yoffs-$yorig,$char,$c_white);
+      $flag = TRUE;
+    }
   }
 }
 fclose($file);
@@ -79,14 +87,21 @@
   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);      
+    imagefilledrectangle($im,$xoffs-$xorig+$box[6],$yoffs-$yorig+$box[7]+5,$xoffs-$xorig+$box[2],$yoffs-$yorig+$box[3]+5,$c_alpha);      
+    imagettftext($im,$labelsize[$zoom],0,$xoffs-$xorig,$yoffs-$yorig+5, $c_white, $fontfile, $char);
+    //imagestring($im,1,$xoffs-$xorig,$yoffs-$yorig,$char,$c_white);      
+    $flag = TRUE;
   }
 }
 fclose($file);
 
+if ($flag)
+{
+  @imagepng($im, $cachefile);
+  @chmod($cachefile, 0644);
+}
 
 header("Content-type: image/png");
 imagepng($im);
+imagedestroy($im);
 ?>