diff --git a/lib/container.js b/lib/container.js index 41129d1..914eecb 100644 --- a/lib/container.js +++ b/lib/container.js @@ -7,7 +7,6 @@ define([], function () { } var self = this; - var container = document.createElement(tag); self.add = function add(d) { diff --git a/lib/main.js b/lib/main.js index 10bca3d..9b53526 100644 --- a/lib/main.js +++ b/lib/main.js @@ -84,53 +84,46 @@ define(['polyglot', 'moment', 'router', 'leaflet', 'gui', 'helper', 'language'], return d.target !== undefined; }); - links.forEach(function (d) { - var unknown = (d.source.node === undefined); - var ids; - if (unknown) { - ids = [d.source.id.replace(/:/g, ''), d.target.node.nodeinfo.node_id]; - } else { - ids = [d.source.node.nodeinfo.node_id, d.target.node.nodeinfo.node_id]; - } - d.id = ids.join('-'); - - if (unknown || !d.source.node.nodeinfo.location || !d.target.node.nodeinfo.location || - isNaN(d.source.node.nodeinfo.location.latitude) || - isNaN(d.source.node.nodeinfo.location.longitude) || - isNaN(d.target.node.nodeinfo.location.latitude) || - isNaN(d.target.node.nodeinfo.location.longitude)) { - return; - } - - d.latlngs = []; - d.latlngs.push(L.latLng(d.source.node.nodeinfo.location.latitude, d.source.node.nodeinfo.location.longitude)); - d.latlngs.push(L.latLng(d.target.node.nodeinfo.location.latitude, d.target.node.nodeinfo.location.longitude)); - - d.distance = d.latlngs[0].distanceTo(d.latlngs[1]); - }); - nodes.forEach(function (d) { d.neighbours = []; }); links.forEach(function (d) { - if (d.target.node.flags.gateway === true || (d.source.node !== undefined && d.source.node.flags.gateway === true)) { - d.type = 'fastd'; - } else { - d.type = 'N/A'; - } var unknown = (d.source.node === undefined); + var ids; + if (unknown) { d.target.node.neighbours.push({ id: d.source.id, link: d, incoming: true }); - return; + ids = [d.source.id.replace(/:/g, ''), d.target.node.nodeinfo.node_id]; + } else { + if (d.target.node.flags.gateway === true || d.source.node.flags.gateway === true) { + d.type = 'fastd'; + } else { + d.type = 'N/A'; + } + + ids = [d.source.node.nodeinfo.node_id, d.target.node.nodeinfo.node_id]; + d.source.node.neighbours.push({ node: d.target.node, link: d, incoming: false }); + d.target.node.neighbours.push({ node: d.source.node, link: d, incoming: true }); + if (d.type !== 'fastd' && d.type !== 'L2TP') { + d.source.node.meshlinks = d.source.node.meshlinks ? d.source.node.meshlinks + 1 : 1; + } } - d.source.node.neighbours.push({ node: d.target.node, link: d, incoming: false }); - d.target.node.neighbours.push({ node: d.source.node, link: d, incoming: true }); - if (d.type !== 'fastd' && d.type !== 'L2TP') { - d.source.node.meshlinks = d.source.node.meshlinks ? d.source.node.meshlinks + 1 : 1; + + d.id = ids.join('-'); + + try { + d.latlngs = []; + d.latlngs.push(L.latLng(d.source.node.nodeinfo.location.latitude, d.source.node.nodeinfo.location.longitude)); + d.latlngs.push(L.latLng(d.target.node.nodeinfo.location.latitude, d.target.node.nodeinfo.location.longitude)); + + d.distance = d.latlngs[0].distanceTo(d.latlngs[1]); + } catch (e) { + // ignore exception } }); + links.sort(function (a, b) { return b.tq - a.tq; }); diff --git a/lib/map.js b/lib/map.js index 5690703..e37101d 100644 --- a/lib/map.js +++ b/lib/map.js @@ -368,18 +368,12 @@ define(['map/clientlayer', 'map/labelslayer', var m; if (highlight !== undefined) { - if (highlight.type === 'node') { + if (highlight.type === 'node' && nodeDict[highlight.o.nodeinfo.node_id]) { m = nodeDict[highlight.o.nodeinfo.node_id]; - - if (m) { - m.setStyle({ color: 'orange', weight: 20, fillOpacity: 1, opacity: 0.7, className: 'stroke-first' }); - } - } else if (highlight.type === 'link') { + m.setStyle({ color: 'orange', weight: 20, fillOpacity: 1, opacity: 0.7, className: 'stroke-first' }); + } else if (highlight.type === 'link' && linkDict[highlight.o.id]) { m = linkDict[highlight.o.id]; - - if (m) { - m.setStyle({ weight: 4, opacity: 1, dashArray: '5, 10' }); - } + m.setStyle({ weight: 4, opacity: 1, dashArray: '5, 10' }); } } @@ -395,12 +389,11 @@ define(['map/clientlayer', 'map/labelslayer', } function mapRTree(d) { - var o = { minX: d.nodeinfo.location.latitude, minY: d.nodeinfo.location.longitude, - maxX: d.nodeinfo.location.latitude, maxY: d.nodeinfo.location.longitude }; - - o.node = d; - - return o; + return { + minX: d.nodeinfo.location.latitude, minY: d.nodeinfo.location.longitude, + maxX: d.nodeinfo.location.latitude, maxY: d.nodeinfo.location.longitude, + node: d + }; } self.setData = function setData(data) { diff --git a/lib/map/clientlayer.js b/lib/map/clientlayer.js index 2cdb718..c1deb08 100644 --- a/lib/map/clientlayer.js +++ b/lib/map/clientlayer.js @@ -31,8 +31,6 @@ define(['leaflet', 'helper'], } var ctx = canvas.getContext('2d'); - - var startDistance = 12; ctx.beginPath(); diff --git a/lib/map/labelslayer.js b/lib/map/labelslayer.js index 3d03471..649ba86 100644 --- a/lib/map/labelslayer.js +++ b/lib/map/labelslayer.js @@ -22,11 +22,7 @@ define(['leaflet', 'rbush', 'helper'], } function mapRTree(d) { - var o = { minX: d.position.lat, minY: d.position.lng, maxX: d.position.lat, maxY: d.position.lng }; - - o.label = d; - - return o; + return { minX: d.position.lat, minY: d.position.lng, maxX: d.position.lat, maxY: d.position.lng, label: d }; } function prepareLabel(fillStyle, fontSize, offset, stroke) { diff --git a/lib/router.js b/lib/router.js index 5f8c9f7..70fd75b 100644 --- a/lib/router.js +++ b/lib/router.js @@ -63,21 +63,6 @@ define(['helper'], function (helper) { return true; } - function gotoLocation(d) { - if (!d) { - return false; - } - - targets.forEach(function (t) { - if (!t.gotoLocation) { - console.warn('has no gotoLocation', t); - } - t.gotoLocation(d); - }); - - return true; - } - function loadState(s, update) { if (!s) { return false; @@ -202,7 +187,20 @@ define(['helper'], function (helper) { }; }; - self.gotoLocation = gotoLocation; + self.gotoLocation = function gotoLocation(d) { + if (!d) { + return false; + } + + targets.forEach(function (t) { + if (!t.gotoLocation) { + console.warn('has no gotoLocation', t); + } + t.gotoLocation(d); + }); + + return true; + }; self.reset = function reset() { resetView();