forked from santi4488/MMM-windy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MMM-windy.js
92 lines (89 loc) · 2.4 KB
/
MMM-windy.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
Module.register('MMM-windy', {
defaults: {
initLoadDelay: 50,
apiKey: '',
zoom: 5,
particlesAnim: 'on',
graticule: false,
englishLabels: false,
hourFormat: '12h',
overlay: 'wind'
},
getScripts: function() {
return [
'https://unpkg.com/[email protected]/dist/leaflet.js',
];
},
getDom: function() {
var self = this;
var wrapper = document.createElement('div');
if (self.config.apiKey === '') {
wrapper.innerHTML = 'Please set the windy.com <i>apiKey</i> in the config for module: ' + this.name + '.';
wrapper.className = 'dimmed light small';
return wrapper;
}
if (!self.loaded) {
wrapper.innerHTML = this.translate('LOADING');
wrapper.innerClassName = 'dimmed light small';
return wrapper;
}
var mapDiv = document.createElement('div');
mapDiv.id = 'windy';
wrapper.appendChild(mapDiv);
console.log(wrapper);
return wrapper;
},
start: function() {
let self = this;
Log.info('Starting module: ' + this.name);
self.loaded = false;
var scripts = [
'https://api4.windy.com/assets/libBoot.js'
];
var loadScripts = function(scripts) {
var script = scripts.shift();
var el = document.createElement('script');
el.type = 'text/javascript';
el.src = script;
el.setAttribute('defer', '');
el.setAttribute('async', '');
el.onload = function() {
if (scripts.length) {
loadScripts(scripts);
} else {
self.loaded = true;
self.updateDom();
self.scheduleInit(self.config.initLoadDelay);
}
};
document.querySelector('body').appendChild(el);
};
loadScripts(scripts);
},
scheduleInit: function(delay) {
var self = this;
setTimeout(() => {
const options = {
key: self.config.apiKey,
zoom: self.config.zoom,
particlesAnim: self.config.particlesAnim,
graticule: self.config.graticule,
englishLabels: self.config.englishLabels,
hourFormat: self.config.hourFormat,
overlay: self.config.overlay,
};
if (self.config.location) {
options.lat = self.config.location.lat;
options.lng = self.config.location.lng;
}
windyInit(options, windyAPI => {
console.log(windyAPI);
});
}, delay);
},
getStyles: function() {
return [
'MMM-windy.css'
];
}
});