diff --git a/index.html b/index.html index 8e6b380..9373e5a 100644 --- a/index.html +++ b/index.html @@ -54,6 +54,15 @@ +
+ + +
+

Latitude: 0, Longitude: 0

Street: , City: , Country:

diff --git a/index.js b/index.js index 5a6e4c6..9e58943 100644 --- a/index.js +++ b/index.js @@ -56,6 +56,7 @@ let speed = 1; // speed unit meter per second let loop = 'off'; // off; loop; uturn let pause = false; let teleportEnabled = false; +const locationHistory = []; const tickInterval = 1000; // update location per 1000ms const randomFactor = 0.2; // +-20% of origin value @@ -65,6 +66,44 @@ const tick = setInterval(function() { navigate(); }, tickInterval); +document.addEventListener('DOMContentLoaded', function () { + const storedHistory = localStorage.getItem('locationHistory'); + if (storedHistory) { + locationHistory.push(...JSON.parse(storedHistory)); + updateHistoryDropdown(); + } +}); + +const updateHistoryDropdown = () => { + const historyDropdown = document.getElementById('historyDropdown'); + + // Clear the existing dropdown items + historyDropdown.innerHTML = ''; + + // Add the latest 5 clicked locations to the dropdown + for (let i = 0; i < Math.min(locationHistory.length, 5); i++) { + const location = locationHistory[i]; + const listItem = document.createElement('button'); + listItem.classList.add('dropdown-item'); + listItem.textContent = `Lat: ${location.lat.toFixed(6)}, Lon: ${location.lng.toFixed(6)}`; + + // Add an event listener to handle when a history item is clicked + listItem.addEventListener('click', () => { + // Update the map and position information with the selected history item + if (teleportEnabled) { + teleport(location); + } else { + if (!initMain({ latlng: location })) { + addStep(location); + } + updatePositionInfo(location); + } + }); + + historyDropdown.appendChild(listItem); + } +}; + const updateRadio = (name, value) => { document.getElementsByName(name).forEach((element) => { @@ -156,6 +195,12 @@ map.on('click', function(e) { } } updatePositionInfo(e.latlng); + locationHistory.unshift(e.latlng); + if (locationHistory.length > 5) { + locationHistory.pop(); + } + updateHistoryDropdown(); + localStorage.setItem('locationHistory', JSON.stringify(locationHistory)); }); map.on('zoomend', function () {