<?php
// ab13karte.php - Welches ist die n&ouml;rdlichste, s&uuml;dlichste, &ouml;stlichste und westlichste Haltestelle?

include 'header.php';

   
// ############ START QUERY ############################################################
$query = "
SELECT latitude, longitude, name FROM stations WHERE latitude = (SELECT MIN(latitude) FROM stations)
UNION
SELECT latitude, longitude, name FROM stations WHERE latitude = (SELECT MAX(latitude) FROM stations)
UNION
SELECT latitude, longitude, name FROM stations WHERE longitude = (SELECT MIN(longitude) FROM stations)
UNION
SELECT latitude, longitude, name FROM stations WHERE longitude = (SELECT MAX(longitude) FROM stations);
";


$result = mysqli_query($db, $query);
if ($result) {
   $rows = mysqli_num_rows($result);
   $cols = mysqli_num_fields($result);
   for($r=0; $r< $rows; $r++) {
		list($xobj[$r], $yobj[$r], $nobj[$r]) = mysqli_fetch_row($result);
   }
}
else {
   echo "Fehler";
}

$lat = 31.195501;
$long = 121.47377;
$zoom = "10";
	
mysqli_free_result($result);

echo '<script type="text/javascript">';
echo '
   function load() {
      function createListener (marker, text) {
         GEvent.addListener(marker, "click", function() {
            marker.openInfoWindowHtml(text);
         }
         );
      }
      if (GBrowserIsCompatible()) {
         var map = new GMap2(document.getElementById("map"));
		 map.setMapType(G_SATELLITE_MAP);
         map.addControl(new GLargeMapControl());
         map.addControl(new GMapTypeControl());
         map.addControl(new GScaleControl());
         map.addControl(new GOverviewMapControl());
         var icon = new GIcon();
         icon.image = "images/markerstation.png";
         icon.shadow = "images/markerstation_schatten.png";
         icon.iconSize = new GSize(20, 20);
         icon.shadowSize = new GSize(20, 20);
         icon.iconAnchor = new GPoint(10, 10);
         icon.infoWindowAnchor = new GPoint(10, 10);
';
echo '
         map.setCenter(new GLatLng('.$lat.', '.$long.'), '.$zoom.');
         var point = new Array();
         var text = new Array();
         var marker = new Array();
';
for ($r=0; $r<$rows; $r++) {
   echo '
         point['.$r.'] = new GLatLng('.$xobj[$r].','.$yobj[$r].');
         text['.$r.'] = "'.$nobj[$r].'";
   ';
}

echo '
         var marker = new Array();
         for (i=0; i< point.length; i++) {
            marker[i] = new GMarker(point[i], icon);
            map.addOverlay(marker[i]);
            createListener (marker[i], text[i]);
         }
';

echo '
      }
   }
   </script>
'; 



echo '</head>';
// ############ START BODY ############################################################
echo '<body onLoad="load()" onUnload="GUnload()">';

include 'menu.php';


// ############ START CONTENT ############################################################
echo '
   <div id="content">
   <a href="abfragen.htm" class="menulink">zur&uuml;ck zu den Abfragen</a>
';   

echo '<h1>Welches ist die n&ouml;rdlichste, s&uuml;dlichste, &ouml;stlichste und westlichste Haltestelle?</h1>';

echo  'Die <b>s&uuml;dlichste</b> Haltestelle ist: <b>'.$nobj[0].'</b><br>';
echo  'Die <b>n&ouml;rdlichste</b> Haltestelle ist: <b>'.$nobj[1].'</b><br>';
echo  'Die <b>&ouml;stlichste</b> Haltestelle ist: <b>'.$nobj[2].'</b><br>';
echo  'Die <b>westlichste</b> Haltestelle ist: <b>'.$nobj[3].'</b><br><br>';
   
echo	'<div id="map" align="center" style="width: 800px; height: 400px"></div>';


include 'footer.php';
?>