Skip to content

Commit d670ea2

Browse files
fix dynamism on node distance
1 parent 207d53e commit d670ea2

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

nebula/frontend/static/js/monitor/monitor.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -657,8 +657,11 @@ class Monitor {
657657
// Queue the graph update
658658
this.updateGraph();
659659

660-
// Process map updates immediately
661-
this.processUpdate(data);
660+
// Process map updates immediately with neighbor distances
661+
this.processUpdate({
662+
...data,
663+
neighbors_distance: data.neighbors_distance || {}
664+
});
662665

663666
// Check if all nodes are offline
664667
this.checkAllNodesOffline();
@@ -1067,7 +1070,8 @@ class Monitor {
10671070
...data,
10681071
latitude: parseFloat(data.latitude),
10691072
longitude: parseFloat(data.longitude),
1070-
neighbors: data.neighbors || ""
1073+
neighbors: data.neighbors || "",
1074+
neighbors_distance: data.neighbors_distance || {}
10711075
};
10721076

10731077
this.log('Validated node data:', nodeData);
@@ -1217,15 +1221,23 @@ class Monitor {
12171221

12181222
// Add popup with distance information
12191223
try {
1220-
const distance = condition
1221-
? (this.droneMarkers[droneId].neighbors_distance &&
1222-
this.droneMarkers[droneId].neighbors_distance[neighborIP])
1223-
: (neighborMarker.neighbors_distance &&
1224-
neighborMarker.neighbors_distance[this.droneMarkers[droneId].ip]);
1224+
const currentMarker = this.droneMarkers[droneId];
1225+
const neighborFullIP = neighborIP.includes(':') ? neighborIP : `${neighborIP}:${currentMarker.port}`;
1226+
1227+
// Get distance from the current marker's neighbors_distance object
1228+
const distance = currentMarker.neighbors_distance &&
1229+
currentMarker.neighbors_distance[neighborFullIP];
1230+
1231+
this.log('Distance data:', {
1232+
marker: currentMarker,
1233+
neighborFullIP,
1234+
neighbors_distance: currentMarker.neighbors_distance,
1235+
distance
1236+
});
12251237

12261238
line.bindPopup(`
12271239
<div class="line-popup">
1228-
<p><strong>Distance:</strong> ${distance ? distance + ' m' : 'Calculating...'}</p>
1240+
<p><strong>Distance:</strong> ${distance ? distance.toFixed(2) + ' m' : 'Calculating...'}</p>
12291241
<p><strong>Status:</strong> Online</p>
12301242
</div>
12311243
`);
@@ -1466,13 +1478,17 @@ class Monitor {
14661478

14671479
// Update map marker if it exists
14681480
if (this.droneMarkers[nodeData.uid]) {
1481+
// Preserve existing neighbor distances
1482+
const existingMarker = this.droneMarkers[nodeData.uid];
1483+
const neighborsDistance = existingMarker.neighbors_distance || {};
1484+
14691485
this.updateDronePosition(
14701486
nodeData.uid,
14711487
nodeData.ip,
14721488
parseFloat(nodeData.latitude),
14731489
parseFloat(nodeData.longitude),
14741490
nodeData.neighbors ? nodeData.neighbors.split(/[\s,]+/).filter(ip => ip.trim() !== '') : [],
1475-
null
1491+
neighborsDistance
14761492
);
14771493
}
14781494
});

0 commit comments

Comments
 (0)