Mercurial > hg > batmud > gmap2
changeset 57:f0f9366ae2f7 gmap2
Preliminary code for generating GMaps polylines from tradelane data, and
some tradelane endpoint definitions.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 09 Jan 2011 13:16:55 +0200 |
parents | 3dbbf2bc1032 |
children | 85c999c92736 |
files | tools/makegmaps.php tradelane.txt |
diffstat | 2 files changed, 76 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/tools/makegmaps.php Sun Jan 09 00:21:50 2011 +0200 +++ b/tools/makegmaps.php Sun Jan 09 13:16:55 2011 +0200 @@ -14,6 +14,7 @@ $tradelaneInCSV = $markerPath."tradelane.txt"; $tradelaneOutXML = $markerPath."tradelane.xml"; +$tradelaneOverXML = $markerPath."troverlay.xml"; // Utilities $convert = "convert"; @@ -241,22 +242,31 @@ */ echo "\nConverting tradelane data '".$tradelaneInCSV."' -> '".$tradelaneOutXML."'.\n"; +$markers = array(); +$file = fopen($tradelaneInCSV, "r"); +if ($file !== FALSE) { + while (($line = fgets($file, 4096)) !== FALSE) { + if ($line[0] == "#") continue; + $data = preg_split("/[\s]+/", $line); + $markers[$data[2]] = array( + "x" => $data[0] + 4096, + "y" => $data[1] + 4096, + "end" => $data[3] + ); + } +} + $doc = new DOMDocument("1.0", "UTF-8"); $node = $doc->createElement("markers"); $parnode = $doc->appendChild($node); - -$file = fopen($tradelaneInCSV, "r"); -while (($data = fgetcsv($file, 512, "\t")) !== FALSE) { - if ($data[0][0] == "#") continue; - list ($x, $y, $name) = $data; - - $html = "<b>TRADELANE WPT</b><br>".$name; +foreach ($markers as $name => $data) { + $html = "<b>TRADELANE WPT</b><br>".htmlentities($name); $node = $doc->createElement("marker"); $newnode = $parnode->appendChild($node); - $newnode->setAttribute("x", $x + 4096); - $newnode->setAttribute("y", $y + 4096); + $newnode->setAttribute("x", $data["x"]); + $newnode->setAttribute("y", $data["y"]); $newnode->setAttribute("name", $name); $newnode->setAttribute("html", $html); $newnode->setAttribute("continent", ""); @@ -265,7 +275,50 @@ $doc->save($tradelaneOutXML); +/* +$paths = array(); +foreach ($markers as $name => $data) { + $end = $data["end"]; + if (isset($end)) { + if (isset($markers[$end])) { + $tmp = $markers[$end]; + $paths[] = array($data["x"], $data["y"], $tmp["x"], $tmp["y"]); + } + } +} +print_r($paths); +*/ +function addNodeCoords($doc, $line, $data) +{ + $elem = $doc->createElement("point"); + $point = $line->appendChild($elem); + + $point->setAttribute("x", $data["x"]); + $point->setAttribute("y", $data["y"]); +} + +$doc = new DOMDocument("1.0", "UTF-8"); +$node = $doc->createElement("tradelanes"); +$parnode = $doc->appendChild($node); +foreach ($markers as $name => $data) { + + $end = $data["end"]; + if (isset($end)) { + if (isset($markers[$end])) { + $tmp = $markers[$end]; + + $node = $doc->createElement("line"); + $newnode = $parnode->appendChild($node); + + addNodeCoords($doc, $newnode, $data); + addNodeCoords($doc, $newnode, $markers[$end]); + } + } +} +$doc->save($tradelaneOverXML); + +exit; /* * Build tiles
--- a/tradelane.txt Sun Jan 09 00:21:50 2011 +0200 +++ b/tradelane.txt Sun Jan 09 13:16:55 2011 +0200 @@ -1,18 +1,19 @@ -5867 2873 rothikgen5 -5867 3069 rothikgen4 -5668 3268 rothikgen1 -5428 3028 rothikgen2 -5428 2930 rothikgen3 -4830 4106 laenor10 -4876 4106 laenor4 -4876 4740 laenor5 +# x y name [endpoint] +5867 2873 rothikgen5 rothikgen4 +5867 3069 rothikgen4 rothikgen1 +5668 3268 rothikgen1 laenor10 +5428 3028 rothikgen2 rothikgen1 +5428 2930 rothikgen3 rothikgen2 +4830 4106 laenor10 laenor4 +4876 4106 laenor4 laenor5 +4876 4740 laenor5 laenor6 4760 4856 laenor6 -4929 4856 laenor-furnachia -5404 5331 furnachia1 +4929 4856 laenor-furnachia furnachia1 +5404 5331 furnachia1 furnachia2 5494 5331 furnachia2 -4301 4856 laenor7 -4241 4796 laenor8 -4241 4611 laenor9 +4301 4856 laenor7 laenor-furnachia +4241 4796 laenor8 laenor7 +4241 4611 laenor9 laenor8 4396 4456 daerwon 4407 4456 arelium1 4460 4509 arelium2