feat(config): Map-Parameter (Zoom, Center, etc.) in config.json ausgelagert

- minZoom, maxZoom, center, zoomOutCenter und basePath in config.json konfigurierbar gemacht
- Kommentare zur Erklärung als _comment-Felder ergänzt
- initializeMap.js und zoomAndCenterUtils.js angepasst, um Werte aus config.json zu lesen
- OSM-Standards für Zoom-Stufen dokumentiert
This commit is contained in:
ISA
2025-08-20 10:03:21 +02:00
parent 26d869f029
commit 9f05a4f63b
7 changed files with 110 additions and 30 deletions

View File

@@ -61,9 +61,14 @@ export const initializeMap = (
}
let tileLayerUrl = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png";
let minZoom = 5;
let maxZoom = 15;
let mapCenter = [53.111111, 8.4625];
try {
if (window && window.__tileSource) {
tileLayerUrl = window.__tileSource;
if (window && window.__tileSource && window.__tileSourceUrl) {
tileLayerUrl = window.__tileSourceUrl;
minZoom = window.__tileSourceMinZoom;
maxZoom = window.__tileSourceMaxZoom;
} else {
// Synchronous config fetch using XMLHttpRequest (since fetch is async)
const xhr = new XMLHttpRequest();
@@ -72,8 +77,18 @@ export const initializeMap = (
if (xhr.status === 200) {
const config = JSON.parse(xhr.responseText);
if (config.tileSources && config.active && config.tileSources[config.active]) {
window.__tileSource = config.tileSources[config.active];
tileLayerUrl = window.__tileSource;
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;
}
}
}
}
@@ -84,10 +99,10 @@ export const initializeMap = (
let initMap;
try {
initMap = L.map(mapContainer, {
center: [53.111111, 8.4625],
zoom: 12,
minZoom: 5,
maxZoom: 15,
center: mapCenter,
zoom: minZoom,
minZoom: minZoom,
maxZoom: maxZoom,
zoomControl: false,
dragging: true,
contextmenu: true,
@@ -108,8 +123,8 @@ export const initializeMap = (
L.tileLayer(tileLayerUrl, {
attribution: "© Eigene Kartenquelle (offline)",
tileSize: 256,
minZoom: 5,
maxZoom: 15,
minZoom: minZoom,
maxZoom: maxZoom,
noWrap: true,
errorTileUrl: "/img/empty-tile.png", // Optional
}).addTo(initMap);