introduce gotoTargets on map

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

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