forked from bschoenfeld/hrva-wiki-walking-tour
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
172 lines (148 loc) · 6.78 KB
/
index.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
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
167
168
169
170
171
172
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Floyd Solar Home Tour</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css">
<link href="./walking-tour.css" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="navbar-header">
<a class="navbar-brand" href="#">Floyd Solar Home Tour</a>
</div>
</nav>
<div class="container">
<div id="tour-overview">
<button id="start-tour" type="button" class="btn btn-success btn-lg btn-block">Start the Tour</button>
</div>
<div id="tour-spot">
<div id="next-button" class="pull-right">
<button type="button" class="btn btn-primary btn-lg">Next</button>
</div>
<h3 id="spot-name"></h3>
<div id="spot-content"></div>
<div id="directions"></div>
<div id="directions-full"></div>
</div>
<div id="tour-end">
<h1>The End!</h1>
</div>
<div id="map-canvas"></div>
</div>
<script src="./jquery-2.0.3.js"></script>
<script src="http://maps.google.com/maps/api/js?sensor=true&libraries=geometry"></script>
<script>
var mapOptions = {
zoom:15,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var directionsService = new google.maps.DirectionsService();
var directionsDisplay = new google.maps.DirectionsRenderer();
var userLocation;
var walkingTourSpots = [];
$("#start-tour").click(function() {
$("#tour-overview").hide();
$("#tour-spot").show();
directionsDisplay.setMap(map);
});
var setTourStop = function() {
$("#spot-name").html(walkingTourSpots[0]["page"]["name"]);
$("#spot-content").html(walkingTourSpots[0]["page"]["content"]);
directionsDisplay.setPanel($("#directions-full")[0]);
var request = {
origin: userLocation,
destination: walkingTourSpots[0]["location"],
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
};
var locateUser = function(onLocated) {
var onSuccess = function(position) {
onLocated(new google.maps.LatLng(position.coords.latitude, position.coords.longitude));
};
var onFail = function() {
//alert('Could not locate you!');
var work = new google.maps.LatLng(36.838050,-76.297453);
onLocated(work);
};
navigator.geolocation ?
navigator.geolocation.getCurrentPosition(onSuccess, onFail) : onFail();
};
var calculateSpotDistances = function() {
for(var i=0; i<walkingTourSpots.length; i++) {
var spotLocation = walkingTourSpots[i]["location"];
var distance = google.maps.geometry.spherical.computeDistanceBetween(userLocation, spotLocation);
walkingTourSpots[i]["distanceFromCurrentLocation"] = distance;
}
walkingTourSpots.sort(function(a,b) {
if (a.distanceFromCurrentLocation < b.distanceFromCurrentLocation)
return -1;
if (a.distanceFromCurrentLocation > b.distanceFromCurrentLocation)
return 1;
return 0;
});
};
$("#next-button button").click(function(){
if(walkingTourSpots.length == 1) {
$("#tour-spot").hide();
$("#map-canvas").hide();
$("#tour-end").show();
} else {
locateUser(function(location) {
userLocation = location;
walkingTourSpots.splice(0,1);
calculateSpotDistances();
setTourStop();
});
}
});
var loadApp = function(pageData, mapData) {
var pages = pageData["results"];
var maps = mapData["results"];
var bounds = new google.maps.LatLngBounds();
locateUser(function(location) {
userLocation = location;
for(var i=0; i<maps.length; i++) {
if(maps[i]["resource_uri"] != pages[i]["map"]) {
console.log("Map data and page data don't match for index " + i);
}
var spotPoint = maps[i]["points"]["coordinates"][0];
var spotLocation = new google.maps.LatLng(spotPoint[1], spotPoint[0]);
walkingTourSpots.push({
"page": pages[i],
"map": maps[i],
"id": $(pages[i]["content"]).find(".walking-tour-id").text(),
"location": spotLocation
});
var marker = new google.maps.Marker({
position: spotLocation,
map: map,
icon: "./yellow-dot.png"
});
bounds.extend(spotLocation);
}
map.fitBounds(bounds);
map.setZoom(15);
calculateSpotDistances();
setTourStop();
});
};
var maps = "https://localwiki.org/api/v4/maps/?region=632&page__tags=floydsolar&limit=100&format=json";
var pages = "https://localwiki.org/api/v4/pages/?region=632&tags=floydsolar&limit=100&format=json";
$.getJSON(pages).done(function(pageData){
$.getJSON(maps).done(function(mapData){
loadApp(pageData, mapData);
});
});
</script>
</body>
</html>