forked from ttwthomas/mcflurry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.js
60 lines (56 loc) · 1.75 KB
/
map.js
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
import { styles } from './styles.js';
import { restaurants } from './missingflurry.js'
export class Map {
constructor() {
const montreal = { lat: 45.54, lng: -73.7 };
this.map = new google.maps.Map(document.getElementById('map'), {
center: montreal,
disableDefaultUI: true,
zoom: 11,
styles
});
this.addRestaurants(restaurants);
}
addRestaurants(restaurants) {
restaurants.forEach((restaurant, index) => {
let location = {
lat: restaurant.location.latitude,
lng: restaurant.location.longitude
};
let icon = 'mcdonalds.png';
if (restaurant.unavailable.length) {
icon = 'mcdonalds-unavail.png';
}
else if (!restaurant.open) {
icon = 'mcdonalds-closed.png';
}
let timeout = index * 10;
window.setTimeout(() => {
this.addMarker(location, restaurant.name, icon, restaurant.unavailable)
}, timeout)
});
}
addMarker(position, name, icon, unavailable) {
let marker = new google.maps.Marker({
position,
map: this.map,
icon,
});
let unavailable_div_content = '';
unavailable.forEach(item => unavailable_div_content += `${item} </br>`);
let unavailable_div = `<div>${unavailable_div_content}</div>`;
const content =
`<div id="content">
<h1 id="firstHeading" class="firstHeading"> ${name} </h1>
<div id="bodyContent">
<p>Missing items:</p>
${unavailable_div}
</div>
</div>`;
const infowindow = new google.maps.InfoWindow({
content
});
marker.addListener('click', () => infowindow.open(this.map, marker));
marker.setAnimation(google.maps.Animation.DROP);
}
}