changeset 160:7a1b8099b5f7 gmap2

Use JSON instead of XML.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 10 Mar 2014 01:36:44 +0200
parents c8040d314354
children 074b6936ec4f
files tools/makegmaps.php
diffstat 1 files changed, 32 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/tools/makegmaps.php	Mon Mar 10 01:01:00 2014 +0200
+++ b/tools/makegmaps.php	Mon Mar 10 01:36:44 2014 +0200
@@ -23,16 +23,13 @@
  */
 $locPath = $mapUtils."maps/";
 $continentJS = $markerPath."continents.js";
-$tradelaneOut = $markerPath."tradelane.xml";
-$tradelaneOverlay = $markerPath."troverlay.xml";
+$tradelaneOut = $markerPath."tradelane.json";
+$tradelaneOverlay = $markerPath."troverlay.json";
 $mkloc = $mapUtils."mkloc";
 
 $modes = array(
   "xml"     => array("batclient.xml"     , 0, 0),
-
-  "overlay" => array("overlay.txt"       , 0, 0),
-  "xml"     => array("markers.xml"       , 0, 0),
-  "labels"  => array("overlaylabels.txt" , 1, -1),
+  "json"    => array("markers.json"       , 0, 0),
 );
 
 $mapPalette = array();
@@ -362,6 +359,13 @@
 }
 
 
+function outputJSON($qfilename, $qdata)
+{
+  if (file_put_contents($qfilename, json_encode($qdata), LOCK_EX) === FALSE)
+    die("Could not write to file '".$qfilename."'.\n");
+}
+
+
 /* Export tradelane waypoint data
  */
 if (!isset($tradelanePoints))
@@ -369,9 +373,7 @@
 
 echo "\nCreating tradelane waypoint data '".$tradelaneOut."' ...\n";
 
-$doc = new DOMDocument("1.0", "UTF-8");
-$node = $doc->createElement("markers");
-$parnode = $doc->appendChild($node);
+$qdata = array();
 
 foreach ($tradelanePoints as $name => $data)
 {
@@ -380,16 +382,17 @@
   if (!getWorldCoords($data[0], $data[1], $data[2], $xc, $yc))
     die("Invalid tradelane waypoint '".$name."', continent '".$data[0]."' not defined.\n");
 
-  $node = $doc->createElement("marker");
-  $newnode = $parnode->appendChild($node);
-  $newnode->setAttribute("x", $xc);
-  $newnode->setAttribute("y", $yc);
-  $newnode->setAttribute("name", $name);
-  $newnode->setAttribute("html", $html);
-  $newnode->setAttribute("continent", "");
-  $newnode->setAttribute("type", "tradelane");
+  $qdata[] = array(
+    "x" => $xc,
+    "y" => $yc,
+    "name" => $name,
+    "html" => $html,
+    "continent" => "",
+    "type" => "tradelane"
+  );
 }
-$doc->save($tradelaneOut);
+
+outputJSON($tradelaneOut, $qdata);
 
 
 /* Export tradelane polyline data
@@ -398,28 +401,27 @@
 if (!isset($tradelaneDefs))
   die("PHP array \$tradelaneDefs not set, '$config' is old or incompatible.\n");
 
-$doc = new DOMDocument("1.0", "UTF-8");
-$node = $doc->createElement("tradelanes");
-$parnode = $doc->appendChild($node);
-
+$qdata = array();
 foreach ($tradelaneDefs as $index => $points)
 {
-  $node = $doc->createElement("line");
-  $line = $parnode->appendChild($node);
+  $qline = array();
+
   foreach ($points as $point)
   {
     if (!getWaypointCoords($point, $xc, $yc))
       die("Invalid tradelane definition #$index: waypoint '".$point."' not defined.\n");
 
-    $elem = $doc->createElement("point");
-    $point = $line->appendChild($elem);
-        
-    $point->setAttribute("x", $xc);
-    $point->setAttribute("y", $yc);
+    $qline[] = array(
+      "x" => $xc,
+      "y" => $yc
+    );
   }
+  
+  $qdata[] = $qline;
 }
-$doc->save($tradelaneOverlay);
+
 
+outputJSON($tradelaneOverlay, $qdata);
 
 /*
  * Build tiles