-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmap.html
More file actions
166 lines (152 loc) · 7.38 KB
/
map.html
File metadata and controls
166 lines (152 loc) · 7.38 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<html>
<head>
<link rel="stylesheet" href="js/leaflet/leaflet.css" />
<link rel="stylesheet" href="css/l.geosearch.css" />
<link rel="stylesheet" href="css/misc.css" />
<link rel="stylesheet" href="css/jquery.mobile-1.4.5.min.css">
<style>
body {
padding: 0;
margin: 0;
}
html, body {
height: 100%;
width: 100%;
}
</style>
<title>NRV Park Search</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
</head>
<body>
<div data-role="page" id="page3">
<div data-role="content" id="map" class="mapfix">
<div id='mapid'></div>
</div>
</div>
<script src="https://npmcdn.com/[email protected]/dist/leaflet.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="js/jquery.mobile-1.4.5.min.js"></script>
<script src="js/misc.js"></script>
<script type="text/javascript">
var map;
function createMap(){
map = L.map('mapid', {closePopupOnClick: false}).setView([getUrlVars()["lat"], getUrlVars()["lon"] ], 13);
L.tileLayer('https://api.mapbox.com/styles/v1/nealf/cj4a7oll139od2spe6ckgufjq/tiles/256/{z}/{x}/{y}?access_token=pk.eyJ1IjoibmVhbGYiLCJhIjoiNmM4MGQ3M2UzNmVlMTY0OWNmZDhiZjk0YWZlYzQ4OTYifQ.VEiV66Tl7sjD5n-bDLjbhw', {
attribution: '© <a href="https://openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
return map;
}
function updateMap(parkId, currentMarker){
var i;
getData.getParks().then(function(data) {
for(i=0; i<data.length; ++i)
{
if(data[i].id == parkId) {
var targetMarker = L.marker([data[i].point_location.coordinates[1], data[i].point_location.coordinates[0]]).addTo(map);
targetMarker.bindPopup(
data[i].park_name + "<br /><a href='park.html?id="+parkId+"'>More Information</a>"
).openPopup();
$('#mapid').height($('body').height()*.95+'px');
map.invalidateSize();
var group = new L.featureGroup([currentMarker, targetMarker]);
map.fitBounds(group.getBounds().pad(0.3));
$('#googleMaps').button().click(function(){
window.location = getGoogleMapsLink([getUrlVars()["lat"], getUrlVars()["lon"]], [data[i].point_location.coordinates[1],data[i].point_location.coordinates[0]]);
});
return data[i];
}
}
alert("Invalid link - redirecting to search page");
window.location = "index.html";
}).fail(function(err){
alert(err);
});
}
var command = L.control({position: 'bottomright'});
command.onAdd = function (map) {
var div = L.DomUtil.create('div', 'command');
div.innerHTML = '<form style="font-weight:bold;"><input id="googleMaps" type="button" value="Google Maps Directions" /><input id="command" type="checkbox"/><label id="command-label" for="command">Update Location Real-Time</label></form>';
return div;
};
function getGoogleMapsLink(currentLocation, targetLocation)
{
return "https://www.google.com/maps/dir/'"+currentLocation[0]+","+currentLocation[1]+"'/"+targetLocation[0]+","+targetLocation[1];
}
function updateLocation(map, currentMarker) {
if(!$('#command').is(':checked'))
{
return;
}
geoLocation.getLocation().then(function(position) {
currentMarker.setLatLng(new L.LatLng(position.coords.latitude, position.coords.longitude));
//fitBounds(map, getAllMarkers(map));
//currentMarker.setIcon(new refreshIcon());
console.log("updated location to " + [position.coords.latitude, position.coords.longitude]);
}).fail(function(err) {
showError(err);
});
}
/*var refreshIcon = L.Icon.extend({
options: {
iconUrl: new url,
iconSize: [30,35],
shadowAnchor: [8, 20],
shadowSize: [25, 18],
iconSize: [20, 25],
iconAnchor: [8, 30] // horizontal puis vertical
}
});*/
function showError(error) {
switch(error.code) {
case error.PERMISSION_DENIED:
console.log("User denied the request for Geolocation.");
break;
case error.POSITION_UNAVAILABLE:
console.log("Location information is unavailable.");
break;
case error.TIMEOUT:
console.log("The request to get user location timed out.");
break;
case error.UNKNOWN_ERROR:
console.log("An unknown error occurred.");
break;
}
uncheck();
}
function fitBounds(map, markers) {
map.invalidateSize();
var group = new L.featureGroup(markers);
map.fitBounds(group.getBounds().pad(0.3));
}
function getAllMarkers(map) {
var allMarkers = [];
map.eachLayer(function (ml) {
if (ml._latlng) {
allMarkers.push(ml);
}
});
console.log(allMarkers);
return allMarkers;
}
$(document).ready(function() {
var map = createMap();
var currentMarker = L.marker([getUrlVars()["lat"], getUrlVars()["lon"]]).addTo(map);
currentMarker.bindPopup("Current location").openPopup();
command.addTo(map);
if(getUrlVars()["location"] == "on") {
setInterval(function(){ updateLocation(map, currentMarker); }, 3000);
$('#command').prop('checked', true).checkboxradio();
} else {
$('#command').hide();
$('#command-label').hide();
}
updateMap(getUrlVars()["id"], currentMarker);
$(window).on("orientationchange",function(){
map.invalidateSize();
});
});
</script>
</body>
</html>