source: subversion/applications/rendering/gpx_slippy_map/list.php @ 30322

Last change on this file since 30322 was 7924, checked in by ojw, 11 years ago

Add error messages if we get redirected back from the map page
+ remove user-notification that we're downloading the RSS
+ RSS update every 0.5 hours

File size: 4.5 KB
Line 
1<?php header('Content-type:text/HTML; charset="UTF-8"'); ?>
2<html><head><title>Slippy-map for GPX tracklogs</title>
3</head>
4<body>
5
6<?php
7switch($_GET['error'])
8{
9  case "nofile": headerMessage("The GPX file you selected couldn't be downloaded from openstreetmap.org/traces");break;
10  case "nopoints": headerMessage("The GPX file you selected doesn't seem to contain any data (this may be a parser problem - report it if you think this is incorrect)");break;
11}
12function headerMessage($Message)
13{
14  print "<p style='background-color:#EFE;border:1px dashed green;padding:8px'>$Message</p>";
15}
16?>
17<h1>Slippy-map for GPX tracklogs</h1>
18
19<p>This page lets you view public GPX traces from
20<a href="http://openstreetmap.org/traces">http://openstreetmap.org/traces</a>
21on a slippy-map</p>
22
23<p>Just enter the ID number of the trace you want to view, and you will be
24taken to a map with your trace overlaid on the map</p>
25
26<p><i>You can't upload GPX files here</i> - to do that, login to
27<a href="http://openstreetmap.org/">openstreetmap.org</a> and go to
28'traces' &rarr; 'view your own traces' and use the upload form.</p>
29
30<p>Don't forget to mark your traces as <b>public</b> if you want to
31use this tool to view them.  We can't download private ones!</p>
32
33<h2>If you know the ID of your trace</h2>
34
35<p><form action="./" method="get">
36<input type="text" name="gpx" size="10" />
37<input type="submit" value="View tracklog" />
38</form></p>
39
40<h2>Recent tracklogs:</h2>
41
42<?php
43
44# Download the latest RSS of tracklogs from OSM
45$Filename = getRss();
46
47# Parse the RSS as XML
48$xml_parser = xml_parser_create();
49xml_set_element_handler($xml_parser, "startElement", "endElement");
50xml_set_character_data_handler($xml_parser, "xmlText");
51
52if (!($fp = fopen($Filename, "r"))) {
53    die("could not open XML input");
54}
55
56$fields = array();
57$inItem = 0;
58$field = '';
59while ($data = fread($fp, 4096)) {
60  if (!xml_parse($xml_parser, $data, feof($fp))) {
61      die(sprintf("<p>XML error: %s at line %d</p>",
62                  xml_error_string(xml_get_error_code($xml_parser)),
63                  xml_get_current_line_number($xml_parser)));
64  }
65}
66xml_parser_free($xml_parser);
67
68if($_GET["print_xml"])
69  print "<pre>".nl2br(htmlentities(file_get_contents($Filename)))."</pre>";
70
71function startElement($parser, $tag, $attributes) 
72{
73  global $fields, $field, $inItem;
74  if(strtolower($tag) == 'item')
75  {
76    $fields = array();
77    $inItem = 1;
78  }
79  elseif($inItem)
80  {
81    $field = strtolower($tag);
82  }
83}
84
85function xmlText($parser, $text) 
86{
87  global $fields, $field, $inItem;
88  if($inItem && $field != "")
89    $fields[$field] .= $text;
90}
91
92function endElement($parser, $tag) 
93{
94  global $fields, $field, $inItem;
95  if(strtolower($tag) == 'item')
96  {
97    $inItem = 0;
98   
99    if(preg_match("{traces/(\d+)}", $fields['link'], $Matches))
100    {
101      $GPX = $Matches[1]+0;
102     
103      if(array_key_exists('geo:lat', $fields))
104      {
105        $URL = sprintf("./?gpx=%d&lat=%f&lon=%f&zoom=12",
106          $GPX,
107          $fields['geo:lat'],
108          $fields['geo:long']);
109      }
110      else
111      {
112        $URL = sprintf("./?gpx=%d",$GPX);
113      }
114     
115      $User = sprintf("<a href='http://openstreetmap.org/user/%s'>%s</a>",
116        urlencode($fields['author']),
117        htmlentities($fields['author'], ENT_COMPAT, "UTF-8"));
118       
119    printf("<p><a href='%s'>%d</a>: %s by %s</p>\n",
120      $URL,
121      $GPX,
122      htmlentities($fields['title'], ENT_COMPAT, "UTF-8"),
123      $User
124      );
125
126    }
127  }
128  $field = "";
129}
130
131
132function getRss()
133{
134  $Filename = "cache/rss";
135  $URL = "http://openstreetmap.org/traces/rss";
136  $StaleTime = 0.5; // hours
137 
138  printf("<p>Updated every %1.0f hours</p>", $StaleTime);
139 
140  if(file_exists($Filename))
141    {
142   
143    $Age = (time() - filemtime($Filename)) / 3600.0;
144    #printf("<p>RSS age: %1.1f hr</p>", $Age);
145   
146    if($Age < 1.0)  # age at which to download new RSS
147      return($Filename);
148    }
149   
150  #print "<p>Downloading RSS!</p>";
151  file_put_contents($Filename, file_get_contents($URL));
152  return($Filename);
153}
154?>
155
156<h2>Copying</h2>
157<p>The map data you see underneath the tracklogs is all licensed as
158Creative Commons CC-BY-SA 2.0, from OpenStreetMap contributors</p>
159
160<p>Tracklogs themselves are also licensed as
161Creative Commons CC-BY-SA 2.0, from OpenStreetMap contributors</p>
162
163<p>This website is available for download on the <a href=http://svn.openstreetmap.org/applications/rendering/gpx_slippy_map/">SVN repositary</a>.</p>
164
165<h2>Help</h2>
166
167<p>See the wiki page for <a href="http://wiki.openstreetmap.org/index.php/GPX_slippy_map">GPX_slippy_map</a></p>
168
169<p>Use the talk page to report any problems</p>
170
171</body></html>
Note: See TracBrowser for help on using the repository browser.