@@ -657,8 +657,11 @@ class Monitor {
657
657
// Queue the graph update
658
658
this . updateGraph ( ) ;
659
659
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
+ } ) ;
662
665
663
666
// Check if all nodes are offline
664
667
this . checkAllNodesOffline ( ) ;
@@ -1067,7 +1070,8 @@ class Monitor {
1067
1070
...data ,
1068
1071
latitude : parseFloat ( data . latitude ) ,
1069
1072
longitude : parseFloat ( data . longitude ) ,
1070
- neighbors : data . neighbors || ""
1073
+ neighbors : data . neighbors || "" ,
1074
+ neighbors_distance : data . neighbors_distance || { }
1071
1075
} ;
1072
1076
1073
1077
this . log ( 'Validated node data:' , nodeData ) ;
@@ -1217,15 +1221,23 @@ class Monitor {
1217
1221
1218
1222
// Add popup with distance information
1219
1223
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
+ } ) ;
1225
1237
1226
1238
line . bindPopup ( `
1227
1239
<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>
1229
1241
<p><strong>Status:</strong> Online</p>
1230
1242
</div>
1231
1243
` ) ;
@@ -1466,13 +1478,17 @@ class Monitor {
1466
1478
1467
1479
// Update map marker if it exists
1468
1480
if ( this . droneMarkers [ nodeData . uid ] ) {
1481
+ // Preserve existing neighbor distances
1482
+ const existingMarker = this . droneMarkers [ nodeData . uid ] ;
1483
+ const neighborsDistance = existingMarker . neighbors_distance || { } ;
1484
+
1469
1485
this . updateDronePosition (
1470
1486
nodeData . uid ,
1471
1487
nodeData . ip ,
1472
1488
parseFloat ( nodeData . latitude ) ,
1473
1489
parseFloat ( nodeData . longitude ) ,
1474
1490
nodeData . neighbors ? nodeData . neighbors . split ( / [ \s , ] + / ) . filter ( ip => ip . trim ( ) !== '' ) : [ ] ,
1475
- null
1491
+ neighborsDistance
1476
1492
) ;
1477
1493
}
1478
1494
} ) ;
0 commit comments