-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
239 lines (217 loc) · 6.25 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<title>Biking tour of Anchorage Breweries</title>
<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px
}
#panel {
position: absolute;
top: 5px;
left: 50%;
margin-left: -180px;
z-index: 5;
background-color: #fff;
padding: 10px;
border: 1px solid #999;
}
details {
background-color: rgba(0, 0, 0, 0.75);
border: 1px solid rgb(0, 0, 0);
position: absolute;
padding: 10px;
top: 62px;
left: 10px;
z-index: 6;
font-family: sans-serif;
color: white;
}
summary {
margin: 10px 0;
}
#menu button{
display: block;
margin: 10px;
width: 100px;
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&key=AIzaSyD4ZO5QaYEUf1BA1DkNhXUtBO-W3tqag2s"></script>
</head>
<body>
<div id="map-canvas"></div>
<details>
<summary>Choose your breweries</summary>
<div id="menu"></div>
</details>
<script>
var map, bikeLayer;
var directionsDisplayOptions = {
preserveViewport: true,
suppressMarkers: true,
suppressBicyclingLayer: true //Otherwise layer disappears when route is changed
};
var directionsDisplay = new google.maps.DirectionsRenderer(directionsDisplayOptions);
var infowindow = new google.maps.InfoWindow({
size: new google.maps.Size(150,50)
});
var directionsService = new google.maps.DirectionsService();
var start_finish = {};
var waypoints = [];
var markers = [];
var markerCluster = null;
const DEFAULT_WAYPOINTS = [
{
name: "Glacier Brewhouse",
address: "737 W 5th Ave Ste. 110, Anchorage, AK 99501",
latlong: new google.maps.LatLng(61.21757050000001, -149.8964654)
},
{
name: "49th State Brewing Co.",
address: "717 W 3rd Ave, Anchorage, AK 99501",
latlong: new google.maps.LatLng(61.2195394, -149.8958217)
},
{
name: "Alpenglow Brewery",
address: "3024 Mountain View Drive, Anchorage, AK 99501",
latlong: new google.maps.LatLng(61.2195981, -149.8227352)
},
{
name: "Mooses Tooth Pub & Pizzeria",
address: "3300 Old Seward Hwy, Anchorage, AK",
latlong: new google.maps.LatLng(61.19068459999999, -149.8682844)
},
{
name: "Onsite Brewing",
address: "3211 Denali St, Anchorage, AK 99503",
latlong: new google.maps.LatLng(61.1913606, -149.8764497)
},
{
name: "Matanuska Brewing Company",
address: "2830 C Street, Anchorage, AK 99503",
latlong: new google.maps.LatLng(61.1947333, -149.8884164)
},
{
name: "Double Shovel Cider Company",
address: "502 W 58th Ave C, Anchorage, AK 99518",
latlong: new google.maps.LatLng(61.168699, -149.8916839)
},
{
name: "Brewerks",
address: "625 W 59th Ave, Units A/B, Anchorage, AK 99518",
latlong: new google.maps.LatLng(61.1675884, -149.8944055)
},
{
name: "Cynosure Brewing",
address: "1363, 144 E Potter Dr unit e, Anchorage, AK 99518",
latlong: new google.maps.LatLng(61.168569, -149.883072)
},
{
name: "Turnagain Brewing",
address: "7920 & 7924 King Street, Anchorage, Alaska 99518",
latlong: new google.maps.LatLng(61.14904, -149.878212)
},
{
name: "Magnetic North Brewing Co",
address: "8861 Golovin St, Anchorage, AK 99507",
latlong: new google.maps.LatLng(61.1404826, -149.8372688)
},
{
name: "Midnight Sun Brewing Co.",
address: "8111 Dimond Hook Dr, Anchorage, AK 99507",
latlong: new google.maps.LatLng(61.1469204, -149.84449940000002)
},
{
name: "Anchorage Brewing Company",
address: "148 West 91st Street, Anchorage, AK 99515",
latlong: new google.maps.LatLng(61.1388234, -149.8815848)
},
{
name: "King Street Brewing Company",
address: "9050 King St, Anchorage, AK 99515",
latlong: new google.maps.LatLng(61.1389589, -149.8799729)
},
]
// build menu
var menu = document.querySelector('#menu')
DEFAULT_WAYPOINTS.forEach(function(waypoint, index) {
var input = document.createElement('input')
input.type = 'checkbox'
input.onchange = loadPath
input.value = index
input.checked = true
menu.appendChild(input)
menu.append(waypoint.name)
menu.append(document.createElement('br'))
})
function initialize() {
var mapOptions = {
zoom: 12,
center: new google.maps.LatLng(61.180610, -149.868374)
};
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
//Add bike layer by default
bikeLayer = new google.maps.BicyclingLayer();
bikeLayer.setMap(map);
//Load full path by default
loadPath("Full");
//add markers to map
waypoints.forEach(function(waypoint, index) {
var marker = new google.maps.Marker({
position: waypoint.latlong,
map: map,
icon: new google.maps.MarkerImage("img/beer.png"),
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent('<b>'+waypoint.name+'</b><br>'+waypoint.address);
infowindow.open(map, marker);
});
markers.push(marker);
})
}
function loadPath(){
clearRoute()
// find the checked breweries
document.querySelectorAll('input:checked').forEach(function(input) {
waypoints.push(DEFAULT_WAYPOINTS[parseInt(input.value)])
})
start_finish = waypoints[0];
directionsDisplay.setMap(map);
calcRoute(start_finish, waypoints[waypoints.length - 1], waypoints);
// hide unselected breweries
document.querySelectorAll('input').forEach(function(input, index) {
if (markers[index]) markers[index].setVisible(input.checked)
})
}
function calcRoute(start, end, routes) {
var waypts = [];
for (var i = 0; i < routes.length; i++) {
waypts.push({
location: routes[i].address,
stopover: true
});
}
var request = {
origin: start.address,
destination: end.address,
waypoints: waypts,
optimizeWaypoints: false,
travelMode: google.maps.TravelMode.BICYCLING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
function clearRoute(){
waypoints = [];
directionsDisplay.setMap(null);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</body>