/** Must of this has been now moved to JS, a cleaning up here is needed */ public static function generateDataForGoogleMaps($data, $addPolylines = false, $addMarkers = false, $showHopNums = false, $addInfoWin = false, $saveKml = false) { global $coordExclude, $webUrl, $savePath, $as_num_color; $trDataToJson = array(); $date = md5(date('d-m-o_G-i-s')); $gmFile = $date . ".js"; $myFile = $savePath . "/" . $gmFile; $fh = fopen($myFile, 'w') or die("can't open file"); // KML TR coords export if ($saveKml) { $kml = ''; $kmlFile = $date . ".kml"; $myKmlFile = $savePath . "/" . $kmlFile; $fhKml = fopen($myKmlFile, 'w') or die("can't open file KML"); } Traceroute::writeGmStart($myFile, $fh); $gMapJs = ''; $markers = ''; $infoWin = ''; $infoWinTmpl = '<div></div>'; $icon_01 = ""; $trIdsCounter = 0; $totHopsAll = 0; $totTrs = count($data); $kml = ''; $kmlA = ''; /* echo "<hr/>".$a. " == " . date('Y-m-d\TG:i:s\Z', $a); echo "<hr/>".$b. " == " . date('Y-m-d\TG:i:s\Z', $b); */ $tConn1 = 0; $tConn2 = 10; $b = strtotime("+12470 seconds"); //$b = strtotime("+37410 seconds"); //$a = strtotime("now"); //$b = $a + (12470*50); // loop TRids foreach ($data as $trId => $hops) { // set start time $a = strtotime("+" . $tConn1 . " seconds"); $a2 = strtotime("+" . $tConn2 . " seconds"); //$a+=50; //$b = strtotime("+".$tConn2." seconds"); //$tConn1++; $tConn1++; $tConn2++; $trIdsCounter++; $totHops = count($hops); $c = 0; $trCoordinates = ''; // save KML if ($saveKml) { // calculate time for animated population of TR /*$tBegin='2013-01-01T01:05:20Z'; $tEnd='2013-01-01T21:05:43Z';*/ $tBegin = date('Y-m-d\\TG:i:s\\Z', $a); $tEnd = date('Y-m-d\\TG:i:s\\Z', $b); $tEndA = date('Y-m-d\\TG:i:s\\Z', $a2); $kml .= ' <Placemark> <name>TR-' . $trId . ' - ' . $tConn1 . '</name> <styleUrl>#msn_ylw-pushpin</styleUrl> <TimeSpan> <begin>' . $tBegin . '</begin> <end>' . $tEnd . '</end> </TimeSpan> <LineString> <tessellate>1</tessellate> <coordinates>'; $kmlA .= ' <Placemark> <name>TR-' . $trId . ' - ' . $tConn1 . 'A</name> <styleUrl>#msn_ylw-pushpin</styleUrl> <TimeSpan> <begin>' . $tBegin . '</begin> <end>' . $tEndA . '</end> </TimeSpan> <LineString> <tessellate>1</tessellate> <coordinates>'; } // loop hops in a TRid for ($r = 0; $r < count($hops); $r++) { $totHopsAll++; $c++; /* echo '<hr/>'; print_r($hop); */ // new approach: use for loopinging in a way that previous hops' data can be accessed easily // minimal data for map generation $ip = $hops[$r][0]; $hopN = $hops[$r][1]; $lat = $hops[$r][2]; $long = $hops[$r][3]; $id = $hops[$r][4]; $asNum = $hops[$r][5]; $asName = $hops[$r][6]; $cEx = "{$lat},{$long}"; $mm_city = $hops[$r][10]; $mm_city = str_replace("'", " ", $mm_city); //$mm_city = ""; $gl_override = $hops[$r][14]; //$gl_override = 'hola'; // FIXME: need to exclude the /* if($gl_override==null || $gl_override=="" || $gl_override=="null"){ $gl_override="0"; } */ // data set to be exported to json $trDataToJson[$id][$hopN] = array('asNum' => $asNum, 'asName' => $asName, 'ip' => $ip, 'lat' => $lat, 'long' => $long, '8' => $hops[$r][8], '9' => $hops[$r][9], '20' => $hops[$r][20], 'hopN' => $hopN, 'mm_city' => $mm_city, 'mm_country' => $hops[$r][11], 'rtt_ms' => $hops[$r][13], 'gl_override' => $gl_override, 'dist_from_origin' => $hops[$r][15], 'imp_dist' => $hops[$r][16], 'time_light' => $hops[$r][17], 'latOrigin' => $hops[$r][18], 'longOrigin' => $hops[$r][19], 'flagged' => $hops[$r][21], 'hostname' => $hops[$r][22], 'country_code' => $hops[$r][23]); // kml export, exclude bad coordinates and exclude non CA US //if($saveKml && $lat!=0 && $long!=0 && (!in_array($cEx, $coordExclude)) && ($hops[$r][11]=='CA' || $hops[$r][11]=='US')) { if ($saveKml && $lat != 0 && $long != 0 && !in_array($cEx, $coordExclude)) { //if($saveKml){ $kml .= ' ' . $long . ',' . $lat . ''; } if ($ip) { // match ISP name for colouring // new approach each hop is represented as a unique polyline // 1. exclude first hop if ($r != 0) { //NOT working very well when excluding inaccurate coordinates of pevious hop // TODO: we need a record of the hops skipped so there are no holes in the path. $lat1 = $hops[$r - 1][2]; $long1 = $hops[$r - 1][3]; $lat2 = $hops[$r][2]; $long2 = $hops[$r][3]; $cEx1 = "{$lat1},{$long1}"; $cEx2 = "{$lat2},{$long2}"; if ($lat1 != 0 && $long1 != 0 && $lat2 != 0 && $long2 != 0 && ($lat1 != $lat2 && $long1 != $long2) && !in_array($cEx1, $coordExclude) && !in_array($cEx2, $coordExclude)) { /* $trDataToJson[$id][$hopN]=array( 'asNum'=>$asNum, 'asName'=>$asName, 'ip'=>$ip, 'lat'=>$lat, 'long'=>$long );*/ $hopCoordinates = ' new google.maps.LatLng(' . $lat1 . ', ' . $long1 . '), new google.maps.LatLng(' . $lat2 . ', ' . $long2 . ')'; // get colour $hopC = ""; if (!isset($as_num_color[$hops[$r - 1][5]])) { $hopC = '#676A6B'; } else { // fixed this notice if (isset($as_num_color[$asNum])) { $hopC = '#' . $as_num_color[$asNum]; } } if ($addPolylines) { // build Hop polyline obj $hopCoordinatesObj = "\n\t\t\t\t\t\t\t var hopRoute_" . $id . "_" . $hopN . " = [" . $hopCoordinates . "\n\t\t\t\t\t\t\t ];\n\n\t\t\t\t\t\t\t var hopRoutePath_" . $id . "_" . $hopN . " = new google.maps.Polyline({\n\t\t\t\t\t\t\t path: hopRoute_" . $id . "_" . $hopN . ",\n\t\t\t\t\t\t\t strokeColor: '" . $hopC . "',\n\t\t\t\t\t\t\t strokeOpacity: 0.6,\n\t\t\t\t\t\t\t strokeWeight: 6.0\n\t\t\t\t\t\t\t });\n\n\t\t\t\t\t\t\t\ttrCollection.push(hopRoutePath_" . $id . "_" . $hopN . ");\n\n\t\t\t\t\t\t\t hopRoutePath_" . $id . "_" . $hopN . ".setMap(map);\n\t\t\t\t\t\t\t "; // adding event listener to polyline object $hopCoordinatesObj .= "\n\t\t\t\t\t\t\t\tgoogle.maps.event.addListener(hopRoutePath_" . $id . "_" . $hopN . ", 'click', function() {\n\t\t\t\t\t\t\t\t trHopClick(" . $id . "," . $hopN . ");\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\tgoogle.maps.event.addListener(hopRoutePath_" . $id . "_" . $hopN . ", 'mouseover', function() {\n\t\t\t\t\t\t\t\t\ttrHopMouseover(" . $id . "," . $hopN . ");\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\tgoogle.maps.event.addListener(hopRoutePath_" . $id . "_" . $hopN . ", 'mouseout', function() {\n\t\t\t\t\t\t\t\t\ttrHopMouseout(" . $id . "," . $hopN . ");\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t "; // add hopCoordinatesObj fwrite($fh, $hopCoordinatesObj); } /////////// } // end if exclude wrong coordinates } // end exclude first hop if ($c == $totHops) { $trCoordinates .= ' new google.maps.LatLng(' . $lat . ', ' . $long . ',' . $id . ')'; } else { // '.$ip.' : '.$hopN.' $trCoordinates .= ' new google.maps.LatLng(' . $lat . ', ' . $long . ',' . $id . '),'; } if ($addMarkers) { // get icon colour if (!isset($as_num_color[$asNum])) { $iconColour = '676A6B'; } else { $iconColour = $as_num_color[$asNum]; } // add marker $markers .= "\n\t\t\t\t\t\tvar tr_" . $id . '_H' . $hopN . " = new google.maps.LatLng(" . $lat . "," . $long . ")\n\t\t\t\t\t\tvar marker" . $id . '_H' . $hopN . " = new google.maps.Marker({\n\t\t\t\t\t position: tr_" . $id . '_H' . $hopN . ",\n\t\t\t\t\t map: map,"; if (!$showHopNums) { $markers .= "\n\t\t\t\t\t\t icon: {\n\t\t\t\t\t\t path: google.maps.SymbolPath.CIRCLE,\n\t\t\t\t\t\t fillOpacity: 0.5,\n\t\t\t\t\t\t fillColor: '#" . $iconColour . "',\n\t\t\t\t\t\t strokeOpacity: 1.0,\n\t\t\t\t\t\t strokeColor: '#000000',\n\t\t\t\t\t\t strokeWeight: 1.0,\n\t\t\t\t\t\t scale: 7,\n\t\t\t\t\t\t \t},"; } $markers .= "\n\t\t\t\t\t title:'" . $ip . "'\n\t\t\t\t\t\t\t});"; if ($showHopNums) { // set icon $markers .= "marker" . $id . '_H' . $hopN . ".setIcon('" . $webUrl . "/images/" . "hop" . $hopN . ".png');"; } } // end if markers // add info window if ($addInfoWin) { $infoWin .= "\n\t\t\t\t\t\tvar infoC_" . $id . '_H' . $hopN . " = '<div class=\"info-win-text\">IP: <b>" . $ip . "</b> | (" . $lat . "," . $long . ")<br/>TRid: <b>" . $id . "</b> | hop: <b>" . $hopN . "</b><br/>AS: <b>" . $asNum . "</b> <br/>Carrier: <b>" . $asName . "</b><br/><a href=\"javascript: viewTrDetails(" . $id . ")\">Traceroute Detail</a></div>';\n\n\t\t\t\t\t\tvar infoW_" . $id . '_H' . $hopN . " = new google.maps.InfoWindow({\n\t\t\t\t\t\t content: infoC_" . $id . '_H' . $hopN . ",\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tgoogle.maps.event.addListener(marker" . $id . '_H' . $hopN . ", 'click', function() {\n\t\t\t\t\t\t infoW_" . $id . '_H' . $hopN . ".open(map,marker" . $id . '_H' . $hopN . ");\n\t\t\t\t\t\t});"; } // end if infowin } // end geoprecision exclude } // end loop 2 // if ($saveKml) { $kml .= ' </coordinates> </LineString> </Placemark> '; $kmlA .= ' </coordinates> <color>ff00ffff</color> </LineString> </Placemark> '; } /*old approach, not used for now we now build a polyline for each hop pair*/ // build polyline obj $trCoordinatesObj = "\n\t\t var traceRoute" . $trId . " = [" . $trCoordinates . "\n\t\t ];\n\n\t\t var traceRoutePath" . $trId . " = new google.maps.Polyline({\n\t\t path: traceRoute" . $trId . ",\n\t\t strokeColor: '" . Traceroute::getColor() . "',\n\t\t strokeOpacity: 1.0,\n\t\t strokeWeight: 3\n\t\t });\n\n\t\t traceRoutePath" . $trId . ".setMap(map);\n\n\t\t "; // add traceroute to js //$gMapJs .=''.$trCoordinatesObj; // write to file //fwrite($fh, $trCoordinatesObj); if ($addMarkers) { //fwrite($fh, $markers); } if ($addInfoWin) { //fwrite($fh, $infoWin); } // reset variables $trCoordinatesObj = ''; $markers = ''; $infoWin = ''; } // end loop 1 // add markers //$gMapJs.=''.$markers; // add info window and click event listeners //$gMapJs.=''.$infoWin; //echo '<textarea>'.$gMapJs.''.$infoWin.'</textarea>'; //$date = date('d '); $trDataToJsonS = json_encode($trDataToJson); //$trDataToJsonS = ""; unset($trDataToJson); Traceroute::writeGmEnd($myFile, $fh, $trDataToJsonS); unset($trDataToJsonS); //fclose($fh); //Traceroute::renderMap($gMapJs); $fileSize = filesize($myFile) / 1024; $fileSize = number_format($fileSize, 2); /*echo '<hr/>IXmaps data'; echo '<br/>TRs: '.$totTrs; echo '<br/>Hops: '.$totHopsAll; echo '<br/>Name: '.$gmFile; echo '<br/>Size: '.$fileSize.' KB';*/ // create results array $statsResult = array('totTrs' => $totTrs, 'totHops' => $totHopsAll, 'ixdata' => $gmFile, 'ixsize' => $fileSize); // save kml if ($saveKml) { $kmlAll = '<?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom"> <Document> <name>polyline-test.kml</name> <Style id="sn_ylw-pushpin"> <IconStyle> <scale>1.1</scale> <Icon> <href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href> </Icon> <hotSpot x="20" y="2" xunits="pixels" yunits="pixels"/> </IconStyle> <LineStyle> <color>ff0000ff</color> <width>3</width> </LineStyle> </Style> <StyleMap id="msn_ylw-pushpin"> <Pair> <key>normal</key> <styleUrl>#sn_ylw-pushpin</styleUrl> </Pair> <Pair> <key>highlight</key> <styleUrl>#sh_ylw-pushpin</styleUrl> </Pair> </StyleMap> <Style id="sh_ylw-pushpin"> <IconStyle> <scale>1.3</scale> <Icon> <href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href> </Icon> <hotSpot x="20" y="2" xunits="pixels" yunits="pixels"/> </IconStyle> <LineStyle> <color>ff0000ff</color> <width>3</width> </LineStyle> </Style> <Folder> <name>IXmaps Trs</name> <open>1</open> ' . $kml . ' </Folder> </Document> </kml>'; fwrite($fhKml, $kmlAll); fclose($fhKml); } return $statsResult; //echo '<script src="'.$webUrl.'/gm-temp/'.$gmFile.'"></script><div style="clear: both;">'; }
/** */ public static function generateGoogleMapsJs($data, $addPolylines = false, $addMarkers = false, $showHopNums = false, $addInfoWin = false) { global $coordExclude, $webUrl, $savePath, $webUrl, $as_num_color; $trDataToJson = array(); $date = md5(date('d-m-o_G-i-s')); $gmFile = $date . ".js"; $myFile = $savePath . "/" . $gmFile; $fh = fopen($myFile, 'w') or die("can't open file"); Traceroute::writeGmStart($myFile, $fh); $gMapJs = ''; $markers = ''; $infoWin = ''; $infoWinTmpl = '<div></div>'; $icon_01 = ""; $trIdsCounter = 0; // loop TRids foreach ($data as $trId => $hops) { $trIdsCounter++; $totHops = count($hops); $c = 0; $trCoordinates = ''; // loop hops in a TRid for ($r = 0; $r < count($hops); $r++) { $c++; /* echo '<hr/>'; print_r($hop); */ // new approach: use for loopinging in a way that previous hops' data can be accessed easily // minimal data for map generation $ip = $hops[$r][0]; $hopN = $hops[$r][1]; $lat = $hops[$r][2]; $long = $hops[$r][3]; $id = $hops[$r][4]; $asNum = $hops[$r][5]; $asName = $hops[$r][6]; $cEx = "{$lat},{$long}"; $mm_city = $hops[$r][10]; $mm_city = str_replace("'", " ", $mm_city); //$mm_city = ""; $gl_override = $hops[$r][14]; //$gl_override = 'hola'; // FIXME: need to exclude the /* if($gl_override==null || $gl_override=="" || $gl_override=="null"){ $gl_override="0"; } */ // full data to export to json $trDataToJson[$id][$hopN] = array('asNum' => $asNum, 'asName' => $asName, 'ip' => $ip, 'lat' => $lat, 'long' => $long, 'mm_city' => $mm_city, 'mm_country' => $hops[$r][11], 'rtt_ms' => $hops[$r][13], 'gl_override' => $gl_override, 'dist_from_origin' => $hops[$r][15], 'imp_dist' => $hops[$r][16], 'time_light' => $hops[$r][17], 'latOrigin' => $hops[$r][18], 'longOrigin' => $hops[$r][19]); /* $ip, 0 $hop, 1 $lat, 2 $long, 3 $trId, 4 $num, 5 $name, 6 $trArr[$i]['dest'], 7 $trArr[$i]['dest_ip'], 8 $trArr[$i]['submitter'], 9 $trArr[$i]['mm_city'], 10 $trArr[$i]['mm_country'], 11 $trArr[$i]['sub_time'], 12 $trArr[$i]['rtt_ms'], 13 $trArr[$i]['gl_override'] 14 $dist_from_origin, 15 $imp_dist, 16 $time_light_will_do, 17 */ // determne geo-precision /* if ip_dict[ip]['override']: #this is a little different than tr-detail, maybe FIX? lat_digits = len(str(d['lat'])) - str(d['lat']).find('.') - 1 long_digits = len(str(d['long'])) - str(d['long']).find('.') - 1 if lat_digits >= 5 or long_digits >= 5: ip_dict[ip]['geo_precision'] = 'building level' elif lat_digits <= 2 or long_digits <= 2: ip_dict[ip]['geo_precision'] = 'city level' else: ip_dict[ip]['geo_precision'] = 'Maxmind' */ // this is experimental: not really accurate //if($lat!=0 && $long!=0 && (!in_array($cEx, $coordExclude))) //if($lat!=0 && $long!=0) // collecting all if ($lat) { /* $trDataToJson[$id][$hopN]=array( 'asNum'=>$asNum, 'asName'=>$asName, 'ip'=>$ip, 'lat'=>$lat, 'long'=>$long, 'rtt_ms'=> );*/ } // ANTO's way: show all, even if it is inaccurate //if($lat!=0 && $long!=0) if ($ip) { // match ISP name for colouring // new approach each hop is represented as a unique polyline // 1. exclude first hop if ($r != 0) { //NOT working very well when excluding inaccurate coordinates of pevious hop // TODO: we need a record of the hops skipped so there are no holes in the path. $lat1 = $hops[$r - 1][2]; $long1 = $hops[$r - 1][3]; $lat2 = $hops[$r][2]; $long2 = $hops[$r][3]; $cEx1 = "{$lat1},{$long1}"; $cEx2 = "{$lat2},{$long2}"; // testing excluding methods, still a long way to go ;) //if($lat1!=0 && $long1!=0 && $lat2!=0 && $long2!=0 && (!in_array($cEx1, $coordExclude)) && (!in_array($cEx2, $coordExclude)) ) { // (NEW!) exclude the construction of a polyline object when the two poins are the same coordinates. This saves a lot of innecesary/invisible segments //if($lat1!=0 && $long1!=0 && $lat2!=0 && $long2!=0 && ($lat1!=$lat2 && $long1!=$long2) && (!in_array($cEx1, $coordExclude)) && (!in_array($cEx2, $coordExclude))) if ($lat1 != 0 && $long1 != 0 && $lat2 != 0 && $long2 != 0 && ($lat1 != $lat2 && $long1 != $long2) && !in_array($cEx1, $coordExclude) && !in_array($cEx2, $coordExclude)) { /* $trDataToJson[$id][$hopN]=array( 'asNum'=>$asNum, 'asName'=>$asName, 'ip'=>$ip, 'lat'=>$lat, 'long'=>$long );*/ $hopCoordinates = ' new google.maps.LatLng(' . $lat1 . ', ' . $long1 . '), new google.maps.LatLng(' . $lat2 . ', ' . $long2 . ')'; // get colour //) if (!isset($as_num_color[$hops[$r - 1][5]])) { $hopC = '#676A6B'; } else { $hopC = '#' . $as_num_color[$asNum]; } if ($addPolylines) { // build Hop polyline obj $hopCoordinatesObj = "\n\t\t\t\t\t\t\t var hopRoute_" . $id . "_" . $hopN . " = [" . $hopCoordinates . "\n\t\t\t\t\t\t\t ];\n\n\t\t\t\t\t\t\t var hopRoutePath_" . $id . "_" . $hopN . " = new google.maps.Polyline({\n\t\t\t\t\t\t\t path: hopRoute_" . $id . "_" . $hopN . ",\n\t\t\t\t\t\t\t strokeColor: '" . $hopC . "',\n\t\t\t\t\t\t\t strokeOpacity: 0.6,\n\t\t\t\t\t\t\t strokeWeight: 6.0\n\t\t\t\t\t\t\t });\n\n\t\t\t\t\t\t\t\ttrCollection.push(hopRoutePath_" . $id . "_" . $hopN . ");\n\n\t\t\t\t\t\t\t hopRoutePath_" . $id . "_" . $hopN . ".setMap(map);\n\t\t\t\t\t\t\t "; // adding event listener to polyline object $hopCoordinatesObj .= "\n\t\t\t\t\t\t\t\tgoogle.maps.event.addListener(hopRoutePath_" . $id . "_" . $hopN . ", 'click', function() {\n\t\t\t\t\t\t\t\t trHopClick(" . $id . "," . $hopN . ");\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\tgoogle.maps.event.addListener(hopRoutePath_" . $id . "_" . $hopN . ", 'mouseover', function() {\n\t\t\t\t\t\t\t\t\ttrHopMouseover(" . $id . "," . $hopN . ");\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\tgoogle.maps.event.addListener(hopRoutePath_" . $id . "_" . $hopN . ", 'mouseout', function() {\n\t\t\t\t\t\t\t\t\ttrHopMouseout(" . $id . "," . $hopN . ");\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t "; // add hopCoordinatesObj fwrite($fh, $hopCoordinatesObj); } /////////// } // end if exclude wrong coordinates } // end exclude first hop if ($c == $totHops) { $trCoordinates .= ' new google.maps.LatLng(' . $lat . ', ' . $long . ',' . $id . ')'; } else { // '.$ip.' : '.$hopN.' $trCoordinates .= ' new google.maps.LatLng(' . $lat . ', ' . $long . ',' . $id . '),'; } if ($addMarkers) { // get icon colour if (!isset($as_num_color[$asNum])) { $iconColour = '676A6B'; } else { $iconColour = $as_num_color[$asNum]; } // add marker $markers .= "\n\t\t\t\t\t\tvar tr_" . $id . '_H' . $hopN . " = new google.maps.LatLng(" . $lat . "," . $long . ")\n\t\t\t\t\t\tvar marker" . $id . '_H' . $hopN . " = new google.maps.Marker({\n\t\t\t\t\t position: tr_" . $id . '_H' . $hopN . ",\n\t\t\t\t\t map: map,"; if (!$showHopNums) { $markers .= "\n\t\t\t\t\t\t icon: {\n\t\t\t\t\t\t path: google.maps.SymbolPath.CIRCLE,\n\t\t\t\t\t\t fillOpacity: 0.5,\n\t\t\t\t\t\t fillColor: '#" . $iconColour . "',\n\t\t\t\t\t\t strokeOpacity: 1.0,\n\t\t\t\t\t\t strokeColor: '#000000',\n\t\t\t\t\t\t strokeWeight: 1.0,\n\t\t\t\t\t\t scale: 7,\n\t\t\t\t\t\t \t},"; } $markers .= "\n\t\t\t\t\t title:'" . $ip . "'\n\t\t\t\t\t\t\t});"; if ($showHopNums) { // set icon $markers .= "marker" . $id . '_H' . $hopN . ".setIcon('" . $webUrl . "/images/" . "hop" . $hopN . ".png');"; } } // end if markers // add info window if ($addInfoWin) { $infoWin .= "\n\t\t\t\t\t\tvar infoC_" . $id . '_H' . $hopN . " = '<div class=\"info-win-text\">IP: <b>" . $ip . "</b> | (" . $lat . "," . $long . ")<br/>TRid: <b>" . $id . "</b> | hop: <b>" . $hopN . "</b><br/>AS: <b>" . $asNum . "</b> <br/>Carrier: <b>" . $asName . "</b><br/><a href=\"javascript: viewTrDetails(" . $id . ")\">Traceroute Detail</a></div>';\n\n\t\t\t\t\t\tvar infoW_" . $id . '_H' . $hopN . " = new google.maps.InfoWindow({\n\t\t\t\t\t\t content: infoC_" . $id . '_H' . $hopN . ",\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tgoogle.maps.event.addListener(marker" . $id . '_H' . $hopN . ", 'click', function() {\n\t\t\t\t\t\t infoW_" . $id . '_H' . $hopN . ".open(map,marker" . $id . '_H' . $hopN . ");\n\t\t\t\t\t\t});"; } // end if infowin } // end geoprecision exclude } // end loop 2 /*old approach, not used for now we now build a polyline for each pair*/ // build polyline obj $trCoordinatesObj = "\n\t\t var traceRoute" . $trId . " = [" . $trCoordinates . "\n\t\t ];\n\n\t\t var traceRoutePath" . $trId . " = new google.maps.Polyline({\n\t\t path: traceRoute" . $trId . ",\n\t\t strokeColor: '" . Traceroute::getColor() . "',\n\t\t strokeOpacity: 1.0,\n\t\t strokeWeight: 3\n\t\t });\n\n\t\t traceRoutePath" . $trId . ".setMap(map);\n\n\t\t "; // add traceroute to js //$gMapJs .=''.$trCoordinatesObj; // write to file //fwrite($fh, $trCoordinatesObj); if ($addMarkers) { fwrite($fh, $markers); } if ($addInfoWin) { fwrite($fh, $infoWin); } // reset variables $trCoordinatesObj = ''; $markers = ''; $infoWin = ''; } // end loop 1 // add markers //$gMapJs.=''.$markers; // add info window and click event listeners //$gMapJs.=''.$infoWin; //echo '<textarea>'.$gMapJs.''.$infoWin.'</textarea>'; //$date = date('d '); $trDataToJsonS = json_encode($trDataToJson); //$trDataToJsonS = ""; unset($trDataToJson); Traceroute::writeGmEnd($myFile, $fh, $trDataToJsonS); unset($trDataToJsonS); //fclose($fh); //Traceroute::renderMap($gMapJs); echo '<script src="' . $webUrl . '/gm-temp/' . $gmFile . '"></script> <div style="clear: both;"> '; }
public static function generatePolylineObject($data, $addMarkers = true, $addInfoWin = true) { global $coordExclude, $webUrl, $savePath, $webUrl; $date = md5(date('d-m-o_G-i-s')); $gmFile = $date . ".js"; $myFile = $savePath . "/" . $gmFile; $fh = fopen($myFile, 'w') or die("can't open file"); Traceroute::writeGmStart($myFile, $fh); $gMapJs = ''; $markers = ''; $infoWin = ''; $infoWinTmpl = '<div></div>'; $icon_01 = ""; foreach ($data as $trId => $hops) { $totHops = count($hops); $c = 0; $trCoordinates = ''; foreach ($hops as $hop) { $c++; /* echo '<hr/>'; print_r($hop); */ $ip = $hop[0]; $hopN = $hop[1]; $lat = $hop[2]; $long = $hop[3]; $id = $hop[4]; $asNum = $hop[5]; $asName = $hop[6]; $cEx = "{$lat},{$long}"; // determne geo-precision /* if ip_dict[ip]['override']: #this is a little different than tr-detail, maybe FIX? lat_digits = len(str(d['lat'])) - str(d['lat']).find('.') - 1 long_digits = len(str(d['long'])) - str(d['long']).find('.') - 1 if lat_digits >= 5 or long_digits >= 5: ip_dict[ip]['geo_precision'] = 'building level' elif lat_digits <= 2 or long_digits <= 2: ip_dict[ip]['geo_precision'] = 'city level' else: ip_dict[ip]['geo_precision'] = 'Maxmind' */ if ($lat != 0 && $long != 0 && !in_array($cEx, $coordExclude)) { if ($c == $totHops) { $trCoordinates .= ' new google.maps.LatLng(' . $lat . ', ' . $long . ',' . $id . ')'; } else { // '.$ip.' : '.$hopN.' $trCoordinates .= ' new google.maps.LatLng(' . $lat . ', ' . $long . ',' . $id . '),'; } if ($addMarkers) { // add marker $markers .= "\n\t\t\t\t\t\tvar tr_" . $id . '_H' . $hopN . " = new google.maps.LatLng(" . $lat . "," . $long . ")\n\t\t\t\t\t\tvar marker" . $id . '_H' . $hopN . " = new google.maps.Marker({\n\t\t\t\t\t position: tr_" . $id . '_H' . $hopN . ",\n\t\t\t\t\t map: map,\n\t\t\t\t\t title:'" . $ip . "'\n\t\t\t\t\t\t\t});"; // set icon $markers .= "marker" . $id . '_H' . $hopN . ".setIcon('" . $webUrl . "/images/" . "hop" . $hopN . ".png');"; } // end if markers // add info window if ($addInfoWin) { $infoWin .= "\n\t\t\t\t\t\tvar infoC_" . $id . '_H' . $hopN . " = '<div class=\"info-win-text\">IP: <b>" . $ip . "</b> | (" . $lat . "," . $long . ")<br/>TRid: <b>" . $id . "</b> | hop: <b>" . $hopN . "</b><br/>AS: <b>" . $asNum . "</b> <br/>Carrier: <b>" . $asName . "</b><br/><a href=\"javascript: viewTrDetails(" . $id . ")\">Traceroute Detail</a></div>';\n\n\t\t\t\t\t\tvar infoW_" . $id . '_H' . $hopN . " = new google.maps.InfoWindow({\n\t\t\t\t\t\t content: infoC_" . $id . '_H' . $hopN . ",\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tgoogle.maps.event.addListener(marker" . $id . '_H' . $hopN . ", 'click', function() {\n\t\t\t\t\t\t infoW_" . $id . '_H' . $hopN . ".open(map,marker" . $id . '_H' . $hopN . ");\n\t\t\t\t\t\t});"; } // end if infowin } // end geoprecision exclude } // end loop 2 // build polyline obj $trCoordinatesObj = "\n\t\t var traceRoute" . $trId . " = [" . $trCoordinates . "\n\t\t ];\n\n\t\t var traceRoutePath" . $trId . " = new google.maps.Polyline({\n\t\t path: traceRoute" . $trId . ",\n\t\t strokeColor: '" . Traceroute::getColor() . "',\n\t\t strokeOpacity: 1.0,\n\t\t strokeWeight: 3\n\t\t });\n\n\t\t traceRoutePath" . $trId . ".setMap(map);\n\n\t\t "; // add traceroute to js //$gMapJs .=''.$trCoordinatesObj; // write to file fwrite($fh, $trCoordinatesObj); if ($addMarkers) { fwrite($fh, $markers); } if ($addInfoWin) { fwrite($fh, $infoWin); } // reset variables $trCoordinatesObj = ''; $markers = ''; $infoWin = ''; } // end loop 1 // add markers //$gMapJs.=''.$markers; // add info window and click event listeners //$gMapJs.=''.$infoWin; //echo '<textarea>'.$gMapJs.''.$infoWin.'</textarea>'; //$date = date('d '); Traceroute::writeGmEnd($myFile, $fh); //fclose($fh); //Traceroute::renderMap($gMapJs); echo '<script src="' . $webUrl . '/gm-temp/' . $gmFile . '"></script> <div id="map_canvas"></div>'; }