forked from tursics/schule-breitband-2020
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
268 lines (228 loc) · 7.19 KB
/
index.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
var main = document.querySelector('main');
var scrolly = main.querySelector('#scrolly');
var figure = scrolly.querySelector('figure');
var article = scrolly.querySelector('article');
var step = article.querySelectorAll('.step');
var currentDistrict = 'none';
var currentType = 'today';
var dataLoaded = false;
var scroller = scrollama();
function handleResize() {
scroller.resize();
}
function convertRemToPixels(rem) {
return rem * parseFloat(getComputedStyle(document.documentElement).fontSize);
}
function statistics() {
var data = ddj.data.get();
if (data) {
var districts = ['01','02','03','04','05','06','07','08','09','10','11','12',''];
for (d = 0; d < districts.length; ++d) {
var district = districts[d];
var valueCount = 0;
var AktuelleBandbreite = 0;
var cAktuelleBandbreite = 0;
var cAktuelleBandbreite16 = 0;
var TelekomDownload = 0;
var cTelekomDownload = 0;
var TelekomUpload = 0;
var cTelekomUpload = 0;
var cTelekomLTE = 0;
console.log('->', district);
for (v = 0; v < data.length; ++v) {
var value = data[v];
if (value.BSN.indexOf(district) === 0) {
++valueCount;
var vAktuelleBandbreite = parseInt(value.AktuelleBandbreite, 10);
if (!isNaN(vAktuelleBandbreite)) {
AktuelleBandbreite += vAktuelleBandbreite;
++cAktuelleBandbreite;
if (vAktuelleBandbreite <= 16) {
++cAktuelleBandbreite16;
}
}
var vTelekomDownload = parseInt(value.TelekomDownload, 10);
if (!isNaN(vTelekomDownload)) {
TelekomDownload += vTelekomDownload;
++cTelekomDownload;
}
var vTelekomUpload = parseInt(value.TelekomUpload, 10);
if (!isNaN(vTelekomUpload)) {
TelekomUpload += vTelekomUpload;
++cTelekomUpload;
}
var vTelekomLTE = parseInt(value.TelekomLTE, 10);
if (!isNaN(vTelekomLTE)) {
++cTelekomLTE;
}
}
}
console.log('schools:', valueCount);
console.log('AktuelleBandbreite:', AktuelleBandbreite,'/',cAktuelleBandbreite,'=',parseInt(AktuelleBandbreite / cAktuelleBandbreite, 10),'MBit/s');
console.log('AktuelleBandbreite <= 16:', cAktuelleBandbreite16,'=',parseInt(cAktuelleBandbreite16 / valueCount * 100, 10),'%');
console.log('TelekomDownload:', TelekomDownload,'/',cTelekomDownload,'=',parseInt(TelekomDownload / cTelekomDownload, 10),'MBit/s');
console.log('TelekomUpload:', TelekomUpload,'/',cTelekomUpload,'=',parseInt(TelekomUpload / cTelekomUpload, 10),'MBit/s');
console.log('TelekomLTE:', cTelekomLTE);
}
}
}
function handleStepEnter(response) {
if (response.element.dataset.district && response.element.dataset.type) {
currentDistrict = response.element.dataset.district;
currentType = response.element.dataset.type;
if (currentDistrict === 'all') {
currentDistrict = '';
}
if (dataLoaded) {
var vw = Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0);
var rem40 = convertRemToPixels(40);
// ddj.tools.showSelection('.visibleWithoutData', true);
ddj.marker.update();
var layerGroup = ddj.marker.default.layerGroup;
var layerCount = 0;
if (layerGroup) {
layerCount = layerGroup.getLayers().length;
}
if (layerCount > 0) {
ddj.map.get().flyToBounds(
ddj.marker.default.layerGroup.getBounds(),
{
paddingTopLeft: L.point(15, 40),
paddingBottomRight: L.point(vw < rem40 ? 15 : 300, 0)
}
);
}
// ddj.tools.showSelection('.visibleWithoutData', false);
}
}
}
function setupStickyfill() {
var sticky = document.querySelectorAll('.sticky');
if (sticky) {
for (var s = 0; s < sticky.length; ++s) {
Stickyfill.add(sticky[s]);
}
}
}
function setupScrollerController() {
var openElement = document.querySelector('.overMap .open');
var closeElement = document.querySelector('.overMap .close');
var overMapElement = document.querySelector('.overMap');
var articleElement = document.querySelector('article');
var openMapElementList = document.querySelectorAll('.openMap');
var openElementClass = openElement.className;
var closeElementClass = closeElement.className;
function openElementCb(event) {
event.preventDefault();
openElement.className = openElementClass;
closeElement.className += ' show';
articleElement.className += ' small';
overMapElement.className += ' small';
ddj.map.get().scrollWheelZoom.enable();
}
function closeElementCb(event) {
event.preventDefault();
openElement.className += ' show';
closeElement.className = closeElementClass;
articleElement.className = articleElement.className.substring(0, articleElement.className.length - 6);
overMapElement.className = overMapElement.className.substring(0, overMapElement.className.length - 6);
ddj.map.get().scrollWheelZoom.disable();
}
openElement.className += ' show';
openElement.addEventListener('click', openElementCb, false);
closeElement.addEventListener('click', closeElementCb, false);
for (o = 0; o < openMapElementList.length; ++o) {
var element = openMapElementList[o];
element.addEventListener('click', openElementCb, false);
}
}
function init() {
setupStickyfill();
setupScrollerController();
handleResize();
scroller
.setup({
step: '#scrolly article .step',
offset: 0.4,
debug: false
})
.onStepEnter(handleStepEnter);
window.addEventListener('resize', handleResize);
}
init();
ddj.autostart.onDone(function() {
ddj.map.get().scrollWheelZoom.disable();
dataLoaded = true;
// statistics();
});
ddj.autostart.onAddMarker(function(marker, value) {
if (value.BSN.indexOf(currentDistrict) !== 0) {
return false;
}
var data = '';
if (currentType === 'today') {
data = value.AktuelleBandbreite;
} else if (currentType === 'telekom') {
data = value.TelekomDownload;
} else if (currentType === 'diff') {
data = Math.max(0, parseInt(value.TelekomDownload, 10) - parseInt(value.AktuelleBandbreite, 10));
} else if (currentType === 'perHead') {
}
var dataInt = parseInt(data, 10);
var iconFace = '';
var iconColor = '';
if (currentType === 'diff') {
if (data === 0) {
iconColor = 'beige';
iconFace = 'fa-minus';
} else if (data <= 100) {
iconColor = 'blue';
iconFace = 'fa-angle-up';
} else {
iconColor = 'darkblue';
iconFace = 'fa-angle-double-up';
}
} else if (currentType === 'perHead') {
iconColor = 'pink';
iconFace = 'fa-circle';
} else {
if (data === '') {
iconColor = 'white';
iconFace = 'fa-question';
} else if (data === '-') {
iconColor = 'white';
iconFace = 'fa-question';
} else if (dataInt < 1) {
iconColor = 'red';
iconFace = 'fa-times';
} else if (dataInt < 7) {
iconColor = 'lightred';
iconFace = 'fa-battery-empty';
} else if (dataInt < 17) {
iconColor = 'orange'
iconFace = 'fa-battery-quarter'
} else if (dataInt < 51) {
iconColor = 'lightgreen'
iconFace = 'fa-battery-half'
} else if (dataInt < 101) {
iconColor = 'green';
iconFace = 'fa-battery-three-quarters';
} else if (dataInt < 1000) {
iconColor = 'darkgreen';
iconFace = 'fa-battery-full';
} else {
iconColor = 'black';
iconFace = 'fa-rocket';
}
}
// marker.index
// marker.count
// marker.lat
// marker.lng
marker.color = iconColor;
// marker.opacity = 1;
// marker.clickable = 1;
marker.iconPrefix = 'fas';
marker.iconFace = iconFace;
return true;
});