Files
eventmap/js/main.js
T
dapelza 2d41bce063 Feature: Standort per Klick auf der Karte auswaehlen
Neuer Toolbar-Button "Standort auf Karte waehlen" ergaenzt die
bestehenden Wege (Browser-Geolocation, manuelle Eingabe): aktiviert
einen Auswahlmodus (Crosshair-Cursor, Hinweisleiste mit
Abbrechen-Option), der naechste Klick auf die Karte setzt
state.userLocation auf die geklickten Koordinaten. Escape oder der
Abbrechen-Button beenden den Modus ohne Aenderung.

js/map/mapController.js: startLocationPicking()/stopLocationPicking()/
isPickingLocation() kapseln den einmaligen Klick-Listener und dessen
Aufraeumen. Wiederverwendet den bereits vorhandenen
"Hier bist du"-Marker (aus dem vorherigen Fix) fuer die Anzeige.
2026-07-24 12:55:04 +02:00

182 lines
5.0 KiB
JavaScript

// Einstiegspunkt der Anwendung: initialisiert Store, Karte und Liste.
(function () {
const { initStore } = EventMap.store;
const {
initMap,
centerOnCoords,
requestUserLocation,
startLocationPicking,
stopLocationPicking,
isPickingLocation,
} = EventMap.map;
const {
initList,
initDetail,
initForm,
initManualLocationForm,
initFilterPanel,
initPromptGenerator,
initImport,
} = EventMap.ui;
function showFatalError(message) {
const status = document.getElementById('app-status');
const statusText = document.getElementById('app-status-text');
if (!status || !statusText) return;
statusText.textContent = message;
status.hidden = false;
}
function hideStatus() {
const status = document.getElementById('app-status');
const statusText = document.getElementById('app-status-text');
if (!status || !statusText) return;
status.hidden = true;
statusText.textContent = '';
}
// Verdrahtet den Schließen-Button der Statusmeldung unabhängig vom
// restlichen Bootstrap-Ablauf, damit er auch dann funktioniert, wenn
// bootstrap() selbst fehlschlägt und showFatalError() aus dem
// catch-Handler heraus aufgerufen wird (siehe Gitea Issue #1: die
// Fehlermeldung war bisher dauerhaft nicht schließbar).
function setupStatusClose() {
const closeBtn = document.getElementById('app-status-close');
if (!closeBtn) return;
closeBtn.addEventListener('click', hideStatus);
}
function setupGeolocationButton() {
const button = document.getElementById('locate-btn');
if (!button) return;
const defaultLabel = button.textContent;
button.addEventListener('click', () => {
button.disabled = true;
button.textContent = 'Standort wird ermittelt…';
requestUserLocation({
onSuccess: ({ lat, lng }) => {
centerOnCoords(lat, lng, 13);
button.disabled = false;
button.textContent = defaultLabel;
},
onError: () => {
button.disabled = false;
button.textContent = defaultLabel;
showFatalError(
'Standort konnte nicht ermittelt werden. Bitte Standortfreigabe im Browser prüfen.'
);
},
});
});
}
function setupManualLocationButton() {
const button = document.getElementById('manual-location-btn');
if (!button) return;
button.addEventListener('click', () => {
EventMap.ui.openManualLocationForm();
});
}
function setupPickLocationButton() {
const button = document.getElementById('pick-location-btn');
const hint = document.getElementById('map-picking-hint');
const cancelBtn = document.getElementById('map-picking-cancel-btn');
if (!button || !hint || !cancelBtn) return;
const defaultLabel = button.textContent;
function endPicking() {
button.textContent = defaultLabel;
button.classList.remove('btn--active');
hint.hidden = true;
}
function beginPicking() {
button.textContent = 'Klicke auf die Karte …';
button.classList.add('btn--active');
hint.hidden = false;
startLocationPicking({
onPick: ({ lat, lng }) => {
EventMap.store.setState({ userLocation: { lat, lng } });
EventMap.store.updateSettings({ userConsentGeo: true });
endPicking();
},
onCancel: endPicking,
});
}
button.addEventListener('click', () => {
if (isPickingLocation()) {
stopLocationPicking();
endPicking();
} else {
beginPicking();
}
});
cancelBtn.addEventListener('click', () => {
stopLocationPicking();
endPicking();
});
}
function setupAddPlaceButton() {
const button = document.getElementById('add-place-btn');
if (!button) return;
button.addEventListener('click', () => {
EventMap.ui.openPlaceForm();
});
}
function setupPromptGeneratorButton() {
const button = document.getElementById('open-prompt-generator-btn');
if (!button) return;
button.addEventListener('click', () => {
EventMap.ui.openPromptGenerator();
});
}
function setupImportButton() {
const button = document.getElementById('open-import-btn');
if (!button) return;
button.addEventListener('click', () => {
EventMap.ui.openImport();
});
}
async function bootstrap() {
await initStore();
initMap('map');
initFilterPanel('filter-panel');
initList('place-list');
initDetail('detail-modal');
initForm('place-form-modal');
initManualLocationForm('manual-location-modal');
initPromptGenerator('prompt-generator-modal');
initImport('import-modal');
setupGeolocationButton();
setupManualLocationButton();
setupPickLocationButton();
setupAddPlaceButton();
setupPromptGeneratorButton();
setupImportButton();
}
setupStatusClose();
bootstrap().catch((err) => {
console.error('EventMap: Initialisierung fehlgeschlagen.', err);
showFatalError('Die Anwendung konnte nicht geladen werden. Bitte Seite neu laden.');
});
})();