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:
@@ -15,29 +15,71 @@ export const zoomIn = (e, map) => {
|
||||
return;
|
||||
}
|
||||
|
||||
const currentZoom = map.getZoom();
|
||||
let maxZoom = 19;
|
||||
try {
|
||||
if (window && window.__tileSourceMaxZoom !== undefined) {
|
||||
maxZoom = window.__tileSourceMaxZoom;
|
||||
} else {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", "/config.json", false);
|
||||
xhr.send(null);
|
||||
if (xhr.status === 200) {
|
||||
const config = JSON.parse(xhr.responseText);
|
||||
if (config.tileSources && config.active && config.tileSources[config.active]) {
|
||||
maxZoom = config.tileSources[config.active].maxZoom;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
if (currentZoom < 14) {
|
||||
map.flyTo(e.latlng, 14);
|
||||
localStorage.setItem("mapZoom", 16);
|
||||
const currentZoom = map.getZoom();
|
||||
if (currentZoom < maxZoom) {
|
||||
map.flyTo(e.latlng, currentZoom + 1);
|
||||
localStorage.setItem("mapZoom", currentZoom + 1);
|
||||
localStorage.setItem("mapCenter", JSON.stringify(map.getCenter()));
|
||||
}
|
||||
};
|
||||
|
||||
export const zoomOut = (map) => {
|
||||
export const zoomOut = map => {
|
||||
if (!map) {
|
||||
console.error("map is not defined in zoomOut");
|
||||
return;
|
||||
}
|
||||
|
||||
let minZoom = 5;
|
||||
try {
|
||||
if (window && window.__tileSourceMinZoom !== undefined) {
|
||||
minZoom = window.__tileSourceMinZoom;
|
||||
} else {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", "/config.json", false);
|
||||
xhr.send(null);
|
||||
if (xhr.status === 200) {
|
||||
const config = JSON.parse(xhr.responseText);
|
||||
if (config.tileSources && config.active && config.tileSources[config.active]) {
|
||||
minZoom = config.tileSources[config.active].minZoom;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
const currentZoom = map.getZoom();
|
||||
if (currentZoom > minZoom) {
|
||||
let zoomOutCenter = [51.41321407879154, 7.739617925303934];
|
||||
try {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", "/config.json", false);
|
||||
xhr.send(null);
|
||||
if (xhr.status === 200) {
|
||||
const config = JSON.parse(xhr.responseText);
|
||||
if (Array.isArray(config.zoomOutCenter) && config.zoomOutCenter.length === 2) {
|
||||
zoomOutCenter = config.zoomOutCenter;
|
||||
}
|
||||
}
|
||||
} catch (e) {}
|
||||
const zoom = minZoom;
|
||||
|
||||
if (currentZoom > 7) {
|
||||
const x = 51.41321407879154;
|
||||
const y = 7.739617925303934;
|
||||
const zoom = 7;
|
||||
|
||||
map.flyTo([x, y], zoom);
|
||||
map.flyTo(zoomOutCenter, zoom);
|
||||
localStorage.setItem("mapZoom", zoom);
|
||||
localStorage.setItem("mapCenter", JSON.stringify(map.getCenter()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user