From 3d4bdf9088184500442c451b237fcc2e954a7b21 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sun, 7 Dec 2008 00:26:18 +0000 Subject: drawing links now --- data.php | 15 ++++++----- index.php | 22 +++++++++++++++- map.js | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 118 insertions(+), 8 deletions(-) diff --git a/data.php b/data.php index 8f26a68..284e65e 100644 --- a/data.php +++ b/data.php @@ -85,19 +85,22 @@ foreach ($lines as $num => $line) if($already[$locations[$locids[$ipfromLoc]]->locid . '-' . $locations[$locids[$iptoLoc]]->locid]->used == true) { $jot = $already[$locations[$locids[$ipfromLoc]]->locid . '-' . $locations[$locids[$iptoLoc]]->locid]->i; - $links[$jot]->label = ($links[$jot]->label + $label)/2; + if($links[$jot]->label != -1) + $links[$jot]->label = ($links[$jot]->label + $label)/2; } elseif($already[$locations[$locids[$iptoLoc]]->locid . '-' . $locations[$locids[$ipfromLoc]]->locid]->used == true) { $jot = $already[$locations[$locids[$iptoLoc]]->locid . '-' . $locations[$locids[$ipfromLoc]]->locid]->i; - $links[$jot]->label = ($links[$jot]->label + $label)/2; + if($links[$jot]->label != -1) + $links[$jot]->label = ($links[$jot]->label + $label)/2; } else { - $already[$locations[$locids[$ipfromLoc]]->locid . '-' . $locations[$locids[$iptoLoc]]->locid]->used =true; + $already[$locations[$locids[$ipfromLoc]]->locid . '-' . $locations[$locids[$iptoLoc]]->locid]->used = true; $already[$locations[$locids[$ipfromLoc]]->locid . '-' . $locations[$locids[$iptoLoc]]->locid]->i = $i; $links[$i]->ipfromLoc = $ipfromLoc; $links[$i]->iptoLoc = $iptoLoc; - $links[$i]->label = $label; + if($links[$i]->label != -1) + $links[$i]->label = $label; if($locations[$locids[$ipfromLoc]]->state == "offline") $locations[$locids[$ipfromLoc]]->state = "online"; if($locations[$locids[$iptoLoc]]->state == "offline") @@ -106,7 +109,7 @@ foreach ($lines as $num => $line) if (($nodename[$ipfromLoc] == "tunnel" && $locations[$locids[$ipfromLoc]]->locname=="housing") || ($nodename[$iptoLoc] == "tunnel" && $locations[$locids[$iptoLoc]]->locname=="housing" ) || ($locations[$locids[$iptoLoc]]->hastinc && $locations[$locids[$ipfromLoc]]->hastinc)) { - $link->label = -1; + $links[$i]->label = -1; $locations[$locids[$ipfromLoc]]->state = "tunnel"; $locations[$locids[$iptoLoc]]->state = "tunnel"; } @@ -136,7 +139,7 @@ foreach ($links as $link) $count[$data1->locid]=true; $count[$data2->locid]=true; - printf("\t" . '' . "\n", + printf("\t" . '' . "\n", $data1->locid, $data1->locname, $data1->lat,$data1->lng,$data2->locid, $data2->locname, $data2->lat, $data2->lng, $link->label); } echo "\n"; diff --git a/index.php b/index.php index f255816..46fee77 100644 --- a/index.php +++ b/index.php @@ -53,7 +53,27 @@ if(empty($marker)) $marker="online"; - + + + + + + + + + + + + + + + + + + + + +
>  Offline Offline
  Online
 Schlecht
 Mittel
 Gut
 Tunnel
diff --git a/map.js b/map.js index 2864643..6a4d1ab 100644 --- a/map.js +++ b/map.js @@ -1,13 +1,15 @@ var map = null; var physicalMaxLevel; var geocoder = null; +var reloadcon = null; var countboxText = null; var overlays = new Array(); overlays["newmarker"] = null; overlays["ruler"] = new Array(); overlays["locations"] = new Array(); +overlays["links"] = new Array(); var locations = new Array(); -var reloadcon = null; +var links = new Array(); function initialize(lat, lng, res) { if (!checkBrowser()) { @@ -69,6 +71,7 @@ function checkBrowser() { function onAddOverlay(overlay) { switch(overlay.overlaytype) { case "location": overlays["locations"].push(overlay); break; + case "link": overlays["links"].push(overlay); break; case "newmarker": { if(overlays["newmarker"]) { map.removeOverlay(overlays["newmarker"]); @@ -114,6 +117,13 @@ function onData(data, responseCode) { locations = []; drawLocations(xmlData); + for(var link in overlays["links"]) { + map.removeOverlay(overlays["links"][link]); + } + overlays["links"] = []; + links = []; + drawLinks(xmlData); + var element = xmlData.getElementsByTagName("count"); var count = element[0].getAttribute("number"); countboxText.data = "Aktiv: " + count; @@ -136,6 +146,9 @@ function drawLocations(xmlData) { if(document.visibleform.elements["offline"].checked) { toggleVisible("offline"); } + if(document.visibleform.elements["online"].checked) { + toggleVisible("online"); + } } function Location(element) { @@ -177,6 +190,75 @@ function convertCoords(x) { return deg + "° " + Math.floor(min) + "' " + sec.toFixed(0) + "\""; } +function drawLinks(xmlData) { + var element = xmlData.getElementsByTagName("link"); + for (var i = 0; i< element.length; i++) { + var id = element[i].getAttribute("from") + "-" + element[i].getAttribute("to"); + links[id] = new Link(element[i]); + + var line = new GPolyline([links[id].frompoint, links[id].topoint], makeColor(Math.floor(links[id].value)), makeWeight(Math.floor(links[id].value))); + line.overlaytype = "link"; + line.linkid = id; + map.addOverlay(line); + } + if(document.visibleform.elements["bad"].checked) { + toggleVisible("bad"); + } + if(document.visibleform.elements["middle"].checked) { + toggleVisible("middle"); + } + if(document.visibleform.elements["good"].checked) { + toggleVisible("good"); + } + if(document.visibleform.elements["tunnel"].checked) { + toggleVisible("tunnel"); + } +} + +function Link(element) { + var link = new Object(); + link.from = element.getAttribute("from"); + link.fromid = parseInt(element.getAttribute("fromid")); + var lat = parseFloat(element.getAttribute("latfrom")); + var lng = parseFloat(element.getAttribute("lngfrom")); + link.frompoint = new GLatLng(lat, lng); + + link.to = element.getAttribute("to"); + link.toid = parseInt(element.getAttribute("toid")); + lat = parseFloat(element.getAttribute("latto")); + lng = parseFloat(element.getAttribute("lngto")); + link.topoint = new GLatLng(lat, lng); + + link.value = parseFloat(element.getAttribute("value")); + + return link; +} + +function makeColor(value) { + switch(value) { + case -1: return '#0000FF'; + case 0: return '#FF0000'; + case 1: return '#33bb33'; + case 2: return '#66bb33'; + case 3: return '#ff9900'; + case 4: return '#ffcc00'; + case 5: return '#cccc33'; + default: return '#000000' + } +} + +function makeWeight(value) { + switch(value) { + case -1: return 1; + case 0: return 3; + case 1: return 3; + case 3: return 1; + case 4: return 1; + case 5: return 1; + default: return 1; + } +} + function addNewNodeText(point) { var html = "adding location at:
\n" + point; return html; @@ -202,6 +284,11 @@ function toggleVisible(element) { var elements = Object(); switch(element) { case 'offline': elements.overlays = overlays["locations"]; elements.select = new Function("id", "return (locations[overlays['locations'][id].locid].state == 'offline');"); break; + case 'online': elements.overlays = overlays["locations"]; elements.select = new Function("id", "return (locations[overlays['locations'][id].locid].state != 'offline');"); break; + case 'bad': elements.overlays = overlays["links"]; elements.select = new Function("id", "return (links[overlays['links'][id].linkid].value >= 6);"); break; + case 'middle': elements.overlays = overlays["links"]; elements.select = new Function("id", "return (links[overlays['links'][id].linkid].value >= 3 && links[overlays['links'][id].linkid].value < 6);"); break; + case 'good': elements.overlays = overlays["links"]; elements.select = new Function("id", "return (links[overlays['links'][id].linkid].value >= 0 && links[overlays['links'][id].linkid].value < 3);"); break; + case 'tunnel': elements.overlays = overlays["links"]; elements.select = new Function("id", "return (links[overlays['links'][id].linkid].value == -1);"); break; } if(document.visibleform.elements[element].checked) { -- cgit v1.2.1