diff --git a/README.md b/README.md index c29888d..4e91123 100644 --- a/README.md +++ b/README.md @@ -19,3 +19,15 @@ vars.geolocation = "," ``` 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! diff --git a/module.info b/module.info index ee9d4ba..0c78f5f 100644 --- a/module.info +++ b/module.info @@ -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 diff --git a/public/js/globe.js b/public/js/globe.js index a804dba..830b9b4 100644 --- a/public/js/globe.js +++ b/public/js/globe.js @@ -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; @@ -445,6 +450,7 @@ DAT.Globe = function(container, colorFn) { }); this.addData = addData; + this.removeAllPoints = removeAllPoints; this.createPoints = createPoints; this.renderer = renderer; this.scene = scene; diff --git a/public/js/module.js b/public/js/module.js index a08c642..e6c1a15 100644 --- a/public/js/module.js +++ b/public/js/module.js @@ -11,10 +11,14 @@ this.initialize(); + this.timer; + this.module.icinga.logger.debug('Globe 3D module loaded'); - }; + }; + var tempData; + Globe.prototype = { initialize: function() @@ -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; }, };