Skip to content

Commit

Permalink
Added data refresh timer
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikesch-mp committed Nov 6, 2016
1 parent b5fc56f commit f2607aa
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 20 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,15 @@ vars.geolocation = "<latitude>,<longitude>"
```

To get Geolocation data, best use a webiste like http://www.latlong.net or use you smartphone :)


## Refresh Timer

To change the default timer of 5 minutes to something that fits you, change in file globe/public/js/module.js
```
// Default refresh is 5 min
300000
// End Default refresh
```

Time is in milliseconds!
4 changes: 2 additions & 2 deletions module.info
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name : Globe 3D
Version: 0.1.0
Version: 1.0.0
Depends: Monitoring
Description: Globe 3D module
Globe is a 3D visualation of host/service groups
Globe is a 3D visualisation of service states
6 changes: 6 additions & 0 deletions public/js/globe.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,15 @@ DAT.Globe = function(container, colorFn) {
morphTargets: true
}));
}
this.points.name = "lines";
scene.addObject(this.points);
}
}

function removeAllPoints() {
scene.removeObject(scene.getChildByName("lines"));
}

function addPoint(lat, lng, size, color, subgeo) {
var phi = (90 - lat) * Math.PI / 180;
var theta = (180 - lng) * Math.PI / 180;
Expand Down Expand Up @@ -445,6 +450,7 @@ DAT.Globe = function(container, colorFn) {
});

this.addData = addData;
this.removeAllPoints = removeAllPoints;
this.createPoints = createPoints;
this.renderer = renderer;
this.scene = scene;
Expand Down
61 changes: 43 additions & 18 deletions public/js/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@

this.initialize();

this.timer;

this.module.icinga.logger.debug('Globe 3D module loaded');
};

};

var tempData;

Globe.prototype = {

initialize: function()
Expand All @@ -23,26 +27,47 @@
this.module.icinga.logger.debug('Globe 3D module initialized');
},

onRenderedContainer: function(event) {
registerTimer: function () {
this.timer = this.module.icinga.timer.register(
this.updateGlobeData,
this,
// Default refresh is 5 min
300000
// End Default refresh
);
return this;
},

var globe = new DAT.Globe(document.getElementById('earthcontainer'), function(label) {
updateGlobeData: function () {
xhr = new XMLHttpRequest();
xhr.open('GET', 'globe/globedata', true);
xhr.onreadystatechange = function(e) {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
var data = JSON.parse(xhr.responseText);
window.data = data;
if(tempData!=null){
globe.removeAllPoints();
}
globe.addData(data, {format: 'legend'});
globe.createPoints(); // Create the geometry
tempData = "1";
}
}
};
xhr.send(null);
},

onRenderedContainer: function(event) {

tempData = null;
globe = new DAT.Globe(document.getElementById('earthcontainer'), function(label) {
return new THREE.Color([0x44bb77,0xffaa44,0xff5566,0xaa44ff,0x0095bf][label]);
});
xhr = new XMLHttpRequest();
xhr.open('GET', 'globe/globedata', true);
xhr.onreadystatechange = function(e) {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
var data = JSON.parse(xhr.responseText);
window.data = data;
globe.addData(data, {format: 'legend'});
globe.createPoints(); // Create the geometry
globe.animate(); // Begin animation
}
}
};
xhr.send(null);

globe.animate(); // Begin animation
this.updateGlobeData();
this.registerTimer();
tempData = null;
},
};

Expand Down

0 comments on commit f2607aa

Please sign in to comment.