// Map initialization and marker management function initMap() { AppState.map = L.map('map').setView([51.1657, 10.4515], 6); L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: '© OpenStreetMap contributors', maxZoom: 19, }).addTo(AppState.map); // Try to get user's location if (navigator.geolocation) { navigator.geolocation.getCurrentPosition( (position) => { const lat = position.coords.latitude; const lon = position.coords.longitude; // Add user location marker const userIcon = L.divIcon({ html: '
', className: '', iconSize: [16, 16], iconAnchor: [8, 8] }); L.marker([lat, lon], { icon: userIcon }) .addTo(AppState.map) .bindPopup('
Dein Standort
'); console.log('User location:', lat, lon); }, (error) => { console.log('Geolocation error:', error.message); } ); } } function clearMarkers() { AppState.markers.forEach(marker => AppState.map.removeLayer(marker)); AppState.markers = []; } function addMarker(listing) { if (!listing.lat || !listing.lon) return; const marker = L.marker([listing.lat, listing.lon]).addTo(AppState.map); // Check if mobile const isMobile = window.innerWidth < 768; if (isMobile) { // On mobile: open fullscreen popup marker.on('click', () => { showMobilePopup(listing); }); } else { // On desktop: use regular leaflet popup const imageHtml = listing.image ? `${listing.title}` : ''; const popupContent = `
${listing.title}
${imageHtml} ${listing.price} €
${listing.address}
Link öffnen →
`; marker.bindPopup(popupContent); marker.on('click', () => { AppState.selectedListingId = listing.id; highlightSelectedListing(); }); } AppState.markers.push(marker); } function showMobilePopup(listing) { const popup = document.getElementById('mobilePopup'); const content = document.getElementById('mobilePopupContent'); const imageHtml = listing.image ? `${listing.title}` : ''; const dateStr = listing.date_added ? new Date(listing.date_added).toLocaleDateString('de-DE') : 'Unbekannt'; content.innerHTML = ` ${imageHtml} Inserat auf Kleinanzeigen.de öffnen `; popup.classList.add('show'); }