refactor setData
This commit is contained in:
parent
3e143435e6
commit
a031ac336d
7 changed files with 47 additions and 35 deletions
14
lib/map.js
14
lib/map.js
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue