The changes involve restructuring the code to use an object for markers and adding new functionalities.
refactor: replace markers array with currentJourney object Co-authored-by: aider (ollama/qwen2.5-coder:32b) <aider@aider.chat>
This commit is contained in:
parent
942de8c297
commit
9603f87573
44
map.html
44
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,7 +141,9 @@
|
||||
controls.appendChild(locateBtn);
|
||||
|
||||
// Marker functionality
|
||||
let markers = [];
|
||||
let currentJourney = {
|
||||
markers: []
|
||||
};
|
||||
|
||||
document.getElementById('add-marker').addEventListener('click', () => {
|
||||
map.on('click', function(e) {
|
||||
@ -145,9 +151,9 @@
|
||||
|
||||
marker.bindPopup('<input type="text" placeholder="Enter title">');
|
||||
|
||||
markers.push(marker);
|
||||
currentJourney.markers.push(marker);
|
||||
|
||||
updateMarkerList();
|
||||
updateMarkersList(); // Call the new function to update the list
|
||||
});
|
||||
});
|
||||
|
||||
@ -161,14 +167,32 @@
|
||||
updateMarkerList();
|
||||
});
|
||||
|
||||
function updateMarkerList() {
|
||||
const list = document.getElementById('marker-list');
|
||||
list.innerHTML = '';
|
||||
function updateMarkersList() {
|
||||
const markersContainer = document.getElementById('markers-container');
|
||||
markersContainer.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);
|
||||
if (currentJourney.markers.length === 0) {
|
||||
markersContainer.innerHTML = '<p class="empty-message">No markers yet. Click on the map to add markers.</p>';
|
||||
return;
|
||||
}
|
||||
|
||||
currentJourney.markers.forEach((marker, index) => {
|
||||
const markerElement = document.createElement('div');
|
||||
markerElement.className = 'marker-item';
|
||||
markerElement.innerHTML = `
|
||||
<strong>${index + 1}</strong>
|
||||
${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);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user