-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
142 lines (111 loc) · 4.7 KB
/
main.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
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
var map, db, currentInfoWindow;
function addSocial(url, prefix, icon, title) {
if (!url)
return ""
return '<a href="'+prefix+url+'" target="_blank"><i class="fa fa-'+icon+'" title="'+title+'" aria-hidden="true"></i></a>'
}
function addCore(active, icon, title) {
if (typeof active === 'string') {
return '<a href="'+active+'" target="_blank"><i class="fa fa-'+icon+'" title="'+title+'" aria-hidden="true"></i></a>'
} else if (active) {
return '<i class="fa fa-'+icon+'" title="'+title+'" aria-hidden="true"></i>'
} else {
return '<i class="fa fa-'+icon+' inactive" title="'+title+'" aria-hidden="true"></i>'
}
}
function addProp(prop, title) {
if (prop) {
return '<li>'+title+': '+prop+'</li>'
} else {
return ''
}
}
function initMarker(col) {
var location = col.geoLocation.split(',')
var lat = parseFloat(location[0])
var lng = parseFloat(location[1])
return new google.maps.Marker({
position: {lat: lat, lng: lng},
map: map,
title: col.name
});
}
function initInfoWindow(col) {
infoTxt = "<div>"
// name
infoTxt += "<h2>"+col.name+"</h2>"
infoTxt += "<ul class='info'>"
if (col.address) {infoTxt += '<li>'+col.address+'</li>'}
if (col.established) {infoTxt += '<li>Established: '+col.established+'</li>'}
infoTxt += "</ul>"
if (col.games) {
infoTxt += "<ul class='games'>"
col.games.forEach(game => infoTxt += '<li>'+game+'</li>')
infoTxt += "</ul>"
}
// cores
infoTxt += "<p>"
infoTxt += addCore(col.coworking, 'desktop', "Offers co-working")
infoTxt += addCore(col.events, 'calendar', "Offers open events")
infoTxt += ' '
// social
infoTxt += addSocial(col.website, '', 'globe', 'Website')
infoTxt += addSocial(col.facebook, 'http://facebook.com/', 'facebook', 'Facebook')
infoTxt += addSocial(col.twitter, 'http://twitter.com/', 'twitter', 'Twitter')
infoTxt += addSocial(col.instagram, 'http://instagram.com/', 'instagram', 'Instagram')
infoTxt += addSocial(col.email, 'mailto:', 'envelope', 'E-mail collective')
infoTxt += "</p>"
infoTxt += "</div>"
return new google.maps.InfoWindow({content: infoTxt});
}
function initMap() {
var mapOptions = {
center: {lat: 52.50369, lng: 13.41956},
zoom: 3,
minZoom: 2,
maxZoom: 20,
// https://snazzymaps.com/style/1/pale-dawn
styles: [{"featureType":"administrative","elementType":"all","stylers":[{"visibility":"on"},{"lightness":33}]},{"featureType":"landscape","elementType":"all","stylers":[{"color":"#f2e5d4"}]},{"featureType":"poi.park","elementType":"geometry","stylers":[{"color":"#c5dac6"}]},{"featureType":"poi.park","elementType":"labels","stylers":[{"visibility":"on"},{"lightness":20}]},{"featureType":"road","elementType":"all","stylers":[{"lightness":20}]},{"featureType":"road.highway","elementType":"geometry","stylers":[{"color":"#c5c6c6"}]},{"featureType":"road.arterial","elementType":"geometry","stylers":[{"color":"#e4d7c6"}]},{"featureType":"road.local","elementType":"geometry","stylers":[{"color":"#fbfaf7"}]},{"featureType":"water","elementType":"all","stylers":[{"visibility":"on"},{"color":"#acbcc9"}]}],
zoomControl: true,
mapTypeControl: false,
scaleControl: false,
streetViewControl: false,
rotateControl: false
};
map = new google.maps.Map(document.getElementById('map'), mapOptions);
jQuery.get('db.yaml', function(data) {
db = jsyaml.load(data);
db.forEach(col => {
if (!col.geoLocation)
return;
var marker = initMarker(col);
marker.addListener('click', function() {
if (currentInfoWindow) {currentInfoWindow.close()}
var infowindow = initInfoWindow(col);
currentInfoWindow = infowindow;
infowindow.open(map, marker);
});
lines = [
`<tr>`,
`<td class=name><a href=${col.website}>${col.name}</a></td>`,
`<td>${col.coworking ? "yes" : ""}</td>`,
`<td>${col.established ? col.established : ""}</td>`,
`<td>${addSocial(col.website, '', 'globe', 'Website')}</td>`,
`<td>${addSocial(col.facebook, 'http://facebook.com/', 'facebook', 'Facebook')}</td>`,
`<td>${addSocial(col.twitter, 'http://twitter.com/', 'twitter', 'Twitter')}</td>`,
`<td>${addSocial(col.instagram, 'http://instagram.com/', 'instagram', 'Instagram')}</td>`,
`</tr>`
]
$("table").append(lines.join())
})
});
map.addListener('click', function() {
if (currentInfoWindow) {currentInfoWindow.close()}
});
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
initialLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
map.setCenter(initialLocation);
});
}
}