-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathl.html
100 lines (82 loc) · 2.83 KB
/
l.html
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
<!DOCTYPE html>
<html>
<head>
<title>CycleStreets</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.css" />
<!--[if lte IE 8]>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.ie.css" />
<![endif]-->
<script src="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script>
<!-- GPX plugin -->
<script src="https://rawgithub.com/mpetazzoni/leaflet-gpx/master/gpx.js"></script>
<style>
body {
padding: 0;
margin: 0;
}
html, body, #map {
height: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<!-- Based on Leaflet JS mobile and GPX plugin examples -->
<!-- Should track device location if found and can display a journey track using j parameter. -->
<!-- Example: http://m.cyclestreets.net/l.html?j=37480393 -->
<script>
var map = L.map('map', {attributionControl: false});
// Top right is more out of way on mobile
L.control.attribution({position: 'topright'}).addTo(map);
var myLocation = false;
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: 'Map data © <a href="http://www.osm.org">OpenStreetMap</a>'
}).addTo(map);
function onLocationFound(e) {
var radius = e.accuracy / 2;
if (!myLocation) {
myLocation = L.circle(e.latlng, radius,{color:'red'}).addTo(map);
} else {
myLocation.setLatLng(e.latlng, radius);
}
}
function onLocationError(e) {
alert(e.message + ' Make sure geolocation is working then reload this page to try again.');
}
map.on('locationfound', onLocationFound);
map.on('locationerror', onLocationError);
// Turn on geolocation
map.locate({setView: true, maxZoom: 16, watch: true, enableHighAccuracy: true, maximumAge: 1500, timeout: 5000,});
// Helper to get the value of a query string parameter
function getQueryVariable (variable) {
var query = window.location.search.substring(1);
var vars = query.split('&');
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('=');
if (decodeURIComponent(pair[0]) == variable) {
return decodeURIComponent(pair[1]);
}
}
return false;
}
// Parse the query string
var journey = getQueryVariable('j');
// Show a journey if specified
if (journey) {
// Requires cross origin access to be granted by this server
var gpx = 'http://www.cyclestreets.net/journey/' + journey + '/cyclestreets' + journey + 'balanced.gpx';
new L.GPX(gpx, {async: true,
marker_options: {
startIconUrl: 'images/cs_start.png',
endIconUrl: 'images/cs_finish.png',
shadowUrl: ''
}
}).on('loaded', function(e) {
map.fitBounds(e.target.getBounds());
}).addTo(map);
}
</script>
</body>
</html>