diff --git a/map.html b/map.html index 62ddb2f..e84aba7 100644 --- a/map.html +++ b/map.html @@ -104,6 +104,10 @@ attribution: '© OpenStreetMap contributors' }).addTo(map); + let currentJourney = { + markers: [] + }; + updateMarkersList(); // Call the new function to update the list // Add controls @@ -137,17 +141,19 @@ controls.appendChild(locateBtn); // Marker functionality - let markers = []; + let currentJourney = { + markers: [] + }; document.getElementById('add-marker').addEventListener('click', () => { map.on('click', function(e) { const marker = L.marker(e.latlng, {draggable: true}).addTo(map); - + marker.bindPopup(''); - - markers.push(marker); - - updateMarkerList(); + + currentJourney.markers.push(marker); + + updateMarkersList(); // Call the new function to update the list }); }); @@ -161,14 +167,32 @@ updateMarkerList(); }); - function updateMarkerList() { - const list = document.getElementById('marker-list'); - list.innerHTML = ''; - - markers.forEach((marker, index) => { - const li = document.createElement('div'); - li.textContent = `Marker ${index + 1}: ${marker.getLatLng().lat.toFixed(4)}, ${marker.getLngLat().lng.toFixed(4)}`; - list.appendChild(li); + function updateMarkersList() { + const markersContainer = document.getElementById('markers-container'); + markersContainer.innerHTML = ''; + + if (currentJourney.markers.length === 0) { + markersContainer.innerHTML = '

No markers yet. Click on the map to add markers.

'; + return; + } + + currentJourney.markers.forEach((marker, index) => { + const markerElement = document.createElement('div'); + markerElement.className = 'marker-item'; + markerElement.innerHTML = ` + ${index + 1} + ${marker.getLatLng().lat.toFixed(4)}, ${marker.getLngLat().lng.toFixed(4)} + `; + + // Add click handler to zoom to marker + markerElement.addEventListener('click', () => { + map.flyTo({ + center: [marker.getLatLng().lat, marker.getLatLng().lng], + zoom: 10 + }); + }); + + markersContainer.appendChild(markerElement); }); }