This commit is contained in:
liamcottle
2024-09-08 00:09:50 +12:00
parent fff4cc9a49
commit e12e56a221

View File

@ -3317,14 +3317,15 @@
nodes = []; nodes = [];
// get config // get config
const now = moment();
const configNodesMaxAgeInSeconds = getConfigNodesMaxAgeInSeconds();
const configNodesOfflineAgeInSeconds = getConfigNodesOfflineAgeInSeconds();
const configNeighboursMaxDistanceInMeters = getConfigNeighboursMaxDistanceInMeters(); const configNeighboursMaxDistanceInMeters = getConfigNeighboursMaxDistanceInMeters();
// add nodes // add nodes
for(var node of updatedNodes){ for(const node of updatedNodes){
// skip nodes older than configured node max age // skip nodes older than configured node max age
const now = moment();
const configNodesMaxAgeInSeconds = getConfigNodesMaxAgeInSeconds();
if(configNodesMaxAgeInSeconds){ if(configNodesMaxAgeInSeconds){
const lastUpdatedAgeInMillis = now.diff(moment(node.updated_at)); const lastUpdatedAgeInMillis = now.diff(moment(node.updated_at));
if(lastUpdatedAgeInMillis > configNodesMaxAgeInSeconds * 1000){ if(lastUpdatedAgeInMillis > configNodesMaxAgeInSeconds * 1000){
@ -3344,9 +3345,10 @@
node.latitude = node.latitude / 10000000; node.latitude = node.latitude / 10000000;
node.longitude = node.longitude / 10000000; node.longitude = node.longitude / 10000000;
var hasLocation = isValidLatLng(node.latitude, node.longitude); // skip nodes with invalid position
if(!isValidLatLng(node.latitude, node.longitude)){
if(hasLocation){ continue;
}
// wrap longitude for shortest path, everything to left of australia should be shown on the right // wrap longitude for shortest path, everything to left of australia should be shown on the right
var longitude = parseFloat(node.longitude); var longitude = parseFloat(node.longitude);
@ -3358,8 +3360,6 @@
var icon = iconMqttDisconnected; var icon = iconMqttDisconnected;
// use offline icon for nodes older than configured node offline age // use offline icon for nodes older than configured node offline age
const now = moment();
const configNodesOfflineAgeInSeconds = getConfigNodesOfflineAgeInSeconds();
if(configNodesOfflineAgeInSeconds){ if(configNodesOfflineAgeInSeconds){
const lastUpdatedAgeInMillis = now.diff(moment(node.updated_at)); const lastUpdatedAgeInMillis = now.diff(moment(node.updated_at));
if(lastUpdatedAgeInMillis > configNodesOfflineAgeInSeconds * 1000){ if(lastUpdatedAgeInMillis > configNodesOfflineAgeInSeconds * 1000){
@ -3374,7 +3374,7 @@
} }
// create node marker // create node marker
var marker = L.marker([node.latitude, longitude], { const marker = L.marker([node.latitude, longitude], {
icon: icon, icon: icon,
tagName: node.node_id, tagName: node.node_id,
// we want to show online nodes above offline, but without needing to use separate layer groups // we want to show online nodes above offline, but without needing to use separate layer groups
@ -3431,9 +3431,7 @@
} }
} for(const node of updatedNodes){
for(var node of updatedNodes){
// find current node // find current node
const currentNode = findNodeMarkerById(node.node_id); const currentNode = findNodeMarkerById(node.node_id);
@ -3522,12 +3520,14 @@
// clear nodes cache // clear nodes cache
waypoints = []; waypoints = [];
// add nodes // get config
for(var waypoint of updatedWaypoints){
// skip waypoints older than configured waypoint max age
const now = moment(); const now = moment();
const configWaypointsMaxAgeInSeconds = getConfigWaypointsMaxAgeInSeconds(); const configWaypointsMaxAgeInSeconds = getConfigWaypointsMaxAgeInSeconds();
// add nodes
for(const waypoint of updatedWaypoints){
// skip waypoints older than configured waypoint max age
if(configWaypointsMaxAgeInSeconds){ if(configWaypointsMaxAgeInSeconds){
const lastUpdatedAgeInMillis = now.diff(moment(waypoint.updated_at)); const lastUpdatedAgeInMillis = now.diff(moment(waypoint.updated_at));
if(lastUpdatedAgeInMillis > configWaypointsMaxAgeInSeconds * 1000){ if(lastUpdatedAgeInMillis > configWaypointsMaxAgeInSeconds * 1000){
@ -3540,7 +3540,7 @@
continue; continue;
} }
// skip nodes without position // skip waypoints without position
if(!waypoint.latitude || !waypoint.longitude){ if(!waypoint.latitude || !waypoint.longitude){
continue; continue;
} }
@ -3549,9 +3549,10 @@
waypoint.latitude = waypoint.latitude / 10000000; waypoint.latitude = waypoint.latitude / 10000000;
waypoint.longitude = waypoint.longitude / 10000000; waypoint.longitude = waypoint.longitude / 10000000;
var hasLocation = isValidLatLng(waypoint.latitude, waypoint.longitude); // skip waypoints with invalid position
if(!isValidLatLng(waypoint.latitude, waypoint.longitude)){
if(hasLocation){ continue;
}
// wrap longitude for shortest path, everything to left of australia should be shown on the right // wrap longitude for shortest path, everything to left of australia should be shown on the right
var longitude = parseFloat(waypoint.longitude); var longitude = parseFloat(waypoint.longitude);
@ -3566,7 +3567,7 @@
var tooltip = getTooltipContentForWaypoint(waypoint); var tooltip = getTooltipContentForWaypoint(waypoint);
// create waypoint marker // create waypoint marker
var marker = L.marker([waypoint.latitude, longitude], { const marker = L.marker([waypoint.latitude, longitude], {
icon: L.divIcon({ icon: L.divIcon({
className: 'waypoint-label', className: 'waypoint-label',
iconSize: [26, 26], // increase from 12px to 26px iconSize: [26, 26], // increase from 12px to 26px
@ -3594,14 +3595,12 @@
} }
}
function onPositionHistoryUpdated(updatedPositionHistories) { function onPositionHistoryUpdated(updatedPositionHistories) {
let positionHistoryLinesCords = []; let positionHistoryLinesCords = [];
// add nodes // add nodes
for(var positionHistory of updatedPositionHistories) { for(const positionHistory of updatedPositionHistories) {
// skip position history without position // skip position history without position
if(!positionHistory.latitude || !positionHistory.longitude){ if(!positionHistory.latitude || !positionHistory.longitude){
@ -3618,8 +3617,10 @@
positionHistory.latitude = positionHistory.latitude / 10000000; positionHistory.latitude = positionHistory.latitude / 10000000;
positionHistory.longitude = positionHistory.longitude / 10000000; positionHistory.longitude = positionHistory.longitude / 10000000;
var hasLocation = isValidLatLng(positionHistory.latitude, positionHistory.longitude); // skip position history with invalid position
if(hasLocation){ if(!isValidLatLng(positionHistory.latitude, positionHistory.longitude)){
continue;
}
// wrap longitude for shortest path, everything to left of australia should be shown on the right // wrap longitude for shortest path, everything to left of australia should be shown on the right
var longitude = parseFloat(positionHistory.longitude); var longitude = parseFloat(positionHistory.longitude);
@ -3659,8 +3660,6 @@
} }
}
// show lines between position history markers // show lines between position history markers
L.polyline(positionHistoryLinesCords).addTo(nodePositionHistoryLayerGroup); L.polyline(positionHistoryLinesCords).addTo(nodePositionHistoryLayerGroup);