forked from CivicTechAtlanta/asset-map
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eventbrite.js
167 lines (135 loc) · 5.6 KB
/
eventbrite.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// use leaflet clustermarkers
// eventbrite integration
var ebConfig = {
apiKey: 'EJAXVB3GXRY550WSHRBEVAHYKIKGHW0YXHQIVJVMMF3OLQID',
authUrl: 'https://www.eventbrite.com/',
apiUrl: 'https://www.eventbriteapi.com/'
};
var page = 1;
var pages = 1;
var EB_TOKEN = 'E55J2U6EXE3CVF6G43VU'
var API_ENDPOINT = 'https://www.eventbriteapi.com/v3/events/search/' +
'?token=EB_TOKEN' +
'&location.latitude=33.74986' +
'&location.longitude=-84.39223' +
'&location.within=1km' +
'&page=PAGE';
var eventbriteLayer = L.layerGroup();
$.getJSON(API_ENDPOINT
.replace('PAGE', 1)
.replace('EB_TOKEN', EB_TOKEN), function(result, status) {
if (status !== 'success') return alert('Request to Eventbrite failed');
pages = result.pagination.page_count;
getData();
});
// loop through pages
function getData() {
while (page <= pages) {
$.getJSON(API_ENDPOINT
.replace('PAGE', page)
.replace('EB_TOKEN', EB_TOKEN), function(result, status) {
if (status !== 'success') return alert('Request to Eventbrite failed');
// transform venue result into map marker
for (var i = 0; i < result.events.length; i++) {
var venue = result.events[i].venue;
var eventInfo = result.events[i];
var category = "";
if (eventInfo.category !== null && eventInfo.category.name !== null) {
category = eventInfo.category;
}
var latlng = L.latLng(venue.latitude, venue.longitude);
var marker = L.marker(latlng, {
icon: makeMarker(category)
})
.bindPopup('<strong>' + venue.name + '</strong><br><a href="' + eventInfo.url + '" target="_blank">' + eventInfo.name.html + '</a><br>Begins: ' + eventInfo.start.local.substr(0,10) + '<br>' + eventInfo.organizer.name + '<br>' + category.name)
.addTo(map); // maybe just add to layer
}
});
page++;
};
}
function makeMarker(category) {
if (category.id == 103 || category.id == 104 || category.id == 105) {
// arts
return L.AwesomeMarkers.icon({
icon: 'paint-brush',
prefix: 'fa',
markerColor: 'red'
})
} else if (category.id == 106 || category.id == 107 || category.id == 108 || category.id == 109 || category.id == 110 || category.id == 117 || category.id == 118 || category.id == 119) {
// hobbies
return L.AwesomeMarkers.icon({
icon: 'futbol-o',
prefix: 'fa',
markerColor: 'blue'
})
} else if (category.id == 101 || category.id == 102) {
// professional
return L.AwesomeMarkers.icon({
icon: 'suitcase',
prefix: 'fa',
markerColor: 'darkgreen'
})
} else if (category.id == 111 || category.id == 113 || category.id == 114) {
// organizations
return L.AwesomeMarkers.icon({
icon: 'group',
prefix: 'fa',
markerColor: 'orange'
})
} else if (category.id == 112) {
// government
return L.AwesomeMarkers.icon({
icon: 'university',
prefix: 'fa',
markerColor: 'green'
})
} else {
return L.AwesomeMarkers.icon({
icon: '',
prefix: 'fa',
markerColor: 'darkpurple'
})
}
};
// colors: 'red', 'darkred', 'orange', 'green', 'darkgreen', 'blue', 'purple', 'darkpuple', 'cadetblue'
// map
var southDowntownLayer = L.geoJson(southDowntown, {
onEachFeature: function(feature, layer) {
layer.bindPopup(feature.properties.name);
},
style: {color: '#007df0',
opacity: 1},
});
var map = L.map('map', {
attributionControl: false,
center: new L.LatLng(33.75, -84.392),
zoom: 15,
layers: [southDowntownLayer, eventbriteLayer]
});
L.control.attribution({position: 'bottomleft'}).addTo(map);
L.tileLayer('http://otile4.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png', {
attribution:
'Made at <a href="http://www.codeforamerica.org/events/codeacross-2015/">CodeAcross</a> for <a href="http://www.codeforatlanta.org/"><img src="images/code-for-atlanta.png" height=70></a>' +
'<br>Tiles © <a href="http://www.mapquest.com/" target="_blank">MapQuest</a> <img src="http://developer.mapquest.com/content/osm/mq_logo.png" />',
maxZoom: 18
}).addTo(map);
var overlayMaps = {
// "<i class='fa fa-cutlery' style='color:#728224'></i> Food <img src='images/foursquare-logomark.png' width='18' valign='bottom'>": foodLayer,
// "<i class='fa fa-home' style='color:#5B396B'></i> Residential Buildings <img src='images/foursquare-logomark.png' width='18' valign='bottom'>": residentialLayer,
// "<i class='fa fa-birthday-cake' style='color:#D152B8'></i> Entertainment <img src='images/foursquare-logomark.png' width='18' valign='bottom'>": entertainmentLayer,
// "<span style='color: #f8b50c;'>▌</span>Population Density": censusBlocksLayer,
// "<span style='color: #f07300;'>▌</span>Parcels": parcelLayer,
// "Neighborhood Profile": neighborhoodProfileLayer,
// "1949 Aerial Survey": historicalMapLayer,
// "<i class='fa fa-circle-o' style='color:#A13336'></i> Vacant Properties": vacantLayer,
// "<i class='fa fa-group' style='color:#436877'></i> Community Assets": communityAssetsLayer,
// "<i class='fa fa-paint-brush' style='color:#D43E2A'></i> Art": artLayer,
// "<i class='fa fa-subway' style='color:#F49630'></i> MARTA Train Stations": MARTALayer,
// "<i class='fa fa-flag' style='color:#38AADD'></i> Historical Markers": historicalMarkersLayer,
// "<span style='color: #8e44ad;'>▌</span>Landmarks": landmarksLayer,
// "<i class='fa fa-university' style='color:#72AF26'></i> Government Buildings <img src='images/foursquare-logomark.png' width='18' valign='bottom'>": governmentBuildingsLayer
};
L.control.layers(null, overlayMaps, {
collapsed: false
}).addTo(map);