feat: osm von server als proxy für den client
This commit is contained in:
@@ -23,4 +23,4 @@ NEXT_PUBLIC_USE_MOCKS=true
|
|||||||
# z.B. http://10.10.0.13/xyz/index.aspx -> basePath in config.json auf /xyz setzen
|
# z.B. http://10.10.0.13/xyz/index.aspx -> basePath in config.json auf /xyz setzen
|
||||||
# basePath wird jetzt in public/config.json gepflegt
|
# basePath wird jetzt in public/config.json gepflegt
|
||||||
# App-Versionsnummer
|
# App-Versionsnummer
|
||||||
NEXT_PUBLIC_APP_VERSION=1.1.348
|
NEXT_PUBLIC_APP_VERSION=1.1.349
|
||||||
|
|||||||
@@ -24,4 +24,4 @@ NEXT_PUBLIC_USE_MOCKS=false
|
|||||||
# basePath wird jetzt in public/config.json gepflegt
|
# basePath wird jetzt in public/config.json gepflegt
|
||||||
|
|
||||||
# App-Versionsnummer
|
# App-Versionsnummer
|
||||||
NEXT_PUBLIC_APP_VERSION=1.1.348
|
NEXT_PUBLIC_APP_VERSION=1.1.349
|
||||||
|
|||||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "nodemap",
|
"name": "nodemap",
|
||||||
"version": "1.1.348",
|
"version": "1.1.349",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "nodemap",
|
"name": "nodemap",
|
||||||
"version": "1.1.348",
|
"version": "1.1.349",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@emotion/react": "^11.13.3",
|
"@emotion/react": "^11.13.3",
|
||||||
"@emotion/styled": "^11.13.0",
|
"@emotion/styled": "^11.13.0",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "nodemap",
|
"name": "nodemap",
|
||||||
"version": "1.1.348",
|
"version": "1.1.349",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@emotion/react": "^11.13.3",
|
"@emotion/react": "^11.13.3",
|
||||||
"@emotion/styled": "^11.13.0",
|
"@emotion/styled": "^11.13.0",
|
||||||
|
|||||||
@@ -13,8 +13,8 @@
|
|||||||
"maxZoom": 15
|
"maxZoom": 15
|
||||||
},
|
},
|
||||||
"osm": {
|
"osm": {
|
||||||
"url": "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
|
"url": "/tiles/{z}/{x}/{y}.png",
|
||||||
"_comment": "OpenStreetMap Online-Kartenquelle",
|
"_comment": "OpenStreetMap Online-Kartenquelle über Server-Proxy (relativ)",
|
||||||
"minZoom": 0,
|
"minZoom": 0,
|
||||||
"maxZoom": 19
|
"maxZoom": 19
|
||||||
}
|
}
|
||||||
|
|||||||
27
server.js
27
server.js
@@ -27,10 +27,35 @@ const extractData = (json, name) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
app.prepare().then(() => {
|
app.prepare().then(() => {
|
||||||
const server = createServer((req, res) => {
|
const express = require("express");
|
||||||
|
const expressApp = express();
|
||||||
|
// Proxy-Route für Karten-Tiles
|
||||||
|
expressApp.get("/tiles/:z/:x/:y.png", async (req, res) => {
|
||||||
|
const { z, x, y } = req.params;
|
||||||
|
// OSM-Subdomain (a, b, c) zufällig wählen
|
||||||
|
const subdomains = ["a", "b", "c"];
|
||||||
|
const s = subdomains[Math.floor(Math.random() * subdomains.length)];
|
||||||
|
const tileUrl = `https://${s}.tile.openstreetmap.org/${z}/${x}/${y}.png`;
|
||||||
|
try {
|
||||||
|
const response = await fetch(tileUrl);
|
||||||
|
if (!response.ok) {
|
||||||
|
res.status(response.status).send("Tile not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
res.set("Content-Type", "image/png");
|
||||||
|
response.body.pipe(res);
|
||||||
|
} catch (err) {
|
||||||
|
res.status(500).send("Error fetching tile");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Alle anderen Routen an Next.js
|
||||||
|
expressApp.all("*", (req, res) => {
|
||||||
handle(req, res);
|
handle(req, res);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const server = createServer(expressApp);
|
||||||
|
|
||||||
const io = new Server(server);
|
const io = new Server(server);
|
||||||
|
|
||||||
// ✅ Globaler Cache für alle aktuellen Daten
|
// ✅ Globaler Cache für alle aktuellen Daten
|
||||||
|
|||||||
@@ -89,6 +89,12 @@ export const initializeMap = (
|
|||||||
if (config.tileSources && config.active && config.tileSources[config.active]) {
|
if (config.tileSources && config.active && config.tileSources[config.active]) {
|
||||||
const tileSource = config.tileSources[config.active];
|
const tileSource = config.tileSources[config.active];
|
||||||
tileLayerUrl = tileSource.url || tileLayerUrl;
|
tileLayerUrl = tileSource.url || tileLayerUrl;
|
||||||
|
// Dynamische URL für Server-Tiles
|
||||||
|
if (tileLayerUrl.startsWith("/tiles") || tileLayerUrl.startsWith("tiles")) {
|
||||||
|
tileLayerUrl = `${window.location.origin.replace(/\/$/, "")}${
|
||||||
|
tileLayerUrl.startsWith("/") ? tileLayerUrl : "/" + tileLayerUrl
|
||||||
|
}`;
|
||||||
|
}
|
||||||
minZoom = tileSource.minZoom ?? minZoom;
|
minZoom = tileSource.minZoom ?? minZoom;
|
||||||
maxZoom = tileSource.maxZoom ?? maxZoom;
|
maxZoom = tileSource.maxZoom ?? maxZoom;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user