fix: leere Array

This commit is contained in:
ISA
2025-08-20 14:41:57 +02:00
parent 819fde9605
commit 22692f8153
7 changed files with 49 additions and 36 deletions

View File

@@ -60,47 +60,58 @@ export const initializeMap = (
mapContainer.innerHTML = "";
}
// --- CONFIG LOADING ---
let config = null;
let tileLayerUrl = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png";
let mapCenter = [53.111111, 8.4625];
let mapZoom = 12;
let minZoom = 5;
let maxZoom = 15;
let mapCenter = [53.111111, 8.4625];
try {
if (window && window.__tileSource && window.__tileSourceUrl) {
tileLayerUrl = window.__tileSourceUrl;
minZoom = window.__tileSourceMinZoom;
maxZoom = window.__tileSourceMaxZoom;
if (window && window.__leafletConfig) {
config = window.__leafletConfig;
} else {
// Synchronous config fetch using XMLHttpRequest (since fetch is async)
const xhr = new XMLHttpRequest();
xhr.open("GET", "/config.json", false); // false = synchronous
xhr.send(null);
if (xhr.status === 200) {
const config = JSON.parse(xhr.responseText);
if (config.tileSources && config.active && config.tileSources[config.active]) {
const source = config.tileSources[config.active];
tileLayerUrl = source.url;
minZoom = source.minZoom;
maxZoom = source.maxZoom;
window.__tileSourceUrl = tileLayerUrl;
window.__tileSourceMinZoom = minZoom;
window.__tileSourceMaxZoom = maxZoom;
if (source.center && Array.isArray(source.center) && source.center.length === 2) {
mapCenter = source.center;
} else if (config.center && Array.isArray(config.center) && config.center.length === 2) {
mapCenter = config.center;
}
}
config = JSON.parse(xhr.responseText);
window.__leafletConfig = config;
}
}
if (config) {
// Tile source
if (config.tileSources && config.active && config.tileSources[config.active]) {
const tileSource = config.tileSources[config.active];
tileLayerUrl = tileSource.url || tileLayerUrl;
minZoom = tileSource.minZoom ?? minZoom;
maxZoom = tileSource.maxZoom ?? maxZoom;
}
// Center
if (Array.isArray(config.center)) {
mapCenter = config.center;
}
// Zoom (optional, fallback to 12)
if (typeof config.zoom === "number") {
mapZoom = config.zoom;
}
// minZoom/maxZoom global fallback
if (typeof config.minZoom === "number") {
minZoom = config.minZoom;
}
if (typeof config.maxZoom === "number") {
maxZoom = config.maxZoom;
}
}
} catch (e) {
// Fallback bleibt OSM
// Fallback bleibt OSM und Defaults
}
let initMap;
try {
initMap = L.map(mapContainer, {
center: mapCenter,
zoom: minZoom,
zoom: mapZoom,
minZoom: minZoom,
maxZoom: maxZoom,
zoomControl: false,