|
@@ -1,309 +1,408 @@
|
|
|
-define(["d3", "leaflet", "moment", "locationmarker", "leaflet.label"],
|
|
|
- function (d3, L, moment, LocationMarker) {
|
|
|
- var options = { worldCopyJump: true,
|
|
|
- zoomControl: false
|
|
|
- }
|
|
|
+define(["map/clientlayer", "map/labelslayer",
|
|
|
+ "d3", "leaflet", "moment", "locationmarker", "rbush",
|
|
|
+ "leaflet.label", "leaflet.providers"],
|
|
|
+ function (ClientLayer, LabelsLayer, d3, L, moment, LocationMarker, rbush) {
|
|
|
+ var options = { worldCopyJump: true,
|
|
|
+ zoomControl: false
|
|
|
+ }
|
|
|
|
|
|
- var LocateButton = L.Control.extend({
|
|
|
- options: {
|
|
|
- position: "bottomright"
|
|
|
- },
|
|
|
+ var AddLayerButton = L.Control.extend({
|
|
|
+ options: {
|
|
|
+ position: "bottomright"
|
|
|
+ },
|
|
|
|
|
|
- active: false,
|
|
|
- button: undefined,
|
|
|
+ initialize: function (f, options) {
|
|
|
+ L.Util.setOptions(this, options)
|
|
|
+ this.f = f
|
|
|
+ },
|
|
|
|
|
|
- initialize: function (f, options) {
|
|
|
- L.Util.setOptions(this, options)
|
|
|
- this.f = f
|
|
|
- },
|
|
|
+ onAdd: function () {
|
|
|
+ var button = L.DomUtil.create("button", "add-layer")
|
|
|
|
|
|
- onAdd: function () {
|
|
|
- var button = L.DomUtil.create("button", "locate-user")
|
|
|
+ L.DomEvent.disableClickPropagation(button)
|
|
|
+ L.DomEvent.addListener(button, "click", this.f, this)
|
|
|
|
|
|
- L.DomEvent.disableClickPropagation(button)
|
|
|
- L.DomEvent.addListener(button, "click", this.onClick, this)
|
|
|
+ this.button = button
|
|
|
|
|
|
- this.button = button
|
|
|
+ return button
|
|
|
+ }
|
|
|
+ })
|
|
|
|
|
|
- return button
|
|
|
- },
|
|
|
+ var LocateButton = L.Control.extend({
|
|
|
+ options: {
|
|
|
+ position: "bottomright"
|
|
|
+ },
|
|
|
|
|
|
- update: function() {
|
|
|
- this.button.classList.toggle("active", this.active)
|
|
|
- },
|
|
|
+ active: false,
|
|
|
+ button: undefined,
|
|
|
|
|
|
- set: function(v) {
|
|
|
- this.active = v
|
|
|
- this.update()
|
|
|
- },
|
|
|
+ initialize: function (f, options) {
|
|
|
+ L.Util.setOptions(this, options)
|
|
|
+ this.f = f
|
|
|
+ },
|
|
|
|
|
|
- onClick: function () {
|
|
|
- this.f(!this.active)
|
|
|
- }
|
|
|
- })
|
|
|
+ onAdd: function () {
|
|
|
+ var button = L.DomUtil.create("button", "locate-user")
|
|
|
|
|
|
- function mkMarker(dict, iconFunc, router) {
|
|
|
- return function (d) {
|
|
|
- var m = L.circleMarker([d.nodeinfo.location.latitude, d.nodeinfo.location.longitude], iconFunc(d))
|
|
|
+ L.DomEvent.disableClickPropagation(button)
|
|
|
+ L.DomEvent.addListener(button, "click", this.onClick, this)
|
|
|
|
|
|
- m.resetStyle = function () {
|
|
|
- m.setStyle(iconFunc(d))
|
|
|
- }
|
|
|
+ this.button = button
|
|
|
|
|
|
- m.on("click", router.node(d))
|
|
|
- m.bindLabel(d.nodeinfo.hostname)
|
|
|
+ return button
|
|
|
+ },
|
|
|
|
|
|
- dict[d.nodeinfo.node_id] = m
|
|
|
+ update: function() {
|
|
|
+ this.button.classList.toggle("active", this.active)
|
|
|
+ },
|
|
|
|
|
|
- return m
|
|
|
- }
|
|
|
- }
|
|
|
+ set: function(v) {
|
|
|
+ this.active = v
|
|
|
+ this.update()
|
|
|
+ },
|
|
|
|
|
|
- function addLinksToMap(dict, linkScale, graph, router) {
|
|
|
- graph = graph.filter( function (d) {
|
|
|
- return "distance" in d && !d.vpn
|
|
|
- })
|
|
|
+ onClick: function () {
|
|
|
+ this.f(!this.active)
|
|
|
+ }
|
|
|
+ })
|
|
|
|
|
|
- var lines = graph.map( function (d) {
|
|
|
- var opts = { color: linkScale(d.tq).hex(),
|
|
|
- weight: 4,
|
|
|
- opacity: 0.5,
|
|
|
- dashArray: "none"
|
|
|
- }
|
|
|
+ function mkMarker(dict, iconFunc, router) {
|
|
|
+ return function (d) {
|
|
|
+ var m = L.circleMarker([d.nodeinfo.location.latitude, d.nodeinfo.location.longitude], iconFunc(d))
|
|
|
|
|
|
- var line = L.polyline(d.latlngs, opts)
|
|
|
+ m.resetStyle = function () {
|
|
|
+ m.setStyle(iconFunc(d))
|
|
|
+ }
|
|
|
|
|
|
- line.resetStyle = function () {
|
|
|
- line.setStyle(opts)
|
|
|
- }
|
|
|
+ m.on("click", router.node(d))
|
|
|
+ m.bindLabel(d.nodeinfo.hostname)
|
|
|
|
|
|
- line.bindLabel(d.source.node.nodeinfo.hostname + " – " + d.target.node.nodeinfo.hostname + "<br><strong>" + showDistance(d) + " / " + showTq(d) + "</strong>")
|
|
|
- line.on("click", router.link(d))
|
|
|
+ dict[d.nodeinfo.node_id] = m
|
|
|
|
|
|
- dict[d.id] = line
|
|
|
+ return m
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- return line
|
|
|
- })
|
|
|
+ function addLinksToMap(dict, linkScale, graph, router) {
|
|
|
+ graph = graph.filter( function (d) {
|
|
|
+ return "distance" in d && !d.vpn
|
|
|
+ })
|
|
|
|
|
|
- return lines
|
|
|
- }
|
|
|
+ var lines = graph.map( function (d) {
|
|
|
+ var opts = { color: linkScale(d.tq).hex(),
|
|
|
+ weight: 4,
|
|
|
+ opacity: 0.5,
|
|
|
+ dashArray: "none"
|
|
|
+ }
|
|
|
|
|
|
- var iconOnline = { color: "#1566A9", fillColor: "#1566A9", radius: 6, fillOpacity: 0.5, opacity: 0.5, weight: 2, className: "stroke-first" }
|
|
|
- var iconOffline = { color: "#D43E2A", fillColor: "#D43E2A", radius: 3, fillOpacity: 0.5, opacity: 0.5, weight: 1, className: "stroke-first" }
|
|
|
- var iconLost = { color: "#D43E2A", fillColor: "#D43E2A", radius: 6, fillOpacity: 0.8, opacity: 0.8, weight: 1, className: "stroke-first" }
|
|
|
- var iconAlert = { color: "#D43E2A", fillColor: "#D43E2A", radius: 6, fillOpacity: 0.8, opacity: 0.8, weight: 2, className: "stroke-first node-alert" }
|
|
|
- var iconNew = { color: "#1566A9", fillColor: "#93E929", radius: 6, fillOpacity: 1.0, opacity: 0.5, weight: 2 }
|
|
|
+ var line = L.polyline(d.latlngs, opts)
|
|
|
|
|
|
- return function (config, linkScale, sidebar, router) {
|
|
|
- var self = this
|
|
|
- var barycenter
|
|
|
- var groupOnline, groupOffline, groupNew, groupLost, groupLines
|
|
|
+ line.resetStyle = function () {
|
|
|
+ line.setStyle(opts)
|
|
|
+ }
|
|
|
|
|
|
- var map, userLocation
|
|
|
+ line.bindLabel(d.source.node.nodeinfo.hostname + " – " + d.target.node.nodeinfo.hostname + "<br><strong>" + showDistance(d) + " / " + showTq(d) + "</strong>")
|
|
|
+ line.on("click", router.link(d))
|
|
|
|
|
|
- var locateUserButton = new LocateButton(function (d) {
|
|
|
- if (d)
|
|
|
- enableTracking()
|
|
|
- else
|
|
|
- disableTracking()
|
|
|
- })
|
|
|
+ dict[d.id] = line
|
|
|
|
|
|
- function enableTracking() {
|
|
|
- map.locate({watch: true,
|
|
|
- enableHighAccuracy: true,
|
|
|
- setView: true
|
|
|
- })
|
|
|
- locateUserButton.set(true)
|
|
|
- }
|
|
|
+ return line
|
|
|
+ })
|
|
|
|
|
|
- function disableTracking() {
|
|
|
- map.stopLocate()
|
|
|
- locationError()
|
|
|
- locateUserButton.set(false)
|
|
|
+ return lines
|
|
|
}
|
|
|
|
|
|
- function locationFound(e) {
|
|
|
- if (!userLocation)
|
|
|
- userLocation = new LocationMarker(e.latlng).addTo(map)
|
|
|
+ var iconOnline = { color: "#1566A9", fillColor: "#1566A9", radius: 6, fillOpacity: 0.5, opacity: 0.5, weight: 2, className: "stroke-first" }
|
|
|
+ var iconOffline = { color: "#D43E2A", fillColor: "#D43E2A", radius: 3, fillOpacity: 0.5, opacity: 0.5, weight: 1, className: "stroke-first" }
|
|
|
+ var iconLost = { color: "#D43E2A", fillColor: "#D43E2A", radius: 6, fillOpacity: 0.8, opacity: 0.8, weight: 1, className: "stroke-first" }
|
|
|
+ var iconAlert = { color: "#D43E2A", fillColor: "#D43E2A", radius: 6, fillOpacity: 0.8, opacity: 0.8, weight: 2, className: "stroke-first node-alert" }
|
|
|
+ var iconNew = { color: "#1566A9", fillColor: "#93E929", radius: 6, fillOpacity: 1.0, opacity: 0.5, weight: 2 }
|
|
|
+
|
|
|
+ return function (config, linkScale, sidebar, router) {
|
|
|
+ var self = this
|
|
|
+ var barycenter
|
|
|
+ var groupOnline, groupOffline, groupNew, groupLost, groupLines
|
|
|
+ var savedView
|
|
|
+
|
|
|
+ var map, userLocation
|
|
|
+ var layerControl
|
|
|
+ var customLayers = new Set()
|
|
|
+
|
|
|
+ var locateUserButton = new LocateButton(function (d) {
|
|
|
+ if (d)
|
|
|
+ enableTracking()
|
|
|
+ else
|
|
|
+ disableTracking()
|
|
|
+ })
|
|
|
|
|
|
- userLocation.setLatLng(e.latlng)
|
|
|
- userLocation.setAccuracy(e.accuracy)
|
|
|
- }
|
|
|
+ function saveView() {
|
|
|
+ savedView = {center: map.getCenter(),
|
|
|
+ zoom: map.getZoom()}
|
|
|
+ }
|
|
|
|
|
|
- function locationError() {
|
|
|
- if (userLocation) {
|
|
|
- map.removeLayer(userLocation)
|
|
|
- userLocation = null
|
|
|
+ function enableTracking() {
|
|
|
+ map.locate({watch: true,
|
|
|
+ enableHighAccuracy: true,
|
|
|
+ setView: true
|
|
|
+ })
|
|
|
+ locateUserButton.set(true)
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- var el = document.createElement("div")
|
|
|
- el.classList.add("map")
|
|
|
- self.div = el
|
|
|
+ function disableTracking() {
|
|
|
+ map.stopLocate()
|
|
|
+ locationError()
|
|
|
+ locateUserButton.set(false)
|
|
|
+ }
|
|
|
|
|
|
- map = L.map(el, options)
|
|
|
+ function locationFound(e) {
|
|
|
+ if (!userLocation)
|
|
|
+ userLocation = new LocationMarker(e.latlng).addTo(map)
|
|
|
|
|
|
- L.tileLayer("https://otile{s}-s.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.jpg", {
|
|
|
- subdomains: "1234",
|
|
|
- type: "osm",
|
|
|
- attribution: "Tiles © <a href=\"https://www.mapquest.com/\" target=\"_blank\">MapQuest</a>, Data CC-BY-SA OpenStreetMap",
|
|
|
- maxZoom: 18
|
|
|
- }).addTo(map)
|
|
|
+ userLocation.setLatLng(e.latlng)
|
|
|
+ userLocation.setAccuracy(e.accuracy)
|
|
|
+ }
|
|
|
|
|
|
- map.on("locationfound", locationFound)
|
|
|
- map.on("locationerror", locationError)
|
|
|
+ function locationError() {
|
|
|
+ if (userLocation) {
|
|
|
+ map.removeLayer(userLocation)
|
|
|
+ userLocation = null
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- map.addControl(locateUserButton)
|
|
|
+ function addLayer(layerName) {
|
|
|
+ if (customLayers.has(layerName))
|
|
|
+ return
|
|
|
|
|
|
- var nodeDict = {}
|
|
|
- var linkDict = {}
|
|
|
- var highlight
|
|
|
+ try {
|
|
|
+ var layer = L.tileLayer.provider(layerName)
|
|
|
+ layerControl.addBaseLayer(layer, layerName)
|
|
|
+ customLayers.add(layerName)
|
|
|
|
|
|
- function resetMarkerStyles(nodes, links) {
|
|
|
- Object.keys(nodes).forEach( function (d) {
|
|
|
- nodes[d].resetStyle()
|
|
|
- })
|
|
|
+ if (!layerControl.added) {
|
|
|
+ layerControl.addTo(map)
|
|
|
+ layerControl.added = true
|
|
|
+ }
|
|
|
|
|
|
- Object.keys(links).forEach( function (d) {
|
|
|
- links[d].resetStyle()
|
|
|
- })
|
|
|
- }
|
|
|
+ if (localStorageTest())
|
|
|
+ localStorage.setItem("map/customLayers", JSON.stringify(Array.from(customLayers)))
|
|
|
+ } catch (e) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- function setView(bounds) {
|
|
|
- map.fitBounds(bounds, {paddingTopLeft: [sidebar.getWidth(), 0]})
|
|
|
- }
|
|
|
+ var el = document.createElement("div")
|
|
|
+ el.classList.add("map")
|
|
|
+ self.div = el
|
|
|
|
|
|
- function resetZoom() {
|
|
|
- setView(barycenter.getBounds())
|
|
|
- }
|
|
|
+ map = L.map(el, options)
|
|
|
|
|
|
- function goto(m) {
|
|
|
- var bounds
|
|
|
+ var baseLayer = L.tileLayer("https://otile{s}-s.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.jpg", {
|
|
|
+ subdomains: "1234",
|
|
|
+ type: "osm",
|
|
|
+ attribution: "Tiles © <a href=\"https://www.mapquest.com/\" target=\"_blank\">MapQuest</a>, Data CC-BY-SA OpenStreetMap",
|
|
|
+ maxZoom: 18
|
|
|
+ }).addTo(map)
|
|
|
|
|
|
- if ("getBounds" in m)
|
|
|
- bounds = m.getBounds()
|
|
|
- else
|
|
|
- bounds = L.latLngBounds([m.getLatLng()])
|
|
|
+ map.on("locationfound", locationFound)
|
|
|
+ map.on("locationerror", locationError)
|
|
|
+ map.on("dragend", saveView)
|
|
|
|
|
|
- setView(bounds)
|
|
|
+ map.addControl(locateUserButton)
|
|
|
|
|
|
- return m
|
|
|
- }
|
|
|
+ map.addControl(new AddLayerButton(function () {
|
|
|
+ /*eslint no-alert:0*/
|
|
|
+ var layerName = prompt("Leaflet Provider:")
|
|
|
+ addLayer(layerName)
|
|
|
+ }))
|
|
|
|
|
|
- function updateView(nopanzoom) {
|
|
|
- resetMarkerStyles(nodeDict, linkDict)
|
|
|
- var m
|
|
|
+ layerControl = L.control.layers({"MapQuest": baseLayer}, [], {position: "bottomright"})
|
|
|
|
|
|
- if (highlight !== undefined)
|
|
|
- if (highlight.type === "node") {
|
|
|
- m = nodeDict[highlight.o.nodeinfo.node_id]
|
|
|
+ if (localStorageTest()) {
|
|
|
+ var layers = JSON.parse(localStorage.getItem("map/customLayers"))
|
|
|
|
|
|
- if (m)
|
|
|
- m.setStyle({ color: "orange", weight: 20, fillOpacity: 1, opacity: 0.7, className: "stroke-first" })
|
|
|
- } else if (highlight.type === "link") {
|
|
|
- m = linkDict[highlight.o.id]
|
|
|
+ if (layers)
|
|
|
+ layers.forEach(addLayer)
|
|
|
+ }
|
|
|
|
|
|
- if (m)
|
|
|
- m.setStyle({ weight: 7, opacity: 1, dashArray: "10, 10" })
|
|
|
- }
|
|
|
+ var clientLayer = new ClientLayer()
|
|
|
+ clientLayer.addTo(map)
|
|
|
+ clientLayer.setZIndex(5)
|
|
|
+
|
|
|
+ var labelsLayer = new LabelsLayer()
|
|
|
+ labelsLayer.addTo(map)
|
|
|
+ labelsLayer.setZIndex(6)
|
|
|
+
|
|
|
+ var nodeDict = {}
|
|
|
+ var linkDict = {}
|
|
|
+ var highlight
|
|
|
|
|
|
- if (!nopanzoom)
|
|
|
- if (m)
|
|
|
- goto(m)
|
|
|
+ function resetMarkerStyles(nodes, links) {
|
|
|
+ Object.keys(nodes).forEach( function (d) {
|
|
|
+ nodes[d].resetStyle()
|
|
|
+ })
|
|
|
+
|
|
|
+ Object.keys(links).forEach( function (d) {
|
|
|
+ links[d].resetStyle()
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ function setView(bounds) {
|
|
|
+ map.fitBounds(bounds, {paddingTopLeft: [sidebar.getWidth(), 0]})
|
|
|
+ }
|
|
|
+
|
|
|
+ function resetZoom() {
|
|
|
+ setView(barycenter.getBounds())
|
|
|
+ }
|
|
|
+
|
|
|
+ function goto(m) {
|
|
|
+ var bounds
|
|
|
+
|
|
|
+ if ("getBounds" in m)
|
|
|
+ bounds = m.getBounds()
|
|
|
else
|
|
|
- resetZoom()
|
|
|
- }
|
|
|
+ bounds = L.latLngBounds([m.getLatLng()])
|
|
|
|
|
|
- function calcBarycenter(nodes) {
|
|
|
- nodes = nodes.map(function (d) { return d.nodeinfo.location })
|
|
|
- var lats = nodes.map(function (d) { return d.latitude })
|
|
|
- var lngs = nodes.map(function (d) { return d.longitude })
|
|
|
+ setView(bounds)
|
|
|
|
|
|
- var barycenter = L.latLng(d3.median(lats), d3.median(lngs))
|
|
|
- var barycenterDev = [d3.deviation(lats), d3.deviation(lngs)]
|
|
|
+ return m
|
|
|
+ }
|
|
|
|
|
|
- var barycenterCircle = L.latLng(barycenter.lat + barycenterDev[0],
|
|
|
- barycenter.lng + barycenterDev[1])
|
|
|
+ function updateView(nopanzoom) {
|
|
|
+ resetMarkerStyles(nodeDict, linkDict)
|
|
|
+ var m
|
|
|
|
|
|
- var r = barycenter.distanceTo(barycenterCircle)
|
|
|
+ if (highlight !== undefined)
|
|
|
+ if (highlight.type === "node") {
|
|
|
+ m = nodeDict[highlight.o.nodeinfo.node_id]
|
|
|
|
|
|
- return L.circle(barycenter, r * config.mapSigmaScale)
|
|
|
- }
|
|
|
+ if (m)
|
|
|
+ m.setStyle({ color: "orange", weight: 20, fillOpacity: 1, opacity: 0.7, className: "stroke-first" })
|
|
|
+ } else if (highlight.type === "link") {
|
|
|
+ m = linkDict[highlight.o.id]
|
|
|
+
|
|
|
+ if (m)
|
|
|
+ m.setStyle({ weight: 7, opacity: 1, dashArray: "10, 10" })
|
|
|
+ }
|
|
|
|
|
|
- self.setData = function (data) {
|
|
|
- nodeDict = {}
|
|
|
- linkDict = {}
|
|
|
+ if (!nopanzoom)
|
|
|
+ if (m)
|
|
|
+ goto(m)
|
|
|
+ else if (savedView)
|
|
|
+ map.setView(savedView.center, savedView.zoom)
|
|
|
+ else
|
|
|
+ resetZoom()
|
|
|
+ }
|
|
|
|
|
|
- if (groupOffline)
|
|
|
- groupOffline.clearLayers()
|
|
|
+ function calcBarycenter(nodes) {
|
|
|
+ nodes = nodes.map(function (d) { return d.nodeinfo.location })
|
|
|
+ var lats = nodes.map(function (d) { return d.latitude })
|
|
|
+ var lngs = nodes.map(function (d) { return d.longitude })
|
|
|
|
|
|
- if (groupOnline)
|
|
|
- groupOnline.clearLayers()
|
|
|
+ var barycenter = L.latLng(d3.median(lats), d3.median(lngs))
|
|
|
+ var barycenterDev = [d3.deviation(lats), d3.deviation(lngs)]
|
|
|
|
|
|
- if (groupNew)
|
|
|
- groupNew.clearLayers()
|
|
|
+ var barycenterCircle = L.latLng(barycenter.lat + barycenterDev[0],
|
|
|
+ barycenter.lng + barycenterDev[1])
|
|
|
|
|
|
- if (groupLost)
|
|
|
- groupLost.clearLayers()
|
|
|
+ var r = barycenter.distanceTo(barycenterCircle)
|
|
|
|
|
|
- if (groupLines)
|
|
|
- groupLines.clearLayers()
|
|
|
+ return L.circle(barycenter, r * config.mapSigmaScale)
|
|
|
+ }
|
|
|
|
|
|
- var lines = addLinksToMap(linkDict, linkScale, data.graph.links, router)
|
|
|
- groupLines = L.featureGroup(lines).addTo(map)
|
|
|
+ function mapRTree(d) {
|
|
|
+ var o = [ d.nodeinfo.location.latitude, d.nodeinfo.location.longitude,
|
|
|
+ d.nodeinfo.location.latitude, d.nodeinfo.location.longitude]
|
|
|
|
|
|
- barycenter = calcBarycenter(data.nodes.all.filter(has_location))
|
|
|
+ o.node = d
|
|
|
|
|
|
- var nodesOnline = subtract(data.nodes.all.filter(online), data.nodes.new)
|
|
|
- var nodesOffline = subtract(data.nodes.all.filter(offline), data.nodes.lost)
|
|
|
+ return o
|
|
|
+ }
|
|
|
|
|
|
- var markersOnline = nodesOnline.filter(has_location)
|
|
|
- .map(mkMarker(nodeDict, function () { return iconOnline }, router))
|
|
|
+ self.setData = function (data) {
|
|
|
+ nodeDict = {}
|
|
|
+ linkDict = {}
|
|
|
|
|
|
- var markersOffline = nodesOffline.filter(has_location)
|
|
|
- .map(mkMarker(nodeDict, function () { return iconOffline }, router))
|
|
|
+ if (groupOffline)
|
|
|
+ groupOffline.clearLayers()
|
|
|
|
|
|
- var markersNew = data.nodes.new.filter(has_location)
|
|
|
- .map(mkMarker(nodeDict, function () { return iconNew }, router))
|
|
|
+ if (groupOnline)
|
|
|
+ groupOnline.clearLayers()
|
|
|
|
|
|
- var markersLost = data.nodes.lost.filter(has_location)
|
|
|
- .map(mkMarker(nodeDict, function (d) {
|
|
|
- if (d.lastseen.isAfter(moment(data.now).subtract(3, "days")))
|
|
|
- return iconAlert
|
|
|
+ if (groupNew)
|
|
|
+ groupNew.clearLayers()
|
|
|
|
|
|
- return iconLost
|
|
|
- }, router))
|
|
|
+ if (groupLost)
|
|
|
+ groupLost.clearLayers()
|
|
|
|
|
|
- groupOffline = L.featureGroup(markersOffline).addTo(map)
|
|
|
- groupOnline = L.featureGroup(markersOnline).addTo(map)
|
|
|
- groupNew = L.featureGroup(markersNew).addTo(map)
|
|
|
- groupLost = L.featureGroup(markersLost).addTo(map)
|
|
|
+ if (groupLines)
|
|
|
+ groupLines.clearLayers()
|
|
|
|
|
|
- updateView(true)
|
|
|
- }
|
|
|
+ var lines = addLinksToMap(linkDict, linkScale, data.graph.links, router)
|
|
|
+ groupLines = L.featureGroup(lines).addTo(map)
|
|
|
|
|
|
- self.resetView = function () {
|
|
|
- disableTracking()
|
|
|
- highlight = undefined
|
|
|
- updateView()
|
|
|
- }
|
|
|
+ barycenter = calcBarycenter(data.nodes.all.filter(has_location))
|
|
|
|
|
|
- self.gotoNode = function (d) {
|
|
|
- disableTracking()
|
|
|
- highlight = {type: "node", o: d}
|
|
|
- updateView()
|
|
|
- }
|
|
|
+ var nodesOnline = subtract(data.nodes.all.filter(online), data.nodes.new)
|
|
|
+ var nodesOffline = subtract(data.nodes.all.filter(offline), data.nodes.lost)
|
|
|
|
|
|
- self.gotoLink = function (d) {
|
|
|
- disableTracking()
|
|
|
- highlight = {type: "link", o: d}
|
|
|
- updateView()
|
|
|
- }
|
|
|
+ var markersOnline = nodesOnline.filter(has_location)
|
|
|
+ .map(mkMarker(nodeDict, function () { return iconOnline }, router))
|
|
|
|
|
|
- self.destroy = function () {
|
|
|
- map.remove()
|
|
|
- }
|
|
|
+ var markersOffline = nodesOffline.filter(has_location)
|
|
|
+ .map(mkMarker(nodeDict, function () { return iconOffline }, router))
|
|
|
+
|
|
|
+ var markersNew = data.nodes.new.filter(has_location)
|
|
|
+ .map(mkMarker(nodeDict, function () { return iconNew }, router))
|
|
|
|
|
|
- return self
|
|
|
- }
|
|
|
+ var markersLost = data.nodes.lost.filter(has_location)
|
|
|
+ .map(mkMarker(nodeDict, function (d) {
|
|
|
+ if (d.lastseen.isAfter(moment(data.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 rtreeOnlineAll = rbush(9)
|
|
|
+
|
|
|
+ rtreeOnlineAll.load(data.nodes.all.filter(online).filter(has_location).map(mapRTree))
|
|
|
+
|
|
|
+ clientLayer.setData(rtreeOnlineAll)
|
|
|
+ labelsLayer.setData({online: nodesOnline.filter(has_location),
|
|
|
+ offline: nodesOffline.filter(has_location),
|
|
|
+ new: data.nodes.new.filter(has_location),
|
|
|
+ lost: data.nodes.lost.filter(has_location)
|
|
|
+ })
|
|
|
+
|
|
|
+ updateView(true)
|
|
|
+ }
|
|
|
+
|
|
|
+ self.resetView = function () {
|
|
|
+ disableTracking()
|
|
|
+ highlight = undefined
|
|
|
+ updateView()
|
|
|
+ }
|
|
|
+
|
|
|
+ self.gotoNode = function (d) {
|
|
|
+ disableTracking()
|
|
|
+ highlight = {type: "node", o: d}
|
|
|
+ updateView()
|
|
|
+ }
|
|
|
+
|
|
|
+ self.gotoLink = function (d) {
|
|
|
+ disableTracking()
|
|
|
+ highlight = {type: "link", o: d}
|
|
|
+ updateView()
|
|
|
+ }
|
|
|
+
|
|
|
+ self.destroy = function () {
|
|
|
+ map.remove()
|
|
|
+ }
|
|
|
+
|
|
|
+ return self
|
|
|
+ }
|
|
|
})
|