[go: up one dir, main page]

Menu

[r4]: / omgm / map.php  Maximize  Restore  History

Download this file

143 lines (119 with data), 3.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
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&amp;v=2&amp;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;
}
?>