OMGM Code
Status: Beta
Brought to you by:
ifkkiruna
--- a +++ b/omgm/map.php @@ -0,0 +1,142 @@ +<?php +header("Content-Type: text/html;charset=iso-8859-1"); +include_once "define.php"; +include "lib/utils.php"; + +$zoom = $_POST["zoom"]; +$center = $_POST["center"]; + +if(!$zoom) $zoom = 4; +if(!$center) $center = '63.704, 20.654'; + +$cParts = split(",", $center); + +$centerLat = $cParts[0]; +$centerLng = trim($cParts[1]); +?> + +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + <title>Map Viewer</title> + <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1" /> + + <link href="resources/main.css" rel="stylesheet" type="text/css" /> + <script type="text/javascript" src="http://maps.google.com/maps?file=api&v=2&key=<?php echo GOOGLE_KEY;?>"></script> + <script type="text/javascript" charset="utf-8"> + <? + include "resources/map.js.php"; + ?> + </script> +<?php +echo "<script type=\"text/javascript\">\n"; +echo "var defZoomLevel = ".$zoom.";\n"; +echo "var defCenter = new GLatLng(".$centerLat.",".$centerLng.");\n"; +echo "var defBounds = null;\n"; +if($_GET["bbox"]){ + $bboxParts = split(",", $_GET["bbox"]); + echo "defBounds = new GLatLngBounds( new GLatLng(".$bboxParts[0].",".$bboxParts[1]."), new GLatLng(".$bboxParts[2].",".$bboxParts[3]."));\n"; +} + +$fileArr = $_FILES["gpxFile"]; +if(is_array($fileArr)){ + $parser = new GpxParser(); + $res = $parser->parse( $fileArr["tmp_name"] ); + + if(is_array($res["WPT"]) && count($res["WPT"])>0){ + foreach($res["WPT"] as $wpt){ + echo "addWpt(".$wpt["LAT"].",".$wpt["LNG"].");\n"; + } + } + + if(is_array($res["TRK"]) && count($res["TRK"])>0){ + foreach($res["TRK"] as $trk){ + $enc = createEncodedPolyline($trk); + echo "addTrk('".$enc["PointsLiteral"]."','".$enc["Levels"]."',".$enc["NumLevels"].",".$enc["ZoomFactor"].");\n"; + } + } +} +echo "</script>\n"; + +?> + +</head> +<body> +<div id="navigation"> +<? + include "menu.inc"; +?> +</div> + +<h1>Viewer for uploaded maps</h1> +<p> + Zoom: <span id="zoomLevel"></span> | Center: <span id="center"></span> +</p> +<div id="map_canvas"></div> + +<div id="uploadGpxArea"> + <h2>Show GPX</h2> + <p>You can view GPX data on the map by using this upload form.</p> + + <form action="map.php" method="post" enctype="multipart/form-data" id="gpxForm"> + <p> + <input type="hidden" name="zoom" value="" /> + <input type="hidden" name="center" value="" /> + GPX file: <input type="file" name="gpxFile" /> <input type="submit" value="Upload" > + </p> + </form> +</div> + +<?php +include "db.php"; + +$db = new Db(); +$maps = $db->getMaps(true); +?> +<h2>Uploaded maps</h2> + +<table class="horizontaldata"> +<tr> +<th>Name</th><th>Added</th><th></th> +</tr> +<?php +foreach($maps as $map){ + echo "<tr>"; + echo "<td><a href=\"map.php?bbox=".createBboxStr($map)."\">".$map["name"]."</a></td><td>".$map["addedDate"]."</td>"; + echo "</tr>"; +} +?> +</table> + +</body> +</html> + +<?php + +function createBboxStr($map){ + return $map["south"].",".$map["west"].",".$map["north"].",".$map["east"]; +} + +function createEncodedPolyline($track){ + $points = mergeTrackToPoints($track); + $enc = new PolylineEncoder($points); + return $enc->dpEncode(); +} + +function mergeTrackToPoints($trackSegments){ + $trackPoints = array(); + foreach($trackSegments as $segment){ + $segmentPoints = mergeSegmentToPoints($segment); + $trackPoints = array_merge($trackPoints, $segmentPoints); + } + return $trackPoints; +} + +function mergeSegmentToPoints($segment){ + $points = array(); + foreach($segment as $latLngs){ + $points[] = array($latLngs["LAT"], $latLngs["LNG"]); + } + return $points; +} +?>