changeset 64:6a267fe394b0 gmap2

Cosmetics.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 21 Feb 2011 17:17:18 +0200
parents e4733b7da18c
children b30043f6c2e3 6fd8670a9243
files tools/makegmaps.php
diffstat 1 files changed, 63 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/tools/makegmaps.php	Mon Feb 21 02:53:13 2011 +0200
+++ b/tools/makegmaps.php	Mon Feb 21 17:17:18 2011 +0200
@@ -89,7 +89,8 @@
  */
 echo "Converting location data from LOC files to GMaps markers...\n";
 $args = "";
-foreach ($continentList as $name => $t) {
+foreach ($continentList as $name => $t)
+{
   if ($t[4]) { // has a map
     $args .=
     "-l ".escapeshellarg($locPath.$name.".loc")." ".
@@ -99,7 +100,8 @@
   }
 }
 
-foreach ($modes as $mode => $file) {
+foreach ($modes as $mode => $file)
+{
   $tmp = escapeshellcmd($mkloc)." -v -o ".escapeshellarg($markerPath.$file)." -G ".$mode." ".$args;
   passthru($tmp) == 0 or die("Error executing: ".$tmp."\n");
 }
@@ -114,7 +116,8 @@
 
   // Try to open input file
   $file = @fopen($inFilename, "r");
-  if ($file === FALSE) {
+  if ($file === FALSE)
+  {
     echo "Could not open input '".$inFilename."'\n";
     return FALSE;
   }
@@ -126,7 +129,8 @@
 
   // Create image and assign colors
   $im = @imagecreate($width*$zoom, $height*$zoom);
-  if ($im === FALSE) {
+  if ($im === FALSE)
+  {
     echo "Could not allocate image data for '".$inFilename."'\n";
     return FALSE;
   }
@@ -148,10 +152,12 @@
   {
     for ($x = 0; $x < $width; $x++)
     {
-      if ($zoom == 1) {
+      if ($zoom == 1)
+      {
         imagesetpixel($im, $x, $y, $colors[$data[$x]]);
       } else 
-      if ($zoom < 6) {
+      if ($zoom < 6)
+      {
         imagefilledrectangle($im, $x*$zoom, $y*$zoom, ($x+1)*$zoom-1, ($y+1)*$zoom-1, $colors[$data[$x]]);
       } else {
         imagettftext($im,
@@ -167,7 +173,8 @@
     echo ".";
   }
 
-  if (imagepng($im, $outFilename) === FALSE) {
+  if (imagepng($im, $outFilename) === FALSE)
+  {
     echo "Error creating '".$outFilename."'\n";
     imagedestroy($im);
     return FALSE;
@@ -186,12 +193,14 @@
 if ($data[4])
 {
   $inFilename = $rawPath.$name.".txt";
-  if (!file_exists($inFilename)) {
+  if (!file_exists($inFilename))
+  {
     die("Required file '".$inFilename."' does not exist.\n");
   }
   $inMtime = filemtime($inFilename);
   
-  for ($zoom = 1; $zoom <= 5; $zoom++) {
+  for ($zoom = 1; $zoom <= 5; $zoom++)
+  {
     $outFilename = $cachePath.$name."_".($zoom + 4).".png";
     $outMtime = file_exists($outFilename) ? filemtime($outFilename) : -1;
     echo "- ".$name." (".$data[0]."): ";
@@ -215,12 +224,14 @@
 {
   $n = count($mapScales);
   $inFilename = $cachePath.$name."_".$n.".png";
-  if (!file_exists($inFilename)) {
+  if (!file_exists($inFilename))
+  {
     die("Required file '".$inFilename."' does not exist.\n");
   }
   $inMtime = filemtime($inFilename);
 
-  foreach ($mapScales as $scale) {
+  foreach ($mapScales as $scale)
+  {
     $n--;
     $outFilename = $cachePath.$name."_".$n.".png";
     $outMtime = file_exists($outFilename) ? filemtime($outFilename) : -1;
@@ -244,8 +255,10 @@
 
 $markers = array();
 $file = fopen($tradelaneInCSV, "r");
-if ($file !== FALSE) {
-  while (($line = fgets($file, 4096)) !== FALSE) {
+if ($file !== FALSE)
+{
+  while (($line = fgets($file, 4096)) !== FALSE)
+  {
     if ($line[0] == "#") continue;
     $data = preg_split("/[\s]+/", $line);
     $markers[$data[2]] = array(
@@ -260,7 +273,8 @@
 $node = $doc->createElement("markers");
 $parnode = $doc->appendChild($node);
 
-foreach ($markers as $name => $data) {
+foreach ($markers as $name => $data)
+{
   $html = "<b>TRADELANE WPT</b><br>".htmlentities($name);
 
   $node = $doc->createElement("marker");
@@ -301,11 +315,13 @@
 $doc = new DOMDocument("1.0", "UTF-8");
 $node = $doc->createElement("tradelanes");
 $parnode = $doc->appendChild($node);
-foreach ($markers as $name => $data) {
-
+foreach ($markers as $name => $data)
+{
   $end = $data["end"];
-  if (isset($end)) {
-    if (isset($markers[$end])) {
+  if (isset($end))
+  {
+    if (isset($markers[$end]))
+    {
       $tmp = $markers[$end];
 
       $node = $doc->createElement("line");
@@ -318,16 +334,17 @@
 }
 $doc->save($tradelaneOverXML);
 
-//exit;
 
 /*
  * Build tiles
  */
-function createTile($scale, $zoom, $x, $y, $mapData, $mapMtime) {
+function createTile($scale, $zoom, $x, $y, $mapData, $mapMtime)
+{
   global $continentList, $worldMap, $cachePath, $tilePath, $tileDim;
 
   $outFilename = $tilePath.$zoom."/".$y."/".$x.".png";
-  if (file_exists($outFilename) && filemtime($outFilename) >= $mapMtime) {
+  if (file_exists($outFilename) && filemtime($outFilename) >= $mapMtime)
+  {
     echo "!";
     return;
   }
@@ -335,8 +352,8 @@
   $drawn = 0;
   $im = false;
 
-  foreach ($continentList as $continent => $data) {
-
+  foreach ($continentList as $continent => $data)
+  {
     $cx = $data[1] + $worldMap["ox"];
     $cy = $data[2] + $worldMap["oy"];
     $cw = $data[5];
@@ -349,7 +366,8 @@
         ($cy + $ch)*$scale > $y*$tileDim &&
         ($cx * $scale)     < ($x+1)*$tileDim && 
         ($cy * $scale)     < ($y+1)*$tileDim) {
-      if ($drawn==0) {
+
+      if ($drawn == 0) {
         if ($zoom < 9) {
           $im = @imagecreate($tileDim, $tileDim);
           $sea = imagecolorallocate($im, 51, 51, 170);
@@ -367,34 +385,40 @@
       $xx = 0;
       $yy = 0;
 
-      if ($tx < 0) {
+      if ($tx < 0)
+      {
         $xx -= $tx;
         $dx += $tx+1;
         $tx  = 0;
       }
 
-      if ($ty < 0) {
+      if ($ty < 0)
+      {
         $yy -= $ty;
         $dy += $ty+1;
         $ty  = 0;
       }
 
-      if ($dx > $cw*$scale-$tx) {
+      if ($dx > $cw*$scale-$tx)
+      {
         $dx = $cw*$scale - $tx;
       }
 
-      if ($dy > $ch*$scale-$ty) {
+      if ($dy > $ch*$scale-$ty)
+      {
         $dy = $ch*$scale - $ty;
       }
 
-      if ($im !== false) {
+      if ($im !== false)
+      {
         imagecopy($im, $mapData[$continent], $xx, $yy, $tx, $ty, $dx, $dy);
         $drawn++;
       }
     }
   }
 
-  if ($drawn) {
+  if ($drawn > 0)
+  {
     makeDir($tilePath.$zoom."/".$y, 0755);
     imagepng($im, $outFilename);
     imagedestroy($im);
@@ -428,7 +452,8 @@
 
   $mapMtime = -1;
   foreach ($continentList as $continent => $data)
-  if ($data[4]) {
+  if ($data[4])
+  {
     $mapFile = $cachePath.$continent."_".$zoom2.".png";
     $mapData[$continent] = @imagecreatefrompng($mapFile);
     $tmp = filemtime($mapFile);
@@ -436,15 +461,20 @@
       $mapMtime = $tmp;
   }
 
-  for ($y = 0; $y < $mx; $y++) {
+  for ($y = 0; $y < $mx; $y++)
+  {
     for ($x = 0; $x < $my; $x++)
+    {
       createTile($scale, $zoom, $x, $y, $mapData, $mapMtime);
+    }
     echo ".";
   }
   echo "\n";
 
+  // Free image data for each continent
   foreach($continentList as $continent => $data)
-  if ($data[4]) {
+  if ($data[4])
+  {
     imagedestroy($mapData[$continent]);
   }
 }