mesh-map/templates/map.html
david 8641463324
All checks were successful
Meshtastic Map - See local Meshtastic Nodes / deploy (push) Successful in 1s
map UI changes
2025-04-23 13:05:48 -07:00

94 lines
3.0 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>Meshtastic Map</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css" />
</head>
<body>
<div id="map" style="height: 100vh;"></div>
<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
<script>
var map = L.map('map').setView([0, 0], 2);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map);
let myCoords = null;
const today = new Date();
const daysSince = (test) => {
if (test) {
const diffTime = Math.abs(test.getTime() - today.getTime());
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
return diffDays;
}
return "N/A"
}
const getNodeDesc = (node) => {
const deviceMetrics = node?.deviceMetrics
const hopsAway = node?.hopsAway ?? 'N/A';
const lastHeard = node?.lastHeard ? new Date(node?.lastHeard * 1000) : null
const num = node?.num;
const position = node?.position;
const snr = node?.snr ?? 'N/A';
const user = node?.user;
const lat = position?.latitude
return `
${user.id}<br/>
${user.shortName}<br/>
${hopsAway} hop<br/>
S/N: ${snr} dbM<br/>
Last Heard: ${daysSince(lastHeard)} days
`
}
const updateNodes = async () => {
const res = await fetch('/nodes');
const json = await res.json();
const myNodeId = json['myNodeId']
// const myNodeNum = json['myNodeNum']
const nodes = json['nodes']
let myNode = null;
// const my
// Object.entries(nodes).forEach()
Object.entries(nodes).forEach(([id, node]) => {
if (id == myNodeId) {
console.log("found")
myNode = node;
}
const deviceMetrics = node?.deviceMetrics
const hopsAway = node?.hopsAway;
const lastHeard = node?.lastHeard;
const num = node?.num;
const position = node?.position;
const snr = node?.snr;
const user = node?.user;
const lat = position?.latitude
const lon = position?.longitude
if (lat && lon) {
L.marker([lat, lon]).addTo(map)
.bindPopup(getNodeDesc(node));
if (id == myNodeId && myCoords != [lat, lon]) {
myCoords = [lat, lon];
map.setView([lat, lon], 15);
}
}
})
}
updateNodes();
center();
setInterval(updateNodes, 10000);
</script>
</body>
</html>