feat: improve mapping functionality with markers, path, CORS

Co-authored-by: aider (ollama/qwen2.5-coder:32b) <aider@aider.chat>
This commit is contained in:
Josh-Dev-Quest 2026-03-01 16:12:00 +01:00
parent 42cb05367c
commit a20036e67c
No known key found for this signature in database

View File

@ -10,12 +10,12 @@ window.createMarker = function(lngLat, content = {}) {
// Create popup with marker content // Create popup with marker content
const popup = new maplibregl.Popup({ offset: 25 }) const popup = new maplibregl.Popup({ offset: 25 })
.setHTML(`<strong>${content.title || 'Untitled'}</strong>`); .setHTML(`<strong>${content.title || 'Untitled'}</strong>${content.description ? `<br>${content.description}` : ''}`);
marker.setPopup(popup); marker.setPopup(popup);
// When the marker is clicked, open the editor // When the marker is clicked, open the editor
marker.getElement().addEventListener('click', () => { marker.on('click', () => {
openMarkerEditor(marker); openMarkerEditor(marker);
}); });
@ -23,11 +23,13 @@ window.createMarker = function(lngLat, content = {}) {
const markerData = { const markerData = {
id: Date.now(), id: Date.now(),
lngLat: lngLat.toArray(), lngLat: lngLat.toArray(),
content: content content: content,
coordinates: [lngLat.lat, lngLat.lng]
}; };
// Add marker to current journey if (!currentJourney.markers) currentJourney.markers = [];
currentJourney.markers.push(marker); currentJourney.markers.push(marker);
updateJourneyPath(); updateJourneyPath();
// Add marker to the markers list // Add marker to the markers list
@ -41,16 +43,17 @@ window.createMarker = function(lngLat, content = {}) {
// Add click event to marker item // Add click event to marker item
markerElement.addEventListener('click', function() { markerElement.addEventListener('click', function() {
// Center map on marker
map.flyTo({ map.flyTo({
center: lngLat, center: [lngLat.lng, lngLat.lat],
zoom: 10 zoom: 10
}); });
// Open marker editor
openMarkerEditor(marker); openMarkerEditor(marker);
}); });
if (markersContainer.children.length === 1 &&
markersContainer.firstElementChild.id === 'empty-markers') {
markersContainer.removeChild(markersContainer.firstElementChild);
}
markersContainer.appendChild(markerElement); markersContainer.appendChild(markerElement);
return marker; return marker;
@ -58,8 +61,35 @@ window.createMarker = function(lngLat, content = {}) {
// Update the updateJourneyPath function to handle cases where markers array is empty // Update the updateJourneyPath function to handle cases where markers array is empty
function updateJourneyPath() { function updateJourneyPath() {
if (!currentJourney.markers || currentJourney.markers.length === 0) { if (!map.getSource('journey-path')) {
// If no markers, clear the path map.addSource('journey-path', {
type: 'geojson',
data: {
type: 'Feature',
properties: {},
geometry: {
type: 'LineString',
coordinates: []
}
}
});
map.addLayer({
id: 'journey-path',
type: 'line',
source: 'journey-path',
layout: {
'line-join': 'round',
'line-cap': 'round'
},
paint: {
'line-color': '#3887be',
'line-width': 4
}
});
}
if (currentJourney.markers.length === 0) {
map.getSource('journey-path').setData({ map.getSource('journey-path').setData({
type: 'Feature', type: 'Feature',
properties: {}, properties: {},
@ -71,7 +101,10 @@ function updateJourneyPath() {
return; return;
} }
const coordinates = currentJourney.markers.map(marker => marker.getLngLat().toArray()); const coordinates = currentJourney.markers.map(marker => [
marker.getLngLat().lng,
marker.getLngLat().lat
]);
map.getSource('journey-path').setData({ map.getSource('journey-path').setData({
type: 'Feature', type: 'Feature',