introduce gotoTargets on map

This commit is contained in:
Nils Schneider 2015-03-25 01:16:15 +01:00
parent 8184e5f625
commit 0c74ddec8f
2 changed files with 47 additions and 34 deletions

View File

@ -7,10 +7,11 @@ require(["map"], function (Map) {
var linkScale = chroma.scale(chroma.interpolate.bezier(['green', 'yellow', 'red'])).domain([1, 5]) var linkScale = chroma.scale(chroma.interpolate.bezier(['green', 'yellow', 'red'])).domain([1, 5])
var map = new Map() var sidebar = mkSidebar(document.body)
var map = new Map(sidebar)
document.body.insertBefore(map.div, document.body.firstChild) document.body.insertBefore(map.div, document.body.firstChild)
var sidebar = mkSidebar(document.body)
var infobox = new Infobox(sidebar) var infobox = new Infobox(sidebar)
var gotoAnything = new gotoBuilder(config, infobox, showNodeinfo, showLinkinfo) var gotoAnything = new gotoBuilder(config, infobox, showNodeinfo, showLinkinfo)
@ -89,9 +90,9 @@ require(["map"], function (Map) {
d.target.node.neighbours.push({ node: d.source.node, link: d }) d.target.node.neighbours.push({ node: d.source.node, link: d })
}) })
var markers = map.setData(linkScale, sidebar, now, newnodes, lostnodes, onlinenodes, links, gotoAnything) map.setData(linkScale, sidebar, now, newnodes, lostnodes, onlinenodes, links, gotoAnything)
gotoAnything.addMarkers(markers) gotoAnything.addTarget(map)
showMeshstats(sidebar, nodes) showMeshstats(sidebar, nodes)
mkNodesList(sidebar, config.showContact, "firstseen", gotoAnything.node, "Neue Knoten", newnodes) mkNodesList(sidebar, config.showContact, "firstseen", gotoAnything.node, "Neue Knoten", newnodes)
@ -601,15 +602,16 @@ require(["map"], function (Map) {
} }
function gotoBuilder(config, infobox, nodes, links) { function gotoBuilder(config, infobox, nodes, links) {
var markers = {} var targets = []
var self = this var self = this
function gotoNode(d, showMap, push) { function gotoNode(d, showMap, push) {
showMap = trueDefault(showMap) showMap = trueDefault(showMap)
push = trueDefault(push) push = trueDefault(push)
if (showMap && d.nodeinfo.node_id in markers) targets.forEach( function (t) {
markers[d.nodeinfo.node_id]() t.gotoNode(d)
})
nodes(config, infobox, self, d) nodes(config, infobox, self, d)
@ -623,8 +625,9 @@ require(["map"], function (Map) {
showMap = trueDefault(showMap) showMap = trueDefault(showMap)
push = trueDefault(push) push = trueDefault(push)
if (showMap && linkId(d) in markers) targets.forEach( function (t) {
markers[linkId(d)]() t.gotoLink(d)
})
links(config, infobox, self, d) links(config, infobox, self, d)
@ -634,15 +637,12 @@ require(["map"], function (Map) {
return false return false
} }
function addMarkers(d) {
markers = d
}
this.node = function (d, m, p) { return function () { return gotoNode(d, m, p) }} this.node = function (d, m, p) { return function () { return gotoNode(d, m, p) }}
this.link = function (d, m, p) { return function () { return gotoLink(d, m, p) }} this.link = function (d, m, p) { return function () { return gotoLink(d, m, p) }}
this.addMarkers = function (d) { this.addMarkers = function (d) {
markers = d markers = d
} }
this.addTarget = function (d) { targets.push(d) }
return this return this
} }

View File

@ -65,7 +65,7 @@ define(function () {
iconOfflineAlert.className = "node-offline node-alert" iconOfflineAlert.className = "node-offline node-alert"
iconOfflineAlert = L.icon(iconOfflineAlert) iconOfflineAlert = L.icon(iconOfflineAlert)
return function () { return function (sidebar) {
var self = this var self = this
var el = document.createElement("div") var el = document.createElement("div")
@ -83,14 +83,18 @@ define(function () {
maxZoom: 18 maxZoom: 18
}).addTo(map) }).addTo(map)
self.setData = function (linkScale, sidebar, now, newnodes, lostnodes, onlinenodes, links, gotoAnything) { var nodeDict = {}
var markersDict = {} var linkDict = {}
var lines = addLinksToMap(markersDict, linkScale, links, gotoAnything) self.setData = function (linkScale, sidebar, now, newnodes, lostnodes, onlinenodes, links, gotoAnything) {
nodeDict = {}
linkDict = {}
var lines = addLinksToMap(linkDict, linkScale, links, gotoAnything)
var nodes = newnodes.concat(lostnodes).filter(has_location) var nodes = newnodes.concat(lostnodes).filter(has_location)
var markers = nodes.map(mkMarker(markersDict, function (d) { var markers = nodes.map(mkMarker(nodeDict, function (d) {
if (d.flags.online) if (d.flags.online)
return iconNew return iconNew
@ -101,7 +105,7 @@ define(function () {
}, gotoAnything)) }, gotoAnything))
var onlinemarkers = subtract(onlinenodes.filter(has_location), newnodes) var onlinemarkers = subtract(onlinenodes.filter(has_location), newnodes)
.map(mkMarker(markersDict, function (d) { return iconOnline }, gotoAnything)) .map(mkMarker(nodeDict, function (d) { return iconOnline }, gotoAnything))
var groupLines = L.featureGroup(lines).addTo(map) var groupLines = L.featureGroup(lines).addTo(map)
var groupOnline = L.featureGroup(onlinemarkers).addTo(map) var groupOnline = L.featureGroup(onlinemarkers).addTo(map)
@ -113,13 +117,18 @@ define(function () {
bounds = groupOnline.getBounds() bounds = groupOnline.getBounds()
if (bounds.isValid()) if (bounds.isValid())
setView(bounds)
}
function setView(bounds) {
map.fitBounds(bounds, {paddingTopLeft: [sidebar.getWidth(), 0]}) map.fitBounds(bounds, {paddingTopLeft: [sidebar.getWidth(), 0]})
}
var funcDict = {} function goto(dict, id) {
var m = dict[id]
if (m === undefined)
return
Object.keys(markersDict).map( function(k) {
funcDict[k] = function (d) {
var m = markersDict[k]
var bounds var bounds
if ("getBounds" in m) if ("getBounds" in m)
@ -127,12 +136,16 @@ define(function () {
else else
bounds = L.latLngBounds([m.getLatLng()]) bounds = L.latLngBounds([m.getLatLng()])
map.fitBounds(bounds, {paddingTopLeft: [sidebar.getWidth(), 0]}) setView(bounds)
m.openPopup(bounds.getCenter()) m.openPopup(bounds.getCenter())
} }
})
return funcDict self.gotoNode = function (d) {
goto(nodeDict, d.nodeinfo.node_id)
}
self.gotoLink = function (d) {
goto(linkDict, linkId(d))
} }
return self return self