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