// Map initialization and management import { CONFIG } from './config.js'; import { showStatus } from './utils.js'; import { currentUser } from './auth.js'; export let map = null; export let startLocationMarker = null; export let isStartLocationVisible = true; // Function to get the map instance export function getMap() { return map; } export async function initializeMap() { try { // Get start location from PUBLIC endpoint (not admin endpoint) const response = await fetch('/api/settings/start-location'); // Changed from /api/config/start-location const data = await response.json(); let startLat = CONFIG.DEFAULT_LAT; let startLng = CONFIG.DEFAULT_LNG; let startZoom = CONFIG.DEFAULT_ZOOM; if (data.success && data.location) { startLat = data.location.latitude; startLng = data.location.longitude; startZoom = data.location.zoom; } // Initialize map map = L.map('map').setView([startLat, startLng], startZoom); // Add tile layer L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: '© OpenStreetMap contributors', maxZoom: CONFIG.MAX_ZOOM, minZoom: CONFIG.MIN_ZOOM }).addTo(map); // Add start location marker addStartLocationMarker(startLat, startLng); console.log('Map initialized successfully'); } catch (error) { console.error('Failed to initialize map:', error); showStatus('Failed to initialize map', 'error'); } } function addStartLocationMarker(lat, lng) { console.log(`Adding start location marker at: ${lat}, ${lng}`); // Remove existing start location marker if it exists if (startLocationMarker) { map.removeLayer(startLocationMarker); } // Create a very distinctive custom icon const startIcon = L.divIcon({ html: `
This is todays starting location!
${currentUser?.isAdmin ? '' : ''}