source: subversion/applications/rendering/gpx_slippy_map/index.php @ 34539

Last change on this file since 34539 was 7925, checked in by ojw, 11 years ago

If the lat/long is not supplied, load-up the GPX file and figure it out
rfom the first trackpoint.

This also has the effect of ensuring the GPX is available and
preprocessed before all 25 image threads get confused about who's
supposed to be downloading first

File size: 4.0 KB
Line 
1<?php
2if(!array_key_exists('gpx', $_GET))
3{
4  # No GPX requested - so redirect to an index where one can be selected
5  header("Location:list.php");
6  exit;
7}
8
9# By default, use lat/long/zoom from query parameters
10$z = floor($_GET['zoom'] + 0);
11$lat = $_GET['lat'] + 0;
12$lon = $_GET['lon'] + 0;
13
14# However, if they don't exist:
15if(!array_key_exists('lat', $_GET))
16{
17  # Lat/long unknown, so look it up from the GPX file rather than
18  # just starting with a view of the whole world!
19 
20  include("gpx.php");
21  $LeaveFilepointerOpen = 1;
22  $Data = getMeta(getGpx($_GET["gpx"] + 0), $LeaveFilepointerOpen);
23 
24  if(!$Data['exists'] || !$Data['valid'])
25    {
26    header("Location:list.php?error=nofile");
27    exit;
28    }
29  if($Data['points'] < 1)
30    {
31    header("Location:list.php?error=nopoints");
32    exit;
33    }
34  $fp = $Data['fp'];
35 
36  # Read the first point
37  list($spare, $rx, $ry) = unpack("N2", fread($fp, 8));
38  $Resolution = 1 / pow(2.0, 31);
39  $rx *= $Resolution;
40  $ry *= $Resolution;
41 
42  # Convert to lat/long
43  $lat = mercatorToLat(M_PI * (1.0 - 2.0 * $ry));
44  $lon = -180.0 + 360.0 * $rx;
45  $z = 14;
46 
47  fclose($fp);
48}
49?>
50<html>
51<head>
52    <script src="http://openlayers.org/api/OpenLayers.js"></script>
53    <script src="http://openstreetmap.org/openlayers/OpenStreetMap.js"></script>
54
55    <script type="text/javascript">
56        <?php
57
58        print " var lat = $lat;\n var lon = $lon;\n var zoom = $z;\n";
59       
60        $Base = '';
61        $Title = "OpenStreetMap tracklog viewer";
62        $Tiles = 'tile.php?';
63        $gpx = 0;
64        if(array_key_exists('gpx', $_GET))
65        {
66          $gpx = floor($_GET['gpx'] + 0);
67          $Base = sprintf("?gpx=%d", $gpx);
68          $Tiles .= sprintf("gpx=%d&t=", $gpx);
69          $Title = sprintf("Tracklog #%d", $gpx);
70        }
71          #$Tiles .= sprintf("t=", $gpx);
72       
73        print "var routeServer = '$Tiles'\n";
74        print "var extraUrlParams = '$Base';\n";
75        ?>
76       
77        if (zoom==0)
78        {
79         zoom = 2;
80         lon = 1.0996;
81         lat = 35.5862;
82        }
83
84        lat=parseFloat(lat)
85        lon=parseFloat(lon)
86        zoom=parseInt(zoom)
87               
88        var map; //complex object of type OpenLayers.Map
89
90        //Initialise the 'map' object
91        function init() {
92         
93            map = new OpenLayers.Map ("map", {
94                controls:[
95                    new OpenLayers.Control.Navigation(),
96                    new OpenLayers.Control.Permalink('',extraUrlParams,''),
97                     new OpenLayers.Control.LayerSwitcher(),
98                    new OpenLayers.Control.PanZoomBar()],
99                maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
100                maxResolution: 156543.0399,
101                numZoomLevels: 19,
102                units: 'meters',
103                projection: new OpenLayers.Projection("EPSG:900913"),
104                displayProjection: new OpenLayers.Projection("EPSG:4326")
105            } );
106               
107           
108            // Base map
109            layerTilesAtHome = new OpenLayers.Layer.OSM.Osmarender("Osmarender");
110
111            // GPX overlay
112            route = new OpenLayers.Layer.OSM(
113              "Route",
114              routeServer,
115              {
116                isBaseLayer: false,
117                type:'png',
118              },
119              {'buffer':1});
120
121
122            map.addLayer(layerTilesAtHome);
123            map.addLayer(route);
124
125            var lonLat = new OpenLayers.LonLat(lon, lat).transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913"));
126
127            map.setCenter (lonLat, zoom);
128        }
129       
130    </script>
131   
132<?php
133print "<title>$Title</title>\n";
134?>
135</head><body onload="init();">
136
137<div style="width:100%; height:100%" id="map">
138<!-- <div style="position:absolute; bottom:10px;width:700px;"><form action='./' method='get'>
139<input type='text' size='10' name='gpx' value='<?php print $gpx ?>' />
140<input type='submit' value='View GPX' />
141<a href="http://openstreetmap.org/traces/">List of GPX traces</a>
142</form></div> -->
143
144</div>
145
146</body>
147</html>
Note: See TracBrowser for help on using the repository browser.