-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMMM-Globe.js
118 lines (100 loc) · 3.03 KB
/
MMM-Globe.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
/* global Module */
/* Magic Mirror
* Module: MMM-Globe
*
* By Eunan Camilleri eunancamilleri@gmail.com
* MIT Licensed.
*/
Module.register("MMM-Globe",{
// Default module config.
defaults: {
size : "medium",
locations : [],
markers: [],
viewAngle: 0,
dayLength: 28
},
// Define required scripts.
getScripts: function() {
return ["encom-globe.js", "grid.js", "data.js", "styles.css", "defaultData.js"];
},
// Define required scripts.
getStyles: function() {
return [];
},
// Define required translations.
getTranslations: function() {
return false;
},
// Define start sequence.
start: function() {
Log.info("Starting module: " + this.name);
this.globe = null;
this.translatedSize = this.sizeTranslate(this.config.size);
this.locations = this.config.locations;
this.viewAngle = this.convertDegreesToRadians(this.config.viewAngle);
if (this.config.dayLength > 0) {
this.dayLength = parseFloat(this.config.dayLength);
} else {
this.dayLength = 1;
}
},
convertDegreesToRadians: function(degrees) {
return (parseFloat(degrees) * Math.PI) / 180;
},
// Override dom generator.
getDom: function() {
var wrapper = document.createElement("div");
wrapper.className = "globe";
wrapper.setAttribute('align', 'center');
wrapper.setAttribute('align-text', 'center');
wrapper.setAttribute('font-family', 'Roboto Condensed');
var container = document.getElementsByClassName("module " + this.name + " " + this.name);
var width = container[0].offsetWidth;
wrapper.appendChild(this.createGlobe(width/this.translatedSize, width/this.translatedSize).domElement);
return wrapper;
},
createGlobe : function(width, height) {
Log.info("Loading data...");
var globeData = [];
if(this.locations.length <= 0) { // enforce config locations
Log.info("Loading default locations.");
Array.prototype.push.apply(globeData, defaultData);
}
else {
Log.info("Loading custom locations.")
Array.prototype.push.apply(globeData, this.locations);
}
Log.info("Creating globe... (" + this.config.dayLength + " sec/rotation)");
var globe = new ENCOM.Globe(width, height, {
tiles: grid.tiles, // The locations of the hexes; this really should be refactored into a standard 3d model.. .from grid.js
data: globeData, // The default pins (Boston, Moscow, etc, and all the non-labelled ones)... from data.js
viewAngle: this.viewAngle, // tilt the globe
dayLength: this.dayLength * 1000 // time for one rotation
});
globe.init(animate); // tell the globe to start the animation loop when everything has been intialized
function animate(){
globe.tick(); // this will rotate the globe, and render it to the canvas referenced as globe.domElement
requestAnimationFrame(animate);
}
this.globe = globe;
data = null;
return globe;
},
sizeTranslate : function(size){
switch(size) {
case "x-small" :
return 4;
case "small" :
return 3;
case "medium" :
return 2;
case "large" :
return 1.5;
case "x-large" :
return 1;
}
},
speedTranslate : function(speed) {
}
});