From 6fe004d036ff1a338d91b3450fa7c799806b7e47 Mon Sep 17 00:00:00 2001 From: lklynet Date: Sat, 3 Jan 2026 12:10:57 -0500 Subject: [PATCH] add your own location to map map updates heatmap without refresh --- public/app.js | 38 ++++++++++++++++++++++++++++++++++++-- server.js | 1 + 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/public/app.js b/public/app.js index ab54520..3878f37 100644 --- a/public/app.js +++ b/public/app.js @@ -106,6 +106,21 @@ let mapInitialized = false; let peerMarkers = {}; // id -> marker let ipCache = {}; // ip -> { lat, lon } let lastPeerData = []; +let myLocation = null; + +const fetchMyLocation = async () => { + if (myLocation) return; + try { + const res = await fetch('https://ipwho.is/'); + const data = await res.json(); + if (data.success) { + myLocation = { lat: data.latitude, lon: data.longitude, city: data.city, country: data.country }; + updateMap(lastPeerData); + } + } catch (e) { + console.error('My location fetch failed', e); + } +} const openMap = () => { document.getElementById('mapModal').classList.add('active'); @@ -116,6 +131,9 @@ const openMap = () => { map.invalidateSize(); }, 100); } + + fetchMyLocation(); + if (lastPeerData.length > 0) { updateMap(lastPeerData); } @@ -172,13 +190,14 @@ const fetchLocation = async (ip) => { } const updateMap = async (peers) => { - if (!mapInitialized || !peers) return; + if (!mapInitialized) return; + if (!peers) peers = []; const currentIds = new Set(peers.map(p => p.id)); // Remove old markers for (const id in peerMarkers) { - if (!currentIds.has(id)) { + if (id !== 'me' && !currentIds.has(id)) { map.removeLayer(peerMarkers[id]); delete peerMarkers[id]; } @@ -205,6 +224,21 @@ const updateMap = async (peers) => { } } } + + // Add My Location + if (myLocation && !peerMarkers['me']) { + const marker = L.circleMarker([myLocation.lat, myLocation.lon], { + radius: 6, + fillColor: "#ffffff", + color: "#4ade80", + weight: 2, + opacity: 1, + fillOpacity: 1 + }).addTo(map); + + marker.bindPopup(`This Node
${myLocation.city}, ${myLocation.country}`); + peerMarkers['me'] = marker; + } } const terminal = document.getElementById('terminal'); diff --git a/server.js b/server.js index 8b226d2..5e0534a 100644 --- a/server.js +++ b/server.js @@ -26,6 +26,7 @@ const main = async () => { id: identity.id, diagnostics: diagnostics.getStats(), chatEnabled: ENABLE_CHAT, + peers: peerManager.getPeersWithIps() }); };