|
From: <ma...@sc...> - 2006-04-13 18:02:53
|
Update of /cvsroot/meshdb/www/db2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26853 Modified Files: google.php Log Message: add display of links between nodes, turned off by default, add links=1 to the url arguments to enable it. the algoritm for trimming old nodes has been disabled for now, it wasn't very good when calculating links to nodes that had previously been excluded from display due to age. i expect this needs to be fixed before we make all-nodes functionality public Index: google.php =================================================================== RCS file: /cvsroot/meshdb/www/db2/google.php,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- google.php 13 Apr 2006 12:49:23 -0000 1.2 +++ google.php 13 Apr 2006 18:02:40 -0000 1.3 @@ -4,7 +4,7 @@ /* declare content type */ header("Content-Type: application/keyhole"); - //header("Content-Type: text/plain"); + //header("Content-Type: text/plain"); /* TEST ONLY */ function nice_die($error) { echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; @@ -21,11 +21,10 @@ $nodeid = $HTTP_GET_VARS['nodeid']; } - /* restrict age of nodes */ - if (isset($HTTP_GET_VARS['maxdays'])) { - $maxdays = $HTTP_GET_VARS['maxdays']; - } else { - $maxdays = 365 * 2; /* default approx 2 years */ + /* show links to peers */ + $links = 0; + if (isset($HTTP_GET_VARS['links'])) { + $links = $HTTP_GET_VARS['links']; } /* used to mark an error */ @@ -49,7 +48,7 @@ mysql_free_result($result); /* single or multiple query */ - $query = "SELECT a.nodeid,a.nodename,a.status,a.updated,p.e,p.n,p.h,c.contactname FROM admin a, physloc p, contact c where a.nodeid = p.nodeid and a.nodeid=c.nodeid and p.e is not NULL and p.n is not null and (DATE_SUB(CURDATE(),INTERVAL $maxdays DAY) <= a.updated)"; + $query = "SELECT a.nodeid,a.nodename,a.status,a.updated,p.e,p.n,p.h,c.contactname FROM admin a, physloc p, contact c where a.nodeid = p.nodeid and a.nodeid=c.nodeid and p.e is not NULL and p.n is not null"; if (isset($nodeid)) { $query = $query . " and a.nodeid=$nodeid"; } else { @@ -64,88 +63,55 @@ echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; echo "<kml xmlns=\"http://earth.google.com/kml/2.0\">\n"; echo "<Document>\n"; - echo "<Folder><name>brismesh.org</name>\n"; - - while (($row = mysql_fetch_assoc($result))) { - - /* updated may be null */ - $updated = "N/A"; - if (isset($row['updated'])) { - $updated = $row['updated']; - } - /* height may be null */ - $alt = 0; - if (isset($row['h'])) { - $alt = $row['h']; - } - - /* convert to lat / lon */ - $lat_lon = cvtlatlon($row['e'], $row['n']); - $lat = $lat_lon[0]; - $lon = $lat_lon[1]; - - /* skip invalid values */ - if ($lat == 0 || $lon == 0) { - echo "<!-- zero lat=$lat OR lon=$lon, skipping -->/n"; - continue; - } - - /* display the row */ - echo " <Placemark>\n"; - echo " <description><![CDATA[Contact's Name: " . htmlspecialchars($row['contactname']) . "<br>View <a href=\"http://www.itee.uq.edu.au/~mesh/db-srtm/view.php?nodeid=".$row['nodeid']."\">Node Details</a> on BrisMESH<br>Last Updated: ".$updated."]]></description>\n"; - echo " <name><![CDATA[" . htmlspecialchars($row['nodename']) . "]]></name>\n"; - echo " <LookAt>\n"; - echo " <longitude>$lon</longitude>\n"; - echo " <latitude>$lat</latitude>\n"; - echo " <range>" . ($alt + 500) . "</range>\n"; - echo " <tilt>0</tilt>\n"; - echo " <heading>3</heading>\n"; - echo " </LookAt>\n"; - + /* predefine styles to save space */ + /* start icon styles */ + $validStyles = array ("nan","interest","build","gather","waiting","test","full","default"); + for ($i=0; $i<8; $i++) { + /* default pallette */ $pallette = "root://icons/palette-3.png"; $sizex = 32; $sizey = 32; - /* choose a icon for the user */ - if ($row['status'] == 'nan') { + /* create icon attribues */ + if ($validStyles[$i] == 'nan') { // landmark icon $offsetx=96; $offsety=64; - } else if ($row['status'] == 'interest') { + } else if ($validStyles[$i] == 'interest') { // small icon $pallette = "root://icons/palette-4.png"; $offsetx=32; $offsety=128; - } else if ($row['status'] == 'build' || $row['status'] == 'gather') { + } else if ($validStyles[$i] == 'build' || $validStyles[$i] == 'gather') { // bit bigger $pallette = "root://icons/palette-4.png"; $offsetx=64; $offsety=128; - } else if ($row['status'] == 'waiting') { + } else if ($validStyles[$i] == 'waiting') { // bit bigger $pallette = "root://icons/palette-4.png"; $offsetx=64; $offsety=128; - } else if ($row['status'] == 'test') { + } else if ($validStyles[$i] == 'test') { // looks like an inactive tower $offsetx=0; $offsety=64; - } else if ($row['status'] == 'full') { + } else if ($validStyles[$i] == 'full') { // looks like an active tower $offsetx=0; $offsety=96; - } else { - // low key icon + } else if ($validStyles[$i] == 'default') { + // default icon $pallette = "root://icons/palette-4.png"; $offsetx=0; $offsety=128; - } - - /* the icon to display */ - echo " <Style>\n"; - echo " <IconStyle>\n"; + } + + /* generate the next icon style */ + echo " <Style id=\"$validStyles[$i]\">\n"; + echo " <IconStyle id=\"iconStyle_$validStyles[$i]\">\n"; echo " <Icon>\n"; echo " <href>$pallette</href>\n"; echo " <x>$offsetx</x>\n"; @@ -154,18 +120,145 @@ echo " <h>$sizey</h>\n"; echo " </Icon>\n"; echo " </IconStyle>\n"; + //echo " <LabelStyle id=\"labelStyle_$validStyles[$i]\">\n"; + //echo " <color>7fffaaff</color>\n"; + //echo " <scale>1.5</scale>\n"; + //echo " </LabelStyle>\n"; + echo " <LineStyle id=\"lineStyle_$validStyles[$i]\">\n"; + echo " <color>ff0000ff</color>\n"; + echo " <width>3</width>\n"; + echo " </LineStyle>\n"; echo " </Style>\n"; - + + } + + /* style for intra node links */ + echo " <Style id=\"linkStyle\">\n"; + echo " <LineStyle id=\"lineStyle_linkStyle\">\n"; + echo " <color>7fff0000</color>\n"; + echo " <width>3</width>\n"; + echo " </LineStyle>\n"; + echo " <IconStyle id=\"iconStyle_$validStyles[$i]\">\n"; + echo " <Icon>\n"; + echo " <href>root://icons/palette-5.png</href>\n"; + echo " <x>96</x>\n"; + echo " <y>64</y>\n"; + echo " <w>32</w>\n"; + echo " <h>32</h>\n"; + echo " </Icon>\n"; + echo " </IconStyle>\n"; + echo " </Style>\n"; + + /* default enclosing folder */ + echo "<Folder><name>brismesh.org</name>\n"; + + while (($row = mysql_fetch_assoc($result))) { + + /* updated may be null */ + $updated = "N/A"; + if (isset($row['updated'])) { + $updated = $row['updated']; + } + + /* height may be null */ + $alt = 0; + if (isset($row['h'])) { + $alt = $row['h']; + } + + /* convert to lat / lon */ + $lat_lon = cvtlatlon($row['e'], $row['n']); + $lat = $lat_lon[0]; + $lon = $lat_lon[1]; + + /* skip invalid values */ + if ($lat == 0 || $lon == 0) { + echo "<!-- zero lat=$lat OR lon=$lon, skipping -->/n"; + continue; + } + + /* find the style to use */ + $style = "#default"; + $i = array_search($row['status'], $validStyles); + if (isset($i)) { + $style="#$validStyles[$i]"; + } + + /* display the row */ + echo " <Placemark>\n"; + echo " <description><![CDATA[Contact's Name: " . htmlspecialchars($row['contactname']) . "<br>View <a href=\"http://www.itee.uq.edu.au/~mesh/db-srtm/view.php?nodeid=".$row['nodeid']."\">Node Details</a> on BrisMESH<br>Last Updated: ".$updated."]]></description>\n"; + echo " <name><![CDATA[" . htmlspecialchars($row['nodename']) . "]]></name>\n"; + echo " <styleUrl>$style</styleUrl>\n"; + echo " <LookAt>\n"; + echo " <longitude>$lon</longitude>\n"; + echo " <latitude>$lat</latitude>\n"; + echo " <range>" . 500 . "</range>\n"; + echo " <tilt>0</tilt>\n"; + echo " <heading>3</heading>\n"; + echo " </LookAt>\n"; + /* point on the map */ - echo " <Point>\n"; - echo " <extrude>1</extrude>\n"; - echo " <altitudeMode>relativeToGround</altitudeMode>\n"; - echo " <coordinates>$lon,$lat,$alt</coordinates>\n"; - echo " </Point>\n"; + echo " <Point>\n"; + echo " <extrude>1</extrude>\n"; + echo " <altitudeMode>relativeToGround</altitudeMode>\n"; + echo " <coordinates>$lon,$lat,$alt</coordinates>\n"; + echo " </Point>\n"; + + /* finish placemark */ echo " </Placemark>\n"; + /* add links as placemarks */ + if ($links == 1) { + + /* find this node's links, if none or error, do nothing */ + $query2 = "SELECT n.nodeid, n.peerid, p1.e as e1, p1.n as n1, p1.h as h1, p2.e as e2, p2.n as n2, p2.h as h2 from netloc n, physloc p1, physloc p2 where n.nodeid is not null and n.peerid is not null and n.nodeid=p1.nodeid and n.peerid=p2.nodeid and n.nodeid=" . $row['nodeid']; + + if ($result2 = mysql_query($query2, $db)) { + + /* now do "placemarks" for node links */ + while (($row2 = mysql_fetch_assoc($result2))) { + + /* convert to lat / lon for p1 */ + $lat_lon1 = cvtlatlon($row2['e1'], $row2['n1']); + $lat1 = $lat_lon1[0]; + $lon1 = $lat_lon1[1]; + $alt1 = 0; + if (isset($row2['h1'])) { + $alt1 = $row2['h1']; + } + + /* convert to lat / lon for p2 */ + $lat_lon2 = cvtlatlon($row2['e2'], $row2['n2']); + $lat2 = $lat_lon2[0]; + $lon2 = $lat_lon2[1]; + $alt2 = 0; + if (isset($row2['h2'])) { + $alt2 = $row2['h2']; + } + + /* emit the link placemark */ + echo " <Placemark>\n"; + echo " <name>link_".$row2['nodeid']."_to_".$row2['peerid']."</name>\n"; + echo " <styleUrl>#linkStyle</styleUrl>\n"; + echo " <LineString>\n"; + echo " <altitudeMode>relativeToGround</altitudeMode>\n"; + echo " <coordinates>\n"; + echo " $lon1, $lat1, $alt1\n"; + echo " $lon2, $lat2, $alt2\n"; + echo " </coordinates>\n"; + echo " </LineString>\n"; + echo " </Placemark>\n"; + + } + + /* give back memory */ + mysql_free_result($result2); + } + } + /* count the rows */ $rows++; + } /* give back memory */ |