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 map = new Map()
var sidebar = mkSidebar(document.body)
var map = new Map(sidebar)
document.body.insertBefore(map.div, document.body.firstChild)
var sidebar = mkSidebar(document.body)
var infobox = new Infobox(sidebar)
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 })
})
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)
mkNodesList(sidebar, config.showContact, "firstseen", gotoAnything.node, "Neue Knoten", newnodes)
@ -601,15 +602,16 @@ require(["map"], function (Map) {
}
function gotoBuilder(config, infobox, nodes, links) {
var markers = {}
var targets = []
var self = this
function gotoNode(d, showMap, push) {
showMap = trueDefault(showMap)
push = trueDefault(push)
if (showMap && d.nodeinfo.node_id in markers)
markers[d.nodeinfo.node_id]()
targets.forEach( function (t) {
t.gotoNode(d)
})
nodes(config, infobox, self, d)
@ -623,8 +625,9 @@ require(["map"], function (Map) {
showMap = trueDefault(showMap)
push = trueDefault(push)
if (showMap && linkId(d) in markers)
markers[linkId(d)]()
targets.forEach( function (t) {
t.gotoLink(d)
})
links(config, infobox, self, d)
@ -634,15 +637,12 @@ require(["map"], function (Map) {
return false
}
function addMarkers(d) {
markers = d
}
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.addMarkers = function (d) {
markers = d
}
this.addTarget = function (d) { targets.push(d) }
return this
}

View File

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