mirror of
https://github.com/pablorevilla-meshtastic/meshview.git
synced 2026-03-04 23:27:46 +01:00
Adding live-map and static pages for the apis
This commit is contained in:
@@ -79,7 +79,7 @@
|
||||
legend.appendChild(item);
|
||||
}
|
||||
|
||||
// Pulse marker animation
|
||||
// Pulse marker animation (dot shrinks but stays full color)
|
||||
function pulseMarker(marker, highlightColor="red") {
|
||||
if (!marker) return;
|
||||
const originalColor = marker.options.originalColor;
|
||||
@@ -131,11 +131,35 @@
|
||||
});
|
||||
|
||||
const markersWithCoords = Array.from(nodeMarkers.values()).filter(m=>m instanceof L.CircleMarker);
|
||||
if(markersWithCoords.length>0) map.fitBounds(L.featureGroup(markersWithCoords).getBounds().pad(0.2));
|
||||
else map.setView([37.77,-122.42],9);
|
||||
if(markersWithCoords.length>0) {
|
||||
// Fit bounds from /api/config instead of default
|
||||
await setMapBoundsFromConfig();
|
||||
} else {
|
||||
map.setView([37.77,-122.42],9);
|
||||
}
|
||||
} catch(err){ console.error(err); }
|
||||
}
|
||||
|
||||
// Set map bounds dynamically from /api/config
|
||||
async function setMapBoundsFromConfig() {
|
||||
try {
|
||||
const res = await fetch("/api/config");
|
||||
const config = await res.json();
|
||||
const topLeft = [
|
||||
parseFloat(config.site.map_top_left_lat),
|
||||
parseFloat(config.site.map_top_left_lon)
|
||||
];
|
||||
const bottomRight = [
|
||||
parseFloat(config.site.map_bottom_right_lat),
|
||||
parseFloat(config.site.map_bottom_right_lon)
|
||||
];
|
||||
map.fitBounds([topLeft, bottomRight]);
|
||||
} catch(err) {
|
||||
console.error("Failed to load map bounds from config:", err);
|
||||
map.setView([37.77,-122.42],9);
|
||||
}
|
||||
}
|
||||
|
||||
// Update ticket tape
|
||||
function updateTicketTape(pkt) {
|
||||
const nodeId = pkt.from_node_id;
|
||||
|
||||
@@ -1695,6 +1695,18 @@ async def api_stats(request):
|
||||
|
||||
return web.json_response(stats)
|
||||
|
||||
|
||||
|
||||
@routes.get("/api/config")
|
||||
async def api_config(request):
|
||||
try:
|
||||
# Return CONFIG as JSON
|
||||
return web.json_response(CONFIG)
|
||||
except Exception as e:
|
||||
return web.json_response({"error": str(e)}, status=500)
|
||||
|
||||
|
||||
|
||||
# Generic static HTML route
|
||||
@routes.get("/{page}")
|
||||
async def serve_page(request):
|
||||
|
||||
Reference in New Issue
Block a user