-
Notifications
You must be signed in to change notification settings - Fork 0
/
soundtracked.js
executable file
·88 lines (78 loc) · 2.62 KB
/
soundtracked.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
var blueNote = L.icon({
iconUrl: 'images/bluenote.png',
shadowUrl: 'images/shadownote.png',
//iconSize: [38, 95], // size of the icon
//shadowSize: [50, 64], // size of the shadow
iconAnchor: [12, 60], // point of the icon which will correspond to marker's location
shadowAnchor: [4, 38], // the same for the shadow
popupAnchor: [-3, -76] // point from which the popup should open relative to the iconAnchor
});
var yellowNote = L.icon({
iconUrl: 'images/yellownote.png',
shadowUrl: 'images/shadownote.png',
//iconSize: [38, 95], // size of the icon
//shadowSize: [50, 64], // size of the shadow
iconAnchor: [12, 60], // point of the icon which will correspond to marker's location
shadowAnchor: [4, 38], // the same for the shadow
popupAnchor: [-3, -76] // point from which the popup should open relative to the iconAnchor
});
var bluePointer = L.icon({
iconUrl: 'images/bluePointer.png',
iconAnchor: [12, 60], // point of the icon which will correspond to marker's location
popupAnchor: [-3, -76] // point from which the popup should open relative to the iconAnchor
});
var markArrow = L.icon({
iconUrl: 'images/markarrow.png',
iconSize: [28, 65], // size of the icon
iconAnchor: [12, 60], // point of the icon which will correspond to marker's location
popupAnchor: [-3, -76] // point from which the popup should open relative to the iconAnchor
});
function AddMarkersForSongsInTheMood(songs){
var markers = [];
for (var i in songs){
var marker = L.marker([songs[i].location.lat, songs[i].location.lon], {icon: blueNote}).addTo(map);
markers.push(marker);
}
return markers;
}
function ShowWindowForNearestSong(song,marker){
marker.bindPopup("<b>Song</b><br />"+ song.song).openPopup();
marker.setIcon(yellowNote);
}
function GetSongsFromJson(val, chosenMood){
var locations = [];
if (chosenMood==""){
for (var i in val ){
locations.push(val[i]);
}
}
else{
for (var i in val ){
if (val[i].mood == chosenMood){
locations.push(val[i]);
}
}
}
return locations;
}
function ShowSongs(chosenMood){
$.getJSON( "mydata.json", function( data ) {
var items = [];
$.each( data, function( key, val ) {
var songs = GetSongsFromJson(val, chosenMood);
var markers = AddMarkersForSongsInTheMood(songs);
if (markers.length > 0){
ShowWindowForNearestSong(songs[0],markers[0]);
}
});
});
}
function ShowAllSongs(){
ShowSongs("");
}
window.onload = function() {
var chosenMood = "";
chosenMood = window.location.search.replace("?", "").split("=")[1];
ShowSongs(chosenMood);
return false;
}