refactor map.js, show all offline nodes
This commit is contained in:
parent
ccd4b1652b
commit
40ecf2641e
@ -66,8 +66,6 @@ function (Router, Map, Sidebar, Tabs, Container, Meshstats, Linklist, Nodelist,
|
|||||||
var newnodes = limit("firstseen", age, sortByKey("firstseen", nodes).filter(online))
|
var newnodes = limit("firstseen", age, sortByKey("firstseen", nodes).filter(online))
|
||||||
var lostnodes = limit("lastseen", age, sortByKey("lastseen", nodes).filter(offline))
|
var lostnodes = limit("lastseen", age, sortByKey("lastseen", nodes).filter(offline))
|
||||||
|
|
||||||
var onlinenodes = nodes.filter(online)
|
|
||||||
|
|
||||||
var graph = data[1].batadv
|
var graph = data[1].batadv
|
||||||
var graphnodes = data[0].nodes
|
var graphnodes = data[0].nodes
|
||||||
|
|
||||||
@ -112,7 +110,7 @@ function (Router, Map, Sidebar, Tabs, Container, Meshstats, Linklist, Nodelist,
|
|||||||
d.target.node.neighbours.push({ node: d.source.node, link: d })
|
d.target.node.neighbours.push({ node: d.source.node, link: d })
|
||||||
})
|
})
|
||||||
|
|
||||||
map.setData(now, newnodes, lostnodes, onlinenodes, links)
|
map.setData(now, nodes, links, newnodes, lostnodes)
|
||||||
meshstats.setData(nodes)
|
meshstats.setData(nodes)
|
||||||
nodelist.setData(now, nodes)
|
nodelist.setData(now, nodes)
|
||||||
linklist.setData(links)
|
linklist.setData(links)
|
||||||
|
56
lib/map.js
56
lib/map.js
@ -49,11 +49,12 @@ define(function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var iconOnline = { color: "#1566A9", radius: 6, fillOpacity: 0.5, weight: 2, className: "stroke-first" }
|
var iconOnline = { color: "#1566A9", radius: 6, fillOpacity: 0.5, weight: 2, className: "stroke-first" }
|
||||||
var iconOffline = { color: "#D43E2A", radius: 6, fillOpacity: 0.5, weight: 2, className: "stroke-first" }
|
var iconOffline = { color: "#D43E2A", radius: 3, fillOpacity: 0.5, weight: 1, className: "stroke-first" }
|
||||||
|
var iconLost = { color: "#D43E2A", radius: 6, fillOpacity: 0.5, weight: 1, className: "stroke-first" }
|
||||||
var iconAlert = { color: "#D43E2A", radius: 6, fillOpacity: 0.5, weight: 2, className: "stroke-first node-alert" }
|
var iconAlert = { color: "#D43E2A", radius: 6, fillOpacity: 0.5, weight: 2, className: "stroke-first node-alert" }
|
||||||
var iconNew = { color: "#558020", radius: 6, fillOpacity: 0.5, weight: 2, className: "stroke-first" }
|
var iconNew = { color: "#558020", radius: 6, fillOpacity: 0.5, weight: 2, className: "stroke-first" }
|
||||||
|
|
||||||
var groupOnline, group
|
var groupOnline, groupOffline, groupNew, groupLost
|
||||||
|
|
||||||
return function (linkScale, sidebar, router) {
|
return function (linkScale, sidebar, router) {
|
||||||
var self = this
|
var self = this
|
||||||
@ -69,47 +70,60 @@ define(function () {
|
|||||||
L.tileLayer("https://otile{s}-s.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.jpg", {
|
L.tileLayer("https://otile{s}-s.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.jpg", {
|
||||||
subdomains: "1234",
|
subdomains: "1234",
|
||||||
type: "osm",
|
type: "osm",
|
||||||
attribution: "Map data Tiles © <a href=\"https://www.mapquest.com/\" target=\"_blank\">MapQuest</a> <img src=\"https://developer.mapquest.com/content/osm/mq_logo.png\" />, Map data © OpenStreetMap contributors, CC-BY-SA",
|
attribution: "Tiles © <a href=\"https://www.mapquest.com/\" target=\"_blank\">MapQuest</a>, Data CC-BY-SA OpenStreetMap",
|
||||||
maxZoom: 18
|
maxZoom: 18
|
||||||
}).addTo(map)
|
}).addTo(map)
|
||||||
|
|
||||||
var nodeDict = {}
|
var nodeDict = {}
|
||||||
var linkDict = {}
|
var linkDict = {}
|
||||||
|
|
||||||
self.setData = function (now, newnodes, lostnodes, onlinenodes, links) {
|
self.setData = function (now, nodes, links, newnodes, lostnodes) {
|
||||||
nodeDict = {}
|
nodeDict = {}
|
||||||
linkDict = {}
|
linkDict = {}
|
||||||
|
|
||||||
var lines = addLinksToMap(linkDict, linkScale, links, router)
|
var lines = addLinksToMap(linkDict, linkScale, links, router)
|
||||||
|
L.featureGroup(lines).addTo(map)
|
||||||
|
|
||||||
var nodes = newnodes.concat(lostnodes).filter(has_location)
|
var nodesOnline = subtract(nodes.filter(online), newnodes)
|
||||||
|
var nodesOffline = subtract(nodes.filter(offline), lostnodes)
|
||||||
|
|
||||||
var markers = nodes.map(mkMarker(nodeDict, function (d) {
|
var markersOnline = nodesOnline.filter(has_location)
|
||||||
if (d.flags.online)
|
|
||||||
return iconNew
|
|
||||||
|
|
||||||
if (d.lastseen.isAfter(moment(now).subtract(1, 'days')))
|
|
||||||
return iconAlert
|
|
||||||
|
|
||||||
return iconOffline
|
|
||||||
}, router))
|
|
||||||
|
|
||||||
var onlinemarkers = subtract(onlinenodes.filter(has_location), newnodes)
|
|
||||||
.map(mkMarker(nodeDict, function (d) { return iconOnline }, router))
|
.map(mkMarker(nodeDict, function (d) { return iconOnline }, router))
|
||||||
|
|
||||||
var groupLines = L.featureGroup(lines).addTo(map)
|
var markersOffline = nodesOffline.filter(has_location)
|
||||||
groupOnline = L.featureGroup(onlinemarkers).addTo(map)
|
.map(mkMarker(nodeDict, function (d) { return iconOffline }, router))
|
||||||
group = L.featureGroup(markers).addTo(map)
|
|
||||||
|
var markersNew = newnodes.filter(has_location)
|
||||||
|
.map(mkMarker(nodeDict, function (d) { return iconNew }, router))
|
||||||
|
|
||||||
|
var markersLost = lostnodes.filter(has_location)
|
||||||
|
.map(mkMarker(nodeDict, function (d) {
|
||||||
|
if (d.lastseen.isAfter(moment(now).subtract(3, 'days')))
|
||||||
|
return iconAlert
|
||||||
|
|
||||||
|
return iconLost
|
||||||
|
}, router))
|
||||||
|
|
||||||
|
groupOffline = L.featureGroup(markersOffline).addTo(map)
|
||||||
|
groupOnline = L.featureGroup(markersOnline).addTo(map)
|
||||||
|
groupNew = L.featureGroup(markersNew).addTo(map)
|
||||||
|
groupLost = L.featureGroup(markersLost).addTo(map)
|
||||||
|
|
||||||
resetView()
|
resetView()
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetView() {
|
function resetView() {
|
||||||
resetMarkerStyles(nodeDict, linkDict)
|
resetMarkerStyles(nodeDict, linkDict)
|
||||||
|
|
||||||
var bounds = group.getBounds()
|
var bounds = L.latLngBounds([])
|
||||||
|
bounds.extend(groupNew.getBounds())
|
||||||
|
bounds.extend(groupLost.getBounds())
|
||||||
|
|
||||||
if (!bounds.isValid())
|
if (!bounds.isValid())
|
||||||
bounds = groupOnline.getBounds()
|
bounds.extend(groupOnline.getBounds())
|
||||||
|
|
||||||
|
if (!bounds.isValid())
|
||||||
|
bounds.extend(groupOffline.getBounds())
|
||||||
|
|
||||||
if (bounds.isValid())
|
if (bounds.isValid())
|
||||||
setView(bounds)
|
setView(bounds)
|
||||||
|
Loading…
Reference in New Issue
Block a user