Skip to content

Commit

Permalink
Update livemap.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Highpoint2000 committed Oct 2, 2024
1 parent a05fe0c commit 8d8d043
Showing 1 changed file with 1 addition and 25 deletions.
26 changes: 1 addition & 25 deletions LiveMap/livemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -1357,28 +1357,15 @@ async function fetchAndCacheStationData(freq, radius, picode, txposLat, txposLon
let previousFreq = null;
let timeoutId = null;
let isFirstUpdateAfterChange = false;
let freq_save

async function handleWebSocketMessage(event) {
const frequencyElement = document.getElementById('data-frequency');

try {
const data = JSON.parse(event.data);
const { pi: picode, freq, txInfo: { itu, city, tx: station, dist: distance, pol, id: stationid }, ps } = data;

if (freq !== previousFreq) {

// Check if the element exists
if (frequencyElement) {
frequencyElement.addEventListener('click', debounce(() => {
const dataToSend = `T${(parseFloat(freq_save) * 1000).toFixed(0)}`;
socket.send(dataToSend);
// console.debug("WebSocket sending:", dataToSend);
}, 50)); // Debounce for 50 ms
freq_save = previousFreq;
} else {
console.error('Element with ID "data-frequency" not found.');
}

previousFreq = freq;
isFirstUpdateAfterChange = true;

Expand All @@ -1398,17 +1385,6 @@ async function handleWebSocketMessage(event) {
}
}

// Debounce function to limit the rate of invoking a function
function debounce(func, wait) {
let timeout;
return function (...args) {
const context = this;
clearTimeout(timeout);
timeout = setTimeout(() => func.apply(context, args), wait);
};
}


// Function to add drag functionality to the iframe
function addDragFunctionality(element) {
let offsetX = 0, offsetY = 0, startX = 0, startY = 0;
Expand Down

0 comments on commit 8d8d043

Please sign in to comment.