From bf85758ba32e035ab08437b136842891ed2220a8 Mon Sep 17 00:00:00 2001 From: Martin Geno Date: Thu, 14 Jul 2016 14:07:36 +0200 Subject: [PATCH] add autorefresh-toggle + map layer node and geojson --- public/app/map/index.jade | 1 + public/app/map/index.js | 74 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 public/app/map/index.jade create mode 100644 public/app/map/index.js diff --git a/public/app/map/index.jade b/public/app/map/index.jade new file mode 100644 index 0000000..9738d4d --- /dev/null +++ b/public/app/map/index.jade @@ -0,0 +1 @@ +leaflet.map.global(id="globalmap") diff --git a/public/app/map/index.js b/public/app/map/index.js new file mode 100644 index 0000000..9c52d3f --- /dev/null +++ b/public/app/map/index.js @@ -0,0 +1,74 @@ +'use strict'; + +angular.module('ffhb') + .controller('MapCtrl',function($state,$stateParams,$scope,store,config,leafletData){ + if($stateParams.nodeid){ + $scope.nodeid = $stateParams.nodeid.toLowerCase(); + } + var layerControl,nodeLayer,geoLayer; + leafletData.getMap('globalmap').then(function(map) { + layerControl = L.control.layers().addTo(map); + map.setView([config.map.view.lat, config.map.view.lng],16); + }); + store.getGeojson.then(function(data){ + leafletData.getMap('globalmap').then(function(map) { + geoLayer = L.geoJson(data,config.map.geojson); + layerControl.addOverlay(geoLayer,'GEOJSON'); + geoLayer.addTo(map); + }); + }); + function render(prom){ + prom.then(function(data){ + leafletData.getMap('globalmap').then(function(map) { + if(nodeLayer!==undefined){ + layerControl.removeLayer(nodeLayer); + } + nodeLayer = L.markerClusterGroup({maxClusterRadius:20}); + Object.keys(data.merged).map(function(nodeid){ + var node = data.merged[nodeid]; + if(node.nodeinfo.location !== undefined && node.nodeinfo.location.latitude !== undefined && node.nodeinfo.location.longitude !== undefined){ + var className = 'node'; + var wifi24='-',wifi5='-',ch24='-',ch5='-',tx24='-',tx5='-'; + if(node.statistics && node.statistics.clients){ + wifi24 = node.statistics.clients.wifi24; + if(wifi24 < config.map.icon.warn.wifi24 && wifi24 > 0){ + className += ' client24'; + } else if(wifi24 < config.map.icon.crit.wifi24 && wifi24 >= config.map.icon.warn.wifi24){ + className += ' client24-warn'; + } else if(wifi24 >= config.map.icon.crit.wifi24){ + className += ' client24-crit'; + } + + wifi5 = node.statistics.clients.wifi5; + if(config.map.icon.warn.wifi5 < 20 && wifi5 > 0){ + className += ' client5'; + } else if(wifi5 < config.map.icon.crit.wifi5 && wifi5 >= config.map.icon.warn.wifi5){ + className += ' client5-warn'; + } else if(wifi5 >= config.map.icon.crit.wifi5){ + className += ' client5-crit'; + } + } + var nodemarker = L.marker([node.nodeinfo.location.latitude, node.nodeinfo.location.longitude],{icon: L.divIcon({className: className})}); + nodemarker.bindLabel(node.nodeinfo.hostname+'
('+nodeid+')'+ + ''+ + ''+ + ''+ + '
ClChTx
2.4G'+wifi24+''+ch24+''+tx24+'
5G'+wifi5+''+ch5+''+tx5+'
'+ + '
' + ); + nodemarker.on('dblclick',function(){ + $state.go('app.node', {nodeid: nodeid}); + }); + nodeLayer.addLayer(nodemarker).addTo(map); + } + }); + layerControl.addOverlay(nodeLayer,'Nodes'); + nodeLayer.addTo(map); + }); + }); + } + render(store.getData); + $scope.$on('store', function(ev, prom) { + render(prom); + }); + });