feat: add journey creation with title, description, and marker management
Co-authored-by: aider (ollama/qwen2.5-coder:32b) <aider@aider.chat>
This commit is contained in:
2 files changed
+108
-19
No files matched your search
+92
-2
@@ -1,13 +1,103 @@
|
||||
// /Volumes/Data/Code/FHGR/Frontend/js/main.js
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Initialize global variables
|
||||
// Initialize current journey when page loads
|
||||
window.currentJourney = {
|
||||
id: Date.now(),
|
||||
name: "Untitled Journey",
|
||||
name: "",
|
||||
description: "",
|
||||
markers: [],
|
||||
path: null
|
||||
};
|
||||
|
||||
// Function to prepare and save the journey
|
||||
function prepareAndSaveJourney() {
|
||||
const journeyData = {
|
||||
name: document.getElementById('journey-title').value,
|
||||
description: document.getElementById('journey-description').value,
|
||||
markers: window.currentJourney.markers.map(marker => ({
|
||||
id: marker.id,
|
||||
lngLat: [marker.getLatLng().lat, marker.getLatLng().lng],
|
||||
content: marker.content
|
||||
}))
|
||||
};
|
||||
|
||||
// Save to backend
|
||||
fetch('http://localhost:5000/api/journeys', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(journeyData)
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
alert('Journey saved successfully!');
|
||||
window.currentJourney = {
|
||||
id: Date.now(),
|
||||
name: "",
|
||||
description: "",
|
||||
markers: [],
|
||||
path: null
|
||||
};
|
||||
document.getElementById('journey-title').value = '';
|
||||
document.getElementById('journey-description').value = '';
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
alert('Failed to save journey. Please try again.');
|
||||
});
|
||||
}
|
||||
|
||||
// Event listeners for the buttons
|
||||
document.getElementById('add-marker-btn').addEventListener('click', function() {
|
||||
map.on('click', function(e) {
|
||||
const marker = L.marker(e.latlng, {draggable: true}).addTo(map);
|
||||
|
||||
// Add popup with input field
|
||||
marker.bindPopup('<input type="text" id="marker-title" placeholder="Enter title">');
|
||||
|
||||
window.currentJourney.markers.push(marker);
|
||||
updateMarkersList();
|
||||
});
|
||||
});
|
||||
|
||||
document.getElementById('save-journey-btn').addEventListener('click', prepareAndSaveJourney);
|
||||
|
||||
document.getElementById('clear-markers-btn').addEventListener('click', function() {
|
||||
map.eachLayer(function(layer) {
|
||||
if (layer instanceof L.Marker) {
|
||||
map.removeLayer(layer);
|
||||
}
|
||||
});
|
||||
window.currentJourney.markers = [];
|
||||
updateMarkersList();
|
||||
});
|
||||
|
||||
function updateMarkersList() {
|
||||
const markersContainer = document.getElementById('markers-container');
|
||||
markersContainer.innerHTML = '';
|
||||
|
||||
if (window.currentJourney.markers.length === 0) {
|
||||
markersContainer.innerHTML = '<p class="empty-message">No markers yet. Click on the map to add markers.</p>';
|
||||
return;
|
||||
}
|
||||
|
||||
window.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 event to edit marker
|
||||
markerElement.addEventListener('click', () => {
|
||||
marker.openPopup();
|
||||
});
|
||||
|
||||
markersContainer.appendChild(markerElement);
|
||||
});
|
||||
}
|
||||
window.journeys = [];
|
||||
window.isCreatingJourney = true;
|
||||
|
||||
|
||||
Reference in new issue
Block a user