Got context menu working

This commit is contained in:
Will Bradley 2025-07-16 13:05:43 -07:00
parent 4dfc0fdf84
commit 429663d80c

View File

@ -375,11 +375,9 @@
// Handle right-click context menu
map.on('contextmenu', function(e) {
console.log('contextmenu event:', e);
e.originalEvent.preventDefault();
const clientX = e.originalEvent.clientX || e.originalEvent.pageX;
const clientY = e.originalEvent.clientY || e.originalEvent.pageY;
console.log('Context menu coordinates:', clientX, clientY);
showContextMenu(clientX, clientY, e.latlng);
});
@ -422,11 +420,9 @@
// Context menu functions
function showContextMenu(x, y, latlng) {
console.log('showContextMenu called with:', x, y, latlng);
hideContextMenu();
const contextMenu = document.getElementById('contextMenu');
contextMenuPosition = latlng;
console.log('contextMenuPosition set to:', contextMenuPosition);
contextMenu.style.display = 'block';
contextMenu.style.left = x + 'px';
@ -451,14 +447,10 @@
}
function contextAddStation() {
console.log('contextAddStation called');
console.log('contextMenuPosition:', contextMenuPosition);
const savedPosition = contextMenuPosition;
hideContextMenu();
if (contextMenuPosition) {
console.log('Opening modal with position:', contextMenuPosition);
openAddStationModal(contextMenuPosition);
} else {
console.log('No contextMenuPosition available');
if (savedPosition) {
openAddStationModal(savedPosition);
}
}
@ -569,16 +561,13 @@
}
function openAddStationModal(latlng = null) {
console.log('openAddStationModal called with:', latlng);
document.getElementById('addModal').style.display = 'block';
if (latlng) {
console.log('Setting coordinates:', latlng.lat, latlng.lng);
document.getElementById('coordinates').value = `${latlng.lat.toFixed(6)}, ${latlng.lng.toFixed(6)}`;
if (tempMarker) {
map.removeLayer(tempMarker);
}
tempMarker = L.marker(latlng).addTo(map);
console.log('Marker added to map');
}
}
@ -734,9 +723,6 @@
const menuItem = document.getElementById('addStationMenuItem');
if (menuItem) {
menuItem.addEventListener('click', contextAddStation);
console.log('Context menu event listener attached');
} else {
console.error('Could not find addStationMenuItem element');
}
});
</script>