<?php
// vim: sw=4:ts=4
/**
* @version 00.04.09
* @package polaring
* @license This component in released under the GNU/GPL License
*
* File: view/gmaps.php
* Role: Contains functions that relates to Google Maps
*
**/
class gmaps {
function htmlHead() {
echo " <script src=\"http://maps.google.com/maps?file=api&v=2&key=".$_SESSION['gmapsApi']."\" type=\"text/javascript\">\n".
" </script>\n\n";
return;
} // end htmlHead
function mapDiv($width, $height) {
echo "<div id=\"map\" class=\"center\" style=\"width: ".
$width."px; height: ".$height."px\"></div>\n";
return(true);
} // end mapDiv
function mapRoute($latPre, $longPre) {
$lat = array_filter($latPre);
$long = array_filter($longPre);
$maxLat = max($lat);
$maxLong = max($long);
$minLat = min($lat);
$minLong = min($long);
$centerLat = (($maxLat - $minLat) / 2 ) + $minLat;
$centerLong = (($maxLong - $minLong) / 2) + $minLong;
$centerOverlay = $centerLat.", ".$centerLong;
?>
<script type="text/javascript">
//<![CDATA[
function loadPolaringGmap() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
var points = [];
var bounds = new GLatLngBounds();
<?php
$totNum = count($lat);
// If we're not looking at a big map,
// e.g. if google map isn't selected,
// then only have a few map points (25).
if ( !isset($_GET['selGraph']) ||
$_GET['selGraph'] != "dayGmapRoute" ) {
$mapPoints = 25;
} else {
// Otherwise, use setting in configuration
// (default: 100)
$mapPoints = $_SESSION['mapPoints'];
}
if ( $mapPoints != 0 &&
$totNum > $mapPoints ) {
$divBy = round($totNum / $mapPoints);
} else {
$divBy = 1;
}
for ( $i = 0; $i < $totNum; $i++ ) {
if (
( $i % $divBy == 0 ||
$i == 0 ||
$i == ($totNum -1 ) ) &&
$lat[$i] &&
$long[$i]
) {
echo " var point = new GLatLng(".$lat[$i].
", ".$long[$i].");\n";
echo " points.push(point);\n";
echo " bounds.extend(point);\n";
}
}
?>
var polyline = new GPolyline(points);
map.setCenter(new GLatLng(<? echo $centerOverlay;?>), 13);
map.setZoom(map.getBoundsZoomLevel(bounds));
map.addOverlay(polyline);
}
}
//]]>
</script>
<?php
return;
} // end mapRoute
} // gmaps
?>