diff --git a/lib/main.js b/lib/main.js index 4ccbf53..2a58676 100644 --- a/lib/main.js +++ b/lib/main.js @@ -66,8 +66,6 @@ function (Router, Map, Sidebar, Tabs, Container, Meshstats, Linklist, Nodelist, var newnodes = limit("firstseen", age, sortByKey("firstseen", nodes).filter(online)) var lostnodes = limit("lastseen", age, sortByKey("lastseen", nodes).filter(offline)) - var onlinenodes = nodes.filter(online) - var graph = data[1].batadv 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 }) }) - map.setData(now, newnodes, lostnodes, onlinenodes, links) + map.setData(now, nodes, links, newnodes, lostnodes) meshstats.setData(nodes) nodelist.setData(now, nodes) linklist.setData(links) diff --git a/lib/map.js b/lib/map.js index 9569229..38ebbd3 100644 --- a/lib/map.js +++ b/lib/map.js @@ -49,11 +49,12 @@ define(function () { } 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 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) { 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", { subdomains: "1234", type: "osm", - attribution: "Map data Tiles © MapQuest , Map data © OpenStreetMap contributors, CC-BY-SA", + attribution: "Tiles © MapQuest, Data CC-BY-SA OpenStreetMap", maxZoom: 18 }).addTo(map) var nodeDict = {} var linkDict = {} - self.setData = function (now, newnodes, lostnodes, onlinenodes, links) { + self.setData = function (now, nodes, links, newnodes, lostnodes) { nodeDict = {} linkDict = {} 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) { - if (d.flags.online) - return iconNew + var markersOnline = nodesOnline.filter(has_location) + .map(mkMarker(nodeDict, function (d) { return iconOnline }, router)) - if (d.lastseen.isAfter(moment(now).subtract(1, 'days'))) - return iconAlert + var markersOffline = nodesOffline.filter(has_location) + .map(mkMarker(nodeDict, function (d) { return iconOffline }, router)) - return iconOffline - }, router)) + var markersNew = newnodes.filter(has_location) + .map(mkMarker(nodeDict, function (d) { return iconNew }, router)) - var onlinemarkers = subtract(onlinenodes.filter(has_location), newnodes) - .map(mkMarker(nodeDict, function (d) { return iconOnline }, 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) - var groupLines = L.featureGroup(lines).addTo(map) - groupOnline = L.featureGroup(onlinemarkers).addTo(map) - group = L.featureGroup(markers).addTo(map) resetView() } function resetView() { resetMarkerStyles(nodeDict, linkDict) - var bounds = group.getBounds() + var bounds = L.latLngBounds([]) + bounds.extend(groupNew.getBounds()) + bounds.extend(groupLost.getBounds()) if (!bounds.isValid()) - bounds = groupOnline.getBounds() + bounds.extend(groupOnline.getBounds()) + + if (!bounds.isValid()) + bounds.extend(groupOffline.getBounds()) if (bounds.isValid()) setView(bounds)