-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
96 lines (75 loc) · 2.92 KB
/
app.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
mapboxgl.accessToken = 'pk.eyJ1IjoiYnJpdHRhbnlydyIsImEiOiJja3RrdzY3bWwwdXp5MnFvMHhmNGV4ejVoIn0.fPh8dPjxReFsNdlodQH14w';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/brittanyrw/cj9yzhuym82yq2skpp4v7n6kv',
center: [-73.972080, 40.752226],
zoom: 12.5
});
map.on('load', 'tony-musicals', function (e) {
buildLocationList(e);
var popup = new mapboxgl.Popup({
closeButton: true,
closeOnClick: true
});
map.on('click', 'tony-musicals', function (e) {
map.flyTo({
center: e.features[0].geometry.coordinates,
zoom: 11
});
});
map.on('mouseenter', 'tony-musicals', function(e) {
const data = e.features[0].properties;
map.getCanvas().style.cursor = 'pointer';
popup.setLngLat(e.features[0].geometry.coordinates)
.setHTML("<h2>" + data.musical + "</h2>" + "<p> Tony " + " " + data.award + " " + data.winYear + "</p>" + "<p>" + data.description + "</p>" + "<p>" + data.setting + "</p>" + "<p>")
.addTo(map);
});
map.on('mouseleave', 'tony-musicals', function () {
map.getCanvas().style.cursor = '';
});
map.addControl(new mapboxgl.NavigationControl());
});
function flyToShow(currentFeature) {
map.flyTo({
center: currentFeature.geometry.coordinates,
zoom: 14
});
}
function filter() {
var input = document.getElementsByClassName('item');
var filter = document.getElementById('search').value.toLowerCase();
for (i = 0; i < input.length; i++) {
var currentItem = input[i];
var currentListingItem = input[i].children[0]
if (currentListingItem.innerHTML.toLowerCase().indexOf(filter) > -1) {
currentItem.style.display = "";
} else {
currentItem.style.display = "none";
}
}
}
document.getElementById('search').addEventListener('keyup', filter);
function buildLocationList(data) {
for (i = 0; i < data.features.length; i++) {
var currentFeature = data.features[i];
var prop = currentFeature.properties;
var listings = document.getElementById('listings');
var listing = listings.appendChild(document.createElement('div'));
listing.className = 'item';
listing.id = "listing-" + i;
var link = listing.appendChild(document.createElement('a'));
link.href = '#';
link.className = 'title';
link.dataPosition = i;
link.innerHTML = prop.musical;
var winYear = listing.appendChild(document.createElement('p'));
winYear.className = 'award';
winYear.innerHTML = "Tony " + prop.award + ", " + prop.winYear;
var description = listing.appendChild(document.createElement('p'));
description.innerHTML = prop.description;
link.addEventListener('click', function(e){
var clickedListing = data.features[this.dataPosition];
flyToShow(clickedListing);
});
}
}