show neighbour info on map
This commit is contained in:
19
src/index.js
19
src/index.js
@ -54,15 +54,26 @@ app.get('/api/v1/nodes', async (req, res) => {
|
||||
// get nodes from db
|
||||
const nodes = await prisma.node.findMany();
|
||||
|
||||
res.json({
|
||||
nodes: nodes.map((node) => {
|
||||
return {
|
||||
const nodesWithNeighbourInfo = [];
|
||||
for(const node of nodes){
|
||||
nodesWithNeighbourInfo.push({
|
||||
...node,
|
||||
node_id_hex: "!" + node.node_id.toString(16),
|
||||
hardware_model_name: HardwareModel.valuesById[node.hardware_model] ?? "UNKNOWN",
|
||||
role_name: Role.valuesById[node.role] ?? "UNKNOWN",
|
||||
}
|
||||
neighbour_info: await prisma.neighbourInfo.findFirst({
|
||||
where: {
|
||||
node_id: node.node_id,
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: 'desc',
|
||||
},
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
res.json({
|
||||
nodes: nodesWithNeighbourInfo,
|
||||
});
|
||||
|
||||
} catch(err) {
|
||||
|
@ -368,6 +368,18 @@
|
||||
|
||||
}
|
||||
|
||||
function findNodeById(id) {
|
||||
|
||||
// find node by id
|
||||
var node = nodes.find((node) => node.node_id.toString() === id.toString());
|
||||
if(node){
|
||||
return node;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
function findNodeMarkerById(id) {
|
||||
|
||||
// find node marker by id
|
||||
@ -557,6 +569,62 @@
|
||||
|
||||
}
|
||||
|
||||
for(var node of updatedNodes){
|
||||
|
||||
// find current node
|
||||
const currentNode = findNodeMarkerById(node.node_id);
|
||||
if(!currentNode){
|
||||
continue;
|
||||
}
|
||||
|
||||
// add node connections
|
||||
const neighbours = node.neighbour_info?.neighbours ?? [];
|
||||
console.log(neighbours);
|
||||
for(const neighbour of neighbours){
|
||||
|
||||
// fixme: skipping zero snr? saw some crazy long neighbours with zero snr...
|
||||
if(neighbour.snr === 0){
|
||||
continue;
|
||||
}
|
||||
|
||||
const neighbourNode = findNodeById(neighbour.node_id);
|
||||
if(!neighbourNode){
|
||||
continue;
|
||||
}
|
||||
|
||||
const neighbourNodeMarker = findNodeMarkerById(neighbour.node_id);
|
||||
if(neighbourNodeMarker){
|
||||
|
||||
const line = L.polyline([
|
||||
currentNode.getLatLng(),
|
||||
neighbourNodeMarker.getLatLng(),
|
||||
], {
|
||||
color: '#2563eb',
|
||||
opacity: 0.5,
|
||||
}).addTo(connectionsLayerGroup);
|
||||
|
||||
const tooltip = `<b>${node.long_name}</b> heard <b>${neighbourNode.long_name}</b>`
|
||||
+ `<br/>SNR: ${neighbour.snr}dB`
|
||||
+ `<br/><br/>ID: ${neighbourNode.node_id} -> ${node.node_id}`
|
||||
+ `<br/>Hex ID: ${neighbourNode.node_id_hex} -> ${node.node_id_hex}`
|
||||
+ `<br/>Updated: ${moment(new Date(node.neighbour_info.updated_at)).fromNow()}`;
|
||||
|
||||
line.bindTooltip(tooltip, {
|
||||
sticky: true,
|
||||
opacity: 1,
|
||||
interactive: true,
|
||||
})
|
||||
.bindPopup(tooltip)
|
||||
.on('click', function(event) {
|
||||
// close tooltip on click to prevent tooltip and popup showing at same time
|
||||
event.target.closeTooltip();
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function setLoading(loading){
|
||||
|
Reference in New Issue
Block a user