refactor setData

This commit is contained in:
Nils Schneider 2015-03-29 17:48:25 +02:00
commit a031ac336d
7 changed files with 47 additions and 35 deletions

View file

@ -77,15 +77,15 @@ define(["leaflet", "moment", "leaflet.label"], function (L, moment) {
var nodeDict = {}
var linkDict = {}
self.setData = function (now, nodes, links, newnodes, lostnodes) {
self.setData = function (data) {
nodeDict = {}
linkDict = {}
var lines = addLinksToMap(linkDict, linkScale, links, router)
var lines = addLinksToMap(linkDict, linkScale, data.links, router)
L.featureGroup(lines).addTo(map)
var nodesOnline = subtract(nodes.filter(online), newnodes)
var nodesOffline = subtract(nodes.filter(offline), lostnodes)
var nodesOnline = subtract(data.nodes.all.filter(online), data.nodes.new)
var nodesOffline = subtract(data.nodes.all.filter(offline), data.nodes.lost)
var markersOnline = nodesOnline.filter(has_location)
.map(mkMarker(nodeDict, function () { return iconOnline }, router))
@ -93,12 +93,12 @@ define(["leaflet", "moment", "leaflet.label"], function (L, moment) {
var markersOffline = nodesOffline.filter(has_location)
.map(mkMarker(nodeDict, function () { return iconOffline }, router))
var markersNew = newnodes.filter(has_location)
var markersNew = data.nodes.new.filter(has_location)
.map(mkMarker(nodeDict, function () { return iconNew }, router))
var markersLost = lostnodes.filter(has_location)
var markersLost = data.nodes.lost.filter(has_location)
.map(mkMarker(nodeDict, function (d) {
if (d.lastseen.isAfter(moment(now).subtract(3, "days")))
if (d.lastseen.isAfter(moment(data.now).subtract(3, "days")))
return iconAlert
return iconLost