-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.js
96 lines (76 loc) · 2.48 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
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
var marketsBerlin = (function() {
var map,
markerArray,
marketData;
function getMarkets(day, time) {
//delete markers from before
deleteMarkers();
// get the data
$.each(marketData, function(index, value) {
//split days into array
var arrayDays = value.Tage.split(' ');
//loop through days
for (var i = 0; i < arrayDays.length; i++) {
if (arrayDays[i] === day) {
//check for the time
if (time >= value.ZeitenOn && time <= value.ZeitenOff) {
geo = value.Geolocations
var marker = L.marker(L.latLng(geo)).addTo(map);
marker.bindPopup("<h2>" + value.Name + "</h2>" + "<br/>" + value.Ort + "<br/>" + value.ZeitenOn + " - " + value.ZeitenOff + "<br/>"
+ "<br/>" + value.Betreiber + "<br/>" + value.Telefonnummer + "<br/>"
+ "<a href=\"mailto:" + value.EMail + "\">" + value.EMail + "<a/>" + "<br/>"
+ "<a href=\"" + "http://" + value.Internetadresse + "\">" + value.Internetadresse + "</a>");
markerArray.push(marker);
}
}
}
});
}
function deleteMarkers() {
$.each(markerArray, function(i, marker) {
map.removeLayer(marker);
})
}
function initDateAndTime() {
var d = new Date(),
day = d.getDay(),
time = d.getHours();
if (day > 0) {
day--;
} else {
day = 6;
}
document.getElementById("weekdays").selectedIndex = day;
if( time < 8 || time > 22) {
time = 0;
} else {
time -= 8;
}
document.getElementById("time").selectedIndex = time;
}
var mB ={};
mB.init = function() {
map = L.map( 'map', {
center: [52.510, 13.5],
minZoom: 11,
zoom: 10
});
markerArray = [];
$.getJSON( "./data/berlin-markets.json", function(data) {
marketData = data;
});
L.tileLayer( 'http://{s}.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright" title="OpenStreetMap" target="_blank">OpenStreetMap</a> contributors | Tiles Courtesy of <a href="http://www.mapquest.com/" title="MapQuest" target="_blank">MapQuest</a> <img src="http://developer.mapquest.com/content/osm/mq_logo.png" width="16" height="16">',
subdomains: ['otile1','otile2','otile3','otile4']
}).addTo( map );
initDateAndTime();
}
mB.setMap = function() {
var days = document.getElementById("weekdays");
var times = document.getElementById("time");
var day = days.options[days.selectedIndex].value;
var time = times.options[times.selectedIndex].text;
getMarkets(day, time);
};
return mB;
}());